Merge "16k: Fix sysconf_SC_ARG_MAX test to support 16k page sizes" into main

This commit is contained in:
Juan Yescas 2023-12-08 21:01:54 +00:00 committed by Gerrit Code Review
commit 717debf261

View file

@ -1127,8 +1127,8 @@ TEST(UNISTD_TEST, sysconf_SC_NPROCESSORS_ONLN) {
TEST(UNISTD_TEST, sysconf_SC_ARG_MAX) {
// Since Linux 2.6.23, ARG_MAX isn't a constant and depends on RLIMIT_STACK.
// See prepare_arg_pages() in the kernel for the gory details:
// https://elixir.bootlin.com/linux/v5.3.11/source/fs/exec.c#L451
// See setup_arg_pages() in the kernel for the gory details:
// https://elixir.bootlin.com/linux/v6.6.4/source/fs/exec.c#L749
// Get our current limit, and set things up so we restore the limit.
rlimit rl;
@ -1145,19 +1145,24 @@ TEST(UNISTD_TEST, sysconf_SC_ARG_MAX) {
// _SC_ARG_MAX should be 1/4 the stack size.
EXPECT_EQ(static_cast<long>(rl.rlim_cur / 4), sysconf(_SC_ARG_MAX));
// If you have a really small stack, the kernel still guarantees "32 pages" (see fs/exec.c).
// If you have a really small stack, the kernel still guarantees a stack
// expansion of 128KiB (see setup_arg_pages() in fs/exec.c).
rl.rlim_cur = 1024;
rl.rlim_max = RLIM_INFINITY;
ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
EXPECT_EQ(static_cast<long>(32 * sysconf(_SC_PAGE_SIZE)), sysconf(_SC_ARG_MAX));
// The stack expansion number is defined in fs/exec.c.
// https://elixir.bootlin.com/linux/v6.6.4/source/fs/exec.c#L845
constexpr long kernel_stack_expansion = 131072;
EXPECT_EQ(kernel_stack_expansion, sysconf(_SC_ARG_MAX));
// With a 128-page stack limit, we know exactly what _SC_ARG_MAX should be...
rl.rlim_cur = 128 * sysconf(_SC_PAGE_SIZE);
// If you have a large stack, the kernel will keep the stack
// expansion to 128KiB (see setup_arg_pages() in fs/exec.c).
rl.rlim_cur = 524288;
rl.rlim_max = RLIM_INFINITY;
ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl));
EXPECT_EQ(static_cast<long>((128 * sysconf(_SC_PAGE_SIZE)) / 4), sysconf(_SC_ARG_MAX));
EXPECT_EQ(kernel_stack_expansion, sysconf(_SC_ARG_MAX));
}
TEST(UNISTD_TEST, sysconf_unknown) {