]> git.ipfire.org Git - thirdparty/glibc.git/blob - hurd/hurd.h
Sat Oct 14 02:52:36 1995 Ulrich Drepper <drepper@ipd.info.uni-karlsruhe.de>
[thirdparty/glibc.git] / hurd / hurd.h
1 /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
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>
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 }
72 \f
73 /* Basic ports and info, initialized by startup. */
74
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;
79
80 /* Shorthand macro for internal library code referencing _hurd_ports (see
81 <hurd/port.h>). */
82
83 #define __USEPORT(which, expr) \
84 HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
85
86 /* Function version of __USEPORT: calls OPERATE with a send right. */
87
88 extern error_t _hurd_ports_use (int which, error_t (*operate) (mach_port_t));
89
90
91 /* Base address and size of the initial stack set up by the exec server.
92 If using cthreads, this stack is deallocated in startup.
93 Not locked. */
94
95 extern vm_address_t _hurd_stack_base;
96 extern vm_size_t _hurd_stack_size;
97
98 /* Initial file descriptor table we were passed at startup. If we are
99 using a real dtable, these are turned into that and then cleared at
100 startup. If not, these are never changed after startup. Not locked. */
101
102 extern mach_port_t *_hurd_init_dtable;
103 extern mach_msg_type_number_t _hurd_init_dtablesize;
104 \f
105 /* Current process IDs. */
106
107 extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
108 extern int _hurd_orphaned;
109
110 /* This variable is incremented every time the process IDs change. */
111
112 unsigned int _hurd_pids_changed_stamp;
113
114 /* This condition is broadcast every time the process IDs change. */
115 struct condition _hurd_pids_changed_sync;
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
123 extern vm_address_t _hurd_brk;
124
125 /* End of allocated space. This is generally `round_page (_hurd_brk)'. */
126
127 extern vm_address_t _hurd_data_end;
128
129 /* This mutex locks _hurd_brk and _hurd_data_end. */
130
131 extern 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
136 extern 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
143 extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
144 extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
145
146 extern process_t getproc (void);
147 extern file_t getcwdir (void), getcrdir (void);
148 extern auth_t getauth (void);
149 extern mach_port_t getcttyid ();
150 extern int setproc (process_t);
151 extern int setcwdir (file_t), setcrdir (file_t);
152 extern int setcttyid (mach_port_t);
153
154 /* Does reauth with the proc server and fd io servers. */
155 extern int __setauth (auth_t), setauth (auth_t);
156
157
158 /* Split FILE into a directory and a name within the directory. The
159 directory lookup uses the current root and working directory. If
160 successful, stores in *NAME a pointer into FILE where the name
161 within directory begins and returns a port to the directory;
162 otherwise sets `errno' and returns MACH_PORT_NULL. */
163
164 extern file_t __file_name_split (const char *file, char **name);
165 extern file_t file_name_split (const char *file, char **name);
166
167 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
168 The file lookup uses the current root and working directory.
169 Returns a port to the file if successful; otherwise sets `errno'
170 and returns MACH_PORT_NULL. */
171
172 extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
173 extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
174
175 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>). The
176 file lookup uses the current root directory, but uses STARTDIR as the
177 "working directory" for file relative names. Returns a port to the file
178 if successful; otherwise sets `errno' and returns MACH_PORT_NULL. */
179
180 extern file_t __file_name_lookup_under (file_t startdir, const char *file,
181 int flags, mode_t mode);
182 extern file_t file_name_lookup_under (file_t startdir, const char *file,
183 int flags, mode_t mode);
184
185
186 /* Open a file descriptor on a port. FLAGS are as for `open'; flags
187 affected by io_set_openmodes are not changed by this. If successful,
188 this consumes a user reference for PORT (which will be deallocated on
189 close). */
190
191 extern int openport (io_t port, int flags);
192
193 /* Open a stream on a port. MODE is as for `fopen'.
194 If successful, this consumes a user reference for PORT
195 (which will be deallocated on fclose). */
196
197 extern FILE *fopenport (io_t port, const char *mode);
198 extern FILE *__fopenport (io_t port, const char *mode);
199
200
201 /* Execute a file, replacing TASK's current program image. */
202
203 extern error_t _hurd_exec (task_t task,
204 file_t file,
205 char *const argv[],
206 char *const envp[]);
207
208
209 /* Inform the proc server we have exitted with STATUS, and kill the
210 task thoroughly. This function never returns, no matter what. */
211
212 extern void _hurd_exit (int status) __attribute__ ((noreturn));
213
214
215 /* Initialize the library data structures from the
216 ints and ports passed to us by the exec server.
217 Then vm_deallocate PORTARRAY and INTARRAY. */
218
219 extern void _hurd_init (int flags, char **argv,
220 mach_port_t *portarray, size_t portarraysize,
221 int *intarray, size_t intarraysize);
222
223 /* Do startup handshaking with the proc server. */
224
225 extern void _hurd_proc_init (char **argv);
226
227
228 /* Return the socket server for sockaddr domain DOMAIN. If DEAD is
229 nonzero, remove the old cached port and always do a fresh lookup.
230
231 It is assumed that a socket server will stay alive during a complex socket
232 operation involving several RPCs. But a socket server may die during
233 long idle periods between socket operations. Callers should first pass
234 zero for DEAD; if the first socket RPC tried on the returned port fails
235 with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
236 went away), the caller should call _hurd_socket_server again with DEAD
237 nonzero and retry the RPC on the new socket server port. */
238
239 extern socket_t _hurd_socket_server (int domain, int dead);
240
241 /* Send a `sig_post' RPC to process number PID. If PID is zero,
242 send the message to all processes in the current process's process group.
243 If PID is < -1, send SIG to all processes in process group - PID.
244 SIG and REFPORT are passed along in the request message. */
245
246 extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
247 extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
248
249 /* Fetch the host privileged port and device master port from the proc
250 server. They are fetched only once and then cached in the
251 variables below. A special program that gets them from somewhere
252 other than the proc server (such as a bootstrap filesystem) can set
253 these variables to install the ports. */
254
255 extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
256 device_t *device_master_ptr);
257 extern mach_port_t _hurd_host_priv, _hurd_device_master;
258
259 /* Return the PID of the task whose control port is TASK.
260 On error, sets `errno' and returns -1. */
261
262 extern pid_t __task2pid (task_t task), task2pid (task_t task);
263
264 /* Return the task control port of process PID.
265 On error, sets `errno' and returns MACH_PORT_NULL. */
266
267 extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
268
269 /* Return the current thread's thread port. This is a cheap operation (no
270 system call), but it relies on Hurd signal state being set up. */
271 extern thread_t hurd_thread_self (void);
272
273
274 /* Cancel pending operations on THREAD. If it is doing an interruptible RPC,
275 that RPC will now return EINTR; otherwise, the "cancelled" flag will be
276 set, causing the next `hurd_check_cancel' call to return nonzero or the
277 next interruptible RPC to return EINTR (whichever is called first). */
278 extern error_t hurd_thread_cancel (thread_t thread);
279
280 /* Test and clear the calling thread's "cancelled" flag. */
281 extern int hurd_check_cancel (void);
282
283
284 /* Return the io server port for file descriptor FD.
285 This adds a Mach user reference to the returned port.
286 On error, sets `errno' and returns MACH_PORT_NULL. */
287
288 extern io_t __getdport (int fd), getdport (int fd);
289
290
291 #endif /* hurd.h */