- if ((major_version == 2 && minor_version >= 6)
- || major_version >= 3) { /* i.e., if running on Linux which is new
- * enough to have <sys/personality.h> */
-#if PERSONALITY_SUPPORTED_AT_COMPILE_TIME
- {
- long pers = personality(-1);
- /* 0x40000 aka. ADDR_NO_RANDOMIZE */
- if (!(pers & 0x40000)) {
- if (personality(pers | 0x40000) != -1) {
- /* Use /proc/self/exe instead of trying to figure out
- * the executable path from PATH and argv[0], since
- * that's unreliable. We follow the symlink instead of
- * executing the file directly in order to prevent top
- * from displaying the name of the process as "exe". */
- char runtime[PATH_MAX+1];
- int i = readlink("/proc/self/exe", runtime, PATH_MAX);
- if (i != -1) {
- runtime[i] = '\0';
- execve(runtime, argv, envp);
- }
+#ifdef LISP_FEATURE_X86
+ if ((major_version == 2
+ /* Some old kernels will apparently lose unsupported personality flags
+ * on exec() */
+ && ((minor_version == 6 && patch_version >= 11)
+ || (minor_version > 6)))
+ || major_version >= 3)
+ {
+ int pers = personality(0xffffffffUL);
+ /* 0x40000 aka. ADDR_NO_RANDOMIZE */
+ if (!(pers & 0x40000)) {
+ int retval = personality(pers | 0x40000);
+ /* Allegedly some Linux kernels (the reported case was
+ * "hardened Linux 2.6.7") won't set the new personality,
+ * but nor will they return -1 for an error. So as a
+ * workaround query the new personality...
+ */
+ int newpers = personality(0xffffffffUL);
+ /* ... and don't re-execute if either the setting resulted
+ * in an error or if the value didn't change. Otherwise
+ * this might result in an infinite loop.
+ */
+ if (retval != -1 && newpers != pers) {
+ /* Use /proc/self/exe instead of trying to figure out
+ * the executable path from PATH and argv[0], since
+ * that's unreliable. We follow the symlink instead of
+ * executing the file directly in order to prevent top
+ * from displaying the name of the process as "exe". */
+ char runtime[PATH_MAX+1];
+ int i = readlink("/proc/self/exe", runtime, PATH_MAX);
+ if (i != -1) {
+ runtime[i] = '\0';
+ execve(runtime, argv, envp);