From: Chris Hanson Date: Mon, 16 Dec 1996 04:40:03 +0000 (+0000) Subject: Use special allocator to allocate the heap when running under Linux. X-Git-Tag: 20090517-FFI~5299 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=e41cb217a3acdc06fb159178f1c38d53c9d51a35;p=mit-scheme.git Use special allocator to allocate the heap when running under Linux. Linux ELF pushes the text and data segments up into high addresses, leaving most of the low addresses empty. To get access to them, we must use mmap. --- diff --git a/v7/src/microcode/config.h b/v7/src/microcode/config.h index 0722ba5a8..35536691b 100644 --- a/v7/src/microcode/config.h +++ b/v7/src/microcode/config.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: config.h,v 9.95 1996/03/04 20:32:53 cph Exp $ +$Id: config.h,v 9.96 1996/12/16 04:37:14 cph Exp $ Copyright (c) 1987-96 Massachusetts Institute of Technology @@ -440,6 +440,11 @@ typedef unsigned long SCHEME_OBJECT; # define HAS_MODF #endif +#ifdef __linux +extern void * linux_heap_malloc (unsigned long); +#define HEAP_MALLOC linux_heap_malloc +#endif + #if defined(WINNT) && !defined(WINNT_RAW_ADDRESSES) /* This kludge exists because of Win32s which allocates diff --git a/v7/src/microcode/s/linux.h b/v7/src/microcode/s/linux.h index 29ea01a9a..87366993a 100644 --- a/v7/src/microcode/s/linux.h +++ b/v7/src/microcode/s/linux.h @@ -1,7 +1,7 @@ /* -*-C-*- System file for Linux -$Id: linux.h,v 1.9 1996/12/11 07:21:37 cph Exp $ +$Id: linux.h,v 1.10 1996/12/16 04:40:03 cph Exp $ Copyright (c) 1995-96 Massachusetts Institute of Technology @@ -39,30 +39,20 @@ MIT in each case. */ #define ALTERNATE_M4 s/ultrix.m4 -/* The following change is necessary if ELF binaries are used. - Unfortunately, it is insufficient, because the Linux ELF - implementation also moves the text and data segments to 0x08000000, - which means that all of the pointer manipulation code must be - changed. This is normal for some architectures, e.g. the MIPS and - HPPA, but it make the binaries for Linux ELF different for the - binaries for all other i386 machines. - - Since I don't currently know any way to adjust the mapping of the - segments, if ELF is in use, I'll just force the switch that causes - GCC to generate a.out format instead of ELF. This is a temporary - patch, because one of these days a.out won't be supported, but - hopefully by then we'll know how to fix this correctly. */ - #ifdef __ELF__ #define M4_SWITCH_SYSTEM -P "define(LINUX_ELF,1)" -#define LD_SWITCH_SYSTEM -rdynamic -T s/linuxelf.lds +/* This is kind of random -- the only system that I've tried this on + is Debian 1.1, which uses ncurses for its termcap support (Debian + 0.93R6 used termcap instead). Debian can have -ltermcap, but it's + an optional package and often not installed. */ #define LIBS_TERMCAP -lncurses #else #define M4_SWITCH_SYSTEM -#define LD_SWITCH_SYSTEM #define LIBS_TERMCAP -ltermcap #endif +#define LD_SWITCH_SYSTEM + /* These definitions configure the microcode to support dynamic loading. */ #define SOURCES_SYSTEM pruxdld.c #define OBJECTS_SYSTEM pruxdld.o diff --git a/v7/src/microcode/ux.c b/v7/src/microcode/ux.c index 839851d2c..1f9187f8e 100644 --- a/v7/src/microcode/ux.c +++ b/v7/src/microcode/ux.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ux.c,v 1.14 1996/04/23 20:58:45 cph Exp $ +$Id: ux.c,v 1.15 1996/12/16 04:37:31 cph Exp $ Copyright (c) 1990-96 Massachusetts Institute of Technology @@ -641,3 +641,22 @@ DEFUN (OS_free, (ptr), void * ptr) { UX_free (ptr); } + +#ifdef __linux + +#include + +void * +linux_heap_malloc (unsigned long requested_length) +{ + unsigned long ps = (getpagesize ()); + void * addr + = (mmap (((void *) ps), + (((requested_length + (ps - 1)) / ps) * ps), + (PROT_EXEC | PROT_READ | PROT_WRITE), + (MAP_PRIVATE | MAP_ANONYMOUS), + 0, 0)); + return ((addr == ((void *) (-1))) ? 0 : addr); +} + +#endif /* __linux */