source: trunk/src/emx/src/lib/sys/DosEx.h@ 1676

Last change on this file since 1676 was 1676, checked in by bird, 21 years ago

Fixed fork() problem by adding DosLoadModuleEx and DosFreeModuleEx. (also fixed heap problem)

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: DosEx.h 1676 2004-12-02 01:42:51Z bird $ */
2/** @file
3 *
4 * Dos API Extension Fundament.
5 *
6 * Copyright (c) 2004 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of InnoTek LIBC.
10 *
11 * InnoTek LIBC is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * InnoTek LIBC is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with InnoTek LIBC; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef __DosEx_h__
28#define __DosEx_h__
29
30#include <sys/cdefs.h>
31
32/**
33 * Entry type.
34 */
35typedef enum
36{
37 /** This block is free. */
38 DOSEX_TYPE_FREE = 0,
39 /** Allocation. */
40 DOSEX_TYPE_MEM_ALLOC,
41 /** Shared allocation. */
42 DOSEX_TYPE_MEM_OPEN,
43 /** Mutex create. */
44 DOSEX_TYPE_MUTEX_CREATE,
45 /** Mutex open. */
46 DOSEX_TYPE_MUTEX_OPEN,
47 /** Event create. */
48 DOSEX_TYPE_EVENT_CREATE,
49 /** Event open. */
50 DOSEX_TYPE_EVENT_OPEN,
51 /** Load module. */
52 DOSEX_TYPE_LOAD_MODULE,
53 /** Max type (exclusive). */
54 DOSEX_TYPE_MAX
55} DOSEXTYPE;
56
57
58/**
59 * Fixed size record for recording an extended Dos operation.
60 *
61 * @remark Make sure this structure have a nice size.
62 */
63#pragma pack(1)
64typedef struct _DOSEXENTRY
65{
66 /** Next pointer. */
67 struct _DOSEXENTRY *pNext;
68
69 /** Type specific data. */
70 union
71 {
72 /** Search key.
73 * We assume that sizeof(unsigned) == sizeof(PVOID) == sizeof(HMTX) == sizeof(HEV) == sizeof(HMODULE).
74 */
75 unsigned uKey;
76
77 /**
78 * DosAllocMemEx with OBJ_FORK.
79 */
80 struct
81 {
82 /** Object address. */
83 PVOID pv;
84 /** Object size. */
85 ULONG cb;
86 /** Object flags. */
87 ULONG flFlags;
88 } MemAlloc;
89
90 /**
91 * Shared memory.
92 * (Must be givable!)
93 */
94 struct
95 {
96 /** Object address. */
97 PVOID pv;
98 /** Open flags. */
99 ULONG flFlags;
100 /** Open count. */
101 unsigned cOpens;
102 } MemOpen;
103
104 /**
105 * Create mutex.
106 */
107 struct
108 {
109 /** Mutex handle. */
110 HMTX hmtx;
111 /** Flags. */
112 ULONG flFlags;
113 /** Initial state. */
114 unsigned short fInitialState;
115 /** Current state. */
116 unsigned short cCurState;
117 } MutexCreate;
118
119 /**
120 * Open mutex.
121 */
122 struct
123 {
124 /** Mutex handle. */
125 HMTX hmtx;
126 /** Open count. */
127 unsigned cOpens;
128 } MutexOpen;
129
130 /**
131 * Create event.
132 */
133 struct
134 {
135 /** Event handle. */
136 HEV hev;
137 /** Flags. */
138 ULONG flFlags;
139 /** Initial state. */
140 unsigned short fInitialState;
141 /** Current state. */
142 unsigned short cCurState;
143 } EventCreate;
144
145 /**
146 * Open mutex.
147 */
148 struct
149 {
150 /** Mutex handle. */
151 HEV hev;
152 /** Open count. */
153 unsigned cOpens;
154 } EventOpen;
155
156 /**
157 * Loaded module.
158 */
159 struct
160 {
161 /** Module handle. */
162 HMODULE hmte;
163 /** Load count. */
164 unsigned cLoads;
165 } LoadModule;
166 } u;
167} DOSEX;
168#pragma pack()
169/** Pointer to DoxEx record. */
170typedef DOSEX *PDOSEX;
171
172
173__BEGIN_DECLS
174
175/** The current size of allocated private memory.
176 * Updated atomically. */
177extern size_t __libc_gcbDosExMemAlloc;
178
179
180/**
181 * Allocate an entry.
182 * @returns Pointer to allocated entry.
183 * @returns NULL on memory shortage.
184 * @param enmType Entry type.
185 */
186PDOSEX __libc_dosexAlloc(DOSEXTYPE enmType);
187
188/**
189 * Free entry.
190 * @returns 0 on success.
191 * @returns -1 if not found.
192 * @returns OS/2 error code on failure.
193 * @param enmType Enter type.
194 * @param uKey They entry key.
195 * @remark Caller is responsible for saving/loading/restoring FS.
196 */
197int __libc_dosexFree(DOSEXTYPE enmType, unsigned uKey);
198
199/**
200 * Finds a entry given by type and key.
201 *
202 * @returns Pointer to the entry on success.
203 * The caller _must_ call __libc_dosexRelease() with this pointer!
204 * @returns NULL on failure.
205 *
206 * @param enmType Type of the entry to find.
207 * @param uKey Entery key.
208 */
209PDOSEX __libc_dosexFind(DOSEXTYPE enmType, unsigned uKey);
210
211/**
212 * Releases an entry obtained by __libc_dosexFind().
213 * @param pEntry Pointer to the entry to release.
214 */
215void __libc_dosexRelease(PDOSEX pEntry);
216
217/**
218 * Get the memory stats.
219 *
220 * This api is intended for fork when it's figuring out the minimum and maximum
221 * sizes of the fork buffer.
222 *
223 * @param pcbPools Where to store the size of the pools.
224 * @param pcbMemAlloc Where to store the size of the allocated private memory.
225 * I.e. memory allocated by DosAllocMemEx(,,..|OBJ_FORK).
226 */
227void __libc_dosexGetMemStats(size_t *pcbPools, size_t *pcbMemAlloc);
228
229#ifdef __InnoTekLIBC_fork_h__
230/**
231 * This function is called very early in the fork, before any
232 * datasegments are copied or anything. The purpose is to
233 * allocate system resources as early to get the best chance to
234 * get hold of them.
235 *
236 * @returns 0 on success.
237 * @returns -errno on failure.
238 * @param pForkHandle Pointer to the fork handle.
239 */
240int __libc_dosexFork(__LIBC_PFORKHANDLE pForkHandle);
241#endif
242
243__END_DECLS
244#endif
Note: See TracBrowser for help on using the repository browser.