include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / ntdll / ntdll_misc.h
blob52875efa6b5a1fc140ec52b20759984948904dbc
1 /*
2 * Copyright 2000 Juergen Schmied
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __WINE_NTDLL_MISC_H
20 #define __WINE_NTDLL_MISC_H
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnt.h"
29 #include "winternl.h"
30 #include "rtlsupportapi.h"
31 #include "unixlib.h"
32 #include "wine/asm.h"
34 #define MAX_NT_PATH_LENGTH 277
36 #define NTDLL_TLS_ERRNO 16 /* TLS slot for _errno() */
38 #ifdef __i386__
39 static const USHORT current_machine = IMAGE_FILE_MACHINE_I386;
40 #elif defined(__x86_64__)
41 static const USHORT current_machine = IMAGE_FILE_MACHINE_AMD64;
42 #elif defined(__arm__)
43 static const USHORT current_machine = IMAGE_FILE_MACHINE_ARMNT;
44 #elif defined(__aarch64__)
45 static const USHORT current_machine = IMAGE_FILE_MACHINE_ARM64;
46 #else
47 static const USHORT current_machine = IMAGE_FILE_MACHINE_UNKNOWN;
48 #endif
50 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
51 static const UINT_PTR page_size = 0x1000;
52 #else
53 extern UINT_PTR page_size;
54 #endif
56 /* exceptions */
57 extern NTSTATUS call_seh_handlers( EXCEPTION_RECORD *rec, CONTEXT *context );
58 extern NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context );
59 extern NTSTATUS WINAPI dispatch_user_callback( void *args, ULONG len, ULONG id );
60 extern EXCEPTION_DISPOSITION WINAPI user_callback_handler( EXCEPTION_RECORD *record, void *frame,
61 CONTEXT *context, void *dispatch );
62 extern EXCEPTION_DISPOSITION WINAPI nested_exception_handler( EXCEPTION_RECORD *rec, void *frame,
63 CONTEXT *context, void *dispatch );
64 extern void DECLSPEC_NORETURN raise_status( NTSTATUS status, EXCEPTION_RECORD *rec );
65 extern LONG WINAPI call_unhandled_exception_filter( PEXCEPTION_POINTERS eptr );
66 extern void WINAPI process_breakpoint(void);
68 static inline BOOL is_valid_frame( ULONG_PTR frame )
70 if (frame & (sizeof(void*) - 1)) return FALSE;
71 return ((void *)frame >= NtCurrentTeb()->Tib.StackLimit &&
72 (void *)frame <= NtCurrentTeb()->Tib.StackBase);
75 extern void WINAPI LdrInitializeThunk(CONTEXT*,ULONG_PTR,ULONG_PTR,ULONG_PTR);
76 extern void WINAPI KiUserExceptionDispatcher(EXCEPTION_RECORD*,CONTEXT*);
77 extern void WINAPI KiUserApcDispatcher(CONTEXT*,ULONG_PTR,ULONG_PTR,ULONG_PTR,PNTAPCFUNC);
78 extern void WINAPI KiUserCallbackDispatcher(ULONG,void*,ULONG);
79 extern void WINAPI KiUserCallbackDispatcherReturn(void);
80 extern void (WINAPI *pWow64PrepareForException)( EXCEPTION_RECORD *rec, CONTEXT *context );
82 /* debug helpers */
83 extern LPCSTR debugstr_us( const UNICODE_STRING *str );
84 extern void set_native_thread_name( DWORD tid, const char *name );
86 /* init routines */
87 extern void loader_init( CONTEXT *context, void **entry );
88 extern void version_init(void);
89 extern void debug_init(void);
90 extern void actctx_init(void);
91 extern void locale_init(void);
92 extern void init_user_process_params(void);
93 extern void get_resource_lcids( LANGID *user, LANGID *user_neutral, LANGID *system );
95 /* module handling */
96 extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
97 DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user );
98 extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
99 FARPROC origfun, DWORD ordinal, const WCHAR *user );
100 extern void RELAY_SetupDLL( HMODULE hmod );
101 extern void SNOOP_SetupDLL( HMODULE hmod );
102 extern const WCHAR windows_dir[];
103 extern const WCHAR system_dir[];
105 extern void (FASTCALL *pBaseThreadInitThunk)(DWORD,LPTHREAD_START_ROUTINE,void *);
107 extern struct _KUSER_SHARED_DATA *user_shared_data;
109 #ifdef _WIN64
110 static inline TEB64 *NtCurrentTeb64(void) { return NULL; }
111 #else
112 static inline TEB64 *NtCurrentTeb64(void) { return (TEB64 *)NtCurrentTeb()->GdiBatchCount; }
113 #endif
115 /* convert from straight ASCII to Unicode without depending on the current codepage */
116 static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
118 while (len--) *dst++ = (unsigned char)*src++;
121 /* FLS data */
122 extern TEB_FLS_DATA *fls_alloc_data(void);
123 extern void heap_thread_detach(void);
125 #if defined __aarch64__ || defined __arm64ec__
126 /* equivalent of WOW64INFO, stored after the 64-bit PEB */
127 struct arm64ec_shared_info
129 ULONG Wow64ExecuteFlags;
130 USHORT NativeMachineType;
131 USHORT EmulatedMachineType;
132 HANDLE SectionHandle;
133 CROSS_PROCESS_WORK_LIST *CrossProcessWorkList;
134 void *unknown;
136 #endif
138 /* register context */
140 #ifdef __i386__
141 # define TRACE_CONTEXT(c) do { \
142 TRACE( "eip=%08lx esp=%08lx ebp=%08lx eflags=%08lx\n", (c)->Eip, (c)->Esp, (c)->Ebp, (c)->EFlags );\
143 TRACE( "eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx\n", (c)->Eax, (c)->Ebx, (c)->Ecx, (c)->Edx ); \
144 TRACE( "esi=%08lx edi=%08lx cs=%04x ds=%04x es=%04x fs=%04x gs=%04x ss=%04x\n", \
145 (c)->Esi, (c)->Edi, LOWORD((c)->SegCs), LOWORD((c)->SegDs), LOWORD((c)->SegEs), \
146 LOWORD((c)->SegFs), LOWORD((c)->SegGs), LOWORD((c)->SegSs) ); \
147 } while(0)
148 #elif defined(__x86_64__)
149 # define TRACE_CONTEXT(c) do { \
150 TRACE( "rip=%016I64x rsp=%016I64x rbp=%016I64x eflags=%08lx\n", (c)->Rip, (c)->Rsp, (c)->Rbp, (c)->EFlags ); \
151 TRACE( "rax=%016I64x rbx=%016I64x rcx=%016I64x rdx=%016I64x\n", (c)->Rax, (c)->Rbx, (c)->Rcx, (c)->Rdx ); \
152 TRACE( "rsi=%016I64x rdi=%016I64x r8=%016I64x r9=%016I64x\n", (c)->Rsi, (c)->Rdi, (c)->R8, (c)->R9 ); \
153 TRACE( "r10=%016I64x r11=%016I64x r12=%016I64x r13=%016I64x\n", (c)->R10, (c)->R11, (c)->R12, (c)->R13 ); \
154 TRACE( "r14=%016I64x r15=%016I64x mxcsr=%08lx\n", (c)->R14, (c)->R15, (c)->MxCsr ); \
155 } while(0)
156 #elif defined(__arm__)
157 # define TRACE_CONTEXT(c) do { \
158 TRACE( "pc=%08lx sp=%08lx lr=%08lx ip=%08lx cpsr=%08lx\n", (c)->Pc, (c)->Sp, (c)->Lr, (c)->R12, (c)->Cpsr ); \
159 TRACE( "r0=%08lx r1=%08lx r2=%08lx r3=%08lx r4=%08lx r5=%08lx\n", (c)->R0, (c)->R1, (c)->R2, (c)->R3, (c)->R4, (c)->R5 ); \
160 TRACE( "r6=%08lx r7=%08lx r8=%08lx r9=%08lx r10=%08lx r11=%08lx\n", (c)->R6, (c)->R7, (c)->R8, (c)->R9, (c)->R10, (c)->R11 ); \
161 } while(0)
162 #elif defined(__aarch64__)
163 # define TRACE_CONTEXT(c) do { \
164 TRACE( " pc=%016I64x sp=%016I64x lr=%016I64x fp=%016I64x\n", (c)->Pc, (c)->Sp, (c)->Lr, (c)->Fp ); \
165 TRACE( " x0=%016I64x x1=%016I64x x2=%016I64x x3=%016I64x\n", (c)->X0, (c)->X1, (c)->X2, (c)->X3 ); \
166 TRACE( " x4=%016I64x x5=%016I64x x6=%016I64x x7=%016I64x\n", (c)->X4, (c)->X5, (c)->X6, (c)->X7 ); \
167 TRACE( " x8=%016I64x x9=%016I64x x10=%016I64x x11=%016I64x\n", (c)->X8, (c)->X9, (c)->X10, (c)->X11 ); \
168 TRACE( "x12=%016I64x x13=%016I64x x14=%016I64x x15=%016I64x\n", (c)->X12, (c)->X13, (c)->X14, (c)->X15 ); \
169 TRACE( "x16=%016I64x x17=%016I64x x18=%016I64x x19=%016I64x\n", (c)->X16, (c)->X17, (c)->X18, (c)->X19 ); \
170 TRACE( "x20=%016I64x x21=%016I64x x22=%016I64x x23=%016I64x\n", (c)->X20, (c)->X21, (c)->X22, (c)->X23 ); \
171 TRACE( "x24=%016I64x x25=%016I64x x26=%016I64x x27=%016I64x\n", (c)->X24, (c)->X25, (c)->X26, (c)->X27 ); \
172 TRACE( "x28=%016I64x cpsr=%08lx fpcr=%08lx fpsr=%08lx\n", (c)->X28, (c)->Cpsr, (c)->Fpcr, (c)->Fpsr ); \
173 } while(0)
174 #endif
176 #ifdef __arm64ec__
178 extern NTSTATUS arm64ec_process_init( HMODULE module );
179 extern NTSTATUS arm64ec_thread_init(void);
181 extern void *__os_arm64x_check_call;
182 extern void *__os_arm64x_check_icall;
183 extern void *__os_arm64x_check_icall_cfg;
184 extern void *__os_arm64x_dispatch_call_no_redirect;
185 extern void *__os_arm64x_dispatch_fptr;
186 extern void *__os_arm64x_dispatch_ret;
187 extern void *__os_arm64x_get_x64_information;
188 extern void *__os_arm64x_set_x64_information;
189 extern void *__os_arm64x_helper0;
190 extern void *__os_arm64x_helper1;
191 extern void *__os_arm64x_helper2;
192 extern void *__os_arm64x_helper3;
193 extern void *__os_arm64x_helper4;
194 extern void *__os_arm64x_helper5;
195 extern void *__os_arm64x_helper6;
196 extern void *__os_arm64x_helper7;
197 extern void *__os_arm64x_helper8;
199 #endif
201 #endif