Signed-off-by: Derek Lesho dereklesho52@Gmail.com ---
v3: Added a test and header definition.
dlls/ntoskrnl.exe/ntoskrnl.c | 20 ++++++++++++++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 17 +++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index f5dee07e2f..770bdfd4fa 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3245,6 +3245,26 @@ NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process) }
+/***************************************************** + * PsLookupThreadByThreadId (NTOSKRNL.EXE.@) + */ +NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE threadid, PETHREAD *thread) +{ + NTSTATUS status; + HANDLE hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, HandleToUlong(threadid) ); + + if (!hThread) + return STATUS_INVALID_PARAMETER; + + status = kernel_object_from_handle( hThread, PsThreadType, (void**)thread ); + + ObReferenceObject( *thread ); + + NtClose( hThread ); + return status; +} + + /***************************************************** * IoSetThreadHardErrorMode (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 43f47470a9..601506246e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -913,7 +913,7 @@ @ stub PsJobType @ stdcall PsLookupProcessByProcessId(ptr ptr) @ stub PsLookupProcessThreadByCid -@ stub PsLookupThreadByThreadId +@ stdcall PsLookupThreadByThreadId(ptr ptr) @ extern PsProcessType @ stub PsReferenceImpersonationToken @ stub PsReferencePrimaryToken diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 66465bb5ae..70831adede 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -826,6 +826,22 @@ static void test_ob_reference(const WCHAR *test_path) ok(!status, "ZwClose failed: %#x\n", status); }
+static void test_lookup_thread(void) +{ + NTSTATUS status; + PETHREAD thread = NULL; + + status = PsLookupThreadByThreadId(PsGetCurrentThreadId(), &thread); + ok(!status, "PsLookupThreadByThreadId failed: %#x\n", status); + ok((PKTHREAD)thread == KeGetCurrentThread(), "thread != KeGetCurrentThread\n"); + + if (thread) + ObDereferenceObject(thread); + + status = PsLookupThreadByThreadId(NULL, &thread); + ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status); +} + static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) { ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength; @@ -868,6 +884,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_stack_callout(); test_lookaside_list(); test_ob_reference(test_input->path); + test_lookup_thread();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index abe357fbc9..9b57ae7ad7 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
#endif
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 16 ++++++++++++++-- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + include/ddk/ntddk.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 770bdfd4fa..49592c6dc1 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2497,6 +2497,8 @@ static void *create_thread_object( HANDLE handle ) if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) thread->id = info.ClientId;
+ thread->critical_region = FALSE; + return thread; }
@@ -3431,7 +3433,8 @@ void WINAPI ExReleaseResourceForThreadLite( PERESOURCE resource, ERESOURCE_THREA */ void WINAPI KeEnterCriticalRegion(void) { - FIXME(": stub\n"); + TRACE(": semi-stub\n"); + KeGetCurrentThread()->critical_region = TRUE; }
/*********************************************************************** @@ -3439,7 +3442,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) { - FIXME(": stub\n"); + TRACE(": semi-stub\n"); + KeGetCurrentThread()->critical_region = FALSE; }
/*********************************************************************** @@ -4379,3 +4383,11 @@ ULONG WINAPI ExSetTimerResolution(ULONG time, BOOLEAN set_resolution) FIXME("stub: %u %d\n", time, set_resolution); return KeQueryTimeIncrement(); } + +/********************************************************************* + * KeAreApcsDisabled (NTOSKRNL.@) + */ +BOOLEAN WINAPI KeAreApcsDisabled(void) +{ + return KeGetCurrentThread()->critical_region; +} diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 601506246e..08de49e760 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -520,7 +520,7 @@ @ stdcall KeAcquireSpinLockAtDpcLevel(ptr) @ stdcall -arch=arm,arm64,x86_64 KeAcquireSpinLockRaiseToDpc(ptr) @ stub KeAddSystemServiceTable -@ stub KeAreApcsDisabled +@ stdcall KeAreApcsDisabled() @ stub KeAttachProcess @ stub KeBugCheck @ stub KeBugCheckEx diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index 152fde9320..ce2a402902 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -32,6 +32,7 @@ struct _KTHREAD { DISPATCHER_HEADER header; CLIENT_ID id; + BOOLEAN critical_region; };
void *alloc_kernel_object( POBJECT_TYPE type, HANDLE handle, SIZE_T size, LONG ref ) DECLSPEC_HIDDEN; diff --git a/include/ddk/ntddk.h b/include/ddk/ntddk.h index 719ba67c6a..f09f879032 100644 --- a/include/ddk/ntddk.h +++ b/include/ddk/ntddk.h @@ -213,6 +213,7 @@ NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE,PULONG,PCONFIGURATION_ PCONFIGURATION_TYPE,PULONG,PIO_QUERY_DEVICE_ROUTINE,PVOID); void WINAPI IoRegisterDriverReinitialization(PDRIVER_OBJECT,PDRIVER_REINITIALIZE,PVOID); NTSTATUS WINAPI IoRegisterShutdownNotification(PDEVICE_OBJECT); +BOOLEAN WINAPI KeAreApcsDisabled(void); NTSTATUS WINAPI KeExpandKernelStackAndCallout(PEXPAND_STACK_CALLOUT,void*,SIZE_T); void WINAPI KeSetTargetProcessorDpc(PRKDPC,CCHAR); BOOLEAN WINAPI MmIsAddressValid(void *);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50859
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
On 4/11/19 8:26 PM, Derek Lesho wrote:
@@ -3431,7 +3433,8 @@ void WINAPI ExReleaseResourceForThreadLite( PERESOURCE resource, ERESOURCE_THREA */ void WINAPI KeEnterCriticalRegion(void) {
- FIXME(": stub\n");
- TRACE(": semi-stub\n");
- KeGetCurrentThread()->critical_region = TRUE; }
According to MSDN, those may be called recursively, so you'd need a counter here instead.
Thanks,
Jacek
Thank you for all these reviews. I have submitted v4 to rebase on master and fix whitespace issues. I'll address all your issues in v5.
On Thu, Apr 11, 2019 at 3:35 PM Jacek Caban jacek@codeweavers.com wrote:
On 4/11/19 8:26 PM, Derek Lesho wrote:
@@ -3431,7 +3433,8 @@ void WINAPI ExReleaseResourceForThreadLite(
PERESOURCE resource, ERESOURCE_THREA
*/ void WINAPI KeEnterCriticalRegion(void) {
- FIXME(": stub\n");
- TRACE(": semi-stub\n");
- KeGetCurrentThread()->critical_region = TRUE; }
According to MSDN, those may be called recursively, so you'd need a counter here instead.
Thanks,
Jacek
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 16 ++++++++++++++-- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + include/ddk/ntddk.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 0365634772..191dbafdeb 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2484,6 +2484,8 @@ static void *create_thread_object( HANDLE handle ) if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) thread->id = info.ClientId;
+ thread->critical_region = FALSE; + return thread; }
@@ -3383,7 +3385,8 @@ NTSTATUS WINAPI IoCsqInitialize(PIO_CSQ csq, PIO_CSQ_INSERT_IRP insert_irp, PIO_ */ void WINAPI KeEnterCriticalRegion(void) { - FIXME(": stub\n"); + TRACE(": semi-stub\n"); + KeGetCurrentThread()->critical_region = TRUE; }
/*********************************************************************** @@ -3391,7 +3394,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) { - FIXME(": stub\n"); + TRACE(": semi-stub\n"); + KeGetCurrentThread()->critical_region = FALSE; }
/*********************************************************************** @@ -4323,3 +4327,11 @@ ULONG WINAPI ExSetTimerResolution(ULONG time, BOOLEAN set_resolution) FIXME("stub: %u %d\n", time, set_resolution); return KeQueryTimeIncrement(); } + +/********************************************************************* + * KeAreApcsDisabled (NTOSKRNL.@) + */ +BOOLEAN WINAPI KeAreApcsDisabled(void) +{ + return KeGetCurrentThread()->critical_region; +} diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index e08abb4150..ebba812a4e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -520,7 +520,7 @@ @ stdcall KeAcquireSpinLockAtDpcLevel(ptr) @ stdcall -arch=arm,arm64,x86_64 KeAcquireSpinLockRaiseToDpc(ptr) @ stub KeAddSystemServiceTable -@ stub KeAreApcsDisabled +@ stdcall KeAreApcsDisabled() @ stub KeAttachProcess @ stub KeBugCheck @ stub KeBugCheckEx diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index f5a76284cb..bfe4707265 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -32,6 +32,7 @@ struct _KTHREAD { DISPATCHER_HEADER header; CLIENT_ID id; + BOOLEAN critical_region; };
void *alloc_kernel_object( POBJECT_TYPE type, HANDLE handle, SIZE_T size, LONG ref ) DECLSPEC_HIDDEN; diff --git a/include/ddk/ntddk.h b/include/ddk/ntddk.h index 719ba67c6a..f09f879032 100644 --- a/include/ddk/ntddk.h +++ b/include/ddk/ntddk.h @@ -213,6 +213,7 @@ NTSTATUS WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE,PULONG,PCONFIGURATION_ PCONFIGURATION_TYPE,PULONG,PIO_QUERY_DEVICE_ROUTINE,PVOID); void WINAPI IoRegisterDriverReinitialization(PDRIVER_OBJECT,PDRIVER_REINITIALIZE,PVOID); NTSTATUS WINAPI IoRegisterShutdownNotification(PDEVICE_OBJECT); +BOOLEAN WINAPI KeAreApcsDisabled(void); NTSTATUS WINAPI KeExpandKernelStackAndCallout(PEXPAND_STACK_CALLOUT,void*,SIZE_T); void WINAPI KeSetTargetProcessorDpc(PRKDPC,CCHAR); BOOLEAN WINAPI MmIsAddressValid(void *);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50876
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- server/process.c | 46 +++++++++++++++++++++++++++------------------- server/process.h | 1 + 2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/server/process.c b/server/process.c index 473d3b1a27..520edaf0d8 100644 --- a/server/process.c +++ b/server/process.c @@ -66,28 +66,29 @@ static unsigned int process_map_access( struct object *obj, unsigned int access static void process_poll_event( struct fd *fd, int event ); static void process_destroy( struct object *obj ); static void terminate_process( struct process *process, struct thread *skip, int exit_code ); +static struct list *process_get_kernel_object_list( struct object *obj );
static const struct object_ops process_ops = { - sizeof(struct process), /* size */ - process_dump, /* dump */ - process_get_type, /* get_type */ - add_queue, /* add_queue */ - remove_queue, /* remove_queue */ - process_signaled, /* signaled */ - no_satisfied, /* satisfied */ - no_signal, /* signal */ - no_get_fd, /* get_fd */ - process_map_access, /* map_access */ - default_get_sd, /* get_sd */ - default_set_sd, /* set_sd */ - no_lookup_name, /* lookup_name */ - no_link_name, /* link_name */ - NULL, /* unlink_name */ - no_open_file, /* open_file */ - no_kernel_obj_list, /* get_kernel_obj_list */ - no_close_handle, /* close_handle */ - process_destroy /* destroy */ + sizeof(struct process), /* size */ + process_dump, /* dump */ + process_get_type, /* get_type */ + add_queue, /* add_queue */ + remove_queue, /* remove_queue */ + process_signaled, /* signaled */ + no_satisfied, /* satisfied */ + no_signal, /* signal */ + no_get_fd, /* get_fd */ + process_map_access, /* map_access */ + default_get_sd, /* get_sd */ + default_set_sd, /* set_sd */ + no_lookup_name, /* lookup_name */ + no_link_name, /* link_name */ + NULL, /* unlink_name */ + no_open_file, /* open_file */ + process_get_kernel_object_list, /* get_kernel_obj_list */ + no_close_handle, /* close_handle */ + process_destroy /* destroy */ };
static const struct fd_ops process_fd_ops = @@ -526,6 +527,7 @@ struct process *create_process( int fd, struct process *parent, int inherit_all, process->trace_data = 0; process->rawinput_mouse = NULL; process->rawinput_kbd = NULL; + list_init( &process->kernel_object ); list_init( &process->thread_list ); list_init( &process->locks ); list_init( &process->asyncs ); @@ -661,6 +663,12 @@ static unsigned int process_map_access( struct object *obj, unsigned int access return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL); }
+static struct list *process_get_kernel_object_list( struct object *obj ) +{ + struct process *process = (struct process *)obj; + return &process->kernel_object; +} + static void process_poll_event( struct fd *fd, int event ) { struct process *process = get_fd_user( fd ); diff --git a/server/process.h b/server/process.h index 4566a04b48..d9d29f0242 100644 --- a/server/process.h +++ b/server/process.h @@ -96,6 +96,7 @@ struct process struct list rawinput_devices;/* list of registered rawinput devices */ const struct rawinput_device *rawinput_mouse; /* rawinput mouse device, if any */ const struct rawinput_device *rawinput_kbd; /* rawinput keyboard device, if any */ + struct list kernel_object; /* list of kernel object pointers */ };
struct process_snapshot
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50860
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
On 4/11/19 8:26 PM, Derek Lesho wrote:
- sizeof(struct process), /* size */
- process_dump, /* dump */
- process_get_type, /* get_type */
- add_queue, /* add_queue */
- remove_queue, /* remove_queue */
- process_signaled, /* signaled */
- no_satisfied, /* satisfied */
- no_signal, /* signal */
- no_get_fd, /* get_fd */
- process_map_access, /* map_access */
- default_get_sd, /* get_sd */
- default_set_sd, /* set_sd */
- no_lookup_name, /* lookup_name */
- no_link_name, /* link_name */
- NULL, /* unlink_name */
- no_open_file, /* open_file */
- no_kernel_obj_list, /* get_kernel_obj_list */
- no_close_handle, /* close_handle */
- process_destroy /* destroy */
- sizeof(struct process), /* size */
- process_dump, /* dump */
- process_get_type, /* get_type */
- add_queue, /* add_queue */
- remove_queue, /* remove_queue */
- process_signaled, /* signaled */
- no_satisfied, /* satisfied */
- no_signal, /* signal */
- no_get_fd, /* get_fd */
- process_map_access, /* map_access */
- default_get_sd, /* get_sd */
- default_set_sd, /* set_sd */
- no_lookup_name, /* lookup_name */
- no_link_name, /* link_name */
- NULL, /* unlink_name */
- no_open_file, /* open_file */
- process_get_kernel_object_list, /* get_kernel_obj_list */
Please use a name consistent with other objects. It's slightly shorter so you'd avoid changing all those comments...
Jacek
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- server/process.c | 46 +++++++++++++++++++++++++++------------------- server/process.h | 1 + 2 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/server/process.c b/server/process.c index 473d3b1a27..520edaf0d8 100644 --- a/server/process.c +++ b/server/process.c @@ -66,28 +66,29 @@ static unsigned int process_map_access( struct object *obj, unsigned int access static void process_poll_event( struct fd *fd, int event ); static void process_destroy( struct object *obj ); static void terminate_process( struct process *process, struct thread *skip, int exit_code ); +static struct list *process_get_kernel_object_list( struct object *obj );
static const struct object_ops process_ops = { - sizeof(struct process), /* size */ - process_dump, /* dump */ - process_get_type, /* get_type */ - add_queue, /* add_queue */ - remove_queue, /* remove_queue */ - process_signaled, /* signaled */ - no_satisfied, /* satisfied */ - no_signal, /* signal */ - no_get_fd, /* get_fd */ - process_map_access, /* map_access */ - default_get_sd, /* get_sd */ - default_set_sd, /* set_sd */ - no_lookup_name, /* lookup_name */ - no_link_name, /* link_name */ - NULL, /* unlink_name */ - no_open_file, /* open_file */ - no_kernel_obj_list, /* get_kernel_obj_list */ - no_close_handle, /* close_handle */ - process_destroy /* destroy */ + sizeof(struct process), /* size */ + process_dump, /* dump */ + process_get_type, /* get_type */ + add_queue, /* add_queue */ + remove_queue, /* remove_queue */ + process_signaled, /* signaled */ + no_satisfied, /* satisfied */ + no_signal, /* signal */ + no_get_fd, /* get_fd */ + process_map_access, /* map_access */ + default_get_sd, /* get_sd */ + default_set_sd, /* set_sd */ + no_lookup_name, /* lookup_name */ + no_link_name, /* link_name */ + NULL, /* unlink_name */ + no_open_file, /* open_file */ + process_get_kernel_object_list, /* get_kernel_obj_list */ + no_close_handle, /* close_handle */ + process_destroy /* destroy */ };
static const struct fd_ops process_fd_ops = @@ -526,6 +527,7 @@ struct process *create_process( int fd, struct process *parent, int inherit_all, process->trace_data = 0; process->rawinput_mouse = NULL; process->rawinput_kbd = NULL; + list_init( &process->kernel_object ); list_init( &process->thread_list ); list_init( &process->locks ); list_init( &process->asyncs ); @@ -661,6 +663,12 @@ static unsigned int process_map_access( struct object *obj, unsigned int access return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL); }
+static struct list *process_get_kernel_object_list( struct object *obj ) +{ + struct process *process = (struct process *)obj; + return &process->kernel_object; +} + static void process_poll_event( struct fd *fd, int event ) { struct process *process = get_fd_user( fd ); diff --git a/server/process.h b/server/process.h index 4566a04b48..d9d29f0242 100644 --- a/server/process.h +++ b/server/process.h @@ -96,6 +96,7 @@ struct process struct list rawinput_devices;/* list of registered rawinput devices */ const struct rawinput_device *rawinput_mouse; /* rawinput mouse device, if any */ const struct rawinput_device *rawinput_kbd; /* rawinput keyboard device, if any */ + struct list kernel_object; /* list of kernel object pointers */ };
struct process_snapshot
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50877
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 16 +++++++++++++++- dlls/ntoskrnl.exe/ntoskrnl_private.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 49592c6dc1..b68de7b250 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2464,15 +2464,29 @@ NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING Redi }
+static void *create_process_object( HANDLE handle ); + static const WCHAR process_type_name[] = {'P','r','o','c','e','s','s',0};
static struct _OBJECT_TYPE process_type = { - process_type_name + process_type_name, + create_process_object };
POBJECT_TYPE PsProcessType = &process_type;
+static void *create_process_object( HANDLE handle ) +{ + PEPROCESS process; + + if (!(process = alloc_kernel_object( PsProcessType, handle, sizeof(*process), 0 ))) return NULL; + + process->header.Type = 3; + process->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */ + return process; +} +
/*********************************************************************** * IoGetCurrentProcess / PsGetCurrentProcess (NTOSKRNL.EXE.@) diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index ce2a402902..b4601a9f83 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -28,6 +28,10 @@ struct _OBJECT_TYPE void (*release)(void*); /* called when the last reference is released */ };
+struct _EPROCESS { + DISPATCHER_HEADER header; +}; + struct _KTHREAD { DISPATCHER_HEADER header;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50861
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
On 4/11/19 8:26 PM, Derek Lesho wrote:
Signed-off-by: Derek Lesho dereklesho52@Gmail.com
dlls/ntoskrnl.exe/ntoskrnl.c | 16 +++++++++++++++- dlls/ntoskrnl.exe/ntoskrnl_private.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 49592c6dc1..b68de7b250 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2464,15 +2464,29 @@ NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING Redi }
+static void *create_process_object( HANDLE handle );
If you move implementation here, you may avoid forward declaration here (file object has it as well, that was needed before the patch for NULL type arguments).
static const WCHAR process_type_name[] = {'P','r','o','c','e','s','s',0};
static struct _OBJECT_TYPE process_type = {
- process_type_name
process_type_name,
create_process_object };
POBJECT_TYPE PsProcessType = &process_type;
+static void *create_process_object( HANDLE handle ) +{
- PEPROCESS process;
- if (!(process = alloc_kernel_object( PsProcessType, handle, sizeof(*process), 0 ))) return NULL;
- process->header.Type = 3;
- process->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */
It would be nice to have a simple test for those. The test may be in later patch (probably together with IoGetCurrentProcess). You could check the Type field and make sure that KeWaitForSingleObject returns timeout.
Jacek
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 16 +++++++++++++++- dlls/ntoskrnl.exe/ntoskrnl_private.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 191dbafdeb..6edb7037a0 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2451,15 +2451,29 @@ NTSTATUS WINAPI FsRtlRegisterUncProvider(PHANDLE MupHandle, PUNICODE_STRING Redi }
+static void *create_process_object( HANDLE handle ); + static const WCHAR process_type_name[] = {'P','r','o','c','e','s','s',0};
static struct _OBJECT_TYPE process_type = { - process_type_name + process_type_name, + create_process_object };
POBJECT_TYPE PsProcessType = &process_type;
+static void *create_process_object( HANDLE handle ) +{ + PEPROCESS process; + + if (!(process = alloc_kernel_object( PsProcessType, handle, sizeof(*process), 0 ))) return NULL; + + process->header.Type = 3; + process->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */ + return process; +} +
/*********************************************************************** * IoGetCurrentProcess / PsGetCurrentProcess (NTOSKRNL.EXE.@) diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index bfe4707265..fe89625d4c 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -28,6 +28,10 @@ struct _OBJECT_TYPE void (*release)(void*); /* called when the last reference is released */ };
+struct _EPROCESS { + DISPATCHER_HEADER header; +}; + struct _KTHREAD { DISPATCHER_HEADER header;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50878
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 15 ++++++++++++--- include/ddk/ntifs.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index b68de7b250..80a6fa89f7 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3255,9 +3255,18 @@ NTSTATUS WINAPI PsSetLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE routine) */ NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process) { - static int once; - if (!once++) FIXME("(%p %p) stub\n", processid, process); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS status; + HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, HandleToUlong(processid) ); + + if (!hProcess) + return STATUS_INVALID_PARAMETER; + + status = kernel_object_from_handle( hProcess, PsProcessType, (void**)process ); + + ObReferenceObject( *process ); + + NtClose( hProcess ); + return status; }
diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index 9b57ae7ad7..ec4d1d5aa7 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50862
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 15 ++++++++++++--- include/ddk/ntifs.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 6edb7037a0..4685f3c394 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3242,9 +3242,18 @@ NTSTATUS WINAPI PsSetLoadImageNotifyRoutine(PLOAD_IMAGE_NOTIFY_ROUTINE routine) */ NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process) { - static int once; - if (!once++) FIXME("(%p %p) stub\n", processid, process); - return STATUS_NOT_IMPLEMENTED; + NTSTATUS status; + HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, HandleToUlong(processid) ); + + if (!hProcess) + return STATUS_INVALID_PARAMETER; + + status = kernel_object_from_handle( hProcess, PsProcessType, (void**)process ); + + ObReferenceObject( *process ); + + NtClose( hProcess ); + return status; }
diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index 9b57ae7ad7..ec4d1d5aa7 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50879
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Jacek says that duplicating and closing the sent handle in kernel_object_from_handle every time would add unecessary overhead. --- dlls/ntoskrnl.exe/ntoskrnl.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 80a6fa89f7..03f6d78759 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2500,6 +2500,7 @@ PEPROCESS WINAPI IoGetCurrentProcess(void)
static void *create_thread_object( HANDLE handle ) { + NTSTATUS status; THREAD_BASIC_INFORMATION info; struct _KTHREAD *thread;
@@ -2508,8 +2509,20 @@ static void *create_thread_object( HANDLE handle ) thread->header.Type = 6; thread->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */
- if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) + if (!(status = NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL ))) thread->id = info.ClientId; + else if (status == STATUS_ACCESS_DENIED) + { + HANDLE info_handle; + + DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), + &info_handle, THREAD_QUERY_LIMITED_INFORMATION, FALSE, 0); + + if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) + thread->id = info.ClientId; + + NtClose( info_handle ); + }
thread->critical_region = FALSE;
@@ -2539,7 +2552,7 @@ PRKTHREAD WINAPI KeGetCurrentThread(void) HANDLE handle = GetCurrentThread();
/* FIXME: we shouldn't need it, GetCurrentThread() should be client thread already */ - if (GetCurrentThreadId() == request_thread) handle = OpenThread( 0, FALSE, client_tid ); + if (GetCurrentThreadId() == request_thread) handle = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, client_tid );
kernel_object_from_handle( handle, PsThreadType, (void**)&thread ); if (handle != GetCurrentThread()) NtClose( handle );
Signed-off-by: Derek Lesho dereklesho52@Gmail.com
On Thu, Apr 11, 2019 at 2:27 PM Derek Lesho dereklesho52@gmail.com wrote:
Jacek says that duplicating and closing the sent handle in kernel_object_from_handle every time would add unecessary overhead.
dlls/ntoskrnl.exe/ntoskrnl.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 80a6fa89f7..03f6d78759 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2500,6 +2500,7 @@ PEPROCESS WINAPI IoGetCurrentProcess(void)
static void *create_thread_object( HANDLE handle ) {
- NTSTATUS status; THREAD_BASIC_INFORMATION info; struct _KTHREAD *thread;
@@ -2508,8 +2509,20 @@ static void *create_thread_object( HANDLE handle ) thread->header.Type = 6; thread->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */
- if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info,
sizeof(info), NULL ))
- if (!(status = NtQueryInformationThread( handle,
ThreadBasicInformation, &info, sizeof(info), NULL ))) thread->id = info.ClientId;
- else if (status == STATUS_ACCESS_DENIED)
- {
HANDLE info_handle;
DuplicateHandle( GetCurrentProcess(), handle,
GetCurrentProcess(),
&info_handle, THREAD_QUERY_LIMITED_INFORMATION,
FALSE, 0);
if (!NtQueryInformationThread( handle, ThreadBasicInformation,
&info, sizeof(info), NULL ))
thread->id = info.ClientId;
NtClose( info_handle );
}
thread->critical_region = FALSE;
@@ -2539,7 +2552,7 @@ PRKTHREAD WINAPI KeGetCurrentThread(void) HANDLE handle = GetCurrentThread();
/* FIXME: we shouldn't need it, GetCurrentThread() should be
client thread already */
if (GetCurrentThreadId() == request_thread) handle = OpenThread(
0, FALSE, client_tid );
if (GetCurrentThreadId() == request_thread) handle = OpenThread(
THREAD_QUERY_LIMITED_INFORMATION, FALSE, client_tid );
kernel_object_from_handle( handle, PsThreadType, (void**)&thread
); if (handle != GetCurrentThread()) NtClose( handle ); -- 2.20.1
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50863
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 485 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 485 Task: Patch failed to apply
Jacek says that duplicating and closing the sent handle in kernel_object_from_handle every time would add unecessary overhead.
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 4685f3c394..1cfc1e1712 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2487,6 +2487,7 @@ PEPROCESS WINAPI IoGetCurrentProcess(void)
static void *create_thread_object( HANDLE handle ) { + NTSTATUS status; THREAD_BASIC_INFORMATION info; struct _KTHREAD *thread;
@@ -2495,8 +2496,20 @@ static void *create_thread_object( HANDLE handle ) thread->header.Type = 6; thread->header.WaitListHead.Blink = INVALID_HANDLE_VALUE; /* mark as kernel object */
- if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) + if (!(status = NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL ))) thread->id = info.ClientId; + else if (status == STATUS_ACCESS_DENIED) + { + HANDLE info_handle; + + DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), + &info_handle, THREAD_QUERY_LIMITED_INFORMATION, FALSE, 0); + + if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) + thread->id = info.ClientId; + + NtClose( info_handle ); + }
thread->critical_region = FALSE;
@@ -2526,7 +2539,7 @@ PRKTHREAD WINAPI KeGetCurrentThread(void) HANDLE handle = GetCurrentThread();
/* FIXME: we shouldn't need it, GetCurrentThread() should be client thread already */ - if (GetCurrentThreadId() == request_thread) handle = OpenThread( 0, FALSE, client_tid ); + if (GetCurrentThreadId() == request_thread) handle = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, client_tid );
kernel_object_from_handle( handle, PsThreadType, (void**)&thread ); if (handle != GetCurrentThread()) NtClose( handle );
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50880
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=29460
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 ++++-- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + dlls/ntoskrnl.exe/tests/driver.c | 1 - 3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 03f6d78759..11dd41f90e 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2493,8 +2493,7 @@ static void *create_process_object( HANDLE handle ) */ PEPROCESS WINAPI IoGetCurrentProcess(void) { - FIXME("() stub\n"); - return NULL; + return KeGetCurrentThread()->process; }
@@ -2524,6 +2523,9 @@ static void *create_thread_object( HANDLE handle ) NtClose( info_handle ); }
+ PsLookupProcessByProcessId( thread->id.UniqueProcess, &thread->process ); + ObDereferenceObject( thread->process ); + thread->critical_region = FALSE;
return thread; diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index b4601a9f83..940ff526f9 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -36,6 +36,7 @@ struct _KTHREAD { DISPATCHER_HEADER header; CLIENT_ID id; + PEPROCESS process; BOOLEAN critical_region; };
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 70831adede..1c12b9d9f0 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -314,7 +314,6 @@ static void test_currentprocess(void) NTSTATUS ret;
current = IoGetCurrentProcess(); -todo_wine ok(current != NULL, "Expected current process to be non-NULL\n");
thread = PsGetCurrentThread();
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50864
Your paranoid android.
=== build (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=29460
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 ++++-- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + dlls/ntoskrnl.exe/tests/driver.c | 1 - 3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 1cfc1e1712..24a4d9455b 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2480,8 +2480,7 @@ static void *create_process_object( HANDLE handle ) */ PEPROCESS WINAPI IoGetCurrentProcess(void) { - FIXME("() stub\n"); - return NULL; + return KeGetCurrentThread()->process; }
@@ -2511,6 +2510,9 @@ static void *create_thread_object( HANDLE handle ) NtClose( info_handle ); }
+ PsLookupProcessByProcessId( thread->id.UniqueProcess, &thread->process ); + ObDereferenceObject( thread->process ); + thread->critical_region = FALSE;
return thread; diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index fe89625d4c..7ddbd002d7 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -36,6 +36,7 @@ struct _KTHREAD { DISPATCHER_HEADER header; CLIENT_ID id; + PEPROCESS process; BOOLEAN critical_region; };
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 75bf934445..79923b9852 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -320,7 +320,6 @@ static void test_currentprocess(void) NTSTATUS ret;
current = IoGetCurrentProcess(); -todo_wine ok(current != NULL, "Expected current process to be non-NULL\n");
thread = PsGetCurrentThread();
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50881
Your paranoid android.
=== build (build log) ===
collect2: error: ld returned 1 exit status Makefile:204: recipe for target 'driver.dll' failed Makefile:7646: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The exe32 Wine crossbuild failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 +++++- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 11dd41f90e..625878d8dd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -91,7 +91,7 @@ static const WCHAR servicesW[] = {'\','R','e','g','i','s','t','r','y', #define MAX_SERVICE_NAME 260
/* tid of the thread running client request */ -static DWORD request_thread; +static DWORD request_thread = 0;
/* tid of the client thread */ static DWORD client_tid; @@ -940,6 +940,8 @@ static void unload_driver( struct wine_rb_entry *entry, void *context ) CloseServiceHandle( (void *)service_handle ); }
+PEPROCESS PsInitialSystemProcess = NULL; + /*********************************************************************** * wine_ntoskrnl_main_loop (Not a Windows API) */ @@ -953,6 +955,8 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) void *in_buff = NULL; HANDLE handles[2];
+ /* Set the system process global before setting up the request thread trickery */ + PsInitialSystemProcess = IoGetCurrentProcess(); request_thread = GetCurrentThreadId();
handles[0] = stop_event; diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 08de49e760..f948c6befe 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -905,7 +905,7 @@ @ stub PsGetThreadWin32Thread @ stdcall PsGetVersion(ptr ptr ptr ptr) @ stdcall PsImpersonateClient(ptr ptr long long long) -@ stub PsInitialSystemProcess +@ extern PsInitialSystemProcess @ stub PsIsProcessBeingDebugged @ stub PsIsSystemThread @ stub PsIsThreadImpersonating
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50865
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 +++++- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 24a4d9455b..eec14b7608 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -91,7 +91,7 @@ static const WCHAR servicesW[] = {'\','R','e','g','i','s','t','r','y', #define MAX_SERVICE_NAME 260
/* tid of the thread running client request */ -static DWORD request_thread; +static DWORD request_thread = 0;
/* tid of the client thread */ static DWORD client_tid; @@ -940,6 +940,8 @@ static void unload_driver( struct wine_rb_entry *entry, void *context ) CloseServiceHandle( (void *)service_handle ); }
+PEPROCESS PsInitialSystemProcess = NULL; + /*********************************************************************** * wine_ntoskrnl_main_loop (Not a Windows API) */ @@ -953,6 +955,8 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event ) void *in_buff = NULL; HANDLE handles[2];
+ /* Set the system process global before setting up the request thread trickery */ + PsInitialSystemProcess = IoGetCurrentProcess(); request_thread = GetCurrentThreadId();
handles[0] = stop_event; diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index ebba812a4e..7f09ba644c 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -905,7 +905,7 @@ @ stub PsGetThreadWin32Thread @ stdcall PsGetVersion(ptr ptr ptr ptr) @ stdcall PsImpersonateClient(ptr ptr long long long) -@ stub PsInitialSystemProcess +@ extern PsInitialSystemProcess @ stub PsIsProcessBeingDebugged @ stub PsIsSystemThread @ stub PsIsThreadImpersonating
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50882
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
On 4/11/19 8:27 PM, Derek Lesho wrote:
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 11dd41f90e..625878d8dd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -91,7 +91,7 @@ static const WCHAR servicesW[] = {'\','R','e','g','i','s','t','r','y', #define MAX_SERVICE_NAME 260
/* tid of the thread running client request */ -static DWORD request_thread; +static DWORD request_thread = 0;
There is no need for that, static variables are zeroed anyway.
Jacek
Ah, I did not know that, thanks.
On Thu, Apr 11, 2019 at 3:45 PM Jacek Caban jacek@codeweavers.com wrote:
On 4/11/19 8:27 PM, Derek Lesho wrote:
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 11dd41f90e..625878d8dd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -91,7 +91,7 @@ static const WCHAR servicesW[] =
{'\','R','e','g','i','s','t','r','y',
#define MAX_SERVICE_NAME 260
/* tid of the thread running client request */ -static DWORD request_thread; +static DWORD request_thread = 0;
There is no need for that, static variables are zeroed anyway.
Jacek
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 9 +++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 18 ++++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 625878d8dd..743a574594 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3028,6 +3028,15 @@ HANDLE WINAPI PsGetCurrentThreadId(void) }
+/*********************************************************************** + * PsIsSystemThread (NTOSKRNL.EXE.@) + */ +BOOLEAN WINAPI PsIsSystemThread(PETHREAD thread) +{ + return ((PKTHREAD)thread)->process == PsInitialSystemProcess; +} + + /*********************************************************************** * PsGetVersion (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index f948c6befe..399258cdfd 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -907,7 +907,7 @@ @ stdcall PsImpersonateClient(ptr ptr long long long) @ extern PsInitialSystemProcess @ stub PsIsProcessBeingDebugged -@ stub PsIsSystemThread +@ stdcall PsIsSystemThread(ptr) @ stub PsIsThreadImpersonating @ stub PsIsThreadTerminating @ stub PsJobType diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 1c12b9d9f0..d2f51e3917 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -29,6 +29,7 @@ #include "winternl.h" #include "winioctl.h" #include "ddk/ntddk.h" +#include "ddk/ntifs.h" #include "ddk/wdm.h"
#include "driver.h" @@ -841,6 +842,22 @@ static void test_lookup_thread(void) ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status); }
+static void WINAPI system_thread( void *arg ) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + ok((result), "got %u\n", result); + + PsTerminateSystemThread( STATUS_SUCCESS ); +} + +static void test_system_thread(void) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + ok(!(result), "got %u\n", result); + + run_thread( system_thread, (void*)0 ); +} + static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) { ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength; @@ -884,6 +901,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_lookaside_list(); test_ob_reference(test_input->path); test_lookup_thread(); + test_system_thread();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index ec4d1d5aa7..2c61329d9e 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +BOOLEAN WINAPI PsIsSystemThread(PETHREAD); NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50866
Your paranoid android.
=== build (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 9 +++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 18 ++++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index eec14b7608..f74c2362de 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3015,6 +3015,15 @@ HANDLE WINAPI PsGetCurrentThreadId(void) }
+/*********************************************************************** + * PsIsSystemThread (NTOSKRNL.EXE.@) + */ +BOOLEAN WINAPI PsIsSystemThread(PETHREAD thread) +{ + return ((PKTHREAD)thread)->process == PsInitialSystemProcess; +} + + /*********************************************************************** * PsGetVersion (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 7f09ba644c..8c347999ba 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -907,7 +907,7 @@ @ stdcall PsImpersonateClient(ptr ptr long long long) @ extern PsInitialSystemProcess @ stub PsIsProcessBeingDebugged -@ stub PsIsSystemThread +@ stdcall PsIsSystemThread(ptr) @ stub PsIsThreadImpersonating @ stub PsIsThreadTerminating @ stub PsJobType diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index 79923b9852..0968581114 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -29,6 +29,7 @@ #include "winternl.h" #include "winioctl.h" #include "ddk/ntddk.h" +#include "ddk/ntifs.h" #include "ddk/wdm.h"
#include "driver.h" @@ -1182,6 +1183,22 @@ static void test_lookup_thread(void) ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status); }
+static void WINAPI system_thread( void *arg ) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + ok((result), "got %u\n", result); + + PsTerminateSystemThread( STATUS_SUCCESS ); +} + +static void test_system_thread(void) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + ok(!(result), "got %u\n", result); + + run_thread( system_thread, (void*)0 ); +} + static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) { ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength; @@ -1226,6 +1243,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_ob_reference(test_input->path); test_resource(); test_lookup_thred(); + test_system_thread();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index ec4d1d5aa7..2c61329d9e 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +BOOLEAN WINAPI PsIsSystemThread(PETHREAD); NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50883
Your paranoid android.
=== build (build log) ===
collect2: error: ld returned 1 exit status Makefile:204: recipe for target 'driver.dll' failed Makefile:7646: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The exe32 Wine crossbuild failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/hal/hal.c | 9 ++++++++- dlls/ntoskrnl.exe/sync.c | 14 ++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c index 269a551f17..d8452952f1 100644 --- a/dlls/hal/hal.c +++ b/dlls/hal/hal.c @@ -89,9 +89,16 @@ void WINAPI ExReleaseFastMutex( FAST_MUTEX *mutex ) DEFINE_FASTCALL1_WRAPPER( ExTryToAcquireFastMutex ) BOOLEAN WINAPI ExTryToAcquireFastMutex( FAST_MUTEX *mutex ) { + BOOLEAN ret; + TRACE("mutex %p.\n", mutex);
- return (InterlockedCompareExchange( &mutex->Count, 0, 1 ) == 1); + ret = (InterlockedCompareExchange( &mutex->Count, 0, 1 ) == 1); + + if (ret) + mutex->Owner = KeGetCurrentThread(); + + return ret; }
DEFINE_FASTCALL1_WRAPPER( KfAcquireSpinLock ) diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 3085543727..bb2d318e56 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -668,13 +668,12 @@ PSLIST_ENTRY WINAPI NTOSKRNL_ExInterlockedPushEntrySList( PSLIST_HEADER list, PS DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutexUnsafe) void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) { - LONG count; - TRACE("mutex %p.\n", mutex);
- count = InterlockedDecrement( &mutex->Count ); - if (count < 0) + if (InterlockedDecrement(&mutex->Count) < 0) KeWaitForSingleObject( &mutex->Event, Executive, KernelMode, FALSE, NULL ); + + mutex->Owner = KeGetCurrentThread(); }
/*********************************************************************** @@ -683,11 +682,10 @@ void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutexUnsafe) void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) { - LONG count; - TRACE("mutex %p.\n", mutex);
- count = InterlockedIncrement( &mutex->Count ); - if (count < 1) + mutex->Owner = NULL; + + if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50867
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/hal/hal.c | 9 ++++++++- dlls/ntoskrnl.exe/sync.c | 14 ++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c index 269a551f17..d8452952f1 100644 --- a/dlls/hal/hal.c +++ b/dlls/hal/hal.c @@ -89,9 +89,16 @@ void WINAPI ExReleaseFastMutex( FAST_MUTEX *mutex ) DEFINE_FASTCALL1_WRAPPER( ExTryToAcquireFastMutex ) BOOLEAN WINAPI ExTryToAcquireFastMutex( FAST_MUTEX *mutex ) { + BOOLEAN ret; + TRACE("mutex %p.\n", mutex);
- return (InterlockedCompareExchange( &mutex->Count, 0, 1 ) == 1); + ret = (InterlockedCompareExchange( &mutex->Count, 0, 1 ) == 1); + + if (ret) + mutex->Owner = KeGetCurrentThread(); + + return ret; }
DEFINE_FASTCALL1_WRAPPER( KfAcquireSpinLock ) diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index fbe9dbe9da..e97c6993f9 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -696,13 +696,12 @@ PSLIST_ENTRY WINAPI NTOSKRNL_ExInterlockedPushEntrySList( PSLIST_HEADER list, PS DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutexUnsafe) void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) { - LONG count; - TRACE("mutex %p.\n", mutex);
- count = InterlockedDecrement( &mutex->Count ); - if (count < 0) + if (InterlockedDecrement(&mutex->Count) < 0) KeWaitForSingleObject( &mutex->Event, Executive, KernelMode, FALSE, NULL ); + + mutex->Owner = KeGetCurrentThread(); }
/*********************************************************************** @@ -711,12 +710,11 @@ void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutexUnsafe) void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) { - LONG count; - TRACE("mutex %p.\n", mutex);
- count = InterlockedIncrement( &mutex->Count ); - if (count < 1) + mutex->Owner = NULL; + + if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50884
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Signed-off-by: Derek Lesho dereklesho52@Gmail.com ---
v3: Removed IRQL raising/restoring functionality, since it needs a better implementation / more tests. Also marked it as x86_64 only as ZF recommended.
dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/sync.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 399258cdfd..5ec5e492b2 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall -arch=x86_64 ExAcquireFastMutex(ptr) @ stub ExAcquireRundownProtection @ stub ExAcquireRundownProtectionEx @ stub ExInitializeRundownProtection @@ -9,6 +10,7 @@ @ stdcall -fastcall -arch=i386 ExInterlockedPushEntrySList (ptr ptr ptr) NTOSKRNL_ExInterlockedPushEntrySList @ stub ExReInitializeRundownProtection @ stdcall -fastcall ExReleaseFastMutexUnsafe(ptr) +@ stdcall -arch=x86_64 ExReleaseFastMutex(ptr) @ stdcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index bb2d318e56..20fefce39f 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -689,3 +689,24 @@ void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); } + + +/********************************************************************* + * ExAcquireFastMutex (NTOSKRNL.@) + */ +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{ + /* TODO: The safe variant raises thread to APC_LEVEL + and stores the previous IRQL in mutex->OldIrql */ + ExAcquireFastMutexUnsafe( mutex ); +} + + + /********************************************************************* + * ExReleaseFastMutex (NTOSKRNL.@) + */ +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{ + ExReleaseFastMutexUnsafe( mutex ); + /* TODO: the safe variant restores the IRQL to mutex->OldIrql */ +}
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50868
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 484 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/sync.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 8c347999ba..d6edf6143a 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall -arch=x86_64 ExAcquireFastMutex(ptr) @ stub ExAcquireRundownProtection @ stub ExAcquireRundownProtectionEx @ stub ExInitializeRundownProtection @@ -9,6 +10,7 @@ @ stdcall -fastcall -arch=i386 ExInterlockedPushEntrySList (ptr ptr ptr) NTOSKRNL_ExInterlockedPushEntrySList @ stub ExReInitializeRundownProtection @ stdcall -fastcall ExReleaseFastMutexUnsafe(ptr) +@ stdcall -arch=x86_64 ExReleaseFastMutex(ptr) @ stdcall -fastcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index e97c6993f9..11fc945041 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -1167,3 +1167,24 @@ ULONG WINAPI ExIsResourceAcquiredSharedLite( ERESOURCE *resource )
return ret; } + + +/********************************************************************* + * ExAcquireFastMutex (NTOSKRNL.@) + */ +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{ + /* TODO: The safe variant raises thread to APC_LEVEL + and stores the previous IRQL in mutex->OldIrql */ + ExAcquireFastMutexUnsafe( mutex ); +} + + + /********************************************************************* + * ExReleaseFastMutex (NTOSKRNL.@) + */ +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{ + ExReleaseFastMutexUnsafe( mutex ); + /* TODO: the safe variant restores the IRQL to mutex->OldIrql */ +}
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50885
Your paranoid android.
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50858
Your paranoid android.
=== build (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/tests/driver.c:826 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 20 ++++++++++++++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 17 +++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 861eb40429..0365634772 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3232,6 +3232,26 @@ NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process) }
+/***************************************************** + * PsLookupThreadByThreadId (NTOSKRNL.EXE.@) + */ +NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE threadid, PETHREAD *thread) +{ + NTSTATUS status; + HANDLE hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, HandleToUlong(threadid) ); + + if (!hThread) + return STATUS_INVALID_PARAMETER; + + status = kernel_object_from_handle( hThread, PsThreadType, (void**)thread ); + + ObReferenceObject( *thread ); + + NtClose( hThread ); + return status; +} + + /***************************************************** * IoSetThreadHardErrorMode (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index ab952e528b..e08abb4150 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -913,7 +913,7 @@ @ stub PsJobType @ stdcall PsLookupProcessByProcessId(ptr ptr) @ stub PsLookupProcessThreadByCid -@ stub PsLookupThreadByThreadId +@ stdcall PsLookupThreadByThreadId(ptr ptr) @ extern PsProcessType @ stub PsReferenceImpersonationToken @ stub PsReferencePrimaryToken diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index c3839da3bf..75bf934445 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -1167,6 +1167,22 @@ static void test_resource(void) ok(status == STATUS_SUCCESS, "got status %#x\n", status); }
+static void test_lookup_thread(void) +{ + NTSTATUS status; + PETHREAD thread = NULL; + + status = PsLookupThreadByThreadId(PsGetCurrentThreadId(), &thread); + ok(!status, "PsLookupThreadByThreadId failed: %#x\n", status); + ok((PKTHREAD)thread == KeGetCurrentThread(), "thread != KeGetCurrentThread\n"); + + if (thread) + ObDereferenceObject(thread); + + status = PsLookupThreadByThreadId(NULL, &thread); + ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status); +} + static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) { ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength; @@ -1210,6 +1226,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_lookaside_list(); test_ob_reference(test_input->path); test_resource(); + test_lookup_thred();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index abe357fbc9..9b57ae7ad7 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
#endif
On 4/11/19 9:45 PM, Derek Lesho wrote:
Signed-off-by: Derek Lesho dereklesho52@Gmail.com
dlls/ntoskrnl.exe/ntoskrnl.c | 20 ++++++++++++++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- dlls/ntoskrnl.exe/tests/driver.c | 17 +++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 861eb40429..0365634772 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -3232,6 +3232,26 @@ NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE processid, PEPROCESS *process) }
+/*****************************************************
PsLookupThreadByThreadId (NTOSKRNL.EXE.@)
- */
+NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE threadid, PETHREAD *thread) +{
- NTSTATUS status;
- HANDLE hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, HandleToUlong(threadid) );
Please avoid Hungarian names like that, 'handle' would be preferred.
- if (!hThread)
return STATUS_INVALID_PARAMETER;
- status = kernel_object_from_handle( hThread, PsThreadType, (void**)thread );
- ObReferenceObject( *thread );
Please use ObReferenceObjectByHandle instead. I made kernel_object_from_handle available for whole ntoskrnl.exe for cases that don't need to reference object (otherwise we'd have unnecessary reference/dereference sequences), but when you actually need to reference the object, ObReferenceObjectByHandle seems to be a better fit.
- NtClose( hThread );
- return status;
+}
- /*****************************************************
*/
IoSetThreadHardErrorMode (NTOSKRNL.EXE.@)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index ab952e528b..e08abb4150 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -913,7 +913,7 @@ @ stub PsJobType @ stdcall PsLookupProcessByProcessId(ptr ptr) @ stub PsLookupProcessThreadByCid -@ stub PsLookupThreadByThreadId +@ stdcall PsLookupThreadByThreadId(ptr ptr) @ extern PsProcessType @ stub PsReferenceImpersonationToken @ stub PsReferencePrimaryToken diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c index c3839da3bf..75bf934445 100644 --- a/dlls/ntoskrnl.exe/tests/driver.c +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -1167,6 +1167,22 @@ static void test_resource(void) ok(status == STATUS_SUCCESS, "got status %#x\n", status); }
+static void test_lookup_thread(void) +{
- NTSTATUS status;
- PETHREAD thread = NULL;
- status = PsLookupThreadByThreadId(PsGetCurrentThreadId(), &thread);
This doesn't compile, you're missing #include "ddk/ntifs.h"
- ok(!status, "PsLookupThreadByThreadId failed: %#x\n", status);
- ok((PKTHREAD)thread == KeGetCurrentThread(), "thread != KeGetCurrentThread\n");
- if (thread)
ObDereferenceObject(thread);
- status = PsLookupThreadByThreadId(NULL, &thread);
- ok(status == STATUS_INVALID_PARAMETER, "PsLookupThreadByThreadId returned %#x\n", status);
+}
- static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) { ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
@@ -1210,6 +1226,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st test_lookaside_list(); test_ob_reference(test_input->path); test_resource();
- test_lookup_thred();
And this won't build either.
/* print process report */ if (winetest_debug)
diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index abe357fbc9..9b57ae7ad7 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -131,6 +131,7 @@ typedef struct _FS_FILTER_CALLBACKS
BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); +NTSTATUS WINAPI PsLookupThreadByThreadId(HANDLE,PETHREAD*); void WINAPI PsRevertToSelf(void);
#endif
Even with fixed test compilation, it will fail on Wine without patch 6.
Jacek
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=50875
Your paranoid android.
=== build (build log) ===
collect2: error: ld returned 1 exit status Makefile:204: recipe for target 'driver.dll' failed Makefile:7646: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The exe32 Wine crossbuild failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8696: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The win32 build failed
=== debian9 (build log) ===
collect2: error: ld returned 1 exit status Makefile:203: recipe for target 'driver.dll.so' failed Makefile:8425: recipe for target 'dlls/ntoskrnl.exe/tests' failed Task: The wow64 build failed