feat: implement per-process environment variables (AI)
- Created env.c/h: key=value store with ENV_MAX_VARS=32 entries per process. Supports get, set, unset, and copy operations. - Added env_block_t and cwd[128] fields to process_t struct. - process_create() initializes CWD=/ by default. - Fork inherits environment via memcpy of the entire process_t. - Added SYS_GETENV (8) and SYS_SETENV (9) system calls. - Created env-test user app that verifies: CWD default, set/get, and inheritance across fork. - Updated kernel.c to launch 'sh' as init process (for next task). - Updated README.md to check off environment variables task. Tested: env-test reads CWD=/, sets TEST=hello, reads it back, forks child which inherits TEST=hello. All verified via QEMU.
This commit is contained in:
18
src/kernel.c
18
src/kernel.c
@@ -152,18 +152,21 @@ void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
offset_print("FAILED to kmalloc\n");
|
||||
}
|
||||
|
||||
/* Load hello-world from the initrd and run it as a user process */
|
||||
/* Load the initial program from the initrd and run it */
|
||||
cpio_entry_t app_entry;
|
||||
if (cpio_find("hello-world", &app_entry) == 0) {
|
||||
offset_print("Found hello-world in initrd (");
|
||||
const char *init_app = "sh";
|
||||
if (cpio_find(init_app, &app_entry) == 0) {
|
||||
offset_print("Found ");
|
||||
offset_print(init_app);
|
||||
offset_print(" in initrd (");
|
||||
print_hex(app_entry.datasize);
|
||||
offset_print(" bytes)\n");
|
||||
|
||||
int32_t pid = process_create("hello-world",
|
||||
int32_t pid = process_create(init_app,
|
||||
app_entry.data,
|
||||
app_entry.datasize);
|
||||
if (pid > 0) {
|
||||
offset_print("Created hello-world process, pid=");
|
||||
offset_print("Created init process, pid=");
|
||||
print_hex((uint32_t)pid);
|
||||
|
||||
/* Enable interrupts before entering user mode */
|
||||
@@ -173,10 +176,11 @@ void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
/* Enter user mode - does not return */
|
||||
process_run_first();
|
||||
} else {
|
||||
offset_print("FAILED to create hello-world process\n");
|
||||
offset_print("FAILED to create init process\n");
|
||||
}
|
||||
} else {
|
||||
offset_print("hello-world not found in initrd\n");
|
||||
offset_print(init_app);
|
||||
offset_print(" not found in initrd\n");
|
||||
}
|
||||
|
||||
/* Enable interrupts */
|
||||
|
||||
Reference in New Issue
Block a user