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