add directory gnu

This commit is contained in:
gohigh
2024-02-19 00:24:47 -05:00
parent 32616db5a4
commit a40f4cadb0
5086 changed files with 1860970 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
# Copyright (C) 1991, 1992 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB. If
# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
subdir := hurd
interface-header-prefix = hurd/
headers = hurd.h # $(interface-headers)
ifneq (,)
user-interfaces := auth process \
exec core interrupt \
fs io socket term
server-interfaces := misc
endif
routines = __pid2task __task2pid pid2task task2pid \
__setauth setauth hurdports \
chcore fchcore fchroot \
hurdauth hurdid hurdpath hurdpid hurdsig hurdsock \
dtable __getdport getdport openport setdtablesize \
sigportdemux _hurd_start_sigthread \
getuids getumask \
_hurd_dead_recv \
fopenport __fopenport \
$(interface-routines)
aux := hurdsyms
all:
# This rule needs to come before the implicit rules in Machrules.
__%.c: intr_rpc.awk %_rpc.c
gawk -v call=__$* -v rpc=__$*_rpc -f $^ > $@-new
mv $@-new $@
# __%_rpc.c is made with mig by Machrules.
%_rpc.c: __%_rpc.c
sed s/MACH_MSG_OPTION_NONE/MACH_SEND_INTERRUPT/ $< > $@
include ../mach/Machrules
ifdef user-interfaces
include hurdintr
endif
hurdintr: hurdintr.awk $(user-interfaces:%=%.defs)
awk -f $^ varname=intr-calls > $@-new
mv $@-new $@
# Make the INTR user stubs be defined as CALL_rpc.
migdefines := $(migdefines) $(foreach call,$(intr-calls),-D$(call)=$(call)_rpc)
interface-routines := $(filter-out %_rpc,$(interface-routines)) \
$(intr-calls:%=__% %)
dont_distribute = $(interface-routines:%=%.c) $(interface-headers)
distribute := intr_rpc.awk hurdintr.awk
include ../Rules

View File

@@ -0,0 +1,31 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <hurd.h>
#include <stdio.h>
/* Open a stream on PORT. MODE is as for fopen. */
FILE *
__fopenport (mach_port_t port, const char *mode)
{
/* The default io functions in sysd-stdio.c use Hurd io ports as cookies. */
return __fopencookie ((void *) port, mode, __default_io_functions);
}

View File

@@ -0,0 +1,49 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
const struct
{
size_t n;
file_t (*getdport) (int fd);
} _hurd_getdport_fn;
file_t
__getdport (int fd)
{
if (_hurd_init_dtable != NULL)
{
/* getdport is the only use of file descriptors,
so we don't bother allocating a real table. */
if (fd < 0 || fd > _hurd_init_dtablesize ||
_hurd_init_dtable[fd] == MACH_PORT_NULL)
{
errno = EBADF;
return MACH_PORT_NULL;
}
else
{
__mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd],
MACH_PORT_RIGHT_SEND, 1);
return _hurd_init_dtable[fd];
}
}
else
return (*_hurd_getdport_fn.getdport) (fd);
}

View File

@@ -0,0 +1,36 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
task_t
__pid2task (pid_t pid)
{
error_t err;
task_t task;
err = _HURD_PORT_USE (&_hurd_proc,
__proc_pid2task (port, pid, &task));
if (err)
{
errno = err;
return MACH_PORT_NULL;
}
else
return task;
}

View File

@@ -0,0 +1,88 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
/* Things in the library which want to be run when the auth port changes. */
const struct
{
size_t n;
void (*fn[0]) ();
} _hurd_reauth_hook;
/* Set the auth port to NEW, and reauthenticate
everything used by the library. */
int
__setauth (auth_t new)
{
error_t err;
auth_t old;
int d;
mach_port_t ignore;
void (**fn) (void);
/* Give the new send right a user reference.
This is a good way to check that it is valid. */
if (__mach_port_mod_refs (__mach_task_self (), new,
MACH_PORT_RIGHT_SEND, 1))
{
errno = EINVAL;
return -1;
}
/* Install the new port in the _hurd_auth cell. */
__mutex_lock (&_hurd_idlock);
_hurd_port_set (&_hurd_auth, new);
_hurd_id_valid = 0;
__mutex_unlock (&_hurd_idlock);
/* Reauthenticate with the proc server. */
if (!_HURD_PORT_USE (&_hurd_proc,
__proc_reauthenticate (port) ||
__auth_user_authenticate (new, port, &ignore))
&& ignore != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), ignore);
/* Reauthenticate the file descriptor table. */
if (_hurd_init_dtable != NULL)
/* We just have the simple table we got at startup. */
for (d = 0; d < _hurd_init_dtablesize; ++d)
if (_hurd_init_dtable[d] != MACH_PORT_NULL)
{
mach_port_t new;
if (! __io_reauthenticate (_hurd_init_dtable[d]) &&
! _HURD_PORT_USE (&_hurd_auth,
__auth_user_authenticate (_hurd_init_dtable[d],
&new)))
{
__mach_port_deallocate (__mach_task_self (),
_hurd_init_dtable[d]);
_hurd_init_dtable[d] = new;
}
}
/* Run things which want to do reauthorization stuff. */
for (fn = _hurd_reauth_hook.fn; *fn != NULL; ++fn)
(**fn) ();
return 0;
}

View File

@@ -0,0 +1,31 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
pid_t
__task2pid (task_t task)
{
error_t err;
pid_t pid;
err = _HURD_PORT_USE (&_hurd_proc,
__proc_task2pid (proc, task, &pid));
if (err)
return __hurd_fail (err);
return pid;
}

View File

@@ -0,0 +1,30 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
/* Return a receive right to which there are no send rights in use. */
mach_port_t
_hurd_dead_recv (void)
{
static mach_port_t port = MACH_PORT_NULL;
if (port == MACH_PORT_NULL)
__mach_port_allocate (__mach_task_self (),
MACH_PORT_RIGHT_RECEIVE, &port);
return port;
}

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <hurd.h>
/* Change the current core to PATH. */
int
DEFUN(chcore, (path), CONST char *path)
{
error_t err;
file_t old, ccdir;
ccdir = __path_lookup (path, FS_LOOKUP_EXECUTE, 0);
if (ccdir == MACH_PORT_NULL)
return -1;
_hurd_port_set (&_hurd_ccdir, ccdir);
return 0;
}

View File

@@ -0,0 +1,206 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <hurd.h>
#include <gnu-stabs.h>
#include <stdlib.h>
#include <limits.h>
struct _hurd_dtable _hurd_dtable;
struct mutex _hurd_dtable_lock;
int *_hurd_dtable_user_dealloc;
const struct _hurd_dtable_resizes _hurd_dtable_resizes;
/* Initialize the file descriptor table at startup. */
static void
init_dtable (void)
{
register size_t i;
__mutex_init (&_hurd_dtable_lock);
_hurd_dtable_user_dealloc = NULL;
/* The initial size of the descriptor table is that of the passed-in
table, rounded up to a multiple of OPEN_MAX descriptors. */
_hurd_dtable.size
= (_hurd_init_dtablesize + OPEN_MAX - 1) / OPEN_MAX * OPEN_MAX;
_hurd_dtable.d = malloc (_hurd_dtable.size * sizeof (*_hurd_dtable.d));
if (_hurd_dtable.d == NULL)
__libc_fatal ("hurd: Can't allocate file descriptor table\n");
for (i = 0; i < _hurd_init_dtablesize; ++i)
{
struct _hurd_fd *const d = &_hurd_dtable.d[i];
io_statbuf_t stb;
io_t ctty;
_hurd_port_init (&d->port, _hurd_init_dtable[i]);
d->flags = 0;
if (_hurd_ctty_fstype != 0 &&
/* We have a controlling tty. Is this it? */
! __io_stat (d->port.port, &stb) &&
stb.stb_fstype == _hurd_ctty_fstype &&
stb.stb_fsid == _hurd_ctty_fsid &&
stb.stb_fileid == _hurd_ctty_fileid &&
/* This is a descriptor to our controlling tty. */
! __term_become_ctty (d->port.port, _hurd_pid, _hurd_pgrp,
_hurd_sigport, &ctty))
{
/* Operations on CTTY return EBACKGROUND when we are not a
foreground user of the tty. */
d->port.port = ctty;
ctty = _hurd_init_dtable[i];
}
else
/* No ctty magic happening here. */
ctty = MACH_PORT_NULL;
_hurd_port_init (&d->ctty, ctty);
}
/* Initialize the remaining empty slots in the table. */
for (; i < _hurd_dtable.size; ++i)
{
_hurd_port_init (&_hurd_dtable.d[i].port, MACH_PORT_NULL);
_hurd_port_init (&_hurd_dtable.d[i].ctty, MACH_PORT_NULL);
_hurd_dtable.d[i].flags = 0;
}
/* Clear out the initial descriptor table.
Everything must use _hurd_dtable now. */
__vm_deallocate (__mach_task_self (),
_hurd_init_dtable,
_hurd_init_dtablesize * sizeof (_hurd_init_dtable[0]));
_hurd_init_dtable = NULL;
_hurd_init_dtablesize = 0;
}
text_set_element (__libc_subinit, init_dtable);
/* Called by `getdport' to do its work. */
static file_t
get_dtable_port (int fd)
{
file_t dport;
int err = _HURD_DPORT_USE (fd,
__mach_port_mod_refs (__mach_task_self (),
(dport = port),
MACH_PORT_RIGHT_SEND,
1));
if (err)
{
errno = err;
return MACH_PORT_NULL;
}
else
return dport;
}
text_set_element (_hurd_getdport_fn, get_dtable_port);
/* Called on fork to install the dtable in NEWTASK.
The dtable lock is held. */
static error_t
fork_dtable (task_t newtask)
{
error_t err;
int i;
err = 0;
for (i = 0; !err && i < _hurd_dtable.size; ++i)
{
int dealloc, dealloc_ctty;
io_t port = _HURD_PORT_USE (&_hurd_dtable.d[i].port, &dealloc);
io_t ctty = _HURD_PORT_USE (&_hurd_dtable.d[i].ctty, &dealloc_ctty);
if (port != MACH_PORT_NULL)
err = __mach_port_insert_right (newtask, port, port,
MACH_PORT_COPY_SEND);
if (!err && ctty != MACH_PORT_NULL)
err = __mach_port_insert_right (newtask, ctty, ctty,
MACH_PORT_COPY_SEND);
_hurd_port_free (port, &dealloc);
_hurd_port_free (ctty, &dealloc_ctty);
/* XXX for each fd with a cntlmap, reauth and re-map_cntl. */
}
__mutex_unlock (&_hurd_dtable_lock);
return err;
}
text_set_element (_hurd_fork_hook, fork_dtable);
text_set_element (_hurd_fork_locks, _hurd_dtable_lock);
/* Called to reauthenticate the dtable when the auth port changes. */
static void
reauth_dtable (void)
{
int d;
__mutex_lock (&_hurd_dtable_lock);
for (d = 0; d < _hurd_dtable.size; ++d)
{
struct _hurd_fd *const d = &hurd_dtable.d[d];
mach_port_t new, newctty;
/* Take the descriptor cell's lock. */
__spin_lock (&cell->port.lock);
/* Reauthenticate the descriptor's port. */
if (cell->port.port != MACH_PORT_NULL &&
! __io_reauthenticate (cell->port.port) &&
! _HURD_PORT_USE (&_hurd_auth,
__auth_user_authenticate (port,
cell->port.port, &new)))
{
/* Replace the port in the descriptor cell
with the newly reauthenticated port. */
if (cell->ctty.port != MACH_PORT_NULL &&
! __io_reauthenticate (cell->ctty.port) &&
! _HURD_PORT_USE (&_hurd_auth,
__auth_user_authenticate (port,
cell->ctty.port,
&newctty)))
_hurd_port_set (&cell->ctty, newctty);
_hurd_port_locked_set (&cell->port, new);
}
else
/* Lost. Leave this descriptor cell alone. */
__spin_unlock (&cell->port.lock);
}
__mutex_unlock (&_hurd_dtable_lock);
}
text_set_element (_hurd_reauth_hook, reauth_dtable);

View File

@@ -0,0 +1,41 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <hurd.h>
/* Change the current core directory to FD. */
int
DEFUN(fchcore, (fd), int fd)
{
error_t err;
file_t ccdir;
if (err = _HURD_DPORT_USE (fd,
__mach_port_mod_refs (__mach_task_self (),
(ccdir = port),
MACH_PORT_RIGHT_SEND, 1)))
return err;
_hurd_port_set (&_hurd_ccdir, ccdir);
return 0;
}

View File

@@ -0,0 +1,41 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <hurd.h>
/* Change the current directory root to FD. */
int
DEFUN(fchroot, (fd), int fd)
{
error_t err;
file_t crdir;
if (err = _HURD_DPORT_USE (fd,
__mach_port_mod_refs (__mach_task_self (),
(crdir = port),
MACH_PORT_RIGHT_SEND, 1)))
return err;
_hurd_port_set (&_hurd_crdir, crdir);
return 0;
}

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__fopenport, fopenport);

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__getdport, getdport);

View File

@@ -0,0 +1,53 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
/* Return the effective uid set. */
int
getuids (int n, uid_t *uidset)
{
int nuids;
__mutex_lock (&_hurd_idlock);
if (!_hurd_id_valid)
{
error_t err = _HURD_PORT_USE (&_hurd_auth,
__auth_getids (port, &_hurd_id));
if (err)
{
__mutex_unlock (&_hurd_idlock);
return __hurd_fail (err);
}
_hurd_id_valid = 1;
}
nuids = _hurd_id.nuids;
if (uidset != NULL)
{
/* Copy into a temporary array before releasing the lock. */
uid_t uids[nuids];
memcpy (uids, _hurd_id.uids, sizeof (uids));
__mutex_unlock (&_hurd_idlock);
/* Lock is released; now copy into user array, which might fault. */
memcpy (uidset, uids, sizeof (uids));
}
else
__mutex_unlock (&_hurd_idlock);
return nuids;
}

View File

@@ -0,0 +1,25 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
mode_t
getumask (void)
{
return _hurd_umask;
}

View File

@@ -0,0 +1,488 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifndef _HURD_H
#define _HURD_H 1
#define _GNU_SOURCE
#include <features.h>
#include <mach.h>
#include <hurd/hurd_types.h>
#include <hurd/process.h>
#include <hurd/fs.h>
#include <hurd/io.h>
#include <errno.h>
#define __hurd_fail(err) (errno = (err), -1)
/* Lightweight user references for ports. */
/* Structure describing a cell containing a port.
With the lock held, a user extracts PORT, and sets USER_DEALLOC to point
to a word in his local storage. PORT can then safely be used. When
PORT is no longer needed, with the lock held, the user examines
USER_DEALLOC. If it is the same address that user stored there, it
extracts *USER_DEALLOC, clears USER_DEALLOC to NULL, and releases the
lock. If *USER_DEALLOC is set, the user deallocates the port he used. */
struct _hurd_port
{
spin_lock_t lock; /* Locks rest. */
mach_port_t port; /* Port. */
int *user_dealloc; /* If not NULL, points to user's flag word. */
};
/* Evaluate EXPR with the variable `port' bound to the port in PORTCELL. */
#define _HURD_PORT_USE(portcell, expr) \
({ struct _hurd_port *const __p = &(portcell); \
int __dealloc; \
const mach_port_t port = _hurd_port_get (__p, &__dealloc); \
__typeof(expr) __result = (expr); \
_hurd_port_free (__p, &__dealloc); \
__result; })
/* Initialize *PORT to INIT. */
static inline void
_hurd_port_init (struct _hurd_port *port, mach_port_t init)
{
__spin_lock_init (&port->lock);
port->port = init;
port->user_dealloc = NULL;
}
/* Get a reference to *PORT, which is locked.
Pass return value and MYFLAG to _hurd_port_free when done. */
static inline mach_port_t
_hurd_port_locked_get (struct _hurd_port *port, int *myflag)
{
mach_port_t result;
result = port->port;
if (result != MACH_PORT_NULL)
{
port->user_dealloc = myflag;
*myflag = 0;
}
__spin_unlock (&port->lock);
return result;
}
/* Same, but locks PORT first. */
static inline mach_port_t
_hurd_port_get (struct _hurd_port *port, int *myflag)
{
__spin_lock (&port->lock);
return _hurd_port_locked_get (port, myflag);
}
/* Free a reference gotten with
`USED_PORT = _hurd_port_get (PORT, MYFLAG);' */
static inline void
_hurd_port_free (struct _hurd_port *port,
int *myflag, mach_port_t used_port)
{
__spin_lock (&port->lock);
if (port->user_dealloc == myflag)
port->user_dealloc = NULL;
__spin_unlock (&port->lock);
if (*myflag)
__mach_port_deallocate (__mach_task_self (), used_port);
}
/* Set *PORT's port to NEWPORT. PORT is locked. */
static inline void
_hurd_port_locked_set (struct _hurd_port *port, mach_port_t newport)
{
mach_port_t old;
if (port->user_dealloc == NULL)
old = port->port;
else
{
old = MACH_PORT_NULL;
*port->user_dealloc = 1;
}
port->port = newport;
__spin_unlock (&port->lock);
if (old != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), old);
}
/* Same, but locks PORT first. */
static inline void
_hurd_port_set (struct _hurd_port *port, mach_port_t newport)
{
__spin_lock (&port->lock);
return _hurd_port_locked_set (port, newport);
}
/* Basic ports and info, initialized by startup. */
extern struct _hurd_port _hurd_proc, _hurd_auth;
extern struct _hurd_port _hurd_ccdir, _hurd_cwdir, _hurd_crdir;
extern volatile mode_t _hurd_umask;
extern struct mutex _hurd_ctty_lock;
extern int _hurd_ctty_fstype;
extern fsid_t _hurd_ctty_fsid;
extern ino_t _hurd_ctty_fileid;
extern vm_address_t _hurd_stack_low, _hurd_stack_high; /* Not locked. */
extern thread_t _hurd_sigport_thread;
extern mach_port_t _hurd_sigport; /* Locked by _hurd_siglock. */
/* Not locked. If we are using a real dtable,
these are turned into that and then cleared at startup.
If not, these are never changed after startup. */
extern mach_port_t *_hurd_init_dtable;
extern size_t _hurd_init_dtablesize;
/* File descriptor table. */
struct _hurd_fd
{
struct _hurd_port port;
int flags; /* fcntl flags; locked by port.lock. */
/* Normal port to the ctty. Also locked by port.lock.
(The ctty.lock is only ever used when the port.lock is held.) */
struct _hurd_port ctty;
};
struct _hurd_dtable
{
int size; /* Number of elts in `d' array. */
/* Uses of individual descriptors are not locked. It is up to the user
to synchronize descriptor operations on a single descriptor. */
struct _hurd_fd *d;
};
extern struct _hurd_dtable _hurd_dtable;
extern struct mutex _hurd_dtable_lock; /* Locks _hurd_dtable. */
/* If not NULL, pointed-to word is set when _hurd_dtable.d changes.
User who set `user_dealloc' should free the _hurd_dtable.d value
he used if his word is set when he is finished.
If NULL, the old value of _hurd_dtable.d is freed by the setter. */
int *_hurd_dtable_user_dealloc;
static inline struct _hurd_dtable
_hurd_dtable_use (int *dealloc)
{
struct _hurd_dtable dtable;
__mutex_lock (&_hurd_dtable_lock);
_hurd_dtable_user_dealloc = dealloc;
dtable = _hurd_dtable;
__mutex_unlock (&_hurd_dtable_lock);
return dtable;
}
struct _hurd_dtable_resizes
{
size_t n;
void (*free) (void *);
void *terminator;
};
extern const struct _hurd_dtable_resizes _hurd_dtable_resizes;
static inline void
_hurd_dtable_done (struct _hurd_dtable dtable, int *dealloc)
{
__mutex_lock (&_hurd_dtable_lock);
if (_hurd_dtable_user_dealloc == dealloc)
_hurd_dtable_user_dealloc = NULL;
__mutex_unlock (&_hurd_dtable_lock);
if (*dealloc)
/* _hurd_dtable_resizes is a symbol set.
setdtablesize.c gives it one element: free.
If setdtablesize is not linked in, *DEALLOC
will never get set, so we will never get here.
This hair avoids linking in free if we don't need it. */
(*_hurd_dtable_resizes.free) (dtable);
}
/* Allocate a new file descriptor and set it to PORT.
If the table is full, deallocate PORT, set errno, and return -1. */
static inline int
_hurd_dalloc (io_t port, io_t ctty, int flags)
{
int i;
__mutex_lock (&hurd_dtable_lock);
for (i = 0; i < _hurd_dtable.size; ++i)
{
struct _hurd_fd *d = &_hurd_dtable.d[i];
__spin_lock (&d->port.lock);
if (d->port.port == MACH_PORT_NULL)
{
d->port.port = port;
d->port.user_dealloc = NULL;
d->ctty.port = ctty;
d->ctty.user_dealloc = NULL;
d->flags = flags;
__spin_unlock (&d->port.lock);
__mutex_unlock (&hurd_dtable_lock);
return i;
}
__spin_unlock (&d->port.lock);
}
__mutex_unlock (&hurd_dtable_lock);
__mach_port_deallocate (__mach_task_self (), port);
__mach_port_deallocate (__mach_task_self (), ctty);
errno = EMFILE;
return -1;
}
/* Returns the descriptor cell for FD in DTABLE, locked. */
static inline struct _hurd_fd *
_hurd_dtable_fd (int fd, struct _hurd_dtable dtable)
{
if (fd < 0 || fd >= dtable.size)
return NULL;
else
{
struct _hurd_fd *cell = &dtable.d[fd];
__spin_lock (&cell->port.lock);
if (cell->port.port == MACH_PORT_NULL)
{
__spin_unlock (&cell->port.lock);
return NULL;
}
return cell;
}
}
struct _hurd_fd_user
{
struct _hurd_dtable dtable;
struct _hurd_fd *d;
};
/* Returns the descriptor cell for FD, locked. */
static inline struct _hurd_fd_user
_hurd_fd (int fd, int *dealloc)
{
struct _hurd_fd_user d;
d.dtable = _hurd_dtable_use (dealloc);
d.d = _hurd_dtable_fd (fd, dtable);
if (d.d == NULL)
_hurd_dtable_done (d.dtable, dealloc);
return d;
}
static inline void
_hurd_fd_done (struct _hurd_fd_user d, int *dealloc)
{
_hurd_dtable_done (d->dtable, dealloc);n
}
/* Evaluate EXPR with the variable `port' bound to the port to FD,
and `ctty' bound to the ctty port. */
#define _HURD_DPORT_USE(fd, expr) \
({ int __dealloc_dt; \
struct _hurd_fd_user __d = _hurd_fd (fd, &__dealloc_dt); \
if (__cell.d == NULL) \
EBADF; \
else \
{ \
int __dealloc = 0, __dealloc_ctty = 0; \
io_t port = _hurd_port_locked_get (&__d.d->port, &__dealloc); \
io_t ctty = _hurd_port_locked_get (&__d.d->ctty, &__dealloc_ctty); \
__typeof (expr) __result; \
__result = (expr); \
_hurd_port_free (&__d.d->port, port, &__dealloc); \
if (ctty != MACH_PORT_NULL) \
_hurd_port_free (&__d.d->ctty, ctty, &__dealloc_ctty); \
_hurd_fd_done (__d, &__dealloc_dt); \
__result; \
} \
}) \
/* Return the socket server for sockaddr domain DOMAIN. */
extern socket_t _hurd_socket_server (int domain);
/* Return a receive right which will not be sent to. */
extern mach_port_t _hurd_dead_recv (void);
/* Current process IDs. */
extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
extern int _hurd_orphaned;
/* User and group IDs. */
extern mutex_t _hurd_idlock;
extern int _hurd_id_valid; /* Nonzero if _hurd_id is valid. */
extern idblock_t _hurd_id;
extern auth_t _hurd_rid_auth; /* Cache used by access. */
/* Unix `data break', for brk and sbrk.
If brk and sbrk are not used, this info will not be initialized or used. */
extern vm_address_t _hurd_brk; /* Data break. */
extern vm_address_t _hurd_data_end; /* End of allocated space. */
extern struct mutex _hurd_brk_lock; /* Locks brk and data_end. */
extern int _hurd_set_data_limit (const struct rlimit *);
/* Set the data break; the brk lock must
be held, and is released on return. */
extern int _hurd_set_brk (vm_address_t newbrk);
/* Resource limit on core file size. Enforced by hurdsig.c. */
extern int _hurd_core_limit;
#include <signal.h>
/* Per-thread signal state. */
struct _hurd_sigstate
{
thread_t thread;
struct _hurd_sigstate *next; /* Linked-list of thread sigstates. */
struct mutex lock; /* Locks the rest of this structure. */
sigset_t blocked;
sigset_t pending;
struct sigaction actions[NSIG];
struct sigstack sigstack;
int sigcodes[NSIG]; /* Codes for pending signals. */
int suspended; /* If nonzero, sig_post signals `arrived'. */
struct condition arrived;
int vforked; /* Nonzero if this thread is a vfork child. */
struct
{
process_t proc;
file_t ccdir, cwdir, crdir, auth;
mode_t umask;
int ctty_fstype;
fsid_t ctty_fsid;
ino_t ctty_fileid;
struct _hurd_dtable *dtable;
jmp_buf continuation;
} *vfork_saved;
/* Not locked. Used only by this thread,
or by signal thread with this thread suspended. */
mach_port_t intr_port; /* Port an interruptible RPC was sent on. */
int intr_restart; /* If nonzero, restart interrupted RPC. */
};
/* Linked list of states of all threads
whose state has been inquired about. */
extern struct _hurd_sigstate *_hurd_sigstates;
extern struct mutex _hurd_siglock; /* Locks _hurd_sigstates. */
/* Get the sigstate of a given thread, taking its lock. */
extern struct _hurd_sigstate *_hurd_thread_sigstate (thread_t);
/* Thread to receive process-global signals. */
extern thread_t _hurd_sigthread;
/* Called by the machine-dependent exception handler. */
extern void _hurd_exc_post_signal (thread_t, int sig, int code);
/* SS->lock is held on entry, and released before return. */
extern void _hurd_internal_post_signal (reply_port_t,
struct _hurd_sigstate *ss,
int signo, int sigcode,
sigset_t *restore_blocked);
/* Function run by the signal thread to receive from the signal port. */
extern void _hurd_sigport_receive (void);
/* Perform interruptible RPC CALL on PORT.
The args in CALL should be constant or local variable refs.
They may be evaluated many times, and must not change.
PORT must not be deallocated before this RPC is finished. */
#define _HURD_EINTR_RPC(port, call) \
({
error_t __err;
struct _hurd_sigstate *__ss
= _hurd_thread_sigstate (__mach_thread_self ());
__mutex_unlock (&__ss->lock); /* Lock not needed. */
/* If we get a signal and should return EINTR, the signal thread will
clear this. The RPC might return EINTR when some other thread gets
a signal, in which case we want to restart our call. */
__ss->intr_restart = 1;
/* This one needs to be last. A signal can arrive before here,
and if intr_port were set before intr_restart are
initialized, the signal thread would get confused. */
__ss->intr_port = (port);
/* A signal may arrive here, after intr_port is set,
but before the mach_msg system call. The signal handler might do an
interruptible RPC, and clobber intr_port; then it would not be set
properly when we actually did send the RPC, and a later signal
wouldn't interrupt that RPC. So, _hurd_run_sighandler saves
intr_port in the sigcontext, and sigreturn restores them. */
__do_call:
switch (__err = (call))
{
case EINTR: /* RPC went out and was interrupted. */
case MACH_SEND_INTERRUPTED: /* RPC didn't get out. */
if (__ss->intr_restart)
/* Restart the interrupted call. */
goto __do_call;
/* Return EINTR. */
__err = EINTR;
break;
case MACH_RCV_PORT_DIED:
/* Server didn't respond to interrupt_operation,
so the signal thread destroyed the reply port. */
__err = EINTR;
break;
}
__ss->intr_port = MACH_PORT_NULL;
__err;
})
/* Calls to get and set basic ports. */
extern process_t getproc (void);
extern file_t getccdir (void), getcwdir (void), getcrdir (void);
extern auth_t getauth (void);
extern int setproc (process_t);
extern int setccdir (file_t), setcwdir (file_t), setcrdir (file_t);
/* Does reauth with the proc server and fd io servers. */
extern int __setauth (auth_t), setauth (auth_t);
#define setauth __setauth
extern error_t __hurd_path_split (file_t crdir, file_t cwdir,
const char *file,
file_t *dir, const char **name);
#define hurd_path_split __hurd_path_split
extern error_t __hurd_path_lookup (file_t crdir, file_t cwdir,
const char *file,
int flags, mode_t mode,
file_t *file);
#define hurd_path_lookup __hurd_path_lookup
/* Returns a port to the directory, and sets *NAME to the file name. */
extern file_t __path_split (const char *file, const char **name);
#define path_split __path_split
/* Looks up FILE with the given FLAGS and MODE (as for dir_pathtrans). */
extern file_t __path_lookup (const char *file, int flags, mode_t mode);
#define path_lookup __path_lookup
/* Open a file descriptor on a port. */
extern int openport (io_t port);
#endif /* hurd.h */

View File

@@ -0,0 +1,100 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
struct _hurd_port _hurd_auth;
error_t
__add_auth (sigthread_t me,
auth_t addauth)
{
error_t err;
auth_t newauth;
if (err = _HURD_PORT_USE (&_hurd_auth,
__auth_combine (port, addauth, &newauth)))
return err;
/* XXX clobbers errno. Need per-thread errno. */
err = __setauth (newauth);
__mach_port_deallocate (__mach_task_self (), newauth);
if (err)
return errno;
__mach_port_deallocate (__mach_task_self (), addauth);
return POSIX_SUCCESS;
}
error_t
__del_auth (sigthread_t me, task_t task,
uid_t *uids, size_t nuids,
gid_t *gids, size_t ngids)
{
error_t err;
auth_t newauth;
size_t i, j;
if (task != __mach_task_self ())
return EPERM;
__mutex_lock (&_hurd_idlock);
if (!_hurd_id_valid)
{
error_t err = _HURD_PORT_USE (&_hurd_auth,
__auth_getids (port, &_hurd_id));
if (err)
{
__mutex_unlock (&_hurd_idlock);
return err;
}
_hurd_id_valid = 1;
}
while (nuids-- > 0)
{
const uid_t uid = *uids++;
for (i = 0; i < _hurd_id.nuids; ++i)
if (_hurd_id.uidset[i] == uid)
/* Move the last uid into this slot, and decrease the
number of uids so the last slot is no longer used. */
_hurd_id.uidset[i] = _hurd_id.uidset[--_hurd_id.nuids];
}
while (ngids-- > 0)
{
const gid_t gid = *gids++;
for (i = 0; i < _hurd_id.ngroups; ++i)
if (_hurd_id.gidset[i] == gid)
/* Move the last gid into this slot, and decrease the
number of gids so the last slot is no longer used. */
_hurd_id.gidset[i] = _hurd_id.gidset[--_hurd_id.ngroups];
}
err = _HURD_PORT_USE (&_hurd_auth,
__auth_makeauth (port, &_hurd_id, &newauth));
_hurd_id_valid = !err;
__mutex_unlock (&_hurd_idlock);
if (err)
return err;
err = __setauth (newauth); /* XXX clobbers errno */
__mach_port_deallocate (__mach_task_self (), newauth);
if (err)
return errno;
return POSIX_SUCCESS;
}

View File

@@ -0,0 +1,33 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
#include <gnu-stabs.h>
struct mutex _hurd_idlock;
int _hurd_id_valid;
struct idblock _hurd_id;
static void
init_id (void)
{
__mutex_init (&_hurd_idlock);
_hurd_id_valid = 0;
}
text_set_element (__libc_subinit, init_id);

View File

@@ -0,0 +1,25 @@
BEGIN { intr=0; wantcall=0; calls=""; }
$1 == "/*" && $2 == "INTR" && $3 == "*/" { intr=1; }
NF == 1 && $1 == "routine" { wantcall=1; next; }
intr != 0 && wantcall == 0 && NF >= 2 && $1 == "routine" \
{
if (substr($2, length($2)-2, 1) == "(")
calls = calls " " substr($2, 0, length($2)-1);
else calls = calls " " $2;
intr=0;
}
wantcall != 0 && NF >= 1 \
{
if (substr($1, length($1)-2, 1) == "(")
calls = calls " " substr($1, 0, length($1)-1);
else calls = calls " " $1;
intr=0;
}
{ wantcall=0; }
END { print varname " :=" calls; }

View File

@@ -0,0 +1,190 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
#include <string.h>
#include <limits.h>
error_t
__hurd_path_lookup (file_t crdir, file_t cwdir,
const char *path, int flags, mode_t mode,
file_t *result)
{
error_t err;
file_t startdir, result;
enum retry_type doretry;
char retryname[PATH_MAX];
file_t newpt;
int dealloc_dir;
int nloops;
if (*path == '/')
{
startdir = crdir;
while (*path == '/')
++path;
}
else
startdir = cwdir;
dealloc_dir = 0;
nloops = 0;
for (;;)
{
err = __dir_pathtrans (startdir, path, flags, mode,
&doretry, retryname, &result);
if (dealloc_dir)
__mach_port_deallocate (__mach_task_self (), startdir);
if (err)
return err;
switch (doretry)
{
case FS_RETRY_NONE:
return POSIX_SUCCESS;
case FS_RETRY_REAUTH:
__io_reauthenticate (*result);
_HURD_PORT_USE (&_hurd_auth,
__auth_user_authenticate (port, result, &newpt));
__mach_port_deallocate (__mach_task_self (), *result);
*result = newpt;
/* Fall through. */
case FS_RETRY_NORMAL:
if (nloops++ >= MAXSYMLINKS)
return ELOOP;
if (retryname[0] == '/')
{
startdir = crdir;
dealloc_dir = 0;
path = retryname;
do
++path;
while (*path == '/');
}
else
{
startdir = *result;
dealloc_dir = 1;
path = retryname;
}
}
}
}
error_t
__hurd_path_split (file_t crdir, file_t cwdir,
const char *path,
file_t *dir, char **name)
{
const char *lastslash;
/* Skip leading slashes in the pathname. */
if (*path == '/')
{
while (*path == '/')
++path;
--path; /* Leave on one slash. */
}
lastslash = strrchr (path, '/');
if (lastslash != NULL)
{
if (lastslash == path)
{
/* "/foobar" => crdir + "foobar". */
*name = path;
__mach_port_mod_refs (__mach_task_self (), MACH_PORT_RIGHT_SEND,
crdir, 1);
*dir = crdir;
return 0;
}
else
{
/* "/dir1/dir2/.../file". */
char dirname[lastslash - path + 1];
memcpy (dirname, path, lastslash - path);
dirname[lastslath - path] = '\0';
*name = lastslash + 1;
return __hurd_path_lookup (crdir, cwdir, dirname, 0, 0, dir);
}
}
else
{
/* "foobar" => cwdir + "foobar". */
*name = path;
__mach_port_mod_refs (__mach_task_self (), MACH_PORT_RIGHT_SEND,
cwdir, 1);
*dir = cwdir;
return 0;
}
}
file_t
__path_lookup (const char *path, int flags, mode_t mode)
{
error_t err;
file_t result, crdir, cwdir;
int dealloc_crdir, dealloc_cwdir;
crdir = _hurd_port_get (&_hurd_crdir, &dealloc_crdir);
cwdir = _hurd_port_get (&_hurd_cwdir, &dealloc_cwdir);
err = __hurd_path_lookup (crdir, cwdir, path, flags, mode, &result);
_hurd_port_free (crdir, &dealloc_crdir);
_hurd_port_free (cwdir, &dealloc_cwdir);
if (err)
{
errno = err;
return MACH_PORT_NULL;
}
else
return result;
}
file_t
__path_split (const char *path, char **name)
{
error_t err;
file_t dir, crdir, cwdir;
int dealloc_crdir, dealloc_cwdir;
crdir = _hurd_port_get (&_hurd_crdir, &dealloc_crdir);
cwdir = _hurd_port_get (&_hurd_cwdir, &dealloc_cwdir);
err = __hurd_path_split (crdir, cwdir, path, &dir, name);
_hurd_port_free (crdir, &dealloc_crdir);
_hurd_port_free (cwdir, &dealloc_cwdir);
if (err)
{
errno = err;
return MACH_PORT_NULL;
}
else
return dir;
}

View File

@@ -0,0 +1,46 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
int _hurd_orphaned;
static void
init_pids (void)
{
int dealloc;
process_t proc = _hurd_port_get (&_hurd_proc, &dealloc);
__proc_getpids (proc, &_hurd_pid, &_hurd_ppid, &_hurd_orphaned);
__proc_getpgrp (proc, _hurd_pid, &_hurd_pgrp);
_hurd_port_free (proc, &dealloc);
}
text_set_element (__libc_subinit, init_pids);
error_t
__proc_newids (sigthread_t me,
pid_t ppid, pid_t pgrp, int orphaned)
{
_hurd_ppid = ppid;
_hurd_pgrp = pgrp;
_hurd_orphaned = orphaned;
return POSIX_SUCCESS;
}

View File

@@ -0,0 +1,72 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
#define GET(lock, type, what) \
type get##what (void) \
{ \
return _hurd_getport (&_hurd_##what, &_hurd_##lock); \
}
static inline mach_port_t
get (struct _hurd_port *cell)
{
mach_port_t result;
error_t err = _HURD_PORT_USE (cell,
__mach_port_mod_refs (__mach_task_self (),
(result = port),
MACH_PORT_RIGHT_SEND,
1));
if (err)
{
errno = err;
return MACH_PORT_NULL;
}
else
return result;
}
#define GET(type, what) \
type get##what (void) { return get (&what); }
static inline int
set (struct _hurd_port *cell, mach_port_t new)
{
error_t err;
if (err = __mach_port_mod_refs (__mach_task_self (), new,
MACH_PORT_RIGHT_SEND, 1))
{
errno = EINVAL;
return -1;
}
_hurd_port_set (cell, new);
return 0;
}
#define SET(type, what) \
int set##what (type new) { return set (&what, new); }
#define GETSET(type, what) \
GET (type, what) SET (type, what)
GETSET (process_t, proc)
GETSET (file_t, ccdir)
GETSET (file_t, cwdir)
GETSET (file_t, crdir)
/* setauth is nontrivial; see __setauth.c. */
GET (auth_t, auth)

View File

@@ -0,0 +1,486 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
#include <gnu-stabs.h>
struct mutex _hurd_siglock;
int _hurd_stopped;
/* Port that receives signals and other miscellaneous messages. */
mach_port_t _hurd_sigport;
/* Thread which receives task-global signals. */
thread_t _hurd_sigthread;
/* Linked-list of per-thread signal state. */
struct _hurd_sigstate *_hurd_sigstates;
struct _hurd_sigstate *
_hurd_thread_sigstate (thread_t thread)
{
struct _hurd_sigstate *ss;
__mutex_lock (&_hurd_siglock);
for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
if (ss->thread == thread)
break;
if (ss == NULL)
{
ss = calloc (1, sizeof (*ss)); /* Zero-initialized. */
if (ss == NULL)
__libc_fatal ("hurd: Can't allocate thread sigstate\n");
ss->thread = thread;
__mutex_init (&ss->lock);
ss->next = _hurd_sigstates;
_hurd_sigstates = ss;
}
__mutex_lock (&ss->lock);
__mutex_unlock (&_hurd_siglock);
return ss;
}
#include <hurd/core.h>
/* Limit on size of core files. */
int _hurd_core_limit;
/* Call the core server to mummify us before we die.
Returns nonzero if a core file was written. */
static inline int
write_corefile (int signo, int sigcode)
{
error_t err;
mach_port_t coreserver;
int dealloc_crdir, dealloc_ccdir;
file_t crdir, ccdir;
if (_hurd_core_limit == 0)
/* User doesn't want a core. */
return 0;
coreserver = __path_lookup (_SERVERS_CORE, 0, 0);
if (coreserver == MACH_PORT_NULL)
return 0;
ccdir = _hurd_port_get (&_hurd_ccdir, &dealloc_ccdir);
crdir = _hurd_port_get (&_hurd_crdir, &dealloc_crdir);
err = __hurd_path_lookup (crdir, ccdir, "core"
FS_LOOKUP_WRITE|FS_LOOKUP_CREATE,
0666 & ~_hurd_umask,
&file);
_hurd_port_free (crdir, &dealloc_crdir);
if (!err)
{
err = __core_dump_task (coreserver,
__mach_task_self (),
file,
signo, sigcode,
getenv ("GNUTARGET"));
__mach_port_deallocate (__mach_task_self (), coreserver);
if (!err && _hurd_core_limit != RLIM_INFINITY)
{
io_statbuf_t stb;
err = __io_stat (file, &stb);
if (!err && stb.stb_size > _hurd_core_limit)
err = EFBIG;
}
__mach_port_deallocate (__mach_task_self (), file);
if (err)
(void) __dir_unlink (ccdir, "core");
}
_hurd_port_free (ccdir, &dealloc_ccdir);
return !err;
}
extern const size_t _hurd_thread_state_count;
/* How long to give servers to respond to
interrupt_operation before giving up on them. */
mach_msg_timeout_t _hurd_interrupt_timeout = 1000; /* One second. */
/* SS->thread is suspended. Fills STATE in with its registers.
SS->lock is held and kept. */
static inline void
abort_rpcs (struct _hurd_sigstate *ss, int signo, void *state)
{
if (ss->intr_port != MACH_PORT_NULL)
{
/* This is the address the PC will be at if the thread
is waiting for a mach_msg syscall to return. */
extern const int __mach_msg_trap_syscall_pc;
extern error_t _hurd_thread_state (thread_t, void *state);
extern int *_hurd_thread_pc (void *state);
/* Abort whatever the thread is doing.
If it is in the mach_msg syscall doing the send,
the syscall will return MACH_SEND_INTERRUPTED. */
__thread_abort (ss->thread);
_hurd_thread_state (ss->thread, state);
if (_hurd_thread_pc (state) == &__mach_msg_trap_syscall_pc)
{
/* The thread was waiting for the RPC to return.
Abort the operation. The RPC will return EINTR. */
struct
{
mach_msg_header_t header;
mach_msg_type_t type;
kern_return_t retcode;
} msg;
kern_return_t err;
msg.header.msgh_request_port = ss->intr_port;
msg.header.msgh_reply_port = __mach_reply_port ();
msg.header.msgh_seqno = 0;
msg.header.msgh_id = 33000; /* interrupt_operation XXX */
err = __mach_msg (&msg.header,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_RCV_TIMEOUT,
sizeof (msg.header), sizeof (msg),
msg.header.msgh_reply_port,
_hurd_interrupt_timeout,
MACH_PORT_NULL);
if (err != MACH_MSG_SUCCESS)
/* The interrupt didn't work.
Destroy the receive right the thread is blocked on. */
__mach_port_destroy (__mach_task_self (),
/* XXX */
_hurd_thread_reply_port (ss->thread));
else
/* In case the server returned something screwy. */
__mach_msg_destroy (&msg.header);
/* Tell the thread whether it should restart the
operation or return EINTR when it wakes up. */
ss->intr_restart = ss->actions[signo].sa_flags & SA_RESTART;
}
/* If the thread is anywhere before the system call trap,
it will start the operation after the signal is handled.
If the thread is after the system call trap, but before it has
cleared SS->intr_port, the operation is already finished. */
}
}
/* Abort the RPCs being run by all threads but this one;
all other threads should be suspended. */
static inline void
abort_all_rpcs (int signo, void *state)
{
thread_t me = __mach_thread_self ();
thread_t *threads;
size_t nthreads, i;
__task_threads (__mach_task_self (), &threads, &nthreads);
for (i = 0; i < nthreads; ++i)
{
if (threads[i] != me)
{
struct _hurd_sigstate *ss = _hurd_thread_sigstate (*nthreads);
abort_rpcs (ss, signo, state);
__mutex_unlock (&ss->lock);
}
__mach_port_deallocate (__mach_task_self (), threads[i]);
}
}
/* Deliver a signal.
SS->lock is held on entry and released before return. */
error_t
_hurd_internal_post_signal (reply_port_t reply,
struct _hurd_sigstate *ss,
int signo,
int sigcode,
sigset_t *restore_blocked)
{
char thread_state[_hurd_thread_state_count];
enum { stop, ignore, core, term } act;
if (ss->actions[signo].sa_handler == SIG_DFL)
switch (signo)
{
case 0:
/* A sig_post msg with SIGNO==0 is sent to
tell us to check for pending signals. */
act = ignore;
break;
case SIGTTIN:
case SIGTTOU:
case SIGSTOP:
case SIGTSTP:
ss->pending &= ~sigmask (SIGCONT);
act = stop;
break;
case SIGCONT:
ss->pending &= ~(sigmask (SIGSTOP) | sigmask (SIGTSTP) |
sigmask (SIGTTIN) | sigmask (SIGTTOU));
/* Fall through. */
case SIGIO:
case SIGURG:
case SIGCHLD:
case SIGWINCH:
act = ignore;
break;
case SIGQUIT:
case SIGILL:
case SIGTRAP:
case SIGIOT:
case SIGEMT:
case SIGFPE:
case SIGBUS:
case SIGSEGV:
case SIGSYS:
act = core;
break;
default:
act = term;
break;
}
else if (ss->actions[signo].sa_handler == SIG_IGN)
act = ignore;
else
act = handle;
if (_hurd_orphaned && (signo == SIGTTIN || signo == SIGTTOU) && act == stop)
{
sigcode = signo;
signo = SIGKILL;
act = term;
}
/* Handle receipt of a blocked signal. */
if ((__sigismember (signo, &ss->blocked) && act != ignore) ||
(signo != SIGKILL && _hurd_stopped))
{
__sigaddmember (signo, &ss->pending);
/* Save the code to be given to the handler when SIGNO is unblocked. */
ss->sigcodes[signo] = sigcode;
act = ignore;
}
if (restore_blocked != NULL)
ss->blocked = *restore_blocked;
switch (act)
{
case stop:
if (reply != MACH_PORT_NULL)
__sig_post_reply (reply, POSIX_SUCCESS);
_HURD_PORT_USE
(&_hurd_proc,
({
/* Hold the siglock while stopping other threads to be
sure it is not held by another thread afterwards. */
__mutex_unlock (&ss->lock);
__mutex_lock (&_hurd_siglock);
__proc_dostop (port, __mach_thread_self ());
__mutex_unlock (&_hurd_siglock);
abort_all_rpcs (signo, thread_state);
__proc_markstop (port, signo);
}));
_hurd_stopped = 1;
__mutex_lock (&ss->lock);
if (ss->suspended)
/* There is a sigsuspend waiting. Tell it to wake up. */
__condition_signal (&ss->arrived);
else
__mutex_unlock (&ss->lock);
return MIG_NO_REPLY; /* Already replied. */
case ignore:
if (reply != MACH_PORT_NULL)
__sig_post_reply (reply, POSIX_SUCCESS);
break;
case core:
case term:
if (reply != MACH_PORT_NULL)
__sig_post_reply (reply, POSIX_SUCCESS);
_HURD_PORT_USE
(&_hurd_proc,
({
__proc_dostop (port, __mach_thread_self ());
abort_all_rpcs (signo, thread_state);
__proc_exit (port,
(W_EXITCODE (0, signo) |
(act == core && write_corefile (signo, sigcode) ?
WCOREDUMP : 0)))
}));
__task_terminate (__mach_task_self ());
return MIG_NO_REPLY; /* Yeah, right. */
case handle:
if (reply != MACH_PORT_NULL)
__sig_post_reply (reply, POSIX_SUCCESS);
__thread_suspend (ss->thread);
abort_rpcs (ss, signo, thread_state);
{
const sigset_t blocked = ss->blocked;
ss->blocked |= __sigmask (signo) | ss->actions[signo].sa_mask;
_hurd_run_sighandler (ss->thread, signo, sigcode,
ss->actions[signo].sa_handler,
ss->actions[signo].sa_flags,
blocked,
&ss->sigstack,
thread_state);
}
__thread_resume (ss->thread);
}
/* We get here only if we are handling or ignoring the signal;
otherwise we are stopped or dead by now. We still hold SS->lock.
Check for pending signals, and loop to post them. */
for (signo = 1; signo < NSIG; ++signo)
if (__sigismember (signo, &ss->pending))
{
__sigdelmember (signo, &ss->pending);
return _hurd_internal_post_signal (MACH_PORT_NULL, ss,
signo, ss->sigcodes[signo],
NULL);
}
if (ss->suspended)
/* There is a sigsuspend waiting. Tell it to wake up. */
__condition_signal (&ss->arrived);
else
__mutex_unlock (&ss->lock);
return MIG_NO_REPLY;
}
/* Called by the proc server to send a signal. */
error_t
__sig_post (sigthread_t me,
mig_reply_port_t reply,
int signo,
mach_port_t refport)
{
struct _hurd_sigstate *ss;
if (signo < 0 || signo >= NSIG)
return EINVAL;
if (refport == __mach_task_self ())
/* Can send any signal. */
goto win;
else if (refport == _hurd_cttyport)
switch (signo)
{
case SIGINT:
case SIGQUIT:
case SIGTSTP:
case SIGHUP:
goto win;
}
else
{
static mach_port_t sessport = MACH_PORT_NULL;
if (sessport == MACH_PORT_NULL)
_HURD_PORT_USE (&_hurd_proc,
__proc_getsidport (port, &sessport));
if (sessport != MACH_PORT_NULL &&
refport == sessport && signo == SIGCONT)
goto win;
}
/* XXX async io? */
return EPERM;
win:
ss = _hurd_thread_sigstate (_hurd_sigthread);
return _hurd_internal_post_signal (reply, ss, signo, 0, NULL);
}
/* Called by the exception handler to take a signal. */
void
_hurd_exc_post_signal (thread_t thread, int signo, int sigcode)
{
(void) _hurd_internal_post_signal (MACH_PORT_NULL,
_hurd_thread_sigstate (thread),
signo, sigcode, NULL);
}
void
_hurdsig_init (void)
{
thread_t sigthread;
__mutex_init (&_hurd_siglock);
if (_hurd_sigport == MACH_PORT_NULL)
if (err = __mach_port_allocate (__mach_task_self (),
MACH_PORT_RIGHT_RECEIVE,
&_hurd_sigport))
__libc_fatal ("hurd: Can't create signal port receive right\n");
if (err = __thread_create (__mach_task_self (), &sigthread))
__libc_fatal ("hurd: Can't create signal thread\n");
if (err = _hurd_start_sigthread (sigthread, _hurd_sigport_receive))
__libc_fatal ("hurd: Can't start signal thread\n");
_hurd_sigport_thread = sigthread;
/* Make a send right to the signal port. */
if (err = __mach_port_insert_right (__mach_task_self (),
_hurd_sigport,
MACH_PORT_RIGHT_MAKE_SEND))
__libc_fatal ("hurd: Can't create send right to signal port\n");
/* Receive exceptions on the signal port. */
__task_set_special_port (__mach_task_self (),
TASK_EXCEPTION,
_hurd_sigport);
}
/* Make PROCSERVER be our proc server port.
Tell the proc server that we exist. */
void
_hurd_proc_init (process_t procserver, char **argv)
{
mach_port_t oldsig, oldtask;
_hurd_port_init (&_hurd_proc, procserver);
/* Tell the proc server where our args and environment are. */
__proc_setprocargs (procserver, argv, __environ);
/* Initialize the signal code; Mach exceptions will become signals.
This sets _hurd_sigport; it must be run before _hurd_proc_init. */
_hurdsig_init ();
/* Give the proc server our task and signal ports. */
__proc_setports (procserver,
_hurd_sigport, __mach_task_self (),
&oldsig, &oldtask);
if (oldsig != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), oldsig);
if (oldtask != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), oldtask);
}

View File

@@ -0,0 +1,90 @@
/* _hurd_socket_server - Find the server for a socket domain.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
#include <sys/socket.h>
#include <gnu-stabs.h>
static struct mutex lock;
static void
init_sock (void)
{
__mutex_init (&lock);
}
text_set_element (__libc_subinit, init_sock);
static file_t sockdir = MACH_PORT_NULL;
static file_t *servers;
static int max_domain;
/* Return a port to the socket server for DOMAIN.
Socket servers translate nodes in the directory _SERVERS_SOCKET
(canonically /servers/socket). These naming point nodes are named
by the simplest decimal representation of the socket domain number,
for example "/servers/socket/3".
Socket servers are assumed not to change very often.
The library keeps all the server socket ports it has ever looked up,
and does not look them up in /servers/socket more than once. */
socket_t
_hurd_socket_server (int domain)
{
error_t err;
__mutex_lock (&lock);
if (sockdir == MACH_PORT_NULL)
{
sockdir = __path_lookup (_SERVERS_SOCKET, FS_LOOKUP_EXEC, 0);
if (sockdir == MACH_PORT_NULL)
{
__mutex_unlock (&lock);
return MACH_PORT_NULL;
}
}
if (domain > max_domain)
{
file_t *new = realloc (servers, (domain + 1) * sizeof (file_t));
if (new == NULL)
{
__mutex_unlock (&lock);
return MACH_PORT_NULL;
}
while (max_domain < domain)
new[max_domain++] = MACH_PORT_NULL;
servers = new;
}
{
char name[100];
sprintf (name, "%d", domain);
if (err = _HURD_PORT_USE (&_hurd_crdir,
__hurd_path_lookup (port, sockdir,
name, 0, 0,
&servers[domain])))
errno = err;
}
__mutex_unlock (&lock);
return servers[domain];
}

View File

@@ -0,0 +1,24 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__hurd_path_lookup, hurd_path_lookup);
symbol_alias (__path_lookup, path_lookup);
symbol_alias (__hurd_path_split, hurd_path_split);
symbol_alias (__path_split, path_split);

View File

@@ -0,0 +1,28 @@
# Icky intimate knowledge of MiG output.
BEGIN { args=""; argsnext=0; echo=1; print "#include <hurd.h>"; }
$NF == rpc \
{
for (i = 1; i < NF; ++i) printf "%s ", $i;
print call;
next;
}
args == "" && $1 == "#else" { argsnext=1; print $0; next; }
argsnext == 1 { args=$0; firstarg=substr($1, 2, length($1)-2); }
{ argsnext=0; }
/^{/ { echo=0; }
echo == 1 { print $0; }
/^}/ \
{
print "{";
print " return _HURD_EINTR_RPC (" firstarg ", " rpc args ");";
print "}";
echo = 1;
}

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
/* Open a file descriptor on a port. */
int
openport (io_t port)
{
int fd;
/* Give the port a new user reference.
This is a good way to check that it is valid. */
if (__mach_port_mod_refs (__mach_task_self (), port,
MACH_PORT_RIGHT_SEND, 1))
{
errno = EINVAL;
return -1;
}
fd = _hurd_dalloc (port, 0);
if (fd < 0)
/* The descriptor table is full. */
__mach_port_deallocate (__mach_task_self (), port);
return fd;
}

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__pid2task, pid2task);

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__setauth, setauth);

View File

@@ -0,0 +1,86 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
/* Change the size of the descriptor table.
You cannot shrink the table if any of the descriptors
which would be removed are being used. */
int
setdtablesize (size_t size)
{
int i;
struct _hurd_fd *table;
__mutex_lock (&_hurd_dtable_lock);
/* Check that no descriptors which are in use are going to disappear. */
for (i = size; i < _hurd_dtable.size; ++i)
{
struct _hurd_fd *const d = &_hurd_dtable.d[i];
__spin_lock (&d->port.lock);
if (d->port.port != MACH_PORT_NULL)
{
__spin_unlock (&d->port.lock);
__mutex_unlock (&_hurd_dtable_lock);
errno = EBUSY;
return -1;
}
}
/* Resize the table. */
if (_hurd_dtable_user_dealloc == NULL)
/* Noone is using the table. We can relocate it. */
table = realloc (_hurd_dtable.d, size * sizeof (*table));
else
/* Someone else is using the table.
We must make a new copy, and let them free the old one. */
table = malloc (size * sizeof (*table));
if (table == NULL)
{
__mutex_unlock (&_hurd_dtable_lock);
return -1;
}
if (_hurd_dtable_user_dealloc != NULL)
{
*_hurd_dtable_user_dealloc = 1;
_hurd_dtable_user_dealloc = NULL;
memcpy (table, _hurd_dtable.d, _hurd_dtable.size * sizeof (table[0]));
}
/* If the table grew, initialize the new slots. */
for (i = _hurd_dtable.size; i < size; ++i)
{
table[i].flags = 0;
_hurd_port_init (&table[i].port, MACH_PORT_NULL);
_hurd_port_init (&table[i].ctty, MACH_PORT_NULL);
}
_hurd_dtable.size = size;
_hurd_dtable.d = table;
__mutex_unlock (&_hurd_dtable_lock);
return 0;
}

View File

@@ -0,0 +1,64 @@
/* Demux messages sent on the signal port.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd.h>
const struct
{
size_t n;
mach_msg_id_t id[0];
} _hurd_sigport_ids;
const struct
{
size_t n;
void (*routine[0]) (mach_msg_header_t *inp, mach_msg_header_t *outp);
} _hurd_sigport_routines;
static boolean_t
_hurd_sigport_demux (mach_msg_header_t *inp,
mach_msg_header_t *outp)
{
size_t i;
if (_hurd_sigport_ids.n != _hurd_sigport_routines.n)
__libc_fatal ("LIBRARY BUG: bogus sigport demux table");
for (i = 0; i < _hurd_sigport_ids.n; ++i)
if (inp->msgh_id == _hurd_sigport_ids.id[i])
{
(*_hurd_sigport_routines.routine[i]) (inp, outp);
return 1;
}
{
mig_reply_header_t *r = (mig_reply_header_t *) outp;
r->RetCode = MIG_BAD_ID;
return 0;
}
}
/* This is the code that the signal thread runs. */
void
_hurd_sigport_receive (void)
{
while (1)
(void) __mach_msg_server (_hurd_sigport_demux, __vm_page_size,
_hurd_sigport);
}

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <gnu-stabs.h>
symbol_alias (__task2pid, task2pid);