Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] The ultimate ros amd64 bringup #361

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
91c8699
[NTOS:IO] Fix parsing of resource lists
tkreuzer Jan 28, 2018
ff1eaad
[NTOS:MM] Make sure to call MmInitializeProcessAddressSpace() from th…
tkreuzer Jan 29, 2018
15a08e8
[NTOS:MM] In the x64 version of MmCreateProcessAddressSpace() zero ou…
tkreuzer Jan 29, 2018
cce3d16
[NTOS:MM] Fix ViewSize parameter passed to MiInsertVadEx() from MiCre…
tkreuzer Jan 29, 2018
286b2fb
[NTOS:MM] On x64 reserve the address range between FFFF800000000000 a…
tkreuzer Jan 29, 2018
12002d4
[HAL] Fix some 64 bit warnings
tkreuzer Jan 29, 2018
546c05b
[NTOS:OB] Fix some 64 bit warnings
tkreuzer Jan 29, 2018
1bc15af
[CRT] Use chkstk_ms.s on x64 builds
tkreuzer Jan 29, 2018
1f6d61b
[CRT] Remove the x64 asm version of sqrt from build
tkreuzer Jan 29, 2018
9e097de
[NTOS:IO] Fix a warning on MSVC builds
tkreuzer Jan 29, 2018
aedb9f6
[NTOS:MM] SLIST handling for kernel stacks
tkreuzer Feb 4, 2018
d139743
[NTOS:MM] Handle PPEs und PXEs as well in MmInitializeProcessAddressS…
tkreuzer Feb 4, 2018
25064d0
[NTOS:MM] Simplify and fix x64 version of MiGetPteForProcess(), fix M…
tkreuzer Feb 4, 2018
75e11df
[NTOS:MM] Fix session space initialization on x64
tkreuzer Feb 4, 2018
13ef07a
[NTOS:MM] Fix paged pool initialization on x64
tkreuzer Feb 4, 2018
03920b1
[NTOS:MM] Fix paged pool expansion
tkreuzer Feb 4, 2018
235566d
[NTOS:SE] Fix SeSetSecurityDescriptorInfoEx to avoid pool corruption …
tkreuzer Feb 4, 2018
1e326fb
[CMAKE] Add baseaddress_msvc_x64.cmake
tkreuzer Feb 4, 2018
c4fbc15
[CSRSRV] Fix type of ViewSize parameter passed to NtMapViewOfSection
tkreuzer Feb 4, 2018
29db059
[NTOS:KE] Implement KiConvertToGuiThread, KeSwitchKernelStack and sup…
tkreuzer Feb 4, 2018
c24203c
[NTOS:KE] Save and restore previous mode in KiZwSystemService and fix…
tkreuzer Feb 5, 2018
c9d1f6a
[NTOS:KE] Implement KiGetUserModeStackAddress() and KeUserModeCallback()
tkreuzer Feb 5, 2018
e503f53
[HAL][NTOS][I8042PRT] Add some hacks related to resource conflicts
tkreuzer Feb 5, 2018
9335f8f
[NTOS:MM] HACK: comment out an ASSERT that still fails on x64
tkreuzer Feb 5, 2018
4b4a334
[REACTOS] Fix many 64 bit warnings
tkreuzer Feb 6, 2018
945d807
[ENVIRON] Fix x64 build
tkreuzer Feb 6, 2018
a26ae1d
[BOOTLIB] Fix 64 bit warnings
tkreuzer Feb 6, 2018
bd078ab
[NTOS:KE] Improve kernel stack switching on GUI system calls
tkreuzer Feb 6, 2018
7749bdc
Fix indentation
tkreuzer Feb 6, 2018
177b3e7
Addendum to session space stuff
tkreuzer Feb 7, 2018
52721c2
Remove a trailing white space
tkreuzer Feb 7, 2018
fbec870
[NDK] Update x64 version of KEXCEPTION_FRAME
tkreuzer Feb 9, 2018
d5bdd7e
[NTOS:KE] Change the logic of KeSwitchKernelStack and friends to be s…
tkreuzer Feb 9, 2018
4351118
[ASM] Add initial version of kxamd64.inc
tkreuzer Feb 9, 2018
5b1588c
[NDK] Add UCALLOUT_FRAME definition
tkreuzer Feb 10, 2018
1dc22b6
[NTOS:KE] Move KiInitializeUserApc to usercall.c
tkreuzer Feb 10, 2018
8366b2c
[NTOS:KE] Simplify KiInitializeUserApc
tkreuzer Feb 10, 2018
29d20df
[NTOS:KE] Implement x64 version of user callback code
tkreuzer Feb 10, 2018
10e086b
[NDK] Fix the type of KPROCESS::ActiveProcessors
tkreuzer Feb 10, 2018
3252ac3
Silence annoying UNIMPLEMENTED messages
tkreuzer Feb 10, 2018
66eb02c
[NTOS:MM] Remove obsolete x64 debug print
tkreuzer Feb 10, 2018
c93d924
[NTOS:PS] Fix an issue with PROCESS_DEVICEMAP_INFORMATION size on 64…
tkreuzer Feb 10, 2018
c3380ef
[NTDLL] Delete obsolete file amd64/stubs.c
tkreuzer Feb 11, 2018
c249c15
[NTOS:PS] On x64 don't fail in NtSetInformationProcess with ProcessUs…
tkreuzer Feb 11, 2018
8b48097
[WIN32K] Fix ULONG/SIZE_T issue
tkreuzer Feb 11, 2018
e7e7e40
[NTOS:KE] Silence KiRundownThread, it has nothing to do
tkreuzer Feb 11, 2018
a9fc91d
[VIDEOPRT] Don't try to use NtVdmControl on x64
tkreuzer Feb 11, 2018
6e0a3be
[VIDEOPRT] [FORMATTING] No code change
tkreuzer Feb 11, 2018
f062e2d
[VIDEOPRT] Call IntInt10CallBios from VideoPortInt10, instead of code…
tkreuzer Feb 11, 2018
21177bb
[VIDEOPRT] Fixes for x64
tkreuzer Feb 11, 2018
ebe9bc4
[NDK] Add BIOS call API for amd64
tkreuzer Feb 11, 2018
c8bd63f
[FAST486] DWORD -> ULONG, so it can be used in kernel mode
tkreuzer Feb 11, 2018
4c80d83
[HAL] Implement amd64 BIOS call support
tkreuzer Feb 11, 2018
96f3020
[VIDEOPRT] Implement support for INT10 on x64 using the newly impleme…
tkreuzer Feb 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions ntoskrnl/include/internal/amd64/mm.h
Expand Up @@ -20,8 +20,8 @@
#define MI_PAGED_POOL_START (PVOID)0xFFFFF8A000000000ULL // 128 GB paged pool [MiVaPagedPool]
//#define MI_PAGED_POOL_END 0xFFFFF8BFFFFFFFFFULL
//#define MI_SESSION_SPACE_START 0xFFFFF90000000000ULL // 512 GB session space [MiVaSessionSpace]
#define MI_SESSION_VIEW_END 0xFFFFF97FFF000000ULL
#define MI_SESSION_SPACE_END 0xFFFFF97FFFFFFFFFULL
//#define MI_SESSION_VIEW_END 0xFFFFF97FFF000000ULL
#define MI_SESSION_SPACE_END 0xFFFFF98000000000ULL
#define MI_SYSTEM_CACHE_START 0xFFFFF98000000000ULL // 1 TB system cache (on Vista+ this is dynamic VA space) [MiVaSystemCache,MiVaSpecialPoolPaged,MiVaSpecialPoolNonPaged]
#define MI_SYSTEM_CACHE_END 0xFFFFFA7FFFFFFFFFULL
#define MI_PFN_DATABASE 0xFFFFFA8000000000ULL // up to 5.5 TB PFN database followed by non paged pool [MiVaPfnDatabase/MiVaNonPagedPool]
Expand Down Expand Up @@ -54,11 +54,11 @@
#define MI_MIN_INIT_PAGED_POOLSIZE (32 * _1MB)
#define MI_MAX_INIT_NONPAGED_POOL_SIZE (128ULL * 1024 * 1024 * 1024)
#define MI_MAX_NONPAGED_POOL_SIZE (128ULL * 1024 * 1024 * 1024)
#define MI_SYSTEM_VIEW_SIZE (16 * _1MB)
#define MI_SESSION_VIEW_SIZE (20 * _1MB)
#define MI_SESSION_POOL_SIZE (16 * _1MB)
#define MI_SESSION_IMAGE_SIZE (8 * _1MB)
#define MI_SESSION_WORKING_SET_SIZE (4 * _1MB)
#define MI_SYSTEM_VIEW_SIZE (104 * _1MB)
#define MI_SESSION_VIEW_SIZE (104 * _1MB)
#define MI_SESSION_POOL_SIZE (64 * _1MB)
#define MI_SESSION_IMAGE_SIZE (16 * _1MB)
#define MI_SESSION_WORKING_SET_SIZE (16 * _1MB)
#define MI_SESSION_SIZE (MI_SESSION_VIEW_SIZE + \
MI_SESSION_POOL_SIZE + \
MI_SESSION_IMAGE_SIZE + \
Expand Down Expand Up @@ -258,8 +258,6 @@ MI_MAKE_SUBSECTION_PTE(
_Out_ PMMPTE NewPte,
_In_ PVOID Segment)
{
ULONG_PTR Offset;

/* Mark this as a prototype */
NewPte->u.Long = 0;
NewPte->u.Subsect.Prototype = 1;
Expand All @@ -286,9 +284,10 @@ FORCEINLINE
BOOLEAN
MI_IS_MAPPED_PTE(PMMPTE PointerPte)
{
/// FIXME
__debugbreak();
return ((PointerPte->u.Long & 0xFFFFFC01) != 0);
return ((PointerPte->u.Hard.Valid != 0) ||
(PointerPte->u.Proto.Prototype != 0) ||
(PointerPte->u.Trans.Transition != 0) ||
(PointerPte->u.Hard.PageFrameNumber != 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh. An old WC of mine says:

    return PointerPte->u.Soft.Valid ||
           PointerPte->u.Soft.Prototype ||
           PointerPte->u.Soft.Transition ||
           PointerPte->u.Soft.UsedPageTableEntries ||
           PointerPte->u.Soft.Reserved ||
           PointerPte->u.Soft.PageFileHigh ||
           PointerPte->u.Transition.PageFrameNumber;

Same thing I suppose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should technically be the same. If there is a reason for your variant, I can change it.

}

VOID
Expand Down
15 changes: 13 additions & 2 deletions ntoskrnl/mm/ARM3/session.c
Expand Up @@ -603,10 +603,14 @@ NTAPI
MiSessionCreateInternal(OUT PULONG SessionId)
{
PEPROCESS Process = PsGetCurrentProcess();
ULONG NewFlags, Flags, Size, i, Color;
ULONG NewFlags, Flags, i, Color;
#if (_MI_PAGING_LEVELS < 3)
ULONG Size;
PMMPDE PageTables;
#endif // (_MI_PAGING_LEVELS < 3)
KIRQL OldIrql;
PMMPTE PointerPte, SessionPte;
PMMPDE PointerPde, PageTables;
PMMPDE PointerPde;
PMM_SESSION_SPACE SessionGlobal;
MMPTE TempPte;
MMPDE TempPde;
Expand Down Expand Up @@ -644,6 +648,7 @@ MiSessionCreateInternal(OUT PULONG SessionId)
/* Now we should own the flag */
ASSERT(Process->Flags & PSF_SESSION_CREATION_UNDERWAY_BIT);

#if (_MI_PAGING_LEVELS < 3)
/*
* Session space covers everything from 0xA0000000 to 0xC0000000.
* Allocate enough page tables to describe the entire region
Expand All @@ -652,6 +657,7 @@ MiSessionCreateInternal(OUT PULONG SessionId)
PageTables = ExAllocatePoolWithTag(NonPagedPool, Size, 'tHmM');
ASSERT(PageTables != NULL);
RtlZeroMemory(PageTables, Size);
#endif // (_MI_PAGING_LEVELS < 3)

/* Lock the session ID creation mutex */
KeAcquireGuardedMutex(&MiSessionIdMutex);
Expand All @@ -662,7 +668,9 @@ MiSessionCreateInternal(OUT PULONG SessionId)
{
/* We ran out of session IDs, we should expand */
DPRINT1("Too many sessions created. Expansion not yet supported\n");
#if (_MI_PAGING_LEVELS < 3)
ExFreePoolWithTag(PageTables, 'tHmM');
#endif // (_MI_PAGING_LEVELS < 3)
return STATUS_NO_MEMORY;
}

Expand Down Expand Up @@ -786,8 +794,11 @@ MiSessionCreateInternal(OUT PULONG SessionId)
MmSessionSpace->PageTables[PointerPde - MiAddressToPde(MmSessionBase)] = *PointerPde;
#endif
InitializeListHead(&MmSessionSpace->ImageList);

#if (_MI_PAGING_LEVELS < 3)
DPRINT1("Session %lu is ready to go: 0x%p 0x%p, %lx 0x%p\n",
*SessionId, MmSessionSpace, SessionGlobal, SessionPageDirIndex, PageTables);
#endif // (_MI_PAGING_LEVELS < 3)

/* Initialize session pool */
//Status = MiInitializeSessionPool();
Expand Down
44 changes: 29 additions & 15 deletions ntoskrnl/mm/amd64/init.c
Expand Up @@ -15,13 +15,13 @@
#include <debug.h>

#include <mm/ARM3/miarm.h>
#include <fltkernel.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It contains a few nice macros like Add2Ptr, PtrOffset, ROUND_TO_SIZE, IS_ALIGNED, We should probably put those somewhere separate and include them from fltkernel.h and ntoskrnl.h, so we don't need the whole clusterfuck, but still have those macros available.


#ifdef _WINKD_
extern PMMPTE MmDebugPte;
#endif

/* Helper macros */
#define IS_ALIGNED(addr, align) (((ULONG64)(addr) & (align - 1)) == 0)
#define IS_PAGE_ALIGNED(addr) IS_ALIGNED(addr, PAGE_SIZE)

/* GLOBALS *****************************************************************/
Expand Down Expand Up @@ -64,41 +64,55 @@ NTAPI
INIT_FUNCTION
MiInitializeSessionSpaceLayout(VOID)
{
/* This is the entire size */
MmSessionSize = MI_SESSION_SIZE;
MmSessionViewSize = MI_SESSION_VIEW_SIZE;
MmSessionPoolSize = MI_SESSION_POOL_SIZE;
MmSessionImageSize = MI_SESSION_IMAGE_SIZE;
MmSystemViewSize = MI_SYSTEM_VIEW_SIZE;

/* Set up session space */
/* Start with session space end */
MiSessionSpaceEnd = (PVOID)MI_SESSION_SPACE_END;

/* This is where we will load Win32k.sys and the video driver */
/* The highest range is the session image range */
MmSessionImageSize = MI_SESSION_IMAGE_SIZE;
MiSessionImageEnd = MiSessionSpaceEnd;
MiSessionImageStart = (PCHAR)MiSessionImageEnd - MmSessionImageSize;
MiSessionImageStart = (PUCHAR)MiSessionImageEnd - MmSessionImageSize;
ASSERT(IS_PAGE_ALIGNED(MiSessionImageStart));

/* Session working set is below the session image range */
MiSessionSpaceWs = (PUCHAR)MiSessionImageStart - MI_SESSION_WORKING_SET_SIZE;

/* The view starts right below the session working set (itself below
* the image area) */
MiSessionViewEnd = (PVOID)MI_SESSION_VIEW_END;
MiSessionViewStart = (PCHAR)MiSessionViewEnd - MmSessionViewSize;
/* Session view is below the session working set */
MmSessionViewSize = MI_SESSION_VIEW_SIZE;
MiSessionViewEnd = (PUCHAR)MiSessionImageStart - MI_SESSION_WORKING_SET_SIZE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to self: use MiSessionSpaceWs here.

MiSessionViewStart = (PUCHAR)MiSessionViewEnd - MmSessionViewSize;
ASSERT(IS_PAGE_ALIGNED(MiSessionViewStart));

/* Session pool follows */
/* Session pool is below session view */
MmSessionPoolSize = MI_SESSION_POOL_SIZE;
MiSessionPoolEnd = MiSessionViewStart;
MiSessionPoolStart = (PCHAR)MiSessionPoolEnd - MmSessionPoolSize;
MiSessionPoolStart = (PUCHAR)MiSessionPoolEnd - MmSessionPoolSize;
ASSERT(IS_PAGE_ALIGNED(MiSessionPoolStart));

/* And it all begins here */
MmSessionBase = MiSessionPoolStart;

/* System view space ends at session space, so now that we know where
* this is, we can compute the base address of system view space itself. */
MiSystemViewStart = (PCHAR)MmSessionBase - MmSystemViewSize;
MmSystemViewSize = MI_SYSTEM_VIEW_SIZE;
MiSystemViewStart = (PUCHAR)MmSessionBase - MmSystemViewSize;
ASSERT(IS_PAGE_ALIGNED(MiSystemViewStart));

/* Sanity checks */
ASSERT(Add2Ptr(MmSessionBase, MmSessionSize) == MiSessionSpaceEnd);
ASSERT(MiSessionViewEnd <= MiSessionImageStart);
ASSERT(MmSessionBase <= MiSessionPoolStart);

/* Compute the PTE addresses for all the addresses we carved out */
MiSessionImagePteStart = MiAddressToPte(MiSessionImageStart);
MiSessionImagePteEnd = MiAddressToPte(MiSessionImageEnd);
MiSessionBasePte = MiAddressToPte(MmSessionBase);
MiSessionLastPte = MiAddressToPte(MiSessionSpaceEnd);

/* Initialize the pointer to the session space structure */
MmSessionSpace = (PMM_SESSION_SPACE)Add2Ptr(MiSessionImageStart, 0x10000);
}

VOID
Expand Down