From b09582a890bd8ed88e4ad47b859b4a6b6b2b351e Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 27 Sep 2005 10:52:10 +0000 Subject: [PATCH] Implemented kernel32 process affinity handling on top on ntdll. --- dlls/kernel/process.c | 44 ++++++++++++++++++---------------- dlls/ntdll/process.c | 13 +++++++++- include/winbase.h | 2 +- include/wine/server_protocol.h | 5 ++-- server/process.c | 3 +-- server/protocol.def | 3 +-- server/trace.c | 3 +-- 7 files changed, 41 insertions(+), 32 deletions(-) diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index fe2fa5d87cd..f599729660e 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -2676,16 +2676,16 @@ DWORD WINAPI GetPriorityClass(HANDLE hProcess) */ BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask ) { - BOOL ret; - SERVER_START_REQ( set_process_info ) + NTSTATUS status; + + status = NtSetInformationProcess(hProcess, ProcessAffinityMask, + &affmask, sizeof(DWORD_PTR)); + if (!status) { - req->handle = hProcess; - req->affinity = affmask; - req->mask = SET_PROCESS_INFO_AFFINITY; - ret = !wine_server_call_err( req ); + SetLastError( RtlNtStatusToDosError(status) ); + return FALSE; } - SERVER_END_REQ; - return ret; + return TRUE; } @@ -2693,22 +2693,24 @@ BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask ) * GetProcessAffinityMask (KERNEL32.@) */ BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, - LPDWORD lpProcessAffinityMask, - LPDWORD lpSystemAffinityMask ) + PDWORD_PTR lpProcessAffinityMask, + PDWORD_PTR lpSystemAffinityMask ) { - BOOL ret = FALSE; - SERVER_START_REQ( get_process_info ) + PROCESS_BASIC_INFORMATION pbi; + NTSTATUS status; + + status = NtQueryInformationProcess(hProcess, + ProcessBasicInformation, + &pbi, sizeof(pbi), NULL); + if (status) { - req->handle = hProcess; - if (!wine_server_call_err( req )) - { - if (lpProcessAffinityMask) *lpProcessAffinityMask = reply->process_affinity; - if (lpSystemAffinityMask) *lpSystemAffinityMask = reply->system_affinity; - ret = TRUE; - } + SetLastError( RtlNtStatusToDosError(status) ); + return FALSE; } - SERVER_END_REQ; - return ret; + if (lpProcessAffinityMask) *lpProcessAffinityMask = pbi.AffinityMask; + /* FIXME */ + if (lpSystemAffinityMask) *lpSystemAffinityMask = 1; + return TRUE; } diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index 2444bc49bf8..8eb3051c994 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -143,7 +143,7 @@ NTSTATUS WINAPI NtQueryInformationProcess( { pbi.ExitStatus = reply->exit_code; pbi.PebBaseAddress = (DWORD)reply->peb; - pbi.AffinityMask = reply->process_affinity; + pbi.AffinityMask = reply->affinity; pbi.BasePriority = reply->priority; pbi.UniqueProcessId = reply->pid; pbi.InheritedFromUniqueProcessId = reply->ppid; @@ -306,6 +306,17 @@ NTSTATUS WINAPI NtSetInformationProcess( switch (ProcessInformationClass) { + case ProcessAffinityMask: + if (ProcessInformationLength != sizeof(DWORD_PTR)) return STATUS_INVALID_PARAMETER; + SERVER_START_REQ( set_process_info ) + { + req->handle = ProcessHandle; + req->affinity = *(PDWORD_PTR)ProcessInformation; + req->mask = SET_PROCESS_INFO_AFFINITY; + ret = wine_server_call( req ); + } + SERVER_END_REQ; + break; case ProcessPriorityClass: if (ProcessInformationLength != sizeof(PROCESS_PRIORITY_CLASS)) return STATUS_INVALID_PARAMETER; diff --git a/include/winbase.h b/include/winbase.h index f89602c4a1d..f5740852b62 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -1559,7 +1559,7 @@ BOOL WINAPI GetPrivateProfileStructA(LPCSTR,LPCSTR,LPVOID,UINT,LPCSTR); BOOL WINAPI GetPrivateProfileStructW(LPCWSTR,LPCWSTR,LPVOID,UINT,LPCWSTR); #define GetPrivateProfileStruct WINELIB_NAME_AW(GetPrivateProfileStruct) FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR); -BOOL WINAPI GetProcessAffinityMask(HANDLE,PDWORD,PDWORD); +BOOL WINAPI GetProcessAffinityMask(HANDLE,PDWORD_PTR,PDWORD_PTR); DWORD WINAPI GetProcessHeaps(DWORD,PHANDLE); DWORD WINAPI GetProcessId(HANDLE); BOOL WINAPI GetProcessIoCounters(HANDLE,PIO_COUNTERS); diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 77c548d2688..48dc8bd7d39 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -339,8 +339,7 @@ struct get_process_info_reply process_id_t ppid; int exit_code; int priority; - int process_affinity; - int system_affinity; + int affinity; void* peb; }; @@ -4207,6 +4206,6 @@ union generic_reply struct set_mailslot_info_reply set_mailslot_info_reply; }; -#define SERVER_PROTOCOL_VERSION 193 +#define SERVER_PROTOCOL_VERSION 194 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ diff --git a/server/process.c b/server/process.c index 8453f182145..c0452d8ca52 100644 --- a/server/process.c +++ b/server/process.c @@ -1034,8 +1034,7 @@ DECL_HANDLER(get_process_info) reply->ppid = process->parent ? get_process_id( process->parent ) : 0; reply->exit_code = process->exit_code; reply->priority = process->priority; - reply->process_affinity = process->affinity; - reply->system_affinity = 1; + reply->affinity = process->affinity; reply->peb = process->peb; release_object( process ); } diff --git a/server/protocol.def b/server/protocol.def index 118ffc04cb3..61a4e09dbab 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -309,8 +309,7 @@ struct security_descriptor process_id_t ppid; /* server process id of parent */ int exit_code; /* process exit code */ int priority; /* priority class */ - int process_affinity; /* process affinity mask */ - int system_affinity; /* system affinity mask */ + int affinity; /* process affinity mask */ void* peb; /* PEB address in process address space */ @END diff --git a/server/trace.c b/server/trace.c index 4a285952858..db86a582501 100644 --- a/server/trace.c +++ b/server/trace.c @@ -699,8 +699,7 @@ static void dump_get_process_info_reply( const struct get_process_info_reply *re fprintf( stderr, " ppid=%04x,", req->ppid ); fprintf( stderr, " exit_code=%d,", req->exit_code ); fprintf( stderr, " priority=%d,", req->priority ); - fprintf( stderr, " process_affinity=%d,", req->process_affinity ); - fprintf( stderr, " system_affinity=%d,", req->system_affinity ); + fprintf( stderr, " affinity=%d,", req->affinity ); fprintf( stderr, " peb=%p", req->peb ); }