about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-10-05 14:14:30 -0700
committerKartik Agaram <vc@akkartik.com>2018-10-05 14:14:30 -0700
commit54ed56f2b43c1274ec569aecb9aa97fb4c293546 (patch)
treec0cdd444f806d76c03c96ab2f67fb6b318f3c402
parent15ae0717ba51649dd8042cd5ef0be3bc296b8a26 (diff)
downloadmu-54ed56f2b43c1274ec569aecb9aa97fb4c293546.tar.gz
4665
Some syscalls expect null-terminated strings while others get lengths.
Be clear about this distinction.
-rw-r--r--subx/010---vm.cc9
-rw-r--r--subx/020syscalls.cc22
2 files changed, 19 insertions, 12 deletions
diff --git a/subx/010---vm.cc b/subx/010---vm.cc
index 3cad468f..b543216f 100644
--- a/subx/010---vm.cc
+++ b/subx/010---vm.cc
@@ -218,9 +218,16 @@ inline int32_t* mem_addr_i32(uint32_t addr) {
   return reinterpret_cast<int32_t*>(mem_addr_u32(addr));
 }
 // helper for some syscalls. But read-only.
-inline const char* mem_addr_string(uint32_t addr) {
+inline const char* mem_addr_kernel_string(uint32_t addr) {
   return reinterpret_cast<const char*>(mem_addr_u8(addr));
 }
+inline string mem_addr_string(uint32_t addr, uint32_t size) {
+  ostringstream out;
+  for (int i = 0;  i < size;  ++i)
+    out << read_mem_u8(addr+i);
+  return out.str();
+}
+
 
 inline void write_mem_u8(uint32_t addr, uint8_t val) {
   uint8_t* handle = mem_addr_u8(addr);
diff --git a/subx/020syscalls.cc b/subx/020syscalls.cc
index c94785bd..d61693ca 100644
--- a/subx/020syscalls.cc
+++ b/subx/020syscalls.cc
@@ -22,14 +22,14 @@ void process_int80() {
     break;
   case 3:
     trace(91, "run") << "read: " << Reg[EBX].u << ' ' << Reg[ECX].u << ' ' << Reg[EDX].u << end();
-    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u) << end();
+    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u, Reg[EDX].u) << end();
     Reg[EAX].i = read(/*file descriptor*/Reg[EBX].u, /*memory buffer*/mem_addr_u8(Reg[ECX].u), /*size*/Reg[EDX].u);
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
     break;
   case 4:
     trace(91, "run") << "write: " << Reg[EBX].u << ' ' << Reg[ECX].u << ' ' << Reg[EDX].u << end();
-    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u) << end();
+    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u, Reg[EDX].u) << end();
     Reg[EAX].i = write(/*file descriptor*/Reg[EBX].u, /*memory buffer*/mem_addr_u8(Reg[ECX].u), /*size*/Reg[EDX].u);
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
@@ -38,8 +38,8 @@ void process_int80() {
     check_flags(ECX);
     check_mode(EDX);
     trace(91, "run") << "open: " << Reg[EBX].u << ' ' << Reg[ECX].u << end();
-    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_string(Reg[EBX].u) << end();
-    Reg[EAX].i = open(/*filename*/mem_addr_string(Reg[EBX].u), /*flags*/Reg[ECX].u, /*mode*/0640);
+    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_kernel_string(Reg[EBX].u) << end();
+    Reg[EAX].i = open(/*filename*/mem_addr_kernel_string(Reg[EBX].u), /*flags*/Reg[ECX].u, /*mode*/0640);
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
     break;
@@ -53,23 +53,23 @@ void process_int80() {
   case 8:
     check_mode(ECX);
     trace(91, "run") << "creat: " << Reg[EBX].u << end();
-    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_string(Reg[EBX].u) << end();
-    Reg[EAX].i = creat(/*filename*/mem_addr_string(Reg[EBX].u), /*mode*/0640);
+    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_kernel_string(Reg[EBX].u) << end();
+    Reg[EAX].i = creat(/*filename*/mem_addr_kernel_string(Reg[EBX].u), /*mode*/0640);
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
     break;
   case 10:
     trace(91, "run") << "unlink: " << Reg[EBX].u << end();
-    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_string(Reg[EBX].u) << end();
-    Reg[EAX].i = unlink(/*filename*/mem_addr_string(Reg[EBX].u));
+    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_kernel_string(Reg[EBX].u) << end();
+    Reg[EAX].i = unlink(/*filename*/mem_addr_kernel_string(Reg[EBX].u));
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
     break;
   case 38:
     trace(91, "run") << "rename: " << Reg[EBX].u << " -> " << Reg[ECX].u << end();
-    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_string(Reg[EBX].u) << end();
-    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_string(Reg[ECX].u) << end();
-    Reg[EAX].i = rename(/*old filename*/mem_addr_string(Reg[EBX].u), /*new filename*/mem_addr_string(Reg[ECX].u));
+    trace(91, "run") << Reg[EBX].u << " => " << mem_addr_kernel_string(Reg[EBX].u) << end();
+    trace(91, "run") << Reg[ECX].u << " => " << mem_addr_kernel_string(Reg[ECX].u) << end();
+    Reg[EAX].i = rename(/*old filename*/mem_addr_kernel_string(Reg[EBX].u), /*new filename*/mem_addr_kernel_string(Reg[ECX].u));
     trace(91, "run") << "result: " << Reg[EAX].i << end();
     if (Reg[EAX].i == -1) raise << strerror(errno) << '\n' << end();
     break;