OSDev.org
https://forum.osdev.org/

Pass object to child process
https://forum.osdev.org/viewtopic.php?f=1&t=46482
Page 1 of 1

Author:  n0p0n3 [ Sun Jul 18, 2021 2:22 am ]
Post subject:  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

Author:  iansjack [ Sun Jul 18, 2021 2:31 am ]
Post subject:  Re: Pass object to child process

Can't you just store the variable at a fixed memory location?

Author:  n0p0n3 [ Sun Jul 18, 2021 2:44 am ]
Post subject:  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.

Author:  nullplan [ Sun Jul 18, 2021 12:30 pm ]
Post subject:  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.

Author:  n0p0n3 [ Sun Jul 18, 2021 5:49 pm ]
Post subject:  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.

Author:  nexos [ Sun Jul 18, 2021 5:54 pm ]
Post subject:  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.

Author:  n0p0n3 [ Sun Jul 18, 2021 6:51 pm ]
Post subject:  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

Author:  MollenOS [ Thu Jul 22, 2021 12:18 am ]
Post subject:  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.

Author:  n0p0n3 [ Sun Jul 25, 2021 8:05 am ]
Post subject:  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.

Author:  davmac314 [ Sun Jul 25, 2021 3:36 pm ]
Post subject:  Re: Pass object to child process

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.

Author:  Octocontrabass [ Sun Jul 25, 2021 4:11 pm ]
Post subject:  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.

Author:  n0p0n3 [ Sun Jul 25, 2021 9:57 pm ]
Post subject:  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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/