feature (syscalls): changed 'nx_fread' and 'nx_fwrite' to match updated sysabi

This commit is contained in:
antifallobst 2023-05-02 18:07:31 +02:00
parent 406dc0ee9e
commit 23af4ccdab
1 changed files with 5 additions and 18 deletions

View File

@ -44,28 +44,23 @@ void syscall_handle_nx_fread(cpu_state_T* state) {
case FILE_DESCRIPTOR_INVALID:
case FILE_DESCRIPTOR_STDOUT:
case FILE_DESCRIPTOR_STDERR: {
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
break;
}
case FILE_DESCRIPTOR_STDIN: {
read_bytes = pipe_read(&process->stdin, mem, n);
state->rax = STATUS_SUCCESS;
break;
}
default: {
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
// TODO: set read_bytes
vfs_file_read(node, offset, n, mem);
state->rax = STATUS_SUCCESS;
read_bytes = vfs_file_read(node, offset, n, mem);
break;
}
}
// TODO: return read_bytes to process
state->rax = read_bytes;
}
void syscall_handle_nx_fwrite(cpu_state_T* state) {
@ -80,7 +75,6 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
switch (fd) {
case FILE_DESCRIPTOR_INVALID:
case FILE_DESCRIPTOR_STDIN: {
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
break;
}
@ -88,8 +82,6 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
if (process->stderr != NULL) {
written_bytes = pipe_write(process->stderr, mem, n);
}
state->rax = STATUS_SUCCESS;
break;
}
@ -97,23 +89,18 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
if (process->stdout != NULL) {
written_bytes = pipe_write(process->stdout, mem, n);
}
state->rax = STATUS_SUCCESS;
break;
}
default: {
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
// TODO: set written_bytes
vfs_file_write(node, offset, n, mem);
state->rax = STATUS_SUCCESS;
written_bytes = vfs_file_write(node, offset, n, mem);
break;
}
}
// TODO: return written_bytes to process
state->rax = written_bytes;
}
void syscall_handle_nx_fdelete(cpu_state_T* state) {