/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <sys/resource.h>
#include <unistd.h>
#include <errno.h>
/*
* Stack allocated by thread when doing blocking operation
*/
typedef struct threadEntry {
/*
* Heap allocated during initialized - one entry per fd
*/
typedef struct {
} fdEntry_t;
/*
* Signal to unblock thread
*/
/*
* The fd table and the number of file descriptors
*/
static int fdCount;
/*
* Null signal handler
*/
}
/*
* Initialization routine (executed when library is loaded)
* Allocate fd tables and sets up signal handler.
*/
/*
* Allocate table based on the maximum number of
* file descriptors.
*/
"unable to allocate file descriptor table - out of memory");
abort();
}
/*
* Setup the signal handler
*/
}
/*
* Return the fd table for this fd or NULL is fd out
* of range.
*/
{
return NULL;
}
}
/*
* Start a blocking operation :-
* Insert thread onto thread list for the fd.
*/
{
{
}
}
/*
* End a blocking operation :-
* Remove thread from thread list for the fd
* If fd has been interrupted then set errno to EBADF
*/
static inline void endOp
{
{
orig_errno = EBADF;
}
} else {
}
break;
}
}
}
errno = orig_errno;
}
/*
* Close or dup2 a file descriptor ensuring that all threads blocked on
* the file descriptor are notified via a wakeup signal.
*
* fd1 < 0 => close(fd2)
* fd1 >= 0 => dup2(fd1, fd2)
*
* Returns -1 with errno set if operation fails.
*/
return -1;
}
/*
* Lock the fd to hold-off additional I/O on this fd.
*/
{
/*
* Send a wakeup signal to all threads blocked on this
* file descriptor.
*/
}
/*
* (restart if interrupted by signal)
*/
do {
if (fd1 < 0) {
} else {
}
}
/*
* Unlock without destroying errno
*/
orig_errno = errno;
errno = orig_errno;
return rv;
}
/*
* Wrapper for dup2 - same semantics as dup2 system call except
* that any threads blocked in an I/O system call on fd2 will be
* preempted and return -1/EBADF;
*/
if (fd < 0) {
return -1;
}
}
/*
* Wrapper for close - same semantics as close system call
* except that any threads blocked in an I/O on fd will be
* preempted and the I/O system call will return -1/EBADF.
*/
}
/************** Basic I/O operations here ***************/
/*
* Macro to perform a blocking IO operation. Restarts
* automatically if interrupted by signal (other than
* our wakeup signal)
*/
int ret; \
return -1; \
} \
do { \
return ret; \
}
}
}
}
}
}
}
}
}
#ifndef USE_SELECT
}
#else
BLOCKING_IO_RETURN_INT( s-1,
}
#endif
/*
* Wrapper for poll(s, timeout).
* Auto restarts with adjusted timeout if interrupted by
* signal other than our wakeup signal.
*/
struct timeval t;
/*
* Check that fd hasn't been closed.
*/
return -1;
}
/*
* Pick up current time as may need to adjust timeout
*/
if (timeout > 0) {
gettimeofday(&t, NULL);
}
for(;;) {
int rv;
/*
* Poll the fd. If interrupted by our wakeup signal
* errno will be set to EBADF.
*/
/*
* If interrupted then adjust timeout. If timeout
* has expired return 0 (indicating timeout expired).
*/
if (timeout > 0) {
gettimeofday(&t, NULL);
if (timeout <= 0) {
return 0;
}
}
} else {
return rv;
}
}
}