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
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp
index d45cb38..2442fd9 100644
--- a/libc/bionic/sysconf.cpp
+++ b/libc/bionic/sysconf.cpp
@@ -52,9 +52,16 @@
// 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 b0fb95f..586cb02 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -58,8 +58,6 @@
# 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 41108f9..ad0e33e 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 8f0a307..e646e23 100644
--- a/libc/upstream-freebsd/android/include/freebsd-compat.h
+++ b/libc/upstream-freebsd/android/include/freebsd-compat.h
@@ -50,6 +50,4 @@
/* FreeBSD has this, but we can't really implement it correctly on Linux. */
#define issetugid() 0
-#define ARG_MAX sysconf(_SC_ARG_MAX)
-
#endif