OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Pass object to child process
PostPosted: Sun Jul 18, 2021 2:22 am 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
I need to pass an object from init to child (and on to each child after that) basically a global variable thats essential to how my os works. I can't pass it using the vfs because its the root vfs node to bootstrap access to the vfs in the first place. I can however assign the page frame its stored on to the child on creation, but dont know how it would be accessed. Would you just use it like normal once assigned, or is there some other way to use it? I can't find the right wording to search for to find the answer. Once the child has the root vfs node, everything after is golden, just having this one last bootstrapping problem. I'm using a single address space (no virtual addressing) and all programs compiled with pic


Last edited by n0p0n3 on Sun Jul 18, 2021 2:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 2:31 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Can't you just store the variable at a fixed memory location?


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 2:44 am 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
I'd seen that as a solution but didnt know if it was a good way of going about it. Once the process gets it, all other things become possible (process scheduling, memory management, device drivers). I could also pass it by modifying the main function to accept it but I'm trying to stay posix and I dont know how that would break things. I'm also using netbsd rumpkernel stuff so I have to dive into the vfs code to see what's there, there very well may be something that I don't know about there that helps.


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 12:30 pm 
Online
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
Pass the object on the stack? Or pass the object anywhere in user space, and add an auxiliary vector that points to it? That's how Linux injects the VDSO.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 5:49 pm 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
How would I do either of those? I've basically got a unikernel running, and once done will have multiple unikernels running, with scheduling, and access controls. Untill then, the only way I can think of other than using a set memory address is to have each Unikernel read from the hdd or a ramdisk or something and which requires drivers, thus negating the whole idea of having them embedded in the vfs v_ops in the first place.


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 5:54 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
What I would do is send the v_ops struct as a parameter to init's main(), and then have init pass it on to children as parameters as well.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 18, 2021 6:51 pm 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
Would it work if I pass the root vfs node address through the args and cast to a pointer? That way I could have the address randomized and not stored as an environ variable for all to see. Also it would ensure all my processes are using the same root vfs node. Its a single flat address space so no virtual addresses and I can have the page assigned to each child on creation for access control. When I search for it, people say it can't work because each process has the same virtual address but different physical addresses, but I can't find much about flat addressing and casting pointers from strings in combo. I was reading a stackoverflow question where one of the answers is to run the text string containing memory address through sscanf and convert to hex, then typecast to void pointer. Would this work, cause that would probably be perfect.

https://stackoverflow.com/questions/415 ... inter-in-c


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Thu Jul 22, 2021 12:18 am 
Offline
Member
Member

Joined: Wed Oct 26, 2011 12:00 pm
Posts: 202
When you initialize the stack for the process's main thread, I would just push all the data you need onto the top of the stack, and then end with a pointer to itself so that becomes the first argument to your process's init function.

_________________
mollenos | gracht (protocol library) | vioarr (window-manager) | bake (package manager)


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 25, 2021 8:05 am 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
I went looking for this and found alot I didnt know about happening under the hood that isn't written about very well, but this would probably be the best way. I found a code snippet that explains a way to fetch the data, but I am not sure how good it is.

<stdio.h>
#include <elf.h>

main(int argc, char* argv[], char* envp[])
{
Elf32_auxv_t *auxv;
while (*envp++ != NULL); /* from stack diagram above: *envp = NULL marks end of envp */

for (auxv = (Elf32_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++)
/* auxv->a_type = AT_NULL marks the end of auxv */
{
if (auxv->a_type == AT_SYSINFO)
printf("AT_SYSINFO is: 0x%x\n", auxv->a_un.a_val);
}
}

Seems like its casting the envp string to aux_t and iterating through. Wouldnt this cause problems since strings are chars and the aux_t struct are different sizes? Wouldn't you risk iterating into the middle of an element?
Or is it iterating through to the end of the string, then once more to reach the auxv? I did see something to that effect somewhere.
Otherwise in likeing this method of passing the needed info.


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 25, 2021 3:36 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
n0p0n3 wrote:
Seems like its casting the envp string to aux_t and iterating through. Wouldnt this cause problems since strings are chars and the aux_t struct are different sizes? Wouldn't you risk iterating into the middle of an element?


envp isn't a string, it's a pointer to the first element in an array of pointers to strings.

The code you posted iterates through the array until it reaches the last one, indicated by a null. Then it goes one further, which is where the auxillary vector is; it casts one pointer to another pointer type. It's not casting a string to a pointer, it's casting a pointer to a pointer.


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 25, 2021 4:11 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Keep in mind main() is not the entry point. You have your startup code that calls main(), and you can put whatever you want in there to make it more convenient to pass the object to the rest of your program.


Top
 Profile  
 
 Post subject: Re: Pass object to child process
PostPosted: Sun Jul 25, 2021 9:57 pm 
Offline

Joined: Fri Jun 25, 2021 11:11 pm
Posts: 10
Yeah I had a total brain fart about the string thing, I definitely think this is the best way to go about it


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], nullplan and 63 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