lab 2 (probably working)
This commit is contained in:
32
kern/syscall/file_syscalls.c
Normal file
32
kern/syscall/file_syscalls.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <syscall.h>
|
||||
#include <lib.h>
|
||||
#include <kern/unistd.h>
|
||||
|
||||
size_t sys_read(int fh, userptr_t buf, size_t size) {
|
||||
int i=0;
|
||||
int * ary = (int*)buf;
|
||||
if (fh!=STDIN_FILENO) {
|
||||
kprintf("sys_read supported only to stdin\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i=0;i<(int)size;i++) {
|
||||
ary[i] = getch();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t sys_write(int fh, const userptr_t buf, size_t size) {
|
||||
int i=0;
|
||||
int * ary = (int*)buf;
|
||||
|
||||
if (fh!=STDOUT_FILENO && fh!=STDERR_FILENO) {
|
||||
kprintf("sys_write supported only to stdout\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i=0;i<(int)size;i++) {
|
||||
putch(ary[i]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
15
kern/syscall/proc_syscalls.c
Normal file
15
kern/syscall/proc_syscalls.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <syscall.h>
|
||||
#include <proc.h>
|
||||
#include <thread.h>
|
||||
#include <addrspace.h>
|
||||
|
||||
void sys__exit(int status) {
|
||||
(void)status;
|
||||
/* delete current process as */
|
||||
struct addrspace *as = proc_getas();
|
||||
as_destroy(as);
|
||||
/* exit thread */
|
||||
thread_exit();
|
||||
|
||||
panic("sys__exit end reached!!\n");
|
||||
}
|
||||
Reference in New Issue
Block a user