/* * Ikarus Scheme -- A compiler for R6RS Scheme. * Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifdef __CYGWIN__ #include #include #include #include #include #define pagesize 4096 #define pageshift 12 #define segment_size (16*pagesize) #define segment_shift (4+pageshift) #include "ikarus-winmmap.h" /* vim:syntax=c */ static unsigned short* table = 0; static char* ap = 0; static size_t as = 0; static void* do_mmap(size_t n){ void* x = mmap(0, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); if(x == (void*)-1){ fprintf(stderr, "failed to mmap: %s\n", strerror(errno)); exit(-1); } assert((((unsigned int)x) & (segment_size-1)) == 0); return x; } static void do_munmap(void* addr, size_t size){ int err = munmap(addr, size); if(err){ fprintf(stderr, "failed to unmap\n"); exit(-1); } } static void init_table(){ assert(sizeof(unsigned short) == 2); table = do_mmap(32*pagesize); bzero(table, 32*pagesize); } void win_munmap(char* addr, size_t size){ while(size){ unsigned int page = (((unsigned int) addr) >> pageshift); unsigned int segment_index = page / 16; unsigned int page_index = page & 15; unsigned short alloc_bits = table[segment_index]; assert((alloc_bits & (1<> segment_shift); size_t aligned_size = segments << segment_shift; char* addr = do_mmap(aligned_size); unsigned int page = (((unsigned int) addr) >> pageshift); unsigned int segment_index = page / 16; int i; for(i=0; i