Change _function() to function() throughout.

* cygwin.din: Remove last vestiges (?) of newlib wrappers.
* cygthread.cc (cygthread::detach): Always wait for event or suffer an
apparently inavoidable race.
* dcrt0.cc (dll_crt0_1): Allocate threads after stack has been relocated.
* debub.cc (lock_debug): Don't acquire lock on exit.
* fork.cc (fork_child): Recreate mmaps before doing anything else since Windows
has a habit of using blocks of memory in the child that could previously have
been occupied by shared memory in the parent.
* mmap.cc (fhandler_disk_file::fixup_mmap_after_fork): Issue error here and
provide some details about what went wrong.
(fixup_mmaps_after_fork): Remove error message.
* shared.cc (open_shared): Move warning message so that more detail is
possible.
* sigproc.cc (sigproc_init): Initialize sync_proc_subproc to avoid a race.
(sigproc_terminate): Specifically wait for process thread to terminate.
This commit is contained in:
Christopher Faylor 2002-10-21 01:00:58 +00:00
parent ccefaab1d5
commit 5ec14fe40a
17 changed files with 164 additions and 126 deletions

View File

@ -1,3 +1,27 @@
2002-10-20 Christopher Faylor <cgf@redhat.com>
Change _function() to function() throughout.
* cygwin.din: Remove last vestiges (?) of newlib wrappers.
2002-10-20 Christopher Faylor <cgf@redhat.com>
* cygthread.cc (cygthread::detach): Always wait for event or suffer an
apparently inavoidable race.
* dcrt0.cc (dll_crt0_1): Allocate threads after stack has been
relocated.
* debub.cc (lock_debug): Don't acquire lock on exit.
* fork.cc (fork_child): Recreate mmaps before doing anything else since
Windows has a habit of using blocks of memory in the child that could
previously have been occupied by shared memory in the parent.
* mmap.cc (fhandler_disk_file::fixup_mmap_after_fork): Issue error here
and provide some details about what went wrong.
(fixup_mmaps_after_fork): Remove error message.
* shared.cc (open_shared): Move warning message so that more detail is
possible.
* sigproc.cc (sigproc_init): Initialize sync_proc_subproc to avoid a
race.
(sigproc_terminate): Specifically wait for process thread to terminate.
2002-10-20 Christopher Faylor <cgf@redhat.com> 2002-10-20 Christopher Faylor <cgf@redhat.com>
* cygthread.cc (cygthread::stub): Fix typo. * cygthread.cc (cygthread::stub): Fix typo.
@ -73,7 +97,7 @@
unneeded SEGV's during debugging. unneeded SEGV's during debugging.
2002-10-17 Thomas Pfaff <tpfaff@gmx.net> 2002-10-17 Thomas Pfaff <tpfaff@gmx.net>
* thread.cc (verifyable_object_isvalid): Test for static object first. * thread.cc (verifyable_object_isvalid): Test for static object first.
2002-10-16 Christopher Faylor <cgf@redhat.com> 2002-10-16 Christopher Faylor <cgf@redhat.com>

View File

@ -64,7 +64,6 @@ cygthread::stub (VOID *arg)
switch (WaitForSingleObject (info->thread_sync, INFINITE)) switch (WaitForSingleObject (info->thread_sync, INFINITE))
{ {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
// ResetEvent (info->thread_sync);
continue; continue;
default: default:
api_fatal ("WFSO failed, %E"); api_fatal ("WFSO failed, %E");
@ -204,10 +203,10 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, LPVOID param,
__name = name; /* Need to set after thread has woken up to __name = name; /* Need to set after thread has woken up to
ensure that it won't be cleared by exiting ensure that it won't be cleared by exiting
thread. */ thread. */
if (thread_sync) if (!thread_sync)
SetEvent (thread_sync);
else
ResumeThread (h); ResumeThread (h);
else
SetEvent (thread_sync);
} }
/* Return the symbolic name of the current thread for debugging. /* Return the symbolic name of the current thread for debugging.
@ -269,15 +268,9 @@ cygthread::detach ()
else else
{ {
DWORD avail = id; DWORD avail = id;
/* Checking for __name here is just a minor optimization to avoid DWORD res = WaitForSingleObject (*this, INFINITE);
an OS call. */ thread_printf ("WFSO returns %d, id %p", res, id);
if (!__name)
thread_printf ("thread id %p returned. No need to wait.", id);
else
{
DWORD res = WaitForSingleObject (*this, INFINITE);
thread_printf ("WFSO returns %d, id %p", res, id);
}
if (is_freerange) if (is_freerange)
{ {
CloseHandle (h); CloseHandle (h);
@ -285,9 +278,8 @@ cygthread::detach ()
} }
else else
{ {
ResetEvent (*this);
id = 0; id = 0;
__name = NULL; ResetEvent (*this);
/* Mark the thread as available by setting avail to non-zero */ /* Mark the thread as available by setting avail to non-zero */
(void) InterlockedExchange ((LPLONG) &this->avail, avail); (void) InterlockedExchange ((LPLONG) &this->avail, avail);
} }

View File

@ -110,8 +110,8 @@ clearerr
_clearerr = clearerr _clearerr = clearerr
clock clock
_clock = clock _clock = clock
_close close
close = _close _close = close
closedir closedir
_closedir = closedir _closedir = closedir
copysign copysign
@ -217,8 +217,8 @@ fcloseall
_fcloseall = fcloseall _fcloseall = fcloseall
_fcloseall_r _fcloseall_r
fcloseall_r = _fcloseall_r fcloseall_r = _fcloseall_r
_fcntl fcntl
fcntl = _fcntl _fcntl = fcntl
fcvt fcvt
_fcvt = fcvt _fcvt = fcvt
fcvtbuf fcvtbuf
@ -534,8 +534,8 @@ login
logout logout
longjmp longjmp
_longjmp = longjmp _longjmp = longjmp
_lseek lseek
lseek = _lseek _lseek = lseek
lseek64 lseek64
lstat = cygwin_lstat lstat = cygwin_lstat
_lstat = cygwin_lstat _lstat = cygwin_lstat
@ -593,8 +593,8 @@ nextafter
_nextafter = nextafter _nextafter = nextafter
nextafterf nextafterf
_nextafterf = nextafterf _nextafterf = nextafterf
_open open
open = _open _open = open
opendir opendir
_opendir = opendir _opendir = opendir
pathconf pathconf
@ -632,8 +632,8 @@ _rand = rand
random random
initstate initstate
setstate setstate
_read read
read = _read _read = read
readdir readdir
_readdir = readdir _readdir = readdir
readlink readlink
@ -652,8 +652,8 @@ remainderf
_remainderf = remainderf _remainderf = remainderf
remove remove
_remove = remove _remove = remove
_rename rename
rename = _rename _rename = rename
rewind rewind
_rewind = rewind _rewind = rewind
rewinddir rewinddir
@ -893,8 +893,8 @@ tempnam
_tempnam = tempnam _tempnam = tempnam
time time
_time = time _time = time
_times times
times = _times _times = times
timezone timezone
tmpfile tmpfile
_tmpfile = tmpfile _tmpfile = tmpfile
@ -921,8 +921,8 @@ uname
_uname = uname _uname = uname
ungetc ungetc
_ungetc = ungetc _ungetc = ungetc
_unlink unlink
unlink = _unlink _unlink = unlink
usleep usleep
_usleep = usleep _usleep = usleep
utime utime
@ -956,8 +956,8 @@ vsscanf
_vsscanf = vsscanf _vsscanf = vsscanf
_vsscanf_r _vsscanf_r
vsscanf_r = _vsscanf_r vsscanf_r = _vsscanf_r
_wait wait
wait = _wait _wait = wait
waitpid waitpid
_waitpid = waitpid _waitpid = waitpid
wait3 wait3
@ -966,8 +966,8 @@ wcstombs
_wcstombs = wcstombs _wcstombs = wcstombs
wctomb wctomb
_wctomb = wctomb _wctomb = wctomb
_write write
write = _write _write = write
writev writev
_writev = writev _writev = writev
y0 y0

View File

@ -574,8 +574,8 @@ dll_crt0_1 ()
if (!child_proc_info) if (!child_proc_info)
{ {
memory_init ();
cygthread::init (); cygthread::init ();
memory_init ();
} }
else else
{ {
@ -584,8 +584,9 @@ dll_crt0_1 ()
switch (child_proc_info->type) switch (child_proc_info->type)
{ {
case _PROC_FORK: case _PROC_FORK:
cygheap_fixup_in_child (0);
alloc_stack (fork_info); alloc_stack (fork_info);
cygthread::init ();
cygheap_fixup_in_child (0);
close_ppid_handle = !!child_proc_info->pppid_handle; close_ppid_handle = !!child_proc_info->pppid_handle;
memory_init (); memory_init ();
set_myself (mypid); set_myself (mypid);
@ -599,6 +600,7 @@ dll_crt0_1 ()
hexec_proc = spawn_info->hexec_proc; hexec_proc = spawn_info->hexec_proc;
around: around:
HANDLE h; HANDLE h;
cygthread::init ();
cygheap_fixup_in_child (1); cygheap_fixup_in_child (1);
memory_init (); memory_init ();
if (!spawn_info->moreinfo->myself_pinfo || if (!spawn_info->moreinfo->myself_pinfo ||
@ -619,7 +621,7 @@ dll_crt0_1 ()
old_title = strcpy (title_buf, spawn_info->moreinfo->old_title); old_title = strcpy (title_buf, spawn_info->moreinfo->old_title);
cfree (spawn_info->moreinfo->old_title); cfree (spawn_info->moreinfo->old_title);
} }
cygthread::init (); // cygthread::init ();
break; break;
} }
if (close_hexec_proc) if (close_hexec_proc)

View File

@ -37,7 +37,8 @@ class lock_debug
public: public:
lock_debug () : acquired (0) lock_debug () : acquired (0)
{ {
if (locker) extern int exit_state;
if (locker && !exit_state)
acquired = !!locker->acquire (INFINITE); acquired = !!locker->acquire (INFINITE);
} }
void unlock () void unlock ()

View File

@ -476,7 +476,7 @@ dtable::dup2 (int oldfd, int newfd)
newfh->get_io_handle (), fds[oldfd]->get_io_handle ()); newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
if (!not_open (newfd)) if (!not_open (newfd))
_close (newfd); close (newfd);
else if ((size_t) newfd < size) else if ((size_t) newfd < size)
/* nothing to do */; /* nothing to do */;
else if (find_unused_handle (newfd) < 0) else if (find_unused_handle (newfd) < 0)

View File

@ -8,6 +8,7 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */ details. */
#define _execve __FOO_execve_
#include "winsup.h" #include "winsup.h"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -20,12 +21,13 @@ details. */
#include "pinfo.h" #include "pinfo.h"
#include "environ.h" #include "environ.h"
#include "cygerrno.h" #include "cygerrno.h"
#undef _execve
/* This is called _execve and not execve because the real execve is defined /* This is called _execve and not execve because the real execve is defined
in libc/posix/execve.c. It calls us. */ in libc/posix/execve.c. It calls us. */
extern "C" int extern "C" int
_execve (const char *path, char *const argv[], char *const envp[]) execve (const char *path, char *const argv[], char *const envp[])
{ {
static char *const empty_env[] = { 0 }; static char *const empty_env[] = { 0 };
MALLOC_CHECK; MALLOC_CHECK;
@ -34,6 +36,9 @@ _execve (const char *path, char *const argv[], char *const envp[])
return spawnve (_P_OVERLAY, path, argv, envp); return spawnve (_P_OVERLAY, path, argv, envp);
} }
extern "C" int _execve (const char *, char *const [], char *const [])
__attribute__ ((alias ("execve")));
extern "C" int extern "C" int
execl (const char *path, const char *arg0, ...) execl (const char *path, const char *arg0, ...)
{ {
@ -49,14 +54,14 @@ execl (const char *path, const char *arg0, ...)
while (argv[i++] != NULL); while (argv[i++] != NULL);
va_end (args); va_end (args);
MALLOC_CHECK; MALLOC_CHECK;
return _execve (path, (char * const *) argv, cur_environ ()); return execve (path, (char * const *) argv, cur_environ ());
} }
extern "C" int extern "C" int
execv (const char *path, char * const *argv) execv (const char *path, char * const *argv)
{ {
MALLOC_CHECK; MALLOC_CHECK;
return _execve (path, (char * const *) argv, cur_environ ()); return execve (path, (char * const *) argv, cur_environ ());
} }
extern "C" pid_t extern "C" pid_t

View File

@ -20,7 +20,6 @@
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#define USE_SYS_TYPES_FD_SET #define USE_SYS_TYPES_FD_SET
#include <winsock2.h> #include <winsock2.h>
#include "cygerrno.h" #include "cygerrno.h"
@ -33,6 +32,7 @@
#include "cygheap.h" #include "cygheap.h"
#include "sigproc.h" #include "sigproc.h"
#include "wsock_event.h" #include "wsock_event.h"
#include <unistd.h>
#define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x" #define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x"
#define ENTROPY_SOURCE_NAME "/dev/urandom" #define ENTROPY_SOURCE_NAME "/dev/urandom"
@ -61,7 +61,7 @@ get_inet_addr (const struct sockaddr *in, int inlen,
} }
else if (in->sa_family == AF_LOCAL) else if (in->sa_family == AF_LOCAL)
{ {
int fd = _open (in->sa_data, O_RDONLY); int fd = open (in->sa_data, O_RDONLY);
if (fd == -1) if (fd == -1)
return 0; return 0;
@ -81,7 +81,7 @@ get_inet_addr (const struct sockaddr *in, int inlen,
*outlen = sizeof sin; *outlen = sizeof sin;
ret = 1; ret = 1;
} }
_close (fd); close (fd);
return ret; return ret;
} }
else else
@ -354,9 +354,7 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
/* bind must fail if file system socket object already exists /* bind must fail if file system socket object already exists
so _open () is called with O_EXCL flag. */ so _open () is called with O_EXCL flag. */
fd = _open (un_addr->sun_path, fd = ::open (un_addr->sun_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0);
O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
0);
if (fd < 0) if (fd < 0)
{ {
if (get_errno () == EEXIST) if (get_errno () == EEXIST)
@ -372,17 +370,17 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
len = strlen (buf) + 1; len = strlen (buf) + 1;
/* Note that the terminating nul is written. */ /* Note that the terminating nul is written. */
if (_write (fd, buf, len) != len) if (::write (fd, buf, len) != len)
{ {
save_errno here; save_errno here;
_close (fd); ::close (fd);
_unlink (un_addr->sun_path); unlink (un_addr->sun_path);
} }
else else
{ {
_close (fd); ::close (fd);
chmod (un_addr->sun_path, chmod (un_addr->sun_path,
(S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask); (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask);
set_sun_path (un_addr->sun_path); set_sun_path (un_addr->sun_path);
res = 0; res = 0;
} }

View File

@ -278,12 +278,12 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
MALLOC_CHECK; MALLOC_CHECK;
cygheap->fdtab.fixup_after_fork (hParent);
ProtectHandleINH (hParent);
if (fixup_mmaps_after_fork (hParent)) if (fixup_mmaps_after_fork (hParent))
api_fatal ("recreate_mmaps_after_fork_failed"); api_fatal ("recreate_mmaps_after_fork_failed");
cygheap->fdtab.fixup_after_fork (hParent);
ProtectHandleINH (hParent);
MALLOC_CHECK; MALLOC_CHECK;
/* If we haven't dynamically loaded any dlls, just signal /* If we haven't dynamically loaded any dlls, just signal
@ -305,7 +305,6 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
if (fixup_shms_after_fork ()) if (fixup_shms_after_fork ())
api_fatal ("recreate_shm areas after fork failed"); api_fatal ("recreate_shm areas after fork failed");
cygthread::init ();
pinfo_fixup_after_fork (); pinfo_fixup_after_fork ();
signal_fixup_after_fork (); signal_fixup_after_fork ();
@ -316,8 +315,8 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
if ((*t)->clear_on_fork ()) if ((*t)->clear_on_fork ())
(*t)->set (); (*t)->set ();
wait_for_sigthread ();
pthread::atforkchild (); pthread::atforkchild ();
wait_for_sigthread ();
cygbench ("fork-child"); cygbench ("fork-child");
return 0; return 0;
} }

View File

@ -86,7 +86,7 @@ heap_init ()
/* FIXME: This function no longer handles "split heaps". */ /* FIXME: This function no longer handles "split heaps". */
extern "C" void * extern "C" void *
_sbrk (int n) sbrk (int n)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
char *newtop, *newbrk; char *newtop, *newbrk;

View File

@ -1,6 +1,6 @@
/* version.h -- Cygwin version numbers and accompanying documentation. /* version.h -- Cygwin version numbers and accompanying documentation.
Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.

View File

@ -868,6 +868,13 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset,
{ {
/* Re-create the MapViewOfFileEx call */ /* Re-create the MapViewOfFileEx call */
void *base = MapViewOfFileEx (h, access, 0, offset, size, address); void *base = MapViewOfFileEx (h, access, 0, offset, size, address);
if (base != address)
{
MEMORY_BASIC_INFORMATION m;
(void) VirtualQuery (address, &m, sizeof (m));
system_printf ("requested %p != %p mem alloc base %p, state %p, size %d, %E",
address, base, m.AllocationBase, m.State, m.RegionSize);
}
return base == address; return base == address;
} }
@ -961,11 +968,7 @@ fixup_mmaps_after_fork (HANDLE parent)
rec->free_fh (fh); rec->free_fh (fh);
if (!ret) if (!ret)
{ return -1;
system_printf ("base address fails to match requested address %p",
rec->get_address ());
return -1;
}
if (rec->get_access () == FILE_MAP_COPY) if (rec->get_access () == FILE_MAP_COPY)
{ {
for (char *address = rec->get_address (); for (char *address = rec->get_address ();

View File

@ -104,14 +104,14 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locat
if (!shared) if (!shared)
{ {
#ifdef DEBUGGING
if (wincap.is_winnt ())
system_printf ("relocating shared object %s(%d) on Windows NT", name, n);
#endif
/* Probably win95, so try without specifying the address. */ /* Probably win95, so try without specifying the address. */
shared = (shared_info *) MapViewOfFileEx (shared_h, shared = (shared_info *) MapViewOfFileEx (shared_h,
FILE_MAP_READ|FILE_MAP_WRITE, FILE_MAP_READ|FILE_MAP_WRITE,
0, 0, 0, 0); 0, 0, 0, 0);
#ifdef DEBUGGING
if (wincap.is_winnt ())
system_printf ("relocating shared object %s(%d) from %p to %p on Windows NT", name, n, addr, shared);
#endif
} }
if (!shared) if (!shared)

View File

@ -472,6 +472,7 @@ proc_terminate (void)
ForceCloseHandle1 (zombies[i]->hProcess, childhProc); ForceCloseHandle1 (zombies[i]->hProcess, childhProc);
ForceCloseHandle1 (zombies[i]->pid_handle, pid_handle); ForceCloseHandle1 (zombies[i]->pid_handle, pid_handle);
} }
zombies[i]->ppid = 1;
zombies[i]->process_state = PID_EXITED; /* CGF FIXME - still needed? */ zombies[i]->process_state = PID_EXITED; /* CGF FIXME - still needed? */
zombies[i].release (); // FIXME: this breaks older gccs for some reason zombies[i].release (); // FIXME: this breaks older gccs for some reason
} }
@ -561,6 +562,11 @@ sigproc_init ()
wait_sig_inited = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); wait_sig_inited = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
ProtectHandle (wait_sig_inited); ProtectHandle (wait_sig_inited);
/* sync_proc_subproc is used by proc_subproc. It serialises
* access to the children and zombie arrays.
*/
new_muto (sync_proc_subproc);
/* local event signaled when main thread has been dispatched /* local event signaled when main thread has been dispatched
to a signal handler function. */ to a signal handler function. */
signal_arrived = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); signal_arrived = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
@ -569,11 +575,6 @@ sigproc_init ()
hwait_sig = new cygthread (wait_sig, cygself, "sig"); hwait_sig = new cygthread (wait_sig, cygself, "sig");
hwait_sig->zap_h (); hwait_sig->zap_h ();
/* sync_proc_subproc is used by proc_subproc. It serialises
* access to the children and zombie arrays.
*/
new_muto (sync_proc_subproc);
/* Initialize waitq structure for main thread. A waitq structure is /* Initialize waitq structure for main thread. A waitq structure is
* allocated for each thread that executes a wait to allow multiple threads * allocated for each thread that executes a wait to allow multiple threads
* to perform waits. Pre-allocate a waitq structure for the main thread. * to perform waits. Pre-allocate a waitq structure for the main thread.
@ -598,6 +599,16 @@ sigproc_terminate (void)
{ {
hwait_sig = NULL; hwait_sig = NULL;
if (!sig_loop_wait)
sigproc_printf ("sigproc_terminate: sigproc handling not active");
else
{
sigproc_printf ("entering");
sig_loop_wait = 0; // Tell wait_sig to exit when it is
// finished with anything it is doing
sig_dispatch_pending (1);
}
if (GetCurrentThreadId () == sigtid) if (GetCurrentThreadId () == sigtid)
{ {
ForceCloseHandle (sigcomplete_main); ForceCloseHandle (sigcomplete_main);
@ -610,22 +621,6 @@ sigproc_terminate (void)
} }
proc_terminate (); // Terminate process handling thread proc_terminate (); // Terminate process handling thread
if (!sig_loop_wait)
sigproc_printf ("sigproc_terminate: sigproc handling not active");
else
{
sigproc_printf ("entering");
sig_loop_wait = 0; // Tell wait_sig to exit when it is
// finished with anything it is doing
sigproc_printf ("done");
}
#if 0
/* Set this so that subsequent tests will succeed. */
if (!myself->dwProcessId)
myself->dwProcessId = GetCurrentProcessId ();
#endif
return; return;
} }

View File

@ -8,6 +8,12 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */ details. */
#define _close __FOO_close__
#define _lseek __FOO_lseek__
#define _open __FOO_open__
#define _read __FOO_read__
#define _write __FOO_write__
#include "winsup.h" #include "winsup.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/vfs.h> /* needed for statfs */ #include <sys/vfs.h> /* needed for statfs */
@ -40,6 +46,12 @@ details. */
#include <setjmp.h> #include <setjmp.h>
#include "perthread.h" #include "perthread.h"
#undef _close
#undef _lseek
#undef _open
#undef _read
#undef _write
SYSTEM_INFO system_info; SYSTEM_INFO system_info;
/* Close all files and process any queued deletions. /* Close all files and process any queued deletions.
@ -94,7 +106,7 @@ dup2 (int oldfd, int newfd)
} }
extern "C" int extern "C" int
_unlink (const char *ourname) unlink (const char *ourname)
{ {
int res = -1; int res = -1;
DWORD devn; DWORD devn;
@ -248,7 +260,7 @@ remove (const char *ourname)
return -1; return -1;
} }
return win32_name.isdir () ? rmdir (ourname) : _unlink (ourname); return win32_name.isdir () ? rmdir (ourname) : unlink (ourname);
} }
extern "C" pid_t extern "C" pid_t
@ -325,7 +337,7 @@ getsid (pid_t pid)
} }
extern "C" ssize_t extern "C" ssize_t
_read (int fd, void *ptr, size_t len) read (int fd, void *ptr, size_t len)
{ {
const struct iovec iov = const struct iovec iov =
{ {
@ -336,8 +348,11 @@ _read (int fd, void *ptr, size_t len)
return readv (fd, &iov, 1); return readv (fd, &iov, 1);
} }
extern "C" ssize_t _read (int, void *, size_t)
__attribute__ ((alias ("read")));
extern "C" ssize_t extern "C" ssize_t
_write (int fd, const void *ptr, size_t len) write (int fd, const void *ptr, size_t len)
{ {
const struct iovec iov = const struct iovec iov =
{ {
@ -348,6 +363,9 @@ _write (int fd, const void *ptr, size_t len)
return writev (fd, &iov, 1); return writev (fd, &iov, 1);
} }
extern "C" ssize_t _write (int fd, const void *ptr, size_t len)
__attribute__ ((alias ("write")));
extern "C" ssize_t extern "C" ssize_t
readv (int fd, const struct iovec *const iov, const int iovcnt) readv (int fd, const struct iovec *const iov, const int iovcnt)
{ {
@ -487,7 +505,7 @@ done:
/* newlib's fcntl.h defines _open as taking variable args so we must /* newlib's fcntl.h defines _open as taking variable args so we must
correspond. The third arg if it exists is: mode_t mode. */ correspond. The third arg if it exists is: mode_t mode. */
extern "C" int extern "C" int
_open (const char *unix_path, int flags, ...) open (const char *unix_path, int flags, ...)
{ {
int res = -1; int res = -1;
va_list ap; va_list ap;
@ -525,6 +543,9 @@ _open (const char *unix_path, int flags, ...)
return res; return res;
} }
extern "C" int _open (const char *, int flags, ...)
__attribute__ ((alias ("open")));
extern "C" __off64_t extern "C" __off64_t
lseek64 (int fd, __off64_t pos, int dir) lseek64 (int fd, __off64_t pos, int dir)
{ {
@ -550,13 +571,16 @@ lseek64 (int fd, __off64_t pos, int dir)
} }
extern "C" __off32_t extern "C" __off32_t
_lseek (int fd, __off32_t pos, int dir) lseek (int fd, __off32_t pos, int dir)
{ {
return lseek64 (fd, (__off64_t) pos, dir); return lseek64 (fd, (__off64_t) pos, dir);
} }
extern "C" __off32_t _lseek (int, __off32_t, int)
__attribute__ ((alias ("lseek")));
extern "C" int extern "C" int
_close (int fd) close (int fd)
{ {
int res; int res;
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
@ -578,6 +602,8 @@ _close (int fd)
return res; return res;
} }
extern "C" int _close (int) __attribute__ ((alias ("close")));
extern "C" int extern "C" int
isatty (int fd) isatty (int fd)
{ {
@ -601,7 +627,7 @@ isatty (int fd)
*/ */
extern "C" int extern "C" int
_link (const char *a, const char *b) link (const char *a, const char *b)
{ {
int res = -1; int res = -1;
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
@ -1231,7 +1257,7 @@ done:
} }
extern "C" int extern "C" int
_rename (const char *oldpath, const char *newpath) rename (const char *oldpath, const char *newpath)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
int res = 0; int res = 0;
@ -2490,16 +2516,16 @@ setutent ()
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
if (utmp_fd == -2) if (utmp_fd == -2)
{ {
utmp_fd = _open (utmp_file, O_RDONLY); utmp_fd = open (utmp_file, O_RDONLY);
} }
_lseek (utmp_fd, 0, SEEK_SET); lseek (utmp_fd, 0, SEEK_SET);
} }
extern "C" void extern "C" void
endutent () endutent ()
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
_close (utmp_fd); close (utmp_fd);
utmp_fd = -2; utmp_fd = -2;
} }
@ -2522,7 +2548,7 @@ getutent ()
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
if (utmp_fd == -2) if (utmp_fd == -2)
setutent (); setutent ();
if (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) != sizeof (utmp_data)) if (read (utmp_fd, &utmp_data, sizeof (utmp_data)) != sizeof (utmp_data))
return NULL; return NULL;
return &utmp_data; return &utmp_data;
} }
@ -2533,7 +2559,7 @@ getutid (struct utmp *id)
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
if (check_null_invalid_struct_errno (id)) if (check_null_invalid_struct_errno (id))
return NULL; return NULL;
while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data)) while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
{ {
switch (id->ut_type) switch (id->ut_type)
{ {
@ -2566,7 +2592,7 @@ getutline (struct utmp *line)
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
if (check_null_invalid_struct_errno (line)) if (check_null_invalid_struct_errno (line))
return NULL; return NULL;
while (_read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data)) while (read (utmp_fd, &utmp_data, sizeof (utmp_data)) == sizeof (utmp_data))
{ {
if ((utmp_data.ut_type == LOGIN_PROCESS || if ((utmp_data.ut_type == LOGIN_PROCESS ||
utmp_data.ut_type == USER_PROCESS) && utmp_data.ut_type == USER_PROCESS) &&

View File

@ -46,7 +46,7 @@ __to_clock_t (FILETIME * src, int flag)
/* times: POSIX 4.5.2.1 */ /* times: POSIX 4.5.2.1 */
extern "C" clock_t extern "C" clock_t
_times (struct tms * buf) times (struct tms *buf)
{ {
FILETIME creation_time, exit_time, kernel_time, user_time; FILETIME creation_time, exit_time, kernel_time, user_time;
@ -86,6 +86,8 @@ _times (struct tms * buf)
return tc; return tc;
} }
extern "C" clock_t _times (struct tms *) __attribute__((alias ("times")));
/* settimeofday: BSD */ /* settimeofday: BSD */
extern "C" int extern "C" int
settimeofday (const struct timeval *tv, const struct timezone *tz) settimeofday (const struct timeval *tv, const struct timezone *tz)
@ -168,11 +170,8 @@ gettimeofday (struct timeval *tv, struct timezone *tz)
return 0; return 0;
} }
extern "C" int extern "C" int _gettimeofday (struct timeval *, struct timezone *)
_gettimeofday (struct timeval *p, struct timezone *z) __attribute__((alias ("gettimeofday")));
{
return gettimeofday (p, z);
}
/* Cygwin internal */ /* Cygwin internal */
void void
@ -266,8 +265,7 @@ time_as_timestruc_t (timestruc_t * out)
/* time: POSIX 4.5.1.1, C 4.12.2.4 */ /* time: POSIX 4.5.1.1, C 4.12.2.4 */
/* Return number of seconds since 00:00 UTC on jan 1, 1970 */ /* Return number of seconds since 00:00 UTC on jan 1, 1970 */
extern "C" extern "C" time_t
time_t
time (time_t * ptr) time (time_t * ptr)
{ {
time_t res; time_t res;
@ -409,8 +407,7 @@ corelocaltime (const time_t * tim_p)
* localtime takes a time_t (which is in UTC) * localtime takes a time_t (which is in UTC)
* and formats it into a struct tm as a local time. * and formats it into a struct tm as a local time.
*/ */
extern "C" extern "C" struct tm *
struct tm *
localtime (const time_t *tim_p) localtime (const time_t *tim_p)
{ {
time_t tim = *tim_p; time_t tim = *tim_p;
@ -434,8 +431,7 @@ localtime (const time_t *tim_p)
* gmtime takes a time_t (which is already in UTC) * gmtime takes a time_t (which is already in UTC)
* and just puts it into a struct tm. * and just puts it into a struct tm.
*/ */
extern "C" extern "C" struct tm *
struct tm *
gmtime (const time_t *tim_p) gmtime (const time_t *tim_p)
{ {
time_t tim = *tim_p; time_t tim = *tim_p;
@ -452,8 +448,7 @@ gmtime (const time_t *tim_p)
#endif /* POSIX_LOCALTIME */ #endif /* POSIX_LOCALTIME */
/* utimes: standards? */ /* utimes: standards? */
extern "C" extern "C" int
int
utimes (const char *path, struct timeval *tvp) utimes (const char *path, struct timeval *tvp)
{ {
int res = 0; int res = 0;
@ -532,8 +527,7 @@ utimes (const char *path, struct timeval *tvp)
} }
/* utime: POSIX 5.6.6.1 */ /* utime: POSIX 5.6.6.1 */
extern "C" extern "C" int
int
utime (const char *path, struct utimbuf *buf) utime (const char *path, struct utimbuf *buf)
{ {
struct timeval tmp[2]; struct timeval tmp[2];
@ -549,8 +543,7 @@ utime (const char *path, struct utimbuf *buf)
} }
/* ftime: standards? */ /* ftime: standards? */
extern "C" extern "C" int
int
ftime (struct timeb *tp) ftime (struct timeb *tp)
{ {
struct timeval tv; struct timeval tv;

View File

@ -21,7 +21,7 @@ details. */
extern "C" extern "C"
pid_t pid_t
_wait (int *status) wait (int *status)
{ {
return wait4 (-1, status, 0, NULL); return wait4 (-1, status, 0, NULL);
} }