need help wit sbrk

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J de Boyne Pollard

    #1

    need help wit sbrk

    hNow the next step is to write malloc and free, for kernel
    hheap management. I am keeping my kernel heap at
    h0XD0000000. My understanding is that malloc calls sbrk
    hto 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.

Working...