dbghelp: Use local declarations of r_debug and link_map structs.
[wine.git] / dlls / ntdll / ntdll_misc.h
blob2a91511f0d5176caed344761975ecd4635afa253
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 <signal.h>
24 #include <sys/types.h>
25 #include <pthread.h>
27 #include "windef.h"
28 #include "winnt.h"
29 #include "winternl.h"
30 #include "wine/server.h"
31 #include "wine/asm.h"
33 #define MAX_NT_PATH_LENGTH 277
35 #define MAX_DOS_DRIVES 26
37 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
38 static const UINT_PTR page_size = 0x1000;
39 #else
40 extern UINT_PTR page_size DECLSPEC_HIDDEN;
41 #endif
43 struct drive_info
45 dev_t dev;
46 ino_t ino;
49 extern NTSTATUS close_handle( HANDLE ) DECLSPEC_HIDDEN;
50 extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
52 /* exceptions */
53 extern void wait_suspend( CONTEXT *context ) DECLSPEC_HIDDEN;
54 extern NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context ) DECLSPEC_HIDDEN;
55 extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) DECLSPEC_HIDDEN;
56 extern void raise_status( NTSTATUS status, EXCEPTION_RECORD *rec ) DECLSPEC_NORETURN DECLSPEC_HIDDEN;
57 extern NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) DECLSPEC_HIDDEN;
58 extern NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) DECLSPEC_HIDDEN;
59 extern NTSTATUS set_thread_context( HANDLE handle, const context_t *context, BOOL *self ) DECLSPEC_HIDDEN;
60 extern NTSTATUS get_thread_context( HANDLE handle, context_t *context, unsigned int flags, BOOL *self ) DECLSPEC_HIDDEN;
61 extern LONG WINAPI call_unhandled_exception_filter( PEXCEPTION_POINTERS eptr ) DECLSPEC_HIDDEN;
63 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
64 extern RUNTIME_FUNCTION *lookup_function_info( ULONG_PTR pc, ULONG_PTR *base, LDR_MODULE **module ) DECLSPEC_HIDDEN;
65 #endif
67 /* debug helpers */
68 extern LPCSTR debugstr_us( const UNICODE_STRING *str ) DECLSPEC_HIDDEN;
69 extern LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa) DECLSPEC_HIDDEN;
71 /* init routines */
72 extern NTSTATUS signal_alloc_thread( TEB **teb ) DECLSPEC_HIDDEN;
73 extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN;
74 extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN;
75 extern void signal_init_process(void) DECLSPEC_HIDDEN;
76 extern void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) DECLSPEC_HIDDEN;
77 extern void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) DECLSPEC_HIDDEN;
78 extern void DECLSPEC_NORETURN signal_exit_thread( int status ) DECLSPEC_HIDDEN;
79 extern void DECLSPEC_NORETURN signal_exit_process( int status ) DECLSPEC_HIDDEN;
80 extern void version_init(void) DECLSPEC_HIDDEN;
81 extern void debug_init(void) DECLSPEC_HIDDEN;
82 extern TEB *thread_init(void) DECLSPEC_HIDDEN;
83 extern void actctx_init(void) DECLSPEC_HIDDEN;
84 extern void virtual_init(void) DECLSPEC_HIDDEN;
85 extern void virtual_init_threading(void) DECLSPEC_HIDDEN;
86 extern void fill_cpu_info(void) DECLSPEC_HIDDEN;
87 extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN;
88 extern void init_unix_codepage(void) DECLSPEC_HIDDEN;
89 extern void init_locale( HMODULE module ) DECLSPEC_HIDDEN;
90 extern void init_user_process_params( SIZE_T data_size ) DECLSPEC_HIDDEN;
91 extern char **build_envp( const WCHAR *envW ) DECLSPEC_HIDDEN;
92 extern NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) DECLSPEC_HIDDEN;
94 /* server support */
95 extern timeout_t server_start_time DECLSPEC_HIDDEN;
96 extern unsigned int server_cpus DECLSPEC_HIDDEN;
97 extern BOOL is_wow64 DECLSPEC_HIDDEN;
98 extern void server_init_process(void) DECLSPEC_HIDDEN;
99 extern void server_init_process_done(void) DECLSPEC_HIDDEN;
100 extern size_t server_init_thread( void *entry_point, BOOL *suspend ) DECLSPEC_HIDDEN;
101 extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;
102 extern void DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN;
103 extern sigset_t server_block_set DECLSPEC_HIDDEN;
104 extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
105 extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN;
106 extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN;
107 extern unsigned int server_select( const select_op_t *select_op, data_size_t size,
108 UINT flags, const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;
109 extern unsigned int server_queue_process_apc( HANDLE process, const apc_call_t *call, apc_result_t *result ) DECLSPEC_HIDDEN;
110 extern int server_remove_fd_from_cache( HANDLE handle ) DECLSPEC_HIDDEN;
111 extern int server_get_unix_fd( HANDLE handle, unsigned int access, int *unix_fd,
112 int *needs_close, enum server_fd_type *type, unsigned int *options ) DECLSPEC_HIDDEN;
113 extern int server_pipe( int fd[2] ) DECLSPEC_HIDDEN;
114 extern NTSTATUS alloc_object_attributes( const OBJECT_ATTRIBUTES *attr, struct object_attributes **ret,
115 data_size_t *ret_len ) DECLSPEC_HIDDEN;
116 extern NTSTATUS validate_open_object_attributes( const OBJECT_ATTRIBUTES *attr ) DECLSPEC_HIDDEN;
117 extern int wait_select_reply( void *cookie ) DECLSPEC_HIDDEN;
118 extern void invoke_apc( const apc_call_t *call, apc_result_t *result ) DECLSPEC_HIDDEN;
120 /* module handling */
121 extern LIST_ENTRY tls_links DECLSPEC_HIDDEN;
122 extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
123 DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
124 extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
125 FARPROC origfun, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
126 extern void RELAY_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
127 extern void SNOOP_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
128 extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
129 extern const WCHAR syswow64_dir[] DECLSPEC_HIDDEN;
131 extern void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) DECLSPEC_HIDDEN;
133 /* Device IO */
134 extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice,
135 HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
136 PVOID UserApcContext,
137 PIO_STATUS_BLOCK piosb,
138 ULONG IoControlCode,
139 LPVOID lpInBuffer, DWORD nInBufferSize,
140 LPVOID lpOutBuffer, DWORD nOutBufferSize) DECLSPEC_HIDDEN;
141 extern NTSTATUS COMM_DeviceIoControl(HANDLE hDevice,
142 HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
143 PVOID UserApcContext,
144 PIO_STATUS_BLOCK piosb,
145 ULONG IoControlCode,
146 LPVOID lpInBuffer, DWORD nInBufferSize,
147 LPVOID lpOutBuffer, DWORD nOutBufferSize) DECLSPEC_HIDDEN;
148 extern NTSTATUS TAPE_DeviceIoControl(HANDLE hDevice,
149 HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
150 PVOID UserApcContext,
151 PIO_STATUS_BLOCK piosb,
152 ULONG IoControlCode,
153 LPVOID lpInBuffer, DWORD nInBufferSize,
154 LPVOID lpOutBuffer, DWORD nOutBufferSize) DECLSPEC_HIDDEN;
155 extern NTSTATUS COMM_FlushBuffersFile( int fd ) DECLSPEC_HIDDEN;
157 /* file I/O */
158 struct stat;
159 extern NTSTATUS FILE_GetNtStatus(void) DECLSPEC_HIDDEN;
160 extern int get_file_info( const char *path, struct stat *st, ULONG *attr ) DECLSPEC_HIDDEN;
161 extern NTSTATUS fill_file_info( const struct stat *st, ULONG attr, void *ptr,
162 FILE_INFORMATION_CLASS class ) DECLSPEC_HIDDEN;
163 extern NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name ) DECLSPEC_HIDDEN;
164 extern void init_directories(void) DECLSPEC_HIDDEN;
165 extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name ) DECLSPEC_HIDDEN;
166 extern NTSTATUS DIR_unmount_device( HANDLE handle ) DECLSPEC_HIDDEN;
167 extern NTSTATUS DIR_get_unix_cwd( char **cwd ) DECLSPEC_HIDDEN;
168 extern unsigned int DIR_get_drives_info( struct drive_info info[MAX_DOS_DRIVES] ) DECLSPEC_HIDDEN;
169 extern NTSTATUS file_id_to_unix_file_name( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name_ret ) DECLSPEC_HIDDEN;
170 extern NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_STRING *unix_name_ret,
171 UINT disposition ) DECLSPEC_HIDDEN;
173 /* virtual memory */
174 extern NTSTATUS virtual_alloc_aligned( PVOID *ret, unsigned short zero_bits_64, SIZE_T *size_ptr,
175 ULONG type, ULONG protect, ULONG alignment ) DECLSPEC_HIDDEN;
176 extern NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64, SIZE_T commit_size,
177 const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
178 ULONG protect, pe_image_info_t *image_info ) DECLSPEC_HIDDEN;
179 extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info ) DECLSPEC_HIDDEN;
180 extern NTSTATUS virtual_create_builtin_view( void *base ) DECLSPEC_HIDDEN;
181 extern NTSTATUS virtual_alloc_thread_stack( INITIAL_TEB *stack, SIZE_T reserve_size,
182 SIZE_T commit_size, SIZE_T *pthread_size ) DECLSPEC_HIDDEN;
183 extern void virtual_clear_thread_stack( void *stack_end ) DECLSPEC_HIDDEN;
184 extern int virtual_handle_stack_fault( void *addr ) DECLSPEC_HIDDEN;
185 extern BOOL virtual_is_valid_code_address( const void *addr, SIZE_T size ) DECLSPEC_HIDDEN;
186 extern NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack ) DECLSPEC_HIDDEN;
187 extern unsigned int virtual_locked_server_call( void *req_ptr ) DECLSPEC_HIDDEN;
188 extern ssize_t virtual_locked_read( int fd, void *addr, size_t size ) DECLSPEC_HIDDEN;
189 extern ssize_t virtual_locked_pread( int fd, void *addr, size_t size, off_t offset ) DECLSPEC_HIDDEN;
190 extern BOOL virtual_check_buffer_for_read( const void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
191 extern BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
192 extern SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
193 extern NTSTATUS virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
194 extern void VIRTUAL_SetForceExec( BOOL enable ) DECLSPEC_HIDDEN;
195 extern void virtual_release_address_space(void) DECLSPEC_HIDDEN;
196 extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
197 extern void virtual_fill_image_information( const pe_image_info_t *pe_info,
198 SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
199 extern struct _KUSER_SHARED_DATA *user_shared_data DECLSPEC_HIDDEN;
201 /* completion */
202 extern NTSTATUS NTDLL_AddCompletion( HANDLE hFile, ULONG_PTR CompletionValue,
203 NTSTATUS CompletionStatus, ULONG Information, BOOL async) DECLSPEC_HIDDEN;
205 /* locale */
206 extern LCID user_lcid, system_lcid;
207 extern DWORD ntdll_umbstowcs( const char* src, DWORD srclen, WCHAR* dst, DWORD dstlen ) DECLSPEC_HIDDEN;
208 extern int ntdll_wcstoumbs( const WCHAR* src, DWORD srclen, char* dst, DWORD dstlen, BOOL strict ) DECLSPEC_HIDDEN;
210 extern int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_list args ) DECLSPEC_HIDDEN;
211 extern int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args ) DECLSPEC_HIDDEN;
213 /* load order */
215 enum loadorder
217 LO_INVALID,
218 LO_DISABLED,
219 LO_NATIVE,
220 LO_BUILTIN,
221 LO_NATIVE_BUILTIN, /* native then builtin */
222 LO_BUILTIN_NATIVE, /* builtin then native */
223 LO_DEFAULT /* nothing specified, use default strategy */
226 extern enum loadorder get_load_order( const WCHAR *app_name, const UNICODE_STRING *nt_name ) DECLSPEC_HIDDEN;
228 struct debug_info
230 unsigned int str_pos; /* current position in strings buffer */
231 unsigned int out_pos; /* current position in output buffer */
232 char strings[1024]; /* buffer for temporary strings */
233 char output[1024]; /* current output line */
236 /* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
237 struct ntdll_thread_data
239 struct debug_info *debug_info; /* info for debugstr functions */
240 void *start_stack; /* stack for thread startup */
241 int request_fd; /* fd for sending server requests */
242 int reply_fd; /* fd for receiving server replies */
243 int wait_fd[2]; /* fd for sleeping server requests */
244 BOOL wow64_redir; /* Wow64 filesystem redirection flag */
245 pthread_t pthread_id; /* pthread thread id */
248 C_ASSERT( sizeof(struct ntdll_thread_data) <= sizeof(((TEB *)0)->GdiTebBatch) );
250 static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
252 return (struct ntdll_thread_data *)&NtCurrentTeb()->GdiTebBatch;
255 static inline int get_unix_exit_code( NTSTATUS status )
257 /* prevent a nonzero exit code to end up truncated to zero in unix */
258 if (status && !(status & 0xff)) return 1;
259 return status;
262 extern mode_t FILE_umask DECLSPEC_HIDDEN;
263 extern HANDLE keyed_event DECLSPEC_HIDDEN;
264 extern SYSTEM_CPU_INFORMATION cpu_info DECLSPEC_HIDDEN;
266 #define HASH_STRING_ALGORITHM_DEFAULT 0
267 #define HASH_STRING_ALGORITHM_X65599 1
268 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
270 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
271 void WINAPI LdrInitializeThunk(CONTEXT*,void**,ULONG_PTR,ULONG_PTR);
273 /* string functions */
274 int __cdecl NTDLL_tolower( int c );
275 int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 );
276 int __cdecl NTDLL__wcsicmp( LPCWSTR str1, LPCWSTR str2 );
277 int __cdecl NTDLL__wcsnicmp( LPCWSTR str1, LPCWSTR str2, size_t n );
278 int __cdecl NTDLL_wcscmp( LPCWSTR str1, LPCWSTR str2 );
279 int __cdecl NTDLL_wcsncmp( LPCWSTR str1, LPCWSTR str2, size_t n );
280 WCHAR __cdecl NTDLL_towlower( WCHAR ch );
281 WCHAR __cdecl NTDLL_towupper( WCHAR ch );
282 LPWSTR __cdecl NTDLL__wcslwr( LPWSTR str );
283 LPWSTR __cdecl NTDLL__wcsupr( LPWSTR str );
284 LPWSTR __cdecl NTDLL_wcscpy( LPWSTR dst, LPCWSTR src );
285 LPWSTR __cdecl NTDLL_wcscat( LPWSTR dst, LPCWSTR src );
286 LPWSTR __cdecl NTDLL_wcschr( LPCWSTR str, WCHAR ch );
287 size_t __cdecl NTDLL_wcslen( LPCWSTR str );
288 size_t __cdecl NTDLL_wcscspn( LPCWSTR str, LPCWSTR reject );
289 LPWSTR __cdecl NTDLL_wcsncat( LPWSTR s1, LPCWSTR s2, size_t n );
290 LPWSTR __cdecl NTDLL_wcsncpy( LPWSTR s1, LPCWSTR s2, size_t n );
291 LPWSTR __cdecl NTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept );
292 LPWSTR __cdecl NTDLL_wcsrchr( LPCWSTR str, WCHAR ch );
293 size_t __cdecl NTDLL_wcsspn( LPCWSTR str, LPCWSTR accept );
294 LPWSTR __cdecl NTDLL_wcsstr( LPCWSTR str, LPCWSTR sub );
295 LPWSTR __cdecl NTDLL_wcstok( LPWSTR str, LPCWSTR delim );
296 LONG __cdecl NTDLL_wcstol( LPCWSTR s, LPWSTR *end, INT base );
297 ULONG __cdecl NTDLL_wcstoul( LPCWSTR s, LPWSTR *end, INT base );
298 int WINAPIV NTDLL_swprintf( WCHAR *str, const WCHAR *format, ... );
300 #define wcsicmp(s1,s2) NTDLL__wcsicmp(s1,s2)
301 #define wcsnicmp(s1,s2,n) NTDLL__wcsnicmp(s1,s2,n)
302 #define towupper(c) NTDLL_towupper(c)
303 #define wcslwr(s) NTDLL__wcslwr(s)
304 #define wcsupr(s) NTDLL__wcsupr(s)
305 #define wcscpy(d,s) NTDLL_wcscpy(d,s)
306 #define wcscat(d,s) NTDLL_wcscat(d,s)
307 #define wcschr(s,c) NTDLL_wcschr(s,c)
308 #define wcspbrk(s,a) NTDLL_wcspbrk(s,a)
309 #define wcsrchr(s,c) NTDLL_wcsrchr(s,c)
310 #define wcstoul(s,e,b) NTDLL_wcstoul(s,e,b)
311 #define wcslen(s) NTDLL_wcslen(s)
312 #define wcscspn(s,r) NTDLL_wcscspn(s,r)
313 #define wcsspn(s,a) NTDLL_wcsspn(s,a)
314 #define wcscmp(s1,s2) NTDLL_wcscmp(s1,s2)
315 #define wcsncmp(s1,s2,n) NTDLL_wcsncmp(s1,s2,n)
317 /* convert from straight ASCII to Unicode without depending on the current codepage */
318 static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
320 while (len--) *dst++ = (unsigned char)*src++;
323 #endif