ntdll_misc.h 7.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2000 Juergen Schmied
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 20 21
#ifndef __WINE_NTDLL_MISC_H
#define __WINE_NTDLL_MISC_H

22 23 24
#include <stdarg.h>

#include "windef.h"
25
#include "winnt.h"
26
#include "winternl.h"
27
#include "winioctl.h"
28
#include "wine/server.h"
29

30 31
#define MAX_NT_PATH_LENGTH 277

32 33
/* exceptions */
extern void wait_suspend( CONTEXT *context );
34
extern void WINAPI __regs_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT );
35
extern void get_cpu_context( CONTEXT *context );
36
extern void set_cpu_context( const CONTEXT *context );
37

38
/* debug helper */
39
extern LPCSTR debugstr_us( const UNICODE_STRING *str );
40
extern void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *ObjectAttributes);
41

42 43
extern void NTDLL_get_server_abstime( abs_time_t *when, const LARGE_INTEGER *timeout );
extern void NTDLL_from_server_abstime( LARGE_INTEGER *time, const abs_time_t *when );
44
extern NTSTATUS NTDLL_wait_for_multiple_objects( UINT count, const HANDLE *handles, UINT flags,
45
                                                 const LARGE_INTEGER *timeout, HANDLE signal_object );
46 47

/* init routines */
48
extern BOOL SIGNAL_Init(void);
49
extern size_t get_signal_stack_total_size(void);
50
extern void version_init( const WCHAR *appname );
51
extern void debug_init(void);
52
extern HANDLE thread_init(void);
53 54
extern void virtual_init(void);
extern void virtual_init_threading(void);
55

56
/* server support */
57
extern abs_time_t server_start_time;
58
extern void server_init_process(void);
59
extern size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point );
60 61
extern void DECLSPEC_NORETURN server_protocol_error( const char *err, ... );
extern void DECLSPEC_NORETURN server_protocol_perror( const char *err );
62
extern void DECLSPEC_NORETURN server_exit_thread( int status );
63 64
extern void DECLSPEC_NORETURN server_abort_thread( int status );

65
/* module handling */
66
extern NTSTATUS MODULE_DllThreadAttach( LPVOID lpReserved );
Eric Pouech's avatar
Eric Pouech committed
67
extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
68
                                     DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user );
Eric Pouech's avatar
Eric Pouech committed
69
extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
70
                                     FARPROC origfun, DWORD ordinal, const WCHAR *user );
71
extern void RELAY_SetupDLL( HMODULE hmod );
72
extern void SNOOP_SetupDLL( HMODULE hmod );
73
extern UNICODE_STRING system_dir;
74

75 76 77 78
/* redefine these to make sure we don't reference kernel symbols */
#define GetProcessHeap()       (NtCurrentTeb()->Peb->ProcessHeap)
#define GetCurrentProcessId()  ((DWORD)NtCurrentTeb()->ClientId.UniqueProcess)
#define GetCurrentThreadId()   ((DWORD)NtCurrentTeb()->ClientId.UniqueThread)
79

80
/* Device IO */
81
extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice, 
82 83 84 85 86 87
                                      HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
                                      PVOID UserApcContext, 
                                      PIO_STATUS_BLOCK piosb, 
                                      ULONG IoControlCode,
                                      LPVOID lpInBuffer, DWORD nInBufferSize,
                                      LPVOID lpOutBuffer, DWORD nOutBufferSize);
88 89 90 91 92 93 94
extern NTSTATUS COMM_DeviceIoControl(HANDLE hDevice, 
                                     HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
                                     PVOID UserApcContext, 
                                     PIO_STATUS_BLOCK piosb, 
                                     ULONG IoControlCode,
                                     LPVOID lpInBuffer, DWORD nInBufferSize,
                                     LPVOID lpOutBuffer, DWORD nOutBufferSize);
95 96 97 98 99 100 101
extern NTSTATUS TAPE_DeviceIoControl(HANDLE hDevice, 
                                     HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
                                     PVOID UserApcContext, 
                                     PIO_STATUS_BLOCK piosb, 
                                     ULONG IoControlCode,
                                     LPVOID lpInBuffer, DWORD nInBufferSize,
                                     LPVOID lpOutBuffer, DWORD nOutBufferSize);
102

103 104
/* file I/O */
extern NTSTATUS FILE_GetNtStatus(void);
105
extern NTSTATUS FILE_GetDeviceInfo( int fd, FILE_FS_DEVICE_INFORMATION *info );
106
extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name );
107
extern NTSTATUS DIR_unmount_device( HANDLE handle );
108
extern NTSTATUS DIR_get_unix_cwd( char **cwd );
109 110

/* virtual memory */
111
extern NTSTATUS VIRTUAL_HandleFault(LPCVOID addr);
112
extern BOOL VIRTUAL_HasMapping( LPCVOID addr );
113
extern void VIRTUAL_UseLargeAddressSpace(void);
114

115 116
extern BOOL is_current_process( HANDLE handle );

117 118 119 120 121
/* code pages */
extern int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen);
extern int ntdll_wcstoumbs(DWORD flags, const WCHAR* src, int srclen, char* dst, int dstlen,
                           const char* defchar, int *used );

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* load order */

enum loadorder
{
    LO_INVALID,
    LO_DISABLED,
    LO_NATIVE,
    LO_BUILTIN,
    LO_NATIVE_BUILTIN,  /* native then builtin */
    LO_BUILTIN_NATIVE,  /* builtin then native */
    LO_DEFAULT          /* nothing specified, use default strategy */
};

extern enum loadorder get_load_order( const WCHAR *app_name, const WCHAR *path );

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
struct debug_info
{
    char *str_pos;       /* current position in strings buffer */
    char *out_pos;       /* current position in output buffer */
    char  strings[1024]; /* buffer for temporary strings */
    char  output[1024];  /* current output line */
};

struct ntdll_thread_data
{
    struct debug_info *debug_info;    /* info for debugstr functions */
    int                request_fd;    /* fd for sending server requests */
    int                reply_fd;      /* fd for receiving server replies */
    int                wait_fd[2];    /* fd for sleeping server requests */
    void              *vm86_ptr;      /* data for vm86 mode */

153
    void              *pad[4];        /* change this if you add fields! */
154 155 156 157 158 159 160
};

static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
{
    return (struct ntdll_thread_data *)NtCurrentTeb()->SystemReserved2;
}

161 162 163
/* thread registers, stored in NtCurrentTeb()->SpareBytes1 */
struct ntdll_thread_regs
{
164 165 166 167 168 169 170 171 172
    DWORD              fs;            /* 00 TEB selector */
    DWORD              gs;            /* 04 libc selector; update winebuild if you move this! */
    DWORD              dr0;           /* 08 debug registers */
    DWORD              dr1;           /* 0c */
    DWORD              dr2;           /* 10 */
    DWORD              dr3;           /* 14 */
    DWORD              dr6;           /* 18 */
    DWORD              dr7;           /* 1c */
    DWORD              spare[2];      /* 20 change this if you add fields! */
173 174 175 176 177 178 179
};

static inline struct ntdll_thread_regs *ntdll_get_thread_regs(void)
{
    return (struct ntdll_thread_regs *)NtCurrentTeb()->SpareBytes1;
}

180
#endif