Commit graph

187 commits

Author SHA1 Message Date
Victor Perevertkin 34593d933b
[FORMATTING][NTOS][HAL][DRIVERS][SDK] Fix trailing spaces 2021-06-11 15:33:08 +03:00
Hermès Bélusca-Maïto 4b4ffa92f5
[NTOS:IO] Modify when 'PartitionBuffer' and how 'DriveLayout' are freed in IopCreateArcNamesDisk().
- Manage the lifetime of the temporary 'PartitionBuffer' buffer where
  it is locally used only, and free it as soon as possible, just after
  calculating the sector checksum. No need to then free it outside of
  the main for-loop.

- When the 'DriveLayout' buffer is freed, ensure the pointer is NULL-ed
  (and assert this at the top of the main for-loop), since it can also
  be freed at cleanup outside this for-loop, and in this case a NULL
  check is performed.
  This will avoid the scenario of possibly double-freeing a pointer,
  in the case the 'DriveLayout' was previously freed (when e.g. reading
  the sector for checksum calculation failed), then the for-loop goes to
  the next disk and stops early.
2021-06-11 02:21:48 +02:00
Hermès Bélusca-Maïto fdd74eb97e
[NTOS:IO/FSTUB] Fix the determination of 'SingleDisk' in IoGetBootDiskInformation().
The purpose of 'SingleDisk' is the same as in the IopCreateArcNames()
function. It is an optimization for that when looking up the
firmware-recognized ARC disks list, in order to match one of these with
the current NT disk being analysed (see e.g. also in IopCreateArcNamesDisk()),
we avoid a possible IopVerifyDiskSignature() call and directly build a
corresponding ARC name NT symbolic link for it.

'SingleDisk' will actually be TRUE, whether the DiskSignatureListHead
list is empty or contains only one element: Indeed in only both these
cases, 'DiskSignatureListHead.Flink->Flink' will refer to the list head.
(If the list is empty but 'SingleDisk' is TRUE, this does not matter,
because the DiskSignatureListHead looking-up loop never starts.)
2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 99078646c3
[NTOS:IO] Avoid hardcoding variable types in sizeofs when possible. 2021-06-11 02:21:47 +02:00
Hermès Bélusca-Maïto 6e65e6b28d
[NTOS:IO] Minor code style fixes (typos; improve comments/DPRINT; IN vs. OUT parameter). 2021-06-11 02:21:47 +02:00
George Bișoc a330b56787
[NTOS:PS] Enable alignment probing for thread/process information classes
In addition to that, here are some stuff done in this commit whilst testing:

- ICIF_QUERY_SIZE_VARIABLE and friends were badly misused, they should be used only when an information class whose information length size is dyanmic and not fixed. By removing such flags from erroneous classes, this fixes the STATUS_INFO_LENGTH_MISMATCH testcases.

- Use CHAR instead of UCHAR for classes that do not need alignment probing, as every other class in the table do, for the sake of consistency.

- ProcessEnableAlignmentFaultFixup uses BOOLEAN as type size, not CHAR. This fixes a testcase failure on ROS.

- Check for information length size before proceeding further on querying the process' cookie information.

- ProcessHandleTracing wants an alignment of a ULONG, not CHAR.

- Move PROCESS_LDT_INFORMATION and PROCESS_LDT_SIZE outside of NTOS_MODE_USER macro case. This fixes a compilation issue when enabling the alignment probing. My mistake of having them inside NTOS_MODE_USER case, sorry.

- On functions like NtQueryInformationThread and the Process equivalent, complete probing is not done at the beginning of the function, complete probing including if the buffer is writable alongside with datatype misalignment check that is. Instead such check is done on each information class case basis. With that said, we have to explicitly tell DefaultQueryInfoBufferCheck if we want a complete probing or not initially.
2021-06-06 17:14:22 +02:00
Jérôme Gardou b0ebf68d98 [NTOS:IO] Be more specific for chasing CORE-17587
Addendum to 42ec1388d7
2021-05-26 11:03:34 +02:00
Jérôme Gardou 42ec1388d7 [NTOS:IO] Break on IoRaiseInformationalHardError
This one will eventually be reverted. For now, this will help debugging CORE-17587
2021-05-26 10:48:29 +02:00
Jérôme Gardou 3adf450867 [REACTOS] Addendum to 5c7ce4475e - Fix MSVC 2015 build
Put data into PAGEDATA or INITDATA sections
Keep section declaration for prototypes

CORE-17540
2021-05-12 11:04:29 +02:00
George Bișoc 207543429b
[NTOSKRNL] Use IQS_SAME instead of ICI_SQ_SAME
And remove the redundant ICI_SQ_SAME macro as it's no longer needed in the codebase.
2021-05-02 21:00:51 +02:00
Jérôme Gardou 662774bca3 [NTOS] Do not force-align an integer value 2021-04-28 13:10:23 +02:00
Eric Kohl d8c38c4b4c [NTOS:PNP] PiSetDevNodeText: Do not overwrite existing DeviceDesc values
CORE-17513
2021-04-05 14:33:48 +02:00
Victor Perevertkin 0fed07b7e4
[NTOS:PNP] Initialize DeviceDesc and LocationInformation registry fields
for manually reported devices, as it is required by the newdev.dll
for installing drivers from INF files

CORE-17212 CORE-17398

Co-authored-by: Stanislav Motylkov <x86corez@gmail.com>
2021-03-19 07:57:41 +03:00
Victor Perevertkin aec3d9cc8f
[NTOS:IO][NTOS:PNP] Fix incorrect usage of IopGetRegistryValue
KEY_VALUE_FULL_INFORMATION was not always freed properly
2021-03-19 01:07:22 +03:00
Victor Perevertkin 59a5dba443
[NTOS:PNP] Implement PlugPlayControlStartDevice control class
This control class is triggered when a driver is being installed for a
non-critical device. The driver info should already be in the registry
so we just need to push the device through the state graph

Meanwhile, combine the code for similar control classes into
PiControlSyncDeviceAction routine

CORE-17463 CORE-17490
2021-03-16 03:17:57 +03:00
Victor Perevertkin 029accdcf7
[NDK] Change the data structure for PlugPlayControlResetDevice control class
PlugPlayControlResetDevice shares the input structure with several other
control classes.
Source: ProcessHacker sources e9c8121f41/ntpnpapi.h
2021-03-16 03:17:42 +03:00
Jérôme Gardou 2d3454a809 [NTOS:IO] VFAT sucks less now 2021-02-03 09:41:22 +01:00
Victor Perevertkin 91fceab36e
[NTOS:IO][NTOS:PNP] Add PiActionAddBootDevices device action
During the boot process, it makes possible to initalize the driver's
devices right after the driver is loaded. Moreover, this way one can be
sure that all critical devices are initialized before the
IopMarkBootPartition call (because we explicitly call the driver's
AddDevice routine now, after each driver is loaded)

CORE-7826
2021-01-27 05:15:16 +03:00
Victor Perevertkin 798fc13b48
[NTOS:PNP] Implement NT5.2-like DEVICE_NODE state management
- Use DeviceNode->State field and its values, instead of
  DeviceNode->Flags for tracking current node state
- Change DNF_* flags to the ones compatible with Windows XP+
- Simplify state changes for device nodes and encapsulate all the logic
  inside the PiDevNodeStateMachine routine. This makes the ground for
  future improvements in the device removal sequence and
  resource management
- Now values inside DeviceNode->State and ->Flags are compatible with
  the windbg !devnode macro and can be tracked using it
- BUGFIX: fixed cases where IRP_MN_START_DEVICE or
  IRP_MN_QUERY_DEVICE_RELATIONS may be sent to a device after a
  IRP_MN_REMOVE_DEVICE

CORE-7826
2021-01-27 05:15:15 +03:00
Victor Perevertkin b704292808
[NTOS:IO] Add more enumeration requests during the boot process
This is to ensure that all needed devices are initialized during the
early boot

CORE-7826
2021-01-27 05:15:15 +03:00
Victor Perevertkin e5254974d2
[NTOS:IO] Start loading drivers from the disk only after SystemRoot is initialized
Add another PnPBootDriversInitialized variable to indicate a point where
both disk subsystem and SystemRoot symlink are initialized, and use it
in a PiCallDriverAddDevice call.
2021-01-04 16:50:33 +03:00
Victor Perevertkin c4c0585f96
[NTOS:IO][NTOS:PNP] Implement PiCallDriverAddDevice
- Move the driver's name obtaining logic into the IopGetDriverNames
  function
- Create a new PiCallDriverAddDevice instead of PipCallDriverAddDevice
  and move it to pnpmgr/devaction.c file. Move around all its internal
  helpers too
- Support a proper Windows-compatible driver loading order for a PDO
  (lower filters, main service, upper filters, etc.)
- Set a correct Problem for the DeviceNode, in case of an error during
  driver loading
- Check the Start Type for all drivers before loading
- Do not try to load drivers during the early boot stage when there is
  no disk subsystem initialized
2021-01-04 16:50:33 +03:00
Victor Perevertkin 4c95339da0
[NTOS:IO] Refactoring of the driver initialization code (2)
- Do not hold the IopDriverLoadResource while trying to reference a
  driver object (but still acquire it when we actually need to load a
  driver)
- Change IopLoadDriver and IopInitializeDriverModule to use registry
  handle instead of a service name string and/or full registry path
- Do not try to reference a driver object inside IopLoadDriver. It's
  supposed to be done before the function call
2021-01-04 16:50:33 +03:00
Victor Perevertkin a6a3aa0f0d
[NTOS:IO] Refactor IopLoadUnloadDriver
- Split IopLoadUnloadDriver into IopLoadDriver and calling DriverUnload
- Schedule the worker for (un)loading driver in a separate routine
  (IopDoLoadUnloadDriver) this allows IopLoadDriver to be called
  separately (if we are sure that we're in the system process)
2021-01-04 16:50:32 +03:00
Victor Perevertkin e18a32df3a
[NTOS:IO] Refactoring of the driver initialization code
- Remove IopCreateDriver and put its code into IoCreateDriver and
  IopInitializeDriverModule. It's hard to extract a meaningful common
  part from it
- Refactor IopInitializeDriverModule. Extend and put the DriverName
  generation logic into it. Now this function frees the ModuleObject in
  case of failure and returns STATUS_FAILED_DRIVER_ENTRY in case of
  DriverInit failure (will be used later)
2021-01-04 16:50:32 +03:00
Victor Perevertkin 6f0e37b042
[NTOS:PNP][NTOS:IO] Do not create a device object + node on every driver load
- Remove the usage of IopCreateDeviceNode and change it to
  PipAllocateDeviceNode where required
2021-01-04 16:50:32 +03:00
Victor Perevertkin 8ee88d3bd5
[NTOS:PNP] Send removal IRPs to a file system device object for mounted devices
If a DeviceObject has VPB attached, it should be treated in a special way

CORE-16106
2020-12-27 18:40:33 +03:00
Hermès Bélusca-Maïto a748350fc9
[NTOS:IO] Fail if the driver name passed to NtLoadDriver() is an empty string.
Otherwise an assertion on the driver name is hit later on.
Can be reproduced by calling NtLoadDriver with a valid UNICODE_STRING
of Length == 0.
2020-12-27 00:52:00 +01:00
Hermès Bélusca-Maïto 44511f0809
[NTOS:IO] Minor formatting only.
Making IopLoadUnloadDriver() looking similar to IopUnloadDriver().
2020-12-27 00:51:59 +01:00
Jérôme Gardou ef4c7ae978 [NTOS:IO] Validate input parameters in NtQueryDirectoryFile
It turns out this is not the job of the FS driver
2020-12-22 11:06:38 +01:00
Jérôme Gardou 1d1dba51db [NTOS:IO] Do not set Shared property of the file if we are failing in IoCheckShareAccess 2020-12-22 11:05:00 +01:00
Jérôme Gardou a6c0af2e21 [NTOS:IO] Do not pass bogus file offset to the FS in NtReadFile & NtWriteFile 2020-12-22 11:02:33 +01:00
Victor Perevertkin 582ca68696
[NTOS:PNP] Improve and refactor PnP notifications
- BUGFIX: do not call IoGetRelatedTargetDevice while guarded mutex is acquired
  (the function issues an APC, but they are disabled inside a critical section)
- BUGFIX: only the beginning of a structure for GUID_PNP_CUSTOM_NOTIFICATION was copied and queued.
  Just pass it as-is to a subscriber, without copying
- Don't convert event GUID to string, store and compare GUID struct itself
- Split IopNotifyPlugPlayNotification into 3 functions for each type of notification
  (less stack usage and for future changes)
- Move initialization code for notifications into a separate routine
- Use separate lists and locks for every type of notification
- Put "TargetDeviceChange" notifications into their place inside DEVICE_NODE
2020-12-05 22:25:40 +03:00
Victor Perevertkin e3198fb644
[NTOS:PNP] Check if APCs are enabled before waiting inside IopSynchronousCall 2020-12-05 22:25:39 +03:00
Thomas Faber 828d5fa93e
[NTOS:IO] Reduce stack usage in IopLoadServiceModule. CORE-17215 2020-11-27 12:44:35 +01:00
Thomas Faber ae1d272add
[NTOS:PNP] Avoid recursion in IopTraverseDeviceTree(Node). CORE-17215 2020-11-27 10:31:41 +01:00
Hervé Poussineau 129e009a2c [NTOS:IO] Do not translate resources of type CmResourceTypeDevicePrivate
CmResourceTypeDevicePrivate resources are created the the bus driver, for its own later use,
when children devices will receive the IRP_MN_START_DEVICE.

Do not translate them, as they have no meaning outside bus driver.
2020-11-15 18:38:37 +01:00
Victor Perevertkin d6ef8f97e9
[NTOS:PNP] Enumerate the device tree after loading boot drivers and HAL 2020-11-10 01:59:49 +03:00
Hermès Bélusca-Maïto 3c722e35b1
[CMD][SERVMAN][SHELL32][WINSPOOL][ROSAPPS][NTOS:PNP] Fix my build. 2020-11-06 01:06:11 +01:00
Victor Perevertkin 5c7ce4475e
[REACTOS] Cleanup INIT and some PAGE section allocations
- Change INIT_FUNCTION and INIT_SECTION to CODE_SEG("INIT") and DATA_SEG("INIT") respectively
- Remove INIT_FUNCTION from function prototypes
- Remove alloc_text pragma calls as they are not needed anymore
2020-11-02 21:45:31 +03:00
Hermès Bélusca-Maïto bd2a40d57b
[NTOS:IO] Some fixes for IoRaiseHardError(). (#3302)
CORE-14037

- Fix buggy retrieval of the current calling Irp->Tail.Overlay.Thread.

- The 4th argument (KernelRoutine) to the KeInitializeApc() is **NOT**
  optional; however its 5th argument (RundownRoutine) is.
  So use the mandatory routine for freeing the allocated APC instead.
  We don't use the rundown routine yet.

- Check whether the ExAllocatePoolWithTag() call failed or not before
  queueing the allocated APC.
2020-10-17 16:13:05 +02:00
Dmitry Borisov c464b02c90
[NTOS:PNP] Install mouse driver on NEC PC-98 series (#3173)
The current implementation of device tree enumeration does not distinguish
between possible identifier strings. This change is not a hack,
NT 5.2 still creates a new device node for this hardware ID.
The entire function should be rewritten to match Windows implementation.
2020-10-10 16:24:17 +03:00
Timo Kreuzer f2e3e8a1eb [NTOS] Remove an old hack 2020-09-28 00:27:30 +02:00
Victor Perevertkin 32c7c1157d
[NTOS:IO] Fix a reference leak in IopSynchronousCall on failure case
Co-authored-by: Vadim Galyant <vgal@rambler.ru>
2020-09-08 14:51:20 +03:00
Victor Perevertkin f562f9c5c6
[NTOS:IO] Fix IRP stack location check in IoForwardIrpSynchronously
We are doing IoCallDriver here, so the valid stack location should be
CurrentLocation <= Irp->StackCount (just a check for a completly incorrect value)
&& CurrentLocation > 1 (ensure that we have a place for another call)

CORE-17189

Co-authored-by: Thomas Faber <thomas.faber@reactos.org>
2020-09-07 04:57:17 +03:00
Victor Perevertkin 162d614cc1
[NTOS:IO] Queue device tree enumeration inside IoReportDetectedDevice
Without that, a DeviceNode is not created for a reported device and thus
it is not being attached to the device tree

CORE-17132
2020-08-21 08:53:33 +03:00
Victor Perevertkin dc1d717b22
[NTOS:IO] Do not raise an unknown bugcheck inside the PiQueueDeviceAction 2020-08-21 08:50:12 +03:00
Victor Perevertkin acd07e725e
[NTOS:IO] Do device reset inside the PipDeviceActionWorker
This make the operation synchonized with the other device tree actions

CORE-10456 CORE-17150
2020-08-21 08:20:59 +03:00
Victor Perevertkin 2839c85092
[NTOS:IO] Enumerate devices only inside the PipDeviceActionWorker
Introduce the PiPerformSyncDeviceAction routine for queuing
synchronous device actions
Change all kernel code to use PiPerformSyncDeviceAction and
PiQueueDeviceAction for device enumeration

CORE-10456
2020-08-21 08:02:26 +03:00
Victor Perevertkin 2ed132e90e
[NTOS:IO] change DEVICE_ACTION values and rename functions 2020-08-21 07:48:56 +03:00