Skip to content
Snippets Groups Projects
validate.c 3.7 KiB
Newer Older
wlott's avatar
wlott committed
/*
rtoy's avatar
rtoy committed
 * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/validate.c,v 1.19 2004/07/08 17:49:04 rtoy Exp $
wlott's avatar
wlott committed
 *
 * Memory Validation
 */

#include <stdio.h>
emarsden's avatar
 
emarsden committed
#include <unistd.h>
rtoy's avatar
rtoy committed
#include <string.h>
#ifdef sparc
toy's avatar
toy committed
#include <alloca.h>
#endif
wlott's avatar
wlott committed
#include "lisp.h"
#include "os.h"
#include "globals.h"
#include "validate.h"
emarsden's avatar
 
emarsden committed
#include "internals.h"
wlott's avatar
wlott committed

unsigned long read_only_space_size = READ_ONLY_SPACE_SIZE;
unsigned long binding_stack_size = BINDING_STACK_SIZE;
unsigned long static_space_size = STATIC_SPACE_SIZE;
unsigned long control_stack_size = CONTROL_STACK_SIZE;

rtoy's avatar
rtoy committed
#ifdef sparc
extern void make_holes(void);
#endif

static void
ensure_space(lispobj *start, size_t size)
wlott's avatar
wlott committed
{
    if (os_validate((os_vm_address_t) start, size) == NULL) {
wlott's avatar
wlott committed
	fprintf(stderr,
		"ensure_space: Failed to validate %ld bytes at 0x%08lx\n",
		(unsigned long) size,
		(unsigned long) start);
wlott's avatar
wlott committed
	exit(1);
    }
}


/* We use the linker symbol redefinition trick here to get the dynamic
   space size when the core is built in to the executable.  Note that
   builtin_image_flag is used as a flag indicating that the lisp image
   is built into the executable.  FMG */
extern int builtin_image_flag;
cwang's avatar
cwang committed
long image_dynamic_space_size = 0;
wlott's avatar
wlott committed
{
    void *dynamic_space_data;

    /* Note: XXX use alloca here because it's not malloc.  I'm assuming
     that anyone who wants to make this scheme work this will be using
     GCC.  FMG */
    if (builtin_image_flag != 0)
      dynamic_space_data = alloca((int)(&image_dynamic_space_size));

    /* Read-Only Space */
    read_only_space = (lispobj *) READ_ONLY_SPACE_START;
    /* Don't try to map this space if the executable contains the
       image. */
    if (builtin_image_flag == 0)
      ensure_space(read_only_space, READ_ONLY_SPACE_SIZE);
wlott's avatar
wlott committed

    /* Static Space */
    static_space = (lispobj *) STATIC_SPACE_START;
    /* Don't try to map this space if the executable contains the
       image. */
    if (builtin_image_flag == 0)
      ensure_space(static_space, STATIC_SPACE_SIZE);
wlott's avatar
wlott committed

    /* Dynamic-0 Space */
    dynamic_0_space = (lispobj *) DYNAMIC_0_SPACE_START;
    if (builtin_image_flag != 0) {
      /* If the executable contains the lisp image, we want to copy the
	 data in the dynamic space out of its segment, then map the
	 dynamic space (which has the side effect of unmapping the
	 dynamic space segment in the executable), then copy the data
	 back into it.  This is necessary to make the data in the
	 dynamic space segment available to the new lisp process.  */
      bcopy(dynamic_0_space, dynamic_space_data, (int)&image_dynamic_space_size);
      ensure_space(dynamic_0_space, dynamic_space_size);
      bcopy(dynamic_space_data, dynamic_0_space, (int)&image_dynamic_space_size);
    } else
      ensure_space(dynamic_0_space, dynamic_space_size);
wlott's avatar
wlott committed

    current_dynamic_space = dynamic_0_space;
wlott's avatar
wlott committed

dtc's avatar
dtc committed
#ifndef GENCGC
    /* Dynamic-1 Space */
    dynamic_1_space = (lispobj *) DYNAMIC_1_SPACE_START;
    ensure_space(dynamic_1_space, dynamic_space_size);
dtc's avatar
dtc committed
#endif
wlott's avatar
wlott committed

    /* Control Stack */
    control_stack = (lispobj *) CONTROL_STACK_START;
cwang's avatar
cwang committed
#if (defined(i386) || defined(__x86_64))
    control_stack_end = (lispobj *) (CONTROL_STACK_START
				     + CONTROL_STACK_SIZE);
ram's avatar
ram committed
#endif
    ensure_space(control_stack, CONTROL_STACK_SIZE);
wlott's avatar
wlott committed

#ifdef SIGNAL_STACK_START
    ensure_space((lispobj *) SIGNAL_STACK_START, SIGNAL_STACK_SIZE);
#endif

    /* Binding Stack */
    binding_stack = (lispobj *) BINDING_STACK_START;
    ensure_space(binding_stack, BINDING_STACK_SIZE);
moore's avatar
 
moore committed
#ifdef LINKAGE_TABLE
    ensure_space((lispobj *)FOREIGN_LINKAGE_SPACE_START,
		 FOREIGN_LINKAGE_SPACE_SIZE);
moore's avatar
 
moore committed
#endif
wlott's avatar
wlott committed
#ifdef PRINTNOISE
    printf(" done.\n");
#endif

#ifdef RED_ZONE_HIT
    os_guard_control_stack (0, 1);
wlott's avatar
wlott committed
#endif
}