1 /* Copyright (C) 1993, 1994, 1999 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: imemory.h,v 1.2.6.1.2.1 2003/01/17 00:49:04 giles Exp $ */
20 /* Ghostscript memory allocator extensions for interpreter level */
21 
22 #ifndef imemory_INCLUDED
23 #  define imemory_INCLUDED
24 
25 #include "ivmspace.h"
26 
27 /*
28  * The interpreter level of Ghostscript defines a "subclass" extension
29  * of the allocator interface in gsmemory.h, by adding the ability to
30  * allocate and free arrays of refs, and by adding the distinction
31  * between local, global, and system allocation.
32  */
33 
34 #include "gsalloc.h"
35 
36 #ifndef gs_ref_memory_DEFINED
37 #  define gs_ref_memory_DEFINED
38 typedef struct gs_ref_memory_s gs_ref_memory_t;
39 #endif
40 
41 	/* Allocate a ref array. */
42 
43 int gs_alloc_ref_array(P5(gs_ref_memory_t * mem, ref * paref,
44 			  uint attrs, uint num_refs, client_name_t cname));
45 
46 	/* Resize a ref array. */
47 	/* Currently this is only implemented for shrinking, */
48 	/* not growing. */
49 
50 int gs_resize_ref_array(P4(gs_ref_memory_t * mem, ref * paref,
51 			   uint new_num_refs, client_name_t cname));
52 
53 	/* Free a ref array. */
54 
55 void gs_free_ref_array(P3(gs_ref_memory_t * mem, ref * paref,
56 			  client_name_t cname));
57 
58 	/* Allocate a string ref. */
59 
60 int gs_alloc_string_ref(P5(gs_ref_memory_t * mem, ref * psref,
61 			   uint attrs, uint nbytes, client_name_t cname));
62 
63 /* Register a ref root.  This just calls gs_register_root. */
64 /* Note that ref roots are a little peculiar: they assume that */
65 /* the ref * that they point to points to a *statically* allocated ref. */
66 int gs_register_ref_root(P4(gs_memory_t *mem, gs_gc_root_t *root,
67 			    void **pp, client_name_t cname));
68 
69 
70 /*
71  * The interpreter allocator can allocate in either local or global VM,
72  * and can switch between the two dynamically.  In Level 1 configurations,
73  * global VM is the same as local; however, this is *not* currently true in
74  * a Level 2 system running in Level 1 mode.  In addition, there is a third
75  * VM space, system VM, that exists in both modes and is used for objects
76  * that must not be affected by even the outermost save/restore (stack
77  * segments and names).
78  *
79  * NOTE: since the interpreter's (only) instances of gs_dual_memory_t are
80  * embedded in-line in context state structures, pointers to these
81  * instances must not be stored anywhere that might persist across a
82  * garbage collection.
83  */
84 #ifndef gs_dual_memory_DEFINED
85 #  define gs_dual_memory_DEFINED
86 typedef struct gs_dual_memory_s gs_dual_memory_t;
87 #endif
88 struct gs_dual_memory_s {
89     gs_ref_memory_t *current;	/* = ...global or ...local */
90     vm_spaces spaces;		/* system, global, local */
91     uint current_space;		/* = current->space */
92     /* Garbage collection hook */
93     int (*reclaim) (P2(gs_dual_memory_t *, int));
94     /* Masks for store checking, see isave.h. */
95     uint test_mask;
96     uint new_mask;
97 };
98 
99 #define public_st_gs_dual_memory()	/* in ialloc.c */\
100   gs_public_st_simple(st_gs_dual_memory, gs_dual_memory_t, "gs_dual_memory_t")
101 #define st_gs_dual_memory_num_ptrs 0
102 
103 #endif /* imemory_INCLUDED */
104