Implement argument_ptr () syscall for handling process arguments
All checks were successful
Build documentation / build-and-deploy (push) Successful in 37s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 37s
This commit is contained in:
@@ -11,5 +11,6 @@
|
|||||||
#define SYS_MUTEX_DELETE 8
|
#define SYS_MUTEX_DELETE 8
|
||||||
#define SYS_MUTEX_LOCK 9
|
#define SYS_MUTEX_LOCK 9
|
||||||
#define SYS_MUTEX_UNLOCK 10
|
#define SYS_MUTEX_UNLOCK 10
|
||||||
|
#define SYS_ARGUMENT_PTR 11
|
||||||
|
|
||||||
#endif // _M_SYSCALL_DEFS_H
|
#endif // _M_SYSCALL_DEFS_H
|
||||||
|
|||||||
24
init/init.c
24
init/init.c
@@ -9,23 +9,10 @@
|
|||||||
|
|
||||||
LOCAL volatile char letter = 'c';
|
LOCAL volatile char letter = 'c';
|
||||||
|
|
||||||
void app_proc1 (void) {
|
void app_proc (void) {
|
||||||
letter = 'b';
|
char arg_letter = (char)(uintptr_t)argument_ptr ();
|
||||||
|
|
||||||
for (;;) {
|
letter = arg_letter;
|
||||||
mutex_lock (MUTEX);
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
test (letter);
|
|
||||||
|
|
||||||
mutex_unlock (MUTEX);
|
|
||||||
}
|
|
||||||
|
|
||||||
process_quit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_proc2 (void) {
|
|
||||||
letter = 'd';
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mutex_lock (MUTEX);
|
mutex_lock (MUTEX);
|
||||||
@@ -44,8 +31,9 @@ void app_main (void) {
|
|||||||
|
|
||||||
letter = 'a';
|
letter = 'a';
|
||||||
|
|
||||||
process_spawn (&app_proc1);
|
process_spawn (&app_proc, (void*)'a');
|
||||||
process_spawn (&app_proc2);
|
process_spawn (&app_proc, (void*)'b');
|
||||||
|
process_spawn (&app_proc, (void*)'c');
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mutex_lock (MUTEX);
|
mutex_lock (MUTEX);
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
|
|||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t entry) {
|
struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t entry,
|
||||||
|
uintptr_t argument_ptr) {
|
||||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||||
spin_lock_ctx_t ctxprt;
|
spin_lock_ctx_t ctxprt;
|
||||||
|
|
||||||
@@ -88,6 +89,8 @@ struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t ent
|
|||||||
proc->pdata.regs.cs = GDT_UCODE | 0x03;
|
proc->pdata.regs.cs = GDT_UCODE | 0x03;
|
||||||
proc->pdata.regs.rip = (uint64_t)entry;
|
proc->pdata.regs.rip = (uint64_t)entry;
|
||||||
|
|
||||||
|
proc->uvaddr_argument = argument_ptr;
|
||||||
|
|
||||||
proc_init_tls (proc);
|
proc_init_tls (proc);
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ struct proc {
|
|||||||
spin_lock_t lock;
|
spin_lock_t lock;
|
||||||
struct cpu* cpu;
|
struct cpu* cpu;
|
||||||
atomic_int state;
|
atomic_int state;
|
||||||
|
uintptr_t uvaddr_argument;
|
||||||
};
|
};
|
||||||
|
|
||||||
void proc_sched (void);
|
void proc_sched (void);
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
struct proc;
|
struct proc;
|
||||||
|
|
||||||
struct proc* proc_from_elf (uint8_t* elf_contents);
|
struct proc* proc_from_elf (uint8_t* elf_contents);
|
||||||
struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t entry);
|
struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t entry,
|
||||||
|
uintptr_t argument_ptr);
|
||||||
void proc_cleanup (struct proc* proc);
|
void proc_cleanup (struct proc* proc);
|
||||||
void proc_init_tls (struct proc* proc);
|
void proc_init_tls (struct proc* proc);
|
||||||
|
|
||||||
|
|||||||
@@ -78,12 +78,13 @@ DEFINE_SYSCALL (sys_unmap) {
|
|||||||
return SYSRESULT (procgroup_unmap (proc->procgroup, vaddr, pages));
|
return SYSRESULT (procgroup_unmap (proc->procgroup, vaddr, pages));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* int clone (uintptr_t vstack_top, void* entry) */
|
/* int clone (uintptr_t vstack_top, void* entry, void* argument_ptr) */
|
||||||
DEFINE_SYSCALL (sys_clone) {
|
DEFINE_SYSCALL (sys_clone) {
|
||||||
uintptr_t vstack_top = a1;
|
uintptr_t vstack_top = a1;
|
||||||
uintptr_t entry = a2;
|
uintptr_t entry = a2;
|
||||||
|
uintptr_t argument_ptr = a3;
|
||||||
|
|
||||||
struct proc* new = proc_clone (proc, vstack_top, entry);
|
struct proc* new = proc_clone (proc, vstack_top, entry, argument_ptr);
|
||||||
|
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
return SYSRESULT (-ST_OOM_ERROR);
|
return SYSRESULT (-ST_OOM_ERROR);
|
||||||
@@ -96,6 +97,9 @@ DEFINE_SYSCALL (sys_clone) {
|
|||||||
return SYSRESULT (pid);
|
return SYSRESULT (pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* void* argument_ptr (void) */
|
||||||
|
DEFINE_SYSCALL (sys_argument_ptr) { return proc->uvaddr_argument; }
|
||||||
|
|
||||||
/* int sched (void) */
|
/* int sched (void) */
|
||||||
DEFINE_SYSCALL (sys_sched) {
|
DEFINE_SYSCALL (sys_sched) {
|
||||||
proc_sched ();
|
proc_sched ();
|
||||||
@@ -165,6 +169,7 @@ static syscall_handler_func_t handler_table[] = {
|
|||||||
[SYS_MAP] = &sys_map,
|
[SYS_MAP] = &sys_map,
|
||||||
[SYS_UNMAP] = &sys_unmap,
|
[SYS_UNMAP] = &sys_unmap,
|
||||||
[SYS_CLONE] = &sys_clone,
|
[SYS_CLONE] = &sys_clone,
|
||||||
|
[SYS_ARGUMENT_PTR] = &sys_argument_ptr,
|
||||||
[SYS_SCHED] = &sys_sched,
|
[SYS_SCHED] = &sys_sched,
|
||||||
[SYS_MUTEX_CREATE] = &sys_mutex_create,
|
[SYS_MUTEX_CREATE] = &sys_mutex_create,
|
||||||
[SYS_MUTEX_DELETE] = &sys_mutex_delete,
|
[SYS_MUTEX_DELETE] = &sys_mutex_delete,
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ void* map (uintptr_t vaddr, size_t pages, uint32_t flags) {
|
|||||||
|
|
||||||
int unmap (uintptr_t vaddr, size_t pages) { return do_syscall (SYS_UNMAP, vaddr, pages); }
|
int unmap (uintptr_t vaddr, size_t pages) { return do_syscall (SYS_UNMAP, vaddr, pages); }
|
||||||
|
|
||||||
int clone (uintptr_t vstack_top, void (*entry) (void)) {
|
int clone (uintptr_t vstack_top, void (*entry) (void), void* argument_ptr) {
|
||||||
return do_syscall (SYS_CLONE, vstack_top, entry);
|
return do_syscall (SYS_CLONE, vstack_top, entry, argument_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mutex_create (int mutex_rid) { return do_syscall (SYS_MUTEX_CREATE, mutex_rid); }
|
int mutex_create (int mutex_rid) { return do_syscall (SYS_MUTEX_CREATE, mutex_rid); }
|
||||||
@@ -32,3 +32,5 @@ int mutex_delete (int mutex_rid) { return do_syscall (SYS_MUTEX_DELETE, mutex_ri
|
|||||||
int mutex_lock (int mutex_rid) { return do_syscall (SYS_MUTEX_LOCK, mutex_rid); }
|
int mutex_lock (int mutex_rid) { return do_syscall (SYS_MUTEX_LOCK, mutex_rid); }
|
||||||
|
|
||||||
int mutex_unlock (int mutex_rid) { return do_syscall (SYS_MUTEX_UNLOCK, mutex_rid); }
|
int mutex_unlock (int mutex_rid) { return do_syscall (SYS_MUTEX_UNLOCK, mutex_rid); }
|
||||||
|
|
||||||
|
void* argument_ptr (void) { return (void*)do_syscall (SYS_ARGUMENT_PTR, 0); }
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ int test (char c);
|
|||||||
int sched (void);
|
int sched (void);
|
||||||
void* map (uintptr_t vaddr, size_t pages, uint32_t flags);
|
void* map (uintptr_t vaddr, size_t pages, uint32_t flags);
|
||||||
int unmap (uintptr_t vaddr, size_t pages);
|
int unmap (uintptr_t vaddr, size_t pages);
|
||||||
int clone (uintptr_t vstack_top, void (*entry) (void));
|
int clone (uintptr_t vstack_top, void (*entry) (void), void* argument_ptr);
|
||||||
int mutex_create (int mutex_rid);
|
int mutex_create (int mutex_rid);
|
||||||
int mutex_delete (int mutex_rid);
|
int mutex_delete (int mutex_rid);
|
||||||
int mutex_lock (int mutex_rid);
|
int mutex_lock (int mutex_rid);
|
||||||
int mutex_unlock (int mutex_rid);
|
int mutex_unlock (int mutex_rid);
|
||||||
|
void* argument_ptr (void);
|
||||||
|
|
||||||
#endif // _LIBMSL_M_SYSTEM_H
|
#endif // _LIBMSL_M_SYSTEM_H
|
||||||
|
|||||||
@@ -5,13 +5,15 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int process_spawn (process_func_t func) {
|
int process_spawn (process_func_t func, void* argument_ptr) {
|
||||||
void* stack = malloc (PROC_STACK_SIZE);
|
void* stack = malloc (PROC_STACK_SIZE);
|
||||||
if (stack == NULL)
|
if (stack == NULL)
|
||||||
return -ST_OOM_ERROR;
|
return -ST_OOM_ERROR;
|
||||||
|
|
||||||
uintptr_t top = (uintptr_t)stack + PROC_STACK_SIZE;
|
uintptr_t top = (uintptr_t)stack + PROC_STACK_SIZE;
|
||||||
return clone (top, func);
|
return clone (top, func, argument_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_quit (void) { return quit (); }
|
int process_quit (void) { return quit (); }
|
||||||
|
|
||||||
|
void* process_argument (void) { return argument_ptr (); }
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
typedef void (*process_func_t) (void);
|
typedef void (*process_func_t) (void);
|
||||||
|
|
||||||
int process_spawn (process_func_t func);
|
int process_spawn (process_func_t func, void* argument_ptr);
|
||||||
int process_quit (void);
|
int process_quit (void);
|
||||||
|
void* process_argument (void);
|
||||||
|
|
||||||
#endif // _LIBMSL_PROC_PROC_H
|
#endif // _LIBMSL_PROC_PROC_H
|
||||||
|
|||||||
Reference in New Issue
Block a user