#ifdef __CYGWIN__ #include #include #include #include #include #define pagesize 4096 #define pageshift 12 #define segment_size (16*pagesize) #define segment_shift (4+pageshift) #include "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