acb5617538
(ftruncate64): Ditto. (lseek64): Ditto. (lstat64): Ditto. (mmap64): Ditto. (seekdir64): Ditto. (stat64): Ditto. (telldir64): Ditto. (truncate64): Ditto. * dir.cc (telldir64): New function. (telldir): Call telldir64(). (seekdir64): New function. (seekdir): Call seekdir64(). * fhandler.h: Redefine all methods using __off32_t to use __off64_t. * fhandler.cc: Use __off64_t and struct __stat64 throughout. * fhandler_clipboard.cc: Ditto. * fhandler_disk_file.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_floppy.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_socket.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_zero.cc: Ditto. * pipe.cc: Ditto. * glob.c: Ditto, call lstat64 and stat64 in Cygwin. * mmap.cc: Use __off64_t throughout. (mmap64): New function. * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. * syscalls.cc (lseek64): New function. (stat64_to_stat32): Ditto. (fstat64): Ditto. (stat64): Ditto. (lstat64): Ditto. (ftruncate64): Ditto. (truncate64): Ditto. (_fstat): Call fstat64. (_stat): Call stat64. (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. (stat_worker): Use struct __stat64. (access): Ditto. (ftruncate): Call ftruncate64. (truncate): Call truncate64. * wincap.cc: Set flag has_64bit_file_access appropriately. * wincap.h: Add flag has_64bit_file_access. * winsup.h (ILLEGAL_SEEK): Define as __off64_t. (stat_dev): Declare using struct __stat64. (stat_worker): Ditto. * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. (struct __stat64): Ditto. (struct stat): Revert definition with explicitly sized datatypes. Eliminate sized field names. * include/cygwin/types.h (blksize_t): New type. (__blkcnt32_t): Ditto. (__blkcnt64_t): Ditto. (blkcnt_t): Ditto.
199 lines
4.6 KiB
C++
199 lines
4.6 KiB
C++
/* pipe.cc: pipe for Cygwin.
|
|
|
|
Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#include "winsup.h"
|
|
#include <unistd.h>
|
|
#include <sys/fcntl.h>
|
|
#include <errno.h>
|
|
#include "cygerrno.h"
|
|
#include "security.h"
|
|
#include "fhandler.h"
|
|
#include "path.h"
|
|
#include "dtable.h"
|
|
#include "cygheap.h"
|
|
#include "thread.h"
|
|
#include "sigproc.h"
|
|
#include "pinfo.h"
|
|
|
|
static unsigned pipecount;
|
|
static const NO_COPY char pipeid_fmt[] = "stupid_pipe.%u.%u";
|
|
|
|
fhandler_pipe::fhandler_pipe (DWORD devtype)
|
|
: fhandler_base (devtype), guard (NULL), broken_pipe (false), writepipe_exists(0),
|
|
orig_pid (0), id (0)
|
|
{
|
|
}
|
|
|
|
__off64_t
|
|
fhandler_pipe::lseek (__off64_t offset, int whence)
|
|
{
|
|
debug_printf ("(%d, %d)", offset, whence);
|
|
set_errno (ESPIPE);
|
|
return -1;
|
|
}
|
|
|
|
void
|
|
fhandler_pipe::set_close_on_exec (int val)
|
|
{
|
|
this->fhandler_base::set_close_on_exec (val);
|
|
if (guard)
|
|
set_inheritance (guard, val);
|
|
if (writepipe_exists)
|
|
set_inheritance (writepipe_exists, val);
|
|
}
|
|
|
|
int __stdcall
|
|
fhandler_pipe::read (void *in_ptr, size_t in_len)
|
|
{
|
|
if (broken_pipe)
|
|
return 0;
|
|
int res = this->fhandler_base::read (in_ptr, in_len);
|
|
(void) ReleaseMutex (guard);
|
|
return res;
|
|
}
|
|
|
|
int fhandler_pipe::close ()
|
|
{
|
|
int res = this->fhandler_base::close ();
|
|
if (guard)
|
|
CloseHandle (guard);
|
|
if (writepipe_exists)
|
|
CloseHandle (writepipe_exists);
|
|
return res;
|
|
}
|
|
|
|
bool
|
|
fhandler_pipe::hit_eof ()
|
|
{
|
|
char buf[80];
|
|
HANDLE ev;
|
|
if (broken_pipe)
|
|
return 1;
|
|
if (!orig_pid)
|
|
return false;
|
|
__small_sprintf (buf, pipeid_fmt, orig_pid, id);
|
|
if ((ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf)))
|
|
CloseHandle (ev);
|
|
debug_printf ("%s %p", buf, ev);
|
|
return ev == NULL;
|
|
}
|
|
|
|
void
|
|
fhandler_pipe::fixup_after_fork (HANDLE parent)
|
|
{
|
|
this->fhandler_base::fixup_after_fork (parent);
|
|
if (guard)
|
|
fork_fixup (parent, guard, "guard");
|
|
if (writepipe_exists)
|
|
fork_fixup (parent, writepipe_exists, "guard");
|
|
}
|
|
|
|
int
|
|
fhandler_pipe::dup (fhandler_base *child)
|
|
{
|
|
int res = this->fhandler_base::dup (child);
|
|
if (res)
|
|
return res;
|
|
|
|
fhandler_pipe *ftp = (fhandler_pipe *) child;
|
|
|
|
if (guard == NULL)
|
|
ftp->guard = NULL;
|
|
else if (!DuplicateHandle (hMainProc, guard, hMainProc, &ftp->guard, 0, 1,
|
|
DUPLICATE_SAME_ACCESS))
|
|
{
|
|
debug_printf ("couldn't duplicate guard %p, %E", guard);
|
|
return -1;
|
|
}
|
|
|
|
if (writepipe_exists == NULL)
|
|
ftp->writepipe_exists = NULL;
|
|
else if (!DuplicateHandle (hMainProc, writepipe_exists, hMainProc,
|
|
&ftp->writepipe_exists, 0, 1,
|
|
DUPLICATE_SAME_ACCESS))
|
|
{
|
|
debug_printf ("couldn't duplicate writepipe_exists %p, %E", writepipe_exists);
|
|
return -1;
|
|
}
|
|
|
|
ftp->id = id;
|
|
ftp->orig_pid = orig_pid;
|
|
return 0;
|
|
}
|
|
|
|
|
|
int
|
|
make_pipe (int fildes[2], unsigned int psize, int mode)
|
|
{
|
|
HANDLE r, w;
|
|
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
|
|
int res = -1;
|
|
|
|
cygheap_fdnew fdr;
|
|
if (fdr >= 0)
|
|
{
|
|
cygheap_fdnew fdw (fdr, false);
|
|
if (fdw < 0)
|
|
/* out of fds? */;
|
|
else if (!CreatePipe (&r, &w, sa, psize))
|
|
__seterrno ();
|
|
else
|
|
{
|
|
fhandler_pipe *fhr = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
|
|
fhandler_pipe *fhw = (fhandler_pipe *) cygheap->fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
|
|
|
|
int binmode = mode & O_TEXT ? 0 : 1;
|
|
fhr->init (r, GENERIC_READ, binmode);
|
|
fhw->init (w, GENERIC_WRITE, binmode);
|
|
if (mode & O_NOINHERIT)
|
|
{
|
|
fhr->set_close_on_exec_flag (1);
|
|
fhw->set_close_on_exec_flag (1);
|
|
}
|
|
|
|
fildes[0] = fdr;
|
|
fildes[1] = fdw;
|
|
|
|
res = 0;
|
|
fhr->create_guard (sa);
|
|
if (wincap.has_unreliable_pipes ())
|
|
{
|
|
char buf[80];
|
|
int count = pipecount++; /* FIXME: Should this be InterlockedIncrement? */
|
|
__small_sprintf (buf, pipeid_fmt, myself->pid, count);
|
|
fhw->writepipe_exists = CreateEvent (sa, TRUE, FALSE, buf);
|
|
fhr->orig_pid = myself->pid;
|
|
fhr->id = count;
|
|
}
|
|
}
|
|
}
|
|
|
|
syscall_printf ("%d = make_pipe ([%d, %d], %d, %p)", res, fildes[0],
|
|
fildes[1], psize, mode);
|
|
return res;
|
|
}
|
|
|
|
extern "C" int
|
|
pipe (int filedes[2])
|
|
{
|
|
extern DWORD binmode;
|
|
return make_pipe (filedes, 16384, (!binmode || binmode == O_BINARY) ? O_BINARY : O_TEXT);
|
|
}
|
|
|
|
extern "C" int
|
|
_pipe (int filedes[2], unsigned int psize, int mode)
|
|
{
|
|
int res = make_pipe (filedes, psize, mode);
|
|
/* This type of pipe is not interruptible so set the appropriate flag. */
|
|
if (!res)
|
|
cygheap->fdtab[filedes[0]]->set_r_no_interrupt (1);
|
|
return res;
|
|
}
|