home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / unixlib / h / unix < prev   
Encoding:
Text File  |  2004-09-24  |  10.0 KB  |  319 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/unixlib/unix.h,v $
  4.  * $Date: 2004/09/23 22:16:39 $
  5.  * $Revision: 1.17 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  * UNIX is a registered trademark of AT&T Bell Laboratories
  10.  *
  11.  ***************************************************************************/
  12.  
  13. #ifndef __UNIXLIB_UNIX_H
  14. #define __UNIXLIB_UNIX_H 1
  15.  
  16. #ifndef __UNIXLIB_FEATURES_H
  17. #include <unixlib/features.h>
  18. #endif
  19. #ifndef __UNIXLIB_TYPES_H
  20. #include <unixlib/types.h>
  21. #endif
  22. #ifndef __UNIXLIB_FD_H
  23. #include <unixlib/fd.h>
  24. #endif
  25. #ifndef __UNIXLIB_SIGSTATE_H
  26. #include <unixlib/sigstate.h>
  27. #endif
  28.  
  29. #ifndef __UNIXLIB_TTY_H
  30. #include <unixlib/tty.h>
  31. #endif
  32. #ifndef __SETJMP_H
  33. #include <setjmp.h>
  34. #endif
  35. #ifndef __SYS_TIME_H
  36. #include <sys/time.h>
  37. #endif
  38. #ifndef __SYS_RESOURCE_H
  39. #include <sys/resource.h>
  40. #endif
  41. #ifndef __SYS_TYPES_H
  42. #include <sys/types.h>
  43. #endif
  44. #ifndef __LIMITS_H
  45. #include <limits.h>
  46. #endif
  47. #ifndef __KERNEL_H
  48. #include <kernel.h>
  49. #endif
  50.  
  51. __BEGIN_DECLS
  52.  
  53. #ifdef __UNIXLIB_INTERNALS
  54.  
  55. struct __process
  56. {
  57.   /* This process has a parent process.  */
  58.   unsigned int has_parent : 1;
  59.   /* This process terminated through a signal handler.  */
  60.   unsigned int signal_exit : 1;
  61.   /* This process terminated with a core dump.  */
  62.   unsigned int core_dump : 1;
  63.   /* This process just stopped.  */
  64.   unsigned int stopped : 1;
  65.   /* This process is controlling the tty. */
  66.   unsigned int tty_control : 1;
  67.   /* The type of tty this process is controlling.  */
  68.   unsigned int tty_type : 8;
  69.   /* The number of the signal we terminated with.  */
  70.   unsigned int signal : 8;
  71.   /* The return code of this process.  */
  72.   unsigned int return_code : 8;
  73. };
  74.  
  75. struct __child_process
  76. {
  77.   __uid_t uid;
  78.   __gid_t gid;
  79.   __pid_t pid;
  80.   int ppri, gpri, upri;
  81.   struct __process status;
  82.   struct rusage usage;
  83.   jmp_buf vreg; /* Process context.  */
  84. };
  85.  
  86. /* UnixLib 3.7b == 0xfedcfa5f.  */
  87. /* UnixLib 3.7c.beta == 0xfedcfa60.  */
  88. /* UnixLib 3.7c.19970803 == 0xfedcfa61.  */
  89. /* UnixLib 3.7c.19980504 == 0xfedcfa62.  */
  90. /* UnixLib 4.0.20040113 == 0xfedcfa63.  */
  91. #define _PROCMAGIC 0xfedcfa63
  92.  
  93. struct proc
  94. {
  95.   unsigned int __magic;  /* Magic word.  */
  96.   int argc, envc;  /* Command line and environment argument count.  */
  97.   char **envp;  /* Environment argument list.  */
  98.   char **argv;  /* Command line arguments.  */
  99.   struct __unixlib_fd fd[MAXFD];  /* File descriptors.  */
  100.   struct tty *tty;
  101.   __uid_t uid, euid;  /* Real and effective UID.  */
  102.   __gid_t gid, egid;  /* Real and effective GID.  */
  103.   __pid_t pgrp;  /* ID of process group that process belongs to.  */
  104.   __pid_t pid;  /* Process ID.  */
  105.   __pid_t ppid;  /* Parent process ID.  */
  106.   int ppri, gpri, upri;  /* Process priority, process group priority
  107.                 and user process priority.  */
  108.   __mode_t umask;  /* File creation mode mask.  */
  109.   struct __process status;  /* Process status.  */
  110.   struct itimerval itimers[__MAX_ITIMERS];  /* Defined interval timers.  */
  111.   struct rlimit limit[RLIMIT_NLIMITS];  /* Process resource limits.  */
  112.   struct rusage usage;  /* Resource usage of the process.  */
  113.   struct proc *pproc;  /* Pointer to the parent process's structure.  */
  114.   /* Details recorded about stopped or terminated children.  */
  115.   struct __child_process child[CHILD_MAX];
  116.   /* The signal states for this process. */
  117.   struct unixlib_sigstate sigstate;
  118.   /* Set to 1 if this process is currently sleeping, orphaned or stopped.
  119.      These could change at any time.  */
  120.   volatile int sleeping, orphaned, stopped;
  121.   jmp_buf vreg;  /* Process context.  */
  122.   /* UGLY HACK: In execve() we store cli malloc pointer prior to calling
  123.      child process.  The malloc store is then freed in __exret().  */
  124.   void *cli;
  125.   /* DDEUtils_Prefix value at the beginning of this process.  */
  126.   const char *dde_prefix;
  127. };
  128.  
  129. extern struct proc *__u;    /* current process */
  130.  
  131. struct pipe
  132. {
  133.   struct __unixlib_fd *p[2];
  134.   char *file;
  135.   struct pipe *next;
  136. };
  137.  
  138. extern struct pipe *__pipe;    /* list of currently active pipes */
  139.  
  140.  
  141. extern int __funcall_error (const char *, int, unsigned int);
  142. #ifndef __PARANOID
  143. #define __funcall(f,p) ((f)p)
  144. #else
  145. #define __funcall(f,p) \
  146.   ((((void *)(f) >= __image_ro_base) && (((unsigned int)(f) & ~3) == (unsigned int)(f)) \
  147.    ? 0 : __funcall_error(__FILE__,__LINE__,(unsigned int)(f))), (f)p)
  148. #endif
  149.  
  150.  
  151. /* Assembler exit.  */
  152.  
  153. /* __returncode is the final program's return code.
  154.  */
  155. extern void __exit (int __returncode) __attribute__ ((__noreturn__));
  156. extern void __exit_no_code (void) __attribute__ ((__noreturn__));
  157.  
  158. /* __unixlib_break is initialised to __image_rw_lomem & __unixlib_stack to
  159.    __image_rw_himem - STAKSIZ;
  160.    __unixlib_stack is extended downwards in chunks by x$stack_overflow()
  161.    and __unixlib_break is extended upwards by brk() and sbrk(). The sl
  162.    register is kept equal to __unixlib_stack + 512. Should x$stack_overflow()
  163.    attempt to extend __unixlib_stack below __unixlib_break then SIGEMT is
  164.    raised.
  165.    Should brk() or sbrk() be asked to extend __unixlib_break above
  166.    __unixlib_stack then they return with ENOMEM.  */
  167.  
  168. extern char *__unixlib_cli;        /* command line from OS_GetEnv */
  169. extern void *__image_ro_base;        /* BASE = Image$$RO$$Base */
  170. extern void *__image_rw_lomem;        /* LOMEM = Image$$RW$$Limit */
  171. extern void *__image_rw_himem;        /* HIMEM from OS_GetEnv */
  172. extern void *__unixlib_real_himem;    /* Real HIMEM  - application space limit */
  173. extern void *__unixlib_rwlimit;
  174.  
  175. extern void *__unixlib_break;        /* end of data area */
  176. extern void *__unixlib_real_break;    /* real end of data area */
  177. extern void *__unixlib_stack;        /* bottom of stack */
  178. extern void *__unixlib_stack_limit;
  179. extern int __codeshift;
  180. extern int __dynamic_num;
  181. extern void __dynamic_area_exit (void);
  182.  
  183. extern void __munmap_all (void);    /* Deallocate all mappings.  */
  184.  
  185. /* Zero if we are not executing within a TaskWindow.  Non-zero otherwise.  */
  186. extern int __taskwindow;
  187. /* Zero if we are running in command mode (not as a WIMP program).  Non-zero
  188.    otherwise and equals current WIMP task handle.  */
  189. extern int __taskhandle;
  190. /* Zero if we are running in 26-bit, non-zero for 32-bit */
  191. extern int __32bit;
  192.  
  193. extern unsigned int __time[2];    /* start time */
  194.  
  195. #define    __OS_ARTHUR    0xA0
  196. #define    __OS_RISCOS_200    0xA1
  197. #define    __OS_RISCOS_201    0xA2
  198. #define    __OS_RISCOS_300    0xA3
  199. #define    __OS_RISCOS_310    0xA4
  200. #define    __OS_RISCOS_350    0xA5
  201. #define    __OS_RISCOS_360    0xA6
  202. #define    __OS_RISCOS_370    0xA7
  203. #define    __OS_RISCOS_400    0xA8
  204.  
  205. /* FP flag reflecting Floating Point presence or not.  */
  206. extern int __fpflag;
  207.  
  208. /* Stop the interval timers.  */
  209. extern void __stop_itimers (void);
  210.  
  211. /* OS_ChangeEnvironment is used to set up exception handlers. These
  212.  * handlers use OS_CallBack to raise signals in the foreground process.
  213.  * RTFM (RISC OS PRM - 'The Program Environment') for more info. */
  214.  
  215. /* Reset handlers, etc. back to original state.  */
  216. extern void __env_riscos (void);
  217. extern void __env_unixlib (void);
  218.  
  219. /* vfork() & exec() */
  220.  
  221. extern void __vret (int);    /* return from child - calls __vexit() */
  222.  
  223. extern int *__vfork (void);    /* fork to child context */
  224. extern int *__vexit (int);    /* restore to parent context */
  225.  
  226. extern void __exret (void);    /* return from __exec() - calls __vret() */
  227.  
  228. extern void (*__exptr) (char *); /* pointer to __exec() routine */
  229. extern int __exlen;        /* length of __exec() routine */
  230. extern int __exshift;        /* __exec() shift */
  231. extern void __exec_cli (const char *) __attribute__ ((__noreturn__));
  232.  
  233. /* vfork weak link.  */
  234.  
  235. extern void (*___vret) (int);
  236.  
  237. /* Return unsigned int from STRING.  END, if non-null, points to character
  238.    after number.  */
  239. extern unsigned int __decstrtoui (const char *__string, char **__end);
  240.  
  241. /* If this variable is non-null then we allocated the current environment.  */
  242. extern char **__last_environ;
  243.  
  244. /* UnixLib's prefix for global RISC OS environment variables.  */
  245. #define __UNIX_ENV_PREFIX "UnixEnv$"
  246.  
  247. /* Add NAME=VALUE to the environment. If NAME is already in the environment,
  248.    only add when REPLACE is non-zero. If NAME is added to the environment
  249.    and ADD_TO_OS is non-zero, then also add it to the RISC OS global
  250.    environment.  */
  251. extern char *__addenv (const char *__name, const char *__value,
  252.                int __replace, int __add_to_os);
  253.  
  254. /* Lookup NAME in the environment and return value if found.  */
  255. extern char *__chkenv (const char *__name);
  256.  
  257. /* Get environment value from OS and copy into BUF and return a pointer to BUF.
  258.    If no match found then return NULL.  If BUF is NULL, then allocate space
  259.    as necessary, otherwise BUFLEN is length of supplied buffer.  */
  260. extern char *__getenv_from_os (const char *__name, char *__buf,
  261.                    size_t __buflen);
  262.  
  263. /* Return the integer value of NAME, from the RISC OS global environment.  */
  264. extern int __intenv (const char *__name);
  265.  
  266. /* Remove NAME from the OS environment. Returns -1 on failure or not found.  */
  267. extern int __remenv_from_os (const char *__name);
  268.  
  269. /* Set runtime features according to system variables.  */
  270. extern void __runtime_features (const char *__cmdline);
  271.  
  272. /* Print an error and exit the process. When MESSAGE is NULL, the printed
  273.    error message is based on the current errno value.  */
  274. extern void
  275. __unixlib_fatal (const char *__message) __attribute__ ((__noreturn__));
  276.  
  277. /* Initialize the signal code.  */
  278. extern void __unixlib_signal_initialise (struct proc *__p);
  279.  
  280. /* Resource limit initialisation */
  281. extern void __resource_initialise (struct proc *__p);
  282.  
  283. /* Stack manipulation */
  284.  
  285. #define STACK_CHUNK_MAGIC 0xf60690ff
  286.  
  287. /* Structure representing the bottom part of a stack chunk */
  288. /* See _syslib.s for more details */
  289. struct __stack_chunk
  290. {
  291.   unsigned int magic;
  292.   struct __stack_chunk *next;
  293.   struct __stack_chunk *prev;
  294.   unsigned int size;
  295.   void (*dealloc) (void *);
  296.   void (*returnaddr) (void);
  297. };
  298.  
  299. extern void __stackalloc_init (void);
  300. extern void *__stackalloc (size_t __size);
  301. extern void __stackfree (void *__ptr);
  302. extern int __stackalloc_trim (void);
  303. extern void __free_stack_chain (void *__ptr);
  304. extern void *__stackalloc_incr_wimpslot (int __incr);
  305.  
  306. /* Initialise the UnixLib world.  */
  307. void __unixinit (void);
  308.  
  309. void _main (void);
  310.  
  311. /* Shared between sys/exec.c & sys/_exec.s */
  312. extern _kernel_oserror *__exerr;
  313.  
  314. #endif  /* __UNIXLIB_INTERNALS */
  315.  
  316. __END_DECLS
  317.  
  318. #endif
  319.