Implement streams IPC mechanism
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m47s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m47s
This commit is contained in:
@@ -1033,6 +1033,70 @@ DEFINE_SYSCALL (sys_get_self_pid) {
|
||||
return SYSRESULT (pid);
|
||||
}
|
||||
|
||||
/* int stream_write (int pgid, int rid, void* buffer, size_t size) */
|
||||
DEFINE_SYSCALL (sys_stream_write) {
|
||||
uint64_t fp;
|
||||
|
||||
int pgid = (int)a1;
|
||||
int rid = (int)a2;
|
||||
uintptr_t uvaddr_buffer = a3;
|
||||
size_t buffer_size = (size_t)a4;
|
||||
|
||||
struct procgroup* target_procgroup = procgroup_find (pgid);
|
||||
|
||||
if (target_procgroup == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
void* buffer = sys_get_user_buffer (procgroup, uvaddr_buffer, buffer_size);
|
||||
|
||||
if (buffer == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct proc_resource* stream_resource = proc_find_resource (target_procgroup, rid);
|
||||
|
||||
if (stream_resource == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
proc_stream_write (proc, &stream_resource->u.stream, rctx, buffer, buffer_size);
|
||||
|
||||
return SYSRESULT (ST_OK);
|
||||
}
|
||||
|
||||
/* int stream_read (int pgid, int rid, void* buffer, size_t size) */
|
||||
DEFINE_SYSCALL (sys_stream_read) {
|
||||
uint64_t fp;
|
||||
|
||||
int pgid = (int)a1;
|
||||
int rid = (int)a2;
|
||||
uintptr_t uvaddr_buffer = a3;
|
||||
size_t buffer_size = (size_t)a4;
|
||||
|
||||
struct procgroup* target_procgroup = procgroup_find (pgid);
|
||||
|
||||
if (target_procgroup == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&proc->lock, &fp);
|
||||
struct procgroup* procgroup = proc->procgroup;
|
||||
spin_unlock (&proc->lock, fp);
|
||||
|
||||
void* buffer = sys_get_user_buffer (procgroup, uvaddr_buffer, buffer_size);
|
||||
|
||||
if (buffer == NULL)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
struct proc_resource* stream_resource = proc_find_resource (target_procgroup, rid);
|
||||
|
||||
if (stream_resource == NULL)
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
return SYSRESULT (proc_stream_read (proc, &stream_resource->u.stream, rctx, buffer, buffer_size));
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_QUIT] = &sys_quit,
|
||||
[SYS_TEST] = &sys_test,
|
||||
@@ -1069,6 +1133,8 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_EXEC_PARTIAL_FINI] = &sys_exec_partial_fini,
|
||||
[SYS_MAIL_RECEIVE_NONBLOCK] = &sys_mail_receive_nonblock,
|
||||
[SYS_GET_SELF_PID] = &sys_get_self_pid,
|
||||
[SYS_STREAM_WRITE] = &sys_stream_write,
|
||||
[SYS_STREAM_READ] = &sys_stream_read,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
Reference in New Issue
Block a user