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

X64 boot fixes #115

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions ntoskrnl/fsrtl/stackovf.c
Expand Up @@ -115,7 +115,7 @@ FsRtlWorkerThread(IN PVOID StartContext)
KIRQL Irql;
PLIST_ENTRY Entry;
PWORK_QUEUE_ITEM WorkItem;
ULONG QueueId = (ULONG)StartContext;
ULONG_PTR QueueId = (ULONG_PTR)StartContext;

/* Set our priority according to the queue we're dealing with */
KeSetPriorityThread(&PsGetCurrentThread()->Tcb, LOW_REALTIME_PRIORITY + QueueId);
Expand Down Expand Up @@ -149,7 +149,7 @@ NTAPI
INIT_FUNCTION
FsRtlInitializeWorkerThread(VOID)
{
ULONG i;
ULONG_PTR i;
NTSTATUS Status;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
Expand Down
4 changes: 2 additions & 2 deletions ntoskrnl/io/pnpmgr/pnpreport.c
Expand Up @@ -425,7 +425,7 @@ IoReportTargetDeviceChange(IN PDEVICE_OBJECT PhysicalDeviceObject,
/* Check for valid PDO */
if (!IopIsValidPhysicalDeviceObject(PhysicalDeviceObject))
{
KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG)PhysicalDeviceObject, 0, 0);
KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
}

/* FileObject must be null. PnP will fill in it */
Expand Down Expand Up @@ -476,7 +476,7 @@ IoReportTargetDeviceChangeAsynchronous(IN PDEVICE_OBJECT PhysicalDeviceObject,
/* Check for valid PDO */
if (!IopIsValidPhysicalDeviceObject(PhysicalDeviceObject))
{
KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG)PhysicalDeviceObject, 0, 0);
KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
}

/* FileObject must be null. PnP will fill in it */
Expand Down
8 changes: 4 additions & 4 deletions ntoskrnl/ps/debug.c
Expand Up @@ -60,18 +60,18 @@ PspDumpThreads(BOOLEAN IncludeSystem)
Thread->Tcb.State == Waiting)
{
ULONG i = 0;
PULONG Esp = (PULONG)Thread->Tcb.KernelStack;
PULONG Ebp = (PULONG)Esp[4];
PULONG_PTR Esp = (PULONG_PTR)Thread->Tcb.KernelStack;
PULONG_PTR Ebp = (PULONG_PTR)Esp[4];

/* Print EBP */
DbgPrint("Ebp %p\n", Ebp);

/* Walk it */
while(Ebp != 0 && Ebp >= (PULONG)Thread->Tcb.StackLimit)
while(Ebp != 0 && Ebp >= (PULONG_PTR)Thread->Tcb.StackLimit)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is x86 specific code. A proper fix would be using KeRosDumpStackFrames() or something similar. Alternatively use #ifdef _M_IX86 ... #else DbgPrint("FIXME: Backtrace skipped on non-x86\n") #endif

Copy link
Author

Choose a reason for hiding this comment

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

OK, made it conditional. Didn't know that these is x86-specific.

{
/* Print what's on the stack */
DbgPrint("%.8X %.8X%s", Ebp[0], Ebp[1], (i % 8) == 7 ? "\n" : " ");
Ebp = (PULONG)Ebp[0];
Ebp = (PULONG_PTR)Ebp[0];
i++;
}

Expand Down
4 changes: 2 additions & 2 deletions ntoskrnl/ps/process.c
Expand Up @@ -1416,8 +1416,8 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
"Parent: %p Attributes: %p\n", ParentProcess, ObjectAttributes);

/* Set new-style flags */
if ((ULONG)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
if ((ULONG)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT;
if ((ULONG_PTR)SectionHandle & 1) Flags |= PROCESS_CREATE_FLAGS_BREAKAWAY;
if ((ULONG_PTR)DebugPort & 1) Flags |= PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT;
if (InheritObjectTable) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;

/* Call the new API */
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/ndk/ldrfuncs.h
Expand Up @@ -109,7 +109,7 @@ NTAPI
LdrLockLoaderLock(
_In_ ULONG Flags,
_Out_opt_ PULONG Disposition,
_Out_opt_ PULONG Cookie
_Out_opt_ PULONG_PTR Cookie
);

NTSTATUS
Expand Down
5 changes: 4 additions & 1 deletion sdk/lib/rtl/memstream.c
Expand Up @@ -205,6 +205,7 @@ RtlReadOutOfProcessMemoryStream(
ULONG CopyLength;
PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
SIZE_T Available = (PUCHAR)Stream->End - (PUCHAR)Stream->Current;
SIZE_T nBytesRead = 0;

if (BytesRead)
*BytesRead = 0;
Expand All @@ -218,7 +219,9 @@ RtlReadOutOfProcessMemoryStream(
Stream->Current,
Buffer,
CopyLength,
BytesRead);
&nBytesRead);

*BytesRead = (ULONG)nBytesRead;

if (NT_SUCCESS(Status))
Stream->Current = (PUCHAR)Stream->Current + *BytesRead;
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/rtl/rtlp.h
Expand Up @@ -27,10 +27,10 @@ extern VOID FASTCALL CHECK_PAGED_CODE_RTL(char *file, int line);
#endif

#define ROUND_DOWN(n, align) \
(((ULONG)(n)) & ~((align) - 1l))
(((ULONG_PTR)(n)) & ~((align) - 1l))

#define ROUND_UP(n, align) \
ROUND_DOWN(((ULONG)(n)) + (align) - 1, (align))
ROUND_DOWN(((ULONG_PTR)(n)) + (align) - 1, (align))
Copy link
Contributor

Choose a reason for hiding this comment

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

This must be carefully synced with the other ALIGN_MEM_xxx macros etc everywhere else (FreeLdr and elsewhere).
I don't know whether @tkreuzer or @ThFabba have some particular comments about that?

Copy link
Author

Choose a reason for hiding this comment

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

Are there any ALIGN_MEM_...? Can't find them

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, these are called ALIGN_UP_... and ALIGN_DOWN_... :
https://git.reactos.org/?p=reactos.git&a=search&h=HEAD&st=grep&s=ALIGN_UP
https://git.reactos.org/?p=reactos.git&a=search&h=HEAD&st=grep&s=ALIGN_DOWN

Also I think some other ROUND_UP (not necessary in the kernel, but in other places in the code, but related to manipulating (what would be 64 bits) points) may need fixup:
https://git.reactos.org/?p=reactos.git&a=search&h=HEAD&st=grep&s=ROUND_UP
and check also for ROUND_DOWN ...


#define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))

Expand Down