home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / include / user.h < prev    next >
C/C++ Source or Header  |  1996-12-11  |  14KB  |  407 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #ifndef _USER_H
  21. #define _USER_H
  22.  
  23. #include <sys/time.h>
  24. #include <sys/resource.h>
  25. #include <sys/syslog.h>
  26. #include <sys/param.h>
  27. #include <sys/socket.h>
  28. #include <setjmp.h>
  29. #include <machine/reg.h>
  30. #include <stdio.h>
  31. #include <netdb.h>
  32. #include <pwd.h>
  33. #include <grp.h>
  34. #include <netinet/in.h>
  35. #include <arpa/inet.h>
  36. #include <arpa/nameser.h>
  37. #include <resolv.h>
  38.  
  39. /* internal structure used by malloc(), kmalloc() and friends */
  40. struct malloc_data {
  41.   struct MinList    md_list;
  42.   unsigned int        md_malloc_sbrk_used;
  43. };
  44.  
  45. /* internal structure used by the stackextend code */
  46. struct stackframe
  47. {
  48.   struct stackframe *next;    /* NULL if there is no next one */
  49.   void *savesp;            /* stored sp for next underlying stackframe */
  50.   void *upper;            /* end of this stackframe+1 */
  51. };
  52.  
  53.  
  54. /*
  55.  * One structure allocated per session.
  56.  */
  57. struct    session {
  58.     int    s_count;        /* ref cnt; pgrps in session */
  59. /*    struct    proc *s_leader;        *//* session leader */
  60.     int    pgrp;            /* controlling process group */
  61. /*    struct    vnode *s_ttyvp;        *//* vnode of controlling terminal */
  62. /*    struct    tty *s_ttyp;        *//* controlling terminal */
  63. /*    char    s_login[MAXLOGNAME];    *//* setlogin() name */
  64. };
  65.  
  66. /*
  67.  * One structure allocated per process group.
  68.  */
  69. struct    pgrp {
  70.     struct    pgrp *pg_hforw;        /* forward link in hash bucket */
  71.     struct    proc *pg_mem;        /* pointer to pgrp members */
  72.     struct    session *pg_session;    /* pointer to session */
  73.     pid_t    pg_id;            /* pgrp id */
  74.     int    pg_jobc;        /* # procs qualifying pgrp for job control */
  75. };
  76.  
  77. /* internal structure used by mmap() and friends */
  78. struct mmap_mem {
  79.     struct mmap_mem    *next;
  80.     void        *addr;
  81.     size_t        length;
  82.     int        fd;
  83.     int        offset;
  84.     int        prot;
  85.     int        flags;
  86. };
  87.  
  88. /*
  89.  * Per process structure
  90.  */
  91.  
  92. /* default size */
  93. #define A4_POINTERS 100
  94.  
  95. /* NB: a list of pointers for shared libraries is allocated *before*
  96.    the start of this struct! So the struct is actually larger, but
  97.    the advantage of this is that the number of free library slots is
  98.    easy to enlarge through a setting, without scrambling the offsets
  99.    within the 'regular' user struct. */
  100.  
  101. struct user {
  102.     /* both a magic cookie and a way to get at the library base thru u */
  103.     struct ixemul_base    *u_ixbase;
  104.     void            *u_user;    /* freely usable user field */
  105.  
  106.     long        u_a4_pointers_size;    /* number of a4 pointers */
  107.  
  108. /* The remainder of this structure is PRIVATE and may change without notice! */
  109.  
  110. /* 1.3 - signal management */
  111.     sig_t        u_signal[NSIG];        /* disposition of signals */
  112.     int        u_sigmask[NSIG];    /* signals to be blocked */
  113.     sigset_t    u_sigonstack;        /* signals to take on sigstack */
  114.     sigset_t    u_sigintr;        /* signals that interrupt syscalls */
  115.     sigset_t    u_oldmask;        /* saved mask from before sigpause */
  116.     struct    sigstack u_sigstack;    /* sp & on stack state variable */
  117. #define    u_onstack    u_sigstack.ss_onstack
  118. #define    u_sigsp        u_sigstack.ss_sp
  119.     int        u_sig;            /* for core dump/debugger XXX */
  120.     int        u_code;            /* for core dump/debugger XXX */
  121.     
  122.     int        p_flag;            /* process flags, as necessary.. */
  123.     char        p_stat;
  124.     int        p_xstat;        /* exit status */
  125.     char        p_cursig;
  126.     sigset_t    p_sig;            /* signals pending to this process */
  127.     sigset_t    p_sigmask;        /* current signal mask */
  128.     sigset_t    p_sigignore;        /* signals being ignored */
  129.     sigset_t    p_sigcatch;        /* signals being caught by user */
  130.  
  131.     caddr_t     p_wchan;        /* event process is awaiting */
  132.  
  133.  
  134. /* 1.4 - descriptor management (for shared library version) */
  135.     struct    file *u_ofile[NOFILE];    /* file structures for open files */
  136.     char    u_pofile[NOFILE];    /* per-process flags of open files */
  137.     int    u_lastfile;        /* high-water mark of u_ofile */
  138. #define    UF_EXCLOSE     0x1        /* auto-close on exec */
  139.     short    u_cmask;        /* mask for file creation */
  140.  
  141. /* 1.5 - timing and statistics */
  142.     struct    rusage u_ru;        /* stats for this proc */
  143.     struct    rusage u_cru;        /* sum of stats for reaped children */
  144.     struct    itimerval u_timer[3];
  145.     struct    timeval u_start;
  146.     short    u_acflag;
  147.  
  148.     struct uprof {            /* profile arguments */
  149.         short    *pr_base;    /* buffer base */
  150.         unsigned pr_size;    /* buffer size */
  151.         unsigned pr_off;    /* pc offset */
  152.         unsigned pr_scale;    /* pc scaling */
  153.     } u_prof;
  154.     unsigned        u_prof_last_pc;    /* last function that called mcount() */
  155.  
  156. /* 1.6 - resource controls */
  157.     struct    rlimit u_rlimit[RLIM_NLIMITS];
  158.  
  159. /* amiga specific stuff */
  160.     struct malloc_data    u_md;
  161.     
  162.     struct MsgPort        *u_sync_mp;    /* PA_SIGNAL message port */
  163.     struct timerequest     *u_time_req;
  164.     int            *u_errno;
  165.     BPTR            u_startup_cd;
  166.     
  167.     int            u_ringring;    /* used in sleep.c and usleep.c */
  168.  
  169.     char            ***u_environ;
  170.  
  171.     /* used to handle AmigaOS signals. see SIGMSG  */
  172.         u_int            u_lastrcvsig;
  173.         char            u_sleep_sig;
  174.         char            u_pipe_sig;
  175.         
  176.         /* c-startup stuff */
  177.         jmp_buf            u_jmp_buf;
  178.         char             *u_argline;
  179.         u_int            u_arglinelen;
  180.         int            u_expand_cmd_line;
  181.  
  182.     struct atexit        *u_atexit;
  183.     
  184.     char            u_getenv_buf[255];
  185.     
  186.     UBYTE            u_otask_flags;
  187.     void            (*u_olaunch)();
  188.     APTR            u_otrap_code;
  189.     APTR            u_otrap_data;
  190.     struct Interrupt    u_itimerint;    /* 1 interrupt / task */
  191.  
  192.     int            p_pgrp;        /* process group */
  193.     struct session        *u_session;    /* session pointer */
  194.  
  195.     char            *u_strtok_last;    /* moved with 37.8 */
  196.     
  197.     /* vfork() support */
  198.     struct MinList        p_zombies;    /* list of death messages */
  199.     int            p_zombie_sig;    /* signal to set when a child died */
  200.     struct Process        *p_pptr;    /* parent */
  201.     struct Process        *p_opptr;    /* old parent (used in ptrace) */
  202.     struct Process        *p_cptr;    /* last recently created child */
  203.     struct Process        *p_osptr;    /* older sybling */
  204.     struct Process        *p_ysptr;    /* younger sybling */
  205.     struct vfork_msg    *p_vfork_msg;
  206.  
  207.     struct my_seg        *u_segs;    /* execve stores the SegList here */
  208.     u_long            u_start_pc;     /* start and end addresses */
  209.         u_long                  u_end_pc;       /* of the code hunk */
  210.     void            (*u_oswitch)();
  211.     
  212.     /* stdio support comes here */
  213.     char            u_tmpnam_buf[MAXPATHLEN]; /* quite large.. */
  214.     u_long            u_tmpcount;
  215. #include <glue.h>
  216.     struct glue        u_sglue;
  217.     /* the 3 `standard' FILE pointers (!) are here */
  218.     void            *u_sF[3];
  219.  
  220.     /* vfork() support #2 */
  221.     void            *u_save_sp;    /* when vfork'd, this is the `real' sp */
  222.     jmp_buf            u_vfork_frame;    /* for the parent in vfork () */
  223.     u_int            u_mini_stack[1000]; /* 4K stack while in vfork () */
  224.  
  225.     /* stack watcher. When usp < u_red_zone && ix.ix_watch_stack -> SIGSEGV */
  226.     void            *u_red_zone;
  227.  
  228.     /* base relative support. This even works for pure programs ! */
  229.     u_int            u_a4;
  230.     
  231.     /* currently there's just 1, meaning don't trace me */
  232.     u_int            u_trace_flags;
  233.     
  234.     /* this is for getmntinfo() */
  235.     struct statfs        *u_mntbuf;
  236.     int            u_mntsize;
  237.     long            u_bufsize;
  238.     
  239.     /* this is for SIGWINCH support. */
  240.     struct IOStdReq        *u_idev_req;
  241.     struct Window        *u_window;    /* the watched window */
  242.     struct Interrupt    u_idev_int;
  243.  
  244.     /* for `ps' (or dump as it's called for now.. ) */
  245.     char            *p_wmesg;
  246.     
  247.     /* new support for `real' process groups, control ttys etc.. */
  248.     struct user        *p_pgrpnxt;
  249.     struct pgrp        *p_pgrpptr;
  250.     struct Process        *p_exec_proc;    /* to get back to struct Process */
  251.     
  252.     /* to be able to switch memory lists on the fly, as required when vfork'd
  253.        processes are supposed to allocate memory from their parents pool until
  254.        they detach. */
  255.     struct malloc_data    *u_mdp;
  256.     
  257.     /* data needed for network support */
  258.     struct Library        *u_ixnetbase;
  259.     void            *u_ixnet;
  260.     int                     *u_h_errno;
  261.  
  262.     /* ptrace() and kern_sig.c:stopped_process_handler() interface.  */
  263.     struct reg              *u_regs;
  264.     struct fpreg            *u_fpregs;
  265.     int            u_mask_state;
  266.  
  267.     /* strftime() globals */
  268.     size_t            u_gsize;
  269.     char            *u_pt;
  270.     
  271.     /* putenv() global */
  272.     int            u_env_alloced;
  273.     
  274.     /* rand() global */
  275.     u_long            u_rand_next;
  276.     
  277.     /* stuff for stackextend */
  278.     void            *u_tc_splower;    /* original entries of task structure */
  279.     void            *u_tc_spupper;    /* to restore them at exit */
  280.     void            *u_org_lower;    /* original stackborders */
  281.     void            *u_org_upper;
  282.     void            **u_stk_limit;    /* pointer to limit variable */
  283.     unsigned long        u_stk_argbt;    /* Maximum size of arguments */
  284.     struct stackframe    *u_stk_used;    /* used stackframes */
  285.     struct stackframe    *u_stk_spare;    /* spare stackframes */
  286.     unsigned long        u_stk_current;    /* current stack size */
  287.     unsigned long        u_stk_max;    /* maximum stack size so far */
  288.  
  289.     char u_root_directory[MAXPATHLEN];    /* for chroot() */
  290.     short            u_is_root;    /* current directory is root */
  291.  
  292.     /* stuff for muFS support */
  293.     struct muUserInfo       *u_UserInfo;    /* private muUserInfo to use */
  294.     struct muGroupInfo      *u_GroupInfo;   /* private muGroupInfo to use */
  295.     struct muUserInfo       *u_fileUserInfo;    /* private muUserInfo for database ops */
  296.     struct muGroupInfo      *u_fileGroupInfo;   /* private muGroupInfo for database ops */
  297.     BOOL                    u_groupfileopen;    /* dummy for emulation */
  298.     BOOL                    u_passwdfileopen;   /* dummy for emulation */
  299.     struct passwd           u_passwd;       /* static buffer to hold the data */
  300.     struct group            u_group;        /* ditto */
  301.  
  302.     FILE            *u_grp_fp;    /* File pointer to the groups file */
  303.     int            u_grp_stayopen;    /* TRUE if group file should stay open */
  304.     char            **u_members;    /* array of group members */
  305.     char            *u_grp_line;    /* buffer for reading a line from the group file */
  306.  
  307.     /* Support for ixnet functions */
  308.     FILE            *u_serv_fp;    /* File pointer to services file */
  309.     char            *u_serv_line;    /* buffer for reading a line from the services file */
  310.     struct servent        u_serv;
  311.     char            **u_serv_aliases;
  312.     int            u_serv_stayopen;
  313.     
  314.     FILE            *u_proto_fp;    /* File pointer to protocol file */
  315.     char            *u_proto_line;
  316.     struct protoent        u_proto;
  317.     char            **u_proto_aliases;
  318.     int            u_proto_stayopen;
  319.     
  320.     int                     u_logname_valid;
  321.     char                    u_logname[MAXLOGNAME + 1];
  322.     char                    u_logname_buf[MAXLOGNAME + 1];
  323.     
  324.     char            u_ntoa_buf[18];    /* used by inet_ntoa */
  325.     
  326.     /* resolv state structure */
  327.     struct __res_state    *u_res;
  328.     int            *u_res_socket;
  329.     
  330.     /* logfile handling */
  331.     int            u_LogFile;    /* fd for log */
  332.     int            u_LogStat;    /* status bits, set by openlog() */
  333.     char            *u_LogTag;    /* string to tag the entry with */
  334.     int            u_LogFacility;    /* default facility code */
  335.     int            u_LogMask;    /* mask of priorities to be logged */
  336.     
  337.     int            u_setuid;    /* used for setuid() - have to remember
  338.                          * to log out */
  339.     /* mmap handling */
  340.     struct mmap_mem        *u_mmap;
  341.  
  342.     struct MsgPort        *u_select_mp;    /* PA_SIGNAL message port */
  343.  
  344.         /* strtod support */
  345.         void                    *u_freelist[16];
  346.         void                    *u_p5s;
  347.         void                    *u_result;
  348.         int                     u_result_k;
  349.         
  350.         /* popen support */
  351.         pid_t                   *u_popen_pids;
  352.  
  353.         /* uid / gid support */
  354.  
  355.     FILE            *u_pwd_fp;    /* File pointer to the passwd file */
  356.     int            u_pwd_stayopen;    /* TRUE if passwd file should stay open */
  357.     char            *u_pwd_line;    /* buffer for reading a line from the passwd file */
  358.  
  359.     char                    u_crypt_buf[21];
  360.  
  361.     uid_t                   u_nextuid;
  362.         uid_t                   u_nextgid;
  363.  
  364.     uid_t                   u_ruid;
  365.         uid_t                   u_euid;
  366.         gid_t                   u_rgid;
  367.         gid_t                   u_egid;
  368.         int                     u_ngroups;
  369.     int                     u_grouplist[NGROUPS_MAX]; /* for init/get/setgroups() */
  370. };
  371.  
  372. /* flag codes */
  373. #define    SLOAD    0x0000001    /* in core */
  374. #define    SSYS    0x0000002    /* swapper or pager process */
  375. #define    SLOCK    0x0000004    /* process being swapped out */
  376. #define    SSWAP    0x0000008    /* save area flag */
  377. #define    STRC    0x0000010    /* process is being traced */
  378. #define    SWTED    0x0000020    /* parent has been told that this process stopped */
  379. #define    SULOCK    0x0000040    /* user settable lock in core */
  380. #define    SNOCLDSTOP    0x0000080    /* tc_Launch has to take a signal next time */
  381. #define    SFREEA4    0x0000100    /* we allocated memory for a4, free it */
  382. #define    SOMASK    0x0000200    /* restore old mask after taking signal */
  383. #define    SWEXIT    0x0000400    /* working on exiting */
  384. #define    SPHYSIO    0x0000800    /* doing physical i/o (bio.c) */
  385. #define    SVFORK    0x0001000    /* process resulted from vfork() */
  386. #define    SVFDONE    0x0002000    /* another vfork flag */
  387. #define    SNOVM    0x0004000    /* no vm, parent in a vfork() */
  388. #define    SPAGI    0x0008000    /* init data space on demand, from inode */
  389. #define    SSEQL    0x0010000    /* user warned of sequential vm behavior */
  390. #define    SUANOM    0x0020000    /* user warned of random vm behavior */
  391. #define    STIMO    0x0040000    /* timing out during sleep */
  392. #define    SORPHAN    0x0080000    /* process is orphaned (can't be ^Z'ed) */
  393. #define    STRACNG    0x0100000    /* process is tracing another process */
  394. #define    SOWEUPC    0x0200000    /* owe process an addupc() call at next ast */
  395. #define    SSEL    0x0400000    /* selecting; wakeup/waiting danger */
  396. #define    SLOGIN    0x0800000    /* a login process (legit child of init) */
  397.  
  398. /* stat codes */
  399. #define    SSLEEP    1        /* awaiting an event */
  400. #define    SWAIT    2        /* (abandoned state) */
  401. #define    SRUN    3        /* running */
  402. #define    SIDL    4        /* intermediate state in process creation */
  403. #define    SZOMB    5        /* has exited, waiting for parent to pick up status */
  404. #define    SSTOP    6        /* stopped */
  405.  
  406. #endif /* _USER_H */
  407.