From 4931a5cca602662dfde12e7a6e4f830450b34125 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 6 Dec 2023 01:07:42 -0800 Subject: [PATCH] caller.py: don't try to make zero-sized memory accesses, they error --- src/openpower/decoder/isa/caller.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/openpower/decoder/isa/caller.py b/src/openpower/decoder/isa/caller.py index e14fa843..53427313 100644 --- a/src/openpower/decoder/isa/caller.py +++ b/src/openpower/decoder/isa/caller.py @@ -1180,7 +1180,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: @@ -1210,7 +1213,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: @@ -1290,7 +1296,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: -- 2.30.2