Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Topics

Recent Status Updates

View All Updates

Photo
- - - - -

Implementing malloc and free

malloc

  • Please log in to reply
8 replies to this topic

#1 manux

manux

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 211 posts

Posted 10 October 2009 - 01:55 PM

Hello all,

recently I've been working with a friend on what could be called an OS(no we do not want to make another Windows and become millionaires,we only want to have fun:thumbup1:)

So, we are now at a point where we need dynamic allocation, that is using xxalloc and free functions.
I've read alot about paging, virtual memory management, and other related topics.
But almost everytime, the author explains himself either considering the reader a newbie(i.e. osdev wiki) or an assembly/hardware expert, which I am not.
So, I have not found any suitable example (that works with djgpp), by suitable I mean, complex enough, but still understandable for a mid-range programmer.

I would like is not to copy someone else's work, and try to understand what is really happening.

So if you have any good links or tips, please share them.
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 October 2009 - 05:46 PM

Have you looked at the Linux kernel, or minix?

If you're making an OS, you have to be close to the hardware.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Guest_h4x_*

Guest_h4x_*
  • Guest

Posted 11 October 2009 - 08:43 AM

or an assembly/hardware expert, which I am not.

then perhaps os writing is too much of a challange for you.

my advice:
**** memory virtualization and protection, turn off everything to have pure flat memory.
all you use is exception handling, calls, and hardware interrupts.
this way you avoid mistakes they made in i386.
security in distributing files for it? no problem! make official HLL language, wich will compile app to have only certain access to your system. no assembly from outside. all protection software driven. or even **** debugger, you run everything via debugger and it check few system dependent things (like if memory its about to access was alloated by this process, if instruction is allowed, and some other customized stuff)
performance? sure, slow. but if you run a server, you dont use debug. if it crash (ok it wont crash, just random instruction executing untill it reach memory limit - then massive interrupt wich indicate exceed memory region /oh wait, we dont have that one, ****/) - **** it, you restart machine wich should take < 1 second and fix the bug. you run a web browser - it will be emulated by software and few times slower. but whatever, if you trust its flawless you run it in unprotected way and its much faster.

i plan writing that os, but... im not ready yes.
i would really like cpu that is so simple, that i dont have to worry about anything beside my code.

and this way we can expect many oses, and even hardware, wich give software full control over it.
computers should be blank, only what is really needed, all managment and protection should be done by software.
slower, yes, but better and affordable with tody tech.
  • 0

#4 JCoder

JCoder

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 240 posts

Posted 11 October 2009 - 08:57 AM

then perhaps os writing is too much of a challange for you.

my advice:
**** memory virtualization and protection, turn off everything to have pure flat memory.


The problem is in real mode you can address only 640 kB of memory and the segmantation complicates keeping structures larger than 64 kB. On x86 you must enter protected mode to get more.
  • 0

#5 Guest_h4x_*

Guest_h4x_*
  • Guest

Posted 11 October 2009 - 09:41 AM

REAL MODE? Did i used that term? no? so skip ur thinking schemes and think of a grand one.
protected mode might be needed indeed, but let all run in ring0, without paging. untill someone build popular cpu supporting that.
  • 0

#6 TkTech

TkTech

    The Crazy One

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1144 posts
  • Location:Ottawa, Ontario

Posted 11 October 2009 - 03:29 PM

h4x, I'm an op in #osdev and a mod on osdev.org. If I EVER see you post there, I'll delete your account so fast you won't even blink.

@manux: See the pedigree link in my signature. The repo is open source, you can see implementations for memory protection and allocation for several different architectures.
  • 0
Helpful CODECALL Links: Join Us, Guidelines, FAQ, Post a Tutorial

#7 manux

manux

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 211 posts

Posted 16 October 2009 - 11:03 AM

I need to understand: where in the code is the difference made between virtual addresses and physical addresses? once I made a page table, where do I tell the computer how to translate the addresses according to my table?
  • 0

#8 TkTech

TkTech

    The Crazy One

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1144 posts
  • Location:Ottawa, Ontario

Posted 16 October 2009 - 12:20 PM

What? The page table IS what maps virtual and physical addresses, via the MMU. I'd advise you read up on what paging does.
  • 0
Helpful CODECALL Links: Join Us, Guidelines, FAQ, Post a Tutorial

#9 manux

manux

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 211 posts

Posted 16 October 2009 - 01:55 PM

Thanks! thats the tiny asm code I needed...
Darn, how did I miss it. :confused:
  • 0





Also tagged with one or more of these keywords: malloc

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download