Page 1 of 1

MSVC - KernelStart and KernelEnd Location

Posted: Fri Apr 08, 2022 6:33 am
by LipkeGu
Hi,

Im Writting an Operating System and got to the Point where i have to setup my Memory (Paging etc.).
Memory and Paging are setted up so far but i have the Problem to tell my MemoryManager where the Kernel Starts and Ends. In GCC i can simply say

Code: Select all

_KernelStart = .; <-----
	.text : ALIGN(0x1000)
	.data : ALIGN(0x1000)
	.rodata : ALIGN(0x1000)
	.bss : ALIGN(0x1000)
_KernelEnd = .; <-----
and using the variables in cpp but how can i do that in msvc?

Re: MSVC - KernelStart and KernelEnd Location

Posted: Sat Apr 09, 2022 12:31 pm
by neon
Hi,

The kernel already has all the information needed; its header information and associated data structures are in memory at the image base address. It can obtain the locations and sizes of all the sections there.

To provide a little more context, this is a small snippet from our system:

Code: Select all

PUBLIC size_t PeGetImageSize(IN char* imageBase) {

	IMAGE_DOS_HEADER*     p;
	IMAGE_NT_HEADERS*     ntHeaders;

	p = (IMAGE_DOS_HEADER*)imageBase;
	ntHeaders = (IMAGE_NT_HEADERS*) (p->lfanew + imageBase);

	return (size_t) ntHeaders->optionalHeader.sizeOfImage;
}
...
PeGetImageSize (KERNEL_PHYSICAL)