source: trunk/libc/include/InnoTekLIBC/sharedpm.h@ 2672

Last change on this file since 2672 was 2672, checked in by bird, 19 years ago
  • *:

o Synced over changed from 0.6.1 bugfixing.

  • libc:

o Try put the log file handle above the range of the standard handles
o #71: Fixed incorrect fmutex padding in FILE which cause _fcloseall

(and perhaps others) to crash. (thanks to froloff)

o #69: Corrected a few problems related to dos drives and slashes in basename and dirname.
o read & write logging, and added support for more size flags to the log formatter.
o #68: Implemented the _GETOPT_DECLARED blocker in getopt.h too.
o #67: Removed termcap.h, curses.h, bsd/curses.h, bsd/termcap.h,

gnu/curses.h and gnu/termcap.h because we never built the libs for them.

o #65: Added sys/_timespec.h and uncommented it's inclusion in

sys/stat.h. This fixes the bustage in non-BSD source mode.

o Fixed wrong target name written into the symlink.
o #62: Fixed incorrect EOF treatment in getdelim (and in getline since that's just a

special case of getdelim).

o #49: Fixed stat backend so ctime is set, and made fstat, lstat and stat convert birthtime too.
o #61: Fixed incorrect ENOENT errno on symlink when it should return EEXIST.
o #60: Fixed blunder in exec/spawn filehandle inheritance code.
o #58: The standard file handles are always initialized as open.
o #54: Fixed unitialized directory handle member fInUnixTree.
o #53: Fixed LIBC panic when _openstream locks the stream vector

in any of it's error cases.

o #52: Fixed two 'symlink/' problems in the path resolver.
o #51: Made unlink able to delete readonly files.
o #50: Inherit umask.
o #30: Committed forgotten header.
o #48: Quick implementation of the freopen(NULL) operation

to make cat from coreutils happy.

o memalign and valloc shouldn't be in USE_GNU in malloc.h.
o #30: Fixed toupper / tolower EOF regression.
o Fixed incorrect assertion in
libc_back_fsInfoObjRelease.
o #41: And added special file mode mask getter and extra validations to check that

the mode mask we read has a valid type. This also shuts up some bad [f]chmod paths.

o #41: Calc st_ino and st_dev at the end of the unix attrib getter if they are not present.
o #40: Fixed double slash preventing root directories from being opened.
o #23: Fixed two incorrect EA size fields, now creating symlinks really works.
o #21: Restrict reading and writing of UnixEAs to HPFS, JFS, FAT and RAMFS.
o #38: Added DosSysCtl prototype and use it on panic to check for debugger.
o #33: Fixed a return path in libc_back_signalWait which didn't reacquire the semaphore.
o #32: Fixed incorrect readdir_r return code when out of files.
o #30: Fixed two locale bugs. First, setlocale called a locale

dependent function for getting ctype flags. Second, all the
is<>() macros / functions was busted for non-ascii chars (-1..-128).

o #23: Corrected EA name in template from "FLAGS" to "SYMLINK".
o #24: Fixed chdir() crash in fts.c.
o #24: Fixed dirfd() problem in fts.c which prevent us from getting

any results in child directories.

o #22: Added DosFindFirst() as fallback when DosQueryPathInfo() fails

to query the symlink EA in the path resolver. This problem occurs
when doing stat() on an open file (pwd_mkdb example).

  • libsocket:

o #25: Ensure correct address length returns from recvmsg and recvfrom.

  • Property cvs2svn:cvs-rev set to 1.25
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 36.7 KB
Line 
1/** $Id: sharedpm.h 2672 2006-03-19 05:18:20Z bird $ */
2/** @file
3 *
4 * LIBC Shared Process Management.
5 *
6 * Copyright (c) 2004-2005 knut st. osmundsen <bird@anduin.net>
7 * Copyright (c) 2004 nickk
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 General Public License as published by
13 * 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 General Public License for more details.
20 *
21 * You should have received a copy of the GNU 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 __InnoTekLIBC_sharedpm_h__
28#define __InnoTekLIBC_sharedpm_h__
29
30#include <sys/cdefs.h>
31#include <sys/types.h>
32#include <sys/signal.h>
33#include <sys/ipc.h>
34
35
36__BEGIN_DECLS
37
38/** The name of the shared semaphore protecting the memory. */
39#define SPM_MUTEX_NAME "\\SEM32\\INNOTEKLIBC-V1.3"
40
41/** The name of the shared memory. */
42#define SPM_MEMORY_NAME "\\SHAREMEM\\INNOTEKLIBC-V1.3"
43
44/** The timeout for accessing the shared mem semaphore. */
45#define SPM_MUTEX_TIMEOUT (30*1000)
46
47/** Allocate 512KB if OBJ_ANY isn't supported.
48 * If it is supported we allocated the double amount. */
49#define SPM_MEMORY_SIZE (512*1024)
50
51/** The defined max size of a process.
52 * A good bit is reserved for the future here.
53 *
54 * Theoretically speaking, OS/2 cannot entertain more than a 1000 processes.
55 * So, even if we reserve a good bit here it's not gonna cause any trouble.
56 */
57#define SPM_PROCESS_SIZE (256)
58
59/**
60 * The SPM version.
61 */
62#define SPM_VERSION 0x00010003
63
64
65/**
66 * Process termination reason.
67 */
68typedef enum __LIBC_EXIT_REASON
69{
70 /** No reason. */
71 __LIBC_EXIT_REASON_NONE = 0,
72 /** Normal exit. */
73 __LIBC_EXIT_REASON_EXIT = 1,
74 /** OS/2 hard error. */
75 __LIBC_EXIT_REASON_HARDERROR = 2,
76 /** Trap (i.e. 16-bit?). */
77 __LIBC_EXIT_REASON_TRAP = 3,
78 /** Kill process. */
79 __LIBC_EXIT_REASON_KILL = 4,
80 /** Exception. */
81 __LIBC_EXIT_REASON_XCPT = 5,
82 /** Signal base. */
83 __LIBC_EXIT_REASON_SIGNAL_BASE = 32,
84 /** Signal max. */
85 __LIBC_EXIT_REASON_SIGNAL_MAX = 256,
86 /** Hack to ensure that this will be a 32-bit int. */
87 __LIBC_EXIT_REASON_MAKE_INT32 = 0x7fffffff
88} __LIBC_EXIT_REASON;
89
90
91/** Pointer to child termination data. */
92typedef struct __LIBC_SPMCHILDNOTIFY *__LIBC_PSPMCHILDNOTIFY;
93
94/**
95 * Child termination notification data.
96 */
97typedef struct __LIBC_SPMCHILDNOTIFY
98{
99 /** Pointer to the next node in the list. */
100 __LIBC_PSPMCHILDNOTIFY volatile pNext;
101 /** Structure size. */
102 unsigned cb;
103 /** Process Id. */
104 pid_t pid;
105 /** Process Group Id. */
106 pid_t pgrp;
107 /** Exit code. */
108 int iExitCode;
109 /** Reason code. */
110 __LIBC_EXIT_REASON enmDeathReason;
111} __LIBC_SPMCHILDNOTIFY;
112
113
114/**
115 * Process state.
116 */
117typedef enum __LIBC_SPMPROCSTAT
118{
119 /** The process is free. */
120 __LIBC_PROCSTATE_FREE = 0,
121 /** The process is waiting for a chile to be created and snatch all the
122 * inherited goodies from it.
123 * If not caught before DosExecPgm/DosStartSession returns
124 * it will be freed by the disappointed parent.
125 */
126 __LIBC_PROCSTATE_EMBRYO = 1,
127 /** The process is running. */
128 __LIBC_PROCSTATE_ALIVE = 2,
129 /** The process is dead but other guys are still using it's data. */
130 __LIBC_PROCSTATE_ZOMBIE = 3,
131 /** Reserved process state. */
132 __LIBC_PROCSTATE_RESERVED = 4,
133 /** The maximum state number (exclusive). */
134 __LIBC_PROCSTATE_MAX = 5,
135 /** Hack to ensure that this will be a 32-bit int. */
136 __LIBC_PROCSTATE_MAKE_INT32 = 0x7fffffff
137} __LIBC_SPMPROCSTAT;
138
139
140/** Pointer to (queued) signal. */
141typedef struct __libc_SPMSignal *__LIBC_PSPMSIGNAL;
142
143/**
144 * Signal (queued).
145 */
146typedef struct __libc_SPMSignal
147{
148 /** Structure size. */
149 unsigned cb;
150 /** Pointer to the next signal. */
151 __LIBC_PSPMSIGNAL volatile pNext;
152 /** Sender process.
153 * This is used to decrement the cSigsSent count of the sender. */
154 pid_t pidSender;
155 /** Signal info. */
156 siginfo_t Info;
157} __LIBC_SPMSIGNAL;
158
159
160/** Inheritance FH Bundle Type.
161 * @{ */
162/** Termination bundle. */
163#define __LIBC_SPM_INH_FHB_TYPE_END (0)
164/** Standard bundle. */
165#define __LIBC_SPM_INH_FHB_TYPE_STANDARD (0xe0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned)))
166/** Directory bundle. */
167#define __LIBC_SPM_INH_FHB_TYPE_DIRECTORY (0xc0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned) + sizeof(unsigned)))
168/** Socket bundle, using the BSD 4.4 backend. */
169#define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44 (0xa0 | (sizeof(unsigned) + sizeof(unsigned short)))
170/** Socket bundle, using the BSD 4.3 backend. */
171#define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43 (0x80 | (sizeof(unsigned) + sizeof(unsigned short)))
172/*#define __LIBC_SPM_INH_FHB_TYPE_ (0x60 | (sizeof(unsigned) + ))*/
173/*#define __LIBC_SPM_INH_FHB_TYPE_ (0x40 | (sizeof(unsigned) + ))*/
174/*#define __LIBC_SPM_INH_FHB_TYPE_ (0x20 | (sizeof(unsigned) + ))*/
175/*#define __LIBC_SPM_INH_FHB_TYPE_ (0x00 | (sizeof(unsigned) + ))*/
176/** Get the per file handle size from the bundle type. */
177#define __LIBC_SPM_INH_FHB_SIZE(type) ((type) & 0x1f)
178/** @} */
179
180/**
181 * SPM Inheritance File Handle Bundle Header.
182 */
183#pragma pack(1)
184typedef struct __libc_SPMInhFHBHdr
185{
186 /** Bundle type. */
187 unsigned char uchType;
188 /** Count of handles in this bundle. */
189 unsigned char cHandles;
190 /** Start handle number. */
191 unsigned short StartFH;
192} __LIBC_SPMINHFHBHDR;
193#pragma pack()
194/** Pointer to SPM filehandle bundle header. */
195typedef __LIBC_SPMINHFHBHDR *__LIBC_PSPMINHFHBHDR;
196
197/**
198 * SPM standard filehandle inherit bundle
199 * This is used for OS/2 filehandles which only needs flags
200 * transfered.
201 */
202#pragma pack(1)
203typedef struct __libc_SPMInhFH
204{
205 /** The common bundle header. */
206 __LIBC_SPMINHFHBHDR Hdr;
207 /** Array Hdr.cHandles entries. */
208 struct
209 {
210 /** The flags. */
211 unsigned fFlags;
212 /** The inode number. */
213 ino_t Inode;
214 /** The device number. */
215 dev_t Dev;
216 /** String table offset of the native path. */
217 unsigned offNativePath : 24;
218 unsigned u8Reserved : 8;
219 } aHandles[1];
220} __LIBC_SPMINHFHBSTD;
221#pragma pack()
222/** Pointer to SPM standard filehandle inherit bundle. */
223typedef __LIBC_SPMINHFHBSTD *__LIBC_PSPMINHFHBSTD;
224
225/**
226 * SPM directory filehandle inherit bundle.
227 */
228#pragma pack(1)
229typedef struct __libc_SPMInhFHDir
230{
231 /** The common bundle header. */
232 __LIBC_SPMINHFHBHDR Hdr;
233 /** Array of flags of Hdr.cHandles entries. */
234 struct
235 {
236 /** The flags. */
237 unsigned fFlags;
238 /** The inode number. */
239 ino_t Inode;
240 /** The device number. */
241 dev_t Dev;
242 /** String table offset of the native path. */
243 unsigned offNativePath : 24;
244 /** Set if this path is in the unix tree. */
245 unsigned fInUnixTree : 1;
246 unsigned u7Reserved : 7;
247 /** The current position. */
248 unsigned uCurEntry;
249 } aHandles[1];
250} __LIBC_SPMINHFHBDIR;
251#pragma pack()
252/** Pointer to SPM directory filehandle inherit bundle. */
253typedef __LIBC_SPMINHFHBDIR *__LIBC_PSPMINHFHBDIR;
254
255/**
256 * SPM socket filehandle inherit bundle.
257 *
258 * This is used for both BSD 4.3 and 4.4 sockets. The data needed
259 * here is the flags and the socket number.
260 */
261#pragma pack(1)
262typedef struct __libc_SPMInhFHSocket
263{
264 /** The common bundle header. */
265 __LIBC_SPMINHFHBHDR Hdr;
266 /** Array of flags of Hdr.cHandles entries. */
267 struct
268 {
269 /** The file handle flags. */
270 unsigned fFlags;
271 /** The socket number. */
272 unsigned short usSocket;
273 } aHandles[1];
274} __LIBC_SPMINHFHBSOCK;
275#pragma pack()
276/** Pointer to SPM socket filehandle inherit bundle. */
277typedef __LIBC_SPMINHFHBSOCK *__LIBC_PSPMINHFHBSOCK;
278
279/**
280 * The SPM fs inherit data, part 1.
281 * The FS data is stored in two sections for legacy reasons.
282 */
283typedef struct __libc_SPMInhFS
284{
285 /** In Unix Tree global. */
286 int fInUnixTree;
287 /** Size of the unix root. Only set if there's an official root. */
288 size_t cchUnixRoot;
289 /** The current unix root if cchUnixRoot is non-zero. */
290 char szUnixRoot[1];
291} __LIBC_SPMINHFS;
292/** Pointer to FS inherit data. */
293typedef __LIBC_SPMINHFS *__LIBC_PSPMINHFS;
294
295/**
296 * SPM fs inherit data, part two.
297 */
298typedef struct __libc_SPMInhFS2
299{
300 /** The size of this structure. */
301 unsigned cb;
302 /** The umask value. */
303 unsigned fUMask;
304} __LIBC_SPMINHFS2;
305/** Pointer to FS inherit data, part two. */
306typedef __LIBC_SPMINHFS2 *__LIBC_PSPMINHFS2;
307
308/**
309 * SPM signal inherit data.
310 */
311typedef struct __libc_SPMInhSig
312{
313 /** The size of this structure. */
314 unsigned cb;
315 /** Mask of signals which should be ignored. */
316 sigset_t SigSetIGN;
317} __LIBC_SPMINHSIG;
318/** Pointer to Signal inherit data. */
319typedef __LIBC_SPMINHSIG *__LIBC_PSPMINHSIG;
320
321
322
323/**
324 * Inherit structure.
325 *
326 * All the data it contains is allocated in one block heap block!
327 */
328typedef struct __libc_SPMInherit
329{
330 /** Size of the inherit structure. */
331 size_t cb;
332 /** Pointer to the filehandle part.
333 * This is a succession of bundles terminating with a _END one. */
334 __LIBC_PSPMINHFHBHDR pFHBundles;
335 /** Pointer to the file system part. If NULL default values are assumed. */
336 __LIBC_PSPMINHFS pFS;
337 /** Pointer to the signal part. If NULL default values are assumed. */
338 __LIBC_PSPMINHSIG pSig;
339 /** Pointer to strings (filenames++).
340 * All the strings are NULL terminated and referenced by offset. */
341 char *pszStrings;
342 /** More file system stuff. */
343 __LIBC_PSPMINHFS2 pFS2;
344} __LIBC_SPMINHERIT;
345/** Pointer to inherit data. */
346typedef __LIBC_SPMINHERIT *__LIBC_PSPMINHERIT;
347
348
349/** Pointer to per process data structure. */
350typedef struct __libc_SPMProcess *__LIBC_PSPMPROCESS;
351
352/**
353 * Per Process Data.
354 */
355typedef struct __libc_SPMProcess
356{
357 /** 0 - Pointer to the next process in the list.
358 * Every process is in one or another list depending on their state. */
359 volatile __LIBC_PSPMPROCESS pNext;
360 /** 4 - Pointer to the previous process in the list. */
361 volatile __LIBC_PSPMPROCESS pPrev;
362
363
364 /** Core
365 * @{ */
366 /** 8 - Version of the SPM which created this process. */
367 unsigned uVersion;
368 /** 12 - Number of references to this process.
369 * A process is not actually free till the reference count
370 * reaches 0. */
371 volatile unsigned cReferences;
372 /** 16 - State of this process. */
373 volatile __LIBC_SPMPROCSTAT enmState;
374 /** 20 - Process id. */
375 pid_t pid;
376 /** 24 - Process id of parent.
377 * This might not match the OS/2 one since there are no notification
378 * when a parent dies. */
379 pid_t pidParent;
380 /** @} */
381
382
383 /** User & Group
384 * @{ */
385 /** 28 - User id (also called Real User id). */
386 uid_t uid;
387 /** 32 - Effective user id. */
388 uid_t euid;
389 /** 36 - Saved user id. */
390 uid_t svuid;
391 /** 40 - Group id (also called Real Group id). */
392 gid_t gid;
393 /** 44 - Effecive group id. */
394 gid_t egid;
395 /** 48 - Saved group id. */
396 gid_t svgid;
397 /** 52 - Supplementary group ids. */
398 gid_t agidGroups[16 /*NGROUPS_MAX*/];
399 /** @} */
400
401
402 /** Misc
403 * @{ */
404 /** 116 - Creation timestamp. */
405 unsigned uTimestamp;
406 /** 120 - The SPM open count of this process. */
407 unsigned cSPMOpens;
408 /** 124 - Indicates that the process is a full featured LIBC process.
409 * Until this flag is set (atomically) it's not a good idea to
410 * queue signals on the process since it won't have a signal handler
411 * installed, and thus won't get to know about them.
412 */
413 volatile unsigned fExeInited;
414 /** 128 - Reserved for future use. Must be 0. */
415 unsigned uMiscReserved;
416 /** @} */
417
418
419 /** Fork
420 * @{ */
421 /** 132 - Pointer to fork module list head. */
422 void * volatile pvModuleHead;
423 /** 136 - Pointer to fork module list tail pointer. */
424 void * volatile * volatile ppvModuleTail;
425 /** 140 - Pointer to fork handle which a child should use when spawned by fork(). */
426 void *pvForkHandle;
427 /** @} */
428
429
430 /** Signals & Job Control
431 * @{ */
432 /** 144 - Incoming signal queue (FIFO).
433 * For signals which aren't queable only one signal can be queued.
434 */
435 volatile __LIBC_PSPMSIGNAL pSigHead;
436 /** 148 - Number of signals send.
437 * After _POSIX_SIGQUEUE_MAX signals only SIGCHLD will be allowed sent.
438 */
439 volatile unsigned cSigsSent;
440 /** 152 - Session Id. */
441 pid_t sid;
442 /** 156 - Process group. */
443 pid_t pgrp;
444 /** 160 - Reserved for future use. Must be 0. */
445 unsigned uSigReserved1;
446 /** 164 - Reserved for future use. Must be 0. */
447 unsigned uSigReserved2;
448 /** @} */
449
450
451 /** Termination
452 * @{ */
453 /** 168 - Termination information which will be sent to the parent process. */
454 __LIBC_PSPMCHILDNOTIFY pTerm;
455 /** 172 - List of child termination notifications. */
456 __LIBC_PSPMCHILDNOTIFY volatile pChildNotifyHead;
457 /** 176 - Pointer to the pointer where to insert the next child notification. */
458 __LIBC_PSPMCHILDNOTIFY volatile * volatile ppChildNotifyTail;
459 /** @} */
460
461 /** 180 - Per Process Sockets Reference Counters. (Data is process local.) */
462 uint16_t *pacTcpipRefs;
463 /** 184 - The Process priority (unix). */
464 int iNice;
465 /** 188 - Reserved fields with default value 0. */
466 unsigned auReserved[56 - 47];
467
468
469 /** 224 - Number of possible pointers to shared memory starting at pInherit.
470 * This means we can extend the structure with pointers for as long as we
471 * want and still have older LIBC versions cleanup the mess. */
472 unsigned cPoolPointers;
473 /** 228 - Pointer to data inherited from the parent process. */
474 __LIBC_PSPMINHERIT volatile pInherit;
475 /** 232 - Pointer to data inherited from the parent process when it's locked.
476 * When locked pInherit is NULL and this member points to the data instead.
477 * This prevents spmAlloc() from reclaiming it while it's in use. */
478 __LIBC_PSPMINHERIT volatile pInheritLocked;
479
480} __LIBC_SPMPROCESS;
481
482/** The current value for __LIBC_SPMPROCESS::cPoolPointers. */
483#define __LIBC_SPMPROCESS_POOLPOINTERS 2
484
485/**
486 * Pool chunk.
487 */
488typedef struct __libc_SPMPoolChunk
489{
490 /** Next block in the list of all blocks.. */
491 struct __libc_SPMPoolChunk *pPrev;
492 /** Previous block in the list of all blocks.. */
493 struct __libc_SPMPoolChunk *pNext;
494} __LIBC_SPMPOOLCHUNK, *__LIBC_PSPMPOOLCHUNK;
495
496/**
497 * Free pool chunk.
498 */
499typedef struct __libc_SPMPoolChunkFree
500{
501 /** Main list. */
502 __LIBC_SPMPOOLCHUNK core;
503 /** Next block in list of free nodes. */
504 struct __libc_SPMPoolChunkFree *pPrev;
505 /** Previous block in list of free nodes. */
506 struct __libc_SPMPoolChunkFree *pNext;
507 /** Size of this block. */
508 size_t cb;
509} __LIBC_SPMPOOLCHUNKFREE, *__LIBC_PSPMPOOLCHUNKFREE;
510
511/**
512 * Pool chunk alignment.
513 */
514#define SPM_POOL_ALIGN(size) (((size) + 7) & ~7)
515
516/**
517 * This structure contains the global TCP/IP socket data.
518 */
519typedef struct __libc_SPMTcpIp
520{
521 /** Size of the structure. */
522 size_t cb;
523 /** The number of elements in the acRefs array. */
524 unsigned cSockets;
525 /** Array containing the references counters for the sockets in the system. */
526 uint16_t acRefs[32768];
527} __LIBC_SPMTCPIP, *__LIBC_PSPMTCPIP;
528
529
530/**
531 * The structure contains the system load averages.
532 */
533typedef struct __libc_SPMLoadAvg
534{
535 /** Array of the three stamples.
536 * The entries are for 1, 5 and 15 min averages respectively.
537 *
538 * The samples them selfs are stored as integers and not as a
539 * double as the interface returns. The reason is that this is smaller
540 * and it's what both BSD and Linux is doing. The fraction part is
541 * the lower 11 bits (this is also identical to BSD and Linux).
542 */
543 uint32_t u32Samples[3];
544 /** Timestamp of the last update. */
545 unsigned uTimestamp;
546} __LIBC_SPMLOADAVG;
547/** Pointer to load averages. */
548typedef __LIBC_SPMLOADAVG *__LIBC_PSPMLOADAVG;
549
550
551/**
552 * This is the header of the LIBC shared memory.
553 */
554typedef struct __libc_SPMHeader
555{
556 /** 0 - SPM version. (the one which initialized the memory) */
557 unsigned uVersion;
558
559 /** 4 - Size of the shared memory. */
560 size_t cb;
561 /** 8 - Free memory. */
562 volatile size_t cbFree;
563 /** 12 - Start chunk of shared memory pool. */
564 volatile __LIBC_PSPMPOOLCHUNK pPoolHead;
565 /** 16 - End chunk of shared memory pool. */
566 volatile __LIBC_PSPMPOOLCHUNK pPoolTail;
567 /** 20 - Start free chunk in the shared memory pool. */
568 volatile __LIBC_PSPMPOOLCHUNKFREE pPoolFreeHead;
569 /** 24 - End free chunk in the shared memory pool. */
570 volatile __LIBC_PSPMPOOLCHUNKFREE pPoolFreeTail;
571
572 /** 28 - The size of one process block in this version of the shared memory. */
573 size_t cbProcess;
574 /** 32 - Array index by process state giving the head pointers
575 * to the processes in that state. */
576 volatile __LIBC_PSPMPROCESS apHeads[__LIBC_PROCSTATE_MAX];
577 /** 52 -List of free child (termination) notification structures. */
578 volatile __LIBC_PSPMCHILDNOTIFY pChildNotifyFreeHead;
579
580 /** 56 - Pointer to the tcpip globals. */
581 __LIBC_PSPMTCPIP pTcpip;
582 /** 60 - Creator pid. */
583 pid_t pidCreate;
584 /** 64 - Creation timestamp. */
585 __extension__ union
586 {
587#ifdef INCL_DOSDATETIME
588 DATETIME dtCreate;
589#endif
590 char ach[16];
591 };
592
593 /** 80 - System Load Averages. */
594 volatile __LIBC_SPMLOADAVG LoadAvg;
595
596 /** 96 - List of free signal structures. This will reduce
597 * the time spent allocating a signal structure in most cases.
598 * During SPM init 8 signal structures will be allocated and queued. */
599 volatile __LIBC_PSPMSIGNAL pSigFreeHead;
600 /** 100 - Number of free signal structures in the list.
601 * This is used to prevent the list from growing infinitly under stress.
602 * When cSigFree reaches 32 unused signal structures will be freed instead
603 * of put in the list. */
604 volatile unsigned cSigFree;
605 /** 104 - Number of active signals.
606 * This is used to keep a reasonable limit of the number of active signal
607 * structures so a process cannot exhaust the shared memory pool.
608 * The maximum is defined by cSigMaxActive.
609 */
610 volatile unsigned cSigActive;
611 /** 108 - The maximum number of active signals.
612 * This is initialized by the SPM creator but can be adjusted later.
613 */
614 unsigned cSigMaxActive;
615 /** 112 - Notification event semaphore.
616 * This semaphore is signaled when an event occurs. An event is either a signal
617 * or a child notification.
618 * At the moment this isn't used by anyone, but it's being signaled just in case.
619 */
620 unsigned long hevNotify;
621
622 /** 116 - Pointer to SysV Sempahore globals. */
623 struct __libc_SysV_Sem *pSysVSem;
624 /** 120 - Pointer to SysV Shared Memory globals. */
625 struct __libc_SysV_Shm *pSysVShm;
626 /** 124 - Pointer to SysV Message Queue globals. */
627 struct __libc_SysV_Msg *pSysVMsg;
628
629 /* 128 - The rest of the block, up to cbProcess, is undefined in this version.
630 * Future versions of LIBC may use this area assuming it's initalized with zeros.
631 */
632} __LIBC_SPMHEADER, *__LIBC_PSPMHEADER;
633
634
635/**
636 * SPM Exception handler registration record.
637 */
638typedef struct __LIBC_SPMXCPTREGREC
639{
640 __extension__ union
641 {
642#ifdef INCL_DOSEXCEPTIONS
643 EXCEPTIONREGISTRATIONRECORD Core;
644#endif
645 void *apv[2];
646 };
647 unsigned uFutureStuff0;
648 unsigned uFutureStuff1;
649} __LIBC_SPMXCPTREGREC;
650/** Pointer to SPM exception handler registration record. */
651typedef __LIBC_SPMXCPTREGREC *__LIBC_PSPMXCPTREGREC;
652
653
654
655
656/**
657 * Gets the current process.
658 *
659 * @returns Pointer to the current process.
660 * @returns NULL and errno on failure.
661 * @remark For this too __libc_spmRelease() must be called when done.
662 */
663__LIBC_PSPMPROCESS __libc_spmSelf(void);
664
665/**
666 * Gets the inherit data associated with the current process.
667 * This call prevents it from being release by underrun handling.
668 *
669 * @returns Pointer to inherit data.
670 * The caller must call __libc_spmInheritRelease() when done.
671 * @returns NULL and errno if no inherit data.
672 */
673__LIBC_PSPMINHERIT __libc_spmInheritRequest(void);
674
675/**
676 * Releases the inherit data locked by the __libc_spmInheritRequest() call.
677 *
678 * @returns 0 on success.
679 * @returns -1 and errno on failure.
680 */
681int __libc_spmInheritRelease(void);
682
683/**
684 * Frees the inherit data of this process.
685 * This is called when the executable is initialized.
686 */
687void __libc_spmInheritFree(void);
688
689/**
690 * Create an embryo related to the current process.
691 *
692 * @returns pointer to the embryo process.
693 * The allocated process must be released by the caller.
694 * @returns NULL and errno on failure.
695 * @param pidParent The parent pid (i.e. this process).
696 */
697__LIBC_PSPMPROCESS __libc_spmCreateEmbryo(pid_t pidParent);
698
699/**
700 * Searches for a process given by pid.
701 *
702 * @returns Pointer to the desired process on success.
703 * @returns NULL and errno on failure.
704 * @param pid Process id to search for.
705 * @param enmState The state of the process.
706 * @remark Call __libc_spmRelease() to release the result.
707 */
708__LIBC_PSPMPROCESS __libc_spmQueryProcess(pid_t pid);
709
710/**
711 * Searches for a process with a given pid and state.
712 *
713 * @returns Pointer to the desired process on success.
714 * @returns NULL and errno on failure.
715 * @param pid Process id to search for.
716 * @param enmState The state of the process.
717 * @remark Call __libc_spmRelease() to release the result.
718 */
719__LIBC_PSPMPROCESS __libc_spmQueryProcessInState(pid_t pid, __LIBC_SPMPROCSTAT enmState);
720
721/**
722 * Process enumeration callback function.
723 *
724 * @returns 0 to continue the enumeration.
725 * @returns Non-zero to stop the enumeration. The enumeration
726 * api will return this same value.
727 *
728 * @param pProcess The current process.
729 * @param pvUser The user argument.
730 * @remark It is *not* allowed to terminate the thread or process, do long jumps
731 * or anything else which causes the enumeration function not to release
732 * the lock.
733 * It is not allowed to do expensive stuff either as it will harm other
734 * processes in the system which want to access the shared process facility!
735 */
736typedef int __LIBC_FNSPNENUM(__LIBC_PSPMPROCESS pProcess, void *pvUser);
737/** Pointer to an process enumeration callback function. */
738typedef __LIBC_FNSPNENUM *__LIBC_PFNSPNENUM;
739
740/**
741 * Enumerates all alive processes in a group.
742 *
743 * @returns 0 on success.
744 * @returns -ESRCH if the process group wasn't found.
745 * @returns -EINVAL if pgrp is negative.
746 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
747 *
748 * @param pgrp The process group id. 0 is an alias for the process group the caller belongs to.
749 * @param pfnCallback Callback function.
750 * @param pvUser User argument to the callback.
751 */
752int __libc_spmEnumProcessesByPGrp(pid_t pgrp, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
753
754/**
755 * Enumerates all alive processes owned by a user.
756 *
757 * @returns 0 on success.
758 * @returns -ESRCH if the process group wasn't found.
759 * @returns -EINVAL if uid is negative.
760 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
761 *
762 * @param uid The process user id.
763 * @param pfnCallback Callback function.
764 * @param pvUser User argument to the callback.
765 */
766int __libc_spmEnumProcessesByUser(uid_t uid, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
767
768/**
769 * Release reference to the given process.
770 *
771 * @returns 0 on success.
772 * @returns -1 on failure.
773 * @param pProcess Pointer to process to release.
774 */
775int __libc_spmRelease(__LIBC_PSPMPROCESS pProcess);
776
777/**
778 * Checks if the calling process can see the specfied one.
779 *
780 * @returns 0 if it can see it.
781 * @returns -ESRCH (or other approriate error code) if it cannot.
782 *
783 * @param pProcess The process in question.
784 */
785int __libc_spmCanSee(__LIBC_PSPMPROCESS pProcess);
786
787/**
788 * Checks if we are a system-wide super user.
789 *
790 * @returns 0 if we are.
791 * @returns -EPERM if we aren't.
792 */
793int __libc_spmIsSuperUser(void);
794
795/**
796 * Checks if the caller can modify the specified process.
797 *
798 * @returns 0 if we can modify it.
799 * @returns -EPERM if we cannot modify it.
800 * @param pProcess The process in question.
801 */
802int __libc_spmCanModify(__LIBC_PSPMPROCESS pProcess);
803
804/**
805 * Checks if the calling process is a member of the specified group.
806 *
807 * @returns 0 if member.
808 * @returns -EPERM if not member.
809 * @param gid The group id in question.
810 */
811int __libc_spmIsGroupMember(gid_t gid);
812
813/**
814 * Check if the caller can access the SysV IPC object as requested.
815 *
816 * @returns 0 if we can.
817 * @returns -EPERM if we cannot.
818 * @param pPerm The IPC permission structure.
819 * @param Mode The access request. IPC_M, IPC_W or IPC_R.
820 */
821int __libc_spmCanIPC(struct ipc_perm *pPerm, mode_t Mode);
822
823/**
824 * Marks the current process (if we have it around) as zombie
825 * or dead freeing all resources associated with it.
826 *
827 * @param uReason The OS/2 exit list type reason code.
828 * This is only used if the current code is NONE.
829 * @param iExitCode The unix exit code for this process.
830 * This is only if the current code is 0.
831 * @remark this might not be a sufficient interface for process termination but we'll see.
832 */
833void __libc_spmTerm(__LIBC_EXIT_REASON enmDeathReason, int iExitCode);
834
835/**
836 * Query about notifications from a specific child process.
837 * The notifications are related to death, the cause and such.
838 *
839 * @returns 0 on success.
840 * @returns Negative error code (errno.h) on failure.
841 * @param pid Process id.
842 * @param pNotify Where to store the notification from the child.
843 */
844int __libc_spmQueryChildNotification(pid_t pid, __LIBC_PSPMCHILDNOTIFY pNotifyOut);
845
846/**
847 * Validates a process group id.
848 *
849 * @returns 0 if valid.
850 * @returns -ESRCH if not valid.
851 * @param pgrp Process group id to validate. 0 if the same as
852 * the same as the current process.
853 * @param fOnlyChildren Restrict the search to immediate children.
854 */
855int __libc_spmValidPGrp(pid_t pgrp, int fOnlyChildren);
856
857
858/**
859 * Identificators which can be obtained using __libc_spmGetId().
860 */
861typedef enum __LIBC_SPMID
862{
863 __LIBC_SPMID_PID = 0,
864 __LIBC_SPMID_PPID,
865 __LIBC_SPMID_SID,
866 __LIBC_SPMID_PGRP,
867 __LIBC_SPMID_UID,
868 __LIBC_SPMID_EUID,
869 __LIBC_SPMID_SVUID,
870 __LIBC_SPMID_GID,
871 __LIBC_SPMID_EGID,
872 __LIBC_SPMID_SVGID
873} __LIBC_SPMID;
874
875
876/**
877 * Gets the specified Id.
878 *
879 * @returns Requested Id.
880 * @param enmId Identification to get.
881 */
882unsigned __libc_spmGetId(__LIBC_SPMID enmId);
883
884/**
885 * Sets the effective user id of the current process.
886 * If the caller is superuser real and saved user id are also set.
887 *
888 * @returns 0 on success.
889 * @returns Negative error code (errno) on failure.
890 * @param uid New effective user id.
891 * For superusers this is also the new real and saved user id.
892 */
893int __libc_spmSetUid(uid_t uid);
894
895/**
896 * Sets the real, effective and saved user ids of the current process.
897 * Unprivilegde users can only set them to the real user id, the
898 * effective user id or the saved user id.
899 *
900 * @returns 0 on success.
901 * @returns Negative error code (errno) on failure.
902 * @param ruid New real user id. Ignore if -1.
903 * @param euid New effective user id. Ignore if -1.
904 * @param svuid New Saved user id. Ignore if -1.
905 */
906int __libc_spmSetUidAll(uid_t ruid, uid_t euid, uid_t svuid);
907
908/**
909 * Sets the effective group id of the current process.
910 * If the caller is superuser real and saved group id are also set.
911 *
912 * @returns 0 on success.
913 * @returns Negative error code (errno) on failure.
914 */
915int __libc_spmSetGid(gid_t gid);
916
917/**
918 * Sets the real, effective and saved group ids of the current process.
919 * Unprivilegde users can only set them to the real group id, the
920 * effective group id or the saved group id.
921 *
922 * @returns 0 on success.
923 * @returns Negative error code (errno) on failure.
924 * @param rgid New real group id. Ignore if -1.
925 * @param egid New effective group id. Ignore if -1.
926 * @param svgid New Saved group id. Ignore if -1.
927 */
928int __libc_spmSetGidAll(gid_t rgid, gid_t egid, gid_t svgid);
929
930/**
931 * Locks the LIBC shared memory for short exclusive access.
932 * The call must call __libc_spmUnlock() as fast as possible and make
933 * no api calls until that is done.
934 *
935 * @returns 0 on success.
936 * @returns Negative error code (errno.h) on failure.
937 *
938 * @param pRegRec Pointer to the exception handler registration record.
939 * @param ppSPMHdr Where to store the pointer to the SPM header. Can be NULL.
940 *
941 * @remark Don't even think of calling this if you're not LIBC!
942 */
943int __libc_spmLock(__LIBC_PSPMXCPTREGREC pRegRec, __LIBC_PSPMHEADER *ppSPMHdr);
944
945/**
946 * Unlock the LIBC shared memory after call to __libc_spmLock().
947 *
948 * @returns 0 on success.
949 * @returns Negative error code (errno.h) on failure.
950 *
951 * @param pRegRec Pointer to the exception handler registration record.
952 *
953 * @remark Don't even think of calling this if you're not LIBC!
954 */
955int __libc_spmUnlock(__LIBC_PSPMXCPTREGREC pRegRec);
956
957/**
958 * Allocate memory from the LIBC shared memory.
959 *
960 * The SPM must be locked using __libc_spmLock() prior to calling this function!
961 *
962 * @returns Pointer to allocated memory on success.
963 * @returns NULL on failure.
964 *
965 * @param cbSize Size of memory to allocate.
966 *
967 * @remark Don't think of calling this if you're not LIBC!
968 */
969void * __libc_spmAllocLocked(size_t cbSize);
970
971/**
972 * Free memory allocated by __libc_spmAllocLocked() or __libc_spmAlloc().
973 *
974 * The SPM must be locked using __libc_spmLock() prior to calling this function!
975 *
976 * @returns 0 on success.
977 * @returns -1 and errno on failure.
978 *
979 * @param pv Pointer to memory block returned by __libc_SpmAlloc().
980 * NULL is allowed.
981 * @remark Don't think of calling this if you're not LIBC!
982 */
983int __libc_spmFreeLocked(void *pv);
984
985/**
986 * Allocate memory from the LIBC shared memory.
987 *
988 * @returns Pointer to allocated memory on success.
989 * @returns NULL on failure.
990 *
991 * @param cbSize Size of memory to allocate.
992 *
993 * @remark Don't think of calling this if you're not LIBC!
994 */
995void * __libc_spmAlloc(size_t cbSize);
996
997/**
998 * Free memory allocated by __libc_SpmAlloc().
999 *
1000 * @returns 0 on success.
1001 * @returns -1 and errno on failure.
1002 *
1003 * @param pv Pointer to memory block returned by __libc_SpmAlloc().
1004 * NULL is allowed.
1005 *
1006 * @remark Don't think of calling this if you're not LIBC!
1007 */
1008int __libc_spmFree(void *pv);
1009
1010/**
1011 * Register termination handler.
1012 *
1013 * This is a manual way of by passing a.out's broken weak symbols.
1014 */
1015void __libc_spmRegTerm(void (*pfnTerm)(void));
1016
1017
1018/**
1019 * Adds the first reference to a new socket.
1020 *
1021 * @returns 0 on success.
1022 * @returns Negative error code (errno.h) on failure.
1023 * @param iSocket The new socket.
1024 */
1025int __libc_spmSocketNew(int iSocket);
1026
1027/**
1028 * References a socket.
1029 *
1030 * @returns The new reference count.
1031 * The low 16-bits are are the global count.
1032 * The high 15-bits are are the process count.
1033 * @returns Negative error code (errno.h) on failure.
1034 * @param iSocket socket to reference.
1035 */
1036int __libc_spmSocketRef(int iSocket);
1037
1038/**
1039 * Dereferences a socket.
1040 *
1041 * @returns The new reference count.
1042 * The low 16-bits are are the global count.
1043 * The high 15-bits are are the process count.
1044 * @returns Negative error code (errno.h) on failure.
1045 * @param iSocket Socket to dereference.
1046 */
1047int __libc_spmSocketDeref(int iSocket);
1048
1049/**
1050 * Get the stored load average samples.
1051 *
1052 * @returns 0 on success.
1053 * @returns Negative error code (errno.h) on failure.
1054 * @param pLoadAvg Where to store the load average samples.
1055 * @param puTimestamp Where to store the current timestamp.
1056 */
1057int __libc_spmGetLoadAvg(__LIBC_PSPMLOADAVG pLoadAvg, unsigned *puTimestamp);
1058
1059/**
1060 * Get the stored load average samples.
1061 *
1062 * @returns 0 on success.
1063 * @returns Negative error code (errno.h) on failure.
1064 * @param pLoadAvg Where to store the load average samples.
1065 */
1066int __libc_spmSetLoadAvg(const __LIBC_SPMLOADAVG *pLoadAvg);
1067
1068/**
1069 * Marks the process as a full LIBC process.
1070 *
1071 * Up to this point it was just a process which LIBC happend to be loaded into.
1072 *
1073 * @returns 0 on success.
1074 * @returns Negative error code (errno.h) on failure.
1075 */
1076void __libc_spmExeInited(void);
1077
1078/**
1079 * Queues a signal on another process.
1080 *
1081 * @returns 0 on success.
1082 * @returns Negative error code (errno.h) on failure.
1083 * @param pSigInfo Signal to queue.
1084 * @param pid Pid to queue it on.
1085 * @param fQueued Set if the signal type is queued.
1086 */
1087int __libc_spmSigQueue(int iSignalNo, siginfo_t *pSigInfo, pid_t pid, int fQueued);
1088
1089/**
1090 * Callback which is called when a signal have been queued on a process.
1091 *
1092 * @returns 0 on success.
1093 * @returns Negative error code (errno.h) on failure.
1094 * @param iSignalNo The signal which have been queued.
1095 * @param pProcess Process which the signal was queued on.
1096 * @param pvUser User argument.
1097 */
1098typedef int (*__LIBC_PFNSPMSIGNALED)(int iSignalNo, const __LIBC_SPMPROCESS * pProcess, void *pvUser);
1099
1100/**
1101 * Queues a signal on another process.
1102 *
1103 * @returns 0 on success.
1104 * @returns Negative error code (errno.h) on failure.
1105 * @param iSignalNo The signal to send. If 0 only permissions are checked.
1106 * @param pSigInfo Signal to queue. If NULL only permissions are checked.
1107 * @param pgrp Process group to queue a signal on.
1108 * @param fQueued Set if the signal type is queued.
1109 * @param pfnCallback Pointer to callback function to post process signaled processes.
1110 * The callback must be _very_ careful. No crashing or blocking!
1111 * @param pvUser User argument specified to pfnCallback.
1112 */
1113int __libc_spmSigQueuePGrp(int iSignalNo, siginfo_t *pSigInfo, pid_t pgrp, int fQueued, __LIBC_PFNSPMSIGNALED pfnCallback, void *pvUser);
1114
1115/**
1116 * Get the signal set of pending signals.
1117 *
1118 * @returns Number of pending signals on success.
1119 * @returns 0 if no signals are pending.
1120 * @returns Negative error code (errno.h) on failure.
1121 * @param pSigSet Where to create the set of pending signals.
1122 */
1123int __libc_spmSigPending(sigset_t *pSigSet);
1124
1125/**
1126 * De-queues one or more pending signals of a specific type.
1127 *
1128 * @returns Number of de-queued signals on success.
1129 * @returns Negative error code (errno.h) on failure.
1130 * @param iSignalNo Signal type to dequeue.
1131 * @param paSignals Where to store the signals.
1132 * @param cSignals Size of the signal array.
1133 * @param cbSignal Size of one signal entry.
1134 */
1135int __libc_spmSigDequeue(int iSignalNo, siginfo_t *paSignals, unsigned cSignals, size_t cbSignal);
1136
1137
1138/**
1139 * Checks the SPM memory for trouble.
1140 *
1141 * @returns 0 on perfect state.
1142 * @returns -1 and errno on mutex failure.
1143 * @returns Number of failures if SPM is broken.
1144 * @param fBreakpoint Raise breakpoint exception if a problem is encountered.
1145 * @param fVerbose Log everything.
1146 */
1147int __libc_SpmCheck(int fBreakpoint, int fVerbose);
1148
1149__END_DECLS
1150
1151#endif /* __InnoTekLIBC_sharedpm_h__ */
Note: See TracBrowser for help on using the repository browser.