1 /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
25 /* Get types, macros, constants and function declarations
26 for all Mach microkernel interaction. */
28 #include <mach/mig_errors.h>
30 /* Get types and constants necessary for Hurd interfaces. */
31 #include <hurd/hurd_types.h>
33 /* Get MiG stub declarations for commonly used Hurd interfaces. */
34 #include <hurd/auth.h>
35 #include <hurd/process.h>
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>
45 #define __hurd_fail(err) (errno = (err), -1)
47 /* Basic ports and info, initialized by startup. */
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
;
54 /* Shorthand macro for referencing _hurd_ports (see <hurd/port.h>). */
56 #define __USEPORT(which, expr) \
57 HURD_PORT_USE (&_hurd_ports[INIT_PORT_##which], (expr))
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.
64 extern vm_address_t _hurd_stack_base
;
65 extern vm_size_t _hurd_stack_size
;
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. */
71 extern mach_port_t
*_hurd_init_dtable
;
72 extern mach_msg_type_number_t _hurd_init_dtablesize
;
74 /* Current process IDs. */
76 extern pid_t _hurd_pid
, _hurd_ppid
, _hurd_pgrp
;
77 extern int _hurd_orphaned
;
79 /* This variable is incremented every time the process IDs change. */
81 unsigned int _hurd_pids_changed_stamp
;
83 /* This condition is broadcast every time the process IDs change. */
84 struct condition _hurd_pids_changed_sync
;
86 /* Unix `data break', for brk and sbrk.
87 If brk and sbrk are not used, this info will not be initialized or used. */
90 /* Data break. This is what `sbrk (0)' returns. */
92 extern vm_address_t _hurd_brk
;
94 /* End of allocated space. This is generally `round_page (_hurd_brk)'. */
96 extern vm_address_t _hurd_data_end
;
98 /* This mutex locks _hurd_brk and _hurd_data_end. */
100 extern struct mutex _hurd_brk_lock
;
102 /* Set the data break to NEWBRK; _hurd_brk_lock must
103 be held, and is released on return. */
105 extern int _hurd_set_brk (vm_address_t newbrk
);
110 /* Calls to get and set basic ports. */
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
);
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
);
123 /* Does reauth with the proc server and fd io servers. */
124 extern int __setauth (auth_t
), setauth (auth_t
);
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. */
133 extern error_t
__hurd_file_name_split (file_t crdir
, file_t cwdir
,
135 file_t
*dir
, char **name
);
136 extern error_t
hurd_file_name_split (file_t crdir
, file_t cwdir
,
138 file_t
*dir
, char **name
);
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. */
145 extern error_t
__hurd_file_name_lookup (file_t crdir
, file_t cwdir
,
147 int flags
, mode_t mode
,
149 extern error_t
hurd_file_name_lookup (file_t crdir
, file_t cwdir
,
150 const char *filename
,
151 int flags
, mode_t mode
,
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. */
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
,
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
,
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. */
179 extern file_t
__file_name_split (const char *file
, char **name
);
180 extern file_t
file_name_split (const char *file
, char **name
);
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. */
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
);
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. */
195 extern error_t
__hurd_invoke_translator (file_t file
, int flags
,
197 extern error_t
hurd_invoke_translator (file_t file
, int flags
,
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
206 extern int openport (io_t port
, int flags
);
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). */
212 extern FILE *fopenport (io_t port
, const char *mode
);
213 extern FILE *__fopenport (io_t port
, const char *mode
);
216 /* Execute a file, replacing TASK's current program image. */
218 extern error_t
_hurd_exec (task_t task
,
224 /* Inform the proc server we have exitted with STATUS, and kill the
225 task thoroughly. This function never returns, no matter what. */
227 extern void _hurd_exit (int status
) __attribute__ ((noreturn
));
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. */
234 extern void _hurd_init (int flags
, char **argv
,
235 mach_port_t
*portarray
, size_t portarraysize
,
236 int *intarray
, size_t intarraysize
);
238 /* Do startup handshaking with the proc server. */
240 extern void _hurd_proc_init (char **argv
);
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.
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. */
254 extern socket_t
_hurd_socket_server (int domain
, int dead
);
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. */
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
);
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. */
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
;
274 /* Return the PID of the task whose control port is TASK.
275 On error, sets `errno' and returns -1. */
277 extern pid_t
__task2pid (task_t task
), task2pid (task_t task
);
279 /* Return the task control port of process PID.
280 On error, sets `errno' and returns MACH_PORT_NULL. */
282 extern task_t
__pid2task (pid_t pid
), pid2task (pid_t pid
);
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. */
289 extern io_t
__getdport (int fd
), getdport (int fd
);