Skip to content
Snippets Groups Projects
Commit 911be032 authored by rtoy's avatar rtoy
Browse files

Patch from Stelian Ionescu on cmucl-imp, 2010/02/01:

    When run on a kernel compiled without COMPAT_BRK CMUCL segfaults,
    so I copied the kludge used by SBCL - check the current
    personality, and if necessary, enable ADDR_NO_RANDOMIZE and
    re-exec itself.

Linux-os.c:
o Check for personality and rexec if necessary.

os.h:
o New prototype for os_init needed because it needs argv and envp.

lisp.c:
Darwin-os.c:
FreeBSD-os.c:
NetBSD-os.c:
OpenBSD-os.c:
hpux-os.c:
irix-os.c:
mach-os.c:
osf1-os.c:
solaris-os.c:
sunos-os.c:
o Update call to os_init, which needs argv and envp now.
parent 806697d3
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Frobbed for OpenBSD by Pierre R. Mai, 2001. * Frobbed for OpenBSD by Pierre R. Mai, 2001.
* Frobbed for Darwin by Pierre R. Mai, 2003. * Frobbed for Darwin by Pierre R. Mai, 2003.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.25 2009/01/06 00:06:46 rtoy Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.26 2010/02/01 15:16:08 rtoy Exp $
* *
*/ */
...@@ -101,7 +101,7 @@ timebase_init(void) ...@@ -101,7 +101,7 @@ timebase_init(void)
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
os_vm_page_size = OS_VM_DEFAULT_PAGESIZE; os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
#ifdef __ppc__ #ifdef __ppc__
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Much hacked by Paul Werkowski * Much hacked by Paul Werkowski
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.31 2009/10/15 15:05:51 rtoy Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.32 2010/02/01 15:16:08 rtoy Exp $
* *
*/ */
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
vm_size_t os_vm_page_size; vm_size_t os_vm_page_size;
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
os_vm_page_size = getpagesize(); os_vm_page_size = getpagesize();
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* Alpha support by Julian Dolby, 1999. * Alpha support by Julian Dolby, 1999.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.46 2009/11/02 15:05:07 rtoy Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.47 2010/02/01 15:16:09 rtoy Exp $
* *
*/ */
...@@ -51,8 +51,88 @@ size_t os_vm_page_size; ...@@ -51,8 +51,88 @@ size_t os_vm_page_size;
#include "gencgc.h" #include "gencgc.h"
#endif #endif
#if defined(__i386) || defined(__x86_64)
/* Prototype for personality(2). Done inline here since the header file
* for this isn't available on old versions of glibc. */
int personality (unsigned long);
#if !defined(ADDR_NO_RANDOMIZE)
#define ADDR_NO_RANDOMIZE 0x40000
#endif
/* From personality(2) */
#define CURRENT_PERSONALITY 0xffffffffUL
#endif
void
check_personality(struct utsname *name, char *argv[], char *envp[])
{
/* 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 CMUCL spaces have already been done at this point).
*
* Since randomization is currently implemented only on x86 kernels,
* don't do this trick on other platforms.
*/
#if defined(__i386) || defined(__x86_64)
int major_version, minor_version, patch_version;
char *p;
p=name->release;
major_version=atoi(p);
p=strchr(p,'.')+1;
minor_version=atoi(p);
p=strchr(p,'.')+1;
patch_version=atoi(p);
if ((major_version == 2
/* Some old kernels will apparently lose unsupported personality flags
* on exec() */
&& ((minor_version == 6 && patch_version >= 11)
|| (minor_version > 6)
/* This is what RHEL 3 reports */
|| (minor_version == 4 && patch_version > 20)))
|| major_version >= 3)
{
int pers = personality(CURRENT_PERSONALITY);
if (!(pers & ADDR_NO_RANDOMIZE)) {
int retval = personality(pers | ADDR_NO_RANDOMIZE);
/* 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(CURRENT_PERSONALITY);
/* ... 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);
}
}
/* 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 CMUCL with the proper personality flags"
"(maybe /proc isn't mounted?). Trying to continue anyway.\n");
}
}
#endif
}
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
struct utsname name; struct utsname name;
...@@ -66,6 +146,8 @@ os_init(void) ...@@ -66,6 +146,8 @@ os_init(void)
} }
os_vm_page_size = getpagesize(); os_vm_page_size = getpagesize();
check_personality(&name, argv, envp);
} }
#ifdef __i386 #ifdef __i386
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Frobbed for OpenBSD by Pierre R. Mai, 2001. * Frobbed for OpenBSD by Pierre R. Mai, 2001.
* Frobbed for NetBSD by Pierre R. Mai, 2002. * Frobbed for NetBSD by Pierre R. Mai, 2002.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.13 2009/10/16 13:38:02 rswindells Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.14 2010/02/01 15:16:09 rtoy Exp $
* *
*/ */
...@@ -45,7 +45,7 @@ size_t os_vm_page_size; ...@@ -45,7 +45,7 @@ size_t os_vm_page_size;
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
os_vm_page_size = OS_VM_DEFAULT_PAGESIZE; os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* GENCGC support by Douglas Crosher, 1996, 1997. * GENCGC support by Douglas Crosher, 1996, 1997.
* Frobbed for OpenBSD by Pierre R. Mai, 2001. * Frobbed for OpenBSD by Pierre R. Mai, 2001.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.c,v 1.8 2008/12/07 02:33:55 agoncharov Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/OpenBSD-os.c,v 1.9 2010/02/01 15:16:09 rtoy Exp $
* *
*/ */
...@@ -41,7 +41,7 @@ vm_size_t os_vm_page_size; ...@@ -41,7 +41,7 @@ vm_size_t os_vm_page_size;
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
os_vm_page_size = OS_VM_DEFAULT_PAGESIZE; os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
} }
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/hpux-os.c,v 1.8 2008/03/19 09:17:10 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/hpux-os.c,v 1.9 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -53,7 +53,7 @@ static struct segment { ...@@ -53,7 +53,7 @@ static struct segment {
} segments[MAX_SEGMENTS]; } segments[MAX_SEGMENTS];
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
int i; int i;
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/irix-os.c,v 1.4 2008/03/19 09:17:10 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/irix-os.c,v 1.5 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -30,7 +30,7 @@ os_vm_size_t os_vm_page_size = (-1); ...@@ -30,7 +30,7 @@ os_vm_size_t os_vm_page_size = (-1);
int zero_fd; int zero_fd;
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
zero_fd = open("/dev/zero", O_RDONLY); zero_fd = open("/dev/zero", O_RDONLY);
os_vm_page_size = getpagesize(); os_vm_page_size = getpagesize();
......
/* /*
* main() entry point for a stand alone lisp image. * main() entry point for a stand alone lisp image.
* *
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.c,v 1.69 2009/12/18 04:03:24 agoncharov Exp $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.c,v 1.70 2010/02/01 15:16:09 rtoy Exp $
* *
*/ */
...@@ -556,7 +556,7 @@ main(int argc, const char *argv[], const char *envp[]) ...@@ -556,7 +556,7 @@ main(int argc, const char *argv[], const char *envp[])
if (default_core == NULL) if (default_core == NULL)
default_core = "lisp.core"; default_core = "lisp.core";
os_init(); os_init(argv, envp);
#if defined FEATURE_EXECUTABLE #if defined FEATURE_EXECUTABLE
if (builtin_image_flag != 0) if (builtin_image_flag != 0)
map_core_sections(argv[0]); map_core_sections(argv[0]);
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/mach-os.c,v 1.6 2008/03/19 09:17:13 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/mach-os.c,v 1.7 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -38,7 +38,7 @@ task_self(void) ...@@ -38,7 +38,7 @@ task_self(void)
#endif #endif
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
os_vm_page_size = vm_page_size; os_vm_page_size = vm_page_size;
} }
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.23 2008/12/10 02:39:13 rtoy Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.24 2010/02/01 15:16:09 rtoy Exp $
* *
* Common interface for os-dependent functions. * Common interface for os-dependent functions.
* *
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
extern os_vm_size_t os_vm_page_size; extern os_vm_size_t os_vm_page_size;
extern void os_init(void); extern void os_init(char *argv[], char *envp[]);
extern void os_install_interrupt_handlers(void); extern void os_install_interrupt_handlers(void);
extern os_vm_address_t os_allocate(os_vm_size_t len); extern os_vm_address_t os_allocate(os_vm_size_t len);
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/osf1-os.c,v 1.4 2008/03/19 09:17:13 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/osf1-os.c,v 1.5 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
vm_size_t os_vm_page_size; vm_size_t os_vm_page_size;
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
int buf[2] = { SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT }; int buf[2] = { SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT };
int error; int error;
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/solaris-os.c,v 1.23 2008/09/24 09:42:33 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/solaris-os.c,v 1.24 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -71,7 +71,7 @@ os_init_bailout(char *arg) ...@@ -71,7 +71,7 @@ os_init_bailout(char *arg)
} }
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
zero_fd = open(ZEROFILE, O_RDONLY); zero_fd = open(ZEROFILE, O_RDONLY);
if (zero_fd < 0) if (zero_fd < 0)
......
/* /*
* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/sunos-os.c,v 1.10 2008/09/07 07:07:49 cshapiro Rel $ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/sunos-os.c,v 1.11 2010/02/01 15:16:09 rtoy Exp $
* *
* OS-dependent routines. This file (along with os.h) exports an * OS-dependent routines. This file (along with os.h) exports an
* OS-independent interface to the operating system VM facilities. * OS-independent interface to the operating system VM facilities.
...@@ -81,7 +81,7 @@ os_init_bailout(arg) ...@@ -81,7 +81,7 @@ os_init_bailout(arg)
} }
void void
os_init(void) os_init(char *argv[], char *envp[])
{ {
char *empty_file = getenv("CMUCL_EMPTYFILE"); char *empty_file = getenv("CMUCL_EMPTYFILE");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment