]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/hurd.h
Sat Mar 18 14:07:08 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[thirdparty/glibc.git] / hurd / hurd.h
CommitLineData
28f540f4
RM
1/* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
2This file is part of the GNU C Library.
3
4The GNU C Library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public License as
6published by the Free Software Foundation; either version 2 of the
7License, or (at your option) any later version.
8
9The GNU C Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public
15License along with the GNU C Library; see the file COPYING.LIB. If
16not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17Cambridge, 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
49extern int _hurd_exec_flags; /* Flags word passed in exec_startup. */
50extern struct hurd_port *_hurd_ports;
51extern unsigned int _hurd_nports;
52extern 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
64extern vm_address_t _hurd_stack_base;
65extern 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
71extern mach_port_t *_hurd_init_dtable;
72extern mach_msg_type_number_t _hurd_init_dtablesize;
73\f
74/* Current process IDs. */
75
76extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
77extern int _hurd_orphaned;
78
79/* This variable is incremented every time the process IDs change. */
80
81unsigned int _hurd_pids_changed_stamp;
82
83/* This condition is broadcast every time the process IDs change. */
84struct 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
92extern vm_address_t _hurd_brk;
93
94/* End of allocated space. This is generally `round_page (_hurd_brk)'. */
95
96extern vm_address_t _hurd_data_end;
97
98/* This mutex locks _hurd_brk and _hurd_data_end. */
99
100extern 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
105extern 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
112extern error_t _hurd_ports_get (int which, mach_port_t *result);
113extern error_t _hurd_ports_set (int which, mach_port_t newport);
114
115extern process_t getproc (void);
116extern file_t getcwdir (void), getcrdir (void);
117extern auth_t getauth (void);
118extern mach_port_t getcttyid ();
119extern int setproc (process_t);
120extern int setcwdir (file_t), setcrdir (file_t);
121extern int setcttyid (mach_port_t);
122
123/* Does reauth with the proc server and fd io servers. */
124extern 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
133extern error_t __hurd_file_name_split (file_t crdir, file_t cwdir,
134 const char *file,
135 file_t *dir, char **name);
136extern 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
145extern 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);
149extern 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
161extern 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);
166extern 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
179extern file_t __file_name_split (const char *file, char **name);
180extern 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
187extern file_t __file_name_lookup (const char *file, int flags, mode_t mode);
188extern 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
195extern error_t __hurd_invoke_translator (file_t file, int flags,
196 file_t *translated);
197extern 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
206extern 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
212extern FILE *fopenport (io_t port, const char *mode);
213extern FILE *__fopenport (io_t port, const char *mode);
214
215
216/* Execute a file, replacing TASK's current program image. */
217
218extern 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
227extern 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
234extern 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
240extern 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
254extern 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
261extern error_t _hurd_sig_post (pid_t pid, int sig, mach_port_t refport);
262extern 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
270extern kern_return_t get_privileged_ports (host_priv_t *host_priv_ptr,
271 device_t *device_master_ptr);
272extern 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
277extern 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
282extern task_t __pid2task (pid_t pid), pid2task (pid_t pid);
283
284
285/* Return the io server port for file descriptor FD.
286 This adds a Mach user reference to the returned port.
287 On error, sets `errno' and returns MACH_PORT_NULL. */
288
289extern io_t __getdport (int fd), getdport (int fd);
290
291
292#endif /* hurd.h */