1 /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
25 /* Get types, macros, constants and function declarations
26 for all Mach microkernel interaction. */
28 #include <mach/mig_errors.h>
30 /* Get types and constants necessary for Hurd interfaces. */
31 #include <hurd/hurd_types.h>
33 /* Get MiG stub declarations for commonly used Hurd interfaces. */
34 #include <hurd/auth.h>
35 #include <hurd/process.h>
39 /* Get `struct hurd_port' and related definitions implementing lightweight
40 user references for ports. These are used pervasively throughout the C
41 library; this is here to avoid putting it in nearly every source file. */
42 #include <hurd/port.h>
47 __hurd_fail (error_t err)
51 case EMACH_SEND_INVALID_DEST:
52 case EMIG_SERVER_DIED:
53 /* The server has disappeared! */
60 case KERN_INVALID_ARGUMENT:
73 /* Basic ports and info, initialized by startup. */
75 extern int _hurd_exec_flags; /* Flags word passed in exec_startup. */
76 extern struct hurd_port *_hurd_ports;
77 extern unsigned int _hurd_nports;
78 extern volatile mode_t _hurd_umask;
80 /* Shorthand macro for referencing _hurd_ports (see <hurd/port.h>). */
82 #define __USEPORT(which, expr) \
83 HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
86 /* Base address and size of the initial stack set up by the exec server.
87 If using cthreads, this stack is deallocated in startup.
90 extern vm_address_t _hurd_stack_base;
91 extern vm_size_t _hurd_stack_size;
93 /* Initial file descriptor table we were passed at startup. If we are
94 using a real dtable, these are turned into that and then cleared at
95 startup. If not, these are never changed after startup. Not locked. */
97 extern mach_port_t *_hurd_init_dtable;
98 extern mach_msg_type_number_t _hurd_init_dtablesize;
100 /* Current process IDs. */
102 extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
103 extern int _hurd_orphaned;
105 /* This variable is incremented every time the process IDs change. */
107 unsigned int _hurd_pids_changed_stamp;
109 /* This condition is broadcast every time the process IDs change. */
110 struct condition _hurd_pids_changed_sync;
112 /* Unix `data break', for brk and sbrk.
113 If brk and sbrk are not used, this info will not be initialized or used. */
116 /* Data break. This is what `sbrk (0)' returns. */
118 extern vm_address_t _hurd_brk;
120 /* End of allocated space. This is generally `round_page (_hurd_brk)'. */
122 extern vm_address_t _hurd_data_end;
124 /* This mutex locks _hurd_brk and _hurd_data_end. */
126 extern struct mutex _hurd_brk_lock;
128 /* Set the data break to NEWBRK; _hurd_brk_lock must
129 be held, and is released on return. */
131 extern int _hurd_set_brk (vm_address_t newbrk);
136 /* Calls to get and set basic ports. */
138 extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
139 extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
141 extern process_t getproc (void);
142 extern file_t getcwdir (void), getcrdir (void);
143 extern auth_t getauth (void);
144 extern mach_port_t getcttyid ();
145 extern int setproc (process_t);
146 extern int setcwdir (file_t), setcrdir (file_t);
147 extern int setcttyid (mach_port_t);
149 /* Does reauth with the proc server and fd io servers. */
150 extern int __setauth (auth_t), setauth (auth_t);
153 /* Split FILE into a directory and a name within the directory. Look up a
154 port for the directory and store it in *DIR; store in *NAME a pointer
155 into FILE where the name within directory begins. The directory lookup
156 uses CRDIR for the root directory and CWDIR for the current directory.
157 Returns zero on success or an error code. */
159 extern error_t __hurd_file_name_split (file_t crdir, file_t cwdir,
161 file_t *dir, char **name);
162 extern error_t hurd_file_name_split (file_t crdir, file_t cwdir,
164 file_t *dir, char **name);
166 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
167 The file lookup uses CRDIR for the root directory and CWDIR for the
168 current directory. If successful, returns zero and store the port
169 to FILE in *PORT; otherwise returns an error code. */
171 extern error_t __hurd_file_name_lookup (file_t crdir, file_t cwdir,
173 int flags, mode_t mode,
175 extern error_t hurd_file_name_lookup (file_t crdir, file_t cwdir,
176 const char *filename,
177 int flags, mode_t mode,
180 /* Process the values returned by `dir_lookup' et al, and loop doing
181 `dir_lookup' calls until one returns FS_RETRY_NONE. CRDIR is the
182 root directory used for things like symlinks to absolute file names; the
183 other arguments should be those just passed to and/or returned from
184 `dir_lookup', `fsys_getroot', or `file_invoke_translator'. This
185 function consumes the reference in *RESULT even if it returns an error. */
187 extern error_t __hurd_file_name_lookup_retry (file_t crdir,
188 enum retry_type doretry,
189 char retryname[1024],
190 int flags, mode_t mode,
192 extern error_t hurd_file_name_lookup_retry (file_t crdir,
193 enum retry_type doretry,
194 char retryname[1024],
195 int flags, mode_t mode,
199 /* Split FILE into a directory and a name within the directory. The
200 directory lookup uses the current root and working directory. If
201 successful, stores in *NAME a pointer into FILE where the name
202 within directory begins and returns a port to the directory;
203 otherwise sets `errno' and returns MACH_PORT_NULL. */
205 extern file_t __file_name_split (const char *file, char **name);
206 extern file_t file_name_split (const char *file, char **name);
208 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
209 The file lookup uses the current root and working directory.
210 Returns a port to the file if successful; otherwise sets `errno'
211 and returns MACH_PORT_NULL. */
213 extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
214 extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
216 /* Invoke any translator set on the node FILE represents, and return in
217 *TRANSLATED a port to the translated node. FLAGS are as for
218 `dir_lookup' et al, but the returned port will not necessarily have
219 any more access rights than FILE does. */
221 extern error_t __hurd_invoke_translator (file_t file, int flags,
223 extern error_t hurd_invoke_translator (file_t file, int flags,
227 /* Open a file descriptor on a port. FLAGS are as for `open'; flags
228 affected by io_set_openmodes are not changed by this. If successful,
229 this consumes a user reference for PORT (which will be deallocated on
232 extern int openport (io_t port, int flags);
234 /* Open a stream on a port. MODE is as for `fopen'.
235 If successful, this consumes a user reference for PORT
236 (which will be deallocated on fclose). */
238 extern FILE *fopenport (io_t port, const char *mode);
239 extern FILE *__fopenport (io_t port, const char *mode);
242 /* Execute a file, replacing TASK's current program image. */
244 extern error_t _hurd_exec (task_t task,
250 /* Inform the proc server we have exitted with STATUS, and kill the
251 task thoroughly. This function never returns, no matter what. */
253 extern void _hurd_exit (int status) __attribute__ ((noreturn));
256 /* Initialize the library data structures from the
257 ints and ports passed to us by the exec server.
258 Then vm_deallocate PORTARRAY and INTARRAY. */
260 extern void _hurd_init (int flags, char **argv,
261 mach_port_t *portarray, size_t portarraysize,
262 int *intarray, size_t intarraysize);
264 /* Do startup handshaking with the proc server. */
266 extern void _hurd_proc_init (char **argv);
269 /* Return the socket server for sockaddr domain DOMAIN. If DEAD is
270 nonzero, remove the old cached port and always do a fresh lookup.
272 It is assumed that a socket server will stay alive during a complex socket
273 operation involving several RPCs. But a socket server may die during
274 long idle periods between socket operations. Callers should first pass
275 zero for DEAD; if the first socket RPC tried on the returned port fails
276 with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
277 went away), the caller should call _hurd_socket_server again with DEAD
278 nonzero and retry the RPC on the new socket server port. */
280 extern socket_t _hurd_socket_server (int domain, int dead);
282 /* Send a `sig_post' RPC to process number PID. If PID is zero,
283 send the message to all processes in the current process's process group.
284 If PID is < -1, send SIG to all processes in process group - PID.
285 SIG and REFPORT are passed along in the request message. */
287 extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
288 extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
290 /* Fetch the host privileged port and device master port from the proc
291 server. They are fetched only once and then cached in the
292 variables below. A special program that gets them from somewhere
293 other than the proc server (such as a bootstrap filesystem) can set
294 these variables to install the ports. */
296 extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
297 device_t *device_master_ptr);
298 extern mach_port_t _hurd_host_priv, _hurd_device_master;
300 /* Return the PID of the task whose control port is TASK.
301 On error, sets `errno' and returns -1. */
303 extern pid_t __task2pid (task_t task), task2pid (task_t task);
305 /* Return the task control port of process PID.
306 On error, sets `errno' and returns MACH_PORT_NULL. */
308 extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
310 /* Return the current thread's thread port. This is a cheap operation (no
311 system call), but it relies on Hurd signal state being set up. */
312 extern thread_t hurd_thread_self (void);
315 /* Cancel pending operations on THREAD. If it is doing an interruptible RPC,
316 that RPC will now return EINTR; otherwise, the "cancelled" flag will be
317 set, causing the next `hurd_check_cancel' call to return nonzero or the
318 next interruptible RPC to return EINTR (whichever is called first). */
319 extern error_t hurd_thread_cancel (thread_t thread);
321 /* Test and clear the calling thread's "cancelled" flag. */
322 extern int hurd_check_cancel (void);
325 /* Return the io server port for file descriptor FD.
326 This adds a Mach user reference to the returned port.
327 On error, sets `errno' and returns MACH_PORT_NULL. */
329 extern io_t __getdport (int fd), getdport (int fd);