Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47 lines
814 B
C
47 lines
814 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#define _GNU_SOURCE
|
|
#define __EXPORTED_HEADERS__
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/memfd.h>
|
|
#include <unistd.h>
|
|
#include <sys/syscall.h>
|
|
|
|
#include "common.h"
|
|
|
|
int hugetlbfs_test = 0;
|
|
|
|
/*
|
|
* Copied from mlock2-tests.c
|
|
*/
|
|
unsigned long default_huge_page_size(void)
|
|
{
|
|
unsigned long hps = 0;
|
|
char *line = NULL;
|
|
size_t linelen = 0;
|
|
FILE *f = fopen("/proc/meminfo", "r");
|
|
|
|
if (!f)
|
|
return 0;
|
|
while (getline(&line, &linelen, f) > 0) {
|
|
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
|
|
hps <<= 10;
|
|
break;
|
|
}
|
|
}
|
|
|
|
free(line);
|
|
fclose(f);
|
|
return hps;
|
|
}
|
|
|
|
int sys_memfd_create(const char *name, unsigned int flags)
|
|
{
|
|
if (hugetlbfs_test)
|
|
flags |= MFD_HUGETLB;
|
|
|
|
return syscall(__NR_memfd_create, name, flags);
|
|
}
|