summaryrefslogtreecommitdiff
path: root/src/sys/compat
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/compat')
-rw-r--r--src/sys/compat/unix/os/os_filedesc.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/sys/compat/unix/os/os_filedesc.c b/src/sys/compat/unix/os/os_filedesc.c
index 48ea6be..673701f 100644
--- a/src/sys/compat/unix/os/os_filedesc.c
+++ b/src/sys/compat/unix/os/os_filedesc.c
@@ -33,6 +33,7 @@
#include <sys/mount.h>
#include <sys/errno.h>
#include <sys/types.h>
+#include <os/kalloc.h>
#include <os/systm.h>
#include <os/filedesc.h>
#include <compat/unix/syscall.h>
@@ -105,3 +106,35 @@ sys_mount(struct syscall_args *scargs)
args.fstype = fstype;
return kmount(&args, u_mountflags);
}
+
+/*
+ * ARG0: fd
+ * ARG1: buf[]
+ * ARG2: count
+ */
+scret_t
+sys_read(struct syscall_args *scargs)
+{
+ int fd = SCARG(scargs, int, 0);
+ char *u_buf = SCARG(scargs, char *, 1);
+ size_t count = SCARG(scargs, size_t, 2);
+ char *kbuf;
+ ssize_t retval;
+ int error;
+
+ /* Do we have enough memory to fulfill this */
+ kbuf = kalloc(count);
+ if (kbuf == NULL) {
+ return -ENOMEM;
+ }
+
+ retval = read(fd, kbuf, count);
+ if (retval < 0) {
+ kfree(kbuf);
+ return retval;
+ }
+
+ error = copyout(kbuf, u_buf, count);
+ kfree(kbuf);
+ return (error == 0) ? retval : error;
+}