Implement the _llseek syscall. It's Linux only, so we'll actually use the lseek syscall.
authorGabe Black <gblack@eecs.umich.edu>
Sat, 3 Mar 2007 03:34:55 +0000 (03:34 +0000)
committerGabe Black <gblack@eecs.umich.edu>
Sat, 3 Mar 2007 03:34:55 +0000 (03:34 +0000)
--HG--
extra : convert_revision : cccfd5efddbba527c6fb4e07ad2ab235a2670918

src/arch/sparc/linux/process.cc
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index 9c7c0e643f18dcdaea61ddf20a7fcf1b0a0d6e98..10cde3af84a3f2faac7e667c25fb6681304b3cb6 100644 (file)
@@ -333,7 +333,7 @@ SyscallDesc SparcLinuxProcess::syscallDescs[] = {
     /* 233 */ SyscallDesc("stime", unimplementedFunc),
     /* 234 */ SyscallDesc("statfs64", unimplementedFunc),
     /* 235 */ SyscallDesc("fstatfs64", unimplementedFunc),
-    /* 236 */ SyscallDesc("_llseek", unimplementedFunc),
+    /* 236 */ SyscallDesc("_llseek", _llseekFunc),
     /* 237 */ SyscallDesc("mlock", unimplementedFunc),
     /* 238 */ SyscallDesc("munlock", unimplementedFunc),
     /* 239 */ SyscallDesc("mlockall", unimplementedFunc),
index ab44c0a35f8efb998e5a17fa0fba423fd1afc69b..876f39e9917575f5ac1da5653d06b96fc3f01472 100644 (file)
@@ -183,6 +183,39 @@ lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 }
 
 
+SyscallReturn
+_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+{
+    int fd = p->sim_fd(tc->getSyscallArg(0));
+    uint64_t offset_high = tc->getSyscallArg(1);
+    uint32_t offset_low = tc->getSyscallArg(2);
+    Addr result_ptr = tc->getSyscallArg(3);
+    int whence = tc->getSyscallArg(4);
+
+    uint64_t offset = (offset_high << 32) | offset_low;
+
+    uint64_t result = lseek(fd, offset, whence);
+    result = TheISA::htog(result);
+
+    if (result == (off_t)-1) {
+        //The seek failed.
+        return -errno;
+    } else {
+        //The seek succeeded.
+        //Copy "result" to "result_ptr"
+        //XXX We'll assume that the size of loff_t is 64 bits on the
+        //target platform
+        BufferArg result_buf(result_ptr, sizeof(result));
+        memcpy(result_buf.bufferPtr(), &result, sizeof(result));
+        result_buf.copyOut(tc->getMemPort());
+        return 0;
+    }
+
+
+    return (result == (off_t)-1) ? -errno : result;
+}
+
+
 SyscallReturn
 munmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
index f57bd52729bf3ec83187f7d3bd92e686e3c2f26e..5ca2f6be5f641e6806686df2a7a70bff287a261f 100644 (file)
@@ -211,6 +211,10 @@ SyscallReturn writeFunc(SyscallDesc *desc, int num,
 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
                         LiveProcess *p, ThreadContext *tc);
 
+/// Target _llseek() handler.
+SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
+                        LiveProcess *p, ThreadContext *tc);
+
 /// Target munmap() handler.
 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
                          LiveProcess *p, ThreadContext *tc);