aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/src/arch/aarch64/lib.h
blob: 41bcfc957d13c183bf9797e8aa61bd8f22f7ed1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: MIT */

#ifndef LIBURING_ARCH_AARCH64_LIB_H
#define LIBURING_ARCH_AARCH64_LIB_H

#include <elf.h>
#include "../../syscall.h"

static inline long __get_page_size(void)
{
	Elf64_Off buf[2];
	long ret = 4096;
	int fd;

	fd = __sys_open("/proc/self/auxv", O_RDONLY, 0);
	if (fd < 0)
		return ret;

	while (1) {
		ssize_t x;

		x = __sys_read(fd, buf, sizeof(buf));
		if (x < (long) sizeof(buf))
			break;

		if (buf[0] == AT_PAGESZ) {
			ret = buf[1];
			break;
		}
	}

	__sys_close(fd);
	return ret;
}

static inline long get_page_size(void)
{
	static long cache_val;

	if (cache_val)
		return cache_val;

	cache_val = __get_page_size();
	return cache_val;
}

#endif /* #ifndef LIBURING_ARCH_AARCH64_LIB_H */