| 1 | /** $Id: sharedpm.h 1454 2004-09-04 06:22:38Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | *
|
|---|
| 4 | * LIBC Shared Process Management.
|
|---|
| 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | *
|
|---|
| 8 | * This file is part of InnoTek LIBC.
|
|---|
| 9 | *
|
|---|
| 10 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
|---|
| 11 | * it under the terms of the GNU General Public License as published by
|
|---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 13 | * (at your option) any later version.
|
|---|
| 14 | *
|
|---|
| 15 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 18 | * GNU General Public License for more details.
|
|---|
| 19 | *
|
|---|
| 20 | * You should have received a copy of the GNU General Public License
|
|---|
| 21 | * along with InnoTek LIBC; if not, write to the Free Software
|
|---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 23 | *
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | #ifndef __InnoTekLIBC_sharedpm_h__
|
|---|
| 27 | #define __InnoTekLIBC_sharedpm_h__
|
|---|
| 28 |
|
|---|
| 29 | #include <sys/cdefs.h>
|
|---|
| 30 | #include <sys/types.h>
|
|---|
| 31 |
|
|---|
| 32 | __BEGIN_DECLS
|
|---|
| 33 |
|
|---|
| 34 | /** The name of the shared semaphore protecting the memory. */
|
|---|
| 35 | #define SPM_MUTEX_NAME "\\SEM32\\INNOTEKLIBC.V01"
|
|---|
| 36 |
|
|---|
| 37 | /** The name of the shared memory. */
|
|---|
| 38 | #define SPM_MEMORY_NAME "\\SHAREMEM\\INNOTEKLIBC.V01"
|
|---|
| 39 |
|
|---|
| 40 | /** The timeout for accessing the shared mem semaphore. */
|
|---|
| 41 | #define SPM_MUTEX_TIMEOUT (30*1000)
|
|---|
| 42 |
|
|---|
| 43 | /** Allocate 512KB if OBJ_ANY isn't supported.
|
|---|
| 44 | * If it is supported we allocated the double amount. */
|
|---|
| 45 | #define SPM_MEMORY_SIZE (512*1024)
|
|---|
| 46 |
|
|---|
| 47 | /** The defined max size of a process.
|
|---|
| 48 | * A good bit is reserved for the future here.
|
|---|
| 49 | *
|
|---|
| 50 | * Theoretically speaking, OS/2 cannot entertain more than a 1000 processes.
|
|---|
| 51 | * So, even if we reserve a good bit here it's not gonna cause any trouble.
|
|---|
| 52 | */
|
|---|
| 53 | #define SPM_PROCESS_SIZE (256)
|
|---|
| 54 |
|
|---|
| 55 | /**
|
|---|
| 56 | * The SPM version.
|
|---|
| 57 | */
|
|---|
| 58 | #define SPM_VERSION 0x00010000
|
|---|
| 59 |
|
|---|
| 60 | /**
|
|---|
| 61 | * Process state.
|
|---|
| 62 | */
|
|---|
| 63 | typedef enum __LIBC_SPMPROCSTAT
|
|---|
| 64 | {
|
|---|
| 65 | /** The process is free. */
|
|---|
| 66 | __LIBC_PROCSTATE_FREE = 0,
|
|---|
| 67 | /** The process is waiting for a chile to be created and snatch all the
|
|---|
| 68 | * inherited goodies from it.
|
|---|
| 69 | * If not caught before DosExecPgm/DosStartSession returns
|
|---|
| 70 | * it will be freed by the disapointed parent.
|
|---|
| 71 | */
|
|---|
| 72 | __LIBC_PROCSTATE_EMBRYO = 1,
|
|---|
| 73 | /** The process is running. */
|
|---|
| 74 | __LIBC_PROCSTATE_ALIVE = 2,
|
|---|
| 75 | /** The process is dead but other guys are still using it's data. */
|
|---|
| 76 | __LIBC_PROCSTATE_ZOMBIE = 3,
|
|---|
| 77 | /** The maximum state number (exclusive). */
|
|---|
| 78 | __LIBC_PROCSTATE_MAX = 10,
|
|---|
| 79 | /** Hack to ensure that this will be a 32-bit int. */
|
|---|
| 80 | __LIBC_PROCSTATE_MAKE_INT32 = 0x7fffffff
|
|---|
| 81 | } __LIBC_SPMPROCSTAT;
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | * Process termination reason.
|
|---|
| 85 | */
|
|---|
| 86 | typedef enum __LIBC_EXIT_REASON
|
|---|
| 87 | {
|
|---|
| 88 | /** No reason. */
|
|---|
| 89 | __LIBC_EXIT_REASON_NONE = 0,
|
|---|
| 90 | /** Normal exit. */
|
|---|
| 91 | __LIBC_EXIT_REASON_EXIT = 1,
|
|---|
| 92 | /** OS/2 hard error. */
|
|---|
| 93 | __LIBC_EXIT_REASON_HARDERROR = 2,
|
|---|
| 94 | /** Trap (i.e. 16-bit?). */
|
|---|
| 95 | __LIBC_EXIT_REASON_TRAP = 3,
|
|---|
| 96 | /** Kill process. */
|
|---|
| 97 | __LIBC_EXIT_REASON_KILL = 4,
|
|---|
| 98 | /** Exception. */
|
|---|
| 99 | __LIBC_EXIT_REASON_XCPT = 5,
|
|---|
| 100 | /** Signal base. */
|
|---|
| 101 | __LIBC_EXIT_REASON_SIGNAL_BASE = 32,
|
|---|
| 102 | /** Signal max. */
|
|---|
| 103 | __LIBC_EXIT_REASON_SIGNAL_MAX = 256,
|
|---|
| 104 | /** Hack to ensure that this will be a 32-bit int. */
|
|---|
| 105 | __LIBC_EXIT_REASON_MAKE_INT32 = 0x7fffffff
|
|---|
| 106 | } __LIBC_EXIT_REASON;
|
|---|
| 107 |
|
|---|
| 108 | /** Inheritance FH Bundle Type.
|
|---|
| 109 | * @{ */
|
|---|
| 110 | /** Termination bundle. */
|
|---|
| 111 | #define __LIBC_SPM_INH_FHB_TYPE_END (0)
|
|---|
| 112 | /** Standard bundle. */
|
|---|
| 113 | #define __LIBC_SPM_INH_FHB_TYPE_STANDARD (0x10 | sizeof(unsigned))
|
|---|
| 114 | /** Socket bundle, using the BSD 4.4 backend. */
|
|---|
| 115 | #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44 (0x20 | (sizeof(unsigned) + sizeof(unsigned short)))
|
|---|
| 116 | /** Socket bundle, using the BSD 4.3 backend. */
|
|---|
| 117 | #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43 (0x30 | (sizeof(unsigned) + sizeof(unsigned short)))
|
|---|
| 118 | /** Get the per file handle size from the bundle type. */
|
|---|
| 119 | #define __LIBC_SPM_INH_FHB_SIZE(type) ((type) & 0x0f)
|
|---|
| 120 | /** @} */
|
|---|
| 121 |
|
|---|
| 122 | /**
|
|---|
| 123 | * SPM Inheritance File Handle Bundle Header.
|
|---|
| 124 | */
|
|---|
| 125 | #pragma pack(1)
|
|---|
| 126 | typedef struct __libc_SPMInhFHBHdr
|
|---|
| 127 | {
|
|---|
| 128 | /** Bundle type. */
|
|---|
| 129 | unsigned char uchType;
|
|---|
| 130 | /** Cound of handles in this bundle. */
|
|---|
| 131 | unsigned char cHandles;
|
|---|
| 132 | /** Start handle number. */
|
|---|
| 133 | unsigned short fhStart;
|
|---|
| 134 | } __LIBC_SPMINHFHBHDR;
|
|---|
| 135 | #pragma pack()
|
|---|
| 136 | /** Pointer to SPM filehandle bundle header. */
|
|---|
| 137 | typedef __LIBC_SPMINHFHBHDR *__LIBC_PSPMINHFHBHDR;
|
|---|
| 138 |
|
|---|
| 139 | /**
|
|---|
| 140 | * SPM standard filehandle inherit bundle
|
|---|
| 141 | * This is used for OS/2 filehandles which only needs flags
|
|---|
| 142 | * transfered.
|
|---|
| 143 | */
|
|---|
| 144 | #pragma pack(1)
|
|---|
| 145 | typedef struct __libc_SPMInhFH
|
|---|
| 146 | {
|
|---|
| 147 | /** The common bundle header. */
|
|---|
| 148 | __LIBC_SPMINHFHBHDR Hdr;
|
|---|
| 149 | /** Array of flags of Hdr.cHandles entries. */
|
|---|
| 150 | unsigned afFlags[1];
|
|---|
| 151 | } __LIBC_SPMINHFHBSTD;
|
|---|
| 152 | #pragma pack()
|
|---|
| 153 | /** Pointer to SPM standard filehandle inherit bundle. */
|
|---|
| 154 | typedef __LIBC_SPMINHFHBSTD *__LIBC_PSPMINHFHBSTD;
|
|---|
| 155 |
|
|---|
| 156 | /**
|
|---|
| 157 | * SPM socket filehandle inherit bundle.
|
|---|
| 158 | *
|
|---|
| 159 | * This is used for both BSD 4.3 and 4.4 sockets. The data needed
|
|---|
| 160 | * here is the flags and the socket number.
|
|---|
| 161 | */
|
|---|
| 162 | #pragma pack(1)
|
|---|
| 163 | typedef struct __libc_SPMInhFHSocket
|
|---|
| 164 | {
|
|---|
| 165 | /** The common bundle header. */
|
|---|
| 166 | __LIBC_SPMINHFHBHDR Hdr;
|
|---|
| 167 | /** Array of flags of Hdr.cHandles entries. */
|
|---|
| 168 | struct
|
|---|
| 169 | {
|
|---|
| 170 | /** The file handle flags. */
|
|---|
| 171 | unsigned fFlags;
|
|---|
| 172 | /** The socket number. */
|
|---|
| 173 | unsigned short usSocket;
|
|---|
| 174 | } aHandles[1];
|
|---|
| 175 | } __LIBC_SPMINHFHBSOCK;
|
|---|
| 176 | #pragma pack()
|
|---|
| 177 | /** Pointer to SPM socket filehandle inherit bundle. */
|
|---|
| 178 | typedef __LIBC_SPMINHFHBSOCK *__LIBC_PSPMINHFHBSOCK;
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | /**
|
|---|
| 182 | * Inherit structure.
|
|---|
| 183 | *
|
|---|
| 184 | * All the data it contains is allocated in one block heap block!
|
|---|
| 185 | */
|
|---|
| 186 | typedef struct __libc_SPMInherit
|
|---|
| 187 | {
|
|---|
| 188 | /** Size of the inherit structure. */
|
|---|
| 189 | size_t cb;
|
|---|
| 190 | /** Pointer to the filehandle part.
|
|---|
| 191 | * This is a succession of bundles terminating with a _END one. */
|
|---|
| 192 | __LIBC_PSPMINHFHBHDR pFHBundles;
|
|---|
| 193 |
|
|---|
| 194 | /** @todo Add signals and the other properties which are inherited. */
|
|---|
| 195 | } __LIBC_SPMINHERIT;
|
|---|
| 196 | /** Pointer to inherit data. */
|
|---|
| 197 | typedef __LIBC_SPMINHERIT *__LIBC_PSPMINHERIT;
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 | /**
|
|---|
| 201 | * Per Process Data.
|
|---|
| 202 | */
|
|---|
| 203 | typedef struct __libc_SPMProcess
|
|---|
| 204 | {
|
|---|
| 205 | /** Pointer to the next process in the list.
|
|---|
| 206 | * Every process is in one or another list depending on their state. */
|
|---|
| 207 | struct __libc_SPMProcess *pNext;
|
|---|
| 208 | /** Version of the SPM which created this process. */
|
|---|
| 209 | unsigned uVersion;
|
|---|
| 210 | /** Number of references to this process.
|
|---|
| 211 | * A process is not actually free till the reference count
|
|---|
| 212 | * reaches 0. */
|
|---|
| 213 | unsigned cReferences;
|
|---|
| 214 | /** Process id. */
|
|---|
| 215 | pid_t pid;
|
|---|
| 216 | /** Process id of parent. */
|
|---|
| 217 | pid_t pidParent;
|
|---|
| 218 | /** State of this process. */
|
|---|
| 219 | __LIBC_SPMPROCSTAT enmState;
|
|---|
| 220 | /** The SPM open count of this process. */
|
|---|
| 221 | unsigned cSPMOpens;
|
|---|
| 222 | /** Exit code. */
|
|---|
| 223 | int iExitCode;
|
|---|
| 224 | /** Reason code. */
|
|---|
| 225 | __LIBC_EXIT_REASON enmDeathReason;
|
|---|
| 226 | /** Pointer to fork module list head. */
|
|---|
| 227 | void * volatile pvModuleHead;
|
|---|
| 228 | /** Pointer to fork module list tail pointer. */
|
|---|
| 229 | void * volatile * volatile ppvModuleTail;
|
|---|
| 230 | /** Pointer to fork handle which a child should use when spawned by fork(). */
|
|---|
| 231 | void *pvForkHandle;
|
|---|
| 232 |
|
|---|
| 233 | /** Reserved pool pointer field with default value 0. */
|
|---|
| 234 | unsigned aReserved[40 - 12];
|
|---|
| 235 |
|
|---|
| 236 | /** Number of possible pointers to shared memory starting at pvInherit.
|
|---|
| 237 | * This means we can extend the structure with pointers for as long as we
|
|---|
| 238 | * want and still have older LIBC versions cleanup the mess. */
|
|---|
| 239 | unsigned cPoolPointers;
|
|---|
| 240 | /** Pointer to data inherited from the parent process. */
|
|---|
| 241 | __LIBC_PSPMINHERIT pInherit;
|
|---|
| 242 | } __LIBC_SPMPROCESS, *__LIBC_PSPMPROCESS;
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 | /**
|
|---|
| 246 | * Pool chunk.
|
|---|
| 247 | */
|
|---|
| 248 | typedef struct __libc_SPMPoolChunk
|
|---|
| 249 | {
|
|---|
| 250 | /** Next block in the list of all blocks.. */
|
|---|
| 251 | struct __libc_SPMPoolChunk *pPrev;
|
|---|
| 252 | /** Previous block in the list of all blocks.. */
|
|---|
| 253 | struct __libc_SPMPoolChunk *pNext;
|
|---|
| 254 | } __LIBC_SPMPOOLCHUNK, *__LIBC_PSPMPOOLCHUNK;
|
|---|
| 255 |
|
|---|
| 256 | /**
|
|---|
| 257 | * Free pool chunk.
|
|---|
| 258 | */
|
|---|
| 259 | typedef struct __libc_SPMPoolChunkFree
|
|---|
| 260 | {
|
|---|
| 261 | /** Main list. */
|
|---|
| 262 | __LIBC_SPMPOOLCHUNK core;
|
|---|
| 263 | /** Next block in list of free nodes. */
|
|---|
| 264 | struct __libc_SPMPoolChunkFree *pPrev;
|
|---|
| 265 | /** Previous block in list of free nodes. */
|
|---|
| 266 | struct __libc_SPMPoolChunkFree *pNext;
|
|---|
| 267 | /** Size of this block. */
|
|---|
| 268 | size_t cb;
|
|---|
| 269 | } __LIBC_SPMPOOLCHUNKFREE, *__LIBC_PSPMPOOLCHUNKFREE;
|
|---|
| 270 |
|
|---|
| 271 | /**
|
|---|
| 272 | * Pool chunk alignment.
|
|---|
| 273 | */
|
|---|
| 274 | #define SPM_POOL_ALIGN(size) (((size) + 7) & ~7)
|
|---|
| 275 |
|
|---|
| 276 | /**
|
|---|
| 277 | * This structure contains the global TCP/IP socket data.
|
|---|
| 278 | */
|
|---|
| 279 | typedef struct __libc_SPMTcpIp
|
|---|
| 280 | {
|
|---|
| 281 | /** Size of the structure. */
|
|---|
| 282 | size_t cb;
|
|---|
| 283 | /** The number of elements in the acRefs array. */
|
|---|
| 284 | unsigned cSockets;
|
|---|
| 285 | /** Array containing the references counters for the sockets in the system. */
|
|---|
| 286 | uint16_t acRefs[32768];
|
|---|
| 287 | } __LIBC_SPMTCPIP, *__LIBC_PSPMTCPIP;
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 | /**
|
|---|
| 291 | * This is the header of the LIBC shared memory.
|
|---|
| 292 | */
|
|---|
| 293 | typedef struct __libc_SPMHeader
|
|---|
| 294 | {
|
|---|
| 295 | /** SPM version. (the one which initialized the memory) */
|
|---|
| 296 | unsigned uVersion;
|
|---|
| 297 |
|
|---|
| 298 | /** Size of the shared memory. */
|
|---|
| 299 | size_t cb;
|
|---|
| 300 | /** Free memory. */
|
|---|
| 301 | size_t cbFree;
|
|---|
| 302 | /** Start chunk of shared memory pool. */
|
|---|
| 303 | __LIBC_PSPMPOOLCHUNK pPoolHead;
|
|---|
| 304 | /** End chunk of shared memory pool. */
|
|---|
| 305 | __LIBC_PSPMPOOLCHUNK pPoolTail;
|
|---|
| 306 | /** Start free chunk in the shared memory pool. */
|
|---|
| 307 | __LIBC_PSPMPOOLCHUNKFREE pPoolFreeHead;
|
|---|
| 308 | /** End free chunk in the shared memory pool. */
|
|---|
| 309 | __LIBC_PSPMPOOLCHUNKFREE pPoolFreeTail;
|
|---|
| 310 |
|
|---|
| 311 | /** The size of one process block in this version of the shared memory. */
|
|---|
| 312 | size_t cbProcess;
|
|---|
| 313 | /** Array index by process state giving the head pointers
|
|---|
| 314 | * to the processes in that state. */
|
|---|
| 315 | __LIBC_PSPMPROCESS apHeads[__LIBC_PROCSTATE_MAX];
|
|---|
| 316 |
|
|---|
| 317 | /** Pointer to the tcpip globals. */
|
|---|
| 318 | __LIBC_PSPMTCPIP pTcpip;
|
|---|
| 319 | /** Creator pid. */
|
|---|
| 320 | pid_t pidCreate;
|
|---|
| 321 | /** Creation timestamp. */
|
|---|
| 322 | DATETIME dtCreate;
|
|---|
| 323 | /* The rest of the block, up to cbProcess, is undefined in this version.
|
|---|
| 324 | * Future versions of LIBC may use this area assuming it's initalized with zeros.
|
|---|
| 325 | */
|
|---|
| 326 | } __LIBC_SPMHEADER, *__LIBC_PSPMHEADER;
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 | /**
|
|---|
| 330 | * Gets the current process.
|
|---|
| 331 | *
|
|---|
| 332 | * @returns Pointer to the current process.
|
|---|
| 333 | * @returns NULL and errno on failure.
|
|---|
| 334 | * @remark For this too __libc_spmRelease() must be called when done.
|
|---|
| 335 | */
|
|---|
| 336 | __LIBC_PSPMPROCESS __libc_spmSelf(void);
|
|---|
| 337 |
|
|---|
| 338 | /**
|
|---|
| 339 | * Create an embryo related to the current process.
|
|---|
| 340 | *
|
|---|
| 341 | * @returns pointer to the embryo process.
|
|---|
| 342 | * The allocated process must be released by the caller.
|
|---|
| 343 | * @returns NULL and errno on failure.
|
|---|
| 344 | * @param pidParent The parent pid (i.e. this process).
|
|---|
| 345 | */
|
|---|
| 346 | __LIBC_PSPMPROCESS __libc_spmCreateEmbryo(pid_t pidParent);
|
|---|
| 347 |
|
|---|
| 348 | /**
|
|---|
| 349 | * Searches for a process given by pid.
|
|---|
| 350 | *
|
|---|
| 351 | * @returns Pointer to the desired process on success.
|
|---|
| 352 | * @returns NULL and errno on failure.
|
|---|
| 353 | * @param pid Process id to search for.
|
|---|
| 354 | * @param enmState The state of the process.
|
|---|
| 355 | * @remark Call __libc_spmRelease() to release the result.
|
|---|
| 356 | */
|
|---|
| 357 | __LIBC_PSPMPROCESS __libc_spmQueryProcess(pid_t pid);
|
|---|
| 358 |
|
|---|
| 359 | /**
|
|---|
| 360 | * Searches for a process with a given pid and state.
|
|---|
| 361 | *
|
|---|
| 362 | * @returns Pointer to the desired process on success.
|
|---|
| 363 | * @returns NULL and errno on failure.
|
|---|
| 364 | * @param pid Process id to search for.
|
|---|
| 365 | * @param enmState The state of the process.
|
|---|
| 366 | * @remark Call __libc_spmRelease() to release the result.
|
|---|
| 367 | */
|
|---|
| 368 | __LIBC_PSPMPROCESS __libc_spmQueryProcessInState(pid_t pid, __LIBC_SPMPROCSTAT enmState);
|
|---|
| 369 |
|
|---|
| 370 | /**
|
|---|
| 371 | * Release reference to the given process.
|
|---|
| 372 | *
|
|---|
| 373 | * @returns 0 on success.
|
|---|
| 374 | * @returns -1 on failure.
|
|---|
| 375 | * @param pProcess Pointer to process to release.
|
|---|
| 376 | */
|
|---|
| 377 | int __libc_spmRelease(__LIBC_PSPMPROCESS pProcess);
|
|---|
| 378 |
|
|---|
| 379 | /**
|
|---|
| 380 | * Marks the current process (if we have it around) as zombie
|
|---|
| 381 | * or dead freeing all resources associated with it.
|
|---|
| 382 | *
|
|---|
| 383 | * @param uReason The OS/2 exit list type reason code.
|
|---|
| 384 | * This is only used if the current code is NONE.
|
|---|
| 385 | * @param iExitCode The unix exit code for this process.
|
|---|
| 386 | * This is only if the current code is 0.
|
|---|
| 387 | * @remark this might not be a sufficient interface for process termination but we'll see.
|
|---|
| 388 | */
|
|---|
| 389 | void __libc_spmTerm(__LIBC_EXIT_REASON enmDeathReason, int iExitCode);
|
|---|
| 390 |
|
|---|
| 391 | /**
|
|---|
| 392 | * Locks the LIBC shared memory for short exclusive access.
|
|---|
| 393 | * The call must call __libc_spmUnlock() as fast as possible and make
|
|---|
| 394 | * no api calls until that is done.
|
|---|
| 395 | *
|
|---|
| 396 | * @returns 0 on success.
|
|---|
| 397 | * @returns -1 and errno on failure.
|
|---|
| 398 | * @remark Don't think of calling this if you're not LIBC!
|
|---|
| 399 | */
|
|---|
| 400 | int __libc_spmLock(void);
|
|---|
| 401 |
|
|---|
| 402 | /**
|
|---|
| 403 | * Unlock the LIBC shared memory after call to __libc_spmLock().
|
|---|
| 404 | *
|
|---|
| 405 | * @returns 0 on success.
|
|---|
| 406 | * @returns 1 on failure.
|
|---|
| 407 | * @remark Don't think of calling this if you're not LIBC!
|
|---|
| 408 | */
|
|---|
| 409 | int __libc_spmUnlock(void);
|
|---|
| 410 |
|
|---|
| 411 | /**
|
|---|
| 412 | * Allocate memory from the LIBC shared memory.
|
|---|
| 413 | *
|
|---|
| 414 | * @returns Pointer to allocated memory on success.
|
|---|
| 415 | * @returns NULL on failure.
|
|---|
| 416 | * @param cbSize Size of memory to allocate.
|
|---|
| 417 | * @remark Don't think of calling this if you're not LIBC!
|
|---|
| 418 | */
|
|---|
| 419 | void * __libc_spmAlloc(size_t cbSize);
|
|---|
| 420 |
|
|---|
| 421 | /**
|
|---|
| 422 | * Free memory allocated by __libc_SpmAlloc().
|
|---|
| 423 | *
|
|---|
| 424 | * @returns 0 on success.
|
|---|
| 425 | * @returns -1 and errno on failure.
|
|---|
| 426 | * @param pv Pointer to memory block returned by __libc_SpmAlloc().
|
|---|
| 427 | * NULL is allowed.
|
|---|
| 428 | * @remark Don't think of calling this if you're not LIBC!
|
|---|
| 429 | */
|
|---|
| 430 | int __libc_spmFree(void *pv);
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 | /**
|
|---|
| 434 | * Register TCPIP termination handler.
|
|---|
| 435 | *
|
|---|
| 436 | * This is a manual way of by passing a.out's broken weak symbols.
|
|---|
| 437 | * @param pfnTerm Pointer to the termination function.
|
|---|
| 438 | */
|
|---|
| 439 | void __libc_spmSocketRegTerm(void (*pfnTerm)(void));
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 | /**
|
|---|
| 443 | * Adds the first reference to a new socket.
|
|---|
| 444 | *
|
|---|
| 445 | * @returns 0 on success.
|
|---|
| 446 | * @returns -1 and errno on failure.
|
|---|
| 447 | * @param iSocket The new socket.
|
|---|
| 448 | */
|
|---|
| 449 | int __libc_spmSocketNew(int iSocket);
|
|---|
| 450 |
|
|---|
| 451 | /**
|
|---|
| 452 | * References a socket.
|
|---|
| 453 | *
|
|---|
| 454 | * @returns The new reference count.
|
|---|
| 455 | * @returns -1 and errno on failure.
|
|---|
| 456 | * @param iSocket socket to reference.
|
|---|
| 457 | */
|
|---|
| 458 | int __libc_spmSocketRef(int iSocket);
|
|---|
| 459 |
|
|---|
| 460 | /**
|
|---|
| 461 | * Dereferences a socket.
|
|---|
| 462 | *
|
|---|
| 463 | * @returns The new reference count.
|
|---|
| 464 | * The caller must close the socket if 0 is returned.
|
|---|
| 465 | * @returns -1 and errno on failure.
|
|---|
| 466 | * @param iSocket Socket to dereference.
|
|---|
| 467 | */
|
|---|
| 468 | int __libc_spmSocketDeref(int iSocket);
|
|---|
| 469 |
|
|---|
| 470 | __END_DECLS
|
|---|
| 471 |
|
|---|
| 472 | #endif /* __InnoTekLIBC_sharedpm_h__ */
|
|---|