Pass object to child process
Pass object to child process
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.
Re: Pass object to child process
Can't you just store the variable at a fixed memory location?
Re: Pass object to child process
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.
Re: Pass object to child process
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!
Re: Pass object to child process
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.
Re: Pass object to child process
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.
Re: Pass object to child process
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
https://stackoverflow.com/questions/415 ... inter-in-c
Re: Pass object to child process
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.
Re: Pass object to child process
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.
<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.
Re: Pass object to child process
envp isn't a string, it's a pointer to the first element in an array of pointers to strings.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?
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.
-
- Member
- Posts: 5567
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Pass object to child process
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.
Re: Pass object to child process
Yeah I had a total brain fart about the string thing, I definitely think this is the best way to go about it