lab 2 (probably working)

This commit is contained in:
2020-05-25 18:00:42 +02:00
parent df7631de81
commit 404ae75cfa
6 changed files with 201 additions and 14 deletions

View 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;
}

View 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");
}