Release 950216
[wine] / include / heap.h
1 /* $Id: heap.h,v 1.2 1993/07/04 04:04:21 root Exp root $
2  */
3 /*
4  * Copyright  Robert J. Amstadt, 1993
5  */
6 #ifndef HEAP_H
7 #define HEAP_H
8
9 #include "segmem.h"
10 #include "atom.h"
11 #include "stackframe.h"
12
13 /**********************************************************************
14  * LOCAL HEAP STRUCTURES AND FUNCTIONS
15  */
16 typedef struct heap_mem_desc_s
17 {
18     struct heap_mem_desc_s *prev, *next;
19     unsigned short length;
20     unsigned char  lock;
21     unsigned char  flags;
22 } MDESC;
23
24 typedef struct heap_local_heap_s
25 {
26     struct heap_local_heap_s *next;
27     MDESC *free_list;
28     ATOMTABLE *local_table;
29     unsigned short selector;
30     unsigned short delta;               /* Number saved for Windows compat. */
31 } LHEAP;
32
33 extern void HEAP_Init(MDESC **free_list, void *start, int length);
34 extern void *HEAP_Alloc(MDESC **free_list, int flags, int bytes);
35 extern int  HEAP_Free(MDESC **free_list, void *block);
36 extern void *HEAP_ReAlloc(MDESC **free_list, void *old_block, 
37                           int new_size, unsigned int flags);
38
39 extern LHEAP *HEAP_LocalFindHeap(unsigned short owner);
40 extern unsigned int HEAP_LocalSize(MDESC **free_list, unsigned int handle);
41 extern void HEAP_LocalInit(unsigned short owner, void *start, int length);
42
43 extern void *WIN16_LocalAlloc(int flags, int bytes);
44 extern int WIN16_LocalCompact(int min_free);
45 extern unsigned int WIN16_LocalFlags(unsigned int handle);
46 extern unsigned int WIN16_LocalFree(unsigned int handle);
47 extern void *WIN16_LocalLock(unsigned int handle);
48 extern void *WIN16_LocalReAlloc(unsigned int handle, int flags, int bytes);
49 extern unsigned int WIN16_LocalUnlock(unsigned int handle);
50
51 /* Use ds instead of owner of cs */
52 #define HEAP_OWNER      (pStack16Frame->ds)
53 #define LOCALHEAP()     (&HEAP_LocalFindHeap(HEAP_OWNER)->free_list)
54 #define LOCALATOMTABLE() (&HEAP_LocalFindHeap(HEAP_OWNER)->local_table)
55
56 /**********************************************************************
57  * GLOBAL HEAP STRUCTURES AND FUNCTIONS:
58  *
59  * Global memory pool descriptor.  Segments MUST be maintained in segment
60  * ascending order.  If not the reallocation routine will die a horrible
61  * death.
62  *
63  * handle  = 0, this descriptor contains the address of a free pool.
64  *        != 0, this describes an allocated block.
65  *
66  * sequence = 0, this is not a huge block
67  *          > 0, this is a portion of a huge block
68  *          =-1, this is a free segment
69  *
70  * addr       - address of this memory block.
71  *
72  * length     - used to maintain huge blocks.
73  */
74 typedef struct global_mem_desc_s
75 {
76     struct global_mem_desc_s *next;     /* Next GDESC in list              */
77     struct global_mem_desc_s *prev;     /* Previous GDESC in list          */
78     unsigned short handle;              /* Handle of this block.           */
79     short          sequence;            /* Block sequence # in huge block  */
80     void          *addr;                /* Address allocated with mmap()   */
81     int            length;              /* Length of block                 */
82     int            lock_count;          /* Block lock count                */
83     unsigned short alias;               /* Offset-zero alias selector      */
84     unsigned int   alias_key;           /* Offset-zero alias sh. mem. key  */
85     void          *linear_addr;         /* Linear address of huge block    */
86     int            linear_key;          /* Linear shared memory key        */
87     int            linear_count;        /* Linear lock count               */
88 } GDESC;
89
90 extern GDESC *GlobalList;
91
92 extern void *GlobalQuickAlloc(int size);
93 extern unsigned int GlobalHandleFromPointer(void *block);
94 extern GDESC *GlobalGetGDesc(unsigned int block);
95 extern void *GlobalLinearLock(unsigned int block);
96 extern unsigned int GlobalLinearUnlock(unsigned int block);
97
98 #endif /* HEAP_H */