Remove env vars
This commit is contained in:
@@ -30,8 +30,6 @@
|
|||||||
#define SYS_CREATE_DIR 27
|
#define SYS_CREATE_DIR 27
|
||||||
#define SYS_REMOVE 28
|
#define SYS_REMOVE 28
|
||||||
#define SYS_CREATE_VOLUME 29
|
#define SYS_CREATE_VOLUME 29
|
||||||
#define SYS_ENV_SET 30
|
|
||||||
#define SYS_ENV_GET 31
|
|
||||||
#define SYS_EXEC_PARTIAL 32
|
#define SYS_EXEC_PARTIAL 32
|
||||||
#define SYS_EXEC_PARTIAL_FINI 33
|
#define SYS_EXEC_PARTIAL_FINI 33
|
||||||
#define SYS_GET_SELF_PID 34
|
#define SYS_GET_SELF_PID 34
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <limine/requests.h>
|
#include <limine/requests.h>
|
||||||
#include <mm/malloc.h>
|
#include <mm/malloc.h>
|
||||||
#include <mm/pmm.h>
|
#include <mm/pmm.h>
|
||||||
#include <proc/env.h>
|
|
||||||
#include <proc/mutex.h>
|
#include <proc/mutex.h>
|
||||||
#include <proc/proc.h>
|
#include <proc/proc.h>
|
||||||
#include <proc/procgroup.h>
|
#include <proc/procgroup.h>
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
#include <libk/fieldlengthof.h>
|
|
||||||
#include <libk/hash.h>
|
|
||||||
#include <libk/lengthof.h>
|
|
||||||
#include <libk/minmax.h>
|
|
||||||
#include <libk/std.h>
|
|
||||||
#include <libk/string.h>
|
|
||||||
#include <mm/malloc.h>
|
|
||||||
#include <proc/env.h>
|
|
||||||
#include <proc/procgroup.h>
|
|
||||||
#include <status.h>
|
|
||||||
|
|
||||||
void proc_env_cleanup(struct procgroup* procgroup) {
|
|
||||||
for (size_t i = 0; i < fieldlengthof(struct proc_env, env_var_buckets); i++) {
|
|
||||||
struct hash_node_link* link = procgroup->env.env_var_buckets[i];
|
|
||||||
|
|
||||||
if (link == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
struct proc_env_var* var = hash_entry(link, struct proc_env_var, env_link);
|
|
||||||
|
|
||||||
free(var->buffer);
|
|
||||||
free(var);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int proc_env_set(struct procgroup* procgroup, const char* key, void* buffer, size_t data_size) {
|
|
||||||
struct proc_env_var* var = malloc(sizeof(*var));
|
|
||||||
|
|
||||||
if (var == NULL)
|
|
||||||
return -ST_OOM_ERROR;
|
|
||||||
|
|
||||||
memset(var, 0, sizeof(*var));
|
|
||||||
|
|
||||||
var->buffer = malloc(data_size);
|
|
||||||
|
|
||||||
if (var->buffer == NULL) {
|
|
||||||
free(var);
|
|
||||||
return -ST_OOM_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
var->data_size = data_size;
|
|
||||||
memcpy(var->key, key, strlen_null(key));
|
|
||||||
memcpy(var->buffer, buffer, data_size);
|
|
||||||
|
|
||||||
uint32_t env_hash = hash_fnv32(var->key, strlen_null(var->key));
|
|
||||||
|
|
||||||
hash_insert(&procgroup->env, &var->env_link, env_hash, lengthof(procgroup->env.env_var_buckets),
|
|
||||||
env_var_buckets);
|
|
||||||
|
|
||||||
return ST_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int proc_env_get(struct procgroup* procgroup, const char* key, void* buffer, size_t size) {
|
|
||||||
struct hash_node_link* found_link = NULL;
|
|
||||||
size_t key_len = strlen_null(key);
|
|
||||||
uint32_t hash = hash_fnv32(key, key_len);
|
|
||||||
|
|
||||||
hash_find(&procgroup->env, key, key_len, hash, lengthof(procgroup->env.env_var_buckets),
|
|
||||||
env_var_buckets, struct proc_env_var, env_link, key, found_link);
|
|
||||||
|
|
||||||
if (found_link == NULL) {
|
|
||||||
return -ST_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct proc_env_var* var = hash_entry(found_link, struct proc_env_var, env_link);
|
|
||||||
|
|
||||||
memcpy(buffer, var->buffer, min(size, var->data_size));
|
|
||||||
|
|
||||||
return ST_OK;
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#ifndef _KERNEL_PROC_ENV_H
|
|
||||||
#define _KERNEL_PROC_ENV_H
|
|
||||||
|
|
||||||
#include <libk/hash.h>
|
|
||||||
#include <libk/std.h>
|
|
||||||
|
|
||||||
#define PROC_ENV_VAR_MAX 512
|
|
||||||
|
|
||||||
struct procgroup;
|
|
||||||
|
|
||||||
struct proc_env_var {
|
|
||||||
char key[PROC_ENV_VAR_MAX];
|
|
||||||
void* buffer;
|
|
||||||
size_t data_size;
|
|
||||||
struct hash_node_link env_link;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct proc_env {
|
|
||||||
struct hash_node_link* env_var_buckets[64];
|
|
||||||
};
|
|
||||||
|
|
||||||
void proc_env_cleanup(struct procgroup* procgroup);
|
|
||||||
|
|
||||||
int proc_env_set(struct procgroup* procgroup, const char* key, void* buffer, size_t data_size);
|
|
||||||
|
|
||||||
int proc_env_get(struct procgroup* procgroup, const char* key, void* buffer, size_t size);
|
|
||||||
|
|
||||||
#endif // _KERNEL_PROC_ENV_H
|
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <limine/requests.h>
|
#include <limine/requests.h>
|
||||||
#include <mm/malloc.h>
|
#include <mm/malloc.h>
|
||||||
#include <mm/pmm.h>
|
#include <mm/pmm.h>
|
||||||
#include <proc/env.h>
|
|
||||||
#include <proc/proc.h>
|
#include <proc/proc.h>
|
||||||
#include <proc/procgroup.h>
|
#include <proc/procgroup.h>
|
||||||
#include <proc/reschedule.h>
|
#include <proc/reschedule.h>
|
||||||
@@ -219,8 +218,6 @@ static void procgroup_delete(struct procgroup* procgroup, struct reschedule_ctx*
|
|||||||
free(mapping);
|
free(mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_env_cleanup(procgroup);
|
|
||||||
|
|
||||||
pmm_free(procgroup->paddr_cmdline, 1);
|
pmm_free(procgroup->paddr_cmdline, 1);
|
||||||
|
|
||||||
pmm_free(procgroup->pd.cr3_paddr, 1);
|
pmm_free(procgroup->pd.cr3_paddr, 1);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <libk/rbtree.h>
|
#include <libk/rbtree.h>
|
||||||
#include <libk/std.h>
|
#include <libk/std.h>
|
||||||
#include <page_size.h>
|
#include <page_size.h>
|
||||||
#include <proc/env.h>
|
|
||||||
#include <proc/resource.h>
|
#include <proc/resource.h>
|
||||||
#include <sync/spin_lock.h>
|
#include <sync/spin_lock.h>
|
||||||
#include <sys/mm.h>
|
#include <sys/mm.h>
|
||||||
@@ -36,7 +35,6 @@ struct procgroup {
|
|||||||
struct list_node_link* mappings;
|
struct list_node_link* mappings;
|
||||||
uintptr_t map_base;
|
uintptr_t map_base;
|
||||||
struct procgroup_tls tls;
|
struct procgroup_tls tls;
|
||||||
struct proc_env env;
|
|
||||||
uintptr_t uvaddr_cmdline;
|
uintptr_t uvaddr_cmdline;
|
||||||
uintptr_t paddr_cmdline;
|
uintptr_t paddr_cmdline;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ c += proc/proc.c \
|
|||||||
proc/procgroup.c \
|
proc/procgroup.c \
|
||||||
proc/suspension_q.c \
|
proc/suspension_q.c \
|
||||||
proc/mail.c \
|
proc/mail.c \
|
||||||
proc/env.c \
|
|
||||||
proc/stream.c
|
proc/stream.c
|
||||||
|
|
||||||
o += proc/proc.o \
|
o += proc/proc.o \
|
||||||
@@ -13,5 +12,4 @@ o += proc/proc.o \
|
|||||||
proc/procgroup.o \
|
proc/procgroup.o \
|
||||||
proc/suspension_q.o \
|
proc/suspension_q.o \
|
||||||
proc/mail.o \
|
proc/mail.o \
|
||||||
proc/env.o \
|
|
||||||
proc/stream.o
|
proc/stream.o
|
||||||
|
|||||||
@@ -734,74 +734,6 @@ DEFINE_SYSCALL(sys_create_volume) {
|
|||||||
return SYSRESULT(vfs_create_volume(proc, rctx, key, type, device, false));
|
return SYSRESULT(vfs_create_volume(proc, rctx, key, type, device, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int env_set (int pgid, char* key, void* buffer, size_t size) */
|
|
||||||
DEFINE_SYSCALL(sys_env_set) {
|
|
||||||
int pgid = (int)a1;
|
|
||||||
uintptr_t uvaddr_key = a2;
|
|
||||||
uintptr_t uvaddr_buffer = a3;
|
|
||||||
size_t size = (size_t)a4;
|
|
||||||
|
|
||||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
|
||||||
|
|
||||||
struct procgroup* target_procgroup = procgroup_find(pgid);
|
|
||||||
|
|
||||||
if (target_procgroup == NULL)
|
|
||||||
return SYSRESULT(-ST_NOT_FOUND);
|
|
||||||
|
|
||||||
uintptr_t out_paddr;
|
|
||||||
|
|
||||||
struct procgroup* procgroup = proc->procgroup;
|
|
||||||
|
|
||||||
out_paddr = mm_v2p(&procgroup->pd, uvaddr_key);
|
|
||||||
|
|
||||||
if (out_paddr == 0) {
|
|
||||||
return SYSRESULT(-ST_BAD_ADDRESS_SPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* key = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
|
||||||
|
|
||||||
void* buffer = sys_get_user_buffer(procgroup, uvaddr_buffer, size);
|
|
||||||
|
|
||||||
if (buffer == NULL)
|
|
||||||
return SYSRESULT(-ST_BAD_ADDRESS_SPACE);
|
|
||||||
|
|
||||||
return SYSRESULT(proc_env_set(target_procgroup, key, buffer, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* int env_get (int pgid, char* key, void* buffer, size_t size) */
|
|
||||||
DEFINE_SYSCALL(sys_env_get) {
|
|
||||||
int pgid = (int)a1;
|
|
||||||
uintptr_t uvaddr_key = a2;
|
|
||||||
uintptr_t uvaddr_buffer = a3;
|
|
||||||
size_t size = (size_t)a4;
|
|
||||||
|
|
||||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
|
||||||
|
|
||||||
struct procgroup* target_procgroup = procgroup_find(pgid);
|
|
||||||
|
|
||||||
if (target_procgroup == NULL)
|
|
||||||
return SYSRESULT(-ST_NOT_FOUND);
|
|
||||||
|
|
||||||
uintptr_t out_paddr;
|
|
||||||
|
|
||||||
struct procgroup* procgroup = proc->procgroup;
|
|
||||||
|
|
||||||
out_paddr = mm_v2p(&procgroup->pd, uvaddr_key);
|
|
||||||
|
|
||||||
if (out_paddr == 0) {
|
|
||||||
return SYSRESULT(-ST_BAD_ADDRESS_SPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* key = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
|
||||||
|
|
||||||
void* buffer = sys_get_user_buffer(procgroup, uvaddr_buffer, size);
|
|
||||||
|
|
||||||
if (buffer == NULL)
|
|
||||||
return SYSRESULT(-ST_BAD_ADDRESS_SPACE);
|
|
||||||
|
|
||||||
return SYSRESULT(proc_env_get(target_procgroup, key, buffer, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* int get_self_pid (void) */
|
/* int get_self_pid (void) */
|
||||||
DEFINE_SYSCALL(sys_get_self_pid) {
|
DEFINE_SYSCALL(sys_get_self_pid) {
|
||||||
int pid = proc->pid;
|
int pid = proc->pid;
|
||||||
@@ -991,8 +923,6 @@ static syscall_handler_func_t handler_table[] = {
|
|||||||
[SYS_CREATE_DIR] = &sys_create_dir,
|
[SYS_CREATE_DIR] = &sys_create_dir,
|
||||||
[SYS_REMOVE] = &sys_remove,
|
[SYS_REMOVE] = &sys_remove,
|
||||||
[SYS_CREATE_VOLUME] = &sys_create_volume,
|
[SYS_CREATE_VOLUME] = &sys_create_volume,
|
||||||
[SYS_ENV_SET] = &sys_env_set,
|
|
||||||
[SYS_ENV_GET] = &sys_env_get,
|
|
||||||
[SYS_EXEC_PARTIAL] = &sys_exec_partial,
|
[SYS_EXEC_PARTIAL] = &sys_exec_partial,
|
||||||
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
||||||
[SYS_GET_SELF_PID] = &sys_get_self_pid,
|
[SYS_GET_SELF_PID] = &sys_get_self_pid,
|
||||||
|
|||||||
@@ -89,14 +89,6 @@ int create_volume(const char* key, int fs_type, const char* device_key) {
|
|||||||
return (int)do_syscall(SYS_CREATE_VOLUME, key, fs_type, device_key);
|
return (int)do_syscall(SYS_CREATE_VOLUME, key, fs_type, device_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int env_set(int pgid, const char* key, void* buffer, size_t len) {
|
|
||||||
return (int)do_syscall(SYS_ENV_SET, pgid, key, buffer, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_get(int pgid, const char* key, void* buffer, size_t len) {
|
|
||||||
return (int)do_syscall(SYS_ENV_GET, pgid, key, buffer, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
int exec_partial(const char* volume, const char* path, const char* cmdline) {
|
int exec_partial(const char* volume, const char* path, const char* cmdline) {
|
||||||
return (int)do_syscall(SYS_EXEC_PARTIAL, volume, path, cmdline);
|
return (int)do_syscall(SYS_EXEC_PARTIAL, volume, path, cmdline);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,12 +97,6 @@ int remove(const char* path);
|
|||||||
/* mount a volume */
|
/* mount a volume */
|
||||||
int create_volume(const char* key, int fs_type, const char* device_key);
|
int create_volume(const char* key, int fs_type, const char* device_key);
|
||||||
|
|
||||||
/* Set environment variable */
|
|
||||||
int env_set(int pgid, const char* key, void* buffer, size_t len);
|
|
||||||
|
|
||||||
/* Get environment variable */
|
|
||||||
int env_get(int pgid, const char* key, void* buffer, size_t len);
|
|
||||||
|
|
||||||
/* Prepare process for execution */
|
/* Prepare process for execution */
|
||||||
int exec_partial(const char* volume, const char* path, const char* cmdline);
|
int exec_partial(const char* volume, const char* path, const char* cmdline);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user