OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 2:38 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Manual process loading in C?
PostPosted: Thu Jan 07, 2016 2:51 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Hello, OSDev.org.

Recently I started working on a kernel that would be able to run in both freestanding and hosted environments. I want to manually load ELF files and build host processes from them. How can I do it? Is there any way to create a "blank" process and control its memory and machine state under UNIX/POSIX?

Google told me that I can use ptrace on a "dummy" process started by fork/execv/etc. Is it a good way? Is there something better? What about forking the kernel and replacing the forked process from inside?

Ideally, I would like a way that is supported by many platforms, but I'm also interested in system-specific paths too.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Last edited by Roman on Thu Jan 07, 2016 4:40 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Manual process loading in C?
PostPosted: Thu Jan 07, 2016 3:56 pm 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
I would recommend forking and replacing the child. Should be fairly easy to do actually. You can either cleanly discard the inherited data (open file descriptors and whatever else is passed from parent to child) or you can just ignore it and initialise your own data structures. Then you can either implement fork in your own operating system for standalone use or replace the process loader.

Something makes me think that there should be an exec that operates on memory rather than files, but obviously (for security reasons, I assume) most kernel developers decided that it would be better to avoid relying on processes correctly loading and executing an executable image (which, if it went wrong, could have drastic consequences) and rather try to enforce that the kernel does it itself.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group