aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-02-01 11:00:38 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-02-01 11:00:52 -0800
commit6c57d320484988e87e446e2e60ce42816bf51d53 (patch)
tree6af6d0431ac741a7891d0c4ad81c52323420c341 /include
parent36231bee7ab36d59dd121ea85b91411ae86945f3 (diff)
downloadglibc-6c57d320484988e87e446e2e60ce42816bf51d53.zip
glibc-6c57d320484988e87e446e2e60ce42816bf51d53.tar.gz
glibc-6c57d320484988e87e446e2e60ce42816bf51d53.tar.bz2
sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305]
Add _SC_MINSIGSTKSZ for the minimum signal stack size derived from AT_MINSIGSTKSZ, which is the minimum number of bytes of free stack space required in order to gurantee successful, non-nested handling of a single signal whose handler is an empty function, and _SC_SIGSTKSZ which is the suggested minimum number of bytes of stack space required for a signal stack. If AT_MINSIGSTKSZ isn't available, sysconf (_SC_MINSIGSTKSZ) returns MINSIGSTKSZ. On Linux/x86 with XSAVE, the signal frame used by kernel is composed of the following areas and laid out as: ------------------------------ | alignment padding | ------------------------------ | xsave buffer | ------------------------------ | fsave header (32-bit only) | ------------------------------ | siginfo + ucontext | ------------------------------ Compute AT_MINSIGSTKSZ value as size of xsave buffer + size of fsave header (32-bit only) + size of siginfo and ucontext + alignment padding. If _SC_SIGSTKSZ_SOURCE or _GNU_SOURCE are defined, MINSIGSTKSZ and SIGSTKSZ are redefined as /* Default stack size for a signal handler: sysconf (SC_SIGSTKSZ). */ # undef SIGSTKSZ # define SIGSTKSZ sysconf (_SC_SIGSTKSZ) /* Minimum stack size for a signal handler: SIGSTKSZ. */ # undef MINSIGSTKSZ # define MINSIGSTKSZ SIGSTKSZ Compilation will fail if the source assumes constant MINSIGSTKSZ or SIGSTKSZ. The reason for not simply increasing the kernel's MINSIGSTKSZ #define (apart from the fact that it is rarely used, due to glibc's shadowing definitions) was that userspace binaries will have baked in the old value of the constant and may be making assumptions about it. For example, the type (char [MINSIGSTKSZ]) changes if this #define changes. This could be a problem if an newly built library tries to memcpy() or dump such an object defined by and old binary. Bounds-checking and the stack sizes passed to things like sigaltstack() and makecontext() could similarly go wrong.
Diffstat (limited to 'include')
-rw-r--r--include/bits/sigstack.h5
-rw-r--r--include/bits/sigstksz.h7
-rw-r--r--include/features.h11
3 files changed, 23 insertions, 0 deletions
diff --git a/include/bits/sigstack.h b/include/bits/sigstack.h
new file mode 100644
index 0000000..eea939f
--- /dev/null
+++ b/include/bits/sigstack.h
@@ -0,0 +1,5 @@
+#include_next <bits/sigstack.h>
+
+#if !defined _ISOMAC && !defined CONSTANT_MINSIGSTKSZ
+# define CONSTANT_MINSIGSTKSZ MINSIGSTKSZ
+#endif
diff --git a/include/bits/sigstksz.h b/include/bits/sigstksz.h
new file mode 100644
index 0000000..2ca891e
--- /dev/null
+++ b/include/bits/sigstksz.h
@@ -0,0 +1,7 @@
+/* NB: Don't define MINSIGSTKSZ nor SIGSTKSZ to sysconf (SC_SIGSTKSZ) for
+ glibc build. IS_IN can only be used when _ISOMAC isn't defined. */
+#ifdef _ISOMAC
+# include_next <bits/sigstksz.h>
+#elif IS_IN (libsupport)
+# include_next <bits/sigstksz.h>
+#endif
diff --git a/include/features.h b/include/features.h
index c6ff971..eb97470 100644
--- a/include/features.h
+++ b/include/features.h
@@ -48,6 +48,8 @@
_LARGEFILE64_SOURCE Additional functionality from LFS for large files.
_FILE_OFFSET_BITS=N Select default filesystem interface.
_ATFILE_SOURCE Additional *at interfaces.
+ _SC_SIGSTKSZ_SOURCE Select correct (but non compile-time constant)
+ MINSIGSTKSZ and SIGSTKSZ.
_GNU_SOURCE All of the above, plus GNU extensions.
_DEFAULT_SOURCE The default set of features (taking precedence over
__STRICT_ANSI__).
@@ -94,6 +96,8 @@
__USE_FILE_OFFSET64 Define 64bit interface as default.
__USE_MISC Define things from 4.3BSD or System V Unix.
__USE_ATFILE Define *at interfaces and AT_* constants for them.
+ __USE_SC_SIGSTKSZ Define correct (but non compile-time constant)
+ MINSIGSTKSZ and SIGSTKSZ.
__USE_GNU Define GNU extensions.
__USE_FORTIFY_LEVEL Additional security measures used, according to level.
@@ -137,6 +141,7 @@
#undef __USE_FILE_OFFSET64
#undef __USE_MISC
#undef __USE_ATFILE
+#undef __USE_SC_SIGSTKSZ
#undef __USE_GNU
#undef __USE_FORTIFY_LEVEL
#undef __KERNEL_STRICT_NAMES
@@ -213,6 +218,8 @@
# define _DEFAULT_SOURCE 1
# undef _ATFILE_SOURCE
# define _ATFILE_SOURCE 1
+# undef _SC_SIGSTKSZ_SOURCE
+# define _SC_SIGSTKSZ_SOURCE 1
#endif
/* If nothing (other than _GNU_SOURCE and _DEFAULT_SOURCE) is defined,
@@ -388,6 +395,10 @@
# define __USE_ATFILE 1
#endif
+#ifdef _SC_SIGSTKSZ_SOURCE
+# define __USE_SC_SIGSTKSZ 1
+#endif
+
#ifdef _GNU_SOURCE
# define __USE_GNU 1
#endif