ntdll: Update the TEB and PEB structures for newer Windows versions.
[wine.git] / dlls / ntdll / ntdll_misc.h
blob47107f2f2e80b9c340c403550f423f67bdc896a3
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 <sys/types.h>
25 #include "windef.h"
26 #include "winnt.h"
27 #include "winternl.h"
28 #include "unixlib.h"
29 #include "wine/server.h"
30 #include "wine/asm.h"
32 #define DECLARE_CRITICAL_SECTION(cs) \
33 static RTL_CRITICAL_SECTION cs; \
34 static RTL_CRITICAL_SECTION_DEBUG cs##_debug = \
35 { 0, 0, &cs, { &cs##_debug.ProcessLocksList, &cs##_debug.ProcessLocksList }, \
36 0, 0, { (DWORD_PTR)(__FILE__ ": " # cs) }}; \
37 static RTL_CRITICAL_SECTION cs = { &cs##_debug, -1, 0, 0, 0, 0 };
39 #define MAX_NT_PATH_LENGTH 277
41 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
42 static const UINT_PTR page_size = 0x1000;
43 #else
44 extern UINT_PTR page_size DECLSPEC_HIDDEN;
45 #endif
47 /* exceptions */
48 extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) DECLSPEC_HIDDEN;
49 extern void DECLSPEC_NORETURN raise_status( NTSTATUS status, EXCEPTION_RECORD *rec ) DECLSPEC_HIDDEN;
50 extern LONG WINAPI call_unhandled_exception_filter( PEXCEPTION_POINTERS eptr ) DECLSPEC_HIDDEN;
52 #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
53 extern RUNTIME_FUNCTION *lookup_function_info( ULONG_PTR pc, ULONG_PTR *base, LDR_DATA_TABLE_ENTRY **module ) DECLSPEC_HIDDEN;
54 #endif
56 /* debug helpers */
57 extern LPCSTR debugstr_us( const UNICODE_STRING *str ) DECLSPEC_HIDDEN;
59 /* init routines */
60 extern void version_init(void) DECLSPEC_HIDDEN;
61 extern void debug_init(void) DECLSPEC_HIDDEN;
62 extern void actctx_init(void) DECLSPEC_HIDDEN;
63 extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN;
64 extern void init_unix_codepage(void) DECLSPEC_HIDDEN;
65 extern void init_locale( HMODULE module ) DECLSPEC_HIDDEN;
66 extern void init_user_process_params(void) DECLSPEC_HIDDEN;
67 extern NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) DECLSPEC_HIDDEN;
69 /* server support */
70 extern BOOL is_wow64 DECLSPEC_HIDDEN;
72 /* module handling */
73 extern LIST_ENTRY tls_links DECLSPEC_HIDDEN;
74 extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
75 DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
76 extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
77 FARPROC origfun, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
78 extern void RELAY_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
79 extern void SNOOP_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
80 extern const WCHAR windows_dir[] DECLSPEC_HIDDEN;
81 extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
82 extern const WCHAR syswow64_dir[] DECLSPEC_HIDDEN;
84 extern const struct unix_funcs *unix_funcs DECLSPEC_HIDDEN;
86 extern void init_directories(void) DECLSPEC_HIDDEN;
88 extern struct _KUSER_SHARED_DATA *user_shared_data DECLSPEC_HIDDEN;
90 /* locale */
91 extern LCID user_lcid, system_lcid;
92 extern DWORD ntdll_umbstowcs( const char* src, DWORD srclen, WCHAR* dst, DWORD dstlen ) DECLSPEC_HIDDEN;
93 extern int ntdll_wcstoumbs( const WCHAR* src, DWORD srclen, char* dst, DWORD dstlen, BOOL strict ) DECLSPEC_HIDDEN;
95 extern int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_list args ) DECLSPEC_HIDDEN;
96 extern int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args ) DECLSPEC_HIDDEN;
98 /* load order */
100 enum loadorder
102 LO_INVALID,
103 LO_DISABLED,
104 LO_NATIVE,
105 LO_BUILTIN,
106 LO_NATIVE_BUILTIN, /* native then builtin */
107 LO_BUILTIN_NATIVE, /* builtin then native */
108 LO_DEFAULT /* nothing specified, use default strategy */
111 extern enum loadorder get_load_order( const WCHAR *app_name, const UNICODE_STRING *nt_name ) DECLSPEC_HIDDEN;
113 /* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
114 struct ntdll_thread_data
116 void *cpu_data[16]; /* reserved for CPU-specific data */
117 struct debug_info *debug_info; /* info for debugstr functions */
118 void *start_stack; /* stack for thread startup */
119 int request_fd; /* fd for sending server requests */
120 int reply_fd; /* fd for receiving server replies */
121 int wait_fd[2]; /* fd for sleeping server requests */
122 BOOL wow64_redir; /* Wow64 filesystem redirection flag */
125 C_ASSERT( sizeof(struct ntdll_thread_data) <= sizeof(((TEB *)0)->GdiTebBatch) );
127 static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
129 return (struct ntdll_thread_data *)&NtCurrentTeb()->GdiTebBatch;
132 #define HASH_STRING_ALGORITHM_DEFAULT 0
133 #define HASH_STRING_ALGORITHM_X65599 1
134 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
136 NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
137 void WINAPI LdrInitializeThunk(CONTEXT*,void**,ULONG_PTR,ULONG_PTR);
139 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
140 #define InterlockedCompareExchange64(dest,xchg,cmp) RtlInterlockedCompareExchange64(dest,xchg,cmp)
141 #endif
143 /* convert from straight ASCII to Unicode without depending on the current codepage */
144 static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
146 while (len--) *dst++ = (unsigned char)*src++;
149 #endif