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