version 1.212, 2008/08/16 17:54:23
|
version 1.213, 2008/08/16 20:20:32
|
Line 28
|
Line 28
|
#include <string.h> |
#include <string.h> |
#include <math.h> |
#include <math.h> |
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <alloca.h> |
#ifndef STANDALONE |
#ifndef STANDALONE |
#include <sys/stat.h> |
#include <sys/stat.h> |
#endif |
#endif |
Line 483 static Address verbose_malloc(Cell size)
|
Line 484 static Address verbose_malloc(Cell size)
|
return r; |
return r; |
} |
} |
|
|
static Address next_address=0; |
static void *next_address=0; |
static void after_alloc(Address r, Cell size) |
static void after_alloc(Address r, Cell size) |
{ |
{ |
if (r != (Address)-1) { |
if (r != (Address)-1) { |
Line 514 static void after_alloc(Address r, Cell
|
Line 515 static void after_alloc(Address r, Cell
|
#if defined(HAVE_MMAP) |
#if defined(HAVE_MMAP) |
static Address alloc_mmap(Cell size) |
static Address alloc_mmap(Cell size) |
{ |
{ |
Address r; |
void *r; |
|
|
#if defined(MAP_ANON) |
#if defined(MAP_ANON) |
debugp(stderr,"try mmap($%lx, $%lx, ..., MAP_ANON, ...); ", (long)next_address, (long)size); |
debugp(stderr,"try mmap($%lx, $%lx, ..., MAP_ANON, ...); ", (long)next_address, (long)size); |
Line 539 static Address alloc_mmap(Cell size)
|
Line 540 static Address alloc_mmap(Cell size)
|
return r; |
return r; |
} |
} |
|
|
static void page_noaccess(Address a) |
static void page_noaccess(void *a) |
{ |
{ |
/* try mprotect first; with munmap the page might be allocated later */ |
/* try mprotect first; with munmap the page might be allocated later */ |
debugp(stderr, "try mprotect(%p,%ld,PROT_NONE); ", a, (long)pagesize); |
debugp(stderr, "try mprotect(%p,%ld,PROT_NONE); ", a, (long)pagesize); |
Line 575 Address gforth_alloc(Cell size)
|
Line 576 Address gforth_alloc(Cell size)
|
return verbose_malloc(size); |
return verbose_malloc(size); |
} |
} |
|
|
static Address dict_alloc_read(FILE *file, Cell imagesize, Cell dictsize, Cell offset) |
static void *dict_alloc_read(FILE *file, Cell imagesize, Cell dictsize, Cell offset) |
{ |
{ |
Address image = MAP_FAILED; |
void *image = MAP_FAILED; |
|
|
#if defined(HAVE_MMAP) |
#if defined(HAVE_MMAP) |
if (offset==0) { |
if (offset==0) { |
image=alloc_mmap(dictsize); |
image=alloc_mmap(dictsize); |
if (image != (Address)MAP_FAILED) { |
if (image != (void *)MAP_FAILED) { |
Address image1; |
void *image1; |
debugp(stderr,"try mmap($%lx, $%lx, ..., MAP_FIXED|MAP_FILE, imagefile, 0); ", (long)image, (long)imagesize); |
debugp(stderr,"try mmap($%lx, $%lx, ..., MAP_FIXED|MAP_FILE, imagefile, 0); ", (long)image, (long)imagesize); |
image1 = mmap(image, imagesize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_FIXED|MAP_FILE|MAP_PRIVATE|map_noreserve, fileno(file), 0); |
image1 = mmap(image, imagesize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_FIXED|MAP_FILE|MAP_PRIVATE|map_noreserve, fileno(file), 0); |
after_alloc(image1,dictsize); |
after_alloc(image1,dictsize); |
if (image1 == (Address)MAP_FAILED) |
if (image1 == (void *)MAP_FAILED) |
goto read_image; |
goto read_image; |
} |
} |
} |
} |
#endif /* defined(HAVE_MMAP) */ |
#endif /* defined(HAVE_MMAP) */ |
if (image == (Address)MAP_FAILED) { |
if (image == (void *)MAP_FAILED) { |
image = gforth_alloc(dictsize+offset)+offset; |
image = gforth_alloc(dictsize+offset)+offset; |
read_image: |
read_image: |
rewind(file); /* fseek(imagefile,0L,SEEK_SET); */ |
rewind(file); /* fseek(imagefile,0L,SEEK_SET); */ |
Line 653 void alloc_stacks(ImageHeader * h)
|
Line 654 void alloc_stacks(ImageHeader * h)
|
size_t p = pagesize; |
size_t p = pagesize; |
size_t totalsize = |
size_t totalsize = |
wholepage(dsize)+wholepage(fsize)+wholepage(rsize)+wholepage(lsize)+5*p; |
wholepage(dsize)+wholepage(fsize)+wholepage(rsize)+wholepage(lsize)+5*p; |
Address a = alloc_mmap(totalsize); |
void *a = alloc_mmap(totalsize); |
if (a != (Address)MAP_FAILED) { |
if (a != (void *)MAP_FAILED) { |
page_noaccess(a); a+=p; h-> data_stack_base=a; a+=wholepage(dsize); |
page_noaccess(a); a+=p; h-> data_stack_base=a; a+=wholepage(dsize); |
page_noaccess(a); a+=p; h-> fp_stack_base=a; a+=wholepage(fsize); |
page_noaccess(a); a+=p; h-> fp_stack_base=a; a+=wholepage(fsize); |
page_noaccess(a); a+=p; h->return_stack_base=a; a+=wholepage(rsize); |
page_noaccess(a); a+=p; h->return_stack_base=a; a+=wholepage(rsize); |
Line 677 void alloc_stacks(ImageHeader * h)
|
Line 678 void alloc_stacks(ImageHeader * h)
|
#endif |
#endif |
|
|
#warning You can ignore the warnings about clobbered variables in gforth_go |
#warning You can ignore the warnings about clobbered variables in gforth_go |
int gforth_go(Address image, int stack, Cell *entries) |
int gforth_go(void *image, int stack, Cell *entries) |
{ |
{ |
volatile ImageHeader *image_header = (ImageHeader *)image; |
volatile ImageHeader *image_header = (ImageHeader *)image; |
Cell *sp0=(Cell*)(image_header->data_stack_base + dsize); |
Cell *sp0=(Cell*)(image_header->data_stack_base + dsize); |
Line 2260 int main(int argc, char **argv, char **e
|
Line 2261 int main(int argc, char **argv, char **e
|
#endif |
#endif |
int retvalue; |
int retvalue; |
|
|
code_here = NULL+CODE_BLOCK_SIZE; /* llvm-gcc does not like this as |
code_here = ((void *)0)+CODE_BLOCK_SIZE; /* llvm-gcc does not like this as |
initializer, so we do it here */ |
initializer, so we do it here */ |
#ifndef STANDALONE |
#ifndef STANDALONE |
/* buffering of the user output device */ |
/* buffering of the user output device */ |
#ifdef _IONBF |
#ifdef _IONBF |