Commit graph

102 commits

Author SHA1 Message Date
Thomas Faber e7de564bfc
[NTOS:MM] Implement big pool table expansion. CORE-15051 2019-01-09 08:18:38 +01:00
Pierre Schweitzer a3f8813fff
[NTOSKRNL] Add support for large allocations in !poolfind 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e1342127f0
[NTOSKRNL] In !irpfind, add info about current stack major/minor 2019-01-08 08:43:23 +01:00
Pierre Schweitzer e6a1851684
[NTOSKRNL] Misc fixes to !irpfind 2019-01-06 23:21:20 +01:00
Pierre Schweitzer 36f90e7e46
[NTOSKRNL] Move KDBG MM functions implementation to their own file 2019-01-06 22:50:57 +01:00
Pierre Schweitzer 28193399ee
[NTOSKRNL] Properly check for address validity in !poolfind 2019-01-06 12:58:14 +01:00
Pierre Schweitzer 47b48520b5
[NTOSKRNL] Reimplement !irpfind using !poolfind helpers
This allows avoiding one of the previous implementation limits:
leaked IRP not queued to a thread are now totally visible since
we look directly in the memory pool.
2019-01-06 12:49:57 +01:00
Pierre Schweitzer 12e579567c
[NTOSKRNL] Implement !poolfind command in KDBG
For now, it allows searching for pool allocations in
both paged and non paged pool.

It is based on Andreas Schuster work to identify POOL_HEADER
structures.
2019-01-06 11:56:38 +01:00
Timo Kreuzer 71fefa32db
[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally
* Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it
* Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC)
* Place INIT_FUNCTION before the return type (required by MSVC)
* Make sure declarations and implementations share the same modifiers (required by MSVC)
* Add a global linker option to suppress warnings about defined but unused INIT section
* Merge INIT section into .text in freeldr
2018-12-30 12:19:11 +01:00
Andrew Boyarshin 3ba51dc218 [NTOS:MM] Fix typo in MiCheckForUserStackOverflow 2018-12-12 12:57:08 +01:00
Pierre Schweitzer 4d974e56ee
[NTOSKRNL] Return the amount of hits in system lookaside lists in ExQueryPoolUsage() 2018-12-09 18:25:11 +01:00
Bernhard Feichtinger 8a0495063b [NTOS:MM] Handle unimplemeted case for MiCheckForUserStackOverflow 2018-11-25 11:29:18 +01:00
Jérôme Gardou df25e4e791 [NTOS/MM] Properly handle page faults in regions marked with
PAGE_NOACCESS or PAGE_GUARD

ROSTESTS-110
2018-11-03 12:50:16 +01:00
Jérôme Gardou 47ac7a2b28 [NTOS/MM] Move up MmAlterViewAttributes for later use in MmNotPresentFaultSectionView
No code change
2018-11-03 12:50:16 +01:00
Pierre Schweitzer fd8893e58f
[NTOSKRNL] Respect PFN cache attribute when required
This fixes noisy DPRINT1 being printed while reading
or writing files with NFS.
2018-10-01 20:59:37 +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
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
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
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
Mark Jansen c7eb46d9fd [NTOSKRNL] Ignore IMAGE_SCN_CNT_UNINITIALIZED_DATA
CORE-12582
CORE-14556
2018-06-03 20:40:51 +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