summaryrefslogtreecommitdiff
path: root/sysdeps/mach
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach')
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.h8
-rw-r--r--sysdeps/mach/hurd/fdopendir.c56
-rw-r--r--sysdeps/mach/hurd/getpeername.c11
-rw-r--r--sysdeps/mach/hurd/i386/init-first.c25
-rw-r--r--sysdeps/mach/hurd/opendir.c65
-rw-r--r--sysdeps/mach/hurd/profil.c4
-rw-r--r--sysdeps/mach/hurd/setitimer.c12
7 files changed, 134 insertions, 47 deletions
diff --git a/sysdeps/mach/hurd/dl-sysdep.h b/sysdeps/mach/hurd/dl-sysdep.h
index 2dc9b0a910..4b21b779ef 100644
--- a/sysdeps/mach/hurd/dl-sysdep.h
+++ b/sysdeps/mach/hurd/dl-sysdep.h
@@ -1,5 +1,5 @@
/* System-specific settings for dynamic linker code. Hurd version.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2005 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
@@ -23,3 +23,9 @@
(open, mmap, etc). */
#define RTLD_PRIVATE_ERRNO 0
+
+#ifdef SHARED
+/* _dl_argv cannot be attribute_relro, because the stack-switching
+ libc initializer for using cthreads might write into it. */
+# define DL_ARGV_NOT_RELRO 1
+#endif
diff --git a/sysdeps/mach/hurd/fdopendir.c b/sysdeps/mach/hurd/fdopendir.c
new file mode 100644
index 0000000000..37dd4bc82e
--- /dev/null
+++ b/sysdeps/mach/hurd/fdopendir.c
@@ -0,0 +1,56 @@
+/* Open a directory stream from a file descriptor. Hurd version.
+ Copyright (C) 2005 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 Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <dirent.h>
+#include <errno.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+#include <fcntl.h>
+
+DIR *_hurd_fd_opendir (struct hurd_fd *d); /* opendir.c */
+
+/* Open a directory stream on FD. */
+DIR *
+fdopendir (int fd)
+{
+ struct hurd_fd *d = _hurd_fd_get (fd);
+
+ if (d == NULL)
+ {
+ errno = EBADF;
+ return NULL;
+ }
+
+ /* Ensure that it's a directory. */
+ error_t err = HURD_FD_PORT_USE
+ (d, ({
+ file_t dir = __file_name_lookup_under (port, "/", O_NOTRANS, 0);
+ if (dir != MACH_PORT_NULL)
+ __mach_port_deallocate (__mach_task_self (), dir);
+ dir != MACH_PORT_NULL ? 0 : errno;
+ }));
+
+ if (err)
+ {
+ errno = err;
+ return NULL;
+ }
+
+ return _hurd_fd_opendir (d);
+}
diff --git a/sysdeps/mach/hurd/getpeername.c b/sysdeps/mach/hurd/getpeername.c
index 2e4f9f6a9d..39071c1da4 100644
--- a/sysdeps/mach/hurd/getpeername.c
+++ b/sysdeps/mach/hurd/getpeername.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1994, 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1992,1994,1997,1999,2000,2005 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
@@ -47,14 +47,19 @@ __getpeername (int fd, __SOCKADDR_ARG addrarg, socklen_t *len)
if (*len > buflen)
*len = buflen;
-
+
if (buf != (char *) addr)
{
memcpy (addr, buf, *len);
__vm_deallocate (__mach_task_self (), (vm_address_t) buf, buflen);
}
- addr->sa_family = type;
+ const sa_family_t family = type;
+ if (*len < (char *) (&addr->sa_family + 1) - (char *) addr)
+ memcpy (&addr->sa_family, &family,
+ *len - offsetof (struct sockaddr, sa_family));
+ else
+ addr->sa_family = family;
return 0;
}
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index caa232026d..f9a7a58deb 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -1,5 +1,6 @@
/* Initialization code run first thing by the ELF startup code. For i386/Hurd.
- Copyright (C) 1995,96,97,98,99,2000,01,02,03,04 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2000,01,02,03,04,05
+ 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
@@ -54,7 +55,7 @@ extern int __libc_argc attribute_hidden;
extern char **__libc_argv attribute_hidden;
extern char **_dl_argv;
-void *(*_cthread_init_routine) (void); /* Returns new SP to use. */
+extern void *(*_cthread_init_routine) (void) __attribute__ ((weak));
void (*_cthread_exit_routine) (int status) __attribute__ ((__noreturn__));
/* Things that want to be run before _hurd_init or much anything else.
@@ -203,7 +204,7 @@ init (int *data)
code as the return address, and the argument data immediately above
that on the stack. */
- if (_cthread_init_routine)
+ if (&_cthread_init_routine && _cthread_init_routine)
{
/* Initialize cthreads, which will allocate us a new stack to run on. */
int *newsp = (*_cthread_init_routine) ();
@@ -271,7 +272,7 @@ init (int *data)
/* The argument data is just above the stack frame we will unwind by
returning. Mutate our own return address to run the code below. */
usercode = data[-1];
- ((void **) data)[-1] = call_init1;
+ data[-1] = (int) &call_init1;
/* Force USERCODE into %eax and &init1 into %ecx, which are not
restored by function return. */
asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1));
@@ -319,11 +320,11 @@ first_init (void)
stack set up just as the user will see it, so it can switch stacks. */
void
-_dl_init_first (int argc, ...)
+_dl_init_first (void)
{
first_init ();
- init (&argc);
+ init ((int *) __builtin_frame_address (0) + 2);
}
#endif
@@ -350,21 +351,23 @@ strong_alias (posixland_init, __libc_init_first);
This poorly-named function is called by static-start.S,
which should not exist at all. */
void
-_hurd_stack_setup (volatile int argc, ...)
+_hurd_stack_setup (void)
{
+ intptr_t caller = (intptr_t) __builtin_return_address (0);
+
void doinit (intptr_t *data)
{
/* This function gets called with the argument data at TOS. */
- void doinit1 (volatile int argc, ...)
+ void doinit1 (void)
{
- init ((int *) &argc);
+ init ((int *) __builtin_frame_address (0) + 2);
}
/* Push the user return address after the argument data, and then
jump to `doinit1' (above), so it is as if __libc_init_first's
caller had called `doinit1' with the argument data already on the
stack. */
- *--data = (&argc)[-1];
+ *--data = caller;
asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack. */
"movl $0, %%ebp\n" /* Clear outermost frame pointer. */
"jmp *%1" : : "r" (data), "r" (&doinit1) : "sp");
@@ -373,7 +376,7 @@ _hurd_stack_setup (volatile int argc, ...)
first_init ();
- _hurd_startup ((void **) &argc, &doinit);
+ _hurd_startup ((void **) __builtin_frame_address (0) + 2, &doinit);
}
#endif
diff --git a/sysdeps/mach/hurd/opendir.c b/sysdeps/mach/hurd/opendir.c
index a1ff947f06..5b10142d39 100644
--- a/sysdeps/mach/hurd/opendir.c
+++ b/sysdeps/mach/hurd/opendir.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993,94,95,96,97,98,2001,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993,94,95,96,97,98,2001,2003,2005
+ 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
@@ -32,13 +33,46 @@
#include "dirstream.h"
+/* Open a directory stream on a file descriptor in Hurd internal form.
+ We do no checking here on the descriptor. */
+DIR *
+_hurd_fd_opendir (struct hurd_fd *d)
+{
+ DIR *dirp;
+
+ if (d == NULL)
+ {
+ errno = EBADF;
+ return NULL;
+ }
+
+ dirp = (DIR *) malloc (sizeof (DIR));
+ if (dirp == NULL)
+ return NULL;
+
+ /* Set the descriptor to close on exec. */
+ __spin_lock (&d->port.lock);
+ d->flags |= FD_CLOEXEC;
+ __spin_unlock (&d->port.lock);
+
+ dirp->__fd = d;
+ dirp->__data = dirp->__ptr = NULL;
+ dirp->__entry_data = dirp->__entry_ptr = 0;
+ dirp->__allocation = 0;
+ dirp->__size = 0;
+
+ __libc_lock_init (dirp->__lock);
+
+ return dirp;
+}
+
+
/* Open a directory stream on NAME. */
DIR *
__opendir (const char *name)
{
- DIR *dirp;
int fd;
- struct hurd_fd *d;
+ DIR *dirp;
if (name[0] == '\0')
{
@@ -71,29 +105,10 @@ __opendir (const char *name)
if (fd < 0)
return NULL;
- dirp = (DIR *) malloc (sizeof (DIR));
- if (dirp == NULL)
- {
- __close (fd);
- return NULL;
- }
-
/* Extract the pointer to the descriptor structure. */
- __mutex_lock (&_hurd_dtable_lock);
- d = dirp->__fd = _hurd_dtable[fd];
- __mutex_unlock (&_hurd_dtable_lock);
-
- /* Set the descriptor to close on exec. */
- __spin_lock (&d->port.lock);
- d->flags |= FD_CLOEXEC;
- __spin_unlock (&d->port.lock);
-
- dirp->__data = dirp->__ptr = NULL;
- dirp->__entry_data = dirp->__entry_ptr = 0;
- dirp->__allocation = 0;
- dirp->__size = 0;
-
- __libc_lock_init (dirp->__lock);
+ dirp = _hurd_fd_opendir (_hurd_fd_get (fd));
+ if (dirp == NULL)
+ __close (fd);
return dirp;
}
diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c
index d212872643..0426f67b6f 100644
--- a/sysdeps/mach/hurd/profil.c
+++ b/sysdeps/mach/hurd/profil.c
@@ -1,5 +1,5 @@
/* Low-level statistical profiling support function. Mach/Hurd version.
- Copyright (C) 1995, 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 2000, 2002, 2005 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
@@ -49,6 +49,7 @@ static kern_return_t profil_task_get_sampled_pcs (mach_port_t,
sampled_pc_array_t,
mach_msg_type_number_t *);
static void fetch_samples (void);
+static void profile_waiter (void);
/* Enable statistical profiling, writing samples of the PC into at most
SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling
@@ -64,7 +65,6 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
if (profile_thread == MACH_PORT_NULL)
{
/* Set up the profiling collector thread. */
- static void profile_waiter (void);
err = __thread_create (__mach_task_self (), &profile_thread);
if (! err)
err = __mach_setup_thread (__mach_task_self (), profile_thread,
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index 9fef56287d..fec64a8cb5 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1994,1995,1996,1997,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1994,1995,1996,1997,2000,2001,2005
+ 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
@@ -41,7 +42,7 @@ static void
quantize_timeval (struct timeval *tv)
{
static time_t quantum = -1;
-
+
if (quantum == -1)
quantum = 1000000 / __getclktck ();
@@ -127,14 +128,15 @@ timer_thread (void)
}
+/* Forward declaration. */
+static int setitimer_locked (const struct itimerval *new,
+ struct itimerval *old, void *crit);
+
static sighandler_t
restart_itimer (struct hurd_signal_preemptor *preemptor,
struct hurd_sigstate *ss,
int *signo, struct hurd_signal_detail *detail)
{
- static int setitimer_locked (const struct itimerval *new,
- struct itimerval *old, void *crit);
-
/* This function gets called in the signal thread
each time a SIGALRM is arriving (even if blocked). */
struct itimerval it;