Commit graph

502 commits

Author SHA1 Message Date
Pierre Schweitzer 15a3ca08b0
[NTOSKRNL] Avoid integer overflow when computing VACB read/write size
This could be triggered when attempting to read/write to really big
files. It was causing an attempt to read 0 bytes in Cc, leading to
asserts failure in the kernel (and corrupted file).

CORE-15067
2018-09-21 08:37:20 +02:00
Pierre Schweitzer 108991a6fb
[NTOSKRNL] Stub IoInitializeCrashDump()
Also call it from NtCreatePagingFile() when we have successfully created
a paging file on the system boot partition.
2018-09-18 21:59:59 +02:00
Pierre Schweitzer 02da7b452c
[NTOSKRNL] Move data mapping implementation to an internel helper 2018-09-09 14:02:13 +02:00
Pierre Schweitzer 3dabca398f
[NTOSKRNL] Don't raise a status when parameters are invalid on file mapping 2018-09-05 22:06:29 +02:00
Pierre Schweitzer e17f61138c
[NTOSKRNL] When allocating a new BCB, save it in a list
This list is stored in the shared map. Later, this will allow
reusing BCB when appropriate
2018-09-05 22:06:25 +02:00
Pierre Schweitzer f96f1224a7
[NTOSKRNL] Fail on pinning when there's no pin access set
Instead of assert, now, CcPinRead will just fail. This is
not consistent without Windows behavior, but still better
than asserting while testing!
2018-09-01 12:41:01 +02:00
Pierre Schweitzer f0eb39084e
[NTOSKRNL] Fix a typo 2018-08-31 19:48:32 +02:00
Pierre Schweitzer e806d16b06
[NTOSKRNL] Warn about unimplemented feature in CcMapData() (in all callers)
Currently, our CcMapData() behavior (same goes for CcPinRead()) is broken
and is the total opposite of what Windows kernel does. By default, the later
will let you map a view in memory without even attempting to bring its
data in memory. On first access, there will be a fault and memory will
be read from the hardware and brought to memory. If you want to force read
on mapping/pinning, you have to set the MAP_NO_READ (or PIN_NO_READ) flag
where kernel will fault on your behalf (hence the need for MAP_WAIT/PIN_WAIT).

On ReactOS, by default, on mapping (and thus pinning), we will force a view
read so that data is in memory. The way our cache memory is managed at the
moment seems not to allow to fault on invalid access and if we don't force
read, the memory content will just be zeroed.
So trying to match Windows behavior, by default, now CcMapData() will enforce
the MAP_NO_READ flag and warn once about this behavior change.
2018-08-31 19:48:32 +02:00
Pierre Schweitzer b8e4af606a
[NTOSKRNL] Properly reset pinning state on pinning failure 2018-08-26 22:56:25 +02:00
Pierre Schweitzer 54f89baad4
[NTOSKRNL] When acquiring BCB shared, starve exclusive waiters 2018-08-26 22:47:48 +02:00
Pierre Schweitzer c1dd4c142f
[NTOSKRNL] Handle the PIN_WAIT flag in CcPinMappedData() 2018-08-26 22:05:11 +02:00
Pierre Schweitzer 469e15c7ae
[NTOSKRNL] Stubplement CcPinMappedData() and simplify CcPinRead()
It's based on the code that was in CcPinRead() implementation. This
made no sense to have CcPinMappedData() doing nothing while implementing
everything in CcPinRead(). Indeed, drivers (starting with MS drivers)
can map data first and pin it afterwards with CcPinMappedData(). It was
leading to incorrect behavior with our previous noop implementation.
2018-08-26 22:05:11 +02:00
Denis Malikov 0cf5efc14c [NTOS:KE] Fix stub for KeAcquireInStackQueuedSpinLockForDpc (#814)
Error was found when building as 0x600+.
CORE-12596
2018-08-26 15:19:26 +02:00
Eric Kohl 06e7233134 [NTOSKRNL] IopGetDeviceProperty: Initialize power data struct and convert flags from device capabilities to power data 2018-08-25 19:49:29 +02:00
Pierre Schweitzer 5c10b02957
[NTOSKRNL] Add the OLE flag where appropriate in FsRtlLegalAnsiCharacterArray
This brings in the ability to check NTFS streams names (OLE | NTFS).
This fixes failing tests from previous commit.
2018-08-25 14:26:49 +02:00
Timo Kreuzer f43a7b81a7
[NTOS:Mm] Fix a 64 bit issue in MmMapViewOfArm3Section (#778)
Fixes a Clang-Cl warning
CORE-14306
2018-08-21 11:25:22 +02:00
Timo Kreuzer d5181e44dd
[NTOS] Fix MiFindInitializationCode (#751)
Short: The code was suffering from an off-by-one bug (inconsistency between inclusive end exclusive end address), which could lead to freeing one page above the initialization code. This led to freeing part of the kernel import section on x64. Now it is consistently using the aligned/exclusive end address.

Long:
* Initialization sections are freed both for the boot loaded images as well as for drivers that are loaded later. Obviously the second mechanism needs to be able to run at any time, so it is not initialization code itself. For some reason someone decided though, it would be a smart idea to implement the code twice, once for the boot loaded images, once for drivers and concluding that the former was initialization code itself and had to be freed.
* Since freeing the code that frees the initialization sections, while it is doing that is not possible, it uses a "smart trick", initially skipping that range, returning its start and end to the caller and have the caller free it afterwards.
* The code was using the end address in an inconsistent way, partly aligning it to the start of the following section, sometimes pointing to the last byte that should be freed. The function that freed each chunk was assuming the latter (i.e. that the end was included in the range) and thus freed the page that contained the end address. The end address for the range that was returned to the caller was aligned to the start of the next section, and the caller used it to free the range including the following page. On x64 this was the start of the import section of ntoskrnl. How that worked on x86 I don't even want to know.
2018-08-21 10:35:57 +02:00
Timo Kreuzer e97b95cc2e [NTOS:MM] Fix ASSERT when expanding paged pool
The page directory is double mapped on x86 in the system process, so writing to it will already write to the PDE.
2018-08-20 23:52:42 +02:00
Timo Kreuzer c219be9409 [NTOS:MM] Fix paged pool expansion 2018-08-20 18:07:35 +02:00
Stanislav Motylkov d033fe9bbf [NTOS:EX] Implement SystemFirmwareTableInformation class 2018-08-19 20:27:59 +02:00
Timo Kreuzer 094a90ad4e [NTOS:PS] Fix an issue with PROCESS_DEVICEMAP_INFORMATION size on 64 bit builds
The PROCESS_DEVICEMAP_INFORMATION  union has 2 fields, one is a handle, the other one is a structure of 36 bytes (independent of architecture). The handle forces 64 bit alignment on 64 bit builds, making the structure 4 bytes bigger than on 32 bit builds. The site is checked in NtQueryInformationProcess (case ProcessDeviceMap). The expected size on x64 is the size of the Query structure without alignment. autocheck correctly passes the site of the Query union member, while smss passes the full size of PROCESS_DEVICEMAP_INFORMATION. Packing the structure is not an option, since it is defined in public headers without packing. Using the original headers sizeof(PROCESS_DEVICEMAP_INFORMATION) is 0x28, sizeof(PROCESS_DEVICEMAP_INFORMATION::Query) is 0x24.
2018-08-17 22:08:37 +02:00
Timo Kreuzer 2c909db295 [NTOS:OB] Rename object types to their official names to satisfy WinDbg
- Rename ObDirectoryType to ObpDirectoryObjectType and remove it from NDK (this is not exported!)
- Rename ObSymbolicLinkType to ObpSymbolicLinkObjectType
- Remove duplicated ObpTypeObjectType from ob.h
2018-08-17 20:28:45 +02:00
Pierre Schweitzer 65f9783808
[NTOSKRNL] Properly initialize the IO_STATUS_BLOCK 2018-08-17 19:13:13 +02:00
Pierre Schweitzer 12e8d7fe0e
[NTOSKRNL] Only allow page file on a few specific device types 2018-08-16 19:00:22 +02:00
Pierre Schweitzer cc59c97308
[NTOSKRNL] Don't need all access for file object 2018-08-16 18:54:23 +02:00
Pierre Schweitzer 8281f4baa6
[NTOSKRNL] Add a check commented out for now.
It's to be enabled once page file handling is moved to ARM3
2018-08-16 18:49:55 +02:00
Pierre Schweitzer 7f0ad923d2
[NTOSKRNL] MmTotalCommitLimit and MmTotalCommitLimitMaximum are in pages, not bytes 2018-08-16 18:40:23 +02:00
Timo Kreuzer dd73d1b6d4 [NTOS:MM] Make SLIST handling for kernel stacks portable
Kernel stacks that re freed, can be placed on an SLIST for quick reuse. The old code was using a member of the PFN of the last stack page as the SLIST_ENTRY. This relies on the following (non-portable) assumptions:
- A stack always has a PTE associated with it.
- This PTE has a PFN associated with it.
- The PFN has an empty field that can be re-used as an SLIST_ENTRY.
- The PFN has another field that points back to the PTE, which then can be used to get the stack base.

Specifically: On x64 the PFN field is not 16 bytes aligned, so it cannot be used as an SLIST_ENTRY. (In a "usermode kernel" the other assumptions are also invalid).

The new code does what Windows does (and which seems absolutely obvious to do): Place the SLIST_ENTRY directly on the stack.
2018-08-16 16:52:02 +02:00
Timo Kreuzer 6c154c0625 [NTOS:SE] Fix SeSetSecurityDescriptorInfoEx to prevent pool corruption on x64 2018-08-16 16:32:49 +02:00
Serge Gautherie 20d4b2cfac [NTOS:MM] Update a DPRINT string (#760)
CORE-12729
2018-08-16 15:10:24 +02:00
Pierre Schweitzer 19318dcc1d
[NTOSKRNL] Start making our MMPAGING_FILE struct look like the real one 2018-08-16 14:04:27 +02:00
Pierre Schweitzer e392bdf962
[NTOSKRNL] Store page file sizes in pages, not in bytes 2018-08-16 13:50:16 +02:00
Pierre Schweitzer 2fe4e71383
[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking 2018-08-16 13:41:16 +02:00
Pierre Schweitzer bfc6a7957c
[NTOSKRNL] Page files don't have an init size, but a minimum size
NFC
2018-08-16 12:42:34 +02:00
Pierre Schweitzer 315867d4ff
[NTOSKRNL] Drop the MmPagingFile spin lock in favor of a guarded mutex 2018-08-16 12:39:24 +02:00
Pierre Schweitzer 891a6eeeb9
[NTOSKRNL] Drop the alloc map from page file
It was making no sense, and implemented in a broken way
that couldn't have worked if code path was used.
2018-08-16 12:16:39 +02:00
Pierre Schweitzer 5bd938bd24
[NTOSKRNL] Stub page file extension support 2018-08-16 11:58:58 +02:00
Pierre Schweitzer 1ea68d0510
[NTOSKRNL] Don't use anonymus allocations for MM objects 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 34e8f45122
[NTOSKRNL] Keep page file name along the page file and free it on shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 5aaadf39db
[NTOSKRNL] Dereference page file objects in MM shutdown phase 1
Hack the call the MM shutdown phase  1
2018-08-13 08:30:17 +02:00
Pierre Schweitzer 3814a822f1
[NTOSKRNL] Close page files (and delete them!) on shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer d793f196df
[NTOSKRNL] Stub MM shutdown 2018-08-13 08:30:17 +02:00
Pierre Schweitzer 02b0ca08e4
[NTOSKRNL] Misc fixes:
- Rename page file struct to MMPAGING_FILE
- Increment page files count after current page file was put in the list
2018-08-11 23:34:08 +02:00
Pierre Schweitzer f106c297de
[NTOSKRNL] Rename PagingFileList to MmPagingFile and make insertion simpler 2018-08-11 23:19:58 +02:00
Pierre Schweitzer 47cd447cfa
[NTOSKRNL] Remove useless define 2018-08-11 23:07:53 +02:00
Pierre Schweitzer f080ee1305
[NTOSKRNL] Replace the alloc map by a bitmap 2018-08-11 23:01:12 +02:00
Pierre Schweitzer fb07332450
[NTOSKRNL] Drop unused field 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 814a6fc098
[NTOSKRNL] Revert r4668 (yeah, that was 15y ago)
It's hardly understandable and doesn't really makes sense.
Furthermore, it breaks compatibility with 3rd party FSD that
don't implement such FSCTL.
Obviously, Windows doesn't do this.
2018-08-11 23:01:11 +02:00
Pierre Schweitzer 28b4b419c2
[NTOSKRNL] Restrict rights on the page file 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 36c20dc56b
[NTOSKRNL] Deny page file creation on floppy disk 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 2969c28a27
[NTOSKRNL] Properly open a page file and set appropriate attributes 2018-08-11 23:01:11 +02:00
Pierre Schweitzer 0ad4ef6002
[NTOSKRNL] Check that caller has appropriate right before creating page file 2018-08-11 23:01:05 +02:00
Serge Gautherie 7d6bda16c6
[REACTOS] Improve how some ASSERTMSG() message values are printed: enforce ending "\n".
NB: Not touching calls in "third-party" code: class and classpnp.
2018-08-08 22:03:45 +02:00
Serge Gautherie 9ff9bd81c4 [NTOSKRNL] Round memory size up, "debug log" part
Assumed to better match actual physical RAM size.

CORE-12321
2018-08-07 20:36:04 +02:00
Mark Jansen b2b1c054e4
[NTOSKRNL] Fix a nullptr dereference in IopStartDevice 2018-08-06 20:51:21 +02:00
Timo Kreuzer ff7cc6f37e [NTOS] Fix 64 bit issues 2018-08-04 19:19:34 +02:00
Pierre Schweitzer cf3b9d5b56
[NTOSKNRL] Only allocate a MDL if we have an output length
For user mode, when probing output buffer, if it's null, length
will also be set to 0.

This avoids user mode applications being able to trigger various
asserts in ReactOS (and thus BSOD when no debugger is plugged ;-)).
2018-07-29 13:58:30 +02:00
Eric Kohl 4ffa0a2e55 [NTOSKRNL][NDK][UMPNPMGR] Define and use PLUGPLAY_CONTROL_PROPERTY_DATA.Properties values
NDK: Define PLUGPLAY_CONTROL_PROPERTY_DATA.Properties and PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA.Relations values.

NTOSKRNL: Map PLUGPLAY_CONTROL_PROPERTY_DATA.Properties values to IoGetDeviceProperty properties and add (dummy) code for unsupported cases.

UMPNPMGR: Use PLUGPLAY_CONTROL_PROPERTY_DATA.Properties values in PNP_GetDeviceRegProp.
2018-07-15 15:57:57 +02:00
Pierre Schweitzer 0075c2a02d
[NTOSKRNL] Be noisy when deferring writes. 2018-07-15 09:57:16 +02:00
Timo Kreuzer ca9fd861aa [DRIVERS][NTOS][NDK] Use IO_STACK_LOCATION instead of EXTENDED_IO_STACK_LOCATION and remove the latter from NDK 2018-07-01 14:45:21 +02:00
Timo Kreuzer de1b195837 [NDK] Fix the type of KPROCESS::ActiveProcessors
Also fix related logic in KiSwapProcess
2018-07-01 14:45:21 +02:00
Hermès Bélusca-Maïto 4d494caf61
[NTOS:SE] Overhaul the token management code.
- Overhaul SepCreateToken() and SepDuplicateToken() so that they
  implement the "variable information area" of the token, where
  immutable lists of user & groups and privileges reside, and the
  "dynamic information area" (allocated separately in paged pool),
  where mutable data such as the token's default DACL is stored.
  Perform the necessary adaptations in SepDeleteToken() and in
  NtSetInformationToken().

- Actually dereference the token's logon session, when needed, in the
  'TokenSessionReference' case in NtSetInformationToken().

- Overhaul SepFindPrimaryGroupAndDefaultOwner() so that it returns
  the indices of candidate primary group and default owner within the
  token's user & groups array. This allows for fixing the 'TokenOwner'
  and 'TokenPrimaryGroup' cases of NtSetInformationToken(), since the
  owner or primary group being set *MUST* already exist in the token's
  user & groups array (as a by-product, memory corruptions that existed
  before due to the broken way of setting these properties disappear too).

- Lock tokens every time operations are performed on them (NOTE: we
  still use a global token lock!).

- Touch the ModifiedId LUID member of tokens everytime a write operation
  (property change, etc...) is made on them.

- Fix some group attributes in the SYSTEM process token, SepCreateSystemProcessToken().

- Make the SeCreateTokenPrivilege mandatory when calling NtCreateToken().

- Update the token pool tags.

- Explicitly use the Ex*ResourceLite() versions of the locking functions
  in the token locking macros.
2018-06-27 23:40:18 +02:00
Hermès Bélusca-Maïto 9594022ce1
[NTOS:SE] Add a documentation note about SeTokenIsWriteRestricted() and SeTokenIsAdmin(), and update the one for NtDuplicateToken().
[XDK] Move TOKEN_HAS_ADMIN_GROUP where appropriate.
2018-06-27 23:40:15 +02:00
Hermès Bélusca-Maïto f61694cfbb
[NTOS:SE] Minor style changes.
- Use TRUE/FALSE instead of 1/0 for booleans.
- Use NULL instead of 0 for null pointers.
- Print 0x prefix for hex values in DPRINTs.
- Use new annotations for SepCreateToken() and SepDuplicateToken().
2018-06-27 23:40:15 +02:00
Hermès Bélusca-Maïto 986bf4c407
[NTOS:SE] In SepCreateClientSecurity(), fix the impersonation level value passed to the SeCopyClientToken() call.
Caught while debugging, in the case the ImpersonationLevel value was
uninitialized, due to the fact it was left untouched on purpose by
PsReferenceEffectiveToken().
2018-06-27 23:40:14 +02:00
Hermès Bélusca-Maïto 0ef734dba4
[FORMATTING] No code change; typo fix. 2018-06-27 23:40:14 +02:00
Hermès Bélusca-Maïto 5b2dda9134
[NTOS:SE] Finish SepCreateImpersonationTokenDacl() implementation.
- Re-enable a commented-out block;
- Return the allocated Dacl.
- Use the correct pool tag when freeing the allocated Dacl.
2018-06-27 23:40:14 +02:00
Hermès Bélusca-Maïto 813879f02f
[NTOS:PS] Adjust the PsReferenceEffectiveToken() prototype in the header; add a comment about the fact that the ImpersonationLevel parameter can be left untouched on purpose in one special case. 2018-06-27 23:40:13 +02:00
Thomas Faber 1d398057a3
[NTOS:CC] Access SectionObjectPointers without lock in CcRosInitializeFileCache. CORE-14691
kmtest:NtCreateSection calls CcInitializeCacheMap with a
NULL value for SectionObjectPointers. This will cause an exception when
trying to access it, which in Windows can be handled gracefully.
However accessing it while holding ViewLock means the lock will not be
released, leading to an APC_INDEX_MISMATCH bugcheck.

This solves the problem by allocating SharedCacheMap outside the lock,
then freeing it again under lock if another thread has updated SharedCacheMap
in the mean time. This is also What Windows Does(TM).
2018-06-05 16:24:13 +02:00
Mark Jansen c7eb46d9fd [NTOSKRNL] Ignore IMAGE_SCN_CNT_UNINITIALIZED_DATA
CORE-12582
CORE-14556
2018-06-03 20:40:51 +02:00
Eric Kohl 4911382913 [NDK] Replace the SYSTEMTIME fields StandardDate and DaylightDate in RTL_TIME_ZONE_INFORMATION by TIME_FIELDs and fix resulting errors
Patch will be sent upstream.

CORE-14658
2018-05-31 17:48:29 +02:00
Serge Gautherie 3ca1ac639c [REACTOS] Improve/Fix some "printf" formats (#555)
The smbios.c one was initially spotted by "Alahndro" on CORE-6328.
2018-05-30 14:18:23 +02:00
Pierre Schweitzer f15afdbc43
[NTOSKRNL] Implement KeQueryValuesProcess().
And make use of it.
2018-05-25 21:40:39 +02:00
Pierre Schweitzer b0b7437882
[NTOSKRNL] Make NtSetInformationJobObject() success for JobObjectExtendedLimitInformation
This fixes pip from Python 2.7.9 starting in ReactOS.
Though it doesn't work due to TLS issues.
2018-05-25 08:48:51 +02:00
Pierre Schweitzer f300ca7245
[NTOSKRNL] Define required sizes with structures sizes 2018-05-25 08:48:51 +02:00
Pierre Schweitzer ffbd6995e6
[NTOSKRNL] Implement NtQueryInformationJobObject().
This is required by some Python2 applications
such as pip.exe
2018-05-25 08:48:51 +02:00
Pierre Schweitzer 2cf9a69bce
[NTOSKRNL] Addendum to 8a8cb4d: don't print uninit pointer. 2018-05-23 08:44:43 +02:00
Pierre Schweitzer 8a8cb4d890
[NTOSKRNL] Only consider SharedCacheMap value once ViewLock is acquired.
This avoids a really nasty race condition in our cache controler where
two concurrents could try to initialize cache on the same file.
This had two nasty effects: first shared map was purely leaked and erased
by the second one. And the private cache map, allocated on the first shared
cache map couldn't be freed and was leading to Mm BSOD (free in a middle of
a block).

This was often triggered while building ReactOS on ReactOS (with multi threads).
With that patch, I cannot crash anylonger while building ReactOS.

CORE-14634
2018-05-23 08:41:46 +02:00
Hermès Bélusca-Maïto de87a936ce
[NTOS] Demote an ASSERT to a mere DPRINT since we only support registry hives with cluster size == 1 in any case so far (other sizes are UNIMPLEMENTED!) 2018-05-19 22:07:06 +02:00
Pierre Schweitzer 7eca874824
[NTOSKRNL] Fix FsRtlStackOverflow work item free.
Oneliner of the day... This typo just prevented the
whole feature to work properly. Because any allocated
work item would miserably fail to be freed.

This will obviously help real world FSD relying on
StackOverflow worker from FsRtl to work better!

CORE-14611
2018-05-10 10:49:17 +02:00
Pierre Schweitzer 65e29b4b1f
[NTOSKRNL] Optimize a bit deferred writes.
In the lazy writer run, first post items that are queued for this.
Only then, start executing deferred writes if any.
If there were any, reschedule immediately a lazy writer run, to keep
Cc warm and to make it unqueue write faster in case of high IOs situation.
To make second lazy writer run happen faster, we keep our state active to
use short delay (1s) instead of standard idle (3s).
2018-05-02 23:33:45 +02:00
Pierre Schweitzer 54c049bd6e
[NTOKSNRL] Always flush dirty VACB.
Recent changes seem to show that it's not
required to be exclusive on VACB to be able
to flush it.

This commit goes with f2c44aa and fixes the
last issues going with copying huge files.
There are no longer BSODs (be it in Mm or Cc).
I could, with 750MB RAM extract a 2GB file from
a 53MB archive and copy a 2,5GB file from a VBox
share to the disk. Note that writes are often
deferred, so if copy works, it's not that fast for now.

Note that it also brings some beloved behavior from
Windows: copy times are totally unreliable now when
writes are deferred. Little remaining times when
actively copying, high remaining times when deferred
writes in action. And goes between both... Sorry! ;-)

https://xkcd.com/612/

CORE-9696
CORE-11175
2018-04-30 22:24:30 +02:00
Pierre Schweitzer 74c5d8b6bd
[NTOSKRNL] Free unused VACB when required.
Same mechanism exists in Windows (even their Cc
is way different from ours...) where when Cc is
out of memory (in their case, out of VACB), we
will start scavenge old & unused VACB to free
some of the memory.

It's useful in case we're operating we big files
operations, we may run out of memory where to map
VACB for them, so start to scavenge VACB to free
some of that memory.

With this, I am able to install Qt 4.8.6 with 2,5GB of RAM,
scavenging acting when needed!

CORE-12081
CORE-14582
2018-04-30 12:10:24 +02:00
Pierre Schweitzer cc54e51495
[NTOSKRNL] Unmark dirty first, and then write.
This will avoid trying to flush twice a dirty VACB under
high IOs pressure.

CORE-14584
2018-04-30 10:36:19 +02:00
Pierre Schweitzer f2c44aa483
[NTOSKRNL] Fix lazy writer for in-use VACB.
Adjusting refcount and enabling lazy-write for pinned
VACB makes it actually more efficient, often purging
data to disk, reducing memory stress for the system.

This is required for defering writes.

This commit unfortunately (?) reverts a previous revert.

CORE-12081
CORE-14582
CORE-14313
2018-04-29 20:42:53 +02:00
Pierre Schweitzer 2ea6de8a42
[NTOSKRNL] Also try to extract name from FCB when leaking VACB 2018-04-27 19:01:35 +02:00
Pierre Schweitzer 43836b0fbb
[NTOSKRNL] In !filecache, try to display FCB name
When no name is set in the file object, try to read the name
from the FCB. We only support FastFAT (ours) FCB for now.

This is clearly a hack, but for a kdbg command, so ;-)
2018-04-27 18:57:30 +02:00
Pierre Schweitzer 579a784e04
[NTOSKNRL] In case we leak a VACB, debug as much information as possible.
CORE-14578
2018-04-27 14:14:56 +02:00
Pierre Schweitzer fcf83315dc
[NTOSKRNL] Noisily dereference mapped VACB on cache release.
It seems that on process killing, some VACB may be deleted while
still mapped. With current reference counting, they will actually
not be deleted, but leaked, and an ASSERT will be triggered.

CORE-14578
2018-04-27 10:23:06 +02:00
Jason Johnson 054c11a02c Correctly bugcheck if we aren't returning a usermode thread (#506)
Cause a corresponding bug check to occur for the reason of the user context flag being zero (a system thread), instead of using DbgBreakPoint.
2018-04-24 23:07:02 +01:00
Hermès Bélusca-Maïto e616a456c0
[NTOSKRNL] Minor PnP enhancements.
- For non-PnP devices reported to the PnP manager through the
  IoReportDetectedDevice() function, store the corresponding
  service/driver name and (non-)legacy information inside their
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\ entries.
- Drivers flagged as "DRVO_BUILTIN_DRIVER" (basically, only those
  created via a IoCreateDriver() call) have their "Service" name that
  contain "\Driver\", which should be stripped before being used in
  building e.g. the corresponding "DETECTEDxxx" PnP compatible IDs.
  CORE-14247

- Use explicit REG_OPTION_NON_VOLATILE flag where needed in the
  IopCreateDeviceKeyPath() calls.
- Save NULL-terminated REG-SZ string properties in the enumeration tree
  for each device enumerated inside \Enum\Root\.
- Always use upcased key name for the "LEGACY_***" elements in \Enum\Root\.
- Add a default "ConfigFlags" value for the legacy elements.
- Simplify few parts of code.
2018-04-22 16:52:45 +02:00
Hermès Bélusca-Maïto fa103197ad
[NTOSKRNL] Whitespace fixes only. 2018-04-22 16:52:40 +02:00
Hermès Bélusca-Maïto 45012aa486
[NTOSKRNL] Set the DRVO_BUILTIN_DRIVER DriverObject flag when a built-in driver is created using IoCreateDriver(). 2018-04-22 16:52:38 +02:00
Hermès Bélusca-Maïto 635775d249
[NTOSKRNL] Set flags the standard way. 2018-04-22 16:52:36 +02:00
Timo Kreuzer e49ef251b7 [NTOS:MM] Fix ViewSize parameter passed to MiInsertVadEx() from MiCreatePebOrTeb()
The size is in bytes, not in pages! On x86 we got away with it, since PEB and TEB require only a single page and the 1 passed to MiInsertVadEx() was aligned up to PAGE_SIZE. On x64 this doesn't work, since the size is 2 pages.
2018-04-22 15:06:19 +02:00
Thomas Faber d82ccaa2a2
[NTOS:PNP] Use pool tagging for DEVICE_ACTION_DATA. CORE-10456 2018-04-18 16:13:14 +02:00
Thomas Faber 121146e651
[NTOS:PNP] Rename IopDeviceRelations* to IopDeviceAction*. CORE-10456 2018-04-18 16:12:56 +02:00
Pierre Schweitzer fd3a6c1089 [NTOSKRNL] Properly reset VACB on free
CID 1434271
2018-04-15 22:52:53 +02:00
Pierre Schweitzer 953dc72dad [NTOSKRNL] Drop the VACB lock.
This has have several benefits for ReactOS Cc:
- It helps reducing potential deadlocks situations in Cc
- It speeds up ReactOS by reducing locks
- It gets us a bit closer to Windows VACB

CORE-14349
2018-04-15 22:52:53 +02:00
Pierre Schweitzer 40017a54f9 [NTOSKRNL] Use interlocked operations when dealing with map count.
CORE-14349
2018-04-15 22:52:53 +02:00
Pierre Schweitzer 1b672981e2 [NTOSKRNL] Map the VACB in kernel space before inserting it in lists.
The avoids race conditions where attempts to read from disk to
not fully initialized VACB were performed.
Also, added more debug prints in such situations.

CORE-14349
2018-04-15 22:52:53 +02:00
Pierre Schweitzer 42df4683d7 [NTOSKRNL] Add extra sanity checks for VACB lists.
We now always initialize list members from the VACB
and make sure the list entry has properly been removed
from the list before free.

CORE-14349
2018-04-15 22:52:53 +02:00
Thomas Faber b54e5c689c
[NTOS:MM] Do not map two pages into hyperspace in MiCopyFromUserPage. CORE-14548
Doing this is not only wrong because it acquires the same spinlock twice,
it also completely breaks the TLB flushing logic in MiMapPageInHyperSpace.
If the PTE with Offset 1 is still valid when a wrap-around to 0 happens,
the TLB flush on wrap-around will not clear the entry for this previous page.
After another loop around all hyperspace pages, page 1 is re-used but its
TLB entry has not been flushed, which may result into incorrect translation.
2018-04-15 20:07:21 +02:00
Serge Gautherie 6618a2fd2c [NTOS:CC] Use UNIMPLEMENTED_ONCE instead of custom code
- Rewrite e319f85e67.
2018-04-07 12:00:10 +02:00
Mark Jansen a5f12908df
[NTOSKRNL] Fix IopValidateID using uninitialized var, reset SeparatorsCount in the MultiSz case. 2018-04-05 22:06:31 +02:00
Timo Kreuzer 6b1ca75899
[REACTOS] Fix 64 bit build (#465)
* [HAL] Simplify HalpReboot() and make it portable
* [NTOS:MM] Cast constant to PVOID
* [BINPATCH] Fix 64 bit build
* [VFDDRV] Fix 64 bit build and buffer overruns
* [USBOHCI] Fix structure alignment issues
* [ATL_APITEST] Fix 64 bit build
* [XDK] Update unwind structures in winnt.h
* [NTDLL_APITEST] Fix 64 bit build
* [NTDLL_WINETEST] Fix 64 bit build
* [TFTPD] Fix x64 build
* [USBPORT] Fix a C_ASSERT
* [DSOUND] Fix x64 build
* [HAL] Remove obsolete GetPteAddress() macro
2018-04-03 15:13:17 -06:00
Hermès Bélusca-Maïto c54aaacc8e
[NTOSKRNL] Formatting fix only. 2018-04-01 22:51:24 +02:00
Hermès Bélusca-Maïto 6cefd1242d
[NTOSKRNL] Simplify NtRaiseHardError() by merging the terminating blocks.
- Return the status codes provided by the Ex(p)RaiseHardError() calls.
- Fix the return values in case of failure.
2018-04-01 22:50:56 +02:00
Hermès Bélusca-Maïto ea390c2b3f
[NTOSKRNL] ExRaiseHardError(): Protect strings copy to user-mode space inside a SEH block. 2018-04-01 22:50:44 +02:00
Hermès Bélusca-Maïto 842605e3ef
[NTOSKRNL] Don't emit hard errors for the calling thread if hard errors have been disabled for this thread on user-mode side. 2018-04-01 22:50:33 +02:00
Hermès Bélusca-Maïto 3a0ecb3dc8
[NTOSKRNL] Don't hardcode flag values for DefaultHardErrorProcessing. 2018-04-01 22:50:16 +02:00
Hermès Bélusca-Maïto 1fadfea053
[NTOSKRNL] Update Doxygen descriptions for NtRaiseHardError, ExRaiseHardError, ExpRaiseHardError and NtSetDefaultHardErrorPort. 2018-04-01 22:39:32 +02:00
Hermès Bélusca-Maïto f0729b30bb
[NTOSKRNL] Forbid processes without the Tcb prvilege to perform a user-mode hard-error BSOD. 2018-04-01 22:39:31 +02:00
Hermès Bélusca-Maïto ed06b843fb
[NTOSKRNL] In addition to the hard-error port, reference also the process that handles the hard errors so that it doesn't disappear behind our back. On shutdown both the hard-error port and process are dereferenced. 2018-04-01 22:39:30 +02:00
Pierre Schweitzer ffd524275e
[NTOSKRNL] Properly delete VACB in CcRosCreateVacb() when mapping fails.
Spotted by Thomas.

CORE-14478
CORE-14502
2018-03-25 18:27:19 +02:00
Pierre Schweitzer 14b05e65ff
[NTOSKRNL] Use interlocked operations for VACB reference counting.
CORE-14480
CORE-14285
2018-03-24 19:15:58 +01:00
Pierre Schweitzer dea9c291ab
[NTOSKRNL] Add a few asserts when mapping a VACB in kernel space
Also, reset VACB content when returning it to the lookaside list

CORE-14478
2018-03-24 19:15:58 +01:00
Pierre Schweitzer 2b6df67f0a
[NTOSKRNL] More asserts regarding reference count
CORE-14285
CORE-14480
2018-03-24 11:59:45 +01:00
Vadim Galyant 111e19f8a4 [NTOSKRNL] Adding IopValidateID() to test characters in PnP IDs (IRP_MN_QUERY_ID). (#341) 2018-03-19 14:04:17 +01:00
Thomas Faber a17bf6f669
[NTOS:MM] Improve debug prints in MmCreateVirtualMappingUnsafe. CORE-14478 2018-03-18 23:49:48 +01:00
Pierre Schweitzer 1e579843bc
[NTOSKNRL] Always reference a newly created VACB
This allows being consistent between newly created and looked up
so that VACB can always safely be released.

Should really help with reference issues.

CORE-14481
CORE-14480
CORE-14482
2018-03-18 18:16:55 +01:00
Pierre Schweitzer 2a0e996c9d
[NTOSKRNL] In CcRosInternalFreeVacb(), in case of invalid free, also print file name.
CORE-14481
CORE-14480
CORE-14482
2018-03-18 13:21:54 +01:00
Pierre Schweitzer 2fbba22789
[NTOSKRNL] In CcFlushCache(), release the VACB using CcRosReleaseVacb()
Instead of reimplementing it partially and wrongly.

CORE-14481
CORE-14480
CORE-14482
2018-03-18 13:21:54 +01:00
Pierre Schweitzer 13b57fb5b5
[NTOSKRNL] Misc fixes to VACB reference counting
This fixes various bugs linked to VACB counting:
- VACB not released when it should be
- Reference count expectations not being accurate

For the record, VACB should always have at least a reference
count of 1, unless you are to free it and removed it from
any linked list.

This commit also adds a bunch of asserts that should
help triggering invalid reference counting.

It should also fix numerous ASSERT currently triggered and
may help fixing random behaviours in Cc.

CORE-14285
CORE-14401
CORE-14293
2018-03-17 11:56:25 +01:00
Thomas Faber 2b8f4f6e24
[NTOS:EX] Worker threads must not exit with a critical region held. CORE-13734 2018-03-07 13:18:09 +01:00
Thomas Faber 6b78ff036f
[NTOS:KE] Don't loop indefinitely trying to figure out the CPU frequency. CORE-14419
Previously, we would keep sampling the CPU frequency until two subsequent
samples differed by at most 1 MHz. This could take several seconds, and would
unnecessarily delay boot.
Instead, if sampling is too unreliable, just give up and calculate the average
frequency from 10 samples. This is no worse than picking the frequency that
just happened to be returned twice in a row.

The fact that this method of sampling fails could indicate that there's a
problem with our performance counter implementation or timer interrupt,
but that's a separate issue...
2018-03-01 14:26:44 +01:00
Pierre Schweitzer c4f58bbfd8
[NTOKSRNL] Don't blindly schedule read-ahead on CcCopyRead() call.
This avoids locking Cc for too long by trying to read-ahead data which
is already in cache.
We now will only schedule a read ahead if next read should bring us
to a new VACB (perhaps not in cache).

This notably fixes Inkscape setup which was slown down by read-ahead
due to continous 1 byte reads.

Thanks to Thomas for his help on this issue.

CORE-14395
2018-02-28 20:58:36 +01:00
Pierre Schweitzer 62facb7a49
[NTOSKRNL] Implement ThreadHideFromDebugger in NtSetInformationThread() 2018-02-24 22:07:12 +01:00
Pierre Schweitzer a3c58ca76f
[NTOSKRNL] Implement the support for reserve IRP in IO
The reserve IRP is an IRP which is allocated on system boot and kept during
the whole system life. Its purpose is to allow page reads in case of
low-memory situations where the system doesn't have enough memory left
to allocate an IRP to read from the page file (would be catastrophic situation).
2018-02-24 14:52:04 +01:00
Pierre Schweitzer 9ac2e9855a
[NTOSKRNL] Add the CcDataFlushes and CcDataPages counters 2018-02-24 14:52:04 +01:00
Pierre Schweitzer 0fbdf31709
[NTOSKRNL] Add the CcPinReadWait and CcPinReadNoWait counters 2018-02-24 14:52:04 +01:00
Pierre Schweitzer 45964099f3
[NTOSKRNL] Return some Cc counters in SystemPerformanceInformation 2018-02-24 13:36:26 +01:00
Pierre Schweitzer 227c4321c2
[NTOSKRNL] Add the CcMapDataWait and CcMapDataNoWait counters 2018-02-24 13:36:26 +01:00
Thomas Faber a2f77ee3fb
[NTOS:CC] Don't read past the end of the file in CcPerformReadAhead. 2018-02-22 14:03:05 +01:00
Thomas Faber 56e2bf2f92
[NTOS:CC] Avoid some magic numbers. 2018-02-22 14:03:03 +01:00
Pierre Schweitzer dd392b9d6c
[NTOSKRNL] Fix mismatching spinlock release in CcPerformReadAhead() 2018-02-18 19:32:08 +01:00
Pierre Schweitzer e319f85e67
[NTOSKRNL] Don't make CcScheduleReadAhead() too noisy 2018-02-18 11:31:14 +01:00
Pierre Schweitzer bdae0cce66
[NTOSKRNL] Don't call OOM dumper in case we were trying to allocate more than 100 pages.
In such case, we'll consider the caller is bogus and we'll fail in silence.
Dedicated to Mark (again!)
2018-02-17 15:09:38 +01:00
Pierre Schweitzer 01fcb02880
[NTOSKRNL] Allow more chars in ExpTagAllowPrint().
Dedicated to Mark
2018-02-17 15:06:29 +01:00
Pierre Schweitzer bd70987909
[NTOSKRNL] In debug builds, print more information about the top level IRP in the Cc worker thread
CORE-14315
2018-02-10 23:50:26 +01:00
Pierre Schweitzer a6e080bd3d
[NTOSKRNL] Avoid private cache map allocation for the first handle
Standard shared cache map provides space for a private cache map, do the same
and make it available for the first handle. It avoids two allocations in a row.
2018-02-09 21:52:41 +01:00
Pierre Schweitzer 5d93941d31
[NTOSKRNL] Modified CcCanIWrite to handle Mm throttling limits 2018-02-09 14:22:00 +01:00
Pierre Schweitzer 6b0cb54fe5
[NTOSKRNL] Define the throttling limits for Cc in Mm: MmThrottleTop, MmThrottleBottom.
Modified !defwrites to reflect that change
2018-02-09 14:21:14 +01:00
Pierre Schweitzer 945ff8ea2e
[NTOSKRNL] Rewrite CcCanIWrite() to make it more accurate and handle specific callers 2018-02-09 13:56:16 +01:00
Pierre Schweitzer f51b74ca61
[NTOSKRNL] Don't defer write through write operations 2018-02-09 12:25:58 +01:00
Pierre Schweitzer d35243d4e0
[NTOSKRNL] Quickly implement the !defwrites in KDBG 2018-02-09 12:16:29 +01:00
Pierre Schweitzer 0518444217
[NTOSKRNL] Drop the iSharedCacheMapLock in favor of the master lock 2018-02-09 11:13:53 +01:00
Pierre Schweitzer 8119e0ad2b
[NTOSKRNL] Silence lazy writer now we know it works 2018-02-09 11:05:44 +01:00
Pierre Schweitzer fc4744da5f
[NTOSKRNL] Use better locking for private cache map in CcRosReleaseFileCache().
Suggested by Thomas
2018-02-09 11:05:15 +01:00
Pierre Schweitzer c5139563db
[NTOSKRNL] Bring an initial (and not perfect ;-)) implementation of read ahead to our Cc!
This halfplements CcScheduleReadAhead() which is responsible for finding the next reads
to perform given last read and previous reads. I made it very basic for now, at least
to test the whole process.
This also introduces the CcExpressWorkQueue in the lazy writer which is responsible
for dealing with read ahead items and which is dealt with before the regular queue.
In CcCopyData(), if read was fine, schedule read ahead so that it can happen in background
without the FSD to notice it! Also, update the read history so that scheduling as a
bit of data.
Implement (à la "old Cc" ;-)) CcPerformReadAhead() which is responsible for performing
the read. It's only to be called by the worker thread.

Side note on the modifications done in CcRosReleaseFileCache(). Private cache map
is tied to a handle. If it goes away, private cache map gets deleted. Read ahead
can run after the handle was closed (and thus, private cache map deleted), so
it is mandatory to always lock the master lock before accessing the structure in
read ahead or before deleting it in CcRosReleaseFileCache(). Otherwise, you'll
just break everything. You've been warned!

This commit also partly reverts f8b5d27.

CORE-14312
2018-02-09 10:14:11 +01:00
Pierre Schweitzer f0c7f862d4
[NTOSKRNL] Fix a ****ing bug where private cache map was deleted in CcUninitializeCacheMap()
before the call to CcRosReleaseFileCache() which expects to have it to properly clean the file.
So, move deletion code to CcRosReleaseFileCache() so that he's the only one to handle private map.
Should hopefully fix all the recent buildbots issues (and the universe perhaps, who knows?)
2018-02-08 14:15:02 +01:00
Pierre Schweitzer f8b5d27807
[NDK] Update the PRIVATE_CACHE_MAP structure to match W2K3 one.
Also update the spin lock on allocation.
2018-02-08 14:02:42 +01:00
Pierre Schweitzer de897cbe3d
[NTOSKRNL] Revert 2362e0f and 07e6e9c (partly) they seem to have caused high instability in Cc.
This reverts BCB being lazy written when marked dirty.

We'll go back to this behavior when this part will have been reworked and stabilized.

CORE-14263
CORE-14279
CORE-14285
2018-02-08 13:40:54 +01:00
Pierre Schweitzer e26e4445b3
[NTOSKRNL] Revert 6ece4e9fc2 for third tools compatibility 2018-02-08 11:50:45 +01:00
Pierre Schweitzer df5839db5b
[NTOSKRNL] Implement CcSetAdditionalCacheAttributes() 2018-02-08 11:49:22 +01:00
Pierre Schweitzer f8c3f0c9c4
[NTOSKRNL] Misc cosmetic changes 2018-02-08 11:02:26 +01:00
Pierre Schweitzer 9c87925197
[NTOSKRNL] Implement CcSetReadAheadGranularity() 2018-02-08 11:02:26 +01:00
Pierre Schweitzer c19c7c7674
[NTOSKRNL] Magic value-- 2018-02-08 11:02:26 +01:00
Pierre Schweitzer 074e7e97fe
[NTOSKRNL] When initializing file cache, also allocate a private cache map if needed.
Not used yet.
2018-02-07 23:18:54 +01:00
Pierre Schweitzer 0e932c7bef
[NTOSKRNL] Drop the CcTryToInitializeFileCache() which is actually doing nothing relevant 2018-02-07 22:23:49 +01:00
Serge Gautherie 6ece4e9fc2 [NTOS:KE] Replace "Fatal System Error" with "BugCheck" 2018-02-07 22:22:28 +01:00
Pierre Schweitzer 323f71a551
[NTOSKRNL] Use the LockQueueMasterLock where appropriate 2018-02-07 21:37:17 +01:00
Pierre Schweitzer 19c822341b
[NTOSKRNL] Handle FSRTL_FLAG_LIMIT_MODIFIED_PAGES flag in CcDeferWrite().
Util now, CcDeferWrite() was ignoring limits per file object.
2018-02-07 21:37:17 +01:00
Pierre Schweitzer c11e947f61
[NTOSKRNL] Add wait support in CcCanIWrite() 2018-02-07 21:37:17 +01:00
Pierre Schweitzer 92e64a6c9b
[NTOSKRNL] Implement CcPostDeferredWrites() that executes deferred writes.
Make use of it in the lazy writer
2018-02-07 21:37:17 +01:00
Pierre Schweitzer f4e67aa837
[NTOSKRNL] Properly implement lazy writer activity watching.
We get rid of the old iLazyWriterNotify event in favor of work items
that contain an event that lazy writer will set once its done.
To implement this, we rely on the newly introduced CcPostTickWorkQueue work queue
that will contain work items that are to be queued once lazy writer is done.

Move the CcWaitForCurrentLazyWriterActivity() implementation to the
lazy writer file, and reimplemented it using the new support mechanisms
2018-02-07 21:37:17 +01:00
Pierre Schweitzer 7e550edb26
[NTOSKRNL] Drop the always running thread for lazy writer.
Instead move to a threading model like the Windows one.
We'll queue several work items to be executed in a system thread (Cc worker)
when there are VACB that have been marked as dirty. Furthermore, some delay
will be observed before action to avoid killing the system with IOs.
This new threading model opens way for read ahead and write behind implementation.

Also, moved the initialization of the lazy writer to CcInitializeCacheManager()
it has nothing to do with views and shouldn't be initialized there.

Also, moved the lazy writer implementation to its own file.

Modified CcDeferWrite() and CcRosMarkDirtyVacb() to take into account the new threading model.

Introduced new functions:
- CcPostWorkQueue(): post an item to be handled by Cc worker and spawn a worker if required
- CcScanDpc(): called after some time (not to have lazy writer always running) to queue a lazy scan
- CcLazyWriteScan(): the lazy writer we used to have
- CcScheduleLazyWriteScan(): function to call when you want to start a lazy writer run. It will make a DPC after some time and queue execution
- CcWorkerThread(): the worker thread that will handle lazy write, read ahead, and so on
2018-02-07 21:37:17 +01:00
Pierre Schweitzer 3b147adafb
[NTOSKRNL] On Cc init, also define CcNumberWorkerThreads which will be used later on
Also make a "default" case (really limited) in case SystemSize doesn't match.
2018-02-07 21:37:17 +01:00
Pierre Schweitzer 853f04e6fc
[NTOSKRNL] Rename ExpCriticalWorkerThreads and ExpDelayedWorkerThreads (no p)
to match Windows names and make them available for the whole kernel.
2018-02-07 21:37:17 +01:00
Pierre Schweitzer ee7b3b315d
[NTOSKRNL] Save system size on init in CcCapturedSystemSize 2018-02-07 21:37:17 +01:00
Pierre Schweitzer d56a249089
[NTOSKRNL] Define the Mm global variables related to Cc on Mm init.
This means that MmSystemCacheStart, MmSystemCacheEnd, MmSizeOfSystemCacheInPages
have now a valid value.
System cache is not used atm the moment though. MmMapViewInSystemCache() is to
be implemented, and Cc is to be made aware of this.

CORE-14259
2018-02-06 13:41:23 +01:00
Timo Kreuzer dae88fb828 [NTOS:MM] Make x64 address space layout more like Vista+
- Change MM_SYSTEM_SPACE_START to 0xFFFFF88000000000
- Move MI_DEBUG_MAPPING to the end of the system PTE range
- Add MI_SYSTEM_CACHE_START and MI_SYSTEM_CACHE_END, which is in the range that Vista uses as dynamic VA space for cache and other allocations
- Wrap x86 specific code that makes now invalid assumptions about the address space layout in #ifdef _M_IX86
2018-02-05 01:09:32 +01:00
Pierre Schweitzer 41792c517e
[NTOSKRNL] Yet another ASSERT...
CORE-14285
2018-02-04 22:02:27 +01:00
Pierre Schweitzer 8dc4ac3692
[NTOSKRNL] Add an assert against VACB reference count overflow.
Very likely to be hit...

CORE-14285
2018-02-04 21:46:08 +01:00
Pierre Schweitzer 3f8788d6e5
[NTOSKRNL] Add an helper for marking a VACB clean (ie, not dirty).
CORE-14263
2018-02-01 08:36:17 +01:00
Pierre Schweitzer f8d58bba38
[NTOSKRNL] Don't let CcWriteVirtualAddress() deal with VACB dirty status
CORE-14263
2018-01-31 21:47:20 +01:00
David Quintana 9b89cd1ef2
[NTOSKRNL] Fix CcIdleDelay initializer for old msvc versions (#339)
[NTOSKRNL] Fix initialization of CcIdleDelay for msvc builds (fixes boot).
* Introduce a macro to initialize LARGE_INTEGERs in a consistent way.
2018-01-31 18:12:57 +01:00
Thomas Faber 6e750d189a
[NTOS:CM] Correctly interpret RtlCreateUnicodeString return value. CORE-14271 2018-01-31 10:37:56 +01:00
Pierre Schweitzer b49a2d6356
[NTOSKRNL] Drop ROS_DEFERRED_WRITE_CONTEXT in favor of DEFERRED_WRITE
that was introduced in d3e0eb2.

CORE-14235
2018-01-28 11:55:40 +01:00
Pierre Schweitzer 52287be9a9
[NTOSKRNL] Misc fixes to Cc:
- CcUnpinDataForThread() only release VACB when the last BCB reference is gone. This avoids having a valid BCB with an invalid VACB
- CcRosMarkDirtyVacb() will only accept non-dirty VACB now. This avoids a major bug where a an already dirty VACB was over-dereferenced
- Thanks to previous point, simplify CcRosUnmapVacb(), CcRosReleaseVacb() implementation
- And only set VACB dirty once in CcSetDirtyPinnedData()
- Add a few sanity checks

With that I can again install ReactOS with 128MB RAM :-).

CORE-14263
CORE-14268
2018-01-28 11:14:15 +01:00
Thomas Faber d3a29816ce
[NTOS:MM] Assert MmLocateMemoryAreaByAddress return value to satisfy Coverity. CID 701289 2018-01-28 10:48:27 +01:00
Thomas Faber 5c52ded05f
[NTOS:PS] Check for rundown success in PsReferenceProcessFilePointer. CID 514553 2018-01-28 10:48:19 +01:00
Pierre Schweitzer f032b77c51
[NTOSKRNL] Fix MSVC build? 2018-01-27 22:02:01 +01:00
Pierre Schweitzer 2d4a54dcf2
[NTOSKRNL] Hello CcIdleDelay :-)
(Good link for the interested reader: https://msdn.microsoft.com/en-us/library/bb742613.aspx)
2018-01-27 21:52:19 +01:00
Pierre Schweitzer 78664ebe15
[NTOSKRNL] On file cache deletion, only manipulate VACB once locked.
Should help avoiding race conditions with lazy write.

CORE-14263
2018-01-27 18:37:34 +01:00
Pierre Schweitzer a3d78067ab
[NTOSKRNL] When marking a VACB dirty on unmap/unpin, use CcRosMarkDirtyVacb().
This should help reducing race conditions with lazy writer, and thus reduce random BSODs.

CORE-14263
2018-01-27 10:59:27 +01:00
Pierre Schweitzer dc85171674
[NTOSKRNL] Simplify (and speedup!) CcCanIWrite() using the dirty pages count in cache map. 2018-01-26 10:50:13 +01:00
Pierre Schweitzer 5cc0668b21
[NTOSKRNL] Store the total dirty pages per shared cache map in it. 2018-01-26 10:42:09 +01:00
Pierre Schweitzer 2362e0faae
[NTOSKRNL] Allow pinned dirty VACB to be lazy written.
This is an addition to 07e6e9c.
Also, fix a cppcheck warning (so minor!).

CORE-14249
2018-01-25 22:00:20 +01:00
Pierre Schweitzer 9c27193a43
[NTOSKRNL] Contrary to WinDBG !filecache, we don't display CONTROL_AREA but shared cache map 2018-01-25 13:47:00 +01:00
Pierre Schweitzer 5c52ae6695
[NTOSKRNL] Fix MSVC build? 2018-01-24 22:03:23 +01:00
Pierre Schweitzer cb52c82125
[NTOSKRNL] Implement (it's a bit raw for now!) the !filecache command in KDBG 2018-01-24 21:46:16 +01:00
Pierre Schweitzer 9d1e16663a
[NTOSKRNL] Link all the shared cache map together. 2018-01-24 21:46:16 +01:00
Pierre Schweitzer 4a910a12cc
[NTOSKRNL] Make lazy writer thread run with higher priority.
CORE-14248
2018-01-24 10:09:19 +01:00
Pierre Schweitzer f93acd806a
[NTOSKRNL] Implement per-file dirty page threshold.
Namely, implement CcSetDirtyPageThreshold() and add support for it
in CcCanIWrite().

Also added my name in the headers of the few files I touched tonight.

CORE-14235
2018-01-23 23:25:26 +01:00
Pierre Schweitzer 389f683026
[NTOSKRNL] Unexpected cleanup 2018-01-23 23:25:26 +01:00
Pierre Schweitzer 9a07c71eef
[NTOSKRNL] Implement support for deferred writes in Cc.
Namely, implement CcCanIWrite() (very basic, and likely wrong).
And implement CcDeferWrite() which will queue the write operation.

In CciLazyWriter() (which may be renamed CcWorkerThread() ;-)),
handle the queued write operations one by one. This is likely
not to be accurate, but, given we have only on FS supporting
this for now (NFS / RDBSS / Shares), this is OK.

CORE-14235
2018-01-23 23:25:26 +01:00
Pierre Schweitzer 07e6e9c9c1
[NTOSKRNL] When marking a BCB dirty, also mark the underlying VACB dirty.
Experiment and MSDN tend to show that a dirty BCB is queued for lazy write.
This will do the job here!

Also, renamed CcRosMarkDirtyFile() which is more accurate, and added a new
function CcRosMarkDirtyVacb() which just takes a VACB as arg (expected locked)
and marks it dirty (using previous implementation). Make CcRosMarkDirtyFile()
use it.

CORE-14235
2018-01-23 23:25:26 +01:00
Pierre Schweitzer 6ba67b8152
[NTOSKRNL] Bug fix: lazy write more often.
CcDirtyPageThreshold is not here to compute when you have to write,
but to know where you have to deny writes.
More commits to come in that direction!

CORE-14235
2018-01-23 23:25:26 +01:00
Pierre Schweitzer c7ad200f8b
[NTOSKRNL] Reimplement the lazy writer in Cc and remove the "basic" one in Mm.
This removes the "modified page writer" thread in Mm that was regularly blindly
attempting to flush dirty pages to the disk.
Instead, this commit introduces a lazy writer that will monitor dirty pages count
and will flush them to disk when this count is above a threshold. The threshold is
computed on Cc init.
Compared to what was done previously, this lazy writer will only write down files
that are not marked as temporary.
The mechanisms involved in this lazy writer worker are well described in Windows
Internals 4th editions (constants are coming from it ;-)).
Also fixed a bad (and old!) bug in CcRosFlushDirtyPages() where target count could
be overflow and the function would spin forever while holding the VACBs lock. This is
mandatory as now lazy writer will call it with "random" values.
This also allows implementing CcWaitForCurrentLazyWriterActivity() :-).
Also renamed DirtyPageCount to its MS equivalent.

CORE-14235
2018-01-23 19:33:59 +01:00
Pierre Schweitzer 2abb99faa9
[NTOSKRNL] In FsRtlAddToTunnelCache() allocate memory from PagedPool when required.
Also, if allocating from lookaside list, reattempt a cold allocation.
2018-01-20 21:21:00 +01:00
Thomas Faber fda24da872
[NTOS] Remove unnecessary NULL checks and add a missing one. CIDs 1411958, 716670, 1322186 2018-01-20 15:59:35 +01:00
Thomas Faber 2ae756a4e5 [NTOS:MM] Fix broken ASSERT. CID 701285 2018-01-16 22:29:19 +01:00
Pierre Schweitzer c779dbd4c5
[NTOSKRNL] Implement CcIsThereDirtyData() 2018-01-15 23:20:53 +01:00
Timo Kreuzer 2dade10d54 [NTOS] Fix 64 bit warnings 2018-01-14 13:54:14 +01:00
Pierre Schweitzer 371aba1abe
[NTOSKRNL] When mapping data in CcMapData(), don't truncate offset to ULONG.
This would affect reads/writes on large volumes where offset is higher than what a ULONG can hold.

This really nasty bug was hitting CcMapData() but also CcPinRead() (due to the nature of its implementation)
and both were returning garbage data under certain circumstances with Ext2Fsd.

This should (I hope!) help some other FSDs to work better in ROS.

CORE-12456
2018-01-13 21:30:37 +01:00
Mark Jansen 7b398514f1 [NTOS] Limit the spam from NtNotifyChangeMultipleKeys.
CORE-13125
2018-01-08 22:24:54 +01:00
Timo Kreuzer 1014d50a4b [NTOS:MM] Pass FaultCode to MiDispatchFault 2018-01-06 18:20:24 +01:00
Timo Kreuzer 3f426aabde [NTOS:MM] Mark local functions with static 2018-01-06 18:20:24 +01:00
Timo Kreuzer a00378a1a1 [NTOS:MM] Add support for NX page-faults 2018-01-06 18:20:24 +01:00
Timo Kreuzer 4d043aa05e [NTOS:MM] Make use of FaultCode and MI_IS_NOT_PRESENT_FAULT and MI_IS_WRITE_ACCESS macros in MmArmAccessFault. 2018-01-06 18:20:24 +01:00
Timo Kreuzer d5c71429d7 [NTOS:MM] Pass The FaultCode to MmArmAcceessFault as well and translate it there to what was declared as "StoreInstruction"
No functional changes.
2018-01-06 18:20:24 +01:00
Timo Kreuzer 3021c2d571 [NTOS:MM] Pass page fault code to MmAccessFault
Note: before we had a BOOLEAN parameter called StoreInstruction, but in reality it was not specifying whether the fault was from a store store instruction, but whether it was an access violation rather than a page-not-present fault. On x86 without PAE there are only 2 kinds of access violations: (1) Access of a kernel mode page from user mode, which is handled early and (2) access of a read-only (or COW) page with a writing instruction. Therefore we could get away with this, even though it relied on the wrong assumption that a fault, which was not a page-not-present-fault, was automatically a write access. This commit only changes one thing: we pass the full fault-code to MmAccessFault and handle the rest from there in exactly the same way as before. More changes are coming to make things clear.
2018-01-06 18:20:24 +01:00
Colin Finck f5d366b200
[NTOS:CM] Improve code in cmsysini.c (#216)
Based on an original patch by Timo Kreuzer, with modifications by me to adapt it to latest HEAD and use a single exit path through the Cleanup label. This reliably frees all allocated handles.

The original code returns STATUS_SUCCESS for many cases. This has been preserved.
In the future, it should be checked though whether returning success is appropriate for all these cases.

CORE-6844
2018-01-06 13:27:41 +01:00
Timo Kreuzer f555c102b7 [NTOS:EX] Don't dereference ExpCritSecOutOfMemoryEvent when it was never referenced. 2018-01-04 21:05:10 +01:00
Katayama Hirofumi MZ a8bd06be98
[NTOS:KDBG] Fix DPRINT format specifier in KdPortInitializeEx. CORE-14174 2018-01-04 11:37:50 +01:00
Timo Kreuzer d17812f933 [NTOS:MM] Use MiResolveDemandZeroFault instead of MiDispatchFault 2018-01-03 23:07:19 +01:00
Timo Kreuzer d4765fe366 [NTOS:MM] Implement resolving PXE/PPE page table demand zero faults 2018-01-03 23:07:19 +01:00
Timo Kreuzer 2eff510074 [NTOS:MM] Increment Prcb->MmDemandZeroCount while holding the Pfn lock 2018-01-03 23:07:19 +01:00
Timo Kreuzer 1240ed9e18 [NTOS/MM] Add Protection parameter to MiResolveDemandZeroFault 2018-01-03 23:07:19 +01:00
Hermes Belusca-Maito b2be558e61 [NTOS:INBV] Simplify a little bit the BootLogoFadeIn() function
- Use KeDelayExecutionThread() instead of KeStallExecutionProcessor().
- Fix magic values and add comments.
- Fix structure name.
2018-01-03 02:57:28 +01:00
Stanislav Motylkov dd71fb5ec8 [NTOS:INBV] Implement rotation bar for boot screen
CORE-10327 #resolve
2018-01-03 02:57:28 +01:00
Timo Kreuzer c4d6c2c3f1 [NTOS:KE] Fix pushing of fake error code in KiDoubleFaultAbort (amd64) 2018-01-01 12:09:38 +01:00
Timo Kreuzer a2f7de7ee8
Amd64/misc 64bit fixes (#236)
[REACTOS] Misc 64 bit fixes

* [NTOS:MM] Allow MEM_DOS_LIM in NtMapViewOfSection on x64 as well
* [NTOS:MM] Implement x64 version of MmIsDisabledPage
* [HAL] Remove obsolete code
* [NTOS:KE] Fix amd64 version of KeContextToTrapFrame and KeTrapFrameToContext
* [XDK] Fix CONTEXT_XSTATE definition
* [PCNET] Convert physical address types from pointers to PHYSICAL_ADDRESS
2018-01-01 12:07:50 +01:00
Hermès Bélusca-Maïto 9fa693e59b
[REACTOS] Switch to year 2018...
... and Happy New Year 2018 to everyone!!

☆.¸¸.•´☆.¸¸.•´☆.¸¸.•´☆.¸¸.•´☆

  ⋱★⋰⋱☆⋰⋱★⋰⋱☆⋰⋱☆⋰⋱★⋰⋱☆⋰⋱★⋰
░░░░░░█░█ █▀█ █▀█ █▀█ █░█░░░░░░
░░░░░░█▀█ █▀█ █▀▀ █▀▀ ▀█▀░░░░░░
░░░░░░▀░▀ ▀░▀ ▀░░ ▀░░ ░▀░░░░░░░
█▄░█ █▀▀ █░█░█░░█░█ █▀▀ █▀█ █▀█
█░██ █▀▀ █░█░█░░▀█▀ █▀▀ █▀█ ██▀
▀░░▀ ▀▀▀ ░▀▀▀░░░░▀░ ▀▀▀ ▀░▀ ▀░▀
  ⋱☆⋰⋱★⋰⋱☆⋰⋱★⋰⋱★⋰⋱☆⋰⋱★⋰⋱☆⋰
░░░▄████▄░▄███▄░░▄██░▄████▄░░░
░░░▀▀░▄██░██░██░████░██▄▄██░░░
░░░░▄██▀░░██░██░░░██░██▀▀██░░░
░░░██████░▀███▀░░░██░▀████▀░░░

☆.¸¸.•´☆.¸¸.•´☆.¸¸.•´☆.¸¸.•´☆
2018-01-01 00:00:00 +01:00
Thomas Faber 75850abcbb
[NTOS] Use KeClearEvent instead of KeResetEvent where the previous state is not needed. 2017-12-30 11:45:03 +01:00
Pierre Schweitzer 7fecde4a20
[NTOSKRNL] Print tags which contains numerics in the memory dumper.
This fixes i8042prt.sys allocations not properly being rendered.
2017-12-29 20:37:43 +01:00
Pierre Schweitzer 4663d02cd7
[NTOSKRNL] In the memory dumper, print in the direct order to make !poolused TAG usage easier 2017-12-29 20:37:43 +01:00
Pierre Schweitzer ca3143b9ab
[NTOSKRNL] Add support for verbose output in the !poolused command 2017-12-29 20:37:43 +01:00
Timo Kreuzer cbc4cfeed6 [NTOS:EX] Fix handle table code for x64.
Based on patch by Ivan Labutin. See PR #115
2017-12-29 19:44:09 +01:00
Pierre Schweitzer 2daf2391a6
[NTOSKNRL] Addendum to 9a633f7 2017-12-29 18:22:37 +01:00
Pierre Schweitzer 9a633f7b48
[NTOSKRNL] Fix MSVC build 2017-12-29 18:03:33 +01:00
Pierre Schweitzer 4e34bf2a0b
[NTOSKRNL] Add support for the ? wildcard in the !poolused command 2017-12-29 17:23:36 +01:00
Pierre Schweitzer 454e8738f2
[NTOSKRNL] Allow filtering !poolused output using a tag 2017-12-29 17:23:36 +01:00
Pierre Schweitzer 879d8f2104
[NTOSKRNL] Now that the memory dumper handles paged pool, make use of it in any situation 2017-12-29 17:23:36 +01:00
Pierre Schweitzer 1433ade827
[NTOSKRNL] Add support for the paged pool in the memory dumper 2017-12-29 17:23:36 +01:00
Pierre Schweitzer bb63841b57
[NTOSKRNL] Prettify the memory dumper output and add number of allocs 2017-12-29 17:23:36 +01:00
Pierre Schweitzer 78b55550bb
[NTOSKRNL] Make the memory dumper available as a kdbg command: !poolused 2017-12-29 17:23:36 +01:00
Amine Khaldi 007131b5de [NTOS] Fix Shim AVL prototypes to exactly match the types expected by RtlInitializeGenericTableAvl. #179 2017-12-25 22:34:57 +01:00
Amine Khaldi 4d4e4bb68a [NTOS] Deduplicate MiSynchronizeSystemPde(). #179 2017-12-25 20:14:46 +01:00
Pierre Schweitzer fc5a61d8b7
[NTOSKRNL] Revert 4ef0887: experiments show that our FastFAT is not ready yet to live on its own.
So, bring back the infamous IopParseDevice() hack. Dismounting is to be fixed in FastFAT.
Even though it might not be the last remaining bug...

CORE-14124
CORE-14126
CORE-14133
2017-12-25 11:24:13 +01:00
Hermès Bélusca-Maïto ff8d8a8162
Revert 57c0678 (PR #194) that has been erroneously committed too early. 2017-12-24 16:54:48 +01:00
Stanislav Motylkov 57c0678818
[NTOS:INBV] Implement rotation bar for boot screen 2017-12-24 16:47:02 +01:00
Samuel Serapion a59d4674de [NTOS] Remove forgotten assert, see CORE-14128. 2017-12-20 21:00:52 +01:00
Timo Kreuzer 12e2c48a25 [NTOS:MM] Fix a bug in MiBuildPfnDatabase
MxPfnAllocation is in pages, not in bytes!
2017-12-20 06:56:09 +01:00
Timo Kreuzer 18cd763160 [NTOS:MM] Make debug code in MmArmInitSystem portable 2017-12-20 06:56:09 +01:00
Timo Kreuzer 11c78f701d [NTOS:MM] Implement x64 version of MI_MAKE_SUBSECTION_PTE 2017-12-20 06:56:09 +01:00
Ivan Labutin 8723be733c [NTOS:PS] Skip backtrace on non-x86 2017-12-20 06:56:09 +01:00
Ivan Labutin 0d01b00871 [NTOS:FSRTL] Fixed incorrect comparison 2017-12-20 06:56:09 +01:00
Ivan Labutin d6792047f3 [NTOS][NDK][RTL] A bunch of 'wrong size' fixes 2017-12-20 06:56:09 +01:00