diff options
author | Juan Yescas <jyescas@google.com> | 2023-12-08 21:01:54 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-12-08 21:01:54 +0000 |
commit | 717debf261c56ada8b7a40d623bf3558ce6aef01 (patch) | |
tree | c16fdb514b1375e059c99eb66ade68d5ee24229a | |
parent | 4fa435479967313de306f176897bf501ff6b5dde (diff) | |
parent | 2da31cf7b0c6071f83244eb0c89f95395a48cb37 (diff) | |
download | bionic-717debf261c56ada8b7a40d623bf3558ce6aef01.tar.gz |
Merge "16k: Fix sysconf_SC_ARG_MAX test to support 16k page sizes" into main
-rw-r--r-- | tests/unistd_test.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 6a94507fa..e9a30809f 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -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) { |