summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpthread/uthread')
-rw-r--r--lib/libpthread/uthread/pthread_private.h11
-rw-r--r--lib/libpthread/uthread/uthread_close.c4
-rw-r--r--lib/libpthread/uthread/uthread_closefrom.c12
-rw-r--r--lib/libpthread/uthread/uthread_dup2.c4
-rw-r--r--lib/libpthread/uthread/uthread_execve.c4
-rw-r--r--lib/libpthread/uthread/uthread_exit.c4
-rw-r--r--lib/libpthread/uthread/uthread_fd.c18
-rw-r--r--lib/libpthread/uthread/uthread_fork.c4
-rw-r--r--lib/libpthread/uthread/uthread_info_openbsd.c6
-rw-r--r--lib/libpthread/uthread/uthread_init.c17
-rw-r--r--lib/libpthread/uthread/uthread_kern.c14
-rw-r--r--lib/libpthread/uthread/uthread_poll.c6
-rw-r--r--lib/libpthread/uthread/uthread_select.c6
-rw-r--r--lib/libpthread/uthread/uthread_sig.c4
14 files changed, 63 insertions, 51 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index 55053e2041d..1607525dfeb 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.60 2007/04/26 18:13:10 kurt Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.61 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -986,7 +986,14 @@ SCLASS struct pollfd *_thread_pfd_table
;
#endif
-SCLASS int _thread_dtablesize /* Descriptor table size. */
+SCLASS int _thread_init_fdtsize /* Initial fd/pfd table size. */
+#ifdef GLOBAL_PTHREAD_PRIVATE
+= 0;
+#else
+;
+#endif
+
+SCLASS int _thread_max_fdtsize /* Max fd/pfd table size. */
#ifdef GLOBAL_PTHREAD_PRIVATE
= 0;
#else
diff --git a/lib/libpthread/uthread/uthread_close.c b/lib/libpthread/uthread/uthread_close.c
index 05057dd026f..60232ec7d8c 100644
--- a/lib/libpthread/uthread/uthread_close.c
+++ b/lib/libpthread/uthread/uthread_close.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_close.c,v 1.13 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_close.c,v 1.14 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -47,7 +47,7 @@ close(int fd)
/* This is a cancelation point: */
_thread_enter_cancellation_point();
- if ((fd < 0) || (fd >= _thread_dtablesize) ||
+ if ((fd < 0) || (fd >= _thread_max_fdtsize) ||
(fd == _thread_kern_pipe[0]) || (fd == _thread_kern_pipe[1])) {
errno = EBADF;
ret = -1;
diff --git a/lib/libpthread/uthread/uthread_closefrom.c b/lib/libpthread/uthread/uthread_closefrom.c
index 62176ec2d24..38a6eb79de3 100644
--- a/lib/libpthread/uthread/uthread_closefrom.c
+++ b/lib/libpthread/uthread/uthread_closefrom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_closefrom.c,v 1.3 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_closefrom.c,v 1.4 2007/04/27 12:59:24 kurt Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
@@ -21,7 +21,7 @@ closefrom(int fd)
_thread_enter_cancellation_point();
- if (fd < 0 || fd >= _thread_dtablesize) {
+ if (fd < 0 || fd >= _thread_max_fdtsize) {
errno = EBADF;
ret = -1;
} else {
@@ -35,13 +35,13 @@ closefrom(int fd)
for (safe_fd++; fd < safe_fd; fd++)
close(fd);
- flags = calloc((size_t)_thread_dtablesize, sizeof *flags);
+ flags = calloc((size_t)_thread_max_fdtsize, sizeof *flags);
if (flags == NULL) {
/* use calloc errno */
ret = -1;
} else {
/* Lock and record all fd entries */
- for (lock_fd = fd; lock_fd < _thread_dtablesize; lock_fd++) {
+ for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) {
if (_thread_fd_table[lock_fd] != NULL &&
_thread_fd_table[lock_fd]->state != FD_ENTRY_CLOSED) {
ret = _FD_LOCK(lock_fd, FD_RDWR_CLOSE, NULL);
@@ -57,7 +57,7 @@ closefrom(int fd)
* Close the entries and reset the non-bocking
* flag when needed.
*/
- for (lock_fd = fd; lock_fd < _thread_dtablesize; lock_fd++) {
+ for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) {
if (flags[lock_fd] != NULL) {
_thread_fd_entry_close(lock_fd);
}
@@ -74,7 +74,7 @@ closefrom(int fd)
/*
* Unlock any locked entries.
*/
- for (lock_fd = fd; lock_fd < _thread_dtablesize; lock_fd++) {
+ for (lock_fd = fd; lock_fd < _thread_max_fdtsize; lock_fd++) {
if (flags[lock_fd] != NULL) {
_FD_UNLOCK(lock_fd, FD_RDWR_CLOSE);
}
diff --git a/lib/libpthread/uthread/uthread_dup2.c b/lib/libpthread/uthread/uthread_dup2.c
index 0ed5578686f..8bd4d5b4bba 100644
--- a/lib/libpthread/uthread/uthread_dup2.c
+++ b/lib/libpthread/uthread/uthread_dup2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_dup2.c,v 1.10 2006/10/03 02:29:14 kurt Exp $ */
+/* $OpenBSD: uthread_dup2.c,v 1.11 2007/04/27 12:59:24 kurt Exp $ */
/* PUBLIC DOMAIN <marc@snafu.org> */
#include <errno.h>
@@ -13,7 +13,7 @@ dup2(int fd, int newfd)
int ret;
int saved_errno;
- if (newfd >= 0 && newfd < _thread_dtablesize &&
+ if (newfd >= 0 && newfd < _thread_max_fdtsize &&
newfd != _thread_kern_pipe[0] && newfd != _thread_kern_pipe[1]) {
ret = _FD_LOCK(fd, FD_RDWR, NULL);
if (ret == 0) {
diff --git a/lib/libpthread/uthread/uthread_execve.c b/lib/libpthread/uthread/uthread_execve.c
index bc45ab1d983..ebf3fb75356 100644
--- a/lib/libpthread/uthread/uthread_execve.c
+++ b/lib/libpthread/uthread/uthread_execve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_execve.c,v 1.9 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_execve.c,v 1.10 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -65,7 +65,7 @@ execve(const char *name, char *const * argv, char *const * envp)
* Enter a loop to set all file descriptors to blocking
* if they were not created as non-blocking:
*/
- for (i = 0; i < _thread_dtablesize; i++) {
+ for (i = 0; i < _thread_max_fdtsize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
_thread_fd_table[i]->status_flags != NULL &&
diff --git a/lib/libpthread/uthread/uthread_exit.c b/lib/libpthread/uthread/uthread_exit.c
index 4836123b2b1..659cb9e81f8 100644
--- a/lib/libpthread/uthread/uthread_exit.c
+++ b/lib/libpthread/uthread/uthread_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_exit.c,v 1.19 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_exit.c,v 1.20 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -64,7 +64,7 @@ _exit(int status)
* Enter a loop to set all file descriptors to blocking
* if they were not created as non-blocking:
*/
- for (i = 0; i < _thread_dtablesize; i++) {
+ for (i = 0; i < _thread_max_fdtsize; i++) {
/* Check if this file descriptor is in use: */
if (_thread_fd_table[i] != NULL &&
_thread_fd_table[i]->status_flags != NULL &&
diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c
index 6d840cb2005..632eadcc968 100644
--- a/lib/libpthread/uthread/uthread_fd.c
+++ b/lib/libpthread/uthread/uthread_fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fd.c,v 1.27 2006/12/01 16:34:41 kurt Exp $ */
+/* $OpenBSD: uthread_fd.c,v 1.28 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -201,12 +201,12 @@ _thread_fd_init(void)
struct fs_flags *status_flags;
saved_errno = errno;
- flags = calloc(_thread_dtablesize, sizeof *flags);
+ flags = calloc(_thread_init_fdtsize, sizeof *flags);
if (flags == NULL)
PANIC("Cannot allocate memory for flags table");
/* read the current file flags */
- for (fd = 0; fd < _thread_dtablesize; fd += 1)
+ for (fd = 0; fd < _thread_init_fdtsize; fd += 1)
flags[fd] = _thread_sys_fcntl(fd, F_GETFL, 0);
/*
@@ -219,7 +219,7 @@ _thread_fd_init(void)
*/
_SPINLOCK(&fd_table_lock);
- for (fd = 0; fd < _thread_dtablesize; fd += 1) {
+ for (fd = 0; fd < _thread_init_fdtsize; fd += 1) {
if (flags[fd] == -1)
continue;
entry1 = _thread_fd_entry();
@@ -227,7 +227,7 @@ _thread_fd_init(void)
if (entry1 != NULL && status_flags != NULL) {
_thread_sys_fcntl(fd, F_SETFL,
flags[fd] ^ O_SYNC);
- for (fd2 = fd + 1; fd2 < _thread_dtablesize; fd2 += 1) {
+ for (fd2 = fd + 1; fd2 < _thread_init_fdtsize; fd2 += 1) {
if (flags[fd2] == -1)
continue;
flag = _thread_sys_fcntl(fd2, F_GETFL, 0);
@@ -266,7 +266,7 @@ _thread_fd_init(void)
know to be duped have been modified so set the non-blocking'
flag. Other files will be set to non-blocking when the
thread code is forced to take notice of the file. */
- for (fd = 0; fd < _thread_dtablesize; fd += 1)
+ for (fd = 0; fd < _thread_init_fdtsize; fd += 1)
if (flags[fd] != -1)
_thread_sys_fcntl(fd, F_SETFL, flags[fd]);
@@ -290,7 +290,7 @@ _thread_fd_table_init(int fd, enum fd_entry_mode init_mode, struct fs_flags *sta
struct fd_table_entry *entry;
struct fs_flags *new_status_flags;
- if (fd < 0 || fd >= _thread_dtablesize) {
+ if (fd < 0 || fd >= _thread_max_fdtsize) {
/*
* file descriptor is out of range, Return a bad file
* descriptor error:
@@ -499,7 +499,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type)
* If file descriptor is out of range or uninitialized,
* do nothing.
*/
- if (fd >= 0 && fd < _thread_dtablesize && _thread_fd_table[fd] != NULL) {
+ if (fd >= 0 && fd < _thread_max_fdtsize && _thread_fd_table[fd] != NULL) {
entry = _thread_fd_table[fd];
/*
@@ -619,7 +619,7 @@ _thread_fd_unlock_owned(pthread_t pthread)
int do_unlock;
int fd;
- for (fd = 0; fd < _thread_dtablesize; fd++) {
+ for (fd = 0; fd < _thread_max_fdtsize; fd++) {
entry = _thread_fd_table[fd];
if (entry) {
_SPINLOCK(&entry->lock);
diff --git a/lib/libpthread/uthread/uthread_fork.c b/lib/libpthread/uthread/uthread_fork.c
index 9253993bc28..f14d1cb1581 100644
--- a/lib/libpthread/uthread/uthread_fork.c
+++ b/lib/libpthread/uthread/uthread_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fork.c,v 1.16 2007/04/10 13:04:37 kurt Exp $ */
+/* $OpenBSD: uthread_fork.c,v 1.17 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -173,7 +173,7 @@ fork(void)
_sched_switch_hook = NULL;
/* Clear out any locks in the file descriptor table: */
- for (i = 0; i < _thread_dtablesize; i++) {
+ for (i = 0; i < _thread_max_fdtsize; i++) {
if (_thread_fd_table[i] != NULL) {
/* Initialise the file locks: */
_SPINLOCK_INIT(&_thread_fd_table[i]->lock);
diff --git a/lib/libpthread/uthread/uthread_info_openbsd.c b/lib/libpthread/uthread/uthread_info_openbsd.c
index 70735efe97b..1bd94f55d36 100644
--- a/lib/libpthread/uthread/uthread_info_openbsd.c
+++ b/lib/libpthread/uthread/uthread_info_openbsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_info_openbsd.c,v 1.11 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_info_openbsd.c,v 1.12 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
@@ -345,7 +345,7 @@ _thread_dump_info(void)
/* Output a header for file descriptors: */
snprintf(s, sizeof(s), "file descriptor table, size %d:\n",
- _thread_dtablesize);
+ _thread_max_fdtsize);
_thread_sys_write(fd, s, strlen(s));
snprintf(s, sizeof s,
@@ -355,7 +355,7 @@ _thread_dump_info(void)
_thread_sys_write(fd, s, strlen(s));
/* Enter a loop to report file descriptor lock usage: */
- for (i = 0; i < _thread_dtablesize; i++) {
+ for (i = 0; i < _thread_max_fdtsize; i++) {
/*
* Check if memory is allocated for this file
* descriptor:
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 6193166856d..c8c57c0170d 100644
--- a/lib/libpthread/uthread/uthread_init.c
+++ b/lib/libpthread/uthread/uthread_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_init.c,v 1.35 2006/04/09 02:57:41 krw Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.36 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -49,6 +49,7 @@
#include <sys/ttycom.h>
#include <sys/user.h>
#include <sys/wait.h>
+#include <sys/resource.h>
#include <dlfcn.h>
#include <dirent.h>
@@ -158,6 +159,7 @@ _thread_init(void)
int mib[2];
struct clockinfo clockinfo;
struct sigaction act;
+ struct rlimit rl;
/* Check if this function has already been called: */
if (_thread_initial)
@@ -345,19 +347,22 @@ _thread_init(void)
clockinfo.tick : CLOCK_RES_USEC_MIN;
/* Get the table size: */
- if ((_thread_dtablesize = getdtablesize()) < 0)
- PANIC("Cannot get dtablesize");
+ if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
+ PANIC("getrlimit failed");
+
+ _thread_init_fdtsize = rl.rlim_cur;
+ _thread_max_fdtsize = rl.rlim_max;
/* Allocate memory for the file descriptor table: */
- _thread_fd_table = calloc(_thread_dtablesize,
+ _thread_fd_table = calloc(_thread_max_fdtsize,
sizeof(struct fd_table_entry *));
if (_thread_fd_table == NULL) {
- _thread_dtablesize = 0;
+ _thread_max_fdtsize = 0;
PANIC("Cannot allocate memory for file descriptor table");
}
/* Allocate memory for the pollfd table: */
- _thread_pfd_table = calloc(_thread_dtablesize, sizeof(struct pollfd));
+ _thread_pfd_table = calloc(_thread_max_fdtsize, sizeof(struct pollfd));
if (_thread_pfd_table == NULL)
PANIC("Cannot allocate memory for pollfd table");
diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c
index dc82afa0d72..02c9a42b418 100644
--- a/lib/libpthread/uthread/uthread_kern.c
+++ b/lib/libpthread/uthread/uthread_kern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kern.c,v 1.33 2006/10/25 14:32:04 kurt Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.34 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -704,7 +704,7 @@ _thread_kern_poll(int wait_reqd)
PTHREAD_WAITQ_SETACTIVE();
} else {
/* Limit number of polled files to table size: */
- if (nfds < _thread_dtablesize) {
+ if (nfds < _thread_max_fdtsize) {
_thread_pfd_table[nfds].events = POLLRDNORM;
_thread_pfd_table[nfds].fd = pthread->data.fd.fd;
nfds++;
@@ -723,7 +723,7 @@ _thread_kern_poll(int wait_reqd)
PTHREAD_WAITQ_SETACTIVE();
} else {
/* Limit number of polled files to table size: */
- if (nfds < _thread_dtablesize) {
+ if (nfds < _thread_max_fdtsize) {
_thread_pfd_table[nfds].events = POLLWRNORM;
_thread_pfd_table[nfds].fd = pthread->data.fd.fd;
nfds++;
@@ -736,7 +736,7 @@ _thread_kern_poll(int wait_reqd)
case PS_SELECT_WAIT:
/* Limit number of polled files to table size: */
if (pthread->data.poll_data->nfds + nfds <
- _thread_dtablesize) {
+ _thread_max_fdtsize) {
for (i = 0; i < pthread->data.poll_data->nfds; i++) {
_thread_pfd_table[nfds + i].fd =
pthread->data.poll_data->fds[i].fd;
@@ -825,7 +825,7 @@ _thread_kern_poll(int wait_reqd)
/* File descriptor read wait: */
case PS_FDR_WAIT:
- if ((nfds < _thread_dtablesize) &&
+ if ((nfds < _thread_max_fdtsize) &&
(_thread_pfd_table[nfds].revents
& (POLLRDNORM|POLLERR|POLLHUP|POLLNVAL))
!= 0) {
@@ -839,7 +839,7 @@ _thread_kern_poll(int wait_reqd)
/* File descriptor write wait: */
case PS_FDW_WAIT:
- if ((nfds < _thread_dtablesize) &&
+ if ((nfds < _thread_max_fdtsize) &&
(_thread_pfd_table[nfds].revents
& (POLLWRNORM|POLLERR|POLLHUP|POLLNVAL))
!= 0) {
@@ -855,7 +855,7 @@ _thread_kern_poll(int wait_reqd)
case PS_POLL_WAIT:
case PS_SELECT_WAIT:
if (pthread->data.poll_data->nfds + nfds <
- _thread_dtablesize) {
+ _thread_max_fdtsize) {
/*
* Enter a loop looking for I/O
* readiness:
diff --git a/lib/libpthread/uthread/uthread_poll.c b/lib/libpthread/uthread/uthread_poll.c
index d667a5a1ed4..8f445235e30 100644
--- a/lib/libpthread/uthread/uthread_poll.c
+++ b/lib/libpthread/uthread/uthread_poll.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_poll.c,v 1.13 2006/10/25 14:32:04 kurt Exp $ */
+/* $OpenBSD: uthread_poll.c,v 1.14 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1999 Daniel Eischen <eischen@vigrid.com>
* All rights reserved.
@@ -56,8 +56,8 @@ poll(struct pollfd fds[], nfds_t nfds, int timeout)
/* This is a cancellation point: */
_thread_enter_cancellation_point();
- if (numfds > (nfds_t)_thread_dtablesize) {
- numfds = _thread_dtablesize;
+ if (numfds > (nfds_t)_thread_max_fdtsize) {
+ numfds = _thread_max_fdtsize;
}
/* Check if a timeout was specified: */
if (timeout == INFTIM) {
diff --git a/lib/libpthread/uthread/uthread_select.c b/lib/libpthread/uthread/uthread_select.c
index b43820d506d..32d6ee7f255 100644
--- a/lib/libpthread/uthread/uthread_select.c
+++ b/lib/libpthread/uthread/uthread_select.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_select.c,v 1.13 2006/10/25 14:32:04 kurt Exp $ */
+/* $OpenBSD: uthread_select.c,v 1.14 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -64,8 +64,8 @@ select(int numfds, fd_set * readfds, fd_set * writefds,
/* This is a cancellation point: */
_thread_enter_cancellation_point();
- if (numfds > _thread_dtablesize) {
- numfds = _thread_dtablesize;
+ if (numfds > _thread_max_fdtsize) {
+ numfds = _thread_max_fdtsize;
}
/* Check if a timeout was specified: */
if (timeout) {
diff --git a/lib/libpthread/uthread/uthread_sig.c b/lib/libpthread/uthread/uthread_sig.c
index 73b2cdfd8ae..5c65781e552 100644
--- a/lib/libpthread/uthread/uthread_sig.c
+++ b/lib/libpthread/uthread/uthread_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sig.c,v 1.22 2006/09/26 14:18:28 kurt Exp $ */
+/* $OpenBSD: uthread_sig.c,v 1.23 2007/04/27 12:59:24 kurt Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -184,7 +184,7 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
* to non-blocking again in case the child
* set some of them to block. Sigh.
*/
- for (i = 0; i < _thread_dtablesize; i++)
+ for (i = 0; i < _thread_max_fdtsize; i++)
if (_thread_fd_table[i] != NULL &&
_thread_fd_table[i]->status_flags != NULL)
_thread_sys_fcntl(i, F_SETFL,