diff --git a/files/change.c b/files/change.c index d5fce064920..4142d39b0ee 100644 --- a/files/change.c +++ b/files/change.c @@ -17,12 +17,6 @@ #include "server.h" #include "debug.h" -/* The change notification object */ -typedef struct -{ - K32OBJ header; -} CHANGE_OBJECT; - /**************************************************************************** * FindFirstChangeNotification32A (KERNEL32.248) @@ -31,7 +25,6 @@ HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter ) { - CHANGE_OBJECT *change; struct create_change_notification_request req; struct create_change_notification_reply reply; @@ -39,19 +32,7 @@ HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, req.filter = dwNotifyFilter; CLIENT_SendRequest( REQ_CREATE_CHANGE_NOTIFICATION, -1, 1, &req, sizeof(req) ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle == -1) return INVALID_HANDLE_VALUE; - - change = HeapAlloc( SystemHeap, 0, sizeof(CHANGE_OBJECT) ); - if (!change) - { - CLIENT_CloseHandle( reply.handle ); - return INVALID_HANDLE_VALUE; - } - change->header.type = K32OBJ_CHANGE; - change->header.refcount = 1; - return HANDLE_Alloc( PROCESS_Current(), &change->header, - STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE /*FIXME*/, - FALSE, reply.handle ); + return reply.handle; } /**************************************************************************** @@ -73,9 +54,6 @@ HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, */ BOOL WINAPI FindNextChangeNotification( HANDLE handle ) { - if (HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_FILE, 0 ) == -1) - return FALSE; /* FIXME: do something */ return TRUE; } diff --git a/files/dos_fs.c b/files/dos_fs.c index 2fa8ebcf82e..b88b2cbb279 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -609,9 +609,7 @@ const DOS_DEVICE *DOSFS_GetDeviceByHandle( HFILE hFile ) struct get_file_info_request req; struct get_file_info_reply reply; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return NULL; + req.handle = hFile; CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) ); if (!CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) && (reply.type == FILE_TYPE_UNKNOWN)) diff --git a/files/file.c b/files/file.c index 8e18adb9afd..e0937775db3 100644 --- a/files/file.c +++ b/files/file.c @@ -50,13 +50,6 @@ #define MAP_ANON MAP_ANONYMOUS #endif -/* The file object */ -typedef struct -{ - K32OBJ header; -} FILE_OBJECT; - - /* Size of per-process table of DOS handles */ #define DOS_TABLE_SIZE 256 @@ -309,7 +302,6 @@ void FILE_SetDosError(void) */ HFILE FILE_DupUnixHandle( int fd, DWORD access ) { - FILE_OBJECT *file; int unix_handle; struct create_file_request req; struct create_file_reply reply; @@ -328,18 +320,7 @@ HFILE FILE_DupUnixHandle( int fd, DWORD access ) CLIENT_SendRequest( REQ_CREATE_FILE, unix_handle, 1, &req, sizeof(req) ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle == -1) return INVALID_HANDLE_VALUE; - - if (!(file = HeapAlloc( SystemHeap, 0, sizeof(FILE_OBJECT) ))) - { - CLIENT_CloseHandle( reply.handle ); - SetLastError( ERROR_TOO_MANY_OPEN_FILES ); - return (HFILE)NULL; - } - file->header.type = K32OBJ_FILE; - file->header.refcount = 0; - return HANDLE_Alloc( PROCESS_Current(), &file->header, req.access, - req.inherit, reply.handle ); + return reply.handle; } @@ -352,7 +333,6 @@ HFILE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, LPSECURITY_ATTRIBUTES sa, DWORD creation, DWORD attributes, HANDLE template ) { - FILE_OBJECT *file; struct create_file_request req; struct create_file_reply reply; @@ -382,20 +362,7 @@ HFILE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); } } - if (reply.handle == -1) return INVALID_HANDLE_VALUE; - - /* Now build the FILE_OBJECT */ - - if (!(file = HeapAlloc( SystemHeap, 0, sizeof(FILE_OBJECT) ))) - { - SetLastError( ERROR_OUTOFMEMORY ); - CLIENT_CloseHandle( reply.handle ); - return (HFILE)INVALID_HANDLE_VALUE; - } - file->header.type = K32OBJ_FILE; - file->header.refcount = 0; - return HANDLE_Alloc( PROCESS_Current(), &file->header, req.access, - req.inherit, reply.handle ); + return reply.handle; } @@ -406,7 +373,6 @@ HFILE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, */ HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ) { - FILE_OBJECT *file; struct create_device_request req; struct create_device_reply reply; @@ -415,20 +381,7 @@ HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ) req.id = client_id; CLIENT_SendRequest( REQ_CREATE_DEVICE, -1, 1, &req, sizeof(req) ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle == -1) return INVALID_HANDLE_VALUE; - - /* Now build the FILE_OBJECT */ - - if (!(file = HeapAlloc( SystemHeap, 0, sizeof(FILE_OBJECT) ))) - { - SetLastError( ERROR_OUTOFMEMORY ); - CLIENT_CloseHandle( reply.handle ); - return (HFILE)INVALID_HANDLE_VALUE; - } - file->header.type = K32OBJ_FILE; - file->header.refcount = 0; - return HANDLE_Alloc( PROCESS_Current(), &file->header, req.access, - req.inherit, reply.handle ); + return reply.handle; } @@ -597,9 +550,7 @@ DWORD WINAPI GetFileInformationByHandle( HFILE hFile, struct get_file_info_reply reply; if (!info) return 0; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return 0; + req.handle = hFile; CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0; @@ -1141,9 +1092,7 @@ BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead, if (bytesRead) *bytesRead = 0; /* Do this before anything else */ if (!bytesToRead) return TRUE; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_UNKNOWN, GENERIC_READ )) == -1) - return FALSE; + req.handle = hFile; CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &req, sizeof(req) ); CLIENT_WaitReply( NULL, &unix_handle, 0 ); if (unix_handle == -1) return FALSE; @@ -1175,9 +1124,7 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, if (bytesWritten) *bytesWritten = 0; /* Do this before anything else */ if (!bytesToWrite) return TRUE; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_UNKNOWN, GENERIC_WRITE )) == -1) - return FALSE; + req.handle = hFile; CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &req, sizeof(req) ); CLIENT_WaitReply( NULL, &unix_handle, 0 ); if (unix_handle == -1) return FALSE; @@ -1293,9 +1240,7 @@ DWORD WINAPI SetFilePointer( HFILE hFile, LONG distance, LONG *highword, TRACE(file, "handle %d offset %ld origin %ld\n", hFile, distance, method ); - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return 0xffffffff; + req.handle = hFile; req.low = distance; req.high = highword ? *highword : 0; /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */ @@ -1493,9 +1438,7 @@ BOOL WINAPI FlushFileBuffers( HFILE hFile ) { struct flush_file_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return FALSE; + req.handle = hFile; CLIENT_SendRequest( REQ_FLUSH_FILE, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); } @@ -1508,9 +1451,7 @@ BOOL WINAPI SetEndOfFile( HFILE hFile ) { struct truncate_file_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return FALSE; + req.handle = hFile; CLIENT_SendRequest( REQ_TRUNCATE_FILE, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); } @@ -1667,9 +1608,7 @@ DWORD WINAPI GetFileType( HFILE hFile ) struct get_file_info_request req; struct get_file_info_reply reply; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_UNKNOWN, 0 )) == -1) - return FILE_TYPE_UNKNOWN; + req.handle = hFile; CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FILE_TYPE_UNKNOWN; @@ -1950,9 +1889,7 @@ BOOL WINAPI SetFileTime( HFILE hFile, { struct set_file_time_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, GENERIC_WRITE )) == -1) - return FALSE; + req.handle = hFile; if (lpLastAccessTime) req.access_time = DOSFS_FileTimeToUnixTime(lpLastAccessTime, NULL); else @@ -1975,9 +1912,7 @@ BOOL WINAPI LockFile( HFILE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh { struct lock_file_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return FALSE; + req.handle = hFile; req.offset_low = dwFileOffsetLow; req.offset_high = dwFileOffsetHigh; req.count_low = nNumberOfBytesToLockLow; @@ -1995,9 +1930,7 @@ BOOL WINAPI UnlockFile( HFILE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHi { struct unlock_file_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, 0 )) == -1) - return FALSE; + req.handle = hFile; req.offset_low = dwFileOffsetLow; req.offset_high = dwFileOffsetHigh; req.count_low = nNumberOfBytesToUnlockLow; diff --git a/include/file.h b/include/file.h index 652b9bf8073..41896653717 100644 --- a/include/file.h +++ b/include/file.h @@ -8,7 +8,7 @@ #define __WINE_FILE_H #include /* time_t */ -#include "k32obj.h" +#include "winbase.h" #define MAX_PATHNAME_LEN 1024 diff --git a/include/k32obj.h b/include/k32obj.h deleted file mode 100644 index f9a00d564b5..00000000000 --- a/include/k32obj.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * KERNEL32 objects - * - * Copyright 1996, 1998 Alexandre Julliard - */ - -#ifndef __WINE_K32OBJ_H -#define __WINE_K32OBJ_H - -#include "wintypes.h" -#include "winbase.h" /* SECURITY_ATTRIBUTES */ - -/* Object types */ -typedef enum -{ - K32OBJ_UNKNOWN = 0, - K32OBJ_SEMAPHORE, - K32OBJ_EVENT, - K32OBJ_MUTEX, - K32OBJ_CRITICAL_SECTION, - K32OBJ_PROCESS, - K32OBJ_THREAD, - K32OBJ_FILE, - K32OBJ_CHANGE, - K32OBJ_CONSOLE, - K32OBJ_SCREEN_BUFFER, - K32OBJ_MEM_MAPPED_FILE, - K32OBJ_SERIAL, - K32OBJ_DEVICE_IOCTL, - K32OBJ_PIPE, - K32OBJ_MAILSLOT, - K32OBJ_TOOLHELP_SNAPSHOT, - K32OBJ_SOCKET, - K32OBJ_NBOBJECTS -} K32OBJ_TYPE; - -/* Kernel object */ -typedef struct -{ - K32OBJ_TYPE type; - LONG refcount; -} K32OBJ; - -/* Kernel object operations */ -typedef struct -{ - void (*destroy)(K32OBJ *); /* Destroy object on refcount==0 */ -} K32OBJ_OPS; - -extern const K32OBJ_OPS * const K32OBJ_Ops[K32OBJ_NBOBJECTS]; - -#define K32OBJ_OPS(obj) (K32OBJ_Ops[(obj)->type]) - -extern void K32OBJ_IncCount( K32OBJ *ptr ); -extern void K32OBJ_DecCount( K32OBJ *ptr ); -extern BOOL K32OBJ_IsValid( K32OBJ *ptr, K32OBJ_TYPE type ); -extern BOOL K32OBJ_AddName( K32OBJ *obj, LPCSTR name ); -extern K32OBJ *K32OBJ_Create( K32OBJ_TYPE type, DWORD size, LPCSTR name, - int server_handle, DWORD access, - SECURITY_ATTRIBUTES *sa, HANDLE *handle ); -extern K32OBJ *K32OBJ_FindName( LPCSTR name ); -extern K32OBJ *K32OBJ_FindNameType( LPCSTR name, K32OBJ_TYPE type ); - -#endif /* __WINE_K32OBJ_H */ diff --git a/include/process.h b/include/process.h index 3cacf399873..d203810931e 100644 --- a/include/process.h +++ b/include/process.h @@ -9,26 +9,10 @@ #include "wintypes.h" #include "module.h" -#include "k32obj.h" struct _NE_MODULE; struct _THREAD_ENTRY; -/* Process handle entry */ -typedef struct -{ - DWORD access; /* Access flags */ - K32OBJ *ptr; /* Object ptr */ - int server; /* Server handle (FIXME: tmp hack) */ -} HANDLE_ENTRY; - -/* Process handle table */ -typedef struct -{ - DWORD count; - HANDLE_ENTRY entries[1]; -} HANDLE_TABLE; - /* Current Process pseudo-handle - Returned by GetCurrentProcess*/ #define CURRENT_PROCESS_PSEUDOHANDLE ((HANDLE)0x7fffffff) @@ -39,16 +23,16 @@ typedef struct DWORD unknown1; /* 04 Unknown */ LPSTR cmd_line; /* 08 Command line */ LPSTR cur_dir; /* 0c Current directory */ - STARTUPINFOA *startup_info; /* 10 Startup information */ - HANDLE hStdin; /* 14 Handle for standard input */ - HANDLE hStdout; /* 18 Handle for standard output */ - HANDLE hStderr; /* 1c Handle for standard error */ + STARTUPINFOA *startup_info; /* 10 Startup information */ + HANDLE hStdin; /* 14 Handle for standard input */ + HANDLE hStdout; /* 18 Handle for standard output */ + HANDLE hStderr; /* 1c Handle for standard error */ DWORD unknown2; /* 20 Unknown */ DWORD inherit_console; /* 24 Inherit console flag */ DWORD break_type; /* 28 Console events flag */ - K32OBJ *break_sem; /* 2c SetConsoleCtrlHandler semaphore */ - K32OBJ *break_event; /* 30 SetConsoleCtrlHandler event */ - K32OBJ *break_thread; /* 34 SetConsoleCtrlHandler thread */ + void *break_sem; /* 2c SetConsoleCtrlHandler semaphore */ + void *break_event; /* 30 SetConsoleCtrlHandler event */ + void *break_thread; /* 34 SetConsoleCtrlHandler thread */ void *break_handlers; /* 38 List of console handlers */ /* The following are Wine-specific fields */ CRITICAL_SECTION section; /* 3c Env DB critical section */ @@ -59,9 +43,9 @@ typedef struct /* Win32 process database */ typedef struct _PDB { - K32OBJ header; /* 00 Kernel object header */ + LONG header[2]; /* 00 Kernel object header */ DWORD unknown1; /* 08 Unknown */ - K32OBJ *event; /* 0c Pointer to an event object (unused) */ + void *event; /* 0c Pointer to an event object (unused) */ DWORD exit_code; /* 10 Process exit code */ DWORD unknown2; /* 14 Unknown */ HANDLE heap; /* 18 Default process heap */ @@ -78,7 +62,7 @@ typedef struct _PDB HTASK task; /* 38 Win16 task */ void *mem_map_files; /* 3c Pointer to mem-mapped files */ ENVDB *env_db; /* 40 Environment database */ - HANDLE_TABLE *handle_table; /* 44 Handle table */ + void *handle_table; /* 44 Handle table */ struct _PDB *parent; /* 48 Parent process */ WINE_MODREF *modref_list; /* 4c MODREF list */ void *thread_list; /* 50 List of threads */ @@ -87,7 +71,7 @@ typedef struct _PDB DWORD unknown4; /* 5c Unknown */ CRITICAL_SECTION crit_section; /* 60 Critical section */ DWORD unknown5[3]; /* 78 Unknown */ - K32OBJ *console; /* 84 Console */ + void *console; /* 84 Console */ DWORD tls_bits[2]; /* 88 TLS in-use bits */ DWORD process_dword; /* 90 Unknown */ struct _PDB *group; /* 94 Process group */ @@ -97,7 +81,7 @@ typedef struct _PDB HANDLE heap_list; /* a4 Head of process heap list */ void *heap_handles; /* a8 Head of heap handles list */ DWORD unknown6; /* ac Unknown */ - K32OBJ *console_provider; /* b0 Console provider (??) */ + void *console_provider; /* b0 Console provider (??) */ WORD env_selector; /* b4 Selector to process environment */ WORD error_mode; /* b6 Error mode */ HANDLE load_done_evt; /* b8 Event for process loading done */ @@ -122,21 +106,6 @@ extern BOOL ENV_BuildEnvironment( PDB *pdb ); extern BOOL ENV_InheritEnvironment( PDB *pdb, LPCSTR env ); extern void ENV_FreeEnvironment( PDB *pdb ); -/* scheduler/handle.c */ -extern BOOL HANDLE_CreateTable( PDB *pdb, BOOL inherit ); -extern HANDLE HANDLE_Alloc( PDB *pdb, K32OBJ *ptr, DWORD access, - BOOL inherit, int server_handle ); -extern int HANDLE_GetServerHandle( PDB *pdb, HANDLE handle, - K32OBJ_TYPE type, DWORD access ); -extern void HANDLE_CloseAll( PDB *pdb, K32OBJ *ptr ); - -/* Global handle macros */ -#define HANDLE_OBFUSCATOR ((DWORD)0x544a4def) -#define HANDLE_IS_GLOBAL(h) (((DWORD)(h) ^ HANDLE_OBFUSCATOR) < 0x10000) -#define HANDLE_LOCAL_TO_GLOBAL(h) ((HANDLE)((DWORD)(h) ^ HANDLE_OBFUSCATOR)) -#define HANDLE_GLOBAL_TO_LOCAL(h) ((HANDLE)((DWORD)(h) ^ HANDLE_OBFUSCATOR)) - - /* scheduler/process.c */ extern BOOL PROCESS_Init( void ); extern PDB *PROCESS_Current(void); @@ -147,11 +116,9 @@ extern PDB *PROCESS_Create( struct _NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, HINSTANCE16 hInstance, HINSTANCE16 hPrevInstance, BOOL inherit, STARTUPINFOA *startup, PROCESS_INFORMATION *info ); +extern void PROCESS_FreePDB( PDB *pdb ); extern void PROCESS_SuspendOtherThreads(void); extern void PROCESS_ResumeOtherThreads(void); -extern int PROCESS_PDBList_Getsize (void); -extern PDB* PROCESS_PDBList_Getfirst (void); -extern PDB* PROCESS_PDBList_Getnext (PDB*); #endif /* __WINE_PROCESS_H */ diff --git a/include/thread.h b/include/thread.h index 8c49ff451ae..83ca6fe8a2a 100644 --- a/include/thread.h +++ b/include/thread.h @@ -9,7 +9,6 @@ #include "config.h" #include "winbase.h" -#include "k32obj.h" #include "selectors.h" /* for SET_FS */ #ifdef linux @@ -58,9 +57,9 @@ typedef struct _TEB /* Thread database */ typedef struct _THDB { - K32OBJ header; /* 00 Kernel object header */ - struct _PDB *process; /* 08 Process owning this thread */ - HANDLE event; /* 0c Thread event */ + LONG header[2]; /* 00 Kernel object header */ + struct _PDB *process; /* 08 Process owning this thread */ + HANDLE event; /* 0c Thread event */ TEB teb; /* 10 Thread exception block */ DWORD flags; /* 44 Flags */ DWORD exit_code; /* 48 Termination status */ diff --git a/loader/task.c b/loader/task.c index 32dfc0ff640..8adcb13eebf 100644 --- a/loader/task.c +++ b/loader/task.c @@ -538,8 +538,8 @@ static void TASK_DeleteTask( HTASK16 hTask ) /* Delete the Win32 part of the task */ - K32OBJ_DecCount( &pTask->thdb->process->header ); - K32OBJ_DecCount( &pTask->thdb->header ); +/* PROCESS_FreePDB( pTask->thdb->process ); FIXME */ +/* K32OBJ_DecCount( &pTask->thdb->header ); FIXME */ /* Free the selector aliases */ diff --git a/memory/virtual.c b/memory/virtual.c index 0a9e6b2f1c5..bf43a3d97d6 100644 --- a/memory/virtual.c +++ b/memory/virtual.c @@ -27,12 +27,6 @@ #define MS_SYNC 0 #endif -/* File mapping */ -typedef struct -{ - K32OBJ header; -} FILE_MAPPING; - /* File view */ typedef struct _FV { @@ -1055,40 +1049,9 @@ HANDLE WINAPI CreateFileMappingA( DWORD size_low, /* [in] Low-order 32 bits of object size */ LPCSTR name /* [in] Name of file-mapping object */ ) { - FILE_MAPPING *mapping = NULL; struct create_mapping_request req; - struct create_mapping_reply reply = { -1 }; - HANDLE handle; + struct create_mapping_reply reply; BYTE vprot; - BOOL inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - - /* First search for an object with the same name */ - - K32OBJ *obj = K32OBJ_FindName( name ); - - if (obj) - { - if (obj->type == K32OBJ_MEM_MAPPED_FILE) - { - req.handle = -1; - CLIENT_SendRequest( REQ_CREATE_MAPPING, -1, 2, - &req, sizeof(req), - name, name ? strlen(name) + 1 : 0 ); - CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle == -1) return 0; - if (GetLastError() != ERROR_ALREADY_EXISTS) - return 0; /* not supposed to happen */ - handle = HANDLE_Alloc( PROCESS_Current(), obj, - FILE_MAP_ALL_ACCESS /*FIXME*/, inherit, reply.handle ); - } - else - { - SetLastError( ERROR_DUP_NAME ); - handle = 0; - } - K32OBJ_DecCount( obj ); - return handle; - } /* Check parameters */ @@ -1107,52 +1070,19 @@ HANDLE WINAPI CreateFileMappingA( else vprot |= VPROT_COMMITTED; if (protect & SEC_NOCACHE) vprot |= VPROT_NOCACHE; - /* Compute the size and extend the file if necessary */ - - if (hFile != INVALID_HANDLE_VALUE) /* We have a file */ - { - DWORD access = GENERIC_READ; - - if (((protect & 0xff) == PAGE_READWRITE) || - ((protect & 0xff) == PAGE_WRITECOPY) || - ((protect & 0xff) == PAGE_EXECUTE_READWRITE) || - ((protect & 0xff) == PAGE_EXECUTE_WRITECOPY)) - access |= GENERIC_WRITE; - - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hFile, - K32OBJ_FILE, access )) == -1) goto error; - } - else req.handle = -1; - /* Create the server object */ + req.handle = hFile; req.size_high = size_high; - req.size_low = ROUND_SIZE( 0, size_low ); + req.size_low = size_low; req.protect = vprot; - req.inherit = inherit; + req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); CLIENT_SendRequest( REQ_CREATE_MAPPING, -1, 2, &req, sizeof(req), name, name ? strlen(name) + 1 : 0 ); - if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) - goto error; - - /* Allocate the mapping object */ - - if (!(mapping = HeapAlloc( SystemHeap, 0, sizeof(*mapping) ))) goto error; - mapping->header.type = K32OBJ_MEM_MAPPED_FILE; - mapping->header.refcount = 1; - - if (!K32OBJ_AddName( &mapping->header, name )) handle = 0; - else handle = HANDLE_Alloc( PROCESS_Current(), &mapping->header, - FILE_MAP_ALL_ACCESS /*FIXME*/, inherit, reply.handle ); - K32OBJ_DecCount( &mapping->header ); - SetLastError(0); /* Last error value is relevant. (see the start of fun) */ - return handle; - -error: - if (reply.handle != -1) CLIENT_CloseHandle( reply.handle ); - if (mapping) HeapFree( SystemHeap, 0, mapping ); - return 0; + CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); + if (reply.handle == -1) return 0; + return reply.handle; } @@ -1185,8 +1115,6 @@ HANDLE WINAPI OpenFileMappingA( BOOL inherit, /* [in] Inherit flag */ LPCSTR name ) /* [in] Name of file-mapping object */ { - HANDLE handle = 0; - K32OBJ *obj; struct open_named_obj_request req; struct open_named_obj_reply reply; int len = name ? strlen(name) + 1 : 0; @@ -1196,21 +1124,8 @@ HANDLE WINAPI OpenFileMappingA( req.inherit = inherit; CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - - if (reply.handle != -1) - { - SYSTEM_LOCK(); - if ((obj = K32OBJ_FindNameType( name, K32OBJ_MEM_MAPPED_FILE ))) - { - handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle ); - K32OBJ_DecCount( obj ); - if (handle == INVALID_HANDLE_VALUE) - handle = 0; /* must return 0 on failure, not -1 */ - } - else CLIENT_CloseHandle( reply.handle ); - SYSTEM_UNLOCK(); - } - return handle; + if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */ + return reply.handle; } @@ -1279,8 +1194,7 @@ LPVOID WINAPI MapViewOfFileEx( return NULL; } - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_MEM_MAPPED_FILE, 0 /* FIXME */ ); + req.handle = handle; CLIENT_SendRequest( REQ_GET_MAPPING_INFO, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &info, sizeof(info), &unix_handle )) goto error; diff --git a/misc/toolhelp.c b/misc/toolhelp.c index a04764c0e0e..8541336ac1a 100644 --- a/misc/toolhelp.c +++ b/misc/toolhelp.c @@ -16,17 +16,10 @@ #include "tlhelp32.h" #include "toolhelp.h" #include "heap.h" -#include "k32obj.h" #include "server.h" #include "debug.h" -/* The K32 snapshot object object */ -typedef struct -{ - K32OBJ header; -} SNAPSHOT_OBJECT; - /* FIXME: to make this working, we have to callback all these registered * functions from all over the WINE code. Someone with more knowledge than * me please do that. -Marcus @@ -121,7 +114,6 @@ FARPROC16 tmp; */ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) { - SNAPSHOT_OBJECT *snapshot; struct create_snapshot_request req; struct create_snapshot_reply reply; @@ -133,21 +125,13 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); return INVALID_HANDLE_VALUE; } - /* Now do the snapshot */ - if (!(snapshot = HeapAlloc( SystemHeap, 0, sizeof(*snapshot) ))) - return INVALID_HANDLE_VALUE; - snapshot->header.type = K32OBJ_TOOLHELP_SNAPSHOT; - snapshot->header.refcount = 1; + /* Now do the snapshot */ req.flags = flags & ~TH32CS_INHERIT; req.inherit = (flags & TH32CS_INHERIT) != 0; CLIENT_SendRequest( REQ_CREATE_SNAPSHOT, -1, 1, &req, sizeof(req) ); - if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) - { - HeapFree( SystemHeap, 0, snapshot ); - return INVALID_HANDLE_VALUE; - } - return HANDLE_Alloc( PROCESS_Current(), &snapshot->header, 0, req.inherit, reply.handle ); + CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); + return reply.handle; } @@ -167,9 +151,7 @@ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL fir ERR (toolhelp, "Result buffer too small\n"); return FALSE; } - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_TOOLHELP_SNAPSHOT, 0 )) == -1) - return FALSE; + req.handle = handle; req.reset = first; CLIENT_SendRequest( REQ_NEXT_PROCESS, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; diff --git a/scheduler/Makefile.in b/scheduler/Makefile.in index c21919d2df0..1b1f87b774e 100644 --- a/scheduler/Makefile.in +++ b/scheduler/Makefile.in @@ -10,7 +10,6 @@ C_SRCS = \ critsection.c \ event.c \ handle.c \ - k32obj.c \ mutex.c \ pipe.c \ process.c \ diff --git a/scheduler/client.c b/scheduler/client.c index 94ff2874952..ae9a1c09ad2 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -288,9 +288,9 @@ int CLIENT_NewThread( THDB *thdb, int *thandle, int *phandle ) fcntl( fd[0], F_SETFD, 1 ); /* set close on exec flag */ if (thandle) *thandle = reply.thandle; - else if (reply.thandle != -1) CLIENT_CloseHandle( reply.thandle ); + else if (reply.thandle != -1) CloseHandle( reply.thandle ); if (phandle) *phandle = reply.phandle; - else if (reply.phandle != -1) CLIENT_CloseHandle( reply.phandle ); + else if (reply.phandle != -1) CloseHandle( reply.phandle ); return 0; error: @@ -330,57 +330,3 @@ int CLIENT_SetDebug( int level ) CLIENT_SendRequest( REQ_SET_DEBUG, -1, 1, &level, sizeof(level) ); return CLIENT_WaitReply( NULL, NULL, 0 ); } - -/*********************************************************************** - * CLIENT_CloseHandle - * - * Send a close handle request. Return 0 if OK. - */ -int CLIENT_CloseHandle( int handle ) -{ - CLIENT_SendRequest( REQ_CLOSE_HANDLE, -1, 1, &handle, sizeof(handle) ); - return CLIENT_WaitReply( NULL, NULL, 0 ); -} - -/*********************************************************************** - * CLIENT_DuplicateHandle - * - * Send a duplicate handle request. Return 0 if OK. - */ -int CLIENT_DuplicateHandle( int src_process, int src_handle, int dst_process, int dst_handle, - DWORD access, BOOL inherit, DWORD options ) -{ - struct dup_handle_request req; - struct dup_handle_reply reply; - - req.src_process = src_process; - req.src_handle = src_handle; - req.dst_process = dst_process; - req.access = access; - req.inherit = inherit; - req.options = options; - - CLIENT_SendRequest( REQ_DUP_HANDLE, -1, 1, &req, sizeof(req) ); - CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - return reply.handle; -} - - -/*********************************************************************** - * CLIENT_OpenProcess - * - * Open a handle to a process. - */ -int CLIENT_OpenProcess( void *pid, DWORD access, BOOL inherit ) -{ - struct open_process_request req; - struct open_process_reply reply; - - req.pid = pid; - req.access = access; - req.inherit = inherit; - - CLIENT_SendRequest( REQ_OPEN_PROCESS, -1, 1, &req, sizeof(req) ); - CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - return reply.handle; -} diff --git a/scheduler/critsection.c b/scheduler/critsection.c index fa88191a0d7..28ea1f82933 100644 --- a/scheduler/critsection.c +++ b/scheduler/critsection.c @@ -8,24 +8,13 @@ #include #include #include -#include #include "debug.h" #include "winerror.h" #include "winbase.h" #include "heap.h" -#include "k32obj.h" #include "debug.h" #include "thread.h" -/* On some systems this is supposed to be defined in the program */ -#ifndef HAVE_UNION_SEMUN -union semun { - int val; - struct semid_ds *buf; - ushort *array; -}; -#endif - /*********************************************************************** * InitializeCriticalSection (KERNEL32.472) (NTDLL.406) @@ -36,23 +25,8 @@ void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit ) crit->RecursionCount = 0; crit->OwningThread = 0; crit->LockSemaphore = 0; - if (SystemHeap) - { - crit->LockSemaphore = CreateSemaphoreA( NULL, 0, 1, NULL ); - crit->Reserved = (DWORD)-1; - } - else - { - union semun val; - crit->Reserved = (DWORD)semget( IPC_PRIVATE, 1, IPC_CREAT | 0777 ); - if (crit->Reserved == (DWORD)-1) - { - perror( "semget" ); - return; - } - val.val = 0; - semctl( (int)crit->Reserved, 0, SETVAL, val ); - } + crit->LockSemaphore = CreateSemaphoreA( NULL, 0, 1, NULL ); + crit->Reserved = (DWORD)-1; } @@ -71,10 +45,6 @@ void WINAPI DeleteCriticalSection( CRITICAL_SECTION *crit ) CloseHandle( crit->LockSemaphore ); crit->LockSemaphore = 0; } - else if (crit->Reserved != (DWORD)-1) - { - semctl( (int)crit->Reserved, 0, IPC_RMID, (union semun)0 ); - } } @@ -83,9 +53,8 @@ void WINAPI DeleteCriticalSection( CRITICAL_SECTION *crit ) */ void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit ) { - if ( (crit->Reserved==-1) && !(crit->LockSemaphore) && - (crit!=HEAP_SystemLock) - ) { + if (!crit->LockSemaphore) + { FIXME(win32,"entering uninitialized section(%p)?\n",crit); InitializeCriticalSection(crit); } @@ -97,28 +66,8 @@ void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit ) return; } /* Now wait for it */ - if (crit->LockSemaphore) - { - /* FIXME: should set a timeout and raise an exception */ - WaitForSingleObject( crit->LockSemaphore, INFINITE ); - } - else if (crit->Reserved != (DWORD)-1) - { - int ret; - struct sembuf sop; - sop.sem_num = 0; - sop.sem_op = -1; - sop.sem_flg = 0/*SEM_UNDO*/; - do - { - ret = semop( (int)crit->Reserved, &sop, 1 ); - } while ((ret == -1) && (errno == EINTR)); - } - else - { - MSG( "Uninitialized critical section (%p)\n", crit ); - return; - } + /* FIXME: should set a timeout and raise an exception */ + WaitForSingleObject( crit->LockSemaphore, INFINITE ); } crit->OwningThread = GetCurrentThreadId(); crit->RecursionCount = 1; @@ -163,18 +112,7 @@ void WINAPI LeaveCriticalSection( CRITICAL_SECTION *crit ) if (InterlockedDecrement( &crit->LockCount ) >= 0) { /* Someone is waiting */ - if (crit->LockSemaphore) - { - ReleaseSemaphore( crit->LockSemaphore, 1, NULL ); - } - else if (crit->Reserved != (DWORD)-1) - { - struct sembuf sop; - sop.sem_num = 0; - sop.sem_op = 1; - sop.sem_flg = 0/*SEM_UNDO*/; - semop( (int)crit->Reserved, &sop, 1 ); - } + ReleaseSemaphore( crit->LockSemaphore, 1, NULL ); } } diff --git a/scheduler/event.c b/scheduler/event.c index 61b1ca66faf..fbdd4b863b0 100644 --- a/scheduler/event.c +++ b/scheduler/event.c @@ -7,19 +7,11 @@ #include #include #include "winerror.h" -#include "k32obj.h" -#include "process.h" -#include "thread.h" #include "heap.h" #include "syslevel.h" #include "server/request.h" #include "server.h" -typedef struct -{ - K32OBJ header; -} EVENT; - /*********************************************************************** * CreateEvent32A (KERNEL32.156) @@ -30,25 +22,14 @@ HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, struct create_event_request req; struct create_event_reply reply; int len = name ? strlen(name) + 1 : 0; - HANDLE handle; - EVENT *event; req.manual_reset = manual_reset; req.initial_state = initial_state; req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); if (reply.handle == -1) return 0; - - SYSTEM_LOCK(); - event = (EVENT *)K32OBJ_Create( K32OBJ_EVENT, sizeof(*event), name, - reply.handle, EVENT_ALL_ACCESS, sa, &handle ); - if (event) - K32OBJ_DecCount( &event->header ); - SYSTEM_UNLOCK(); - if (handle == INVALID_HANDLE_VALUE) handle = 0; - return handle; + return reply.handle; } @@ -78,8 +59,6 @@ HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state ) */ HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) { - HANDLE handle = 0; - K32OBJ *obj; struct open_named_obj_request req; struct open_named_obj_reply reply; int len = name ? strlen(name) + 1 : 0; @@ -89,20 +68,8 @@ HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) req.inherit = inherit; CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle != -1) - { - SYSTEM_LOCK(); - if ((obj = K32OBJ_FindNameType( name, K32OBJ_EVENT )) != NULL) - { - handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle ); - K32OBJ_DecCount( obj ); - if (handle == INVALID_HANDLE_VALUE) - handle = 0; /* must return 0 on failure, not -1 */ - } - else CLIENT_CloseHandle( reply.handle ); - SYSTEM_UNLOCK(); - } - return handle; + if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */ + return (HANDLE)reply.handle; } @@ -127,10 +94,8 @@ static BOOL EVENT_Operation( HANDLE handle, enum event_op op ) { struct event_op_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_EVENT, EVENT_MODIFY_STATE ); - if (req.handle == -1) return FALSE; - req.op = op; + req.handle = handle; + req.op = op; CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); } diff --git a/scheduler/handle.c b/scheduler/handle.c index 032921b0e2a..e4850f47c61 100644 --- a/scheduler/handle.c +++ b/scheduler/handle.c @@ -7,296 +7,7 @@ #include #include #include "winbase.h" -#include "winerror.h" -#include "heap.h" -#include "process.h" #include "server.h" -#include "thread.h" -#include "debug.h" - -#define HTABLE_SIZE 0x30 /* Handle table initial size */ -#define HTABLE_INC 0x10 /* Handle table increment */ - -/* Reserved access rights */ -#define RESERVED_ALL (0x0007 << RESERVED_SHIFT) -#define RESERVED_SHIFT 25 -#define RESERVED_INHERIT (HANDLE_FLAG_INHERIT<handle_table; - table = HeapReAlloc( process->system_heap, - HEAP_ZERO_MEMORY | HEAP_NO_SERIALIZE, table, - sizeof(HANDLE_TABLE) + - (table->count + incr - 1) * sizeof(HANDLE_ENTRY) ); - if (table) - { - table->count += incr; - process->handle_table = table; - } - SYSTEM_UNLOCK(); - return (table != NULL); -} - - -/*********************************************************************** - * HANDLE_CreateTable - * - * Create a process handle table, optionally inheriting the parent's handles. - */ -BOOL HANDLE_CreateTable( PDB *pdb, BOOL inherit ) -{ - DWORD size; - - /* Process must not already have a handle table */ - assert( !pdb->handle_table ); - - /* If this is the first process, simply allocate a table */ - if (!pdb->parent) inherit = FALSE; - - SYSTEM_LOCK(); - size = inherit ? pdb->parent->handle_table->count : HTABLE_SIZE; - if ((pdb->handle_table = HeapAlloc( pdb->system_heap, - HEAP_ZERO_MEMORY | HEAP_NO_SERIALIZE, - sizeof(HANDLE_TABLE) + - (size-1) * sizeof(HANDLE_ENTRY) ))) - { - pdb->handle_table->count = size; - if (inherit) - { - HANDLE_ENTRY *src = pdb->parent->handle_table->entries; - HANDLE_ENTRY *dst = pdb->handle_table->entries; - HANDLE h; - - for (h = 0; h < size; h++, src++, dst++) - { - /* Check if handle is valid and inheritable */ - if (src->ptr && (src->access & RESERVED_INHERIT)) - { - dst->access = src->access; - dst->ptr = src->ptr; - dst->server = src->server; - K32OBJ_IncCount( dst->ptr ); - } - } - } - /* Handle 1 is the process itself (unless the parent decided otherwise) */ - if (!pdb->handle_table->entries[1].ptr) - { - pdb->handle_table->entries[1].ptr = &pdb->header; - pdb->handle_table->entries[1].access = PROCESS_ALL_ACCESS; - pdb->handle_table->entries[1].server = -1; /* FIXME */ - K32OBJ_IncCount( &pdb->header ); - } - } - SYSTEM_UNLOCK(); - return (pdb->handle_table != NULL); -} - - -/*********************************************************************** - * HANDLE_Alloc - * - * Allocate a handle for a kernel object and increment its refcount. - */ -HANDLE HANDLE_Alloc( PDB *pdb, K32OBJ *ptr, DWORD access, - BOOL inherit, int server_handle ) -{ - HANDLE h; - HANDLE_ENTRY *entry; - - assert( ptr ); - - /* Set the inherit reserved flag */ - access &= ~RESERVED_ALL; - if (inherit) access |= RESERVED_INHERIT; - - SYSTEM_LOCK(); - K32OBJ_IncCount( ptr ); - /* Don't try to allocate handle 0 */ - entry = pdb->handle_table->entries + 1; - for (h = 1; h < pdb->handle_table->count; h++, entry++) - if (!entry->ptr) break; - if ((h < pdb->handle_table->count) || HANDLE_GrowTable( pdb, HTABLE_INC )) - { - entry = &pdb->handle_table->entries[h]; - entry->access = access; - entry->ptr = ptr; - entry->server = server_handle; - SYSTEM_UNLOCK(); - return h; - } - K32OBJ_DecCount( ptr ); - SYSTEM_UNLOCK(); - if (server_handle != -1) CLIENT_CloseHandle( server_handle ); - SetLastError( ERROR_OUTOFMEMORY ); - return INVALID_HANDLE_VALUE; -} - - -/*********************************************************************** - * HANDLE_GetObjPtr - * - * Retrieve a pointer to a kernel object and increments its reference count. - * The refcount must be decremented when the pointer is no longer used. - */ -K32OBJ *HANDLE_GetObjPtr( PDB *pdb, HANDLE handle, - K32OBJ_TYPE type, DWORD access, - int *server_handle ) -{ - K32OBJ *ptr = NULL; - - SYSTEM_LOCK(); - if (HANDLE_IS_GLOBAL( handle )) - { - handle = HANDLE_GLOBAL_TO_LOCAL( handle ); - pdb = PROCESS_Initial(); - } - if ((handle > 0) && (handle < pdb->handle_table->count)) - { - HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle]; - if ((entry->access & access) != access) - WARN(win32, "Handle %08x bad access (acc=%08lx req=%08lx)\n", - handle, entry->access, access ); - ptr = entry->ptr; - if (server_handle) *server_handle = entry->server; - } - else if (handle == CURRENT_THREAD_PSEUDOHANDLE) - { - ptr = (K32OBJ *)THREAD_Current(); - if (server_handle) *server_handle = CURRENT_THREAD_PSEUDOHANDLE; - } - else if (handle == CURRENT_PROCESS_PSEUDOHANDLE) - { - ptr = (K32OBJ *)PROCESS_Current(); - if (server_handle) *server_handle = CURRENT_PROCESS_PSEUDOHANDLE; - } - - if (ptr && ((type == K32OBJ_UNKNOWN) || (ptr->type == type))) - K32OBJ_IncCount( ptr ); - else - ptr = NULL; - - SYSTEM_UNLOCK(); - if (!ptr) SetLastError( ERROR_INVALID_HANDLE ); - return ptr; -} - - -/*********************************************************************** - * HANDLE_GetServerHandle - * - * Retrieve the server handle associated to an object. - */ -int HANDLE_GetServerHandle( PDB *pdb, HANDLE handle, - K32OBJ_TYPE type, DWORD access ) -{ - int server_handle; - K32OBJ *obj; - - SYSTEM_LOCK(); - if ((obj = HANDLE_GetObjPtr( pdb, handle, type, access, &server_handle ))) - K32OBJ_DecCount( obj ); - else - server_handle = -1; - SYSTEM_UNLOCK(); - return server_handle; -} - - -/********************************************************************* - * HANDLE_GetAccess - */ -static BOOL HANDLE_GetAccess( PDB *pdb, HANDLE handle, LPDWORD access ) -{ - BOOL ret = FALSE; - - SYSTEM_LOCK(); - if ((handle > 0) && (handle < pdb->handle_table->count)) - { - HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle]; - if (entry->ptr) - { - *access = entry->access & ~RESERVED_ALL; - ret = TRUE; - } - } - SYSTEM_UNLOCK(); - if (!ret) SetLastError( ERROR_INVALID_HANDLE ); - return ret; -} - - -/********************************************************************* - * HANDLE_Close - */ -static BOOL HANDLE_Close( PDB *pdb, HANDLE handle ) -{ - BOOL ret = FALSE; - K32OBJ *ptr; - - if (HANDLE_IS_GLOBAL( handle )) - { - handle = HANDLE_GLOBAL_TO_LOCAL( handle ); - pdb = PROCESS_Initial(); - } - SYSTEM_LOCK(); - if ((handle > 0) && (handle < pdb->handle_table->count)) - { - HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle]; - if ((ptr = entry->ptr)) - { - if (!(entry->access & RESERVED_CLOSE_PROTECT)) - { - entry->access = 0; - entry->ptr = NULL; - if (entry->server != -1) - CLIENT_CloseHandle( entry->server ); - K32OBJ_DecCount( ptr ); - ret = TRUE; - } - /* FIXME: else SetLastError */ - } - } - SYSTEM_UNLOCK(); - if (!ret) SetLastError( ERROR_INVALID_HANDLE ); - return ret; -} - - -/********************************************************************* - * HANDLE_CloseAll - * - * Close all handles pointing to a given object (or all handles of the - * process if the object is NULL) - */ -void HANDLE_CloseAll( PDB *pdb, K32OBJ *obj ) -{ - HANDLE_ENTRY *entry; - K32OBJ *ptr; - HANDLE handle; - - SYSTEM_LOCK(); - entry = pdb->handle_table->entries; - for (handle = 0; handle < pdb->handle_table->count; handle++, entry++) - { - if (!(ptr = entry->ptr)) continue; /* empty slot */ - if (obj && (ptr != obj)) continue; /* not the right object */ - entry->access = 0; - entry->ptr = NULL; - if (entry->server != -1) CLIENT_CloseHandle( entry->server ); - K32OBJ_DecCount( ptr ); - } - SYSTEM_UNLOCK(); -} /********************************************************************* @@ -304,7 +15,9 @@ void HANDLE_CloseAll( PDB *pdb, K32OBJ *obj ) */ BOOL WINAPI CloseHandle( HANDLE handle ) { - return HANDLE_Close( PROCESS_Current(), handle ); + struct close_handle_request req = { handle }; + CLIENT_SendRequest( REQ_CLOSE_HANDLE, -1, 1, &req, sizeof(req) ); + return !CLIENT_WaitReply( NULL, NULL, 0 ); } @@ -313,23 +26,14 @@ BOOL WINAPI CloseHandle( HANDLE handle ) */ BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags ) { - BOOL ret = FALSE; - PDB *pdb = PROCESS_Current(); + struct get_handle_info_request req; + struct get_handle_info_reply reply; - SYSTEM_LOCK(); - if ((handle > 0) && (handle < pdb->handle_table->count)) - { - HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle]; - if (entry->ptr) - { - if (flags) - *flags = (entry->access & RESERVED_ALL) >> RESERVED_SHIFT; - ret = TRUE; - } - } - SYSTEM_UNLOCK(); - if (!ret) SetLastError( ERROR_INVALID_HANDLE ); - return ret; + req.handle = handle; + CLIENT_SendRequest( REQ_GET_HANDLE_INFO, -1, 1, &req, sizeof(req) ); + if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; + if (flags) *flags = reply.flags; + return TRUE; } @@ -338,24 +42,13 @@ BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags ) */ BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags ) { - BOOL ret = FALSE; - PDB *pdb = PROCESS_Current(); + struct set_handle_info_request req; - mask = (mask << RESERVED_SHIFT) & RESERVED_ALL; - flags = (flags << RESERVED_SHIFT) & RESERVED_ALL; - SYSTEM_LOCK(); - if ((handle > 0) && (handle < pdb->handle_table->count)) - { - HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle]; - if (entry->ptr) - { - entry->access = (entry->access & ~mask) | flags; - ret = TRUE; - } - } - SYSTEM_UNLOCK(); - if (!ret) SetLastError( ERROR_INVALID_HANDLE ); - return ret; + req.handle = handle; + req.flags = flags; + req.mask = mask; + CLIENT_SendRequest( REQ_SET_HANDLE_INFO, -1, 1, &req, sizeof(req) ); + return !CLIENT_WaitReply( NULL, NULL, 0 ); } @@ -366,52 +59,20 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source, HANDLE dest_process, HANDLE *dest, DWORD access, BOOL inherit, DWORD options ) { - PDB *src_pdb = NULL, *dst_pdb = NULL; - K32OBJ *obj = NULL; - BOOL ret = FALSE; - HANDLE handle; - int src_process, src_handle, dst_process, dst_handle; + struct dup_handle_request req; + struct dup_handle_reply reply; - SYSTEM_LOCK(); + req.src_process = source_process; + req.src_handle = source; + req.dst_process = dest_process; + req.access = access; + req.inherit = inherit; + req.options = options; - if (!(src_pdb = (PDB *)HANDLE_GetObjPtr( PROCESS_Current(), source_process, - K32OBJ_PROCESS, PROCESS_DUP_HANDLE, &src_process ))) - goto done; - if (!(obj = HANDLE_GetObjPtr( src_pdb, source, K32OBJ_UNKNOWN, 0, &src_handle ))) - goto done; - - /* Now that we are sure the source is valid, handle the options */ - - if (options & DUPLICATE_SAME_ACCESS) - HANDLE_GetAccess( src_pdb, source, &access ); - if (options & DUPLICATE_CLOSE_SOURCE) - HANDLE_Close( src_pdb, source ); - - /* And duplicate the handle in the dest process */ - - if (!(dst_pdb = (PDB *)HANDLE_GetObjPtr( PROCESS_Current(), dest_process, - K32OBJ_PROCESS, PROCESS_DUP_HANDLE, &dst_process ))) - goto done; - - if ((src_process != -1) && (src_handle != -1) && (dst_process != -1)) - dst_handle = CLIENT_DuplicateHandle( src_process, src_handle, dst_process, -1, - access, inherit, options ); - else - dst_handle = -1; - - if ((handle = HANDLE_Alloc( dst_pdb, obj, access, inherit, - dst_handle )) != INVALID_HANDLE_VALUE) - { - if (dest) *dest = handle; - ret = TRUE; - } - -done: - if (dst_pdb) K32OBJ_DecCount( &dst_pdb->header ); - if (obj) K32OBJ_DecCount( obj ); - if (src_pdb) K32OBJ_DecCount( &src_pdb->header ); - SYSTEM_UNLOCK(); - return ret; + CLIENT_SendRequest( REQ_DUP_HANDLE, -1, 1, &req, sizeof(req) ); + if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; + if (dest) *dest = reply.handle; + return TRUE; } @@ -420,31 +81,17 @@ done: */ HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc) { - int src_handle, dst_handle; - HANDLE handle; - K32OBJ *obj = NULL; - DWORD access; + struct dup_handle_request req; + struct dup_handle_reply reply; - if (HANDLE_IS_GLOBAL(hSrc)) - return hSrc; + req.src_process = GetCurrentProcess(); + req.src_handle = hSrc; + req.dst_process = -1; + req.access = 0; + req.inherit = FALSE; + req.options = DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS; - if (!(obj = HANDLE_GetObjPtr( PROCESS_Current(), hSrc, K32OBJ_UNKNOWN, 0, &src_handle ))) - return 0; - - HANDLE_GetAccess( PROCESS_Current(), hSrc, &access ); - - if (src_handle != -1) - dst_handle = CLIENT_DuplicateHandle( GetCurrentProcess(), src_handle, -1, -1, 0, FALSE, - DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS ); - else - dst_handle = -1; - - if ((handle = HANDLE_Alloc( PROCESS_Initial(), obj, access, FALSE, - dst_handle )) != INVALID_HANDLE_VALUE) - handle = HANDLE_LOCAL_TO_GLOBAL(handle); - else - handle = 0; - - CloseHandle( hSrc ); - return handle; + CLIENT_SendRequest( REQ_DUP_HANDLE, -1, 1, &req, sizeof(req) ); + CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); + return reply.handle; } diff --git a/scheduler/k32obj.c b/scheduler/k32obj.c deleted file mode 100644 index 36919389283..00000000000 --- a/scheduler/k32obj.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * KERNEL32 objects - * - * Copyright 1996 Alexandre Julliard - */ - -#include -#include -#include "winerror.h" -#include "k32obj.h" -#include "heap.h" -#include "process.h" -#include "server.h" - - -/* The declarations are here to avoid including a lot of unnecessary files */ -extern const K32OBJ_OPS PROCESS_Ops; -extern const K32OBJ_OPS THREAD_Ops; - -static const K32OBJ_OPS K32OBJ_NullOps = -{ - NULL /* destroy */ -}; - -static void K32OBJ_Destroy( K32OBJ *obj ); - -static const K32OBJ_OPS K32OBJ_DefaultOps = -{ - K32OBJ_Destroy /* destroy */ -}; - - -const K32OBJ_OPS * const K32OBJ_Ops[K32OBJ_NBOBJECTS] = -{ - NULL, - &K32OBJ_DefaultOps, /* K32OBJ_SEMAPHORE */ - &K32OBJ_DefaultOps, /* K32OBJ_EVENT */ - &K32OBJ_DefaultOps, /* K32OBJ_MUTEX */ - &K32OBJ_NullOps, /* K32OBJ_CRITICAL_SECTION */ - &PROCESS_Ops, /* K32OBJ_PROCESS */ - &THREAD_Ops, /* K32OBJ_THREAD */ - &K32OBJ_DefaultOps, /* K32OBJ_FILE */ - &K32OBJ_DefaultOps, /* K32OBJ_CHANGE */ - &K32OBJ_DefaultOps, /* K32OBJ_CONSOLE */ - &K32OBJ_NullOps, /* K32OBJ_SCREEN_BUFFER */ - &K32OBJ_DefaultOps, /* K32OBJ_MEM_MAPPED_FILE */ - &K32OBJ_NullOps, /* K32OBJ_SERIAL */ - &K32OBJ_NullOps, /* K32OBJ_DEVICE_IOCTL */ - &K32OBJ_DefaultOps, /* K32OBJ_PIPE */ - &K32OBJ_NullOps, /* K32OBJ_MAILSLOT */ - &K32OBJ_DefaultOps, /* K32OBJ_TOOLHELP_SNAPSHOT */ - &K32OBJ_NullOps /* K32OBJ_SOCKET */ -}; - -typedef struct _NE -{ - struct _NE *next; - K32OBJ *obj; - UINT len; - char name[1]; -} NAME_ENTRY; - -static NAME_ENTRY *K32OBJ_FirstEntry = NULL; - - -/*********************************************************************** - * K32OBJ_IncCount - */ -void K32OBJ_IncCount( K32OBJ *ptr ) -{ - assert( ptr->type && ((unsigned)ptr->type < K32OBJ_NBOBJECTS) ); - SYSTEM_LOCK(); - ptr->refcount++; - SYSTEM_UNLOCK(); - assert( ptr->refcount > 0 ); /* No wrap-around allowed */ -} - - -/*********************************************************************** - * K32OBJ_DecCount - */ -void K32OBJ_DecCount( K32OBJ *ptr ) -{ - NAME_ENTRY **pptr; - - assert( ptr->type && ((unsigned)ptr->type < K32OBJ_NBOBJECTS) ); - assert( ptr->refcount > 0 ); - SYSTEM_LOCK(); - if (--ptr->refcount) - { - SYSTEM_UNLOCK(); - return; - } - - /* Check if the object has a name entry and free it */ - - pptr = &K32OBJ_FirstEntry; - while (*pptr && ((*pptr)->obj != ptr)) pptr = &(*pptr)->next; - if (*pptr) - { - NAME_ENTRY *entry = *pptr; - *pptr = entry->next; - HeapFree( SystemHeap, 0, entry ); - } - - /* Free the object */ - - if (K32OBJ_Ops[ptr->type]->destroy) K32OBJ_Ops[ptr->type]->destroy( ptr ); - SYSTEM_UNLOCK(); -} - - -/*********************************************************************** - * K32OBJ_Destroy - * - * Generic destroy functions for objects that don't need any special treatment. - */ -static void K32OBJ_Destroy( K32OBJ *obj ) -{ - obj->type = K32OBJ_UNKNOWN; - HeapFree( SystemHeap, 0, obj ); -} - - -/*********************************************************************** - * K32OBJ_IsValid - * - * Check if a pointer is a valid kernel object - */ -BOOL K32OBJ_IsValid( K32OBJ *ptr, K32OBJ_TYPE type ) -{ - if (IsBadReadPtr( ptr, sizeof(*ptr) )) return FALSE; - return (ptr->type == type); -} - - -/*********************************************************************** - * K32OBJ_AddName - * - * Add a name entry for an object. We don't check for duplicates here. - * FIXME: should use some sort of hashing. - */ -BOOL K32OBJ_AddName( K32OBJ *obj, LPCSTR name ) -{ - NAME_ENTRY *entry; - UINT len; - - if (!name) return TRUE; /* Anonymous object */ - len = strlen( name ); - SYSTEM_LOCK(); - if (!(entry = HeapAlloc( SystemHeap, 0, sizeof(NAME_ENTRY) + len ))) - { - SYSTEM_UNLOCK(); - SetLastError( ERROR_OUTOFMEMORY ); - return FALSE; - } - entry->next = K32OBJ_FirstEntry; - entry->obj = obj; - entry->len = len; - lstrcpyA( entry->name, name ); - K32OBJ_FirstEntry = entry; - SYSTEM_UNLOCK(); - return TRUE; -} - - -/*********************************************************************** - * K32OBJ_Create - * - * Create a named kernel object. - * Returns NULL if there was an error _or_ if the object already existed. - * The refcount of the object must be decremented once it is initialized. - */ -K32OBJ *K32OBJ_Create( K32OBJ_TYPE type, DWORD size, LPCSTR name, int server_handle, - DWORD access, SECURITY_ATTRIBUTES *sa, HANDLE *handle) -{ - BOOL inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - - /* Check if the name already exists */ - - K32OBJ *obj = K32OBJ_FindName( name ); - if (obj) - { - if (obj->type == type) - { - SetLastError( ERROR_ALREADY_EXISTS ); - *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, server_handle ); - } - else - { - SetLastError( ERROR_DUP_NAME ); - *handle = INVALID_HANDLE_VALUE; - if (server_handle != -1) CLIENT_CloseHandle( server_handle ); - } - K32OBJ_DecCount( obj ); - return NULL; - } - - /* Create the object */ - - SYSTEM_LOCK(); - if (!(obj = HeapAlloc( SystemHeap, 0, size ))) - { - SYSTEM_UNLOCK(); - *handle = INVALID_HANDLE_VALUE; - if (server_handle != -1) CLIENT_CloseHandle( server_handle ); - return NULL; - } - obj->type = type; - obj->refcount = 1; - - /* Add a name for it */ - - if (!K32OBJ_AddName( obj, name )) - { - /* Don't call the destroy function, as the object wasn't - * initialized properly */ - HeapFree( SystemHeap, 0, obj ); - SYSTEM_UNLOCK(); - *handle = INVALID_HANDLE_VALUE; - if (server_handle != -1) CLIENT_CloseHandle( server_handle ); - return NULL; - } - - /* Allocate a handle */ - - *handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, server_handle ); - SYSTEM_UNLOCK(); - return obj; -} - - -/*********************************************************************** - * K32OBJ_FindName - * - * Find the object referenced by a given name. - * The reference count is incremented. - */ -K32OBJ *K32OBJ_FindName( LPCSTR name ) -{ - NAME_ENTRY *entry; - UINT len; - - if (!name) return NULL; /* Anonymous object */ - len = strlen( name ); - SYSTEM_LOCK(); - entry = K32OBJ_FirstEntry; - while (entry) - { - if ((len == entry->len) && !strcmp( name, entry->name)) - { - K32OBJ *obj = entry->obj; - K32OBJ_IncCount( obj ); - SYSTEM_UNLOCK(); - return entry->obj; - } - entry = entry->next; - } - SYSTEM_UNLOCK(); - return NULL; -} - - -/*********************************************************************** - * K32OBJ_FindNameType - * - * Find an object by name and check its type. - * The reference count is incremented. - */ -K32OBJ *K32OBJ_FindNameType( LPCSTR name, K32OBJ_TYPE type ) -{ - K32OBJ *obj = K32OBJ_FindName( name ); - if (!obj) return NULL; - if (obj->type == type) return obj; - SetLastError( ERROR_DUP_NAME ); - K32OBJ_DecCount( obj ); - return NULL; -} diff --git a/scheduler/mutex.c b/scheduler/mutex.c index 91eae648b34..180d28f8afb 100644 --- a/scheduler/mutex.c +++ b/scheduler/mutex.c @@ -7,18 +7,10 @@ #include #include #include "winerror.h" -#include "k32obj.h" -#include "process.h" -#include "thread.h" #include "heap.h" #include "server/request.h" #include "server.h" -typedef struct _MUTEX -{ - K32OBJ header; -} MUTEX; - /*********************************************************************** * CreateMutex32A (KERNEL32.166) @@ -29,24 +21,13 @@ HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, struct create_mutex_request req; struct create_mutex_reply reply; int len = name ? strlen(name) + 1 : 0; - HANDLE handle; - MUTEX *mutex; req.owned = owner; req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - CLIENT_SendRequest( REQ_CREATE_MUTEX, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); if (reply.handle == -1) return 0; - - SYSTEM_LOCK(); - mutex = (MUTEX *)K32OBJ_Create( K32OBJ_MUTEX, sizeof(*mutex), - name, reply.handle, MUTEX_ALL_ACCESS, - sa, &handle ); - if (mutex) K32OBJ_DecCount( &mutex->header ); - if (handle == INVALID_HANDLE_VALUE) handle = 0; - SYSTEM_UNLOCK(); - return handle; + return reply.handle; } @@ -68,8 +49,6 @@ HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, */ HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) { - HANDLE handle = 0; - K32OBJ *obj; struct open_named_obj_request req; struct open_named_obj_reply reply; int len = name ? strlen(name) + 1 : 0; @@ -79,20 +58,8 @@ HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name ) req.inherit = inherit; CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle != -1) - { - SYSTEM_LOCK(); - if ((obj = K32OBJ_FindNameType( name, K32OBJ_MUTEX )) != NULL) - { - handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle ); - K32OBJ_DecCount( obj ); - if (handle == INVALID_HANDLE_VALUE) - handle = 0; /* must return 0 on failure, not -1 */ - } - else CLIENT_CloseHandle( reply.handle ); - SYSTEM_UNLOCK(); - } - return handle; + if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */ + return reply.handle; } @@ -115,9 +82,7 @@ BOOL WINAPI ReleaseMutex( HANDLE handle ) { struct release_mutex_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_MUTEX, MUTEX_MODIFY_STATE ); - if (req.handle == -1) return FALSE; + req.handle = handle; CLIENT_SendRequest( REQ_RELEASE_MUTEX, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); } diff --git a/scheduler/pipe.c b/scheduler/pipe.c index a7b4889900a..31157c4d33f 100644 --- a/scheduler/pipe.c +++ b/scheduler/pipe.c @@ -6,18 +6,10 @@ #include #include "winerror.h" -#include "k32obj.h" -#include "process.h" -#include "thread.h" -#include "heap.h" +#include "winbase.h" #include "server/request.h" #include "server.h" -typedef struct _PIPE -{ - K32OBJ header; -} PIPE; - /*********************************************************************** * CreatePipe (KERNEL32.170) @@ -27,39 +19,13 @@ BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe, { struct create_pipe_request req; struct create_pipe_reply reply; - PIPE *read_pipe, *write_pipe; int len; req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); CLIENT_SendRequest( REQ_CREATE_PIPE, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) ) != ERROR_SUCCESS) return FALSE; - - SYSTEM_LOCK(); - if (!(read_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*read_pipe), - NULL, reply.handle_read, - STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ, - sa, hReadPipe ))) - { - CLIENT_CloseHandle( reply.handle_write ); - /* handle_read already closed by K32OBJ_Create */ - SYSTEM_UNLOCK(); - return FALSE; - } - K32OBJ_DecCount( &read_pipe->header ); - if (!(write_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*write_pipe), - NULL, reply.handle_write, - STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE, - sa, hWritePipe ))) - { - CloseHandle( *hReadPipe ); - *hReadPipe = INVALID_HANDLE_VALUE; - SYSTEM_UNLOCK(); - return FALSE; - } - /* everything OK */ - K32OBJ_DecCount( &write_pipe->header ); - SetLastError(0); /* FIXME */ - SYSTEM_UNLOCK(); + *hReadPipe = reply.handle_read; + *hWritePipe = reply.handle_write; return TRUE; } diff --git a/scheduler/process.c b/scheduler/process.c index 7859587ff1a..00e8f0d3ea3 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -24,12 +24,6 @@ #include "server.h" #include "debug.h" -static void PROCESS_Destroy( K32OBJ *obj ); - -const K32OBJ_OPS PROCESS_Ops = -{ - PROCESS_Destroy /* destroy */ -}; /* The initial process PDB */ static PDB initial_pdb; @@ -66,8 +60,7 @@ static BOOL PROCESS_QueryInfo( HANDLE handle, struct get_process_info_reply *reply ) { struct get_process_info_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_PROCESS, PROCESS_QUERY_INFORMATION ); + req.handle = handle; CLIENT_SendRequest( REQ_GET_PROCESS_INFO, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL ); } @@ -190,12 +183,10 @@ static BOOL PROCESS_InheritEnvDB( PDB *pdb, LPCSTR cmd_line, LPCSTR env, * * Free a PDB and all associated storage. */ -static void PROCESS_FreePDB( PDB *pdb ) +void PROCESS_FreePDB( PDB *pdb ) { PDB **pptr = &PROCESS_First; - pdb->header.type = K32OBJ_UNKNOWN; - if (pdb->handle_table) HANDLE_CloseAll( pdb, NULL ); ENV_FreeEnvironment( pdb ); while (*pptr && (*pptr != pdb)) pptr = &(*pptr)->next; if (*pptr) *pptr = pdb->next; @@ -216,8 +207,6 @@ static PDB *PROCESS_CreatePDB( PDB *parent, BOOL inherit ) PDB *pdb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(PDB) ); if (!pdb) return NULL; - pdb->header.type = K32OBJ_PROCESS; - pdb->header.refcount = 1; pdb->exit_code = 0x103; /* STILL_ACTIVE */ pdb->threads = 1; pdb->running_threads = 1; @@ -229,15 +218,7 @@ static PDB *PROCESS_CreatePDB( PDB *parent, BOOL inherit ) pdb->heap = pdb->system_heap; /* will be changed later on */ pdb->next = PROCESS_First; PROCESS_First = pdb; - - /* Create the handle table */ - - if (!HANDLE_CreateTable( pdb, inherit )) goto error; return pdb; - -error: - PROCESS_FreePDB( pdb ); - return NULL; } @@ -264,8 +245,6 @@ BOOL PROCESS_Init(void) THDB *thdb; /* Fill the initial process structure */ - initial_pdb.header.type = K32OBJ_PROCESS; - initial_pdb.header.refcount = 1; initial_pdb.exit_code = 0x103; /* STILL_ACTIVE */ initial_pdb.threads = 1; initial_pdb.running_threads = 1; @@ -276,17 +255,16 @@ BOOL PROCESS_Init(void) /* Initialize virtual memory management */ if (!VIRTUAL_Init()) return FALSE; - /* Create the system heap */ - if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE; - initial_pdb.system_heap = initial_pdb.heap = SystemHeap; - - /* Create the initial process and thread structures */ - if (!HANDLE_CreateTable( &initial_pdb, FALSE )) return FALSE; + /* Create the initial thread structure */ if (!(thdb = THREAD_CreateInitialThread( &initial_pdb ))) return FALSE; /* Remember TEB selector of initial process for emergency use */ SYSLEVEL_EmergencyTeb = thdb->teb_sel; + /* Create the system heap */ + if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE; + initial_pdb.system_heap = initial_pdb.heap = SystemHeap; + /* Create the environment DB of the first process */ if (!PROCESS_BuildEnvDB( &initial_pdb )) return FALSE; @@ -351,12 +329,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, if (!(thdb = THREAD_Create( pdb, size, hInstance == 0, &server_thandle, &server_phandle, NULL, NULL ))) goto error; - if ((info->hThread = HANDLE_Alloc( parent, &thdb->header, THREAD_ALL_ACCESS, - FALSE, server_thandle )) == INVALID_HANDLE_VALUE) - goto error; - if ((info->hProcess = HANDLE_Alloc( parent, &pdb->header, PROCESS_ALL_ACCESS, - FALSE, server_phandle )) == INVALID_HANDLE_VALUE) - goto error; + info->hThread = server_thandle; + info->hProcess = server_phandle; info->dwProcessId = (DWORD)pdb->server_pid; info->dwThreadId = (DWORD)thdb->server_tid; @@ -391,27 +365,11 @@ PDB *PROCESS_Create( NE_MODULE *pModule, LPCSTR cmd_line, LPCSTR env, error: if (info->hThread != INVALID_HANDLE_VALUE) CloseHandle( info->hThread ); if (info->hProcess != INVALID_HANDLE_VALUE) CloseHandle( info->hProcess ); - if (thdb) K32OBJ_DecCount( &thdb->header ); PROCESS_FreePDB( pdb ); return NULL; } -/*********************************************************************** - * PROCESS_Destroy - */ -static void PROCESS_Destroy( K32OBJ *ptr ) -{ - PDB *pdb = (PDB *)ptr; - assert( ptr->type == K32OBJ_PROCESS ); - - /* Free everything */ - - ptr->type = K32OBJ_UNKNOWN; - PROCESS_FreePDB( pdb ); -} - - /*********************************************************************** * ExitProcess (KERNEL32.100) */ @@ -424,11 +382,9 @@ void WINAPI ExitProcess( DWORD status ) if ( pTask && pTask->thdb != THREAD_Current() ) ExitThread( status ); - SYSTEM_LOCK(); /* FIXME: should kill all running threads of this process */ pdb->exit_code = status; - if (pdb->console) FreeConsole(); - SYSTEM_UNLOCK(); + FreeConsole(); __RESTORE_ES; /* Necessary for Pietrek's showseh example program */ TASK_KillCurrentTask( status ); @@ -441,9 +397,7 @@ void WINAPI ExitProcess( DWORD status ) BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code ) { struct terminate_process_request req; - - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_PROCESS, PROCESS_TERMINATE ); + req.handle = handle; req.exit_code = exit_code; CLIENT_SendRequest( REQ_TERMINATE_PROCESS, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); @@ -463,18 +417,15 @@ HANDLE WINAPI GetCurrentProcess(void) */ HANDLE WINAPI OpenProcess( DWORD access, BOOL inherit, DWORD id ) { - PDB *pdb; struct open_process_request req; struct open_process_reply reply; - if (!(pdb = PROCESS_IdToPDB( id ))) return 0; req.pid = (void *)id; req.access = access; req.inherit = inherit; CLIENT_SendRequest( REQ_OPEN_PROCESS, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0; - return HANDLE_Alloc( PROCESS_Current(), &pdb->header, access, - inherit, reply.handle ); + return reply.handle; } @@ -512,9 +463,7 @@ LCID WINAPI GetThreadLocale(void) BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass ) { struct set_process_info_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hprocess, - K32OBJ_PROCESS, PROCESS_SET_INFORMATION ); - if (req.handle == -1) return FALSE; + req.handle = hprocess; req.priority = priorityclass; req.mask = SET_PROCESS_INFO_PRIORITY; CLIENT_SendRequest( REQ_SET_PROCESS_INFO, -1, 1, &req, sizeof(req) ); @@ -539,9 +488,7 @@ DWORD WINAPI GetPriorityClass(HANDLE hprocess) BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD affmask ) { struct set_process_info_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hProcess, - K32OBJ_PROCESS, PROCESS_SET_INFORMATION ); - if (req.handle == -1) return FALSE; + req.handle = hProcess; req.affinity = affmask; req.mask = SET_PROCESS_INFO_AFFINITY; CLIENT_SendRequest( REQ_SET_PROCESS_INFO, -1, 1, &req, sizeof(req) ); diff --git a/scheduler/semaphore.c b/scheduler/semaphore.c index 6fdcf7050b1..b321331d93b 100644 --- a/scheduler/semaphore.c +++ b/scheduler/semaphore.c @@ -7,18 +7,10 @@ #include #include #include "winerror.h" -#include "k32obj.h" -#include "process.h" -#include "thread.h" #include "heap.h" #include "server/request.h" #include "server.h" -typedef struct -{ - K32OBJ header; -} SEMAPHORE; - /*********************************************************************** * CreateSemaphore32A (KERNEL32.174) @@ -29,8 +21,6 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, struct create_semaphore_request req; struct create_semaphore_reply reply; int len = name ? strlen(name) + 1 : 0; - HANDLE handle; - SEMAPHORE *sem; /* Check parameters */ @@ -47,15 +37,7 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, CLIENT_SendRequest( REQ_CREATE_SEMAPHORE, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); if (reply.handle == -1) return 0; - - SYSTEM_LOCK(); - sem = (SEMAPHORE *)K32OBJ_Create( K32OBJ_SEMAPHORE, sizeof(*sem), - name, reply.handle, SEMAPHORE_ALL_ACCESS, - sa, &handle); - if (sem) K32OBJ_DecCount( &sem->header ); - SYSTEM_UNLOCK(); - if (handle == INVALID_HANDLE_VALUE) handle = 0; - return handle; + return reply.handle; } @@ -77,8 +59,6 @@ HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, */ HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) { - HANDLE handle = 0; - K32OBJ *obj; struct open_named_obj_request req; struct open_named_obj_reply reply; int len = name ? strlen(name) + 1 : 0; @@ -88,20 +68,8 @@ HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name ) req.inherit = inherit; CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle != -1) - { - SYSTEM_LOCK(); - if ((obj = K32OBJ_FindNameType( name, K32OBJ_SEMAPHORE )) != NULL) - { - handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle ); - K32OBJ_DecCount( obj ); - if (handle == INVALID_HANDLE_VALUE) - handle = 0; /* must return 0 on failure, not -1 */ - } - else CLIENT_CloseHandle( reply.handle ); - SYSTEM_UNLOCK(); - } - return handle; + if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */ + return reply.handle; } @@ -130,10 +98,8 @@ BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous ) SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_SEMAPHORE, SEMAPHORE_MODIFY_STATE ); - if (req.handle == -1) return FALSE; - req.count = (unsigned int)count; + req.handle = handle; + req.count = (unsigned int)count; CLIENT_SendRequest( REQ_RELEASE_SEMAPHORE, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; if (previous) *previous = reply.prev_count; diff --git a/scheduler/synchro.c b/scheduler/synchro.c index 9a23e53ebbe..8c82f40b343 100644 --- a/scheduler/synchro.c +++ b/scheduler/synchro.c @@ -8,7 +8,6 @@ #include #include #include -#include "k32obj.h" #include "heap.h" #include "process.h" #include "thread.h" @@ -85,17 +84,7 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, return WAIT_FAILED; } - for (i = 0; i < count; i++) - { - TRACE(win32,"handle %d is %08x\n",i,handles[i]); - server_handle[i] = HANDLE_GetServerHandle( PROCESS_Current(), handles[i], - K32OBJ_UNKNOWN, SYNCHRONIZE ); - if (server_handle[i] == -1) - { - ERR(win32,"No server handle for %08x\n",handles[i] ); - return WAIT_FAILED; - } - } + for (i = 0; i < count; i++) server_handle[i] = handles[i]; req.count = count; req.flags = 0; diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c index 06e2b5869a8..0337dd960fe 100644 --- a/scheduler/sysdeps.c +++ b/scheduler/sysdeps.c @@ -119,11 +119,11 @@ int SYSDEPS_SpawnThread( THDB *thread ) * SYSDEPS_ExitThread * * Exit a running thread; must not return. + * Must not make any reference to the thread structures (THDB etc.) as + * they have already been deleted. */ void SYSDEPS_ExitThread(void) { - THDB *thdb = THREAD_Current(); - close( thdb->socket ); _exit( 0 ); } diff --git a/scheduler/thread.c b/scheduler/thread.c index 8df13517188..6e75b2057a5 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -28,13 +28,6 @@ THDB *pCurrentThread; #endif -static void THREAD_Destroy( K32OBJ *obj ); - -const K32OBJ_OPS THREAD_Ops = -{ - THREAD_Destroy /* destroy */ -}; - /* Is threading code initialized? */ BOOL THREAD_InitDone = FALSE; @@ -173,8 +166,6 @@ THDB *THREAD_CreateInitialThread( PDB *pdb ) extern void server_init( int fd ); extern void select_loop(void); - initial_thdb.header.type = K32OBJ_THREAD; - initial_thdb.header.refcount = 1; initial_thdb.process = pdb; initial_thdb.teb.except = (void *)-1; initial_thdb.teb.self = &initial_thdb.teb; @@ -241,8 +232,6 @@ THDB *THREAD_Create( PDB *pdb, DWORD stack_size, BOOL alloc_stack16, { THDB *thdb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(THDB) ); if (!thdb) return NULL; - thdb->header.type = K32OBJ_THREAD; - thdb->header.refcount = 1; thdb->process = pdb; thdb->teb.except = (void *)-1; thdb->teb.htask16 = pdb->task; @@ -277,43 +266,6 @@ error: } -/*********************************************************************** - * THREAD_Destroy - */ -static void THREAD_Destroy( K32OBJ *ptr ) -{ - THDB *thdb = (THDB *)ptr; - THDB **pptr = &THREAD_First; - - assert( ptr->type == K32OBJ_THREAD ); - ptr->type = K32OBJ_UNKNOWN; - - while (*pptr && (*pptr != thdb)) pptr = &(*pptr)->next; - if (*pptr) *pptr = thdb->next; - - /* Free the associated memory */ - -#ifdef __i386__ - { - /* Check if we are deleting the current thread */ - WORD fs; - GET_FS( fs ); - if (fs == thdb->teb_sel) - { - GET_DS( fs ); - SET_FS( fs ); - } - } -#endif - CloseHandle( thdb->event ); - close( thdb->socket ); - SELECTOR_FreeBlock( thdb->teb_sel, 1 ); - if (thdb->teb.stack_sel) SELECTOR_FreeBlock( thdb->teb.stack_sel, 1 ); - HeapFree( SystemHeap, 0, thdb ); - -} - - /*********************************************************************** * THREAD_Start * @@ -336,24 +288,18 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack, LPTHREAD_START_ROUTINE start, LPVOID param, DWORD flags, LPDWORD id ) { - int server_handle = -1; - HANDLE handle = INVALID_HANDLE_VALUE; + int handle = -1; BOOL inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); - THDB *thread = THREAD_Create( PROCESS_Current(), stack, - TRUE, &server_handle, NULL, start, param ); + TRUE, &handle, NULL, start, param ); if (!thread) return INVALID_HANDLE_VALUE; - handle = HANDLE_Alloc( PROCESS_Current(), &thread->header, - THREAD_ALL_ACCESS, inherit, server_handle ); - if (handle == INVALID_HANDLE_VALUE) goto error; - if (SYSDEPS_SpawnThread( thread ) == -1) goto error; + if (SYSDEPS_SpawnThread( thread ) == -1) + { + CloseHandle( handle ); + return INVALID_HANDLE_VALUE; + } if (id) *id = (DWORD)thread->server_tid; return handle; - -error: - if (handle != INVALID_HANDLE_VALUE) CloseHandle( handle ); - K32OBJ_DecCount( &thread->header ); - return INVALID_HANDLE_VALUE; } @@ -367,26 +313,32 @@ void WINAPI ExitThread( DWORD code) /* [in] Exit code for this thread */ { THDB *thdb = THREAD_Current(); - LONG count; + THDB **pptr = &THREAD_First; + WORD ds; MODULE_InitializeDLLs( 0, DLL_THREAD_DETACH, NULL ); - SYSTEM_LOCK(); thdb->exit_code = code; /* cleanup the message queue, if there's one */ if (thdb->teb.queue) USER_QueueCleanup( thdb->teb.queue ); + CloseHandle( thdb->event ); + while (*pptr && (*pptr != thdb)) pptr = &(*pptr)->next; + if (*pptr) *pptr = thdb->next; + + /* Free the associated memory */ + + if (thdb->teb.stack_sel) SELECTOR_FreeBlock( thdb->teb.stack_sel, 1 ); + GET_DS( ds ); + SET_FS( ds ); + SELECTOR_FreeBlock( thdb->teb_sel, 1 ); + close( thdb->socket ); + HeapFree( SystemHeap, HEAP_NO_SERIALIZE, thdb ); + /* FIXME: should free the stack somehow */ -#if 0 - /* FIXME: We cannot do this; once the current thread is destroyed, - synchronization primitives do not work properly. */ - K32OBJ_DecCount( &thdb->header ); -#endif - /* Completely unlock the system lock just in case */ - count = SYSTEM_LOCK_COUNT(); - while (count--) SYSTEM_UNLOCK(); + SYSDEPS_ExitThread(); } @@ -653,8 +605,7 @@ INT WINAPI GetThreadPriority( { struct get_thread_info_request req; struct get_thread_info_reply reply; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_QUERY_INFORMATION ); + req.handle = hthread; CLIENT_SendRequest( REQ_GET_THREAD_INFO, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return THREAD_PRIORITY_ERROR_RETURN; @@ -674,9 +625,7 @@ BOOL WINAPI SetThreadPriority( INT priority) /* [in] Thread priority level */ { struct set_thread_info_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_SET_INFORMATION ); - if (req.handle == -1) return FALSE; + req.handle = hthread; req.priority = priority; req.mask = SET_THREAD_INFO_PRIORITY; CLIENT_SendRequest( REQ_SET_THREAD_INFO, -1, 1, &req, sizeof(req) ); @@ -690,9 +639,7 @@ BOOL WINAPI SetThreadPriority( DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) { struct set_thread_info_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hThread, - K32OBJ_THREAD, THREAD_SET_INFORMATION ); - if (req.handle == -1) return FALSE; + req.handle = hThread; req.affinity = dwThreadAffinityMask; req.mask = SET_THREAD_INFO_AFFINITY; CLIENT_SendRequest( REQ_SET_THREAD_INFO, -1, 1, &req, sizeof(req) ); @@ -713,9 +660,7 @@ BOOL WINAPI TerminateThread( DWORD exitcode) /* [in] Exit code for thread */ { struct terminate_thread_request req; - - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_THREAD, THREAD_TERMINATE ); + req.handle = handle; req.exit_code = exitcode; CLIENT_SendRequest( REQ_TERMINATE_THREAD, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); @@ -735,8 +680,7 @@ BOOL WINAPI GetExitCodeThread( { struct get_thread_info_request req; struct get_thread_info_reply reply; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_QUERY_INFORMATION ); + req.handle = hthread; CLIENT_SendRequest( REQ_GET_THREAD_INFO, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; if (exitcode) *exitcode = reply.exit_code; @@ -760,8 +704,7 @@ DWORD WINAPI ResumeThread( { struct resume_thread_request req; struct resume_thread_reply reply; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_SUSPEND_RESUME ); + req.handle = hthread; CLIENT_SendRequest( REQ_RESUME_THREAD, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0xffffffff; return reply.count; @@ -780,8 +723,7 @@ DWORD WINAPI SuspendThread( { struct suspend_thread_request req; struct suspend_thread_reply reply; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_SUSPEND_RESUME ); + req.handle = hthread; CLIENT_SendRequest( REQ_SUSPEND_THREAD, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0xffffffff; return reply.count; @@ -794,10 +736,9 @@ DWORD WINAPI SuspendThread( DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) { struct queue_apc_request req; - req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hthread, - K32OBJ_THREAD, THREAD_SET_CONTEXT ); - req.func = func; - req.param = (void *)data; + req.handle = hthread; + req.func = func; + req.param = (void *)data; CLIENT_SendRequest( REQ_QUEUE_APC, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitReply( NULL, NULL, 0 ); } diff --git a/win32/console.c b/win32/console.c index 0fb413b20f5..aeb68442a59 100644 --- a/win32/console.c +++ b/win32/console.c @@ -36,7 +36,6 @@ #include "winbase.h" #include "wine/winuser16.h" #include "wine/keyboard16.h" -#include "k32obj.h" #include "thread.h" #include "async.h" #include "file.h" @@ -49,10 +48,6 @@ #include "server/request.h" #include "server.h" -/* The CONSOLE kernel32 Object */ -typedef struct _CONSOLE { - K32OBJ header; -} CONSOLE; /* FIXME: Should be in an internal header file. OK, so which one? Used by CONSOLE_makecomplex. */ @@ -66,9 +61,7 @@ static BOOL CONSOLE_GetInfo( HANDLE handle, struct get_console_info_reply *reply { struct get_console_info_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; + req.handle = handle; CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) ); return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL ); } @@ -432,32 +425,8 @@ DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput ) */ BOOL WINAPI FreeConsole(VOID) { - - PDB *pdb = PROCESS_Current(); - CONSOLE *console; - - SYSTEM_LOCK(); - - console = (CONSOLE *)pdb->console; - - if (console == NULL) { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - CLIENT_SendRequest( REQ_FREE_CONSOLE, -1, 0 ); - if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS) - { - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); - return FALSE; - } - - HANDLE_CloseAll( pdb, &console->header ); - K32OBJ_DecCount( &console->header ); - pdb->console = NULL; - SYSTEM_UNLOCK(); - return TRUE; + CLIENT_SendRequest( REQ_FREE_CONSOLE, -1, 0 ); + return !CLIENT_WaitReply( NULL, NULL, 0 ); } @@ -470,29 +439,13 @@ HANDLE CONSOLE_OpenHandle( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES sa ) { struct open_console_request req; struct open_console_reply reply; - CONSOLE *console; - HANDLE handle; req.output = output; req.access = access; req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); - if (reply.handle == -1) return INVALID_HANDLE_VALUE; - - SYSTEM_LOCK(); - if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console)))) - { - SYSTEM_UNLOCK(); - return FALSE; - } - console->header.type = K32OBJ_CONSOLE; - console->header.refcount = 1; - handle = HANDLE_Alloc( PROCESS_Current(), &console->header, req.access, - req.inherit, reply.handle ); - SYSTEM_UNLOCK(); - K32OBJ_DecCount(&console->header); - return handle; + return reply.handle; } @@ -531,10 +484,6 @@ static BOOL CONSOLE_make_complex(HANDLE handle) } term.c_lflag = ~(ECHO|ICANON); - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_CONSOLE, 0 )) == -1) - return FALSE; - if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0) return FALSE; @@ -549,6 +498,7 @@ static BOOL CONSOLE_make_complex(HANDLE handle) exit(1); } + req.handle = handle; req.pid = xpid; CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(slave), 1, &req, sizeof(req) ); CLIENT_WaitReply( NULL, NULL, 0 ); @@ -591,37 +541,10 @@ BOOL WINAPI AllocConsole(VOID) { struct open_console_request req; struct open_console_reply reply; - PDB *pdb = PROCESS_Current(); - CONSOLE *console; HANDLE hIn, hOut, hErr; - SYSTEM_LOCK(); /* FIXME: really only need to lock the process */ - - console = (CONSOLE *)pdb->console; - - /* don't create a console if we already have one */ - if (console != NULL) { - SetLastError(ERROR_ACCESS_DENIED); - SYSTEM_UNLOCK(); - return FALSE; - } - - if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console)))) - { - SYSTEM_UNLOCK(); - return FALSE; - } - - console->header.type = K32OBJ_CONSOLE; - console->header.refcount = 1; - CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 0 ); - if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS) - { - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); - return FALSE; - } + if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS) return FALSE; req.output = 0; req.access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; @@ -629,35 +552,20 @@ BOOL WINAPI AllocConsole(VOID) CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS) { - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); + /* FIXME: free console */ return FALSE; } - if ((hIn = HANDLE_Alloc(pdb,&console->header, req.access, - FALSE, reply.handle)) == INVALID_HANDLE_VALUE) - { - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); - return FALSE; - } + hIn = reply.handle; req.output = 1; CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS) { CloseHandle(hIn); - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); + /* FIXME: free console */ return FALSE; } - if ((hOut = HANDLE_Alloc(pdb,&console->header, req.access, - FALSE, reply.handle)) == INVALID_HANDLE_VALUE) - { - CloseHandle(hIn); - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); - return FALSE; - } + hOut = reply.handle; if (!DuplicateHandle( GetCurrentProcess(), hOut, GetCurrentProcess(), &hErr, @@ -665,22 +573,15 @@ BOOL WINAPI AllocConsole(VOID) { CloseHandle(hIn); CloseHandle(hOut); - K32OBJ_DecCount(&console->header); - SYSTEM_UNLOCK(); return FALSE; } - if (pdb->console) K32OBJ_DecCount( pdb->console ); - pdb->console = (K32OBJ *)console; - K32OBJ_IncCount( pdb->console ); - /* NT resets the STD_*_HANDLEs on console alloc */ SetStdHandle(STD_INPUT_HANDLE, hIn); SetStdHandle(STD_OUTPUT_HANDLE, hOut); SetStdHandle(STD_ERROR_HANDLE, hErr); SetLastError(ERROR_SUCCESS); - SYSTEM_UNLOCK(); SetConsoleTitleA("Wine Console"); return TRUE; } @@ -714,9 +615,7 @@ BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode) struct get_console_mode_request req; struct get_console_mode_reply reply; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; + req.handle = hcon; CLIENT_SendRequest( REQ_GET_CONSOLE_MODE, -1, 1, &req, sizeof(req)); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; *mode = reply.mode; @@ -739,9 +638,7 @@ BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode ) { struct set_console_mode_request req; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; + req.handle = hcon; req.mode = mode; CLIENT_SendRequest( REQ_SET_CONSOLE_MODE, -1, 1, &req, sizeof(req)); return !CLIENT_WaitReply( NULL, NULL, 0 ); @@ -762,12 +659,7 @@ DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size) if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE) return 0; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - { - CloseHandle( hcon ); - return 0; - } + req.handle = hcon; CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) ); if (!CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply), title, size )) { @@ -913,9 +805,6 @@ BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput, struct read_console_input_request req; INPUT_RECORD ir; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hConsoleInput, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; TRACE(console,"(%d,%p,%ld,%p,%p)\n", hConsoleInput,lpBuffer,nNumberOfCharsToRead, lpNumberOfCharsRead,lpReserved @@ -923,6 +812,7 @@ BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput, CONSOLE_get_input(hConsoleInput,FALSE); + req.handle = hConsoleInput; req.count = 1; req.flush = 1; @@ -994,9 +884,7 @@ BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, struct read_console_input_request req; int len; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hConsoleInput, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; + req.handle = hConsoleInput; req.count = nLength; req.flush = 1; @@ -1035,9 +923,7 @@ BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle ) struct read_console_input_request req; int len; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; + req.handle = handle; req.count = -1; /* get all records */ req.flush = 1; CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); @@ -1058,11 +944,8 @@ BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer, struct read_console_input_request req; int len; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_CONSOLE, GENERIC_READ )) == -1) - return FALSE; - CONSOLE_get_input(handle,FALSE); + req.handle = handle; req.count = count; req.flush = 0; @@ -1098,9 +981,7 @@ BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer, struct write_console_input_request req; struct write_console_input_reply reply; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) - return FALSE; + req.handle = handle; req.count = count; CLIENT_SendRequest( REQ_WRITE_CONSOLE_INPUT, -1, 2, &req, sizeof(req), buffer, count * sizeof(*buffer) ); @@ -1121,47 +1002,6 @@ BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer, */ BOOL WINAPI SetConsoleTitleA(LPCSTR title) { -#if 0 - PDB *pdb = PROCESS_Current(); - CONSOLE *console; - DWORD written; - char titleformat[]="\033]2;%s\a"; /*this should work for xterms*/ - LPSTR titlestring; - BOOL ret=FALSE; - - TRACE(console,"(%s)\n",title); - - console = (CONSOLE *)pdb->console; - if (!console) - return FALSE; - if(console->title) /* Free old title, if there is one */ - HeapFree( SystemHeap, 0, console->title ); - console->title = (LPSTR)HeapAlloc(SystemHeap, 0,strlen(title)+1); - if(console->title) strcpy(console->title,title); - titlestring = HeapAlloc(GetProcessHeap(), 0,strlen(title)+strlen(titleformat)+1); - if (!titlestring) { - K32OBJ_DecCount(&console->header); - return FALSE; - } - - sprintf(titlestring,titleformat,title); -#if 0 - /* only set title for complex console (own xterm) */ - if (console->pid != -1) { - WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),titlestring,strlen(titlestring),&written,NULL); - if (written == strlen(titlestring)) - ret =TRUE; - } else - ret = TRUE; -#endif - HeapFree( GetProcessHeap(), 0, titlestring ); - K32OBJ_DecCount(&console->header); - return ret; - - - -#endif - struct set_console_info_request req; struct get_console_info_reply info; HANDLE hcon; @@ -1170,9 +1010,7 @@ BOOL WINAPI SetConsoleTitleA(LPCSTR title) if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE) return FALSE; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, - K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) - goto error; + req.handle = hcon; req.mask = SET_CONSOLE_INFO_TITLE; CLIENT_SendRequest( REQ_SET_CONSOLE_INFO, -1, 2, &req, sizeof(req), title, strlen(title)+1 ); @@ -1184,6 +1022,7 @@ BOOL WINAPI SetConsoleTitleA(LPCSTR title) WriteFile( hcon, title, strlen(title), &written, NULL ); WriteFile( hcon, "\a", 1, &written, NULL ); } + CloseHandle( hcon ); return TRUE; error: CloseHandle( hcon ); @@ -1307,9 +1146,7 @@ BOOL WINAPI SetConsoleCursorInfo( char buf[8]; DWORD xlen; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, - K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) - return FALSE; + req.handle = hcon; CONSOLE_make_complex(hcon); sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l'); WriteFile(hcon,buf,strlen(buf),&xlen,NULL); diff --git a/win32/device.c b/win32/device.c index 12b3cd18ba3..780177d73e3 100644 --- a/win32/device.c +++ b/win32/device.c @@ -272,9 +272,7 @@ static const struct VxDInfo *DEVICE_GetInfo( HANDLE handle ) struct get_file_info_request req; struct get_file_info_reply reply; - if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, - K32OBJ_FILE, 0 )) == -1) - return NULL; + req.handle = handle; CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) ); if (!CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) && (reply.type == FILE_TYPE_UNKNOWN) &&