Commit Diff


commit - 21ec87349ebe2d4f71bf60a93be60c30ef49b804
commit + 5218bf96a9cf008e4683c68ae848419336f16817
blob - 2bda756a811c891b361ee1d635509cffe283eb18
blob + b8c6268487b71259fffcf9e84908d2b29bb95551
--- src/ecall.c
+++ src/ecall.c
@@ -164,9 +164,65 @@ static u64 my_brk (u64 new)
 	return brkval;
 }
 
+#define LO_ACCMODE	00000003
+#define LO_RDONLY	00000000
+#define LO_WRONLY 	00000001
+#define LO_RDWR		00000002
+#define LO_CREAT	00000100
+#define LO_EXCL		00000200
+#define LO_TRUNC	00001000
+#define LO_APPEND	00002000
+#define LO_NONBLOCK	00004000
+#define LO_DSYNC	00010000
+#define LO_DIRECTORY	00200000
+#define LO_NOFOLLOW	00400000
+#define LO_CLOEXEC	02000000
+
 static int open_flags (int x)
 {
-	int o = O_RDONLY;
+	int o;
+
+	switch (x & LO_ACCMODE) {
+	case LO_RDONLY:
+		o = O_RDONLY;
+		break;
+	case LO_WRONLY:
+		o = O_WRONLY;
+		break;
+	case LO_RDWR:
+		o = O_RDWR;
+		break;
+	default:
+		abort ();
+	}
+
+	if (x & LO_CREAT)
+		o |= O_CREAT;
+
+	if (x & LO_EXCL)
+		o |= O_EXCL;
+
+	if (x & LO_TRUNC)
+		o |= O_TRUNC;
+
+	if (x & LO_APPEND)
+		o |= O_APPEND;
+
+	if (x & LO_NONBLOCK)
+		o |= O_NONBLOCK;
+
+	if (x & LO_DSYNC)
+		o |= O_SYNC;
+
+	if (x & LO_DIRECTORY)
+		o |= O_DIRECTORY;
+
+	if (x & LO_NOFOLLOW)
+		o |= O_NOFOLLOW;
+
+	if (x & LO_CLOEXEC)
+		o |= O_CLOEXEC;
+
 	eprintf ("open_flags(%d) = %d\n", x, o);
 	return o;
 }
@@ -802,7 +858,7 @@ void ecall (void)
 		tmp2 = mmap_prot ((int)a2);
 		eprintf ("mmap (%p, %zu, %d, %d, %d, %lld);\n", ptr (void, a0), (size_t)a1, tmp2, tmp, (int)a4, (off_t)a5);
 		ptr = mmap (ptr (void, a0), (size_t)a1, tmp2, tmp, (int)a4, (off_t)a5);
-		printf ("ptr = %p\n", ptr);
+		eprintf ("ptr = %p", ptr);
 		if (ptr == NULL) {
 			ret = -map_errno (errno);
 		} else {