Blame hurd/hurd.h

Packit 6c4009
/* Copyright (C) 1993-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef	_HURD_H
Packit 6c4009
Packit 6c4009
#define	_HURD_H	1
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Get types, macros, constants and function declarations
Packit 6c4009
   for all Mach microkernel interaction.  */
Packit 6c4009
#include <mach.h>
Packit 6c4009
#include <mach/mig_errors.h>
Packit 6c4009
Packit 6c4009
/* Get types and constants necessary for Hurd interfaces.  */
Packit 6c4009
#include <hurd/hurd_types.h>
Packit 6c4009
Packit 6c4009
/* Get MiG stub declarations for commonly used Hurd interfaces.  */
Packit 6c4009
#include <hurd/auth.h>
Packit 6c4009
#include <hurd/process.h>
Packit 6c4009
#include <hurd/fs.h>
Packit 6c4009
#include <hurd/io.h>
Packit 6c4009
Packit 6c4009
/* Get `struct hurd_port' and related definitions implementing lightweight
Packit 6c4009
   user references for ports.  These are used pervasively throughout the C
Packit 6c4009
   library; this is here to avoid putting it in nearly every source file.  */
Packit 6c4009
#include <hurd/port.h>
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <bits/types/error_t.h>
Packit 6c4009
#include <bits/types/sigset_t.h>
Packit 6c4009
Packit 6c4009
#ifndef _HURD_H_EXTERN_INLINE
Packit 6c4009
#define _HURD_H_EXTERN_INLINE __extern_inline
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
extern int __hurd_fail (error_t err);
Packit 6c4009
Packit 6c4009
#ifdef __USE_EXTERN_INLINES
Packit 6c4009
_HURD_H_EXTERN_INLINE int
Packit 6c4009
__hurd_fail (error_t err)
Packit 6c4009
{
Packit 6c4009
  switch (err)
Packit 6c4009
    {
Packit 6c4009
    case EMACH_SEND_INVALID_DEST:
Packit 6c4009
    case EMIG_SERVER_DIED:
Packit 6c4009
      /* The server has disappeared!  */
Packit 6c4009
      err = (error_t) EIEIO;
Packit 6c4009
      break;
Packit 6c4009
Packit 6c4009
    case KERN_NO_SPACE:
Packit 6c4009
      err = (error_t) ENOMEM;
Packit 6c4009
      break;
Packit 6c4009
Packit 6c4009
    case KERN_INVALID_ARGUMENT:
Packit 6c4009
      err = (error_t) EINVAL;
Packit 6c4009
      break;
Packit 6c4009
Packit 6c4009
    case 0:
Packit 6c4009
      return 0;
Packit 6c4009
Packit 6c4009
    default:
Packit 6c4009
      break;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  errno = err;
Packit 6c4009
  return -1;
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009

Packit 6c4009
/* Basic ports and info, initialized by startup.  */
Packit 6c4009
Packit 6c4009
extern int _hurd_exec_flags;	/* Flags word passed in exec_startup.  */
Packit 6c4009
extern struct hurd_port *_hurd_ports;
Packit 6c4009
extern unsigned int _hurd_nports;
Packit 6c4009
extern mode_t _hurd_umask;
Packit 6c4009
extern sigset_t _hurdsig_traced;
Packit 6c4009
Packit 6c4009
/* Shorthand macro for internal library code referencing _hurd_ports (see
Packit 6c4009
   <hurd/port.h>).  */
Packit 6c4009
Packit 6c4009
#define	__USEPORT(which, expr) \
Packit 6c4009
  HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
Packit 6c4009
Packit 6c4009
/* Function version of __USEPORT: calls OPERATE with a send right.  */
Packit 6c4009
Packit 6c4009
extern error_t _hurd_ports_use (int which, error_t (*operate) (mach_port_t));
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Base address and size of the initial stack set up by the exec server.
Packit 6c4009
   If using cthreads, this stack is deallocated in startup.
Packit 6c4009
   Not locked.  */
Packit 6c4009
Packit 6c4009
extern vm_address_t _hurd_stack_base;
Packit 6c4009
extern vm_size_t _hurd_stack_size;
Packit 6c4009
Packit 6c4009
/* Initial file descriptor table we were passed at startup.  If we are
Packit 6c4009
   using a real dtable, these are turned into that and then cleared at
Packit 6c4009
   startup.  If not, these are never changed after startup.  Not locked.  */
Packit 6c4009
Packit 6c4009
extern mach_port_t *_hurd_init_dtable;
Packit 6c4009
extern mach_msg_type_number_t _hurd_init_dtablesize;
Packit 6c4009

Packit 6c4009
/* Current process IDs.  */
Packit 6c4009
Packit 6c4009
extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
Packit 6c4009
extern int _hurd_orphaned;
Packit 6c4009
Packit 6c4009
/* This variable is incremented every time the process IDs change.  */
Packit 6c4009
extern unsigned int _hurd_pids_changed_stamp;
Packit 6c4009
Packit 6c4009
/* This condition is broadcast every time the process IDs change.  */
Packit 6c4009
extern struct condition _hurd_pids_changed_sync;
Packit 6c4009

Packit 6c4009
/* Unix `data break', for brk and sbrk.
Packit 6c4009
   If brk and sbrk are not used, this info will not be initialized or used.  */
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Data break.  This is what `sbrk (0)' returns.  */
Packit 6c4009
Packit 6c4009
extern vm_address_t _hurd_brk;
Packit 6c4009
Packit 6c4009
/* End of allocated space.  This is generally `round_page (_hurd_brk)'.  */
Packit 6c4009
Packit 6c4009
extern vm_address_t _hurd_data_end;
Packit 6c4009
Packit 6c4009
/* This mutex locks _hurd_brk and _hurd_data_end.  */
Packit 6c4009
Packit 6c4009
extern struct mutex _hurd_brk_lock;
Packit 6c4009
Packit 6c4009
/* Set the data break to NEWBRK; _hurd_brk_lock must
Packit 6c4009
   be held, and is released on return.  */
Packit 6c4009
Packit 6c4009
extern int _hurd_set_brk (vm_address_t newbrk);
Packit 6c4009

Packit 6c4009
#include <bits/types/FILE.h>
Packit 6c4009
Packit 6c4009
/* Calls to get and set basic ports.  */
Packit 6c4009
Packit 6c4009
extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
Packit 6c4009
extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
Packit 6c4009
Packit 6c4009
extern process_t getproc (void);
Packit 6c4009
extern file_t getcwdir (void), getcrdir (void);
Packit 6c4009
extern auth_t getauth (void);
Packit 6c4009
extern mach_port_t getcttyid (void);
Packit 6c4009
extern int setproc (process_t);
Packit 6c4009
extern int setcwdir (file_t), setcrdir (file_t);
Packit 6c4009
extern int setcttyid (mach_port_t);
Packit 6c4009
Packit 6c4009
/* Does reauth with the proc server and fd io servers.  */
Packit 6c4009
extern int __setauth (auth_t), setauth (auth_t);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Modify a port cell by looking up a directory name.
Packit 6c4009
   This verifies that it is a directory and that we have search permission.  */
Packit 6c4009
extern int _hurd_change_directory_port_from_name (struct hurd_port *portcell,
Packit 6c4009
						  const char *name);
Packit 6c4009
/* Same thing, but using an open file descriptor.
Packit 6c4009
   Also verifies that it is a directory and that we have search permission.  */
Packit 6c4009
extern int _hurd_change_directory_port_from_fd (struct hurd_port *portcell,
Packit 6c4009
						int fd);
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Get and set the effective UID set.  */
Packit 6c4009
extern int geteuids (int __n, uid_t *__uidset);
Packit 6c4009
extern int seteuids (int __n, const uid_t *__uidset);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Split FILE into a directory and a name within the directory.  The
Packit 6c4009
   directory lookup uses the current root and working directory.  If
Packit 6c4009
   successful, stores in *NAME a pointer into FILE where the name
Packit 6c4009
   within directory begins and returns a port to the directory;
Packit 6c4009
   otherwise sets `errno' and returns MACH_PORT_NULL.  */
Packit 6c4009
Packit 6c4009
extern file_t __file_name_split (const char *file, char **name);
Packit 6c4009
extern file_t file_name_split (const char *file, char **name);
Packit 6c4009
Packit 6c4009
/* Split DIRECTORY into a parent directory and a name within the directory.
Packit 6c4009
   This is the same as file_name_split, but ignores trailing slashes.  */
Packit 6c4009
Packit 6c4009
extern file_t __directory_name_split (const char *file, char **name);
Packit 6c4009
extern file_t directory_name_split (const char *file, char **name);
Packit 6c4009
Packit 6c4009
/* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
Packit 6c4009
   The file lookup uses the current root and working directory.
Packit 6c4009
   Returns a port to the file if successful; otherwise sets `errno'
Packit 6c4009
   and returns MACH_PORT_NULL.  */
Packit 6c4009
Packit 6c4009
extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
Packit 6c4009
extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
Packit 6c4009
Packit 6c4009
/* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).  The
Packit 6c4009
   file lookup uses the current root directory, but uses STARTDIR as the
Packit 6c4009
   "working directory" for file relative names.  Returns a port to the file
Packit 6c4009
   if successful; otherwise sets `errno' and returns MACH_PORT_NULL.  */
Packit 6c4009
Packit 6c4009
extern file_t __file_name_lookup_under (file_t startdir, const char *file,
Packit 6c4009
					int flags, mode_t mode);
Packit 6c4009
extern file_t file_name_lookup_under (file_t startdir, const char *file,
Packit 6c4009
				      int flags, mode_t mode);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Lookup FILE_NAME and return the node opened with FLAGS & MODE
Packit 6c4009
   (see hurd_file_name_lookup for details), but a simple file name (without
Packit 6c4009
   any directory prefixes) will be consecutively prefixed with the pathnames
Packit 6c4009
   in the `:' separated list PATH until one succeeds in a successful lookup.
Packit 6c4009
   If none succeed, then the first error that wasn't ENOENT is returned, or
Packit 6c4009
   ENOENT if no other errors were returned.  If PREFIXED_NAME is non-NULL,
Packit 6c4009
   then if the result is looked up directly, *PREFIXED_NAME is set to NULL, and
Packit 6c4009
   if it is looked up using a prefix from PATH, *PREFIXED_NAME is set to
Packit 6c4009
   malloc'd storage containing the prefixed name.  */
Packit 6c4009
extern file_t file_name_path_lookup (const char *file_name, const char *path,
Packit 6c4009
				     int flags, mode_t mode,
Packit 6c4009
				     char **prefixed_name);
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Open a file descriptor on a port.  FLAGS are as for `open'; flags
Packit 6c4009
   affected by io_set_openmodes are not changed by this.  If successful,
Packit 6c4009
   this consumes a user reference for PORT (which will be deallocated on
Packit 6c4009
   close).  */
Packit 6c4009
Packit 6c4009
extern int openport (io_t port, int flags);
Packit 6c4009
Packit 6c4009
/* Open a stream on a port.  MODE is as for `fopen'.
Packit 6c4009
   If successful, this consumes a user reference for PORT
Packit 6c4009
   (which will be deallocated on fclose).  */
Packit 6c4009
Packit 6c4009
extern FILE *fopenport (io_t port, const char *mode);
Packit 6c4009
extern FILE *__fopenport (io_t port, const char *mode);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Deprecated: use _hurd_exec_paths instead.  */
Packit 6c4009
Packit 6c4009
extern error_t _hurd_exec (task_t task,
Packit 6c4009
			   file_t file,
Packit 6c4009
			   char *const argv[],
Packit 6c4009
			   char *const envp[]) __attribute_deprecated__;
Packit 6c4009
Packit 6c4009
/* Execute a file, replacing TASK's current program image.  */
Packit 6c4009
Packit 6c4009
extern error_t _hurd_exec_paths (task_t task,
Packit 6c4009
				 file_t file,
Packit 6c4009
				 const char *path,
Packit 6c4009
				 const char *abspath,
Packit 6c4009
				 char *const argv[],
Packit 6c4009
				 char *const envp[]);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Inform the proc server we have exited with STATUS, and kill the
Packit 6c4009
   task thoroughly.  This function never returns, no matter what.  */
Packit 6c4009
Packit 6c4009
extern void _hurd_exit (int status) __attribute__ ((noreturn));
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Initialize the library data structures from the
Packit 6c4009
   ints and ports passed to us by the exec server.
Packit 6c4009
   Then vm_deallocate PORTARRAY and INTARRAY.  */
Packit 6c4009
Packit 6c4009
extern void _hurd_init (int flags, char **argv,
Packit 6c4009
			mach_port_t *portarray, size_t portarraysize,
Packit 6c4009
			int *intarray, size_t intarraysize);
Packit 6c4009
Packit 6c4009
/* Do startup handshaking with the proc server, and initialize library data
Packit 6c4009
   structures that require proc server interaction.  This includes
Packit 6c4009
   initializing signals; see _hurdsig_init in <hurd/signal.h>.  */
Packit 6c4009
Packit 6c4009
extern void _hurd_proc_init (char **argv,
Packit 6c4009
			     const int *intarray, size_t intarraysize);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the socket server for sockaddr domain DOMAIN.  If DEAD is
Packit 6c4009
   nonzero, remove the old cached port and always do a fresh lookup.
Packit 6c4009
Packit 6c4009
   It is assumed that a socket server will stay alive during a complex socket
Packit 6c4009
   operation involving several RPCs.  But a socket server may die during
Packit 6c4009
   long idle periods between socket operations.  Callers should first pass
Packit 6c4009
   zero for DEAD; if the first socket RPC tried on the returned port fails
Packit 6c4009
   with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
Packit 6c4009
   went away), the caller should call _hurd_socket_server again with DEAD
Packit 6c4009
   nonzero and retry the RPC on the new socket server port.  */
Packit 6c4009
Packit 6c4009
extern socket_t _hurd_socket_server (int domain, int dead);
Packit 6c4009
Packit 6c4009
/* Send a `sig_post' RPC to process number PID.  If PID is zero,
Packit 6c4009
   send the message to all processes in the current process's process group.
Packit 6c4009
   If PID is < -1, send SIG to all processes in process group - PID.
Packit 6c4009
   SIG and REFPORT are passed along in the request message.  */
Packit 6c4009
Packit 6c4009
extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
Packit 6c4009
extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
Packit 6c4009
Packit 6c4009
/* Fetch the host privileged port and device master port from the proc
Packit 6c4009
   server.  They are fetched only once and then cached in the
Packit 6c4009
   variables below.  A special program that gets them from somewhere
Packit 6c4009
   other than the proc server (such as a bootstrap filesystem) can set
Packit 6c4009
   these variables to install the ports.  */
Packit 6c4009
Packit 6c4009
extern kern_return_t __get_privileged_ports (mach_port_t *host_priv_ptr,
Packit 6c4009
					     device_t *device_master_ptr);
Packit 6c4009
extern kern_return_t get_privileged_ports (mach_port_t *host_priv_ptr,
Packit 6c4009
					   device_t *device_master_ptr);
Packit 6c4009
extern mach_port_t _hurd_host_priv, _hurd_device_master;
Packit 6c4009
Packit 6c4009
/* Return the PID of the task whose control port is TASK.
Packit 6c4009
   On error, sets `errno' and returns -1.  */
Packit 6c4009
Packit 6c4009
extern pid_t __task2pid (task_t task), task2pid (task_t task);
Packit 6c4009
Packit 6c4009
/* Return the task control port of process PID.
Packit 6c4009
   On error, sets `errno' and returns MACH_PORT_NULL.  */
Packit 6c4009
Packit 6c4009
extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
Packit 6c4009
Packit 6c4009
/* Return the current thread's thread port.  This is a cheap operation (no
Packit 6c4009
   system call), but it relies on Hurd signal state being set up.  */
Packit 6c4009
extern thread_t hurd_thread_self (void);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Cancel pending operations on THREAD.  If it is doing an interruptible RPC,
Packit 6c4009
   that RPC will now return EINTR; otherwise, the "cancelled" flag will be
Packit 6c4009
   set, causing the next `hurd_check_cancel' call to return nonzero or the
Packit 6c4009
   next interruptible RPC to return EINTR (whichever is called first).  */
Packit 6c4009
extern error_t hurd_thread_cancel (thread_t thread);
Packit 6c4009
Packit 6c4009
/* Test and clear the calling thread's "cancelled" flag.  */
Packit 6c4009
extern int hurd_check_cancel (void);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the io server port for file descriptor FD.
Packit 6c4009
   This adds a Mach user reference to the returned port.
Packit 6c4009
   On error, sets `errno' and returns MACH_PORT_NULL.  */
Packit 6c4009
Packit 6c4009
extern io_t __getdport (int fd), getdport (int fd);
Packit 6c4009
Packit 6c4009
Packit 6c4009
#include <stdarg.h>
Packit 6c4009
Packit 6c4009
/* Write formatted output to PORT, a Mach port supporting the i/o protocol,
Packit 6c4009
   according to the format string FORMAT, using the argument list in ARG.  */
Packit 6c4009
int vpprintf (io_t port, const char *format, va_list arg);
Packit 6c4009
Packit 6c4009
Packit 6c4009
#endif	/* hurd.h */