caller.py: don't try to make zero-sized memory accesses, they error
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 6 Dec 2023 09:07:42 +0000 (01:07 -0800)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 6 Dec 2023 09:07:42 +0000 (01:07 -0800)
src/openpower/decoder/isa/caller.py

index 556c9b1085a2d5c9793d927a5bd160d95d37a7e8..44b0fd06731807e17b784f737d6ee4570ff4ad05 100644 (file)
@@ -1171,7 +1171,10 @@ class SyscallEmulator(openpower.syscalls.Dispatcher):
         raise ExitSyscallCalled(status)
 
     def sys_write(self, fd, buf, count, *rest):
-        buf = self.__isacaller.mem.get_ctypes(buf, count, is_write=False)
+        if count != 0:
+            buf = self.__isacaller.mem.get_ctypes(buf, count, is_write=False)
+        else:
+            buf = b""
         try:
             return os.write(fd, buf)
         except OSError as e:
@@ -1201,7 +1204,10 @@ class SyscallEmulator(openpower.syscalls.Dispatcher):
             return -e.errno
 
     def sys_read(self, fd, buf, count, *rest):
-        buf = self.__isacaller.mem.get_ctypes(buf, count, is_write=True)
+        if count != 0:
+            buf = self.__isacaller.mem.get_ctypes(buf, count, is_write=True)
+        else:
+            buf = bytearray()
         try:
             return os.readv(fd, [buf])
         except OSError as e:
@@ -1281,7 +1287,11 @@ class SyscallEmulator(openpower.syscalls.Dispatcher):
     def sys_readlinkat(self, dirfd, pathname, buf, bufsiz, *rest):
         try:
             path = self.__isacaller.mem.read_cstr(pathname)
-            buf = self.__isacaller.mem.get_ctypes(buf, bufsiz, is_write=True)
+            if bufsiz != 0:
+                buf = self.__isacaller.mem.get_ctypes(
+                    buf, bufsiz, is_write=True)
+            else:
+                buf = bytearray()
         except (ValueError, MemException):
             return -errno.EFAULT
         try: