Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

My OS


lukem_95's Avatar
Member
0 0

I always wanted to make an OS, ever since i first read a mini article on the topic back at HTS 3 years ago.

I finally started 3 days ago. Its remarkably easy once you get started, you just gotta be extremely patient, play around with ALOT of very low level c, and read alot of documentation for VGA drivers and other such boring things.

I was thinking of posting bits of the source, or the iso's or whatever once theres something worth showing, but for now i'd just like to ask a fairly quick question (and i felt like showing off slightly, cos im fucking proud of myself lol).

Does anybody have any clue how i could implement my own version of malloc() without using any system calls except:

strcat
strcpy
strcmp
strlen
memset
memcpy
memsetw
inportb
outportb

These are the ones i've got to work so far. Aswell as the worlds crappiest print function, and a pimped, colour, ascii art logo. Theres also CPU and floppy detection cos i worked out how to do that using the importb() asm ported function.


ghost's Avatar
0 0

You're going to have to manage start managing your own heap for allocation calls :)

The simplest form would be:

// 100k heap
char myHeap[100 * 1024];
char *nextBlock = &myHeap[0];

void* malloc( size_t size )
{
  void *ptr;

  // Check to see if there's anything left
  if( (nextBlock + size) > (myHeap + (100 * 1024)) )
  {
    return NULL;
  }

  ptr = (void *)nextBlock;
  nextBlock += size;

  return ptr;
}

Going further than that you can use a linked list to keep track of how much memory is being used and the blocks next to it (but as the first, say, 64 bytes of each allocation) and work your own algorithm up to handle freeing & re-allocating memory etc.

I think the Thinking in C++ 2nd edition book covers mini object allocators which was an interesting read :)


lukem_95's Avatar
Member
0 0

Thanks for your amazing reply, i really didnt expect much help hereā€¦ no offence to everyone but there really arent that many great coders that i know of. Just the odd one or two ;)


ghost's Avatar
0 0

You know, there are some pretty good libc small implementations that you can look at for malloc implementations.