syscall_emul: implement fallocate
authorBrandon Potter <brandon.potter@amd.com>
Thu, 15 Dec 2016 18:16:25 +0000 (13:16 -0500)
committerBrandon Potter <brandon.potter@amd.com>
Thu, 15 Dec 2016 18:16:25 +0000 (13:16 -0500)
src/arch/x86/linux/process.cc
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index e5db3cb49705d9f5f2df4db069e515e6ad63b877..8eb064ae45bf1c7b2b275a7d62b1b16334097bfe 100644 (file)
@@ -503,7 +503,7 @@ static SyscallDesc syscallDescs64[] = {
     /* 282 */ SyscallDesc("signalfd", unimplementedFunc),
     /* 283 */ SyscallDesc("timerfd_create", unimplementedFunc),
     /* 284 */ SyscallDesc("eventfd", unimplementedFunc),
-    /* 285 */ SyscallDesc("fallocate", unimplementedFunc),
+    /* 285 */ SyscallDesc("fallocate", fallocateFunc),
     /* 286 */ SyscallDesc("timerfd_settime", unimplementedFunc),
     /* 287 */ SyscallDesc("timerfd_gettime", unimplementedFunc),
     /* 288 */ SyscallDesc("accept4", unimplementedFunc),
index e62a8686ae0d61982a593be208ab4dddf47cb745..9c3f50bb3ea8049285bf91ee269b65748d1fde7b 100644 (file)
@@ -934,6 +934,27 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
     }
 }
 
+SyscallReturn
+fallocateFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+              ThreadContext *tc)
+{
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
+    int mode = process->getSyscallArg(tc, index);
+    off_t offset = process->getSyscallArg(tc, index);
+    off_t len = process->getSyscallArg(tc, index);
+
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
+
+    int result = fallocate(sim_fd, mode, offset, len);
+    if (result < 0)
+        return -errno;
+
+    return 0;
+}
+
 SyscallReturn
 accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc,
         int index)
index bf7ec1ae774f6125c84d39466a7b4f5d73f224ac..a3ac9ed3f3683d3b7fad54281a2dbabe841c4130 100644 (file)
@@ -157,6 +157,10 @@ SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
                          LiveProcess *p, ThreadContext *tc);
 
+// Target fallocateFunc() handler.
+SyscallReturn fallocateFunc(SyscallDesc *desc, int num,
+                            LiveProcess *p, ThreadContext *tc);
+
 /// Target exit() handler: terminate current context.
 SyscallReturn exitFunc(SyscallDesc *desc, int num,
                        LiveProcess *p, ThreadContext *tc);