ntdll: Set the initial environment and command line in the process parameters on...
[wine.git] / dlls / ntdll / unix / unix_private.h
blob3970cd334483eb360dd1e60550d21a3a344d5c46
1 /*
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
24 #include <pthread.h>
25 #include <signal.h>
26 #include "unixlib.h"
27 #include "wine/list.h"
29 #ifdef __i386__
30 static const enum cpu_type client_cpu = CPU_x86;
31 #elif defined(__x86_64__)
32 static const enum cpu_type client_cpu = CPU_x86_64;
33 #elif defined(__arm__)
34 static const enum cpu_type client_cpu = CPU_ARM;
35 #elif defined(__aarch64__)
36 static const enum cpu_type client_cpu = CPU_ARM64;
37 #endif
39 struct debug_info
41 unsigned int str_pos; /* current position in strings buffer */
42 unsigned int out_pos; /* current position in output buffer */
43 char strings[1024]; /* buffer for temporary strings */
44 char output[1024]; /* current output line */
47 /* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
48 struct ntdll_thread_data
50 void *cpu_data[16]; /* reserved for CPU-specific data */
51 struct debug_info *debug_info; /* info for debugstr functions */
52 void *start_stack; /* stack for thread startup */
53 int request_fd; /* fd for sending server requests */
54 int reply_fd; /* fd for receiving server replies */
55 int wait_fd[2]; /* fd for sleeping server requests */
56 pthread_t pthread_id; /* pthread thread id */
57 struct list entry; /* entry in TEB list */
58 PRTL_THREAD_START_ROUTINE start; /* thread entry point */
59 void *param; /* thread entry point parameter */
62 C_ASSERT( sizeof(struct ntdll_thread_data) <= sizeof(((TEB *)0)->GdiTebBatch) );
64 static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
66 return (struct ntdll_thread_data *)&NtCurrentTeb()->GdiTebBatch;
69 static const SIZE_T page_size = 0x1000;
70 static const SIZE_T signal_stack_mask = 0xffff;
71 #ifdef _WIN64
72 static const SIZE_T teb_size = 0x2000;
73 static const SIZE_T teb_offset = 0;
74 static const SIZE_T signal_stack_size = 0x10000 - 0x2000;
75 #else
76 static const SIZE_T teb_size = 0x3000; /* TEB64 + TEB */
77 static const SIZE_T teb_offset = 0x2000;
78 static const SIZE_T signal_stack_size = 0x10000 - 0x3000;
79 #endif
81 /* callbacks to PE ntdll from the Unix side */
82 extern void (WINAPI *pDbgUiRemoteBreakin)( void *arg ) DECLSPEC_HIDDEN;
83 extern NTSTATUS (WINAPI *pKiRaiseUserExceptionDispatcher)(void) DECLSPEC_HIDDEN;
84 extern void (WINAPI *pKiUserApcDispatcher)(CONTEXT*,ULONG_PTR,ULONG_PTR,ULONG_PTR,PNTAPCFUNC) DECLSPEC_HIDDEN;
85 extern NTSTATUS (WINAPI *pKiUserExceptionDispatcher)(EXCEPTION_RECORD*,CONTEXT*) DECLSPEC_HIDDEN;
86 extern void (WINAPI *pLdrInitializeThunk)(CONTEXT*,void**,ULONG_PTR,ULONG_PTR) DECLSPEC_HIDDEN;
87 extern void (WINAPI *pRtlUserThreadStart)( PRTL_THREAD_START_ROUTINE entry, void *arg ) DECLSPEC_HIDDEN;
88 extern NTSTATUS CDECL fast_RtlpWaitForCriticalSection( RTL_CRITICAL_SECTION *crit, int timeout ) DECLSPEC_HIDDEN;
89 extern NTSTATUS CDECL fast_RtlpUnWaitCriticalSection( RTL_CRITICAL_SECTION *crit ) DECLSPEC_HIDDEN;
90 extern NTSTATUS CDECL fast_RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit ) DECLSPEC_HIDDEN;
91 extern NTSTATUS CDECL fast_RtlTryAcquireSRWLockExclusive( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
92 extern NTSTATUS CDECL fast_RtlAcquireSRWLockExclusive( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
93 extern NTSTATUS CDECL fast_RtlTryAcquireSRWLockShared( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
94 extern NTSTATUS CDECL fast_RtlAcquireSRWLockShared( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
95 extern NTSTATUS CDECL fast_RtlReleaseSRWLockExclusive( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
96 extern NTSTATUS CDECL fast_RtlReleaseSRWLockShared( RTL_SRWLOCK *lock ) DECLSPEC_HIDDEN;
97 extern NTSTATUS CDECL fast_RtlWakeConditionVariable( RTL_CONDITION_VARIABLE *variable, int count ) DECLSPEC_HIDDEN;
98 extern LONGLONG CDECL fast_RtlGetSystemTimePrecise(void) DECLSPEC_HIDDEN;
99 extern NTSTATUS CDECL fast_wait_cv( RTL_CONDITION_VARIABLE *variable, const void *value,
100 const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;
102 extern NTSTATUS CDECL get_dynamic_environment( WCHAR *env, SIZE_T *size ) DECLSPEC_HIDDEN;
103 extern USHORT * CDECL get_unix_codepage_data(void) DECLSPEC_HIDDEN;
104 extern void CDECL get_locales( WCHAR *sys, WCHAR *user ) DECLSPEC_HIDDEN;
105 extern void CDECL virtual_release_address_space(void) DECLSPEC_HIDDEN;
107 extern NTSTATUS CDECL unwind_builtin_dll( ULONG type, struct _DISPATCHER_CONTEXT *dispatch,
108 CONTEXT *context ) DECLSPEC_HIDDEN;
110 extern void CDECL set_show_dot_files( BOOL enable ) DECLSPEC_HIDDEN;
112 extern const char *home_dir DECLSPEC_HIDDEN;
113 extern const char *data_dir DECLSPEC_HIDDEN;
114 extern const char *build_dir DECLSPEC_HIDDEN;
115 extern const char *config_dir DECLSPEC_HIDDEN;
116 extern const char *user_name DECLSPEC_HIDDEN;
117 extern const char **dll_paths DECLSPEC_HIDDEN;
118 extern USHORT *uctable DECLSPEC_HIDDEN;
119 extern USHORT *lctable DECLSPEC_HIDDEN;
120 extern SIZE_T startup_info_size DECLSPEC_HIDDEN;
121 extern int main_argc DECLSPEC_HIDDEN;
122 extern char **main_argv DECLSPEC_HIDDEN;
123 extern char **main_envp DECLSPEC_HIDDEN;
124 extern WCHAR **main_wargv DECLSPEC_HIDDEN;
125 extern unsigned int server_cpus DECLSPEC_HIDDEN;
126 extern BOOL is_wow64 DECLSPEC_HIDDEN;
127 extern BOOL process_exiting DECLSPEC_HIDDEN;
128 extern HANDLE keyed_event DECLSPEC_HIDDEN;
129 extern timeout_t server_start_time DECLSPEC_HIDDEN;
130 extern sigset_t server_block_set DECLSPEC_HIDDEN;
131 extern struct _KUSER_SHARED_DATA *user_shared_data DECLSPEC_HIDDEN;
132 #ifdef __i386__
133 extern struct ldt_copy __wine_ldt_copy DECLSPEC_HIDDEN;
134 #endif
136 extern void init_environment( int argc, char *argv[], char *envp[] ) DECLSPEC_HIDDEN;
137 extern void init_startup_info(void) DECLSPEC_HIDDEN;
138 extern DWORD ntdll_umbstowcs( const char *src, DWORD srclen, WCHAR *dst, DWORD dstlen ) DECLSPEC_HIDDEN;
139 extern int ntdll_wcstoumbs( const WCHAR *src, DWORD srclen, char *dst, DWORD dstlen, BOOL strict ) DECLSPEC_HIDDEN;
140 extern char **build_envp( const WCHAR *envW ) DECLSPEC_HIDDEN;
141 extern NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_info ) DECLSPEC_HIDDEN;
142 extern void start_server( BOOL debug ) DECLSPEC_HIDDEN;
143 extern ULONG_PTR get_image_address(void) DECLSPEC_HIDDEN;
145 extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
146 extern void server_enter_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
147 extern void server_leave_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
148 extern unsigned int server_select( const select_op_t *select_op, data_size_t size, UINT flags,
149 timeout_t abs_timeout, CONTEXT *context, pthread_mutex_t *mutex,
150 user_apc_t *user_apc ) DECLSPEC_HIDDEN;
151 extern unsigned int server_wait( const select_op_t *select_op, data_size_t size, UINT flags,
152 const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;
153 extern unsigned int server_queue_process_apc( HANDLE process, const apc_call_t *call,
154 apc_result_t *result ) DECLSPEC_HIDDEN;
155 extern int server_get_unix_fd( HANDLE handle, unsigned int wanted_access, int *unix_fd,
156 int *needs_close, enum server_fd_type *type, unsigned int *options ) DECLSPEC_HIDDEN;
157 extern size_t server_init_process(void) DECLSPEC_HIDDEN;
158 extern void server_init_process_done(void) DECLSPEC_HIDDEN;
159 extern void server_init_thread( void *entry_point, BOOL *suspend ) DECLSPEC_HIDDEN;
160 extern int server_pipe( int fd[2] ) DECLSPEC_HIDDEN;
162 extern NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) DECLSPEC_HIDDEN;
163 extern NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) DECLSPEC_HIDDEN;
164 extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;
165 extern void DECLSPEC_NORETURN abort_process( int status ) DECLSPEC_HIDDEN;
166 extern void DECLSPEC_NORETURN exit_process( int status ) DECLSPEC_HIDDEN;
167 extern void wait_suspend( CONTEXT *context ) DECLSPEC_HIDDEN;
168 extern NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance ) DECLSPEC_HIDDEN;
169 extern NTSTATUS set_thread_context( HANDLE handle, const context_t *context, BOOL *self ) DECLSPEC_HIDDEN;
170 extern NTSTATUS get_thread_context( HANDLE handle, context_t *context, unsigned int flags, BOOL *self ) DECLSPEC_HIDDEN;
171 extern NTSTATUS alloc_object_attributes( const OBJECT_ATTRIBUTES *attr, struct object_attributes **ret,
172 data_size_t *ret_len ) DECLSPEC_HIDDEN;
174 extern void *anon_mmap_fixed( void *start, size_t size, int prot, int flags ) DECLSPEC_HIDDEN;
175 extern void *anon_mmap_alloc( size_t size, int prot ) DECLSPEC_HIDDEN;
176 extern void virtual_init(void) DECLSPEC_HIDDEN;
177 extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
178 extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info ) DECLSPEC_HIDDEN;
179 extern NTSTATUS virtual_create_builtin_view( void *module, const UNICODE_STRING *nt_name,
180 pe_image_info_t *info ) DECLSPEC_HIDDEN;
181 extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN;
182 extern NTSTATUS virtual_alloc_teb( TEB **ret_teb ) DECLSPEC_HIDDEN;
183 extern void virtual_free_teb( TEB *teb ) DECLSPEC_HIDDEN;
184 extern NTSTATUS virtual_clear_tls_index( ULONG index ) DECLSPEC_HIDDEN;
185 extern NTSTATUS virtual_alloc_thread_stack( INITIAL_TEB *stack, SIZE_T reserve_size, SIZE_T commit_size,
186 SIZE_T *pthread_size ) DECLSPEC_HIDDEN;
187 extern void virtual_map_user_shared_data(void) DECLSPEC_HIDDEN;
188 extern NTSTATUS virtual_handle_fault( void *addr, DWORD err, void *stack ) DECLSPEC_HIDDEN;
189 extern unsigned int virtual_locked_server_call( void *req_ptr ) DECLSPEC_HIDDEN;
190 extern ssize_t virtual_locked_read( int fd, void *addr, size_t size ) DECLSPEC_HIDDEN;
191 extern ssize_t virtual_locked_pread( int fd, void *addr, size_t size, off_t offset ) DECLSPEC_HIDDEN;
192 extern BOOL virtual_is_valid_code_address( const void *addr, SIZE_T size ) DECLSPEC_HIDDEN;
193 extern void *virtual_setup_exception( void *stack_ptr, size_t size, EXCEPTION_RECORD *rec ) DECLSPEC_HIDDEN;
194 extern BOOL virtual_check_buffer_for_read( const void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
195 extern BOOL virtual_check_buffer_for_write( void *ptr, SIZE_T size ) DECLSPEC_HIDDEN;
196 extern SIZE_T virtual_uninterrupted_read_memory( const void *addr, void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
197 extern NTSTATUS virtual_uninterrupted_write_memory( void *addr, const void *buffer, SIZE_T size ) DECLSPEC_HIDDEN;
198 extern void virtual_set_force_exec( BOOL enable ) DECLSPEC_HIDDEN;
199 extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
200 extern void virtual_fill_image_information( const pe_image_info_t *pe_info,
201 SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
203 extern NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN;
204 extern BOOL get_thread_times( int unix_pid, int unix_tid, LARGE_INTEGER *kernel_time,
205 LARGE_INTEGER *user_time ) DECLSPEC_HIDDEN;
206 extern void signal_init_threading(void) DECLSPEC_HIDDEN;
207 extern NTSTATUS signal_alloc_thread( TEB *teb ) DECLSPEC_HIDDEN;
208 extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN;
209 extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN;
210 extern void signal_init_process(void) DECLSPEC_HIDDEN;
211 extern void DECLSPEC_NORETURN signal_start_thread( PRTL_THREAD_START_ROUTINE entry, void *arg,
212 BOOL suspend, void *thunk, TEB *teb ) DECLSPEC_HIDDEN;
213 extern void DECLSPEC_NORETURN signal_exit_thread( int status, void (*func)(int) ) DECLSPEC_HIDDEN;
214 extern void DECLSPEC_NORETURN exec_process( NTSTATUS status ) DECLSPEC_HIDDEN;
215 extern void __wine_syscall_dispatcher(void) DECLSPEC_HIDDEN;
216 extern void fill_vm_counters( VM_COUNTERS_EX *pvmi, int unix_pid ) DECLSPEC_HIDDEN;
218 extern NTSTATUS cdrom_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
219 IO_STATUS_BLOCK *io, ULONG code, void *in_buffer,
220 ULONG in_size, void *out_buffer, ULONG out_size ) DECLSPEC_HIDDEN;
221 extern NTSTATUS serial_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
222 IO_STATUS_BLOCK *io, ULONG code, void *in_buffer,
223 ULONG in_size, void *out_buffer, ULONG out_size ) DECLSPEC_HIDDEN;
224 extern NTSTATUS serial_FlushBuffersFile( int fd ) DECLSPEC_HIDDEN;
225 extern NTSTATUS tape_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE apc, void *apc_user,
226 IO_STATUS_BLOCK *io, ULONG code, void *in_buffer,
227 ULONG in_size, void *out_buffer, ULONG out_size ) DECLSPEC_HIDDEN;
229 extern NTSTATUS errno_to_status( int err ) DECLSPEC_HIDDEN;
230 extern NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret,
231 UNICODE_STRING *nt_name, UINT disposition ) DECLSPEC_HIDDEN;
232 extern NTSTATUS unix_to_nt_file_name( const char *name, WCHAR **nt ) DECLSPEC_HIDDEN;
233 extern NTSTATUS open_unix_file( HANDLE *handle, const char *unix_name, ACCESS_MASK access,
234 OBJECT_ATTRIBUTES *attr, ULONG attributes, ULONG sharing, ULONG disposition,
235 ULONG options, void *ea_buffer, ULONG ea_length ) DECLSPEC_HIDDEN;
236 extern void init_files(void) DECLSPEC_HIDDEN;
237 extern void init_cpu_info(void) DECLSPEC_HIDDEN;
239 extern void dbg_init(void) DECLSPEC_HIDDEN;
241 extern void WINAPI DECLSPEC_NORETURN call_user_apc_dispatcher( CONTEXT *context_ptr, ULONG_PTR ctx,
242 ULONG_PTR arg1, ULONG_PTR arg2,
243 PNTAPCFUNC func,
244 void (WINAPI *dispatcher)(CONTEXT*,ULONG_PTR,ULONG_PTR,ULONG_PTR,PNTAPCFUNC) ) DECLSPEC_HIDDEN;
245 extern void WINAPI DECLSPEC_NORETURN call_user_exception_dispatcher( EXCEPTION_RECORD *rec, CONTEXT *context,
246 NTSTATUS (WINAPI *dispatcher)(EXCEPTION_RECORD*,CONTEXT*) ) DECLSPEC_HIDDEN;
247 extern void WINAPI DECLSPEC_NORETURN call_raise_user_exception_dispatcher( NTSTATUS (WINAPI *dispatcher)(void) ) DECLSPEC_HIDDEN;
249 extern void *get_syscall_frame(void) DECLSPEC_HIDDEN;
250 extern void set_syscall_frame(void *frame) DECLSPEC_HIDDEN;
252 #define TICKSPERSEC 10000000
253 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)86400)
255 static inline ULONGLONG ticks_from_time_t( time_t time )
257 if (sizeof(time_t) == sizeof(int)) /* time_t may be signed */
258 return ((ULONGLONG)(ULONG)time + SECS_1601_TO_1970) * TICKSPERSEC;
259 else
260 return ((ULONGLONG)time + SECS_1601_TO_1970) * TICKSPERSEC;
263 static inline const char *debugstr_us( const UNICODE_STRING *us )
265 if (!us) return "<null>";
266 return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
269 /* convert from straight ASCII to Unicode without depending on the current codepage */
270 static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
272 while (len--) *dst++ = (unsigned char)*src++;
275 static inline IMAGE_NT_HEADERS *get_exe_nt_header(void)
277 IMAGE_DOS_HEADER *module = (IMAGE_DOS_HEADER *)NtCurrentTeb()->Peb->ImageBaseAddress;
278 return (IMAGE_NT_HEADERS *)((char *)module + module->e_lfanew);
281 static inline void *get_signal_stack(void)
283 return (char *)NtCurrentTeb() + teb_size - teb_offset;
286 static inline void mutex_lock( pthread_mutex_t *mutex )
288 if (!process_exiting) pthread_mutex_lock( mutex );
291 static inline void mutex_unlock( pthread_mutex_t *mutex )
293 if (!process_exiting) pthread_mutex_unlock( mutex );
296 #ifndef _WIN64
297 static inline TEB64 *NtCurrentTeb64(void) { return (TEB64 *)NtCurrentTeb()->GdiBatchCount; }
298 #endif
300 struct xcontext
302 CONTEXT c;
303 CONTEXT_EX c_ex;
304 ULONG64 host_compaction_mask;
307 #if defined(__i386__) || defined(__x86_64__)
308 static inline XSTATE *xstate_from_context( const CONTEXT *context )
310 CONTEXT_EX *xctx = (CONTEXT_EX *)(context + 1);
312 if ((context->ContextFlags & CONTEXT_XSTATE) != CONTEXT_XSTATE)
313 return NULL;
315 return (XSTATE *)((char *)(context + 1) + xctx->XState.Offset);
318 static inline void context_init_xstate( CONTEXT *context, void *xstate_buffer )
320 CONTEXT_EX *xctx;
322 xctx = (CONTEXT_EX *)(context + 1);
323 xctx->Legacy.Length = sizeof(CONTEXT);
324 xctx->Legacy.Offset = -(LONG)sizeof(CONTEXT);
326 xctx->XState.Length = sizeof(XSTATE);
327 xctx->XState.Offset = (BYTE *)xstate_buffer - (BYTE *)xctx;
329 xctx->All.Length = sizeof(CONTEXT) + xctx->XState.Offset + xctx->XState.Length;
330 xctx->All.Offset = -(LONG)sizeof(CONTEXT);
331 context->ContextFlags |= 0x40;
334 static inline void xstate_to_server( context_t *to, const XSTATE *xs )
336 if (!xs)
337 return;
339 to->flags |= SERVER_CTX_YMM_REGISTERS;
340 if (xs->Mask & 4)
341 memcpy(&to->ymm.ymm_high_regs.ymm_high, &xs->YmmContext, sizeof(xs->YmmContext));
342 else
343 memset(&to->ymm.ymm_high_regs.ymm_high, 0, sizeof(xs->YmmContext));
346 static inline void xstate_from_server_( XSTATE *xs, const context_t *from, BOOL compaction_enabled)
348 if (!xs)
349 return;
351 xs->Mask = 0;
352 xs->CompactionMask = compaction_enabled ? 0x8000000000000004 : 0;
354 if (from->flags & SERVER_CTX_YMM_REGISTERS)
356 unsigned long *src = (unsigned long *)&from->ymm.ymm_high_regs.ymm_high;
357 unsigned int i;
359 for (i = 0; i < sizeof(xs->YmmContext) / sizeof(unsigned long); ++i)
360 if (src[i])
362 memcpy( &xs->YmmContext, &from->ymm.ymm_high_regs.ymm_high, sizeof(xs->YmmContext) );
363 xs->Mask = 4;
364 break;
368 #define xstate_from_server( xs, from ) xstate_from_server_( xs, from, user_shared_data->XState.CompactionEnabled )
370 #else
371 static inline XSTATE *xstate_from_context( const CONTEXT *context )
373 return NULL;
375 static inline void context_init_xstate( CONTEXT *context, void *xstate_buffer )
378 #endif
380 static inline size_t ntdll_wcslen( const WCHAR *str )
382 const WCHAR *s = str;
383 while (*s) s++;
384 return s - str;
387 static inline WCHAR *ntdll_wcscpy( WCHAR *dst, const WCHAR *src )
389 WCHAR *p = dst;
390 while ((*p++ = *src++));
391 return dst;
394 static inline WCHAR *ntdll_wcscat( WCHAR *dst, const WCHAR *src )
396 ntdll_wcscpy( dst + ntdll_wcslen(dst), src );
397 return dst;
400 static inline int ntdll_wcscmp( const WCHAR *str1, const WCHAR *str2 )
402 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
403 return *str1 - *str2;
406 static inline int ntdll_wcsncmp( const WCHAR *str1, const WCHAR *str2, int n )
408 if (n <= 0) return 0;
409 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
410 return *str1 - *str2;
413 static inline WCHAR *ntdll_wcschr( const WCHAR *str, WCHAR ch )
415 do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
416 return NULL;
419 static inline WCHAR *ntdll_wcsrchr( const WCHAR *str, WCHAR ch )
421 WCHAR *ret = NULL;
422 do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
423 return ret;
426 static inline WCHAR *ntdll_wcspbrk( const WCHAR *str, const WCHAR *accept )
428 for ( ; *str; str++) if (ntdll_wcschr( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
429 return NULL;
432 static inline WCHAR ntdll_towupper( WCHAR ch )
434 return ch + uctable[uctable[uctable[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0x0f)];
437 static inline WCHAR ntdll_towlower( WCHAR ch )
439 return ch + lctable[lctable[lctable[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0x0f)];
442 static inline WCHAR *ntdll_wcsupr( WCHAR *str )
444 WCHAR *ret;
445 for (ret = str; *str; str++) *str = ntdll_towupper(*str);
446 return ret;
449 static inline int ntdll_wcsicmp( const WCHAR *str1, const WCHAR *str2 )
451 int ret;
452 for (;;)
454 if ((ret = ntdll_towupper( *str1 ) - ntdll_towupper( *str2 )) || !*str1) return ret;
455 str1++;
456 str2++;
460 static inline int ntdll_wcsnicmp( const WCHAR *str1, const WCHAR *str2, int n )
462 int ret;
463 for (ret = 0; n > 0; n--, str1++, str2++)
464 if ((ret = ntdll_towupper(*str1) - ntdll_towupper(*str2)) || !*str1) break;
465 return ret;
468 #define wcslen(str) ntdll_wcslen(str)
469 #define wcscpy(dst,src) ntdll_wcscpy(dst,src)
470 #define wcscat(dst,src) ntdll_wcscat(dst,src)
471 #define wcscmp(s1,s2) ntdll_wcscmp(s1,s2)
472 #define wcsncmp(s1,s2,n) ntdll_wcsncmp(s1,s2,n)
473 #define wcschr(str,ch) ntdll_wcschr(str,ch)
474 #define wcsrchr(str,ch) ntdll_wcsrchr(str,ch)
475 #define wcspbrk(str,ac) ntdll_wcspbrk(str,ac)
476 #define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2)
477 #define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n)
478 #define wcsupr(str) ntdll_wcsupr(str)
479 #define towupper(c) ntdll_towupper(c)
480 #define towlower(c) ntdll_towlower(c)
482 #endif /* __NTDLL_UNIX_PRIVATE_H */