/* Static Heap management routines for XEmacs. Copyright (C) 1994, 1998 Free Software Foundation, Inc.This file is part of XEmacs.XEmacs is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option) anylater version.XEmacs is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licensefor more details.You should have received a copy of the GNU General Public Licensealong with XEmacs; see the file COPYING. If not, write to the FreeSoftware Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA02111-1307, USA.*/#include <config.h>#include <stdio.h>#include "lisp.h"#include <stddef.h>#include <unistd.h>#include <sheap-adjust.h>#define STATIC_HEAP_BASE 0x600000#define STATIC_HEAP_SLOP 0x40000#define STATIC_HEAP_SIZE \(STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)#define BLOCKSIZE (1<<12)#define ALLOC_UNIT (BLOCKSIZE-1)#define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))#define ALIGN_ALLOC(addr) ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)charstatic_heap_buffer[STATIC_HEAP_SIZE]={0};char*static_heap_base=static_heap_buffer;char*static_heap_ptr=static_heap_buffer;unsignedlongstatic_heap_size=STATIC_HEAP_SIZE;intstatic_heap_initialized=0;intstatic_heap_dumped=0;void*more_static_core(ptrdiff_tincrement){intsize=(int)increment;void*result;if(!static_heap_initialized){#ifdef VALMASKif(((unsignedlong)static_heap_base&~VALMASK)!=0){printf("error: The heap was allocated in upper memory.\n");exit(-1);}#endifstatic_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);static_heap_ptr=static_heap_base;static_heap_size=STATIC_HEAP_SIZE-(static_heap_base-static_heap_buffer);#ifdef __CYGWIN32__sbrk(BLOCKSIZE);/* force space for fork to work */#endifstatic_heap_initialized=1;}result=static_heap_ptr;/* we don't need to align - handled by gmalloc. */if(size<0){if(static_heap_ptr+size<static_heap_base){return0;}}else{if(static_heap_ptr+size>=static_heap_base+static_heap_size){printf("\nRequested %d bytes, static heap exhausted! base is %p, current ptris%p.Youhaveexhaustedthestaticheap.Ifyouaresimplytryingtocompile,removesheap-adjust.handpuresize-adjust.handrecompilefromthetoplevel.Ifthisdoesn'tworkthenSTATIC_HEAP_SLOP(definedinthisfile)istoosmall.Ifyouwanttoruntemacs,changeSHEAP_ADJUSTMENTinsheap-adjust.hto0ora+venumber.Generallyyoushould*not*trytoruntemacswithastaticheap,youshoulddumpfirst.\n", size,static_heap_base,static_heap_ptr);exit(-1);return0;}}static_heap_ptr+=size;returnresult;}voidsheap_adjust_h(){FILE*stream=fopen("sheap-adjust.h","w");if(stream==NULL)report_file_error("Opening sheap adjustment file",Fcons(build_string("sheap-adjust.h"),Qnil));fprintf(stream,"/*\tDo not edit this file!\n""\tAutomatically generated by XEmacs */\n""# define SHEAP_ADJUSTMENT (%d)\n",((static_heap_ptr-static_heap_buffer)-STATIC_HEAP_BASE));fclose(stream);}