Page 1 of 1

Multitasking , Memory Management and Process Cleanup

Posted: Thu Apr 02, 2009 10:30 am
by Duleb
Hi everybody,
I have been working on my kernel for few weeks now.I have just completed my memory manager recently.I need to clarifie some issues ; here is what i have done in memory manager

top level - malloc()
middle level - memory_mapper()
bottom - physical_frame_allocate().

1)malloc () - simple bin approach.starts allocation from 0xC0000000.
2)memory_mapper() - asks os for memory and maps this memory to the end of Heap(stating from 0XC0000000).( I have set 1023rd entry of page directory to itself so that i can manipulate physical address once paging is enabled)
3)physical_frame_allocate() - simple bitmap approach.memory_mapper() asks this function to supply pages.

These are for kernel code. and are working fine.Is writing memory manager for application layer code any different from this .I have been thinking
1) exact same methods except user heap starts from say 2 gb mark and
2) level bit in frame is set to user level.
would this suffice ??

Question 2) I have read James tutorial for multitasking. Is there some other way for copying stack to different location.( Handling esp and ebp )

question 3) How does kernel knows if a process has ended if process do not call exit() explicitly.I have read that compilers places exit() call at end but what if system call is implemented by some different name?What does DJGPP add in such cases ?

Re: Multitasking , Memory Management and Process Cleanup

Posted: Fri Apr 03, 2009 12:46 am
by Combuster
Duleb wrote:Question 2) I have read James tutorial for multitasking. Is there some other way for copying stack to different location.( Handling esp and ebp )
Generally, moving a stack is a bad idea since there's no way to make sure everything points to the new stack rather than the old stack (and not corrupt things in the process)
question 3) How does kernel knows if a process has ended if process do not call exit() explicitly.I have read that compilers places exit() call at end but what if system call is implemented by some different name?What does DJGPP add in such cases ?
The compiler doesn't. The C library does.

When you link an application, it includes the C runtime (commonly in the form of crt0.o, crtbegin.o and crtend.o). what crt0 does (and looks like) is this:

Code: Select all

entry:
// do some setup (opening stdin, stdout, global c++ constructors)
call main
// do some cleanup (atexit, closing files, c++ destructors)
call exit
Which is a very platform dependent piece of code. Since all programs only write main, and all programs include this file by virtue of the linker, you get the automatic safeguard that anything that returns from main will cause an implicit exit()

Re: Multitasking , Memory Management and Process Cleanup

Posted: Fri Apr 03, 2009 1:14 am
by prajwal
Question 3). My kernel currently supports only ELF 32Bit Exes. The Loader inserts an Entry /Exit code(small startup function) into the executable memory image and modifies ELF Entry Address to point to this stattup function. So, if the process /user program completes gracefully, control comes back to this startup function which then calls EXIT API