| 1 | /* $Id: DosEx.h 1519 2004-09-27 02:15:07Z 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 | */
|
|---|
| 35 | typedef 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 | /** Max type (exclusive). */
|
|---|
| 52 | DOSEX_TYPE_MAX
|
|---|
| 53 | } DOSEXTYPE;
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | /**
|
|---|
| 57 | * Fixed size record for recording an extended Dos operation.
|
|---|
| 58 | *
|
|---|
| 59 | * @remark Make sure this structure have a nice size.
|
|---|
| 60 | */
|
|---|
| 61 | #pragma pack(1)
|
|---|
| 62 | typedef struct _DOSEXENTRY
|
|---|
| 63 | {
|
|---|
| 64 | /** Next pointer. */
|
|---|
| 65 | struct _DOSEXENTRY *pNext;
|
|---|
| 66 |
|
|---|
| 67 | /** Type specific data. */
|
|---|
| 68 | union
|
|---|
| 69 | {
|
|---|
| 70 | /** Search key.
|
|---|
| 71 | * We assume that sizeof(unsigned) == sizeof(PVOID) == sizeof(HMTX) == sizeof(HEV).
|
|---|
| 72 | */
|
|---|
| 73 | unsigned uKey;
|
|---|
| 74 |
|
|---|
| 75 | /**
|
|---|
| 76 | * DosAllocMemEx with OBJ_FORK.
|
|---|
| 77 | */
|
|---|
| 78 | struct
|
|---|
| 79 | {
|
|---|
| 80 | /** Object address. */
|
|---|
| 81 | PVOID pv;
|
|---|
| 82 | /** Object size. */
|
|---|
| 83 | ULONG cb;
|
|---|
| 84 | /** Object flags. */
|
|---|
| 85 | ULONG flFlags;
|
|---|
| 86 | } MemAlloc;
|
|---|
| 87 |
|
|---|
| 88 | /**
|
|---|
| 89 | * Shared memory.
|
|---|
| 90 | * (Must be givable!)
|
|---|
| 91 | */
|
|---|
| 92 | struct
|
|---|
| 93 | {
|
|---|
| 94 | /** Object address. */
|
|---|
| 95 | PVOID pv;
|
|---|
| 96 | /** Open flags. */
|
|---|
| 97 | ULONG flFlags;
|
|---|
| 98 | /** Open count. */
|
|---|
| 99 | unsigned cOpens;
|
|---|
| 100 | } MemOpen;
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * Create mutex.
|
|---|
| 104 | */
|
|---|
| 105 | struct
|
|---|
| 106 | {
|
|---|
| 107 | /** Mutex handle. */
|
|---|
| 108 | HMTX hmtx;
|
|---|
| 109 | /** Flags. */
|
|---|
| 110 | ULONG flFlags;
|
|---|
| 111 | /** Initial state. */
|
|---|
| 112 | unsigned short fInitialState;
|
|---|
| 113 | /** Current state. */
|
|---|
| 114 | unsigned short cCurState;
|
|---|
| 115 | } MutexCreate;
|
|---|
| 116 |
|
|---|
| 117 | /**
|
|---|
| 118 | * Open mutex.
|
|---|
| 119 | */
|
|---|
| 120 | struct
|
|---|
| 121 | {
|
|---|
| 122 | /** Mutex handle. */
|
|---|
| 123 | HMTX hmtx;
|
|---|
| 124 | /** Open count. */
|
|---|
| 125 | unsigned cOpens;
|
|---|
| 126 | } MutexOpen;
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * Create event.
|
|---|
| 130 | */
|
|---|
| 131 | struct
|
|---|
| 132 | {
|
|---|
| 133 | /** Event handle. */
|
|---|
| 134 | HEV hev;
|
|---|
| 135 | /** Flags. */
|
|---|
| 136 | ULONG flFlags;
|
|---|
| 137 | /** Initial state. */
|
|---|
| 138 | unsigned short fInitialState;
|
|---|
| 139 | /** Current state. */
|
|---|
| 140 | unsigned short cCurState;
|
|---|
| 141 | } EventCreate;
|
|---|
| 142 |
|
|---|
| 143 | /**
|
|---|
| 144 | * Open mutex.
|
|---|
| 145 | */
|
|---|
| 146 | struct
|
|---|
| 147 | {
|
|---|
| 148 | /** Mutex handle. */
|
|---|
| 149 | HEV hev;
|
|---|
| 150 | /** Open count. */
|
|---|
| 151 | unsigned cOpens;
|
|---|
| 152 | } EventOpen;
|
|---|
| 153 | } u;
|
|---|
| 154 | } DOSEX;
|
|---|
| 155 | #pragma pack()
|
|---|
| 156 | /** Pointer to DoxEx record. */
|
|---|
| 157 | typedef DOSEX *PDOSEX;
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | __BEGIN_DECLS
|
|---|
| 161 |
|
|---|
| 162 | /** The current size of allocated private memory.
|
|---|
| 163 | * Updated atomically. */
|
|---|
| 164 | extern size_t __libc_gcbDosExMemAlloc;
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | /**
|
|---|
| 168 | * Allocate an entry.
|
|---|
| 169 | * @returns Pointer to allocated entry.
|
|---|
| 170 | * @returns NULL on memory shortage.
|
|---|
| 171 | * @param enmType Entry type.
|
|---|
| 172 | */
|
|---|
| 173 | PDOSEX __libc_dosexAlloc(DOSEXTYPE enmType);
|
|---|
| 174 |
|
|---|
| 175 | /**
|
|---|
| 176 | * Free entry.
|
|---|
| 177 | * @returns 0 on success.
|
|---|
| 178 | * @returns -1 if not found.
|
|---|
| 179 | * @returns OS/2 error code on failure.
|
|---|
| 180 | * @param enmType Enter type.
|
|---|
| 181 | * @param uKey They entry key.
|
|---|
| 182 | * @remark Caller is responsible for saving/loading/restoring FS.
|
|---|
| 183 | */
|
|---|
| 184 | int __libc_dosexFree(DOSEXTYPE enmType, unsigned uKey);
|
|---|
| 185 |
|
|---|
| 186 | /**
|
|---|
| 187 | * Finds a entry given by type and key.
|
|---|
| 188 | *
|
|---|
| 189 | * @returns Pointer to the entry on success.
|
|---|
| 190 | * The caller _must_ call __libc_dosexRelease() with this pointer!
|
|---|
| 191 | * @returns NULL on failure.
|
|---|
| 192 | *
|
|---|
| 193 | * @param enmType Type of the entry to find.
|
|---|
| 194 | * @param uKey Entery key.
|
|---|
| 195 | */
|
|---|
| 196 | PDOSEX __libc_dosexFind(DOSEXTYPE enmType, unsigned uKey);
|
|---|
| 197 |
|
|---|
| 198 | /**
|
|---|
| 199 | * Releases an entry obtained by __libc_dosexFind().
|
|---|
| 200 | * @param pEntry Pointer to the entry to release.
|
|---|
| 201 | */
|
|---|
| 202 | void __libc_dosexRelease(PDOSEX pEntry);
|
|---|
| 203 |
|
|---|
| 204 | /**
|
|---|
| 205 | * Get the memory stats.
|
|---|
| 206 | *
|
|---|
| 207 | * This api is intended for fork when it's figuring out the minimum and maximum
|
|---|
| 208 | * sizes of the fork buffer.
|
|---|
| 209 | *
|
|---|
| 210 | * @param pcbPools Where to store the size of the pools.
|
|---|
| 211 | * @param pcbMemAlloc Where to store the size of the allocated private memory.
|
|---|
| 212 | * I.e. memory allocated by DosAllocMemEx(,,..|OBJ_FORK).
|
|---|
| 213 | */
|
|---|
| 214 | void __libc_dosexGetMemStats(size_t *pcbPools, size_t *pcbMemAlloc);
|
|---|
| 215 |
|
|---|
| 216 | #ifdef __InnoTekLIBC_fork_h__
|
|---|
| 217 | /**
|
|---|
| 218 | * This function is called very early in the fork, before any
|
|---|
| 219 | * datasegments are copied or anything. The purpose is to
|
|---|
| 220 | * allocate system resources as early to get the best chance to
|
|---|
| 221 | * get hold of them.
|
|---|
| 222 | *
|
|---|
| 223 | * @returns 0 on success.
|
|---|
| 224 | * @returns -errno on failure.
|
|---|
| 225 | * @param pForkHandle Pointer to the fork handle.
|
|---|
| 226 | */
|
|---|
| 227 | int __libc_dosexFork(__LIBC_PFORKHANDLE pForkHandle);
|
|---|
| 228 | #endif
|
|---|
| 229 |
|
|---|
| 230 | __END_DECLS
|
|---|
| 231 | #endif
|
|---|