2 * Ntdll Unix private interface
4 * Copyright (C) 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __NTDLL_UNIX_PRIVATE_H
22 #define __NTDLL_UNIX_PRIVATE_H
27 #include "wine/unixlib.h"
28 #include "wine/server.h"
29 #include "wine/list.h"
34 static const WORD current_machine
= IMAGE_FILE_MACHINE_I386
;
35 #elif defined(__x86_64__)
36 static const WORD current_machine
= IMAGE_FILE_MACHINE_AMD64
;
37 #elif defined(__arm__)
38 static const WORD current_machine
= IMAGE_FILE_MACHINE_ARMNT
;
39 #elif defined(__aarch64__)
40 static const WORD current_machine
= IMAGE_FILE_MACHINE_ARM64
;
42 extern WORD native_machine DECLSPEC_HIDDEN
;
44 static const BOOL is_win64
= (sizeof(void *) > sizeof(int));
46 static inline BOOL
is_machine_64bit( WORD machine
)
48 return (machine
== IMAGE_FILE_MACHINE_AMD64
|| machine
== IMAGE_FILE_MACHINE_ARM64
);
51 /* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
52 struct ntdll_thread_data
54 void *cpu_data
[16]; /* reserved for CPU-specific data */
55 void *kernel_stack
; /* stack for thread startup and kernel syscalls */
56 int request_fd
; /* fd for sending server requests */
57 int reply_fd
; /* fd for receiving server replies */
58 int wait_fd
[2]; /* fd for sleeping server requests */
59 pthread_t pthread_id
; /* pthread thread id */
60 struct list entry
; /* entry in TEB list */
61 PRTL_THREAD_START_ROUTINE start
; /* thread entry point */
62 void *param
; /* thread entry point parameter */
63 void *jmp_buf; /* setjmp buffer for exception handling */
66 C_ASSERT( sizeof(struct ntdll_thread_data
) <= sizeof(((TEB
*)0)->GdiTebBatch
) );
68 static inline struct ntdll_thread_data
*ntdll_get_thread_data(void)
70 return (struct ntdll_thread_data
*)&NtCurrentTeb()->GdiTebBatch
;
73 typedef NTSTATUS
async_callback_t( void *user
, ULONG_PTR
*info
, NTSTATUS status
);
77 async_callback_t
*callback
;
78 struct async_fileio
*next
;
82 static const SIZE_T page_size
= 0x1000;
83 static const SIZE_T teb_size
= 0x3800; /* TEB64 + TEB32 + debug info */
84 static const SIZE_T signal_stack_mask
= 0xffff;
85 static const SIZE_T signal_stack_size
= 0x10000 - 0x3800;
86 static const SIZE_T kernel_stack_size
= 0x20000;
87 static const LONG teb_offset
= 0x2000;
89 #define FILE_WRITE_TO_END_OF_FILE ((LONGLONG)-1)
90 #define FILE_USE_FILE_POINTER_POSITION ((LONGLONG)-2)
92 /* callbacks to PE ntdll from the Unix side */
93 extern void (WINAPI
*pDbgUiRemoteBreakin
)( void *arg
) DECLSPEC_HIDDEN
;
94 extern NTSTATUS (WINAPI
*pKiRaiseUserExceptionDispatcher
)(void) DECLSPEC_HIDDEN
;
95 extern void (WINAPI
*pKiUserApcDispatcher
)(CONTEXT
*,ULONG_PTR
,ULONG_PTR
,ULONG_PTR
,PNTAPCFUNC
) DECLSPEC_HIDDEN
;
96 extern NTSTATUS (WINAPI
*pKiUserExceptionDispatcher
)(EXCEPTION_RECORD
*,CONTEXT
*) DECLSPEC_HIDDEN
;
97 extern void (WINAPI
*pLdrInitializeThunk
)(CONTEXT
*,void**,ULONG_PTR
,ULONG_PTR
) DECLSPEC_HIDDEN
;
98 extern void (WINAPI
*pRtlUserThreadStart
)( PRTL_THREAD_START_ROUTINE entry
, void *arg
) DECLSPEC_HIDDEN
;
99 extern void (WINAPI
*p__wine_ctrl_routine
)(void *) DECLSPEC_HIDDEN
;
100 extern SYSTEM_DLL_INIT_BLOCK
*pLdrSystemDllInitBlock DECLSPEC_HIDDEN
;
102 extern NTSTATUS CDECL
fast_RtlpWaitForCriticalSection( RTL_CRITICAL_SECTION
*crit
, int timeout
) DECLSPEC_HIDDEN
;
103 extern NTSTATUS CDECL
fast_RtlpUnWaitCriticalSection( RTL_CRITICAL_SECTION
*crit
) DECLSPEC_HIDDEN
;
104 extern NTSTATUS CDECL
fast_RtlDeleteCriticalSection( RTL_CRITICAL_SECTION
*crit
) DECLSPEC_HIDDEN
;
105 extern NTSTATUS CDECL
fast_RtlTryAcquireSRWLockExclusive( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
106 extern NTSTATUS CDECL
fast_RtlAcquireSRWLockExclusive( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
107 extern NTSTATUS CDECL
fast_RtlTryAcquireSRWLockShared( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
108 extern NTSTATUS CDECL
fast_RtlAcquireSRWLockShared( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
109 extern NTSTATUS CDECL
fast_RtlReleaseSRWLockExclusive( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
110 extern NTSTATUS CDECL
fast_RtlReleaseSRWLockShared( RTL_SRWLOCK
*lock
) DECLSPEC_HIDDEN
;
111 extern NTSTATUS CDECL
fast_RtlWakeConditionVariable( RTL_CONDITION_VARIABLE
*variable
, int count
) DECLSPEC_HIDDEN
;
112 extern LONGLONG CDECL
fast_RtlGetSystemTimePrecise(void) DECLSPEC_HIDDEN
;
113 extern NTSTATUS CDECL
fast_wait_cv( RTL_CONDITION_VARIABLE
*variable
, const void *value
,
114 const LARGE_INTEGER
*timeout
) DECLSPEC_HIDDEN
;
116 extern NTSTATUS CDECL
unwind_builtin_dll( ULONG type
, struct _DISPATCHER_CONTEXT
*dispatch
,
117 CONTEXT
*context
) DECLSPEC_HIDDEN
;
119 extern const char wine_build
[] DECLSPEC_HIDDEN
;
121 extern const char *home_dir DECLSPEC_HIDDEN
;
122 extern const char *data_dir DECLSPEC_HIDDEN
;
123 extern const char *build_dir DECLSPEC_HIDDEN
;
124 extern const char *config_dir DECLSPEC_HIDDEN
;
125 extern const char *user_name DECLSPEC_HIDDEN
;
126 extern const char **dll_paths DECLSPEC_HIDDEN
;
127 extern PEB
*peb DECLSPEC_HIDDEN
;
128 extern USHORT
*uctable DECLSPEC_HIDDEN
;
129 extern USHORT
*lctable DECLSPEC_HIDDEN
;
130 extern SIZE_T startup_info_size DECLSPEC_HIDDEN
;
131 extern BOOL is_prefix_bootstrap DECLSPEC_HIDDEN
;
132 extern SECTION_IMAGE_INFORMATION main_image_info DECLSPEC_HIDDEN
;
133 extern int main_argc DECLSPEC_HIDDEN
;
134 extern char **main_argv DECLSPEC_HIDDEN
;
135 extern char **main_envp DECLSPEC_HIDDEN
;
136 extern WCHAR
**main_wargv DECLSPEC_HIDDEN
;
137 extern const WCHAR system_dir
[] DECLSPEC_HIDDEN
;
138 extern unsigned int supported_machines_count DECLSPEC_HIDDEN
;
139 extern USHORT supported_machines
[8] DECLSPEC_HIDDEN
;
140 extern BOOL process_exiting DECLSPEC_HIDDEN
;
141 extern HANDLE keyed_event DECLSPEC_HIDDEN
;
142 extern timeout_t server_start_time DECLSPEC_HIDDEN
;
143 extern sigset_t server_block_set DECLSPEC_HIDDEN
;
144 extern struct _KUSER_SHARED_DATA
*user_shared_data DECLSPEC_HIDDEN
;
145 extern SYSTEM_CPU_INFORMATION cpu_info DECLSPEC_HIDDEN
;
147 extern BOOL is_wow64 DECLSPEC_HIDDEN
;
150 extern struct ldt_copy __wine_ldt_copy DECLSPEC_HIDDEN
;
153 extern void init_environment( int argc
, char *argv
[], char *envp
[] ) DECLSPEC_HIDDEN
;
154 extern void init_startup_info(void) DECLSPEC_HIDDEN
;
155 extern void *create_startup_info( const UNICODE_STRING
*nt_image
, const RTL_USER_PROCESS_PARAMETERS
*params
,
156 DWORD
*info_size
) DECLSPEC_HIDDEN
;
157 extern char **build_envp( const WCHAR
*envW
) DECLSPEC_HIDDEN
;
158 extern NTSTATUS
exec_wineloader( char **argv
, int socketfd
, const pe_image_info_t
*pe_info
) DECLSPEC_HIDDEN
;
159 extern NTSTATUS
load_builtin( const pe_image_info_t
*image_info
, WCHAR
*filename
,
160 void **addr_ptr
, SIZE_T
*size_ptr
) DECLSPEC_HIDDEN
;
161 extern BOOL
is_builtin_path( const UNICODE_STRING
*path
, WORD
*machine
) DECLSPEC_HIDDEN
;
162 extern NTSTATUS
load_main_exe( const WCHAR
*name
, const char *unix_name
, const WCHAR
*curdir
, WCHAR
**image
,
163 void **module
) DECLSPEC_HIDDEN
;
164 extern NTSTATUS
load_start_exe( WCHAR
**image
, void **module
) DECLSPEC_HIDDEN
;
165 extern NTSTATUS
get_builtin_init_funcs( void *handle
, void **funcs
, SIZE_T len
, SIZE_T
*retlen
) DECLSPEC_HIDDEN
;
166 extern void start_server( BOOL debug
) DECLSPEC_HIDDEN
;
168 extern unsigned int server_call_unlocked( void *req_ptr
) DECLSPEC_HIDDEN
;
169 extern void server_enter_uninterrupted_section( pthread_mutex_t
*mutex
, sigset_t
*sigset
) DECLSPEC_HIDDEN
;
170 extern void server_leave_uninterrupted_section( pthread_mutex_t
*mutex
, sigset_t
*sigset
) DECLSPEC_HIDDEN
;
171 extern unsigned int server_select( const select_op_t
*select_op
, data_size_t size
, UINT flags
,
172 timeout_t abs_timeout
, context_t
*context
, pthread_mutex_t
*mutex
,
173 user_apc_t
*user_apc
) DECLSPEC_HIDDEN
;
174 extern unsigned int server_wait( const select_op_t
*select_op
, data_size_t size
, UINT flags
,
175 const LARGE_INTEGER
*timeout
) DECLSPEC_HIDDEN
;
176 extern unsigned int server_queue_process_apc( HANDLE process
, const apc_call_t
*call
,
177 apc_result_t
*result
) DECLSPEC_HIDDEN
;
178 extern int server_get_unix_fd( HANDLE handle
, unsigned int wanted_access
, int *unix_fd
,
179 int *needs_close
, enum server_fd_type
*type
, unsigned int *options
) DECLSPEC_HIDDEN
;
180 extern void wine_server_send_fd( int fd
) DECLSPEC_HIDDEN
;
181 extern void process_exit_wrapper( int status
) DECLSPEC_HIDDEN
;
182 extern size_t server_init_process(void) DECLSPEC_HIDDEN
;
183 extern void server_init_process_done(void) DECLSPEC_HIDDEN
;
184 extern void server_init_thread( void *entry_point
, BOOL
*suspend
) DECLSPEC_HIDDEN
;
185 extern int server_pipe( int fd
[2] ) DECLSPEC_HIDDEN
;
187 extern void fpux_to_fpu( I386_FLOATING_SAVE_AREA
*fpu
, const XSAVE_FORMAT
*fpux
) DECLSPEC_HIDDEN
;
188 extern void fpu_to_fpux( XSAVE_FORMAT
*fpux
, const I386_FLOATING_SAVE_AREA
*fpu
) DECLSPEC_HIDDEN
;
189 extern void *get_cpu_area( USHORT machine
) DECLSPEC_HIDDEN
;
190 extern void set_thread_id( TEB
*teb
, DWORD pid
, DWORD tid
) DECLSPEC_HIDDEN
;
191 extern NTSTATUS
init_thread_stack( TEB
*teb
, ULONG_PTR zero_bits
, SIZE_T reserve_size
, SIZE_T commit_size
) DECLSPEC_HIDDEN
;
192 extern void DECLSPEC_NORETURN
abort_thread( int status
) DECLSPEC_HIDDEN
;
193 extern void DECLSPEC_NORETURN
abort_process( int status
) DECLSPEC_HIDDEN
;
194 extern void DECLSPEC_NORETURN
exit_process( int status
) DECLSPEC_HIDDEN
;
195 extern void wait_suspend( CONTEXT
*context
) DECLSPEC_HIDDEN
;
196 extern NTSTATUS
send_debug_event( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
) DECLSPEC_HIDDEN
;
197 extern NTSTATUS
set_thread_context( HANDLE handle
, const void *context
, BOOL
*self
, USHORT machine
) DECLSPEC_HIDDEN
;
198 extern NTSTATUS
get_thread_context( HANDLE handle
, void *context
, BOOL
*self
, USHORT machine
) DECLSPEC_HIDDEN
;
199 extern NTSTATUS
alloc_object_attributes( const OBJECT_ATTRIBUTES
*attr
, struct object_attributes
**ret
,
200 data_size_t
*ret_len
) DECLSPEC_HIDDEN
;
202 extern void *anon_mmap_fixed( void *start
, size_t size
, int prot
, int flags
) DECLSPEC_HIDDEN
;
203 extern void *anon_mmap_alloc( size_t size
, int prot
) DECLSPEC_HIDDEN
;
204 extern void virtual_init(void) DECLSPEC_HIDDEN
;
205 extern ULONG_PTR
get_system_affinity_mask(void) DECLSPEC_HIDDEN
;
206 extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION
*info
, BOOL wow64
) DECLSPEC_HIDDEN
;
207 extern NTSTATUS
virtual_map_builtin_module( HANDLE mapping
, void **module
, SIZE_T
*size
,
208 SECTION_IMAGE_INFORMATION
*info
, WORD machine
, BOOL prefer_native
) DECLSPEC_HIDDEN
;
209 extern NTSTATUS
virtual_create_builtin_view( void *module
, const UNICODE_STRING
*nt_name
,
210 pe_image_info_t
*info
, void *so_handle
) DECLSPEC_HIDDEN
;
211 extern TEB
*virtual_alloc_first_teb(void) DECLSPEC_HIDDEN
;
212 extern NTSTATUS
virtual_alloc_teb( TEB
**ret_teb
) DECLSPEC_HIDDEN
;
213 extern void virtual_free_teb( TEB
*teb
) DECLSPEC_HIDDEN
;
214 extern NTSTATUS
virtual_clear_tls_index( ULONG index
) DECLSPEC_HIDDEN
;
215 extern NTSTATUS
virtual_alloc_thread_stack( INITIAL_TEB
*stack
, ULONG_PTR zero_bits
, SIZE_T reserve_size
,
216 SIZE_T commit_size
, SIZE_T extra_size
) DECLSPEC_HIDDEN
;
217 extern void virtual_map_user_shared_data(void) DECLSPEC_HIDDEN
;
218 extern NTSTATUS
virtual_handle_fault( void *addr
, DWORD err
, void *stack
) DECLSPEC_HIDDEN
;
219 extern unsigned int virtual_locked_server_call( void *req_ptr
) DECLSPEC_HIDDEN
;
220 extern ssize_t
virtual_locked_read( int fd
, void *addr
, size_t size
) DECLSPEC_HIDDEN
;
221 extern ssize_t
virtual_locked_pread( int fd
, void *addr
, size_t size
, off_t offset
) DECLSPEC_HIDDEN
;
222 extern ssize_t
virtual_locked_recvmsg( int fd
, struct msghdr
*hdr
, int flags
) DECLSPEC_HIDDEN
;
223 extern BOOL
virtual_is_valid_code_address( const void *addr
, SIZE_T size
) DECLSPEC_HIDDEN
;
224 extern void *virtual_setup_exception( void *stack_ptr
, size_t size
, EXCEPTION_RECORD
*rec
) DECLSPEC_HIDDEN
;
225 extern BOOL
virtual_check_buffer_for_read( const void *ptr
, SIZE_T size
) DECLSPEC_HIDDEN
;
226 extern BOOL
virtual_check_buffer_for_write( void *ptr
, SIZE_T size
) DECLSPEC_HIDDEN
;
227 extern SIZE_T
virtual_uninterrupted_read_memory( const void *addr
, void *buffer
, SIZE_T size
) DECLSPEC_HIDDEN
;
228 extern NTSTATUS
virtual_uninterrupted_write_memory( void *addr
, const void *buffer
, SIZE_T size
) DECLSPEC_HIDDEN
;
229 extern void virtual_set_force_exec( BOOL enable
) DECLSPEC_HIDDEN
;
230 extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN
;
231 extern void virtual_fill_image_information( const pe_image_info_t
*pe_info
,
232 SECTION_IMAGE_INFORMATION
*info
) DECLSPEC_HIDDEN
;
233 extern void *get_builtin_so_handle( void *module
) DECLSPEC_HIDDEN
;
234 extern NTSTATUS
get_builtin_unix_info( void *module
, const char **name
, void **handle
, void **entry
) DECLSPEC_HIDDEN
;
235 extern NTSTATUS
set_builtin_unix_handle( void *module
, const char *name
, void *handle
) DECLSPEC_HIDDEN
;
236 extern NTSTATUS
set_builtin_unix_entry( void *module
, void *entry
) DECLSPEC_HIDDEN
;
238 extern NTSTATUS
get_thread_ldt_entry( HANDLE handle
, void *data
, ULONG len
, ULONG
*ret_len
) DECLSPEC_HIDDEN
;
239 extern void *get_native_context( CONTEXT
*context
) DECLSPEC_HIDDEN
;
240 extern void *get_wow_context( CONTEXT
*context
) DECLSPEC_HIDDEN
;
241 extern BOOL
get_thread_times( int unix_pid
, int unix_tid
, LARGE_INTEGER
*kernel_time
,
242 LARGE_INTEGER
*user_time
) DECLSPEC_HIDDEN
;
243 extern void signal_init_threading(void) DECLSPEC_HIDDEN
;
244 extern NTSTATUS
signal_alloc_thread( TEB
*teb
) DECLSPEC_HIDDEN
;
245 extern void signal_free_thread( TEB
*teb
) DECLSPEC_HIDDEN
;
246 extern void signal_init_thread( TEB
*teb
) DECLSPEC_HIDDEN
;
247 extern void signal_init_process(void) DECLSPEC_HIDDEN
;
248 extern void DECLSPEC_NORETURN
signal_start_thread( PRTL_THREAD_START_ROUTINE entry
, void *arg
,
249 BOOL suspend
, TEB
*teb
) DECLSPEC_HIDDEN
;
250 extern void DECLSPEC_NORETURN
signal_exit_thread( int status
, void (*func
)(int), TEB
*teb
) DECLSPEC_HIDDEN
;
251 extern void __wine_syscall_dispatcher(void) DECLSPEC_HIDDEN
;
252 extern void WINAPI DECLSPEC_NORETURN
__wine_syscall_dispatcher_return( void *frame
, ULONG_PTR retval
) DECLSPEC_HIDDEN
;
253 extern unsigned int __wine_syscall_flags DECLSPEC_HIDDEN
;
254 extern NTSTATUS
signal_set_full_context( CONTEXT
*context
) DECLSPEC_HIDDEN
;
255 extern NTSTATUS
get_thread_wow64_context( HANDLE handle
, void *ctx
, ULONG size
) DECLSPEC_HIDDEN
;
256 extern NTSTATUS
set_thread_wow64_context( HANDLE handle
, const void *ctx
, ULONG size
) DECLSPEC_HIDDEN
;
257 extern void fill_vm_counters( VM_COUNTERS_EX
*pvmi
, int unix_pid
) DECLSPEC_HIDDEN
;
258 extern NTSTATUS
open_hkcu_key( const char *path
, HANDLE
*key
) DECLSPEC_HIDDEN
;
260 extern NTSTATUS
cdrom_DeviceIoControl( HANDLE device
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
261 IO_STATUS_BLOCK
*io
, ULONG code
, void *in_buffer
,
262 ULONG in_size
, void *out_buffer
, ULONG out_size
) DECLSPEC_HIDDEN
;
263 extern NTSTATUS
serial_DeviceIoControl( HANDLE device
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
264 IO_STATUS_BLOCK
*io
, ULONG code
, void *in_buffer
,
265 ULONG in_size
, void *out_buffer
, ULONG out_size
) DECLSPEC_HIDDEN
;
266 extern NTSTATUS
serial_FlushBuffersFile( int fd
) DECLSPEC_HIDDEN
;
267 extern NTSTATUS
sock_ioctl( HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
, IO_STATUS_BLOCK
*io
,
268 ULONG code
, void *in_buffer
, ULONG in_size
, void *out_buffer
, ULONG out_size
) DECLSPEC_HIDDEN
;
269 extern NTSTATUS
tape_DeviceIoControl( HANDLE device
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
270 IO_STATUS_BLOCK
*io
, ULONG code
, void *in_buffer
,
271 ULONG in_size
, void *out_buffer
, ULONG out_size
) DECLSPEC_HIDDEN
;
273 extern struct async_fileio
*alloc_fileio( DWORD size
, async_callback_t callback
, HANDLE handle
) DECLSPEC_HIDDEN
;
274 extern void release_fileio( struct async_fileio
*io
) DECLSPEC_HIDDEN
;
275 extern NTSTATUS
errno_to_status( int err
) DECLSPEC_HIDDEN
;
276 extern BOOL
get_redirect( OBJECT_ATTRIBUTES
*attr
, UNICODE_STRING
*redir
) DECLSPEC_HIDDEN
;
277 extern NTSTATUS
nt_to_unix_file_name( const OBJECT_ATTRIBUTES
*attr
, char **name_ret
, UINT disposition
) DECLSPEC_HIDDEN
;
278 extern NTSTATUS
unix_to_nt_file_name( const char *name
, WCHAR
**nt
) DECLSPEC_HIDDEN
;
279 extern NTSTATUS
get_full_path( const WCHAR
*name
, const WCHAR
*curdir
, WCHAR
**path
) DECLSPEC_HIDDEN
;
280 extern NTSTATUS
open_unix_file( HANDLE
*handle
, const char *unix_name
, ACCESS_MASK access
,
281 OBJECT_ATTRIBUTES
*attr
, ULONG attributes
, ULONG sharing
, ULONG disposition
,
282 ULONG options
, void *ea_buffer
, ULONG ea_length
) DECLSPEC_HIDDEN
;
283 extern void init_files(void) DECLSPEC_HIDDEN
;
284 extern void init_cpu_info(void) DECLSPEC_HIDDEN
;
285 extern void add_completion( HANDLE handle
, ULONG_PTR value
, NTSTATUS status
, ULONG info
, BOOL async
) DECLSPEC_HIDDEN
;
287 extern void dbg_init(void) DECLSPEC_HIDDEN
;
289 extern NTSTATUS
call_user_apc_dispatcher( CONTEXT
*context_ptr
, ULONG_PTR arg1
, ULONG_PTR arg2
, ULONG_PTR arg3
,
290 PNTAPCFUNC func
, NTSTATUS status
) DECLSPEC_HIDDEN
;
291 extern NTSTATUS
call_user_exception_dispatcher( EXCEPTION_RECORD
*rec
, CONTEXT
*context
) DECLSPEC_HIDDEN
;
292 extern void call_raise_user_exception_dispatcher(void) DECLSPEC_HIDDEN
;
294 #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
296 #define TICKSPERSEC 10000000
297 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)86400)
299 static inline ULONGLONG
ticks_from_time_t( time_t time
)
301 if (sizeof(time_t) == sizeof(int)) /* time_t may be signed */
302 return ((ULONGLONG
)(ULONG
)time
+ SECS_1601_TO_1970
) * TICKSPERSEC
;
304 return ((ULONGLONG
)time
+ SECS_1601_TO_1970
) * TICKSPERSEC
;
307 static inline const char *debugstr_us( const UNICODE_STRING
*us
)
309 if (!us
) return "<null>";
310 return debugstr_wn( us
->Buffer
, us
->Length
/ sizeof(WCHAR
) );
313 /* convert from straight ASCII to Unicode without depending on the current codepage */
314 static inline void ascii_to_unicode( WCHAR
*dst
, const char *src
, size_t len
)
316 while (len
--) *dst
++ = (unsigned char)*src
++;
319 static inline void *get_signal_stack(void)
321 return (void *)(((ULONG_PTR
)NtCurrentTeb() & ~signal_stack_mask
) + teb_size
);
324 static inline BOOL
is_inside_signal_stack( void *ptr
)
326 return ((char *)ptr
>= (char *)get_signal_stack() &&
327 (char *)ptr
< (char *)get_signal_stack() + signal_stack_size
);
330 static inline void mutex_lock( pthread_mutex_t
*mutex
)
332 if (!process_exiting
) pthread_mutex_lock( mutex
);
335 static inline void mutex_unlock( pthread_mutex_t
*mutex
)
337 if (!process_exiting
) pthread_mutex_unlock( mutex
);
340 static inline async_data_t
server_async( HANDLE handle
, struct async_fileio
*user
, HANDLE event
,
341 PIO_APC_ROUTINE apc
, void *apc_context
, client_ptr_t iosb
)
344 async
.handle
= wine_server_obj_handle( handle
);
345 async
.user
= wine_server_client_ptr( user
);
347 async
.event
= wine_server_obj_handle( event
);
348 async
.apc
= wine_server_client_ptr( apc
);
349 async
.apc_context
= wine_server_client_ptr( apc_context
);
353 static inline NTSTATUS
wait_async( HANDLE handle
, BOOL alertable
)
355 return NtWaitForSingleObject( handle
, alertable
, NULL
);
358 static inline void set_async_iosb( client_ptr_t iosb
, NTSTATUS status
, ULONG_PTR info
)
362 if (NtCurrentTeb()->WowTebOffset
)
368 } *io
= wine_server_get_ptr( iosb
);
370 io
->Information
= info
;
375 IO_STATUS_BLOCK
*io
= wine_server_get_ptr( iosb
);
376 #ifdef NONAMELESSUNION
377 io
->u
.Status
= status
;
381 io
->Information
= info
;
385 static inline client_ptr_t
iosb_client_ptr( IO_STATUS_BLOCK
*io
)
388 #ifdef NONAMELESSUNION
389 if (io
&& NtCurrentTeb()->WowTebOffset
) return wine_server_client_ptr( io
->u
.Pointer
);
391 if (io
&& NtCurrentTeb()->WowTebOffset
) return wine_server_client_ptr( io
->Pointer
);
394 return wine_server_client_ptr( io
);
398 typedef TEB32 WOW_TEB
;
399 static inline TEB64
*NtCurrentTeb64(void) { return NULL
; }
401 typedef TEB64 WOW_TEB
;
402 static inline TEB64
*NtCurrentTeb64(void) { return (TEB64
*)NtCurrentTeb()->GdiBatchCount
; }
405 static inline WOW_TEB
*get_wow_teb( TEB
*teb
)
407 return teb
->WowTebOffset
? (WOW_TEB
*)((char *)teb
+ teb
->WowTebOffset
) : NULL
;
416 LO_NATIVE_BUILTIN
, /* native then builtin */
417 LO_BUILTIN_NATIVE
, /* builtin then native */
418 LO_DEFAULT
/* nothing specified, use default strategy */
421 extern void set_load_order_app_name( const WCHAR
*app_name
) DECLSPEC_HIDDEN
;
422 extern enum loadorder
get_load_order( const UNICODE_STRING
*nt_name
) DECLSPEC_HIDDEN
;
424 static inline size_t ntdll_wcslen( const WCHAR
*str
)
426 const WCHAR
*s
= str
;
431 static inline WCHAR
*ntdll_wcscpy( WCHAR
*dst
, const WCHAR
*src
)
434 while ((*p
++ = *src
++));
438 static inline WCHAR
*ntdll_wcscat( WCHAR
*dst
, const WCHAR
*src
)
440 ntdll_wcscpy( dst
+ ntdll_wcslen(dst
), src
);
444 static inline int ntdll_wcscmp( const WCHAR
*str1
, const WCHAR
*str2
)
446 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
447 return *str1
- *str2
;
450 static inline int ntdll_wcsncmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
452 if (n
<= 0) return 0;
453 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
454 return *str1
- *str2
;
457 static inline WCHAR
*ntdll_wcschr( const WCHAR
*str
, WCHAR ch
)
459 do { if (*str
== ch
) return (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
463 static inline WCHAR
*ntdll_wcsrchr( const WCHAR
*str
, WCHAR ch
)
466 do { if (*str
== ch
) ret
= (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
470 static inline WCHAR
*ntdll_wcspbrk( const WCHAR
*str
, const WCHAR
*accept
)
472 for ( ; *str
; str
++) if (ntdll_wcschr( accept
, *str
)) return (WCHAR
*)(ULONG_PTR
)str
;
476 static inline SIZE_T
ntdll_wcsspn( const WCHAR
*str
, const WCHAR
*accept
)
479 for (ptr
= str
; *ptr
; ptr
++) if (!ntdll_wcschr( accept
, *ptr
)) break;
483 static inline SIZE_T
ntdll_wcscspn( const WCHAR
*str
, const WCHAR
*reject
)
486 for (ptr
= str
; *ptr
; ptr
++) if (ntdll_wcschr( reject
, *ptr
)) break;
490 static inline WCHAR
ntdll_towupper( WCHAR ch
)
492 return ch
+ uctable
[uctable
[uctable
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0x0f)];
495 static inline WCHAR
ntdll_towlower( WCHAR ch
)
497 return ch
+ lctable
[lctable
[lctable
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0x0f)];
500 static inline WCHAR
*ntdll_wcsupr( WCHAR
*str
)
503 for (ret
= str
; *str
; str
++) *str
= ntdll_towupper(*str
);
507 static inline int ntdll_wcsicmp( const WCHAR
*str1
, const WCHAR
*str2
)
512 if ((ret
= ntdll_towupper( *str1
) - ntdll_towupper( *str2
)) || !*str1
) return ret
;
518 static inline int ntdll_wcsnicmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
521 for (ret
= 0; n
> 0; n
--, str1
++, str2
++)
522 if ((ret
= ntdll_towupper(*str1
) - ntdll_towupper(*str2
)) || !*str1
) break;
526 #define wcslen(str) ntdll_wcslen(str)
527 #define wcscpy(dst,src) ntdll_wcscpy(dst,src)
528 #define wcscat(dst,src) ntdll_wcscat(dst,src)
529 #define wcscmp(s1,s2) ntdll_wcscmp(s1,s2)
530 #define wcsncmp(s1,s2,n) ntdll_wcsncmp(s1,s2,n)
531 #define wcschr(str,ch) ntdll_wcschr(str,ch)
532 #define wcsrchr(str,ch) ntdll_wcsrchr(str,ch)
533 #define wcspbrk(str,ac) ntdll_wcspbrk(str,ac)
534 #define wcsspn(str,ac) ntdll_wcsspn(str,ac)
535 #define wcscspn(str,rej) ntdll_wcscspn(str,rej)
536 #define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2)
537 #define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n)
538 #define wcsupr(str) ntdll_wcsupr(str)
539 #define towupper(c) ntdll_towupper(c)
540 #define towlower(c) ntdll_towlower(c)
542 static inline void init_unicode_string( UNICODE_STRING
*str
, const WCHAR
*data
)
544 str
->Length
= wcslen(data
) * sizeof(WCHAR
);
545 str
->MaximumLength
= str
->Length
+ sizeof(WCHAR
);
546 str
->Buffer
= (WCHAR
*)data
;
549 #endif /* __NTDLL_UNIX_PRIVATE_H */