diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-15 14:05:29 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-15 14:12:29 +0200 |
| commit | b3eef140da853414776c8e03a70629a613a25ed0 (patch) | |
| tree | dcdb314d2fdd92f501c09f3ae5681a731cb00dee /km/src/nt_namespace | |
| parent | wdk10: disable the packaging target (diff) | |
| download | windows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.tar.gz windows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.zip | |
workflows/ci: add clang-format job
Diffstat (limited to 'km/src/nt_namespace')
| -rw-r--r-- | km/src/nt_namespace/device.c | 81 | ||||
| -rw-r--r-- | km/src/nt_namespace/device.h | 2 | ||||
| -rw-r--r-- | km/src/nt_namespace/main.c | 8 | ||||
| -rw-r--r-- | km/src/nt_namespace/nt2dos.c | 50 | ||||
| -rw-r--r-- | km/src/nt_namespace/nt2dos.h | 2 |
5 files changed, 55 insertions, 88 deletions
diff --git a/km/src/nt_namespace/device.c b/km/src/nt_namespace/device.c index 6d88dc4..afb9813 100644 --- a/km/src/nt_namespace/device.c +++ b/km/src/nt_namespace/device.c @@ -5,14 +5,14 @@ * Distributed under the MIT License. */ -#include "control_codes.h" #include "device.h" + +#include "control_codes.h" #include "nt2dos.h" #include <ntddk.h> -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ +static NTSTATUS device_open(DEVICE_OBJECT* device_object, IRP* irp) { NTSTATUS status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(device_object); @@ -23,25 +23,22 @@ static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) return status; } -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); +typedef NTSTATUS (*ioctl_handler)(void*, unsigned long, void*, unsigned long, ULONG_PTR*); static NTSTATUS handle_convert_nt_path( - void *in_buf, + void* in_buf, unsigned long in_buf_size, - void *out_buf, + void* out_buf, unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ + ULONG_PTR* nbwritten +) { UNICODE_STRING uUnresolved, uResolved; NTSTATUS status = STATUS_SUCCESS; - DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR *) in_buf); + DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR*)in_buf); DbgPrint("nt_namespace: unresolved size: %lu\n", in_buf_size); - RtlInitUnicodeString(&uUnresolved, (WCHAR *) in_buf); + RtlInitUnicodeString(&uUnresolved, (WCHAR*)in_buf); status = nt2dos(&uResolved, &uUnresolved); if (!NT_SUCCESS(status)) @@ -52,8 +49,7 @@ static NTSTATUS handle_convert_nt_path( DbgPrint("nt_namespace: resolved path: %wZ\n", &uResolved); DbgPrint("nt_namespace: resolved size: %Iu\n", *nbwritten); - if (out_buf_size < *nbwritten) - { + if (out_buf_size < *nbwritten) { status = STATUS_BUFFER_OVERFLOW; goto free_resolved; } @@ -67,10 +63,9 @@ free_resolved: return status; } -static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) -{ - IO_STACK_LOCATION *io_stack_loc; - void* in_buf, *out_buf; +static NTSTATUS device_ioctl(DEVICE_OBJECT* device_object, IRP* irp) { + IO_STACK_LOCATION* io_stack_loc; + void *in_buf, *out_buf; unsigned long in_buf_size, out_buf_size; ioctl_handler handler; NTSTATUS status = STATUS_UNSUCCESSFUL; @@ -85,8 +80,7 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; - switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) - { + switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) { case CONVERT_NT_PATH: handler = handle_convert_nt_path; break; @@ -96,10 +90,8 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) goto complete_request; } - status = irp->IoStatus.Status = handler( - in_buf, in_buf_size, - out_buf, out_buf_size, - &irp->IoStatus.Information); + status = irp->IoStatus.Status = + handler(in_buf, in_buf_size, out_buf, out_buf_size, &irp->IoStatus.Information); complete_request: IoCompleteRequest(irp, IO_NO_INCREMENT); @@ -107,25 +99,20 @@ complete_request: return status; } -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; +typedef struct { + const wchar_t* path; + const wchar_t* symlink; +} DeviceInfo; -typedef struct -{ - DEVICE_OBJECT *object; +typedef struct { + DEVICE_OBJECT* object; UNICODE_STRING path; UNICODE_STRING symlink; -} -Device; +} Device; #define NUMOF_DEVICES 1 -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ +static DeviceInfo devices_info[NUMOF_DEVICES] = { { L"\\Device\\nt_namespace", L"\\DosDevices\\nt_namespace", @@ -134,21 +121,18 @@ static DeviceInfo devices_info[NUMOF_DEVICES] = static Device devices[NUMOF_DEVICES]; -static void destroy_device(int i) -{ +static void destroy_device(int i) { IoDeleteSymbolicLink(&devices[i].symlink); IoDeleteDevice(devices[i].object); } -void destroy_devices() -{ +void destroy_devices() { int i; for (i = 0; i < NUMOF_DEVICES; ++i) destroy_device(i); } -static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) -{ +static NTSTATUS set_up_device(DRIVER_OBJECT* driver_object, int i) { NTSTATUS status = STATUS_SUCCESS; RtlInitUnicodeString(&devices[i].path, devices_info[i].path); @@ -161,7 +145,8 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, - &devices[i].object); + &devices[i].object + ); if (!NT_SUCCESS(status)) return status; @@ -169,8 +154,7 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) devices[i].object->Flags |= DO_BUFFERED_IO; devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; - if (!NT_SUCCESS(status = IoCreateSymbolicLink( - &devices[i].symlink, &devices[i].path))) + if (!NT_SUCCESS(status = IoCreateSymbolicLink(&devices[i].symlink, &devices[i].path))) goto delete_device; return status; @@ -181,8 +165,7 @@ delete_device: return status; } -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ +NTSTATUS set_up_devices(DRIVER_OBJECT* driver_object) { int i, j; NTSTATUS status = STATUS_SUCCESS; diff --git a/km/src/nt_namespace/device.h b/km/src/nt_namespace/device.h index 4f117e9..8cc2c1d 100644 --- a/km/src/nt_namespace/device.h +++ b/km/src/nt_namespace/device.h @@ -9,5 +9,5 @@ #include <ntddk.h> -NTSTATUS set_up_devices(DRIVER_OBJECT *); +NTSTATUS set_up_devices(DRIVER_OBJECT*); void destroy_devices(); diff --git a/km/src/nt_namespace/main.c b/km/src/nt_namespace/main.c index 4c7ef74..a8d0c14 100644 --- a/km/src/nt_namespace/main.c +++ b/km/src/nt_namespace/main.c @@ -9,17 +9,13 @@ #include <ntddk.h> -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ +static void on_driver_unload(DRIVER_OBJECT* driver_object) { UNREFERENCED_PARAMETER(driver_object); destroy_devices(); } -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ +NTSTATUS DriverEntry(DRIVER_OBJECT* driver_object, UNICODE_STRING* registry_path) { UNREFERENCED_PARAMETER(registry_path); ExInitializeDriverRuntime(DrvRtPoolNxOptIn); diff --git a/km/src/nt_namespace/nt2dos.c b/km/src/nt_namespace/nt2dos.c index be2c2f5..2e6db6c 100644 --- a/km/src/nt_namespace/nt2dos.c +++ b/km/src/nt_namespace/nt2dos.c @@ -5,12 +5,13 @@ * Distributed under the MIT License. */ +/* clang-format off */ #include <ntifs.h> #include "nt2dos.h" +/* clang-format on */ -static PVOID allocate(SIZE_T nb) -{ +static PVOID allocate(SIZE_T nb) { #if !defined(NTDDI_WIN10) || NTDDI_VERSION < NTDDI_WIN10 return ExAllocatePoolWithTag(PagedPool, nb, '1l'); #else @@ -18,10 +19,7 @@ static PVOID allocate(SIZE_T nb) #endif } -static NTSTATUS get_object_name_info( - void *object, - OBJECT_NAME_INFORMATION **object_name_info) -{ +static NTSTATUS get_object_name_info(void* object, OBJECT_NAME_INFORMATION** object_name_info) { unsigned long nbneeded; NTSTATUS status = STATUS_SUCCESS; @@ -48,11 +46,10 @@ free_object_name_info: return status; } -NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) -{ +NTSTATUS nt2dos(UNICODE_STRING* u_resolved, UNICODE_STRING* u_unresolved) { IO_STATUS_BLOCK io_status_block; - DEVICE_OBJECT *volume_object; - FILE_OBJECT *file_object; + DEVICE_OBJECT* volume_object; + FILE_OBJECT* file_object; HANDLE file; OBJECT_ATTRIBUTES file_attrs; OBJECT_NAME_INFORMATION *file_name_info, *volume_name_info; @@ -61,11 +58,8 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) NTSTATUS status = STATUS_SUCCESS; InitializeObjectAttributes( - &file_attrs, - u_unresolved, - OBJ_CASE_INSENSITIVE | OBJ_OPENIF, - NULL, - NULL); + &file_attrs, u_unresolved, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, NULL, NULL + ); status = ZwCreateFile( &file, @@ -78,18 +72,15 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, - 0); + 0 + ); if (!NT_SUCCESS(status)) return status; status = ObReferenceObjectByHandle( - file, - FILE_READ_ATTRIBUTES, - *IoFileObjectType, - KernelMode, - &file_object, - NULL); + file, FILE_READ_ATTRIBUTES, *IoFileObjectType, KernelMode, &file_object, NULL + ); if (!NT_SUCCESS(status)) goto close_file; @@ -99,18 +90,15 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) if (!NT_SUCCESS(status)) goto close_file; - if (file_object->Vpb == NULL) - { + if (file_object->Vpb == NULL) { u_resolved->Buffer = allocate(file_name_info->Name.Length); - if (u_resolved->Buffer == NULL) - { + if (u_resolved->Buffer == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto free_file_name_info; } - RtlInitEmptyUnicodeString( - u_resolved, u_resolved->Buffer, file_name_info->Name.Length); + RtlInitEmptyUnicodeString(u_resolved, u_resolved->Buffer, file_name_info->Name.Length); RtlCopyUnicodeString(u_resolved, &file_name_info->Name); goto free_file_name_info; } @@ -126,12 +114,12 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) if (!NT_SUCCESS(status)) goto free_volume_name_info; - u_resolved_size = file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; + u_resolved_size = + file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; u_resolved->Buffer = allocate(u_resolved_size); - if (u_resolved->Buffer == NULL) - { + if (u_resolved->Buffer == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto free_dos_name; } diff --git a/km/src/nt_namespace/nt2dos.h b/km/src/nt_namespace/nt2dos.h index ce0b690..7f24b5b 100644 --- a/km/src/nt_namespace/nt2dos.h +++ b/km/src/nt_namespace/nt2dos.h @@ -9,4 +9,4 @@ #include <ntstrsafe.h> -NTSTATUS nt2dos(UNICODE_STRING *resolved, UNICODE_STRING *unresolved); +NTSTATUS nt2dos(UNICODE_STRING* resolved, UNICODE_STRING* unresolved); |
