]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/hurd.h
1999-02-27 Roland McGrath <roland@baalperazim.frob.com>
[thirdparty/glibc.git] / hurd / hurd.h
CommitLineData
62495816 1/* Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
c84142e8
UD
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4
RM
18
19#ifndef _HURD_H
20
21#define _HURD_H 1
22#include <features.h>
23
24
25/* Get types, macros, constants and function declarations
26 for all Mach microkernel interaction. */
27#include <mach.h>
28#include <mach/mig_errors.h>
29
30/* Get types and constants necessary for Hurd interfaces. */
31#include <hurd/hurd_types.h>
32
33/* Get MiG stub declarations for commonly used Hurd interfaces. */
34#include <hurd/auth.h>
35#include <hurd/process.h>
36#include <hurd/fs.h>
37#include <hurd/io.h>
38
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>
43
44#include <errno.h>
b122c703
RM
45
46_EXTERN_INLINE int
47__hurd_fail (error_t err)
48{
49 switch (err)
50 {
51 case EMACH_SEND_INVALID_DEST:
52 case EMIG_SERVER_DIED:
53 /* The server has disappeared! */
54 err = EIEIO;
55 break;
56
57 case KERN_NO_SPACE:
58 err = ENOMEM;
59 break;
60 case KERN_INVALID_ARGUMENT:
61 err = EINVAL;
62 break;
63
64 case 0:
65 return 0;
66 default:
67 }
68
69 errno = err;
70 return -1;
71}
28f540f4
RM
72\f
73/* Basic ports and info, initialized by startup. */
74
75extern int _hurd_exec_flags; /* Flags word passed in exec_startup. */
76extern struct hurd_port *_hurd_ports;
77extern unsigned int _hurd_nports;
78extern volatile mode_t _hurd_umask;
8f0c527e 79extern sigset_t _hurdsig_traced;
28f540f4 80
8f5ca04b
RM
81/* Shorthand macro for internal library code referencing _hurd_ports (see
82 <hurd/port.h>). */
28f540f4
RM
83
84#define __USEPORT(which, expr) \
85 HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
86
8f5ca04b
RM
87/* Function version of __USEPORT: calls OPERATE with a send right. */
88
89extern error_t _hurd_ports_use (int which, error_t (*operate) (mach_port_t));
90
28f540f4
RM
91
92/* Base address and size of the initial stack set up by the exec server.
93 If using cthreads, this stack is deallocated in startup.
94 Not locked. */
95
96extern vm_address_t _hurd_stack_base;
97extern vm_size_t _hurd_stack_size;
98
99/* Initial file descriptor table we were passed at startup. If we are
100 using a real dtable, these are turned into that and then cleared at
101 startup. If not, these are never changed after startup. Not locked. */
102
103extern mach_port_t *_hurd_init_dtable;
104extern mach_msg_type_number_t _hurd_init_dtablesize;
105\f
106/* Current process IDs. */
107
108extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
109extern int _hurd_orphaned;
110
111/* This variable is incremented every time the process IDs change. */
6bac11d9 112extern unsigned int _hurd_pids_changed_stamp;
28f540f4
RM
113
114/* This condition is broadcast every time the process IDs change. */
6bac11d9 115extern struct condition _hurd_pids_changed_sync;
28f540f4
RM
116\f
117/* Unix `data break', for brk and sbrk.
118 If brk and sbrk are not used, this info will not be initialized or used. */
119
120
121/* Data break. This is what `sbrk (0)' returns. */
122
123extern vm_address_t _hurd_brk;
124
125/* End of allocated space. This is generally `round_page (_hurd_brk)'. */
126
127extern vm_address_t _hurd_data_end;
128
129/* This mutex locks _hurd_brk and _hurd_data_end. */
130
131extern struct mutex _hurd_brk_lock;
132
133/* Set the data break to NEWBRK; _hurd_brk_lock must
134 be held, and is released on return. */
135
136extern int _hurd_set_brk (vm_address_t newbrk);
137\f
138#define __need_FILE
139#include <stdio.h>
140
141/* Calls to get and set basic ports. */
142
1e9dc039
RM
143extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
144extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
28f540f4
RM
145
146extern process_t getproc (void);
147extern file_t getcwdir (void), getcrdir (void);
148extern auth_t getauth (void);
1d8dc429 149extern mach_port_t getcttyid (void);
28f540f4
RM
150extern int setproc (process_t);
151extern int setcwdir (file_t), setcrdir (file_t);
152extern int setcttyid (mach_port_t);
153
154/* Does reauth with the proc server and fd io servers. */
155extern int __setauth (auth_t), setauth (auth_t);
156
157
2d6d0728
RM
158/* Get and set the effective UID set. */
159extern int geteuids (int __n, uid_t *__uidset);
160extern int seteuids (int __n, const uid_t *__uidset);
161
162
28f540f4
RM
163/* Split FILE into a directory and a name within the directory. The
164 directory lookup uses the current root and working directory. If
165 successful, stores in *NAME a pointer into FILE where the name
166 within directory begins and returns a port to the directory;
167 otherwise sets `errno' and returns MACH_PORT_NULL. */
168
169extern file_t __file_name_split (const char *file, char **name);
170extern file_t file_name_split (const char *file, char **name);
171
172/* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
173 The file lookup uses the current root and working directory.
174 Returns a port to the file if successful; otherwise sets `errno'
175 and returns MACH_PORT_NULL. */
176
177extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
178extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
179
8f5ca04b
RM
180/* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>). The
181 file lookup uses the current root directory, but uses STARTDIR as the
182 "working directory" for file relative names. Returns a port to the file
183 if successful; otherwise sets `errno' and returns MACH_PORT_NULL. */
28f540f4 184
8f5ca04b
RM
185extern file_t __file_name_lookup_under (file_t startdir, const char *file,
186 int flags, mode_t mode);
187extern file_t file_name_lookup_under (file_t startdir, const char *file,
188 int flags, mode_t mode);
28f540f4
RM
189
190
8f0c527e
RM
191/* Lookup FILE_NAME and return the node opened with FLAGS & MODE
192 (see hurd_file_name_lookup for details), but a simple file name (without
193 any directory prefixes) will be consecutively prefixed with the pathnames
194 in the `:' separated list PATH until one succeeds in a successful lookup.
195 If none succeed, then the first error that wasn't ENOENT is returned, or
196 ENOENT if no other errors were returned. If PREFIXED_NAME is non-NULL,
197 then if the result is looked up directly, *PREFIXED_NAME is set to NULL, and
198 if it is looked up using a prefix from PATH, *PREFIXED_NAME is set to
199 malloc'd storage containing the prefixed name. */
200extern file_t file_name_path_lookup (const char *file_name, const char *path,
201 int flags, mode_t mode,
202 char **prefixed_name);
203
204
205
28f540f4
RM
206/* Open a file descriptor on a port. FLAGS are as for `open'; flags
207 affected by io_set_openmodes are not changed by this. If successful,
208 this consumes a user reference for PORT (which will be deallocated on
209 close). */
210
211extern int openport (io_t port, int flags);
212
213/* Open a stream on a port. MODE is as for `fopen'.
214 If successful, this consumes a user reference for PORT
215 (which will be deallocated on fclose). */
216
217extern FILE *fopenport (io_t port, const char *mode);
218extern FILE *__fopenport (io_t port, const char *mode);
219
220
221/* Execute a file, replacing TASK's current program image. */
222
223extern error_t _hurd_exec (task_t task,
224 file_t file,
225 char *const argv[],
226 char *const envp[]);
227
228
6d52618b 229/* Inform the proc server we have exited with STATUS, and kill the
28f540f4
RM
230 task thoroughly. This function never returns, no matter what. */
231
232extern void _hurd_exit (int status) __attribute__ ((noreturn));
233
234
235/* Initialize the library data structures from the
236 ints and ports passed to us by the exec server.
237 Then vm_deallocate PORTARRAY and INTARRAY. */
238
239extern void _hurd_init (int flags, char **argv,
240 mach_port_t *portarray, size_t portarraysize,
241 int *intarray, size_t intarraysize);
242
62495816
RM
243/* Do startup handshaking with the proc server, and initialize library data
244 structures that require proc server interaction. This includes
245 initializing signals; see _hurdsig_init in <hurd/signal.h>. */
28f540f4 246
62495816
RM
247extern void _hurd_proc_init (char **argv,
248 const int *intarray, size_t intarraysize);
28f540f4
RM
249
250
251/* Return the socket server for sockaddr domain DOMAIN. If DEAD is
252 nonzero, remove the old cached port and always do a fresh lookup.
253
254 It is assumed that a socket server will stay alive during a complex socket
255 operation involving several RPCs. But a socket server may die during
256 long idle periods between socket operations. Callers should first pass
257 zero for DEAD; if the first socket RPC tried on the returned port fails
258 with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
259 went away), the caller should call _hurd_socket_server again with DEAD
260 nonzero and retry the RPC on the new socket server port. */
261
262extern socket_t _hurd_socket_server (int domain, int dead);
263
264/* Send a `sig_post' RPC to process number PID. If PID is zero,
265 send the message to all processes in the current process's process group.
266 If PID is < -1, send SIG to all processes in process group - PID.
267 SIG and REFPORT are passed along in the request message. */
268
269extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
270extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
271
272/* Fetch the host privileged port and device master port from the proc
273 server. They are fetched only once and then cached in the
274 variables below. A special program that gets them from somewhere
275 other than the proc server (such as a bootstrap filesystem) can set
276 these variables to install the ports. */
277
278extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
279 device_t *device_master_ptr);
280extern mach_port_t _hurd_host_priv, _hurd_device_master;
281
282/* Return the PID of the task whose control port is TASK.
283 On error, sets `errno' and returns -1. */
284
285extern pid_t __task2pid (task_t task), task2pid (task_t task);
286
287/* Return the task control port of process PID.
288 On error, sets `errno' and returns MACH_PORT_NULL. */
289
290extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
291
ded29119
RM
292/* Return the current thread's thread port. This is a cheap operation (no
293 system call), but it relies on Hurd signal state being set up. */
294extern thread_t hurd_thread_self (void);
295
28f540f4 296
54da5be3
RM
297/* Cancel pending operations on THREAD. If it is doing an interruptible RPC,
298 that RPC will now return EINTR; otherwise, the "cancelled" flag will be
299 set, causing the next `hurd_check_cancel' call to return nonzero or the
300 next interruptible RPC to return EINTR (whichever is called first). */
301extern error_t hurd_thread_cancel (thread_t thread);
302
303/* Test and clear the calling thread's "cancelled" flag. */
304extern int hurd_check_cancel (void);
305
306
28f540f4
RM
307/* Return the io server port for file descriptor FD.
308 This adds a Mach user reference to the returned port.
309 On error, sets `errno' and returns MACH_PORT_NULL. */
310
311extern io_t __getdport (int fd), getdport (int fd);
312
313
0d8733c4
UD
314#include <stdarg.h>
315
316/* Write formatted output to PORT, a Mach port supporting the i/o protocol,
317 according to the format string FORMAT, using the argument list in ARG. */
318int vpprintf (io_t port, const char *format, va_list arg);
319
320
28f540f4 321#endif /* hurd.h */