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