From b3badc7dd357b23e6a6be4a36136c3ae69bc9726 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 6 Sep 2005 10:25:11 +0000 Subject: [PATCH] - rewrite kernel32:{Set|Get}PriorityClass on top of ntdll equivalent - priority for process in wineserver is now the NTDLL form (no longer the kernel32 one) --- dlls/kernel/process.c | 55 ++++++++++++++++++++++++++++++++++-------- dlls/kernel/toolhelp.c | 20 ++++++++++++++- dlls/ntdll/process.c | 33 ++++++++++++++++++++++--- include/winternl.h | 12 +++++++++ server/process.c | 5 ++-- 5 files changed, 108 insertions(+), 17 deletions(-) diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index 5ec428dbc62..c622f242a0e 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -2607,16 +2607,38 @@ HANDLE WINAPI CreateSocketHandle(void) */ BOOL WINAPI SetPriorityClass( HANDLE hprocess, DWORD priorityclass ) { - BOOL ret; - SERVER_START_REQ( set_process_info ) + NTSTATUS status; + PROCESS_PRIORITY_CLASS ppc; + + ppc.Foreground = FALSE; + switch (priorityclass) { - req->handle = hprocess; - req->priority = priorityclass; - req->mask = SET_PROCESS_INFO_PRIORITY; - ret = !wine_server_call_err( req ); + case IDLE_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_IDLE; break; + case BELOW_NORMAL_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_BELOW_NORMAL; break; + case NORMAL_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_NORMAL; break; + case ABOVE_NORMAL_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_ABOVE_NORMAL; break; + case HIGH_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_HIGH; break; + case REALTIME_PRIORITY_CLASS: + ppc.PriorityClass = PROCESS_PRIOCLASS_REALTIME; break; + default: + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; } - SERVER_END_REQ; - return ret; + + status = NtSetInformationProcess(hprocess, ProcessPriorityClass, + &ppc, sizeof(ppc)); + + if (status != STATUS_SUCCESS) + { + SetLastError( RtlNtStatusToDosError(status) ); + return FALSE; + } + return TRUE; } @@ -2630,8 +2652,21 @@ DWORD WINAPI GetPriorityClass(HANDLE hProcess) status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL); - if (status == STATUS_SUCCESS) return pbi.BasePriority; - SetLastError( RtlNtStatusToDosError(status) ); + if (status != STATUS_SUCCESS) + { + SetLastError( RtlNtStatusToDosError(status) ); + return 0; + } + switch (pbi.BasePriority) + { + case PROCESS_PRIOCLASS_IDLE: return IDLE_PRIORITY_CLASS; + case PROCESS_PRIOCLASS_BELOW_NORMAL: return BELOW_NORMAL_PRIORITY_CLASS; + case PROCESS_PRIOCLASS_NORMAL: return NORMAL_PRIORITY_CLASS; + case PROCESS_PRIOCLASS_ABOVE_NORMAL: return ABOVE_NORMAL_PRIORITY_CLASS; + case PROCESS_PRIOCLASS_HIGH: return HIGH_PRIORITY_CLASS; + case PROCESS_PRIOCLASS_REALTIME: return REALTIME_PRIORITY_CLASS; + } + SetLastError( ERROR_INVALID_PARAMETER ); return 0; } diff --git a/dlls/kernel/toolhelp.c b/dlls/kernel/toolhelp.c index 0a661a2005e..cfbe0e3f5c7 100644 --- a/dlls/kernel/toolhelp.c +++ b/dlls/kernel/toolhelp.c @@ -160,7 +160,25 @@ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY32W lppe, BOOL lppe->th32ModuleID = (DWORD)reply->module; lppe->cntThreads = reply->threads; lppe->th32ParentProcessID = reply->ppid; - lppe->pcPriClassBase = reply->priority; + switch (reply->priority) + { + case PROCESS_PRIOCLASS_IDLE: + lppe->pcPriClassBase = IDLE_PRIORITY_CLASS; break; + case PROCESS_PRIOCLASS_BELOW_NORMAL: + lppe->pcPriClassBase = BELOW_NORMAL_PRIORITY_CLASS; break; + case PROCESS_PRIOCLASS_NORMAL: + lppe->pcPriClassBase = NORMAL_PRIORITY_CLASS; break; + case PROCESS_PRIOCLASS_ABOVE_NORMAL: + lppe->pcPriClassBase = ABOVE_NORMAL_PRIORITY_CLASS; break; + case PROCESS_PRIOCLASS_HIGH: + lppe->pcPriClassBase = HIGH_PRIORITY_CLASS; break; + case PROCESS_PRIOCLASS_REALTIME: + lppe->pcPriClassBase = REALTIME_PRIORITY_CLASS; break; + default: + FIXME("Unknown NT priority class %d, setting to normal\n", reply->priority); + lppe->pcPriClassBase = NORMAL_PRIORITY_CLASS; + break; + } lppe->dwFlags = -1; /* FIXME */ if (unicode) { diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index 75b3417d78b..2444bc49bf8 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -302,9 +302,36 @@ NTSTATUS WINAPI NtSetInformationProcess( IN PVOID ProcessInformation, IN ULONG ProcessInformationLength) { - FIXME("(%p,0x%08x,%p,0x%08lx) stub\n", - ProcessHandle,ProcessInformationClass,ProcessInformation,ProcessInformationLength); - return 0; + NTSTATUS ret = STATUS_SUCCESS; + + switch (ProcessInformationClass) + { + case ProcessPriorityClass: + if (ProcessInformationLength != sizeof(PROCESS_PRIORITY_CLASS)) + return STATUS_INVALID_PARAMETER; + else + { + PROCESS_PRIORITY_CLASS* ppc = ProcessInformation; + + SERVER_START_REQ( set_process_info ) + { + req->handle = ProcessHandle; + /* FIXME Foreground isn't used */ + req->priority = ppc->PriorityClass; + req->mask = SET_PROCESS_INFO_PRIORITY; + ret = wine_server_call( req ); + } + SERVER_END_REQ; + } + break; + default: + FIXME("(%p,0x%08x,%p,0x%08lx) stub\n", + ProcessHandle,ProcessInformationClass,ProcessInformation, + ProcessInformationLength); + ret = STATUS_NOT_IMPLEMENTED; + break; + } + return ret; } /****************************************************************************** diff --git a/include/winternl.h b/include/winternl.h index 158531fe3e6..81f9020332c 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -932,6 +932,18 @@ typedef struct _PROCESS_BASIC_INFORMATION { #endif } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; +#define PROCESS_PRIOCLASS_IDLE 1 +#define PROCESS_PRIOCLASS_NORMAL 2 +#define PROCESS_PRIOCLASS_HIGH 3 +#define PROCESS_PRIOCLASS_REALTIME 4 +#define PROCESS_PRIOCLASS_BELOW_NORMAL 5 +#define PROCESS_PRIOCLASS_ABOVE_NORMAL 6 + +typedef struct _PROCESS_PRIORITY_CLASS { + BOOLEAN Foreground; + UCHAR PriorityClass; +} PROCESS_PRIORITY_CLASS, *PPROCESS_PRIORITY_CLASS; + typedef struct _RTL_HEAP_DEFINITION { ULONG Length; /* = sizeof(RTL_HEAP_DEFINITION) */ diff --git a/server/process.c b/server/process.c index a1d03d39a8a..8453f182145 100644 --- a/server/process.c +++ b/server/process.c @@ -37,8 +37,7 @@ #include #endif -#include "windef.h" -#include "winnt.h" +#include "winternl.h" #include "file.h" #include "handle.h" @@ -233,7 +232,7 @@ struct thread *create_process( int fd ) process->msg_fd = NULL; process->exit_code = STILL_ACTIVE; process->running_threads = 0; - process->priority = NORMAL_PRIORITY_CLASS; + process->priority = PROCESS_PRIOCLASS_NORMAL; process->affinity = 1; process->suspend = 0; process->create_flags = 0;