about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-28 22:31:52 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-28 22:31:52 -0700
commit583a966d3e0b0f0e0fa9166986c877fda0643196 (patch)
treee62b31a3ed4f615330d7bf42d83a84b54e0c315f
parent429cebf3e4c4ce5ba81443968d28b88bdfd2584e (diff)
downloadmu-583a966d3e0b0f0e0fa9166986c877fda0643196.tar.gz
6422 - size-of for handles
-rw-r--r--020syscalls.cc2
-rw-r--r--105files.subx9
-rwxr-xr-xapps/mubin256130 -> 256151 bytes
-rw-r--r--apps/mu.subx11
-rw-r--r--apps/print-file.mu8
-rw-r--r--init.linux2
6 files changed, 26 insertions, 6 deletions
diff --git a/020syscalls.cc b/020syscalls.cc
index 16495411..be075426 100644
--- a/020syscalls.cc
+++ b/020syscalls.cc
@@ -100,7 +100,7 @@ void check_flags(int reg) {
 
 void check_mode(int reg) {
   if (Reg[reg].u != 0600) {
-    cerr << HEXWORD << EIP << ": SubX is oblivious to file permissions; register " << reg << " must be 0.\n";
+    cerr << HEXWORD << EIP << ": SubX is oblivious to file permissions; register " << reg << " must be 0x180.\n";
     exit(1);
   }
 }
diff --git a/105files.subx b/105files.subx
index ae85b493..ee1a2d6b 100644
--- a/105files.subx
+++ b/105files.subx
@@ -18,19 +18,24 @@ open:  # filename: (addr array byte), write?: boolean, out: (addr handle buffere
     8b/-> *ecx 2/r32/edx
     42/increment-edx
     # var s/esi: (stream size)
-    29/subtract-from %esp 0/r32/eax
-    50/push-eax  # size
+    29/subtract-from %esp 2/r32/edx
+    52/push-edx  # size
     68/push 0/imm32/read
     68/push 0/imm32/write
     89/<- %esi 4/r32/esp
     # copy filename and a final null character
     (clear-stream %esi)
     (write %esi %ecx)
+    # spill edx
+    52/push-edx
     # var fd/ecx: fd = open(filename)
     8d/copy-address *(esi+0xc) 3/r32/ebx
     8b/-> *(ebp+0xc) 1/r32/ecx/flags
+    ba/copy-to-edx 0x180/imm32/permissions
     e8/call syscall_open/disp32
     89/<- %ecx 0/r32/eax
+    # restore edx
+    5a/pop-to-edx
     # allocate a buffered-file
     (allocate Heap 0x1010 *(ebp+0x10))  # file-buffer-size + 16 for other fields
     # var out-addr/edi: (addr buffered-file)
diff --git a/apps/mu b/apps/mu
index 5158562c..1f77f3b4 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 2e657c89..5bc534f1 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -7943,10 +7943,17 @@ size-of-type-id:  # t: type-id -> result/eax: int
     89/<- %ecx 4/r32/esp
     # eax = t
     8b/-> *(ebp+8) 0/r32/eax
-    # if v is a literal, return 0
+    # if t is a literal, return 0
     3d/compare-eax-and 0/imm32
     74/jump-if-= $size-of-type-id:end/disp8  # eax changes type from type-id to int
-    # if v has a user-defined type, return its size
+    # if t is a handle, return 8
+    3d/compare-eax-and 4/imm32/handle
+    {
+      75/jump-if-!= break/disp8
+      b8/copy-to-eax 8/imm32
+      eb/jump $size-of-type-id:end/disp8  # eax changes type from type-id to int
+    }
+    # if t is a user-defined type, return its size
     # TODO: support non-atom type
     (find-typeinfo %eax %ecx)
     {
diff --git a/apps/print-file.mu b/apps/print-file.mu
index 5010bafb..b5b5601b 100644
--- a/apps/print-file.mu
+++ b/apps/print-file.mu
@@ -14,8 +14,16 @@ $main-body: {
     {
       break-if-<=
       var filename/edx: (addr addr array byte) <- index args 1
+      var in: (handle buffered-file)
+      {
+        var addr-in/eax: (addr handle buffered-file) <- address in
+        open *filename, 0, addr-in
+      }
+      var in-addr/eax: (addr buffered-file) <- lookup in
       print-string "filename: "
       print-string *filename
+      print-string ": "
+      print-int32-to-screen in-addr
       print-string "\n"
     }
   }
diff --git a/init.linux b/init.linux
index f59cde48..497b1ea1 100644
--- a/init.linux
+++ b/init.linux
@@ -32,7 +32,7 @@ syscall_write:  # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/e
     c3/return
 
 # http://man7.org/linux/man-pages/man2/open.2.html
-syscall_open:  # filename/ebx: (addr kernel-string), flags/ecx: int -> fd-or-error/eax: int
+syscall_open:  # filename/ebx: (addr kernel-string), flags/ecx: int, dummy=0x180/edx -> fd-or-error/eax: int
     b8/copy-to-eax 5/imm32
     cd/syscall 0x80/imm8
     c3/return