ntdll: Block async signals during process init and thread creation.
[wine] / dlls / ntdll / ntdll_misc.h
1 /*
2  * Copyright 2000 Juergen Schmied
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #ifndef __WINE_NTDLL_MISC_H
20 #define __WINE_NTDLL_MISC_H
21
22 #include <stdarg.h>
23 #include <signal.h>
24
25 #include "windef.h"
26 #include "winnt.h"
27 #include "winternl.h"
28 #include "winioctl.h"
29 #include "wine/server.h"
30
31 #define MAX_NT_PATH_LENGTH 277
32
33 /* exceptions */
34 extern void wait_suspend( CONTEXT *context );
35 extern void WINAPI __regs_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT );
36 extern void get_cpu_context( CONTEXT *context );
37 extern void set_cpu_context( const CONTEXT *context );
38
39 /* debug helper */
40 extern LPCSTR debugstr_us( const UNICODE_STRING *str );
41 extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes);
42
43 extern void NTDLL_get_server_abstime( abs_time_t *when, const LARGE_INTEGER *timeout );
44 extern void NTDLL_from_server_abstime( LARGE_INTEGER *time, const abs_time_t *when );
45 extern NTSTATUS NTDLL_queue_process_apc( HANDLE process, const apc_call_t *call, apc_result_t *result );
46 extern NTSTATUS NTDLL_wait_for_multiple_objects( UINT count, const HANDLE *handles, UINT flags,
47                                                  const LARGE_INTEGER *timeout, HANDLE signal_object );
48
49 /* init routines */
50 extern BOOL SIGNAL_Init(void);
51 extern size_t get_signal_stack_total_size(void);
52 extern void version_init( const WCHAR *appname );
53 extern void debug_init(void);
54 extern HANDLE thread_init(void);
55 extern void virtual_init(void);
56 extern void virtual_init_threading(void);
57
58 /* server support */
59 extern abs_time_t server_start_time;
60 extern void server_init_process(void);
61 extern NTSTATUS server_init_process_done(void);
62 extern size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point );
63 extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... );
64 extern void DECLSPEC_NORETURN server_protocol_perror( const char *err );
65 extern void DECLSPEC_NORETURN server_exit_thread( int status );
66 extern void DECLSPEC_NORETURN server_abort_thread( int status );
67 extern sigset_t server_block_set;
68 extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset );
69 extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset );
70 extern int server_remove_fd_from_cache( obj_handle_t handle );
71 extern int server_get_unix_fd( obj_handle_t handle, unsigned int access, int *unix_fd,
72                                int *needs_close, enum server_fd_type *type, int *flags );
73
74 /* module handling */
75 extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved );
76 extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
77                                      DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user );
78 extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
79                                      FARPROC origfun, DWORD ordinal, const WCHAR *user );
80 extern void RELAY_SetupDLL( HMODULE hmod );
81 extern void SNOOP_SetupDLL( HMODULE hmod );
82 extern UNICODE_STRING system_dir;
83
84 /* redefine these to make sure we don't reference kernel symbols */
85 #define GetProcessHeap()       (NtCurrentTeb()->Peb->ProcessHeap)
86 #define GetCurrentProcessId()  ((DWORD)NtCurrentTeb()->ClientId.UniqueProcess)
87 #define GetCurrentThreadId()   ((DWORD)NtCurrentTeb()->ClientId.UniqueThread)
88
89 /* Device IO */
90 extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice, 
91                                       HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
92                                       PVOID UserApcContext, 
93                                       PIO_STATUS_BLOCK piosb, 
94                                       ULONG IoControlCode,
95                                       LPVOID lpInBuffer, DWORD nInBufferSize,
96                                       LPVOID lpOutBuffer, DWORD nOutBufferSize);
97 extern NTSTATUS COMM_DeviceIoControl(HANDLE hDevice, 
98                                      HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
99                                      PVOID UserApcContext, 
100                                      PIO_STATUS_BLOCK piosb, 
101                                      ULONG IoControlCode,
102                                      LPVOID lpInBuffer, DWORD nInBufferSize,
103                                      LPVOID lpOutBuffer, DWORD nOutBufferSize);
104 extern NTSTATUS TAPE_DeviceIoControl(HANDLE hDevice, 
105                                      HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
106                                      PVOID UserApcContext, 
107                                      PIO_STATUS_BLOCK piosb, 
108                                      ULONG IoControlCode,
109                                      LPVOID lpInBuffer, DWORD nInBufferSize,
110                                      LPVOID lpOutBuffer, DWORD nOutBufferSize);
111
112 /* file I/O */
113 extern NTSTATUS FILE_GetNtStatus(void);
114 extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name );
115 extern NTSTATUS DIR_unmount_device( HANDLE handle );
116 extern NTSTATUS DIR_get_unix_cwd( char **cwd );
117
118 /* virtual memory */
119 extern NTSTATUS VIRTUAL_HandleFault(LPCVOID addr);
120 extern void VIRTUAL_SetForceExec( BOOL enable );
121 extern void VIRTUAL_UseLargeAddressSpace(void);
122
123 extern BOOL is_current_process( HANDLE handle );
124
125 /* code pages */
126 extern int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen);
127 extern int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
128                            const char* defchar, int *used );
129
130 /* load order */
131
132 enum loadorder
133 {
134     LO_INVALID,
135     LO_DISABLED,
136     LO_NATIVE,
137     LO_BUILTIN,
138     LO_NATIVE_BUILTIN,  /* native then builtin */
139     LO_BUILTIN_NATIVE,  /* builtin then native */
140     LO_DEFAULT          /* nothing specified, use default strategy */
141 };
142
143 extern enum loadorder get_load_order( const WCHAR *app_name, const WCHAR *path );
144
145 struct debug_info
146 {
147     char *str_pos;       /* current position in strings buffer */
148     char *out_pos;       /* current position in output buffer */
149     char  strings[1024]; /* buffer for temporary strings */
150     char  output[1024];  /* current output line */
151 };
152
153 struct ntdll_thread_data
154 {
155     struct debug_info *debug_info;    /* info for debugstr functions */
156     int                request_fd;    /* fd for sending server requests */
157     int                reply_fd;      /* fd for receiving server replies */
158     int                wait_fd[2];    /* fd for sleeping server requests */
159     void              *vm86_ptr;      /* data for vm86 mode */
160
161     void              *pad[4];        /* change this if you add fields! */
162 };
163
164 static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
165 {
166     return (struct ntdll_thread_data *)NtCurrentTeb()->SystemReserved2;
167 }
168
169 /* thread registers, stored in NtCurrentTeb()->SpareBytes1 */
170 struct ntdll_thread_regs
171 {
172     DWORD              fs;            /* 00 TEB selector */
173     DWORD              gs;            /* 04 libc selector; update winebuild if you move this! */
174     DWORD              dr0;           /* 08 debug registers */
175     DWORD              dr1;           /* 0c */
176     DWORD              dr2;           /* 10 */
177     DWORD              dr3;           /* 14 */
178     DWORD              dr6;           /* 18 */
179     DWORD              dr7;           /* 1c */
180     DWORD              spare[2];      /* 20 change this if you add fields! */
181 };
182
183 static inline struct ntdll_thread_regs *ntdll_get_thread_regs(void)
184 {
185     return (struct ntdll_thread_regs *)NtCurrentTeb()->SpareBytes1;
186 }
187
188 #endif