Commit graph

42582 commits

Author SHA1 Message Date
Sir Richard 01194e41b9 [NTOS]: Silence more debug spew.
svn path=/trunk/; revision=47607
2010-06-06 04:37:53 +00:00
Sir Richard 143221853b [NTOS]: Fix for the the bug that broke ARM3 paged pool (and has been corrupting ReactOS paged pool behind the scenes for years):
When a KCB (key stuff) is allocated, the key name associated with it receives an NCB (name stuff). In case this name is already used, a cache exists, and an existing NCB is grabbed, and its reference count is increased. When the KCB goes away, its NCB loses a reference. When all references are gone, the NCB is destroyed. Simple enough.
        It turns out that what was currently happening is that an NCB would get dereferenced to 0, deleted, but still remained attached to a valid KCB (shouldn't happen). When that KCB went away, the NCB's reference count was dropped to... -1, and then -2, -3, -4, etc. Remember this is a FREED NCB. In other words, freed pool, that might now belong to someone else, was getting "-1" operations on it. So any value stored in that freed pool would get decremented by one. In ARM3 paged pool, because the allocator keeps a linked list, what would happen is that the FLINK pointer would be 0xE0F01234 instead of 0xE1A01234. What happened is that "0xE1A0" was treated as the reference count of the freed NCB, and it kept getting dereferenced down to 0xE0F0.
        Proving this was easy, by adding an ASSERT(Ncb->RefCount >= 1) to the routine that dereferences NCBs. Obviously, we should not try to dereference an NCB that has a reference count of 0, because that NCB is now gone. Adding this ASSERT immediately caught the error, regardless of which pool implementation was being used, so this was a problem in ReactOS today, right now.
        My first thought was that we were taking references to NCBs without incrementing the reference count. The NCB gets referenced in two places: when it gets created, and everytime a cached NCB is re-used for a new KCB (all this in CmpGetNameControlBlock).
	After adding some tracing code, I discovered that CmpGetNameControlBlock would sometimes return an NCB that was cached, but without referencing it. I did not understand why, since the code says "if (Found) Ncb->RefCount++".
        Further analysis showed that what would happen, on this particular instance, is that NCB "Foo" was being Found, but NCB "Bar" was returned instead. Therefore, causing some serious issues: First, NCB Foo was receiving too many references. Secondly, NCB Bar was not being referenced.
        Worse though, it turns out this would happen when "Foo" was the CORRECT NCB, and "Bar" was an INCORRECT NCB. What do we mean by correct and incorrect? Well, because NCBs are hashed, it's possible for two NCB hashes to be VERY SIMILAR, but only ONE OF THOSE NCBs will be the right one -- for example, HKLM\Software\Hello vs HKLM\Software\Hell.
        In our case, when a KCB for "Hello" was searching for the "Hello" NCB, the "Hello NCB would get a reference, but the "Hell" NCB would be returned. In other words, whenever a HASH COLLISION happened, the incorrect NCB was returned, probably messing up registry code in the process. Subsequently, when the KCB was dereferneced, it was attached to this incorrect, under-referenced NCB.
        Since in ANY hash collision with "Hell", in our example, the "Hell" NCB would come first, subsequent searches for "Hellmaster", "Hellboy", "Hello World" would all still return "Hell". Eventually when all these KCBs would go away, the "Hell" NCB would reach even -18 references.
        The simple solution? When the CORRECT NCB is found, STOP SEARCHING! By adding a simple "break" statement. Otherwise, even after the correct NCB is found, further, incorrect, collided NCBs are found, and eventually the last one ("Hell", in our example) got returned, and under-referenced, while "Hellmaster" and "Hellboy" were not returned, but LEAKED REFERENCES.
        There you have it folks, MEMORY CORRUPTION (USE-AFTER-FREE), INCORRECT REGISTRY NAME PARSHING, REFERENCE LEAKS and REFERENCE UNDERRUNS, all due to ONE missing "break;".
        -r

svn path=/trunk/; revision=47605
2010-06-06 01:04:03 +00:00
Sir Richard 570567b87e [NTOS]: Kill some debug spew.
svn path=/trunk/; revision=47604
2010-06-06 00:49:26 +00:00
Sir Richard c28fc63bf4 [NTOS]: Even after allowing ARM3 paged pool, we should still use the old allocator to free allocations made by the old allocator!
svn path=/trunk/; revision=47601
2010-06-05 19:32:46 +00:00
Sir Richard 5f1255ce5b [NTOS]: Fix up POOL_PREV_BLOCK based on suggestion by hpoussin.
[NTOS]: Fix up NTAPI location in function definition.
[NTOS]: Implement even more stringent header checks: ExpCheckPoolHeader and ExpCheckPoolBlocks. Normally we would only want this on a DBG build, but I am enabling them for now until I can fix paged pool. If your machine crashes, reverting this commit is NOT the solution (boots for me).
[NTOS]: Add a AllowPagedPool BOOLEAN that will allow us to selectively enable when the ARM3 pool can be used, playing around with the situation that causes the corruption, and perhaps making it easier to find/fix.

svn path=/trunk/; revision=47600
2010-06-05 19:19:28 +00:00
Sir Richard ed9f4ad2de [NTOS]: Kill debug spew.
svn path=/trunk/; revision=47599
2010-06-05 19:17:21 +00:00
Sir Richard 5d77839f4f [NTOS]: Fix Exp*PoolList macros. Also make then non-inlined, so we can see who called them in a stack trace.
[NTOS]: Enable them.
This boots on my system -- if it doesn't boot on yours, someone is corrupting your nonpaged pool. Reverting this patch is NOT the solution to your woes.

svn path=/trunk/; revision=47598
2010-06-05 18:26:15 +00:00
Jeffrey Morlan ffce25e515 [WIN32CSR]
- Implement basic support for history in line editing
- Reorganize code to reflect that line input is more coupled to history than it is to character input

svn path=/trunk/; revision=47597
2010-06-05 18:17:42 +00:00
Sir Richard 745031cf0b [NTOS]: Add some paranoid-invariant list access checks to the pool code. They serve a dual purpose: catch pool corruption by broken drivers/kernel code, as well as catch malicious modification of the pool links as part of a kernel-mode exploit.
[NTOS]: Not yet used, thanks to Arthur for the idea.
See comment for more information.

svn path=/trunk/; revision=47596
2010-06-05 18:02:45 +00:00
Sir Richard 81589f83ca [NTOS]: Defensive programming on the pool macros.
svn path=/trunk/; revision=47595
2010-06-05 17:54:19 +00:00
Sir Richard fc1ffb8a44 [NTOS]: Use logical math operations on the various block<->entry<->free_list_head operations in the pool code, instead of works-by-chance-and-assumption pointer math operations. This will now allow pool implementations where the pool header is not the size of a pool block (and the size of a LIST_ENTRY, by definition, although, even that, could change, if we choose to implement a cache-aligned overhead).
svn path=/trunk/; revision=47594
2010-06-05 17:53:17 +00:00
Cameron Gutman e8b356d800 [NTOSKRNL]
- Print the base address of the process that we killed to make debugging much easier

svn path=/trunk/; revision=47593
2010-06-05 17:51:12 +00:00
Sir Richard cb9c4019bb [NTOS]: Define the POOL_HEADER for x64.
[NTOS]: Define POOL_BLOCK_SIZE definition to set the minimum pool block size. In NT, this is equal to a LIST_ENTRY structure, because the Pool Allocator must be able to store a LIST_ENTRY into a freed pool block. This also determines the alignment of pool allocations. So 8 on x86, 16 on x64.
[NTOS]: Don't depend on LIST_ENTRY, but use POOL_BLOCK_SIZE instead (on IA64, if we ever want to support this, the pool block size is different from a LIST_ENTRY/POOL_HEADER).
[NTOS]: The following ASSERTs must hold: the POOL_HEADER must be as big as the the smallest pool block (POOL_BLOCK_SIZE), which must be at least as big as a LIST_ENTRY structure. 8 == 8 == 8 on x86, 16 == 16 == 16 on x64.

svn path=/trunk/; revision=47592
2010-06-05 16:53:54 +00:00
Sir Richard 6aad48190c [NTOS]: Don't assume that ANY fault in the system address range, not associated to a memory area, might be ARM3. Instead, since this hack only exists for early boot page pool support, make only treat this as an ARM3 fault when it happens in the paged pool area or higher. Leads to more direct Mm crashes when invalid page access happens, instead of infinite "PAGE FAULT ON PAGE TABLES".
svn path=/trunk/; revision=47589
2010-06-05 14:59:50 +00:00
Sir Richard 549eedeeb4 [NTOS]: In MiInitializePfnForOtherProcess, should increment the sharecount of the page table PFN entry, not the PFN entry of the PTE itself. Spotted by Stefan100.
svn path=/trunk/; revision=47588
2010-06-05 14:55:17 +00:00
Sir Richard a2a190f44b [NTOS]: In MiDeleteSystemPageableVm, should also handle the case where the PTE is demand-zero. This can happen if the caller allocated, say, 12KB (3 pages) of paged pool, only touched 4KB (1 page), and then frees the allocation -- the other 2 pages will still be demand-zero at this point.
svn path=/trunk/; revision=47587
2010-06-05 14:54:26 +00:00
Eric Kohl 89c8d4178c [NTOSKRNL]
NtDuplicateToken: Fail, if a primary token is to be created from an impersonation token and and the impersonation level of the impersonation token is below SecurityImpersonation.

svn path=/trunk/; revision=47586
2010-06-05 12:20:53 +00:00
Jeffrey Morlan 7da6d0a6e2 [WIN32CSR] Implement some basic line editing capability
svn path=/trunk/; revision=47584
2010-06-05 06:10:53 +00:00
Sir Richard f4f8ee78d1 [NTOS]: Implement MiDeleteSystemPageableVm.
[NTOS]: The paged pool free code was behaving incorrectly, assuming that paged pool was "locked down" and never paged out/reused (a valid NT operation mode), while the allocation code was assuming paged pool was a volatile, reusable, pageable resource (normal NT operation mode). The free code now assumes normal operation mode, and actually frees the freed paged pool pages, by using MiDeleteSystemPageableVm.
I have a feeling this will make ARM3 paged pool work.

svn path=/trunk/; revision=47582
2010-06-05 04:16:46 +00:00
Jeffrey Morlan 9ef0181983 add missing file
svn path=/trunk/; revision=47581
2010-06-05 03:12:51 +00:00
Jeffrey Morlan ffcb1445f7 [KERNEL32], [WIN32CSR]
- Implement console history (note: not too useful yet without any way to recall it)
- Implement APIs GetConsoleCommandHistoryLength, GetConsoleCommandHistory, ExpungeConsoleCommandHistory, SetConsoleNumberOfCommands, GetConsoleHistoryInfo, SetConsoleHistoryInfo.
- Remove stub of obsolete function SetConsoleCommandHistoryMode, which no longer exists in Windows.

svn path=/trunk/; revision=47580
2010-06-05 00:45:08 +00:00
Sir Richard 25bf23bfc1 [NTOS]: When expanding paged pool, use MiRemoveAnyPage, not MmAllocPage.
[NTOS]: When expanding paged pool, initialize the PFN entry for the allocated page. Note we might be in arbitrary process space, so the PTE is not necessary valid for the process causing the expansion.
[NTOS]: Implement MiInitializePfnForOtherProcess to handle the case above.
[NTOS]: Change two static ASSERTs into C_ASSERTs. Might break non-x86 builds for a bit (vs breaking them at boot, which is worse).
Paged pool should start working soon.

svn path=/trunk/; revision=47579
2010-06-04 22:08:40 +00:00
Timo Kreuzer c25fc39e6f [winnt.h]
Fix definition of KNONVOLATILE_CONTEXT_POINTERS for amd64

svn path=/trunk/; revision=47578
2010-06-04 21:50:06 +00:00
Cameron Gutman 682cf08ee8 [FREELOADER]
- Use the old method for identifying the drive type (based on partition number) which actually works for floppies now because I changed the DrivePartition value returned (floppy = 0, cdrom = 0xFF) in a previous commit
- Fixes bug 5233

svn path=/trunk/; revision=47577
2010-06-04 20:36:48 +00:00
Cameron Gutman fc022a8506 [FREELOADER]
- Remove duplicated code
- Add back the Mac hack but use 0x8A for the lowest CD-ROM drive number instead of 0x90

svn path=/trunk/; revision=47576
2010-06-04 20:22:29 +00:00
Sir Richard 63ce635b0f [NTOS]: Build paged pool demand-zero PTE with MI_MAKE_SOFTWARE_PTE macro.
[NTOS]: Handle paged pool demand-zero fault fulfillment with MI_MAKE_HARDWARE_PTE macro.
[NTOS]: Use MiRemoveAnyPage instead of MmAllocPage, in paged pool demand-zero fault fulfillment.
These changes affect code paths that are not currently in-use.

svn path=/trunk/; revision=47575
2010-06-04 20:18:27 +00:00
Timo Kreuzer f150c299f2 [DDK]
Fix definition of USE_DMA_MACROS

svn path=/trunk/; revision=47574
2010-06-04 20:16:26 +00:00
Timo Kreuzer ffc6aac247 [MMEBUDDY]
Make mmebuddy more 64bit compliant. Based on r40127 by Samuel Serapion with some modifications by me.

svn path=/trunk/; revision=47573
2010-06-04 18:37:14 +00:00
Jeffrey Morlan 6659ae1d98 [WIN32CSR] Console input simplification:
- Put code for processing events for line input in one place, instead of duplicating it everywhere
- Remove "Fake" and "NotChar" fields from ConsoleInput struct. ConioProcessKey didn't actually add Fake events; they were used for the \n when converting \r to \r\n, but this is better done by the line input code.
- Build an input line completely on the server side; this will make it practical to add history and more sophisticated editing later

svn path=/trunk/; revision=47572
2010-06-04 18:26:22 +00:00
Sir Richard d3c4ade827 Testers: Please test this build.
[NTOS]: Implement a MI_MAKE_HARDWARE_PTE macro for the generation of valid kernel PTEs instead of always taking the ValidKernelPte and changing its flags. This macro will take into account the protection mask (up until now ignored) and use the array previously implemented to determine the correct hardware PTE settings. Assertions are also added to validate correct usage of the macro, and later revisions will fill out NT-specific fields to help deal with transition PTEs, page faults, etc.
[NTOS]: Make the stack code the first user of this macro, for the stack PTEs. Good testing base as we create kernel stacks very often.
[NTOS]: The NT MM ABI specifies that in between the allocation of a new PTE and its initialization as a valid PFN, the PTE entry should be an invalid PTE, and should only be marked valid after the PFN has been initialized. For stack PTEs, do this -- first allocating the page, making it invalid, then initializing the PFN, and then writing the valid page.

svn path=/trunk/; revision=47571
2010-06-04 17:49:36 +00:00
Sir Richard 1c28c16dfe [NTOS]: Allocate non-paged pool pages with MiRemoveAnyPage instead of MmAllocPage.
svn path=/trunk/; revision=47570
2010-06-04 17:40:11 +00:00
Timo Kreuzer 86ed4d64b5 [HAL]
Delete empty folder

svn path=/trunk/; revision=47569
2010-06-04 16:56:14 +00:00
Jeffrey Morlan 05740b5556 [WIN32CSR] Consistently store console input events internally as unicode.
svn path=/trunk/; revision=47568
2010-06-04 16:31:56 +00:00
Timo Kreuzer 3c5af5bea1 [KS]
- KSSTREAM_POINTER_OFFSET doesn't have an Alignment member on 64 bit systems. Comment the use out in these cases. It should probably be removed completely, as it's only an alignment / dummy value, but I leave this to the expert in this field.
- ULONG -> ULONG_PTR for pointer casts

svn path=/trunk/; revision=47567
2010-06-04 15:58:43 +00:00
Giannis Adamopoulos eca252dba7 [win32k]
- CreateWindow: initialize window position after sending WM_GETMINMAXINFO message

svn path=/trunk/; revision=47566
2010-06-04 11:30:14 +00:00
Timo Kreuzer 2b0533a1b0 [HAL]
- Move all amd64 specific files to one amd64 folder
- Compile x86 specific timer code only on x86
- Use KeRegisterInterruptHandler instead of manual idt manipulation
- add missing stubs for amd64

svn path=/trunk/; revision=47565
2010-06-04 10:59:19 +00:00
Timo Kreuzer a95f10c476 [NTOSKRNL]
Implement KeRegisterInterruptHandler and KeQueryInterruptHandler for amd64

svn path=/trunk/; revision=47564
2010-06-04 10:51:44 +00:00
Timo Kreuzer 32f5fc6eab [HAL]
- Move memory functions from halinit.c to new memory.c
- HalpAllocPhysicalMemory: MemoryFirmwareTemporary -> LoaderFirmwareTemporary (same value, different enum)

svn path=/trunk/; revision=47563
2010-06-04 10:17:55 +00:00
Jeffrey Morlan 0d06145871 [KERNEL32], [WIN32CSR]
- Make Get/SetConsoleTitle more compatible with windows; in particular, transfer title via capture buffer to allow for longer titles.
- Tighten up capture buffer validation in win32csr.

svn path=/trunk/; revision=47562
2010-06-04 06:36:12 +00:00
Timo Kreuzer 591e5017e9 revert 47559 and 47560 (once again... sigh)
svn path=/trunk/; revision=47561
2010-06-04 00:49:33 +00:00
Timo Kreuzer 38717f6840 try to fix build
svn path=/trunk/; revision=47560
2010-06-04 00:26:49 +00:00
Timo Kreuzer babe335c71 [DDK]
Merge the rest of the old header-branch version of ntddk.h, but with a large number of additional types #if 0'ed out

svn path=/trunk/; revision=47559
2010-06-04 00:19:39 +00:00
Timo Kreuzer a9cf165e5f [DDK]
try to work around the testbot brokenness with an #if 0"

svn path=/trunk/; revision=47558
2010-06-03 23:40:33 +00:00
Timo Kreuzer a8d609e19d [HAL]
Include the correct headers for amd64 vs i386

svn path=/trunk/; revision=47557
2010-06-03 23:18:20 +00:00
Timo Kreuzer 9bbc1250d2 [DDK]
In an incredibly daring move, add even more types to ntddk.h

svn path=/trunk/; revision=47556
2010-06-03 23:08:40 +00:00
Timo Kreuzer 3cbb0a3c40 [DDK]
2nd try, this time adding half of the structures.

svn path=/trunk/; revision=47555
2010-06-03 22:25:25 +00:00
Timo Kreuzer da7f98efe8 Revert r47553 because testbot doesn't like it
svn path=/trunk/; revision=47554
2010-06-03 22:15:54 +00:00
Timo Kreuzer c3179d84ef [DDK}
Add a number of PCI related types to ntddk.h

svn path=/trunk/; revision=47553
2010-06-03 21:55:57 +00:00
Timo Kreuzer 9d059198bb [ReactOS-amd64.rbuild]
The old explorer won't compile for amd64 without massive hacking, so remove it from the build.

svn path=/trunk/; revision=47552
2010-06-03 20:57:25 +00:00
Timo Kreuzer 5cede710e0 [ROSTESTS]
Fix 64 bit build of some modules (Samuel Serapion, modified by me)

svn path=/trunk/; revision=47551
2010-06-03 20:08:26 +00:00