malloc() in pmode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Adrian

malloc() in pmode

Post by Adrian »

How is this supposed to work? How to allow the program to access the data?

I cannot give away generel linear selectors to PL#3, perhaps I should create a new one for each block

Adrian.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:malloc() in pmode

Post by Pype.Clicker »

giving each block a separate segment will not work with traditionnal C programming
- because people assume malloc to return a void* and they also assume sizeof(void*) == sizeof(int).
- because you only have 8192 selectors and that you're likely to have more blocks than this ...

I would rather promote the use of segments for some "special things" like shared memory areas, mapped files, etc.

Of course in a perfect world, the compiler would do that for you, but the world isn't perfect :(
Adrian

Re:malloc() in pmode

Post by Adrian »

How does it work then?

Adrian
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:malloc() in pmode

Post by Pype.Clicker »

you usually have one big segment for the data & heap and chunks you got with malloc have no "buffer-overflow" protections (i.e. *(malloc(10)+10)='0' will not necessarily raise an exception, except if the allocated block is next to the latest allocated page.

That's a pity, but from that point of view, Intel Architecture didn't manage what it promised.

Now, maybe with some FARPTR tricks, you could protect some very important buffers, but that's all.

If you need more info on malloc algorithm, i suggest you read the tutorials about memory management (from Tim Robinson's page or Bona Fide Development, i think?
pskyboy

Re:malloc() in pmode

Post by pskyboy »

I didn't find the algorithm for my malloc function to hard to implement and its not that compilcated either. It still doesn't fulyl work at the moment as i have to set up the page fault interupt but i think the malloc function will work alright when it actually has memory behind it.

Peter
Post Reply