/* begincopyright Copyright (c) 1988 Xerox Corporation. All rights reserved. Use and copying of this software and preparation of derivative works based upon this software are permitted. Any distribution of this software or derivative works must comply with all applicable United States export control laws. This software is made available AS IS, and Xerox Corporation makes no warranty about the software, its performance or its conformity to any specification. Any person obtaining a copy of this software is requested to send their name and post office or electronic mail address to: PCR Coordinator Xerox PARC 3333 Coyote Hill Rd. Palo Alto, CA 94304 endcopyright */ /* * ThreadsSharedMem.h * * Demers, December 5, 1990 8:24:18 am PST */ #ifndef _XR_THREADS_SHARED_MEM_ #define _XR_THREADS_SHARED_MEM_ 1 #ifndef _XR_BASIC_TYPES_ #include "BasicTypes.h" #endif /* * VM size parameters and operations */ #define XR_ROUND_UP 1 #define XR_ROUND_DOWN (-1) #define XR_DONT_ROUND 0 extern XR_Pointer XR_ComputeAddress (/* XR_Pointer addr, unsigned bytes, int round */); /* Return (addr + bytes), rounded to page boundary as specified by `round'. */ extern unsigned XR_RoundToPage(/* unsigned sizeVal, int round */); /* Return sizeVal, page-rounded as specified by 'round'. */ #define XR_PAGE_ALIGNED(x) \ (((unsigned)(x)) == XR_RoundToPage(((unsigned)(x)), XR_ROUND_DOWN)) extern int XR_GetPageSize(); /* Return page size of this machine. Equivalent to (int) XR_ComputeAddress( (XR_Pointer)0, 1, XR_ROUND_UP ). */ extern int XR_GetWorstCasePageSize(); /* Return largest page size used on any machine of this architecture. */ extern XR_Pointer XR_VMReserve (/* unsigned bytes */); /* Reserve at least bytes of page-aligned virtual address space. Call during initialization (before FORK, after InitSharedSysMem) or from a thread. */ /* * Package initialization */ extern char * /* NIL or err msg */ XR_SetShmType(/* char * shmType */); extern char * XR_GetShmType(); extern char * /* NIL or err msg */ XR_SetShmArg(/* char * shmArg */); extern char * XR_GetShmArg(); extern char * /* NIL or err msg */ XR_InitSharedMem(); /* The PCR command line argument is shmtype type [arg] XR_SetShmType/XR_SetShmArg set these. They should be called at most once, in that order, before anything else in this interface. Finally, XR_InitSharedMem should be called. This happens automatically at the beginning of the PCR world. */ extern void XR_CleanUpSharedMem(); /* Free resources allocated by the shared memory implementation. Called automatically at end of PCR world. */ /* * Shared data + bss */ extern char * /* NIL or err msg */ XR_ShareMemInitial (/* XR_pointer p */); /* Arrange for all data and bss addresses above p to be shared among all the VPs and IOPs. The value of p must be page-aligned. Call only once, and only during initialization, before FORK. */ /* * System memory */ extern char * /* NIL or err msg */ XR_InitSharedSysMem(/* unsigned nBytes */); /* Initialize "system" memory with at least nBytes available. Call only once, during initialization, before FORK, before any call to XR_AllocSharedSysMem. */ extern XR_Pointer XR_AllocSharedSysMem(/* unsigned nBytes */); /* Allocate and clear a most-restrictively-aligned (e.g. doubleword on SPARC) block of shared memory. It can never be freed. Return NIL if out of memory. Call any time (initialization or thread) after calling InitSharedSysMem. */ /* * Stacks */ extern char * /* NIL or err msg */ XR_InitSharedStackMem(/* unsigned maxStacks, unsigned totalBytes */); /* Initialize for "stack" memory allocation for maxStacks thread stacks whose size totals to at most totalBytes. Call once during initialization (before FORK). */ extern XR_Pointer XR_AllocSharedStackMem(/* int index, unsigned nBytes */); /* Allocate and map a stack memory. A page of protected memory is automatically provided below each stack, so all the memory that's returned is accessible. Call during initialization (before FORK), after InitSharedStackMem. */ extern int /* bytesRemaining or -errno */ XR_FlushSharedStackMem(/* int index, XR_Pointer pLow, pHigh, int minBytesToFlush, int *pBytesFlushed */); /* Assume pLow .. pHigh is cold end of index'th stack (which must be a different thread from the caller). The index is the value passed to AllocSharedStackMem. Discard the stack (hotter than) p: * all protections remain unchanged * stack contents hotter than p may change * backing store resources may be released If the number of bytes of backing store that can be released is less than minBytesToFlush, don't bother. Return the number of bytes that remain allocated to the stack (or -errno on failure), and if pBytesFlushed is not NIL store the number of bytes flushed there. Call from a (daemon) thread. The victim thread should not be running at the time. This is not guaranteed to do anything -- it's just resource reclaiming advice. */ /* * Heap Segments */ typedef struct XR_SegRep { XR_Pointer seg_addr; /* virtual address where segment is mapped */ unsigned seg_bytes; /* size of segment */ } * XR_Seg; extern void XR_InitSeg2(/* XR_Seg seg, XR_Pointer vaddr, unsigned bytes, */); /* Initialize segment descriptor to represent 0 bytes at `vaddr'. Do not map the segment. */ extern void XR_ExtendSeg (/* XR_Seg seg, unsigned bytes */); /* Extend size of shared memory segment described in `seg' by `bytes'. Do not map the segment. */ extern void XR_InitSeg (/* XR_Seg seg, XR_Pointer vaddr */); extern XR_Pointer XR_InitSharedHeapMem(/* unsigned nBytes */); /* Initialize heap, with given max size. This doesn't map the memory, just reserves it. Call once during initialization (before FORK). Return address of reserved vm, or NIL if failed. */ extern int /* -errno */ XR_MapSharedHeapSeg(/* XR_Seg seg */); /* Arrange for page-aligned region of heap memory (described by seg) to be mapped and shared among all VPs and IOPs. The segment should not already be mapped. Call during initialization (before FORK) or from a thread. Return 0 on success. */ extern bool XR_ApplyToSysMem(/* bool (*proc)(void *start, void *limit, void *clientData), void *clientData */); /* Apply proc to every area of shared system memory that is "interesting" -- i.e. might be a root for the garbage collector. This includes the thread descriptors and thread stacks. It does not include PCR data or bss. Won't crash if the world is running, but it's only meaningful if the world is stopped. The enumeration terminates if proc ever returns FALSE. Result is last value returned by proc. */ #endif _XR_THREADS_SHARED_MEM_