- /* This could just as well be in arch_init(), but it's not. */
-#ifdef __i386__
- /* FIXME: This used to be here. However, I have just removed it
- with no apparent ill effects (it may be that earlier kernels
- started up a process with a different set of traps, or
- something?) Find out what this was meant to do, and reenable it
- or delete it if possible. -- CSR, 2002-07-15 */
- /* SET_FPU_CONTROL_WORD(0x1372|4|8|16|32); no interrupts */
+
+#ifdef LISP_FEATURE_LINUX
+ /* KLUDGE: Disable memory randomization on new Linux kernels
+ * by setting a personality flag and re-executing. (We need
+ * to re-execute, since the memory maps that can conflict with
+ * the SBCL spaces have already been done at this point).
+ */
+ 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);
+ }
+ }
+ /* Either changing the personality or execve() failed. Either
+ * way we might as well continue, and hope that the random
+ * memory maps are ok this time around.
+ */
+ fprintf(stderr, "WARNING: Couldn't re-execute SBCL with the proper personality flags (maybe /proc isn't mounted?). Trying to continue anyway.\n");
+ }
+ }
+#else
+ /* KLUDGE: This doesn't seem like a particularly clever thing
+ * to do, but I can't think of anything better at the moment.
+ * One rigorously-correct-seeming possibility would be to have
+ * personality() stuff be suppressed only at the explicit
+ * request of the builder (in customize-target-features.lisp),
+ * and then simply continue here without error, on the theory
+ * that the builder knew what he was doing. But even to me
+ * that seems like a lot of trouble to put the user to in the
+ * common case when he's building on the same system he's
+ * running on. -- WHN */
+ lose("This SBCL executable was built on some system too old to have <sys/personality.h>, and running it on this newer system which has <sys/personality.h> is unsupported. Consider rebuilding SBCL from source on the new system.");