]> git.ipfire.org Git - thirdparty/glibc.git/blob - hurd/hurd.h
Sun Jun 4 22:14:11 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[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 #define __hurd_fail(err) (errno = (err), -1)
46 \f
47 /* Basic ports and info, initialized by startup. */
48
49 extern int _hurd_exec_flags; /* Flags word passed in exec_startup. */
50 extern struct hurd_port *_hurd_ports;
51 extern unsigned int _hurd_nports;
52 extern volatile mode_t _hurd_umask;
53
54 /* Shorthand macro for referencing _hurd_ports (see <hurd/port.h>). */
55
56 #define __USEPORT(which, expr) \
57 HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
58
59
60 /* Base address and size of the initial stack set up by the exec server.
61 If using cthreads, this stack is deallocated in startup.
62 Not locked. */
63
64 extern vm_address_t _hurd_stack_base;
65 extern vm_size_t _hurd_stack_size;
66
67 /* Initial file descriptor table we were passed at startup. If we are
68 using a real dtable, these are turned into that and then cleared at
69 startup. If not, these are never changed after startup. Not locked. */
70
71 extern mach_port_t *_hurd_init_dtable;
72 extern mach_msg_type_number_t _hurd_init_dtablesize;
73 \f
74 /* Current process IDs. */
75
76 extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
77 extern int _hurd_orphaned;
78
79 /* This variable is incremented every time the process IDs change. */
80
81 unsigned int _hurd_pids_changed_stamp;
82
83 /* This condition is broadcast every time the process IDs change. */
84 struct condition _hurd_pids_changed_sync;
85 \f
86 /* Unix `data break', for brk and sbrk.
87 If brk and sbrk are not used, this info will not be initialized or used. */
88
89
90 /* Data break. This is what `sbrk (0)' returns. */
91
92 extern vm_address_t _hurd_brk;
93
94 /* End of allocated space. This is generally `round_page (_hurd_brk)'. */
95
96 extern vm_address_t _hurd_data_end;
97
98 /* This mutex locks _hurd_brk and _hurd_data_end. */
99
100 extern struct mutex _hurd_brk_lock;
101
102 /* Set the data break to NEWBRK; _hurd_brk_lock must
103 be held, and is released on return. */
104
105 extern int _hurd_set_brk (vm_address_t newbrk);
106 \f
107 #define __need_FILE
108 #include <stdio.h>
109
110 /* Calls to get and set basic ports. */
111
112 extern error_t _hurd_ports_get (unsigned int which, mach_port_t *result);
113 extern error_t _hurd_ports_set (unsigned int which, mach_port_t newport);
114
115 extern process_t getproc (void);
116 extern file_t getcwdir (void), getcrdir (void);
117 extern auth_t getauth (void);
118 extern mach_port_t getcttyid ();
119 extern int setproc (process_t);
120 extern int setcwdir (file_t), setcrdir (file_t);
121 extern int setcttyid (mach_port_t);
122
123 /* Does reauth with the proc server and fd io servers. */
124 extern int __setauth (auth_t), setauth (auth_t);
125
126
127 /* Split FILE into a directory and a name within the directory. Look up a
128 port for the directory and store it in *DIR; store in *NAME a pointer
129 into FILE where the name within directory begins. The directory lookup
130 uses CRDIR for the root directory and CWDIR for the current directory.
131 Returns zero on success or an error code. */
132
133 extern error_t __hurd_file_name_split (file_t crdir, file_t cwdir,
134 const char *file,
135 file_t *dir, char **name);
136 extern error_t hurd_file_name_split (file_t crdir, file_t cwdir,
137 const char *file,
138 file_t *dir, char **name);
139
140 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
141 The file lookup uses CRDIR for the root directory and CWDIR for the
142 current directory. If successful, returns zero and store the port
143 to FILE in *PORT; otherwise returns an error code. */
144
145 extern error_t __hurd_file_name_lookup (file_t crdir, file_t cwdir,
146 const char *file,
147 int flags, mode_t mode,
148 file_t *port);
149 extern error_t hurd_file_name_lookup (file_t crdir, file_t cwdir,
150 const char *filename,
151 int flags, mode_t mode,
152 file_t *port);
153
154 /* Process the values returned by `dir_lookup' et al, and loop doing
155 `dir_lookup' calls until one returns FS_RETRY_NONE. CRDIR is the
156 root directory used for things like symlinks to absolute file names; the
157 other arguments should be those just passed to and/or returned from
158 `dir_lookup', `fsys_getroot', or `file_invoke_translator'. This
159 function consumes the reference in *RESULT even if it returns an error. */
160
161 extern error_t __hurd_file_name_lookup_retry (file_t crdir,
162 enum retry_type doretry,
163 char retryname[1024],
164 int flags, mode_t mode,
165 file_t *result);
166 extern error_t hurd_file_name_lookup_retry (file_t crdir,
167 enum retry_type doretry,
168 char retryname[1024],
169 int flags, mode_t mode,
170 file_t *result);
171
172
173 /* Split FILE into a directory and a name within the directory. The
174 directory lookup uses the current root and working directory. If
175 successful, stores in *NAME a pointer into FILE where the name
176 within directory begins and returns a port to the directory;
177 otherwise sets `errno' and returns MACH_PORT_NULL. */
178
179 extern file_t __file_name_split (const char *file, char **name);
180 extern file_t file_name_split (const char *file, char **name);
181
182 /* Open a port to FILE with the given FLAGS and MODE (see <fcntl.h>).
183 The file lookup uses the current root and working directory.
184 Returns a port to the file if successful; otherwise sets `errno'
185 and returns MACH_PORT_NULL. */
186
187 extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
188 extern file_t file_name_lookup (const char *file, int flags, mode_t mode);
189
190 /* Invoke any translator set on the node FILE represents, and return in
191 *TRANSLATED a port to the translated node. FLAGS are as for
192 `dir_lookup' et al, but the returned port will not necessarily have
193 any more access rights than FILE does. */
194
195 extern error_t __hurd_invoke_translator (file_t file, int flags,
196 file_t *translated);
197 extern error_t hurd_invoke_translator (file_t file, int flags,
198 file_t *translated);
199
200
201 /* Open a file descriptor on a port. FLAGS are as for `open'; flags
202 affected by io_set_openmodes are not changed by this. If successful,
203 this consumes a user reference for PORT (which will be deallocated on
204 close). */
205
206 extern int openport (io_t port, int flags);
207
208 /* Open a stream on a port. MODE is as for `fopen'.
209 If successful, this consumes a user reference for PORT
210 (which will be deallocated on fclose). */
211
212 extern FILE *fopenport (io_t port, const char *mode);
213 extern FILE *__fopenport (io_t port, const char *mode);
214
215
216 /* Execute a file, replacing TASK's current program image. */
217
218 extern error_t _hurd_exec (task_t task,
219 file_t file,
220 char *const argv[],
221 char *const envp[]);
222
223
224 /* Inform the proc server we have exitted with STATUS, and kill the
225 task thoroughly. This function never returns, no matter what. */
226
227 extern void _hurd_exit (int status) __attribute__ ((noreturn));
228
229
230 /* Initialize the library data structures from the
231 ints and ports passed to us by the exec server.
232 Then vm_deallocate PORTARRAY and INTARRAY. */
233
234 extern void _hurd_init (int flags, char **argv,
235 mach_port_t *portarray, size_t portarraysize,
236 int *intarray, size_t intarraysize);
237
238 /* Do startup handshaking with the proc server. */
239
240 extern void _hurd_proc_init (char **argv);
241
242
243 /* Return the socket server for sockaddr domain DOMAIN. If DEAD is
244 nonzero, remove the old cached port and always do a fresh lookup.
245
246 It is assumed that a socket server will stay alive during a complex socket
247 operation involving several RPCs. But a socket server may die during
248 long idle periods between socket operations. Callers should first pass
249 zero for DEAD; if the first socket RPC tried on the returned port fails
250 with MACH_SEND_INVALID_DEST or MIG_SERVER_DIED (indicating the server
251 went away), the caller should call _hurd_socket_server again with DEAD
252 nonzero and retry the RPC on the new socket server port. */
253
254 extern socket_t _hurd_socket_server (int domain, int dead);
255
256 /* Send a `sig_post' RPC to process number PID. If PID is zero,
257 send the message to all processes in the current process's process group.
258 If PID is < -1, send SIG to all processes in process group - PID.
259 SIG and REFPORT are passed along in the request message. */
260
261 extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
262 extern error_t hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
263
264 /* Fetch the host privileged port and device master port from the proc
265 server. They are fetched only once and then cached in the
266 variables below. A special program that gets them from somewhere
267 other than the proc server (such as a bootstrap filesystem) can set
268 these variables to install the ports. */
269
270 extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
271 device_t *device_master_ptr);
272 extern mach_port_t _hurd_host_priv, _hurd_device_master;
273
274 /* Return the PID of the task whose control port is TASK.
275 On error, sets `errno' and returns -1. */
276
277 extern pid_t __task2pid (task_t task), task2pid (task_t task);
278
279 /* Return the task control port of process PID.
280 On error, sets `errno' and returns MACH_PORT_NULL. */
281
282 extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
283
284 /* Return the current thread's thread port. This is a cheap operation (no
285 system call), but it relies on Hurd signal state being set up. */
286 extern thread_t hurd_thread_self (void);
287
288
289 /* Return the io server port for file descriptor FD.
290 This adds a Mach user reference to the returned port.
291 On error, sets `errno' and returns MACH_PORT_NULL. */
292
293 extern io_t __getdport (int fd), getdport (int fd);
294
295
296 #endif /* hurd.h */