diff options
| author | Dmitry Torokhov <[email protected]> | 2023-05-01 15:20:08 -0700 | 
|---|---|---|
| committer | Dmitry Torokhov <[email protected]> | 2023-05-01 15:20:08 -0700 | 
| commit | 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e (patch) | |
| tree | d57f3a63479a07b4e0cece029886e76e04feb984 /tools/testing/selftests/mm/on-fault-limit.c | |
| parent | 5dc63e56a9cf8df0b59c234a505a1653f1bdf885 (diff) | |
| parent | 53bea86b5712c7491bb3dae12e271666df0a308c (diff) | |
Merge branch 'next' into for-linus
Prepare input updates for 6.4 merge window.
Diffstat (limited to 'tools/testing/selftests/mm/on-fault-limit.c')
| -rw-r--r-- | tools/testing/selftests/mm/on-fault-limit.c | 48 | 
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/testing/selftests/mm/on-fault-limit.c b/tools/testing/selftests/mm/on-fault-limit.c new file mode 100644 index 000000000000..634d87dfb2a4 --- /dev/null +++ b/tools/testing/selftests/mm/on-fault-limit.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <sys/mman.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <sys/time.h> +#include <sys/resource.h> + +#ifndef MCL_ONFAULT +#define MCL_ONFAULT (MCL_FUTURE << 1) +#endif + +static int test_limit(void) +{ +	int ret = 1; +	struct rlimit lims; +	void *map; + +	if (getrlimit(RLIMIT_MEMLOCK, &lims)) { +		perror("getrlimit"); +		return ret; +	} + +	if (mlockall(MCL_ONFAULT | MCL_FUTURE)) { +		perror("mlockall"); +		return ret; +	} + +	map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE, +		   MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); +	if (map != MAP_FAILED) +		printf("mmap should have failed, but didn't\n"); +	else { +		ret = 0; +		munmap(map, 2 * lims.rlim_max); +	} + +	munlockall(); +	return ret; +} + +int main(int argc, char **argv) +{ +	int ret = 0; + +	ret += test_limit(); +	return ret; +}  |