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

Last change on this file since 2446 was 2323, checked in by bird, 20 years ago

o Implemented fchdir().
o Implemented inheritance of open directory handles. Unfortunately,

I ran out of size bits for the bundle type, so the SPM bit is no
longer compatible with earlier versions. The consequences
of this are related to inheritance and signaling - so recompile!

  • 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.3 KB
Line 
1/** $Id: sharedpm.h 2323 2005-09-25 11:01:36Z 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 * SPM fs inherit data.
281 */
282typedef struct __libc_SPMInhFS
283{
284 /** In Unix Tree global. */
285 int fInUnixTree;
286 /** Size of the unix root. Only set if there's an official root. */
287 size_t cchUnixRoot;
288 /** The current unix root if cchUnixRoot is non-zero. */
289 char szUnixRoot[1];
290} __LIBC_SPMINHFS;
291/** Pointer to FS inherit data. */
292typedef __LIBC_SPMINHFS *__LIBC_PSPMINHFS;
293
294/**
295 * SPM signal inherit data.
296 */
297typedef struct __libc_SPMInhSig
298{
299 /** The size of this structure. */
300 unsigned cb;
301 /** Mask of signals which should be ignored. */
302 sigset_t SigSetIGN;
303} __LIBC_SPMINHSIG;
304/** Pointer to Signal inherit data. */
305typedef __LIBC_SPMINHSIG *__LIBC_PSPMINHSIG;
306
307
308
309/**
310 * Inherit structure.
311 *
312 * All the data it contains is allocated in one block heap block!
313 */
314typedef struct __libc_SPMInherit
315{
316 /** Size of the inherit structure. */
317 size_t cb;
318 /** Pointer to the filehandle part.
319 * This is a succession of bundles terminating with a _END one. */
320 __LIBC_PSPMINHFHBHDR pFHBundles;
321 /** Pointer to the file system part. If NULL default values are assumed. */
322 __LIBC_PSPMINHFS pFS;
323 /** Pointer to the signal part. If NULL default values are assumed. */
324 __LIBC_PSPMINHSIG pSig;
325 /** Pointer to strings (filenames++).
326 * All the strings are NULL terminated and referenced by offset. */
327 char *pszStrings;
328} __LIBC_SPMINHERIT;
329/** Pointer to inherit data. */
330typedef __LIBC_SPMINHERIT *__LIBC_PSPMINHERIT;
331
332
333/** Pointer to per process data structure. */
334typedef struct __libc_SPMProcess *__LIBC_PSPMPROCESS;
335
336/**
337 * Per Process Data.
338 */
339typedef struct __libc_SPMProcess
340{
341 /** 0 - Pointer to the next process in the list.
342 * Every process is in one or another list depending on their state. */
343 volatile __LIBC_PSPMPROCESS pNext;
344 /** 4 - Pointer to the previous process in the list. */
345 volatile __LIBC_PSPMPROCESS pPrev;
346
347
348 /** Core
349 * @{ */
350 /** 8 - Version of the SPM which created this process. */
351 unsigned uVersion;
352 /** 12 - Number of references to this process.
353 * A process is not actually free till the reference count
354 * reaches 0. */
355 volatile unsigned cReferences;
356 /** 16 - State of this process. */
357 volatile __LIBC_SPMPROCSTAT enmState;
358 /** 20 - Process id. */
359 pid_t pid;
360 /** 24 - Process id of parent.
361 * This might not match the OS/2 one since there are no notification
362 * when a parent dies. */
363 pid_t pidParent;
364 /** @} */
365
366
367 /** User & Group
368 * @{ */
369 /** 28 - User id (also called Real User id). */
370 uid_t uid;
371 /** 32 - Effective user id. */
372 uid_t euid;
373 /** 36 - Saved user id. */
374 uid_t svuid;
375 /** 40 - Group id (also called Real Group id). */
376 gid_t gid;
377 /** 44 - Effecive group id. */
378 gid_t egid;
379 /** 48 - Saved group id. */
380 gid_t svgid;
381 /** 52 - Supplementary group ids. */
382 gid_t agidGroups[16 /*NGROUPS_MAX*/];
383 /** @} */
384
385
386 /** Misc
387 * @{ */
388 /** 116 - Creation timestamp. */
389 unsigned uTimestamp;
390 /** 120 - The SPM open count of this process. */
391 unsigned cSPMOpens;
392 /** 124 - Indicates that the process is a full featured LIBC process.
393 * Until this flag is set (atomically) it's not a good idea to
394 * queue signals on the process since it won't have a signal handler
395 * installed, and thus won't get to know about them.
396 */
397 volatile unsigned fExeInited;
398 /** 128 - Reserved for future use. Must be 0. */
399 unsigned uMiscReserved;
400 /** @} */
401
402
403 /** Fork
404 * @{ */
405 /** 132 - Pointer to fork module list head. */
406 void * volatile pvModuleHead;
407 /** 136 - Pointer to fork module list tail pointer. */
408 void * volatile * volatile ppvModuleTail;
409 /** 140 - Pointer to fork handle which a child should use when spawned by fork(). */
410 void *pvForkHandle;
411 /** @} */
412
413
414 /** Signals & Job Control
415 * @{ */
416 /** 144 - Incoming signal queue (FIFO).
417 * For signals which aren't queable only one signal can be queued.
418 */
419 volatile __LIBC_PSPMSIGNAL pSigHead;
420 /** 148 - Number of signals send.
421 * After _POSIX_SIGQUEUE_MAX signals only SIGCHLD will be allowed sent.
422 */
423 volatile unsigned cSigsSent;
424 /** 152 - Session Id. */
425 pid_t sid;
426 /** 156 - Process group. */
427 pid_t pgrp;
428 /** 160 - Reserved for future use. Must be 0. */
429 unsigned uSigReserved1;
430 /** 164 - Reserved for future use. Must be 0. */
431 unsigned uSigReserved2;
432 /** @} */
433
434
435 /** Termination
436 * @{ */
437 /** 168 - Termination information which will be sent to the parent process. */
438 __LIBC_PSPMCHILDNOTIFY pTerm;
439 /** 172 - List of child termination notifications. */
440 __LIBC_PSPMCHILDNOTIFY volatile pChildNotifyHead;
441 /** 176 - Pointer to the pointer where to insert the next child notification. */
442 __LIBC_PSPMCHILDNOTIFY volatile * volatile ppChildNotifyTail;
443 /** @} */
444
445 /** 180 - Per Process Sockets Reference Counters. (Data is process local.) */
446 uint16_t *pacTcpipRefs;
447 /** 184 - The Process priority (unix). */
448 int iNice;
449 /** 188 - Reserved fields with default value 0. */
450 unsigned auReserved[56 - 47];
451
452
453 /** 224 - Number of possible pointers to shared memory starting at pInherit.
454 * This means we can extend the structure with pointers for as long as we
455 * want and still have older LIBC versions cleanup the mess. */
456 unsigned cPoolPointers;
457 /** 228 - Pointer to data inherited from the parent process. */
458 __LIBC_PSPMINHERIT volatile pInherit;
459 /** 232 - Pointer to data inherited from the parent process when it's locked.
460 * When locked pInherit is NULL and this member points to the data instead.
461 * This prevents spmAlloc() from reclaiming it while it's in use. */
462 __LIBC_PSPMINHERIT volatile pInheritLocked;
463
464} __LIBC_SPMPROCESS;
465
466/** The current value for __LIBC_SPMPROCESS::cPoolPointers. */
467#define __LIBC_SPMPROCESS_POOLPOINTERS 2
468
469/**
470 * Pool chunk.
471 */
472typedef struct __libc_SPMPoolChunk
473{
474 /** Next block in the list of all blocks.. */
475 struct __libc_SPMPoolChunk *pPrev;
476 /** Previous block in the list of all blocks.. */
477 struct __libc_SPMPoolChunk *pNext;
478} __LIBC_SPMPOOLCHUNK, *__LIBC_PSPMPOOLCHUNK;
479
480/**
481 * Free pool chunk.
482 */
483typedef struct __libc_SPMPoolChunkFree
484{
485 /** Main list. */
486 __LIBC_SPMPOOLCHUNK core;
487 /** Next block in list of free nodes. */
488 struct __libc_SPMPoolChunkFree *pPrev;
489 /** Previous block in list of free nodes. */
490 struct __libc_SPMPoolChunkFree *pNext;
491 /** Size of this block. */
492 size_t cb;
493} __LIBC_SPMPOOLCHUNKFREE, *__LIBC_PSPMPOOLCHUNKFREE;
494
495/**
496 * Pool chunk alignment.
497 */
498#define SPM_POOL_ALIGN(size) (((size) + 7) & ~7)
499
500/**
501 * This structure contains the global TCP/IP socket data.
502 */
503typedef struct __libc_SPMTcpIp
504{
505 /** Size of the structure. */
506 size_t cb;
507 /** The number of elements in the acRefs array. */
508 unsigned cSockets;
509 /** Array containing the references counters for the sockets in the system. */
510 uint16_t acRefs[32768];
511} __LIBC_SPMTCPIP, *__LIBC_PSPMTCPIP;
512
513
514/**
515 * The structure contains the system load averages.
516 */
517typedef struct __libc_SPMLoadAvg
518{
519 /** Array of the three stamples.
520 * The entries are for 1, 5 and 15 min averages respectively.
521 *
522 * The samples them selfs are stored as integers and not as a
523 * double as the interface returns. The reason is that this is smaller
524 * and it's what both BSD and Linux is doing. The fraction part is
525 * the lower 11 bits (this is also identical to BSD and Linux).
526 */
527 uint32_t u32Samples[3];
528 /** Timestamp of the last update. */
529 unsigned uTimestamp;
530} __LIBC_SPMLOADAVG;
531/** Pointer to load averages. */
532typedef __LIBC_SPMLOADAVG *__LIBC_PSPMLOADAVG;
533
534
535/**
536 * This is the header of the LIBC shared memory.
537 */
538typedef struct __libc_SPMHeader
539{
540 /** 0 - SPM version. (the one which initialized the memory) */
541 unsigned uVersion;
542
543 /** 4 - Size of the shared memory. */
544 size_t cb;
545 /** 8 - Free memory. */
546 volatile size_t cbFree;
547 /** 12 - Start chunk of shared memory pool. */
548 volatile __LIBC_PSPMPOOLCHUNK pPoolHead;
549 /** 16 - End chunk of shared memory pool. */
550 volatile __LIBC_PSPMPOOLCHUNK pPoolTail;
551 /** 20 - Start free chunk in the shared memory pool. */
552 volatile __LIBC_PSPMPOOLCHUNKFREE pPoolFreeHead;
553 /** 24 - End free chunk in the shared memory pool. */
554 volatile __LIBC_PSPMPOOLCHUNKFREE pPoolFreeTail;
555
556 /** 28 - The size of one process block in this version of the shared memory. */
557 size_t cbProcess;
558 /** 32 - Array index by process state giving the head pointers
559 * to the processes in that state. */
560 volatile __LIBC_PSPMPROCESS apHeads[__LIBC_PROCSTATE_MAX];
561 /** 52 -List of free child (termination) notification structures. */
562 volatile __LIBC_PSPMCHILDNOTIFY pChildNotifyFreeHead;
563
564 /** 56 - Pointer to the tcpip globals. */
565 __LIBC_PSPMTCPIP pTcpip;
566 /** 60 - Creator pid. */
567 pid_t pidCreate;
568 /** 64 - Creation timestamp. */
569 __extension__ union
570 {
571#ifdef INCL_DOSDATETIME
572 DATETIME dtCreate;
573#endif
574 char ach[16];
575 };
576
577 /** 80 - System Load Averages. */
578 volatile __LIBC_SPMLOADAVG LoadAvg;
579
580 /** 96 - List of free signal structures. This will reduce
581 * the time spent allocating a signal structure in most cases.
582 * During SPM init 8 signal structures will be allocated and queued. */
583 volatile __LIBC_PSPMSIGNAL pSigFreeHead;
584 /** 100 - Number of free signal structures in the list.
585 * This is used to prevent the list from growing infinitly under stress.
586 * When cSigFree reaches 32 unused signal structures will be freed instead
587 * of put in the list. */
588 volatile unsigned cSigFree;
589 /** 104 - Number of active signals.
590 * This is used to keep a reasonable limit of the number of active signal
591 * structures so a process cannot exhaust the shared memory pool.
592 * The maximum is defined by cSigMaxActive.
593 */
594 volatile unsigned cSigActive;
595 /** 108 - The maximum number of active signals.
596 * This is initialized by the SPM creator but can be adjusted later.
597 */
598 unsigned cSigMaxActive;
599 /** 112 - Notification event semaphore.
600 * This semaphore is signaled when an event occurs. An event is either a signal
601 * or a child notification.
602 * At the moment this isn't used by anyone, but it's being signaled just in case.
603 */
604 unsigned long hevNotify;
605
606 /** 116 - Pointer to SysV Sempahore globals. */
607 struct __libc_SysV_Sem *pSysVSem;
608 /** 120 - Pointer to SysV Shared Memory globals. */
609 struct __libc_SysV_Shm *pSysVShm;
610 /** 124 - Pointer to SysV Message Queue globals. */
611 struct __libc_SysV_Msg *pSysVMsg;
612
613 /* 128 - The rest of the block, up to cbProcess, is undefined in this version.
614 * Future versions of LIBC may use this area assuming it's initalized with zeros.
615 */
616} __LIBC_SPMHEADER, *__LIBC_PSPMHEADER;
617
618
619/**
620 * SPM Exception handler registration record.
621 */
622typedef struct __LIBC_SPMXCPTREGREC
623{
624 __extension__ union
625 {
626#ifdef INCL_DOSEXCEPTIONS
627 EXCEPTIONREGISTRATIONRECORD Core;
628#endif
629 void *apv[2];
630 };
631 unsigned uFutureStuff0;
632 unsigned uFutureStuff1;
633} __LIBC_SPMXCPTREGREC;
634/** Pointer to SPM exception handler registration record. */
635typedef __LIBC_SPMXCPTREGREC *__LIBC_PSPMXCPTREGREC;
636
637
638
639
640/**
641 * Gets the current process.
642 *
643 * @returns Pointer to the current process.
644 * @returns NULL and errno on failure.
645 * @remark For this too __libc_spmRelease() must be called when done.
646 */
647__LIBC_PSPMPROCESS __libc_spmSelf(void);
648
649/**
650 * Gets the inherit data associated with the current process.
651 * This call prevents it from being release by underrun handling.
652 *
653 * @returns Pointer to inherit data.
654 * The caller must call __libc_spmInheritRelease() when done.
655 * @returns NULL and errno if no inherit data.
656 */
657__LIBC_PSPMINHERIT __libc_spmInheritRequest(void);
658
659/**
660 * Releases the inherit data locked by the __libc_spmInheritRequest() call.
661 *
662 * @returns 0 on success.
663 * @returns -1 and errno on failure.
664 */
665int __libc_spmInheritRelease(void);
666
667/**
668 * Frees the inherit data of this process.
669 * This is called when the executable is initialized.
670 */
671void __libc_spmInheritFree(void);
672
673/**
674 * Create an embryo related to the current process.
675 *
676 * @returns pointer to the embryo process.
677 * The allocated process must be released by the caller.
678 * @returns NULL and errno on failure.
679 * @param pidParent The parent pid (i.e. this process).
680 */
681__LIBC_PSPMPROCESS __libc_spmCreateEmbryo(pid_t pidParent);
682
683/**
684 * Searches for a process given by pid.
685 *
686 * @returns Pointer to the desired process on success.
687 * @returns NULL and errno on failure.
688 * @param pid Process id to search for.
689 * @param enmState The state of the process.
690 * @remark Call __libc_spmRelease() to release the result.
691 */
692__LIBC_PSPMPROCESS __libc_spmQueryProcess(pid_t pid);
693
694/**
695 * Searches for a process with a given pid and state.
696 *
697 * @returns Pointer to the desired process on success.
698 * @returns NULL and errno on failure.
699 * @param pid Process id to search for.
700 * @param enmState The state of the process.
701 * @remark Call __libc_spmRelease() to release the result.
702 */
703__LIBC_PSPMPROCESS __libc_spmQueryProcessInState(pid_t pid, __LIBC_SPMPROCSTAT enmState);
704
705/**
706 * Process enumeration callback function.
707 *
708 * @returns 0 to continue the enumeration.
709 * @returns Non-zero to stop the enumeration. The enumeration
710 * api will return this same value.
711 *
712 * @param pProcess The current process.
713 * @param pvUser The user argument.
714 * @remark It is *not* allowed to terminate the thread or process, do long jumps
715 * or anything else which causes the enumeration function not to release
716 * the lock.
717 * It is not allowed to do expensive stuff either as it will harm other
718 * processes in the system which want to access the shared process facility!
719 */
720typedef int __LIBC_FNSPNENUM(__LIBC_PSPMPROCESS pProcess, void *pvUser);
721/** Pointer to an process enumeration callback function. */
722typedef __LIBC_FNSPNENUM *__LIBC_PFNSPNENUM;
723
724/**
725 * Enumerates all alive processes in a group.
726 *
727 * @returns 0 on success.
728 * @returns -ESRCH if the process group wasn't found.
729 * @returns -EINVAL if pgrp is negative.
730 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
731 *
732 * @param pgrp The process group id. 0 is an alias for the process group the caller belongs to.
733 * @param pfnCallback Callback function.
734 * @param pvUser User argument to the callback.
735 */
736int __libc_spmEnumProcessesByPGrp(pid_t pgrp, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
737
738/**
739 * Enumerates all alive processes owned by a user.
740 *
741 * @returns 0 on success.
742 * @returns -ESRCH if the process group wasn't found.
743 * @returns -EINVAL if uid is negative.
744 * @returns Whatever non-zero value the pfnCallback function returns to stop the enumeration.
745 *
746 * @param uid The process user id.
747 * @param pfnCallback Callback function.
748 * @param pvUser User argument to the callback.
749 */
750int __libc_spmEnumProcessesByUser(uid_t uid, __LIBC_PFNSPNENUM pfnCallback, void *pvUser);
751
752/**
753 * Release reference to the given process.
754 *
755 * @returns 0 on success.
756 * @returns -1 on failure.
757 * @param pProcess Pointer to process to release.
758 */
759int __libc_spmRelease(__LIBC_PSPMPROCESS pProcess);
760
761/**
762 * Checks if the calling process can see the specfied one.
763 *
764 * @returns 0 if it can see it.
765 * @returns -ESRCH (or other approriate error code) if it cannot.
766 *
767 * @param pProcess The process in question.
768 */
769int __libc_spmCanSee(__LIBC_PSPMPROCESS pProcess);
770
771/**
772 * Checks if we are a system-wide super user.
773 *
774 * @returns 0 if we are.
775 * @returns -EPERM if we aren't.
776 */
777int __libc_spmIsSuperUser(void);
778
779/**
780 * Checks if the caller can modify the specified process.
781 *
782 * @returns 0 if we can modify it.
783 * @returns -EPERM if we cannot modify it.
784 * @param pProcess The process in question.
785 */
786int __libc_spmCanModify(__LIBC_PSPMPROCESS pProcess);
787
788/**
789 * Checks if the calling process is a member of the specified group.
790 *
791 * @returns 0 if member.
792 * @returns -EPERM if not member.
793 * @param gid The group id in question.
794 */
795int __libc_spmIsGroupMember(gid_t gid);
796
797/**
798 * Check if the caller can access the SysV IPC object as requested.
799 *
800 * @returns 0 if we can.
801 * @returns -EPERM if we cannot.
802 * @param pPerm The IPC permission structure.
803 * @param Mode The access request. IPC_M, IPC_W or IPC_R.
804 */
805int __libc_spmCanIPC(struct ipc_perm *pPerm, mode_t Mode);
806
807/**
808 * Marks the current process (if we have it around) as zombie
809 * or dead freeing all resources associated with it.
810 *
811 * @param uReason The OS/2 exit list type reason code.
812 * This is only used if the current code is NONE.
813 * @param iExitCode The unix exit code for this process.
814 * This is only if the current code is 0.
815 * @remark this might not be a sufficient interface for process termination but we'll see.
816 */
817void __libc_spmTerm(__LIBC_EXIT_REASON enmDeathReason, int iExitCode);
818
819/**
820 * Query about notifications from a specific child process.
821 * The notifications are related to death, the cause and such.
822 *
823 * @returns 0 on success.
824 * @returns Negative error code (errno.h) on failure.
825 * @param pid Process id.
826 * @param pNotify Where to store the notification from the child.
827 */
828int __libc_spmQueryChildNotification(pid_t pid, __LIBC_PSPMCHILDNOTIFY pNotifyOut);
829
830/**
831 * Validates a process group id.
832 *
833 * @returns 0 if valid.
834 * @returns -ESRCH if not valid.
835 * @param pgrp Process group id to validate. 0 if the same as
836 * the same as the current process.
837 * @param fOnlyChildren Restrict the search to immediate children.
838 */
839int __libc_spmValidPGrp(pid_t pgrp, int fOnlyChildren);
840
841
842/**
843 * Identificators which can be obtained using __libc_spmGetId().
844 */
845typedef enum __LIBC_SPMID
846{
847 __LIBC_SPMID_PID = 0,
848 __LIBC_SPMID_PPID,
849 __LIBC_SPMID_SID,
850 __LIBC_SPMID_PGRP,
851 __LIBC_SPMID_UID,
852 __LIBC_SPMID_EUID,
853 __LIBC_SPMID_SVUID,
854 __LIBC_SPMID_GID,
855 __LIBC_SPMID_EGID,
856 __LIBC_SPMID_SVGID
857} __LIBC_SPMID;
858
859
860/**
861 * Gets the specified Id.
862 *
863 * @returns Requested Id.
864 * @param enmId Identification to get.
865 */
866unsigned __libc_spmGetId(__LIBC_SPMID enmId);
867
868/**
869 * Sets the effective user id of the current process.
870 * If the caller is superuser real and saved user id are also set.
871 *
872 * @returns 0 on success.
873 * @returns Negative error code (errno) on failure.
874 * @param uid New effective user id.
875 * For superusers this is also the new real and saved user id.
876 */
877int __libc_spmSetUid(uid_t uid);
878
879/**
880 * Sets the real, effective and saved user ids of the current process.
881 * Unprivilegde users can only set them to the real user id, the
882 * effective user id or the saved user id.
883 *
884 * @returns 0 on success.
885 * @returns Negative error code (errno) on failure.
886 * @param ruid New real user id. Ignore if -1.
887 * @param euid New effective user id. Ignore if -1.
888 * @param svuid New Saved user id. Ignore if -1.
889 */
890int __libc_spmSetUidAll(uid_t ruid, uid_t euid, uid_t svuid);
891
892/**
893 * Sets the effective group id of the current process.
894 * If the caller is superuser real and saved group id are also set.
895 *
896 * @returns 0 on success.
897 * @returns Negative error code (errno) on failure.
898 */
899int __libc_spmSetGid(gid_t gid);
900
901/**
902 * Sets the real, effective and saved group ids of the current process.
903 * Unprivilegde users can only set them to the real group id, the
904 * effective group id or the saved group id.
905 *
906 * @returns 0 on success.
907 * @returns Negative error code (errno) on failure.
908 * @param rgid New real group id. Ignore if -1.
909 * @param egid New effective group id. Ignore if -1.
910 * @param svgid New Saved group id. Ignore if -1.
911 */
912int __libc_spmSetGidAll(gid_t rgid, gid_t egid, gid_t svgid);
913
914/**
915 * Locks the LIBC shared memory for short exclusive access.
916 * The call must call __libc_spmUnlock() as fast as possible and make
917 * no api calls until that is done.
918 *
919 * @returns 0 on success.
920 * @returns Negative error code (errno.h) on failure.
921 *
922 * @param pRegRec Pointer to the exception handler registration record.
923 * @param ppSPMHdr Where to store the pointer to the SPM header. Can be NULL.
924 *
925 * @remark Don't even think of calling this if you're not LIBC!
926 */
927int __libc_spmLock(__LIBC_PSPMXCPTREGREC pRegRec, __LIBC_PSPMHEADER *ppSPMHdr);
928
929/**
930 * Unlock the LIBC shared memory after call to __libc_spmLock().
931 *
932 * @returns 0 on success.
933 * @returns Negative error code (errno.h) on failure.
934 *
935 * @param pRegRec Pointer to the exception handler registration record.
936 *
937 * @remark Don't even think of calling this if you're not LIBC!
938 */
939int __libc_spmUnlock(__LIBC_PSPMXCPTREGREC pRegRec);
940
941/**
942 * Allocate memory from the LIBC shared memory.
943 *
944 * The SPM must be locked using __libc_spmLock() prior to calling this function!
945 *
946 * @returns Pointer to allocated memory on success.
947 * @returns NULL on failure.
948 *
949 * @param cbSize Size of memory to allocate.
950 *
951 * @remark Don't think of calling this if you're not LIBC!
952 */
953void * __libc_spmAllocLocked(size_t cbSize);
954
955/**
956 * Free memory allocated by __libc_spmAllocLocked() or __libc_spmAlloc().
957 *
958 * The SPM must be locked using __libc_spmLock() prior to calling this function!
959 *
960 * @returns 0 on success.
961 * @returns -1 and errno on failure.
962 *
963 * @param pv Pointer to memory block returned by __libc_SpmAlloc().
964 * NULL is allowed.
965 * @remark Don't think of calling this if you're not LIBC!
966 */
967int __libc_spmFreeLocked(void *pv);
968
969/**
970 * Allocate memory from the LIBC shared memory.
971 *
972 * @returns Pointer to allocated memory on success.
973 * @returns NULL on failure.
974 *
975 * @param cbSize Size of memory to allocate.
976 *
977 * @remark Don't think of calling this if you're not LIBC!
978 */
979void * __libc_spmAlloc(size_t cbSize);
980
981/**
982 * Free memory allocated by __libc_SpmAlloc().
983 *
984 * @returns 0 on success.
985 * @returns -1 and errno on failure.
986 *
987 * @param pv Pointer to memory block returned by __libc_SpmAlloc().
988 * NULL is allowed.
989 *
990 * @remark Don't think of calling this if you're not LIBC!
991 */
992int __libc_spmFree(void *pv);
993
994/**
995 * Register termination handler.
996 *
997 * This is a manual way of by passing a.out's broken weak symbols.
998 */
999void __libc_spmRegTerm(void (*pfnTerm)(void));
1000
1001
1002/**
1003 * Adds the first reference to a new socket.
1004 *
1005 * @returns 0 on success.
1006 * @returns Negative error code (errno.h) on failure.
1007 * @param iSocket The new socket.
1008 */
1009int __libc_spmSocketNew(int iSocket);
1010
1011/**
1012 * References a socket.
1013 *
1014 * @returns The new reference count.
1015 * The low 16-bits are are the global count.
1016 * The high 15-bits are are the process count.
1017 * @returns Negative error code (errno.h) on failure.
1018 * @param iSocket socket to reference.
1019 */
1020int __libc_spmSocketRef(int iSocket);
1021
1022/**
1023 * Dereferences a socket.
1024 *
1025 * @returns The new reference count.
1026 * The low 16-bits are are the global count.
1027 * The high 15-bits are are the process count.
1028 * @returns Negative error code (errno.h) on failure.
1029 * @param iSocket Socket to dereference.
1030 */
1031int __libc_spmSocketDeref(int iSocket);
1032
1033/**
1034 * Get the stored load average samples.
1035 *
1036 * @returns 0 on success.
1037 * @returns Negative error code (errno.h) on failure.
1038 * @param pLoadAvg Where to store the load average samples.
1039 * @param puTimestamp Where to store the current timestamp.
1040 */
1041int __libc_spmGetLoadAvg(__LIBC_PSPMLOADAVG pLoadAvg, unsigned *puTimestamp);
1042
1043/**
1044 * Get the stored load average samples.
1045 *
1046 * @returns 0 on success.
1047 * @returns Negative error code (errno.h) on failure.
1048 * @param pLoadAvg Where to store the load average samples.
1049 */
1050int __libc_spmSetLoadAvg(const __LIBC_SPMLOADAVG *pLoadAvg);
1051
1052/**
1053 * Marks the process as a full LIBC process.
1054 *
1055 * Up to this point it was just a process which LIBC happend to be loaded into.
1056 *
1057 * @returns 0 on success.
1058 * @returns Negative error code (errno.h) on failure.
1059 */
1060void __libc_spmExeInited(void);
1061
1062/**
1063 * Queues a signal on another process.
1064 *
1065 * @returns 0 on success.
1066 * @returns Negative error code (errno.h) on failure.
1067 * @param pSigInfo Signal to queue.
1068 * @param pid Pid to queue it on.
1069 * @param fQueued Set if the signal type is queued.
1070 */
1071int __libc_spmSigQueue(int iSignalNo, siginfo_t *pSigInfo, pid_t pid, int fQueued);
1072
1073/**
1074 * Callback which is called when a signal have been queued on a process.
1075 *
1076 * @returns 0 on success.
1077 * @returns Negative error code (errno.h) on failure.
1078 * @param iSignalNo The signal which have been queued.
1079 * @param pProcess Process which the signal was queued on.
1080 * @param pvUser User argument.
1081 */
1082typedef int (*__LIBC_PFNSPMSIGNALED)(int iSignalNo, const __LIBC_SPMPROCESS * pProcess, void *pvUser);
1083
1084/**
1085 * Queues a signal on another process.
1086 *
1087 * @returns 0 on success.
1088 * @returns Negative error code (errno.h) on failure.
1089 * @param iSignalNo The signal to send. If 0 only permissions are checked.
1090 * @param pSigInfo Signal to queue. If NULL only permissions are checked.
1091 * @param pgrp Process group to queue a signal on.
1092 * @param fQueued Set if the signal type is queued.
1093 * @param pfnCallback Pointer to callback function to post process signaled processes.
1094 * The callback must be _very_ careful. No crashing or blocking!
1095 * @param pvUser User argument specified to pfnCallback.
1096 */
1097int __libc_spmSigQueuePGrp(int iSignalNo, siginfo_t *pSigInfo, pid_t pgrp, int fQueued, __LIBC_PFNSPMSIGNALED pfnCallback, void *pvUser);
1098
1099/**
1100 * Get the signal set of pending signals.
1101 *
1102 * @returns Number of pending signals on success.
1103 * @returns 0 if no signals are pending.
1104 * @returns Negative error code (errno.h) on failure.
1105 * @param pSigSet Where to create the set of pending signals.
1106 */
1107int __libc_spmSigPending(sigset_t *pSigSet);
1108
1109/**
1110 * De-queues one or more pending signals of a specific type.
1111 *
1112 * @returns Number of de-queued signals on success.
1113 * @returns Negative error code (errno.h) on failure.
1114 * @param iSignalNo Signal type to dequeue.
1115 * @param paSignals Where to store the signals.
1116 * @param cSignals Size of the signal array.
1117 * @param cbSignal Size of one signal entry.
1118 */
1119int __libc_spmSigDequeue(int iSignalNo, siginfo_t *paSignals, unsigned cSignals, size_t cbSignal);
1120
1121
1122/**
1123 * Checks the SPM memory for trouble.
1124 *
1125 * @returns 0 on perfect state.
1126 * @returns -1 and errno on mutex failure.
1127 * @returns Number of failures if SPM is broken.
1128 * @param fBreakpoint Raise breakpoint exception if a problem is encountered.
1129 * @param fVerbose Log everything.
1130 */
1131int __libc_SpmCheck(int fBreakpoint, int fVerbose);
1132
1133__END_DECLS
1134
1135#endif /* __InnoTekLIBC_sharedpm_h__ */
Note: See TracBrowser for help on using the repository browser.