annotate keiko/gc0.c @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 /*
mike@0 2 * gc0.c
mike@0 3 *
mike@0 4 * This file is part of the Oxford Oberon-2 compiler
mike@0 5 * Copyright (c) 2006 J. M. Spivey
mike@0 6 * All rights reserved
mike@0 7 *
mike@0 8 * Redistribution and use in source and binary forms, with or without
mike@0 9 * modification, are permitted provided that the following conditions are met:
mike@0 10 *
mike@0 11 * 1. Redistributions of source code must retain the above copyright notice,
mike@0 12 * this list of conditions and the following disclaimer.
mike@0 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
mike@0 14 * this list of conditions and the following disclaimer in the documentation
mike@0 15 * and/or other materials provided with the distribution.
mike@0 16 * 3. The name of the author may not be used to endorse or promote products
mike@0 17 * derived from this software without specific prior written permission.
mike@0 18 *
mike@0 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
mike@0 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
mike@0 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mike@0 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
mike@0 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
mike@0 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
mike@0 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
mike@0 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
mike@0 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
mike@0 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mike@0 29 *
mike@0 30 * $Id: gc.c 1557 2010-01-24 20:59:31Z mike $
mike@0 31 */
mike@0 32
mike@0 33 /* keiko/gc0.c */
mike@0 34 /* Copyright (c) 2017 J. M. Spivey */
mike@0 35
mike@0 36 #include "obx.h"
mike@0 37
mike@0 38 #include <sys/mman.h>
mike@0 39
mike@0 40 #ifndef MAP_ANONYMOUS
mike@0 41 #define MAP_ANONYMOUS MAP_ANON
mike@0 42 #endif
mike@0 43
mike@0 44 #ifdef M64X32
mike@0 45 #define MAP_FLAGS MAP_PRIVATE|MAP_32BIT|MAP_ANONYMOUS
mike@0 46 #else
mike@0 47 #define MAP_FLAGS MAP_PRIVATE|MAP_ANONYMOUS
mike@0 48 #endif
mike@0 49
mike@0 50 static void *get_memory(unsigned size) {
mike@0 51 void *p = mmap(NULL, size, PROT_READ|PROT_WRITE,
mike@0 52 MAP_FLAGS, -1, 0);
mike@0 53 if (p == MAP_FAILED) panic("Out of memory");
mike@0 54 return p;
mike@0 55 }
mike@0 56
mike@0 57 #define CHUNK 16384
mike@0 58
mike@0 59 static unsigned char *alloc = NULL;
mike@0 60 static unsigned char *limit = NULL;
mike@0 61
mike@0 62 #define roundup(x, n) (((x)+(n-1))&~(n-1))
mike@0 63
mike@0 64 void *scratch_alloc(unsigned size) {
mike@0 65 if (size % PAGESIZE == 0 || size > CHUNK)
mike@0 66 return get_memory(roundup(size, PAGESIZE));
mike@0 67
mike@0 68 if (alloc == NULL || size > limit - alloc) {
mike@0 69 alloc = get_memory(CHUNK);
mike@0 70 limit = alloc + CHUNK;
mike@0 71 }
mike@0 72
mike@0 73 void *p = alloc;
mike@0 74 alloc += size;
mike@0 75 return p;
mike@0 76 }
mike@0 77
mike@0 78 /* gc_init -- initialise everything */
mike@0 79 void gc_init(void) {
mike@0 80 }