[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <d1d2eabc49e9c8790470010d161ff297c172096c.1684425792.git.falcon@tinylab.org>
Date: Fri, 19 May 2023 01:03:50 +0800
From: Zhangjin Wu <falcon@...ylab.org>
To: Willy Tarreau <w@....eu>, Palmer Dabbelt <palmer@...osinc.com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Albert Ou <aou@...s.berkeley.edu>
Cc: "Paul E . McKenney" <paulmck@...nel.org>,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
Zhangjin Wu <falcon@...ylab.org>
Subject: [PATCH 2/2] tools/nolibc: riscv: Support __NR_llseek for rv32
There is no __NR_lseek for rv32, use __NR_llseek instead.
This code is based on sysdeps/unix/sysv/linux/lseek.c of glibc.
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
---
tools/include/nolibc/std.h | 1 +
tools/include/nolibc/sys.h | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/tools/include/nolibc/std.h b/tools/include/nolibc/std.h
index 933bc0be7e1c..83c0b0cb9564 100644
--- a/tools/include/nolibc/std.h
+++ b/tools/include/nolibc/std.h
@@ -32,5 +32,6 @@ typedef signed long off_t;
typedef signed long blksize_t;
typedef signed long blkcnt_t;
typedef signed long time_t;
+typedef long long loff_t;
#endif /* _NOLIBC_STD_H */
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 5d624dc63a42..ab32f3c0a460 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -668,7 +668,26 @@ int link(const char *old, const char *new)
static __attribute__((unused))
off_t sys_lseek(int fd, off_t offset, int whence)
{
+#ifdef __NR_lseek
return my_syscall3(__NR_lseek, fd, offset, whence);
+#elif defined(__NR_llseek)
+ loff_t res;
+ off_t retval;
+
+ int rc = my_syscall5(__NR_llseek, fd, (long) (((uint64_t) (offset)) >> 32), (long) offset, &res, whence);
+
+ if (rc)
+ return rc;
+
+ retval = (off_t) res;
+ if (retval == res)
+ return retval;
+
+ SET_ERRNO(EOVERFLOW);
+ return (off_t) -1;
+#else
+#error Neither __NR_lseek nor __NR_llseek defined, cannot implement sys_lseek()
+#endif
}
static __attribute__((unused))
--
2.25.1
Powered by blists - more mailing lists