[PATCH liburing v1 7/9] arch/arm64: Add `get_page_size()` function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>

This is a preparation patch to add aarch64 nolibc support.

aarch64 supports three values of page size: 4K, 16K, and 64K which are
selected at kernel compilation time. Therefore, we can't hard code the
page size for this arch. Utilize open(), read() and close() syscall to
find the page size from /proc/self/auxv. For more details about the
auxv data structure, check the link below.

Link: https://github.com/torvalds/linux/blob/v5.19-rc4/fs/binfmt_elf.c#L260
Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>
---
 src/arch/arm64/lib.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/arch/arm64/lib.h

diff --git a/src/arch/arm64/lib.h b/src/arch/arm64/lib.h
new file mode 100644
index 0000000..4dc39a8
--- /dev/null
+++ b/src/arch/arm64/lib.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: MIT */
+
+#ifndef LIBURING_ARCH_ARM64_LIB_H
+#define LIBURING_ARCH_ARM64_LIB_H
+
+#include <elf.h>
+#include <sys/auxv.h>
+#include "../../syscall.h"
+
+static inline long get_page_size(void)
+{
+	Elf64_Off buf[2];
+	long page_size;
+	int fd;
+
+	fd = __sys_open("/proc/self/auxv", O_RDONLY, 0);
+	if (fd < 0)
+		return fd;
+
+	while (1) {
+		ssize_t ret;
+
+		ret = __sys_read(fd, buf, sizeof(buf));
+		if (ret < 0) {
+			page_size = -errno;
+			break;
+		}
+
+		if (ret < sizeof(buf)) {
+			page_size = -ENOENT;
+			break;
+		}
+
+		if (buf[0] == AT_PAGESZ) {
+			page_size = buf[1];
+			break;
+		}
+	}
+
+	__sys_close(fd);
+	return page_size;
+}
+
+#endif /* #ifndef LIBURING_ARCH_ARM64_LIB_H */
-- 
Ammar Faizi




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux