Commit graph

171 commits

Author SHA1 Message Date
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
Nguyen Trung Khanh 37c63770d7
[NTOS:IO] Fix pool memory disclosure in IopQueueTargetDeviceEvent (#2966) 2020-07-04 15:41:18 +02:00
Victor Perevertkin 21e9e2baa5
[NTOS:IO] Move device manipulation functions from pnpmgr/pnpmgr.c to pnpmgr/devaction.c
And rearrange them in more logical order.

This effectively splits the file, leaving public "Io" functions in
pnpmgr.c along with some things not related do device object management.
Functions which manipulate the device tree are left in devaction.c.
In future all these functions will only be accessed from
DeviceActionWorker.
While being public API, IoRequestDeviceEject and IoInvalidateDeviceState
have been moved to devaction.c as well. In next commits they will be
converted to DeviceActionWorker routines and their callers will be put
in pnpmgr.c
2020-06-24 04:03:35 +03:00
Victor Perevertkin b5815efe83
[NTOS:IO] Move device node functions from pnpmgr/pnpmgr.c to pnpmgr/devnode.c
Add SAL2 annotations to functions while moving
Convert IopCreateDeviceNode description to a Doxygen format
2020-06-21 09:39:13 +03:00
Serge Gautherie b20f815126
[NTOSKRNL] Place INIT_FUNCTION before the return type (#2823)
(but after 'static' or SAL 2 annotation.)
Follow-up to 71fefa32, which mentions that it's actually required by the compiler in some circumstances.
2020-05-23 15:56:10 +02:00
Thomas Faber c60d25fb26
[NTOS:PNP] Directly accept a UNICODE_STRING in LocateChildDevice. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber 2242ca6920
[NTOS:PNP] Avoid an unnecessary stack buffer in PnpRootCreateDevice. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber 1b0fe76d0d
[NTOS:PNP] Avoid an unnecessary stack buffer in EnumerateDevices. CORE-15882 2020-05-17 20:56:16 +02:00
Thomas Faber ac52401d74
[NTOS:PNP] Move child device creation into its own function
Also fix some leaks and a DPRINT format string.
2020-05-17 20:56:11 +02:00
Timo Kreuzer b82bf8ce16
[NTOS:IO] Fix parsing of resource lists
Also add a hack to avoid failing on now occurring resource conflict detection and try to fix at least one resource in ACPI hal.

CORE-10146
CORE-12892
2020-04-24 13:58:09 +03:00
Vadim Galyant 374f2b4d98
[NTOS][SDK:LIB] Add a Resources Arbiter library, to be used by bus drivers (acpi, pci), kernel and legacy hal (PIC HAL). (#2471) 2020-04-09 19:41:11 +02:00
Vadim Galyant 7db342f8a1
[NTOS:PNP] Add set functions for debugging PNP and IO managers. (#2457)
Useful functions for debugging IO and PNP managers:

PipDumpDeviceNodes() - displays information about a node(s) in the device tree;
PipDumpResourceRequirementsList() - displays information about a Io List;
PipDumpCmResourceList() - displays information about a Cm List

The tree list of devices (DEVICE_NODE structures) is perhaps the main one in the PnP manager. They also store information about the hardware resources required and assigned to devices.
These functions can help with debugging. For example, you can call PipDumpDeviceNodes() before and after device enumeration and compare the resulting information.

For PipDumpDeviceNodes() it is possible to optionally output:
- allocated resources and boot configuration resources
- resources required
- translated resources
It is possible to displays both a single node and the entire tree.
Optionally, you can display child nodes.

The information output format for resource lists is maximally compressed, since often the only debugging port is a monitor.

The DebugLevel parameter allows dumping in two modes:
0 - unconditional;
1 - if NDEBUG is not defined in "debug.c".
2020-04-04 14:30:40 +02:00
Eric Kohl 93e72ed3d6 [NTOS:IO] Fix indentation. No code changes! 2020-03-21 14:32:18 +01:00
Eric Kohl 52d22630f5 [NTOS:PNP] Fix indentation. No code changes! 2020-03-21 13:23:23 +01:00
Eric Kohl a8846037e1 [NTOS:PNP] Map device capabilities to capability flags
This fixes a devices Capabilities value in the registry.
2020-03-21 13:23:22 +01:00
Thomas Faber 72c51aabba
[NTOS:IO][GDI32][CMD] Fix some under-sized variables. CORE-14922
Fixes x64 boot with RTC.
2020-03-13 20:45:06 +01:00
Eric Kohl 7a7212f984 [NTOS:IO] Fix indentation. No code changes! 2020-03-01 23:34:30 +01:00