0001
0002 #define _GNU_SOURCE
0003 #define __EXPORTED_HEADERS__
0004
0005 #include <stdio.h>
0006 #include <stdlib.h>
0007 #include <linux/fcntl.h>
0008 #include <linux/memfd.h>
0009 #include <unistd.h>
0010 #include <sys/syscall.h>
0011
0012 #include "common.h"
0013
0014 int hugetlbfs_test = 0;
0015
0016
0017
0018
0019 unsigned long default_huge_page_size(void)
0020 {
0021 unsigned long hps = 0;
0022 char *line = NULL;
0023 size_t linelen = 0;
0024 FILE *f = fopen("/proc/meminfo", "r");
0025
0026 if (!f)
0027 return 0;
0028 while (getline(&line, &linelen, f) > 0) {
0029 if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
0030 hps <<= 10;
0031 break;
0032 }
0033 }
0034
0035 free(line);
0036 fclose(f);
0037 return hps;
0038 }
0039
0040 int sys_memfd_create(const char *name, unsigned int flags)
0041 {
0042 if (hugetlbfs_test)
0043 flags |= MFD_HUGETLB;
0044
0045 return syscall(__NR_memfd_create, name, flags);
0046 }