1*e93f7393Sniklas /* 2*e93f7393Sniklas * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC. 3*e93f7393Sniklas * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY 4*e93f7393Sniklas * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION 5*e93f7393Sniklas * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems 6*e93f7393Sniklas * To anyone who acknowledges that this file is provided "AS IS" without 7*e93f7393Sniklas * any express or implied warranty: permission to use, copy, modify, and 8*e93f7393Sniklas * distribute this file for any purpose is hereby granted without fee, 9*e93f7393Sniklas * provided that the above copyright notices and this notice appears in 10*e93f7393Sniklas * all source code copies, and that none of the names listed above be used 11*e93f7393Sniklas * in advertising or publicity pertaining to distribution of the software 12*e93f7393Sniklas * without specific, written prior permission. None of these organizations 13*e93f7393Sniklas * makes any representations about the suitability of this software for 14*e93f7393Sniklas * any purpose. 15*e93f7393Sniklas */ 16*e93f7393Sniklas /* 17*e93f7393Sniklas * Header file for stack management (internal to cma_stack.c, but 18*e93f7393Sniklas * separate for convenience, and unit testing). 19*e93f7393Sniklas */ 20*e93f7393Sniklas 21*e93f7393Sniklas #ifndef CMA_STACK_INT 22*e93f7393Sniklas #define CMA_STACK_INT 23*e93f7393Sniklas 24*e93f7393Sniklas /* 25*e93f7393Sniklas * INCLUDE FILES 26*e93f7393Sniklas */ 27*e93f7393Sniklas 28*e93f7393Sniklas #include <cma.h> 29*e93f7393Sniklas #include <cma_queue.h> 30*e93f7393Sniklas #include <cma_list.h> 31*e93f7393Sniklas #include <cma_tcb_defs.h> 32*e93f7393Sniklas 33*e93f7393Sniklas /* 34*e93f7393Sniklas * CONSTANTS AND MACROS 35*e93f7393Sniklas */ 36*e93f7393Sniklas 37*e93f7393Sniklas #define cma___c_first_free_chunk 0 38*e93f7393Sniklas #define cma___c_min_count 2 /* Smallest number of chunks to leave */ 39*e93f7393Sniklas #define cma___c_end (-1) /* End of free list (flag) */ 40*e93f7393Sniklas #define cma__c_yellow_size 0 41*e93f7393Sniklas 42*e93f7393Sniklas /* 43*e93f7393Sniklas * Cluster types 44*e93f7393Sniklas */ 45*e93f7393Sniklas #define cma___c_cluster 0 /* Default cluster */ 46*e93f7393Sniklas #define cma___c_bigstack 1 /* Looks like a cluster, but it's a stack */ 47*e93f7393Sniklas 48*e93f7393Sniklas 49*e93f7393Sniklas #define cma___c_null_cluster (cma___t_cluster *)cma_c_null_ptr 50*e93f7393Sniklas 51*e93f7393Sniklas 52*e93f7393Sniklas /* 53*e93f7393Sniklas * TYPEDEFS 54*e93f7393Sniklas */ 55*e93f7393Sniklas 56*e93f7393Sniklas #ifndef __STDC__ 57*e93f7393Sniklas struct CMA__T_INT_STACK; 58*e93f7393Sniklas #endif 59*e93f7393Sniklas 60*e93f7393Sniklas typedef cma_t_natural cma___t_index; /* Type for chunk index */ 61*e93f7393Sniklas 62*e93f7393Sniklas typedef struct CMA___T_CLU_DESC { 63*e93f7393Sniklas cma__t_list list; /* Queue element for cluster list */ 64*e93f7393Sniklas cma_t_integer type; /* Type of cluster */ 65*e93f7393Sniklas cma_t_address stacks; 66*e93f7393Sniklas cma_t_address limit; 67*e93f7393Sniklas } cma___t_clu_desc; 68*e93f7393Sniklas 69*e93f7393Sniklas typedef union CMA___T_MAP_ENTRY { 70*e93f7393Sniklas struct { 71*e93f7393Sniklas cma__t_int_tcb *tcb; /* TCB associated with stack chunk */ 72*e93f7393Sniklas struct CMA__T_INT_STACK *stack; /* Stack desc. ass. with stack chunk */ 73*e93f7393Sniklas } mapped; 74*e93f7393Sniklas struct { 75*e93f7393Sniklas cma___t_index size; /* Number of chunks in block */ 76*e93f7393Sniklas cma___t_index next; /* Next free block */ 77*e93f7393Sniklas } free; 78*e93f7393Sniklas } cma___t_map_entry; 79*e93f7393Sniklas 80*e93f7393Sniklas /* 81*e93f7393Sniklas * NOTE: It is VERY IMPORTANT that both cma___t_cluster and cma___t_bigstack 82*e93f7393Sniklas * begin with the cma___t_clu_desc structure, as there is some code in the 83*e93f7393Sniklas * stack manager that relies on being able to treat both as equivalent! 84*e93f7393Sniklas */ 85*e93f7393Sniklas typedef struct CMA___T_CLUSTER { 86*e93f7393Sniklas cma___t_clu_desc desc; /* Describe this cluster */ 87*e93f7393Sniklas cma___t_map_entry map[cma__c_chunk_count]; /* thread map */ 88*e93f7393Sniklas cma___t_index free; /* First free chunk index */ 89*e93f7393Sniklas } cma___t_cluster; 90*e93f7393Sniklas 91*e93f7393Sniklas /* 92*e93f7393Sniklas * NOTE: It is VERY IMPORTANT that both cma___t_cluster and cma___t_bigstack 93*e93f7393Sniklas * begin with the cma___t_clu_desc structure, as there is some code in the 94*e93f7393Sniklas * stack manager that relies on being able to treat both as equivalent! 95*e93f7393Sniklas */ 96*e93f7393Sniklas typedef struct CMA___T_BIGSTACK { 97*e93f7393Sniklas cma___t_clu_desc desc; /* Describe this cluster */ 98*e93f7393Sniklas cma__t_int_tcb *tcb; /* TCB associated with stack */ 99*e93f7393Sniklas struct CMA__T_INT_STACK *stack; /* Stack desc. ass. with stack */ 100*e93f7393Sniklas cma_t_natural size; /* Size of big stack */ 101*e93f7393Sniklas cma_t_boolean in_use; /* Set if allocated */ 102*e93f7393Sniklas } cma___t_bigstack; 103*e93f7393Sniklas 104*e93f7393Sniklas #if _CMA_PROTECT_MEMORY_ 105*e93f7393Sniklas typedef struct CMA___T_INT_HOLE { 106*e93f7393Sniklas cma__t_queue link; /* Link holes together */ 107*e93f7393Sniklas cma_t_boolean protected; /* Set when pages are protected */ 108*e93f7393Sniklas cma_t_address first; /* First protected byte */ 109*e93f7393Sniklas cma_t_address last; /* Last protected byte */ 110*e93f7393Sniklas } cma___t_int_hole; 111*e93f7393Sniklas #endif 112*e93f7393Sniklas 113*e93f7393Sniklas typedef struct CMA__T_INT_STACK { 114*e93f7393Sniklas cma__t_object header; /* Common header (sequence, type info */ 115*e93f7393Sniklas cma__t_int_attr *attributes; /* Backpointer to attr obj */ 116*e93f7393Sniklas cma___t_cluster *cluster; /* Stack's cluster */ 117*e93f7393Sniklas cma_t_address stack_base; /* base address of stack */ 118*e93f7393Sniklas cma_t_address yellow_zone; /* first address of yellow zone */ 119*e93f7393Sniklas cma_t_address last_guard; /* last address of guard pages */ 120*e93f7393Sniklas cma_t_natural first_chunk; /* First chunk allocated */ 121*e93f7393Sniklas cma_t_natural chunk_count; /* Count of chunks allocated */ 122*e93f7393Sniklas cma__t_int_tcb *tcb; /* TCB backpointer */ 123*e93f7393Sniklas #if _CMA_PROTECT_MEMORY_ 124*e93f7393Sniklas cma___t_int_hole hole; /* Description of hole */ 125*e93f7393Sniklas #endif 126*e93f7393Sniklas } cma__t_int_stack; 127*e93f7393Sniklas 128*e93f7393Sniklas /* 129*e93f7393Sniklas * GLOBAL DATA 130*e93f7393Sniklas */ 131*e93f7393Sniklas 132*e93f7393Sniklas /* 133*e93f7393Sniklas * INTERNAL INTERFACES 134*e93f7393Sniklas */ 135*e93f7393Sniklas 136*e93f7393Sniklas #endif 137