Back to index

glibc  2.9
hurd.h
Go to the documentation of this file.
00001 /* Copyright (C) 1993,94,95,96,97,98,99,2001,2002,2007
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _HURD_H
00021 
00022 #define       _HURD_H       1
00023 #include <features.h>
00024 
00025 
00026 /* Get types, macros, constants and function declarations
00027    for all Mach microkernel interaction.  */
00028 #include <mach.h>
00029 #include <mach/mig_errors.h>
00030 
00031 /* Get types and constants necessary for Hurd interfaces.  */
00032 #include <hurd/hurd_types.h>
00033 
00034 /* Get MiG stub declarations for commonly used Hurd interfaces.  */
00035 #include <hurd/auth.h>
00036 #include <hurd/process.h>
00037 #include <hurd/fs.h>
00038 #include <hurd/io.h>
00039 
00040 /* Get `struct hurd_port' and related definitions implementing lightweight
00041    user references for ports.  These are used pervasively throughout the C
00042    library; this is here to avoid putting it in nearly every source file.  */
00043 #include <hurd/port.h>
00044 
00045 #include <errno.h>
00046 
00047 #ifndef _HURD_H_EXTERN_INLINE
00048 #define _HURD_H_EXTERN_INLINE __extern_inline
00049 #endif
00050 
00051 _HURD_H_EXTERN_INLINE int
00052 __hurd_fail (error_t err)
00053 {
00054   switch (err)
00055     {
00056     case EMACH_SEND_INVALID_DEST:
00057     case EMIG_SERVER_DIED:
00058       /* The server has disappeared!  */
00059       err = EIEIO;
00060       break;
00061 
00062     case KERN_NO_SPACE:
00063       err = ENOMEM;
00064       break;
00065 
00066     case KERN_INVALID_ARGUMENT:
00067       err = EINVAL;
00068       break;
00069 
00070     case 0:
00071       return 0;
00072 
00073     default:
00074       break;
00075     }
00076 
00077   errno = err;
00078   return -1;
00079 }
00080 
00081 /* Basic ports and info, initialized by startup.  */
00082 
00083 extern int _hurd_exec_flags;       /* Flags word passed in exec_startup.  */
00084 extern struct hurd_port *_hurd_ports;
00085 extern unsigned int _hurd_nports;
00086 extern mode_t _hurd_umask;
00087 extern sigset_t _hurdsig_traced;
00088 
00089 /* Shorthand macro for internal library code referencing _hurd_ports (see
00090    <hurd/port.h>).  */
00091 
00092 #define       __USEPORT(which, expr) \
00093   HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
00094 
00095 /* Function version of __USEPORT: calls OPERATE with a send right.  */
00096 
00097 extern error_t _hurd_ports_use (int which, error_t (*operate) (mach_port_t));
00098 
00099 
00100 /* Base address and size of the initial stack set up by the exec server.
00101    If using cthreads, this stack is deallocated in startup.
00102    Not locked.  */
00103 
00104 extern vm_address_t _hurd_stack_base;
00105 extern vm_size_t _hurd_stack_size;
00106 
00107 /* Initial file descriptor table we were passed at startup.  If we are
00108    using a real dtable, these are turned into that and then cleared at
00109    startup.  If not, these are never changed after startup.  Not locked.  */
00110 
00111 extern mach_port_t *_hurd_init_dtable;
00112 extern mach_msg_type_number_t _hurd_init_dtablesize;
00113 
00114 /* Current process IDs.  */
00115 
00116 extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
00117 extern int _hurd_orphaned;
00118 
00119 /* This variable is incremented every time the process IDs change.  */
00120 extern unsigned int _hurd_pids_changed_stamp;
00121 
00122 /* This condition is broadcast every time the process IDs change.  */
00123 extern struct condition _hurd_pids_changed_sync;
00124 
00125 /* Unix `data break', for brk and sbrk.
00126    If brk and sbrk are not used, this info will not be initialized or used.  */
00127 
00128 
00129 /* Data break.  This is what `sbrk (0)' returns.  */
00130 
00131 extern vm_address_t _hurd_brk;
00132 
00133 /* End of allocated space.  This is generally `round_page (_hurd_brk)'.  */
00134 
00135 extern vm_address_t _hurd_data_end;
00136 
00137 /* This mutex locks _hurd_brk and _hurd_data_end.  */
00138 
00139 extern struct mutex _hurd_brk_lock;
00140 
00141 /* Set the data break to NEWBRK; _hurd_brk_lock must
00142    be held, and is released on return.  */
00143 
00144 extern int _hurd_set_brk (vm_address_t newbrk);
00145 
00146 #define __need_FILE
00147 #include <stdio.h>
00148 
00149 /* Calls to get and set basic ports.  */
00150 
00151 extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
00152 extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
00153 
00154 extern process_t getproc (void);
00155 extern file_t getcwdir (void), getcrdir (void);
00156 extern auth_t getauth (void);
00157 extern mach_port_t getcttyid (void);
00158 extern int setproc (process_t);
00159 extern int setcwdir (file_t), setcrdir (file_t);
00160 extern int setcttyid (mach_port_t);
00161 
00162 /* Does reauth with the proc server and fd io servers.  */
00163 extern int __setauth (auth_t), setauth (auth_t);
00164 
00165 
00166 /* Modify a port cell by looking up a directory name.
00167    This verifies that it is a directory and that we have search permission.  */
00168 extern int _hurd_change_directory_port_from_name (struct hurd_port *portcell,
00169                                             const char *name);
00170 /* Same thing, but using an open file descriptor.
00171    Also verifies that it is a directory and that we have search permission.  */
00172 extern int _hurd_change_directory_port_from_fd (struct hurd_port *portcell,
00173                                           int fd);
00174 
00175 
00176 
00177 /* Get and set the effective UID set.  */
00178 extern int geteuids (int __n, uid_t *__uidset);
00179 extern int seteuids (int __n, const uid_t *__uidset);
00180 
00181 
00182 /* Split FILE into a directory and a name within the directory.  The
00183    directory lookup uses the current root and working directory.  If
00184    successful, stores in *NAME a pointer into FILE where the name
00185    within directory begins and returns a port to the directory;
00186    otherwise sets `errno' and returns MACH_PORT_NULL.  */
00187 
00188 extern file_t __file_name_split (const char *file, char **name);
00189 extern file_t file_name_split (const char *file, char **name);
00190 
00191 /* Split DIRECTORY into a parent directory and a name within the directory.
00192    This is the same as file_name_split, but ignores trailing slashes.  */
00193 
00194 extern file_t __directory_name_split (const char *file, char **name);
00195 extern file_t directory_name_split (const char *file, char **name);
00196 
00197 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
00198    The file lookup uses the current root and working directory.
00199    Returns a port to the file if successful; otherwise sets `errno'
00200    and returns MACH_PORT_NULL.  */
00201 
00202 extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
00203 extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
00204 
00205 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).  The
00206    file lookup uses the current root directory, but uses STARTDIR as the
00207    "working directory" for file relative names.  Returns a port to the file
00208    if successful; otherwise sets `errno' and returns MACH_PORT_NULL.  */
00209 
00210 extern file_t __file_name_lookup_under (file_t startdir, const char *file,
00211                                    int flags, mode_t mode);
00212 extern file_t file_name_lookup_under (file_t startdir, const char *file,
00213                                   int flags, mode_t mode);
00214 
00215 
00216 /* Lookup FILE_NAME and return the node opened with FLAGS & MODE
00217    (see hurd_file_name_lookup for details), but a simple file name (without
00218    any directory prefixes) will be consecutively prefixed with the pathnames
00219    in the `:' separated list PATH until one succeeds in a successful lookup.
00220    If none succeed, then the first error that wasn't ENOENT is returned, or
00221    ENOENT if no other errors were returned.  If PREFIXED_NAME is non-NULL,
00222    then if the result is looked up directly, *PREFIXED_NAME is set to NULL, and
00223    if it is looked up using a prefix from PATH, *PREFIXED_NAME is set to
00224    malloc'd storage containing the prefixed name.  */
00225 extern file_t file_name_path_lookup (const char *file_name, const char *path,
00226                                  int flags, mode_t mode,
00227                                  char **prefixed_name);
00228 
00229 
00230 
00231 /* Open a file descriptor on a port.  FLAGS are as for `open'; flags
00232    affected by io_set_openmodes are not changed by this.  If successful,
00233    this consumes a user reference for PORT (which will be deallocated on
00234    close).  */
00235 
00236 extern int openport (io_t port, int flags);
00237 
00238 /* Open a stream on a port.  MODE is as for `fopen'.
00239    If successful, this consumes a user reference for PORT
00240    (which will be deallocated on fclose).  */
00241 
00242 extern FILE *fopenport (io_t port, const char *mode);
00243 extern FILE *__fopenport (io_t port, const char *mode);
00244 
00245 
00246 /* Execute a file, replacing TASK's current program image.  */
00247 
00248 extern error_t _hurd_exec (task_t task,
00249                         file_t file,
00250                         char *const argv[],
00251                         char *const envp[]);
00252 
00253 
00254 /* Inform the proc server we have exited with STATUS, and kill the
00255    task thoroughly.  This function never returns, no matter what.  */
00256 
00257 extern void _hurd_exit (int status) __attribute__ ((noreturn));
00258 
00259 
00260 /* Initialize the library data structures from the
00261    ints and ports passed to us by the exec server.
00262    Then vm_deallocate PORTARRAY and INTARRAY.  */
00263 
00264 extern void _hurd_init (int flags, char **argv,
00265                      mach_port_t *portarray, size_t portarraysize,
00266                      int *intarray, size_t intarraysize);
00267 
00268 /* Do startup handshaking with the proc server, and initialize library data
00269    structures that require proc server interaction.  This includes
00270    initializing signals; see _hurdsig_init in <hurd/signal.h>.  */
00271 
00272 extern void _hurd_proc_init (char **argv,
00273                           const int *intarray, size_t intarraysize);
00274 
00275 
00276 /* Return the socket server for sockaddr domain DOMAIN.  If DEAD is
00277    nonzero, remove the old cached port and always do a fresh lookup.
00278 
00279    It is assumed that a socket server will stay alive during a complex socket
00280    operation involving several RPCs.  But a socket server may die during
00281    long idle periods between socket operations.  Callers should first pass
00282    zero for DEAD; if the first socket RPC tried on the returned port fails
00283    with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
00284    went away), the caller should call _hurd_socket_server again with DEAD
00285    nonzero and retry the RPC on the new socket server port.  */
00286 
00287 extern socket_t _hurd_socket_server (int domain, int dead);
00288 
00289 /* Send a `sig_post' RPC to process number PID.  If PID is zero,
00290    send the message to all processes in the current process's process group.
00291    If PID is < -1, send SIG to all processes in process group - PID.
00292    SIG and REFPORT are passed along in the request message.  */
00293 
00294 extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
00295 extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
00296 
00297 /* Fetch the host privileged port and device master port from the proc
00298    server.  They are fetched only once and then cached in the
00299    variables below.  A special program that gets them from somewhere
00300    other than the proc server (such as a bootstrap filesystem) can set
00301    these variables to install the ports.  */
00302 
00303 extern kern_return_t __get_privileged_ports (mach_port_t *host_priv_ptr,
00304                                         device_t *device_master_ptr);
00305 extern kern_return_t get_privileged_ports (mach_port_t *host_priv_ptr,
00306                                       device_t *device_master_ptr);
00307 extern mach_port_t _hurd_host_priv, _hurd_device_master;
00308 
00309 /* Return the PID of the task whose control port is TASK.
00310    On error, sets `errno' and returns -1.  */
00311 
00312 extern pid_t __task2pid (task_t task), task2pid (task_t task);
00313 
00314 /* Return the task control port of process PID.
00315    On error, sets `errno' and returns MACH_PORT_NULL.  */
00316 
00317 extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
00318 
00319 /* Return the current thread's thread port.  This is a cheap operation (no
00320    system call), but it relies on Hurd signal state being set up.  */
00321 extern thread_t hurd_thread_self (void);
00322 
00323 
00324 /* Cancel pending operations on THREAD.  If it is doing an interruptible RPC,
00325    that RPC will now return EINTR; otherwise, the "cancelled" flag will be
00326    set, causing the next `hurd_check_cancel' call to return nonzero or the
00327    next interruptible RPC to return EINTR (whichever is called first).  */
00328 extern error_t hurd_thread_cancel (thread_t thread);
00329 
00330 /* Test and clear the calling thread's "cancelled" flag.  */
00331 extern int hurd_check_cancel (void);
00332 
00333 
00334 /* Return the io server port for file descriptor FD.
00335    This adds a Mach user reference to the returned port.
00336    On error, sets `errno' and returns MACH_PORT_NULL.  */
00337 
00338 extern io_t __getdport (int fd), getdport (int fd);
00339 
00340 
00341 #include <stdarg.h>
00342 
00343 /* Write formatted output to PORT, a Mach port supporting the i/o protocol,
00344    according to the format string FORMAT, using the argument list in ARG.  */
00345 int vpprintf (io_t port, const char *format, va_list arg);
00346 
00347 
00348 #endif /* hurd.h */