Message ID | 20220629002028.1232579-8-ammar.faizi@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | aarch64 nolibc support | expand |
On 6/29/22 7:27 AM, Ammar Faizi wrote: > + while (1) { > + ssize_t ret; > + > + ret = __sys_read(fd, buf, sizeof(buf)); > + if (ret < 0) { > + page_size = -errno; > + break; > + } Oops, this is wrong, I shouldn't use errno here, it should be: page_size = ret; Should I resend? Or you can fix it?
On 6/28/22 6:27 PM, Ammar Faizi wrote: > From: Ammar Faizi <ammarfaizi2@gnuweeb.org> > > 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. We should probably cache this value if already read? At least I don't think we have systems where the page size would differ between applications.
On 6/29/22 9:49 PM, Jens Axboe wrote: > On 6/28/22 6:27 PM, Ammar Faizi wrote: >> From: Ammar Faizi <ammarfaizi2@gnuweeb.org> >> >> 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. > > We should probably cache this value if already read? At least I don't > think we have systems where the page size would differ between > applications. Good idea, will use a static variable to cache it in v2 then...
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 */