diff options
author | Elliott Hughes <enh@google.com> | 2017-11-15 15:14:35 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-11-15 15:14:35 -0800 |
commit | baed51ee3a13dae4b87b11870bdf7f10bdc9efc1 (patch) | |
tree | 7c04199156be4e1e7101b2c57cd4fa558baadcda | |
parent | de5f9a1c54eebd1b66a5dfeaffbe3e703e76c86e (diff) | |
download | bionic-baed51ee3a13dae4b87b11870bdf7f10bdc9efc1.tar.gz |
Change ARG_MAX/_SC_ARG_MAX back to a constant.
As per the lkml thread https://lkml.org/lkml/2017/11/1/946.
Bug: http://b/65818597
Test: ran tests
Change-Id: I7a0610e6903e6761f2b31416e2f5017bd7a60659
-rw-r--r-- | libc/bionic/sysconf.cpp | 13 | ||||
-rw-r--r-- | libc/kernel/tools/defaults.py | 2 | ||||
-rw-r--r-- | libc/kernel/uapi/linux/limits.h | 2 | ||||
-rw-r--r-- | libc/upstream-freebsd/android/include/freebsd-compat.h | 2 | ||||
-rw-r--r-- | tests/unistd_test.cpp | 35 |
5 files changed, 16 insertions, 38 deletions
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp index d45cb3874..2442fd9a7 100644 --- a/libc/bionic/sysconf.cpp +++ b/libc/bionic/sysconf.cpp @@ -52,9 +52,16 @@ long sysconf(int name) { // Things we actually have to calculate... // case _SC_ARG_MAX: - // Not a constant since Linux 2.6.23; see fs/exec.c for details. - // At least 32 pages, otherwise a quarter of the stack limit. - return MAX(__sysconf_rlimit(RLIMIT_STACK) / 4, _KERNEL_ARG_MAX); + // https://lkml.org/lkml/2017/11/15/813... + // + // I suspect a 128kB sysconf(_SC_ARG_MAX) is the sanest bet, simply + // because of that "conservative is better than aggressive". + // + // Especially since _technically_ we're still limiting things to that + // 128kB due to the single-string limit. + // + // Linus + return ARG_MAX; case _SC_AVPHYS_PAGES: return get_avphys_pages(); case _SC_CHILD_MAX: return __sysconf_rlimit(RLIMIT_NPROC); diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py index b0fb95fb7..586cb0271 100644 --- a/libc/kernel/tools/defaults.py +++ b/libc/kernel/tools/defaults.py @@ -58,8 +58,6 @@ kernel_arch_token_replacements = { # Replace tokens in the output according to this mapping. kernel_token_replacements = { - # The kernel's ARG_MAX is actually the "minimum" maximum (see fs/exec.c). - "ARG_MAX": "_KERNEL_ARG_MAX", # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>. "__unused": "__linux_unused", # The kernel usage of C++ keywords causes problems for C++ code so rename. diff --git a/libc/kernel/uapi/linux/limits.h b/libc/kernel/uapi/linux/limits.h index 41108f9b3..ad0e33ea2 100644 --- a/libc/kernel/uapi/linux/limits.h +++ b/libc/kernel/uapi/linux/limits.h @@ -20,7 +20,7 @@ #define _LINUX_LIMITS_H #define NR_OPEN 1024 #define NGROUPS_MAX 65536 -#define _KERNEL_ARG_MAX 131072 +#define ARG_MAX 131072 #define LINK_MAX 127 #define MAX_CANON 255 #define MAX_INPUT 255 diff --git a/libc/upstream-freebsd/android/include/freebsd-compat.h b/libc/upstream-freebsd/android/include/freebsd-compat.h index 8f0a30742..e646e23e1 100644 --- a/libc/upstream-freebsd/android/include/freebsd-compat.h +++ b/libc/upstream-freebsd/android/include/freebsd-compat.h @@ -50,6 +50,4 @@ void* reallocarray(void*, size_t, size_t); /* FreeBSD has this, but we can't really implement it correctly on Linux. */ #define issetugid() 0 -#define ARG_MAX sysconf(_SC_ARG_MAX) - #endif diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 456ddded5..022da4db4 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -1017,36 +1017,11 @@ 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. - - // Get our current limit, and set things up so we restore the limit. - rlimit rl; - ASSERT_EQ(0, getrlimit(RLIMIT_STACK, &rl)); - uint64_t original_rlim_cur = rl.rlim_cur; - if (rl.rlim_cur == RLIM_INFINITY) { - rl.rlim_cur = 8 * 1024 * 1024; // Bionic reports unlimited stacks as 8MiB. - } - auto guard = android::base::make_scope_guard([&rl, original_rlim_cur]() { - rl.rlim_cur = original_rlim_cur; - ASSERT_EQ(0, setrlimit(RLIMIT_STACK, &rl)); - }); - - // _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" (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)); - - // With a 128-page stack limit, we know exactly what _SC_ARG_MAX should be... - rl.rlim_cur = 128 * sysconf(_SC_PAGE_SIZE); - 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)); + // https://lkml.org/lkml/2017/11/15/813. +#if !defined(ARG_MAX) +#define ARG_MAX 131072 +#endif + ASSERT_EQ(ARG_MAX, sysconf(_SC_ARG_MAX)); } TEST(UNISTD_TEST, dup2_same) { |