[PATCH liburing v4 03/10] arch: syscall: Add `__sys_read()` syscall

Ammar Faizi
2022-07-04T19:32:30Z

A prep patch to support aarch64 nolibc. We will use this to get the
page size by reading /proc/self/auxv.

v2:
- Fix return type, __sys_read() returns ssize_t, not int.

Reviewed-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
src/arch/generic/syscall.h | 7 +++++++
src/arch/syscall-defs.h | 5 +++++
2 files changed, 12 insertions(+)

diff --git a/src/arch/generic/syscall.h b/src/arch/generic/syscall.h
index 71b2234..22252a1 100644
--- a/src/arch/generic/syscall.h
+++ b/src/arch/generic/syscall.h
@@ -50,6 +50,13 @@ static inline int __sys_open(const char *pathname, int flags, mode_t mode)
return (ret < 0) ? -errno : ret;
}

+static inline ssize_t __sys_read(int fd, void *buffer, size_t size)
+{
+ ssize_t ret;
+ ret = read(fd, buffer, size);
+ return (ret < 0) ? -errno : ret;
+}
+
static inline void *__sys_mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
diff --git a/src/arch/syscall-defs.h b/src/arch/syscall-defs.h
index 9d4424d..bde69fa 100644
--- a/src/arch/syscall-defs.h
+++ b/src/arch/syscall-defs.h
@@ -17,6 +17,11 @@ static inline int __sys_open(const char *pathname, int flags, mode_t mode)
#endif
}

+static inline ssize_t __sys_read(int fd, void *buffer, size_t size)
+{
+ return (ssize_t) __do_syscall3(__NR_read, fd, buffer, size);
+}
+
static inline void *__sys_mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
--
Ammar Faizi