Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 20 ++++++++++++++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- 2 files changed, 21 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
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 + 3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 770bdfd4fa..ec05125f27 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"); + /* FIXME: actually disable certain APCs */ + KeGetCurrentThread()->critical_region = TRUE; }
/*********************************************************************** @@ -3439,7 +3442,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) { - FIXME(": stub\n"); + /* FIXME: actually re-enable certain APCs */ + 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 d44ffd5d3c..67e5068c9b 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 *unused[0x100]; };
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=50735
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
This patch fails because it looks like the Jacek removed the unused field in the patches he submitted yesterday. If I'm not mistaken, I don't think he's changed anything else.
On Tue, Apr 9, 2019 at 2:10 PM Derek Lesho dereklesho52@gmail.com wrote:
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 + 3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 770bdfd4fa..ec05125f27 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");
- /* FIXME: actually disable certain APCs */
- KeGetCurrentThread()->critical_region = TRUE;
}
/*********************************************************************** @@ -3439,7 +3442,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) {
- FIXME(": stub\n");
- /* FIXME: actually re-enable certain APCs */
- 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 d44ffd5d3c..67e5068c9b 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 *unused[0x100];
};
-- 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=50738
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 161 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 161 Task: Patch failed to apply
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 + 3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 770bdfd4fa..ec05125f27 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"); + /* FIXME: actually disable certain APCs */ + KeGetCurrentThread()->critical_region = TRUE; }
/*********************************************************************** @@ -3439,7 +3442,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) { - FIXME(": stub\n"); + /* FIXME: actually re-enable certain APCs */ + 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;
On 04/09/2019 02:29 PM, Derek Lesho wrote:
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 + 3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 770bdfd4fa..ec05125f27 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");
- /* FIXME: actually disable certain APCs */
- KeGetCurrentThread()->critical_region = TRUE;
}
Can you please change this to a TRACE rather than removing it entirely?
Similarly for other functions you add, it would be nice to add trace messages.
/*********************************************************************** @@ -3439,7 +3442,8 @@ void WINAPI KeEnterCriticalRegion(void) */ void WINAPI KeLeaveCriticalRegion(void) {
- FIXME(": stub\n");
- /* FIXME: actually re-enable certain APCs */
- 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;
+}
Again, can you please add this to the public header?
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=50736
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
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=50739
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
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
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 ec05125f27..869edef458 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 67e5068c9b..cba0da8c67 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=50737
Your paranoid android.
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
=== debian9 (build log) ===
error: patch failed: dlls/ntoskrnl.exe/ntoskrnl_private.h:32 Task: Patch failed to apply
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=50740
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
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 ec05125f27..869edef458 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;
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 869edef458..bf7378b968 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 abe357fbc9..ffa103bcc5 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -132,5 +132,6 @@ typedef struct _FS_FILTER_CALLBACKS BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); void WINAPI PsRevertToSelf(void); +NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*);
#endif
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=50741
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 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 869edef458..bf7378b968 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 abe357fbc9..ffa103bcc5 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -132,5 +132,6 @@ typedef struct _FS_FILTER_CALLBACKS BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); void WINAPI PsRevertToSelf(void); +NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*);
#endif
On 04/09/2019 02:29 PM, Derek Lesho wrote:
diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index abe357fbc9..ffa103bcc5 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -132,5 +132,6 @@ typedef struct _FS_FILTER_CALLBACKS BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN, PWCH); NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); void WINAPI PsRevertToSelf(void); +NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*);
#endif
Nitpick, but can you please keep this alphabetized, as in other DDK headers?
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 ++++-- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index bf7378b968..9f1298a51e 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; }
@@ -2511,6 +2510,9 @@ static void *create_thread_object( HANDLE handle ) if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) thread->id = info.ClientId;
+ 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 cba0da8c67..e40e866f47 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; void *unused[0x100]; };
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=50742
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 6 ++++-- dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index bf7378b968..9f1298a51e 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; }
@@ -2511,6 +2510,9 @@ static void *create_thread_object( HANDLE handle ) if (!NtQueryInformationThread( handle, ThreadBasicInformation, &info, sizeof(info), NULL )) thread->id = info.ClientId;
+ 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; };
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 9f1298a51e..80e53b4f72 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=50743
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 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 9f1298a51e..80e53b4f72 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=50754
Your paranoid android.
=== debian9 (32 bit WoW report) ===
ntoskrnl.exe: driver.c:620: Test failed: got 0 driver.c:623: Test failed: got 0x102
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 | 22 ++++++++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 80e53b4f72..46fd243d75 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 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 66465bb5ae..ebfdb05b86 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" @@ -826,6 +827,26 @@ static void test_ob_reference(const WCHAR *test_path) ok(!status, "ZwClose failed: %#x\n", status); }
+static void WINAPI system_thread( void *arg ) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + +todo_wine + ok((result), "got %u\n", result); + + PsTerminateSystemThread( STATUS_SUCCESS ); +} + +static void test_system_thread(void) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + +todo_wine + 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; @@ -868,6 +889,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_system_thread();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index ffa103bcc5..61f7526cbf 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -133,5 +133,6 @@ BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); void WINAPI PsRevertToSelf(void); NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); +BOOLEAN WINAPI PsIsSystemThread(PETHREAD);
#endif
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=50744
Your paranoid android.
=== build (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 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 | 22 ++++++++++++++++++++++ include/ddk/ntifs.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 80e53b4f72..46fd243d75 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 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 66465bb5ae..ebfdb05b86 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" @@ -826,6 +827,26 @@ static void test_ob_reference(const WCHAR *test_path) ok(!status, "ZwClose failed: %#x\n", status); }
+static void WINAPI system_thread( void *arg ) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + +todo_wine + ok((result), "got %u\n", result); + + PsTerminateSystemThread( STATUS_SUCCESS ); +} + +static void test_system_thread(void) +{ + BOOLEAN result = PsIsSystemThread((PETHREAD)KeGetCurrentThread()); + +todo_wine + 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; @@ -868,6 +889,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_system_thread();
/* print process report */ if (winetest_debug) diff --git a/include/ddk/ntifs.h b/include/ddk/ntifs.h index ffa103bcc5..61f7526cbf 100644 --- a/include/ddk/ntifs.h +++ b/include/ddk/ntifs.h @@ -133,5 +133,6 @@ BOOLEAN WINAPI FsRtlIsNameInExpression(PUNICODE_STRING, PUNICODE_STRING, BOOLEAN NTSTATUS WINAPI ObQueryNameString(PVOID,POBJECT_NAME_INFORMATION,ULONG,PULONG); void WINAPI PsRevertToSelf(void); NTSTATUS WINAPI PsLookupProcessByProcessId(HANDLE,PEPROCESS*); +BOOLEAN WINAPI PsIsSystemThread(PETHREAD);
#endif
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=50755
Your paranoid android.
=== debian9 (32 bit report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit French report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit Japanese:Japan report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit Chinese:China report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (64 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/sync.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
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=50745
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/sync.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
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=50756
Your paranoid android.
=== debian9 (32 bit report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit Chinese:China report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (64 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
On 04/09/2019 02:29 PM, Derek Lesho wrote:
Signed-off-by: Derek Lesho dereklesho52@Gmail.com
dlls/ntoskrnl.exe/sync.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
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 );
}
This could do with a more descriptive title, like "ntoskrnl.exe: Set Owner in fast mutex functions."
You probably also want to make the corresponding change to ExTryToAcquireFastMutex() in hal.
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 1 + dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + dlls/ntoskrnl.exe/sync.c | 34 ++++++++++++++++++++++++++++ include/ddk/wdm.h | 4 ++++ 5 files changed, 42 insertions(+)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 46fd243d75..32ead1ff20 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2518,6 +2518,7 @@ static void *create_thread_object( HANDLE handle ) ObDereferenceObject( thread->process );
thread->critical_region = FALSE; + thread->irql = PASSIVE_LEVEL;
return thread; } diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 399258cdfd..f4e6d8f710 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall 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 ExReleaseFastMutex(ptr) @ stdcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index e40e866f47..85d0dcbeba 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -37,6 +37,7 @@ struct _KTHREAD DISPATCHER_HEADER header; CLIENT_ID id; PEPROCESS process; + UCHAR irql; BOOLEAN critical_region; void *unused[0x100]; }; diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index bb2d318e56..15a602d3f4 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -689,3 +689,37 @@ void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); } + + +/********************************************************************* + * ExAcquireFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutex) +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql; + PKTHREAD thread = KeGetCurrentThread(); + + /* The safe variant raises thread to APC_LEVEL */ + old_irql = thread->irql; + thread->irql = APC_LEVEL; + + ExAcquireFastMutexUnsafe( mutex ); + + mutex->OldIrql = old_irql; +} + + + /********************************************************************* + * ExReleaseFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutex) +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql = mutex->OldIrql; + PKTHREAD thread = mutex->Owner; + + ExReleaseFastMutexUnsafe( mutex ); + + thread->irql = old_irql; +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 02c1bf3f20..3611c7cd90 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -168,6 +168,10 @@ typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
#define FM_LOCK_BIT 0x1
+/* irqls */ +#define PASSIVE_LEVEL 0 +#define APC_LEVEL 1 + typedef struct _FAST_MUTEX { LONG Count;
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=50746
Your paranoid android.
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
=== debian9 (build log) ===
error: corrupt patch at line 160 Task: Patch failed to apply
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 1 + dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + dlls/ntoskrnl.exe/sync.c | 34 ++++++++++++++++++++++++++++ include/ddk/wdm.h | 4 ++++ 5 files changed, 42 insertions(+)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 46fd243d75..32ead1ff20 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2518,6 +2518,7 @@ static void *create_thread_object( HANDLE handle ) ObDereferenceObject( thread->process );
thread->critical_region = FALSE; + thread->irql = PASSIVE_LEVEL;
return thread; } diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 399258cdfd..f4e6d8f710 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall 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 ExReleaseFastMutex(ptr) @ stdcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index 940ff526f9..84f8387262 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -38,6 +38,7 @@ struct _KTHREAD CLIENT_ID id; PEPROCESS process; BOOLEAN critical_region; + UCHAR irql; };
void *alloc_kernel_object( POBJECT_TYPE type, HANDLE handle, SIZE_T size, LONG ref ) DECLSPEC_HIDDEN; diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index bb2d318e56..15a602d3f4 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -689,3 +689,37 @@ void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); } + + +/********************************************************************* + * ExAcquireFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutex) +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql; + PKTHREAD thread = KeGetCurrentThread(); + + /* The safe variant raises thread to APC_LEVEL */ + old_irql = thread->irql; + thread->irql = APC_LEVEL; + + ExAcquireFastMutexUnsafe( mutex ); + + mutex->OldIrql = old_irql; +} + + + /********************************************************************* + * ExReleaseFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutex) +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql = mutex->OldIrql; + PKTHREAD thread = mutex->Owner; + + ExReleaseFastMutexUnsafe( mutex ); + + thread->irql = old_irql; +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 02c1bf3f20..3611c7cd90 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -168,6 +168,10 @@ typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
#define FM_LOCK_BIT 0x1
+/* irqls */ +#define PASSIVE_LEVEL 0 +#define APC_LEVEL 1 + typedef struct _FAST_MUTEX { LONG Count;
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=50757
Your paranoid android.
=== debian9 (32 bit report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit Chinese:China report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (32 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
=== debian9 (64 bit WoW report) ===
ntoskrnl.exe: driver.c:872: Test succeeded inside todo block: got 0 driver.c:862: Test succeeded inside todo block: got 1
On 04/09/2019 02:29 PM, Derek Lesho wrote:
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 399258cdfd..f4e6d8f710 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall 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 ExReleaseFastMutex(ptr) @ stdcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx
I don't remember offhand, but I think these functions shouldn't be exported on i386 (they're exported from hal instead).
diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index 940ff526f9..84f8387262 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -38,6 +38,7 @@ struct _KTHREAD CLIENT_ID id; PEPROCESS process; BOOLEAN critical_region;
- UCHAR irql;
};
void *alloc_kernel_object( POBJECT_TYPE type, HANDLE handle, SIZE_T size, LONG ref ) DECLSPEC_HIDDEN; diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index bb2d318e56..15a602d3f4 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -689,3 +689,37 @@ void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); }
+/*********************************************************************
ExAcquireFastMutex (NTOSKRNL.@)
- */
+DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutex) +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{
- KIRQL old_irql;
- PKTHREAD thread = KeGetCurrentThread();
- /* The safe variant raises thread to APC_LEVEL */
This comment seems superfluous.
- old_irql = thread->irql;
- thread->irql = APC_LEVEL;
This should probably be KeRaiseIrql() instead (and similarly KeLowerIrql() below), assuming that we ever will need to emulate proper IRQL handling. That said, is it really necessary right now? You don't use it in this patch.
- ExAcquireFastMutexUnsafe( mutex );
- mutex->OldIrql = old_irql;
+}
- /*********************************************************************
ExReleaseFastMutex (NTOSKRNL.@)
- */
+DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutex) +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{
- KIRQL old_irql = mutex->OldIrql;
- PKTHREAD thread = mutex->Owner;
- ExReleaseFastMutexUnsafe( mutex );
- thread->irql = old_irql;
+}
Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 20 ++++++++++++++++++++ dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 +- 2 files changed, 21 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
On 04/09/2019 02:29 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 +- 2 files changed, 21 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
Can we have tests for this function?
And while you're at it, can you add it to the public header?
On Tue, Apr 9, 2019 at 7:34 PM Zebediah Figura z.figura12@gmail.com wrote:
On 04/09/2019 02:29 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 +- 2 files changed, 21 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
Can we have tests for this function?
And while you're at it, can you add it to the public header?
Sure, will do. I Just based the return value on the MSDN, but I guess it
doesn't hurt to check.
On 4/10/19 12:12 AM, Derek Lesho wrote:
On Tue, Apr 9, 2019 at 7:34 PM Zebediah Figura <z.figura12@gmail.com mailto:z.figura12@gmail.com> wrote:
On 04/09/2019 02:29 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 +- > 2 files changed, 21 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 > Can we have tests for this function? And while you're at it, can you add it to the public header?
Sure, will do. I Just based the return value on the MSDN, but I guess it doesn't hurt to check.
As far as signatures go, it's better to look at the PSDK headers anyway; I've seen MSDN be wrong several times.