[0.4.13][BTRFS] Create system threads with OBJ_KERNEL_HANDLE

CORE-16375 #1914

Thanks to patches author ThFabba.
According to JIRA user 'Zero3k' this allows to format a
BTRFS drive again without INVALID_KERNEL_HANDLE BSOD.

Master remains affected,
our devs wait for upstream integration
This commit is contained in:
Joachim Henze 2019-10-13 22:11:43 +02:00
parent e2e90230d1
commit c722bc867e
6 changed files with 49 additions and 1 deletions

View file

@ -3599,7 +3599,11 @@ NTSTATUS start_balance(device_extension* Vcb, void* data, ULONG length, KPROCESS
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent, !Vcb->balance.paused);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, &system_thread_attributes, NULL, NULL, balance_thread, Vcb);
#else
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, NULL, NULL, NULL, balance_thread, Vcb);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
return Status;
@ -3679,7 +3683,11 @@ NTSTATUS look_for_balance_item(_Requires_lock_held_(_Curr_->tree_lock) device_ex
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent, !Vcb->balance.paused);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, &system_thread_attributes, NULL, NULL, balance_thread, Vcb);
#else
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, NULL, NULL, NULL, balance_thread, Vcb);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
return Status;
@ -3876,7 +3884,11 @@ NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG length, KPROCESS
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent, !Vcb->balance.paused);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, &system_thread_attributes, NULL, NULL, balance_thread, Vcb);
#else
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, NULL, NULL, NULL, balance_thread, Vcb);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
dev->reloc = false;

View file

@ -107,7 +107,9 @@ HANDLE degraded_wait_handle = NULL, mountmgr_thread_handle = NULL;
bool degraded_wait = true;
KEVENT mountmgr_thread_event;
bool shutting_down = false;
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
OBJECT_ATTRIBUTES system_thread_attributes = RTL_CONSTANT_OBJECT_ATTRIBUTES(NULL, OBJ_KERNEL_HANDLE);
#endif
#ifdef _DEBUG
PFILE_OBJECT comfo = NULL;
PDEVICE_OBJECT comdo = NULL;
@ -4020,7 +4022,11 @@ static NTSTATUS create_calc_threads(_In_ PDEVICE_OBJECT DeviceObject) {
Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, false);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, &system_thread_attributes, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
#else
Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
#endif
if (!NT_SUCCESS(Status)) {
ULONG j;
@ -4826,7 +4832,11 @@ static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
KeInitializeEvent(&Vcb->flush_thread_finished, NotificationEvent, false);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->flush_thread_handle, 0, &system_thread_attributes, NULL, NULL, flush_thread, NewDeviceObject);
#else
Status = PsCreateSystemThread(&Vcb->flush_thread_handle, 0, NULL, NULL, NULL, flush_thread, NewDeviceObject);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
goto exit;
@ -5518,7 +5528,11 @@ static void init_serial(bool first_time) {
ERR("IoGetDeviceObjectPointer returned %08x\n", Status);
if (first_time) {
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&serial_thread_handle, 0, &system_thread_attributes, NULL, NULL, serial_thread, NULL);
#else
Status = PsCreateSystemThread(&serial_thread_handle, 0, NULL, NULL, NULL, serial_thread, NULL);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
return;
@ -5990,7 +6004,11 @@ NTSTATUS __stdcall DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_S
IoInvalidateDeviceRelations(bde->buspdo, BusRelations);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&degraded_wait_handle, 0, &system_thread_attributes, NULL, NULL, degraded_wait_thread, NULL);
#else
Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
#endif
if (!NT_SUCCESS(Status))
WARN("PsCreateSystemThread returned %08x\n", Status);
@ -6013,7 +6031,11 @@ NTSTATUS __stdcall DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_S
KeInitializeEvent(&mountmgr_thread_event, NotificationEvent, false);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, &system_thread_attributes, NULL, NULL, mountmgr_thread, NULL);
#else
Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
#endif
if (!NT_SUCCESS(Status))
WARN("PsCreateSystemThread returned %08x\n", Status);

View file

@ -1756,6 +1756,8 @@ typedef BOOLEAN (*tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOff
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
typedef struct _ECP_LIST ECP_LIST;
typedef struct _ECP_LIST *PECP_LIST;
extern OBJECT_ATTRIBUTES system_thread_attributes;
#endif
typedef VOID (*tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags);

View file

@ -4751,7 +4751,11 @@ static NTSTATUS resize_device(device_extension* Vcb, void* data, ULONG len, PIRP
space_list_subtract2(&dev->space, NULL, br->size, delta, NULL, NULL);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, &system_thread_attributes, NULL, NULL, balance_thread, Vcb);
#else
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, NULL, NULL, NULL, balance_thread, Vcb);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
goto end;

View file

@ -3292,7 +3292,11 @@ NTSTATUS start_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode) {
Vcb->scrub.error = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->scrub.event, NotificationEvent, !Vcb->scrub.paused);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&Vcb->scrub.thread, 0, &system_thread_attributes, NULL, NULL, scrub_thread, Vcb);
#else
Status = PsCreateSystemThread(&Vcb->scrub.thread, 0, NULL, NULL, NULL, scrub_thread, Vcb);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
return Status;

View file

@ -3810,7 +3810,11 @@ NTSTATUS send_subvol(device_extension* Vcb, void* data, ULONG datalen, PFILE_OBJ
InterlockedIncrement(&Vcb->running_sends);
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
Status = PsCreateSystemThread(&send->thread, 0, &system_thread_attributes, NULL, NULL, send_thread, context);
#else
Status = PsCreateSystemThread(&send->thread, 0, NULL, NULL, NULL, send_thread, context);
#endif
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
ccb->send = NULL;