Message passing / mail system
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m20s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m20s
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <m/status.h>
|
||||
#include <m/syscall_defs.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/mail.h>
|
||||
#include <proc/mutex.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/procgroup.h>
|
||||
@@ -171,6 +172,58 @@ DEFINE_SYSCALL (sys_mutex_unlock) {
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int mail_send (int pgid, void* mesg, size_t mesg_size) */
|
||||
DEFINE_SYSCALL (sys_mail_send) {
|
||||
int pgid = (int)a1;
|
||||
uintptr_t uvaddr_mesg = a2;
|
||||
size_t mesg_size = (size_t)a3;
|
||||
|
||||
void* mesg = sys_get_user_buffer (proc, uvaddr_mesg, mesg_size);
|
||||
|
||||
if (mesg == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct procgroup* procgroup = procgroup_find (pgid);
|
||||
|
||||
if (procgroup == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
struct proc_resource* mail_resource = proc_find_resource (procgroup, 1);
|
||||
|
||||
if (mail_resource == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
if (proc_mail_send (proc, &mail_resource->u.mail, reschedule_cpu, mesg, mesg_size) ==
|
||||
PROC_NEED_RESCHEDULE) {
|
||||
*reschedule = true;
|
||||
}
|
||||
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int mail_receive (void* recv_mesg, size_t mesg_size) */
|
||||
DEFINE_SYSCALL (sys_mail_receive) {
|
||||
uintptr_t uvaddr_mesg = a1;
|
||||
size_t mesg_size = (size_t)a2;
|
||||
|
||||
void* mesg = sys_get_user_buffer (proc, uvaddr_mesg, mesg_size);
|
||||
|
||||
if (mesg == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct proc_resource* mail_resource = proc_find_resource (proc->procgroup, 1);
|
||||
|
||||
if (mail_resource == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
if (proc_mail_receive (proc, &mail_resource->u.mail, reschedule_cpu, mesg, mesg_size) ==
|
||||
PROC_NEED_RESCHEDULE) {
|
||||
*reschedule = true;
|
||||
}
|
||||
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4) */
|
||||
DEFINE_SYSCALL (sys_device_do) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
@@ -255,6 +308,7 @@ DEFINE_SYSCALL (sys_exec) {
|
||||
return SYSRESULT (-ST_EXEC_ERROR);
|
||||
|
||||
int pid = new->pid;
|
||||
new->exec_pid = proc->pid;
|
||||
|
||||
if (proc_register (new, reschedule_cpu) == PROC_NEED_RESCHEDULE)
|
||||
*reschedule = true;
|
||||
@@ -381,6 +435,18 @@ DEFINE_SYSCALL (sys_describe) {
|
||||
return SYSRESULT (vfs_describe (proc->procgroup, mountpoint, subpath, desc));
|
||||
}
|
||||
|
||||
/* int get_procgroup (int pid) */
|
||||
DEFINE_SYSCALL (sys_get_procgroup) {
|
||||
int pid = (int)a1;
|
||||
|
||||
struct proc* target_proc = proc_find_pid (pid);
|
||||
|
||||
return SYSRESULT (target_proc->procgroup->pgid);
|
||||
}
|
||||
|
||||
/* int get_exec_pid (void) */
|
||||
DEFINE_SYSCALL (sys_get_exec_pid) { return SYSRESULT (proc->exec_pid); }
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_QUIT] = &sys_quit,
|
||||
[SYS_TEST] = &sys_test,
|
||||
@@ -399,6 +465,10 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_CLOSE] = &sys_close,
|
||||
[SYS_READ] = &sys_read,
|
||||
[SYS_DESCRIBE] = &sys_describe,
|
||||
[SYS_MAIL_SEND] = &sys_mail_send,
|
||||
[SYS_MAIL_RECEIVE] = &sys_mail_receive,
|
||||
[SYS_GET_PROCGROUP] = &sys_get_procgroup,
|
||||
[SYS_GET_EXEC_PID] = &sys_get_exec_pid,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user