need help wit sbrk

J

J de Boyne Pollard

h> Now the next step is to write malloc and free, for kernel
h> heap management. I am keeping my kernel heap at
h> 0XD0000000. My understanding is that malloc calls sbrk
h> to allocate more memory to the heap. [...]

Your understanding is wrong. You're doing kernel-mode programming.
Throw out your applications-mode programming assumptions. They
aren't, in this particular instance, even suitable for applications-
mode. (The concept underpinning sbrk() is about 30 years out of
date. It was out of date in 1988, when it was excluded from POSIX
1003.1.) malloc() calls whatever you implement it as calling.

To implement a simple malloc()/free()/new/delete, you need three
things: a list of heaps, a heap creator/destroyer to create and
destroy those heaps on demand, and a heap sub-allocator/deallocator to
allocate and free memory from within individual heaps. In
applications mode, these are often provided as standard operating
system functions. Witness DosAllocMem()/DosFreeMem()/DosSubSetMem()
and DosSubAllocMem()/DosSubFreeMem() on OS/2, and HeapAlloc()/
HeapDestroy() and HeapAlloc()/HeapFree() on Win32. For kernel-mode
programming, you need to implement something akin to these yourself.
You say that you have a facility for allocating and freeing 1 or more
whole pages. You thus have the necessary equivalents to DosAllocMem()
and DosFreeMem() already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top