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