* mmap.cc: Clean up *ResourceLock calls throughout.

* thread.cc (pthread_cond::TimedWait): Check for WAIT_TIMEOUT as well as
WAIT_ABANDONED.
(__pthread_cond_timedwait): Calculate a relative wait from the abstime
parameter.
This commit is contained in:
Christopher Faylor 2001-06-26 14:47:48 +00:00
parent d006404dae
commit 462f4effb1
15 changed files with 473 additions and 449 deletions

View File

@ -1,3 +1,14 @@
Tue Jun 26 10:47:24 2001 Christopher Faylor <cgf@cygnus.com>
* mmap.cc: Clean up *ResourceLock calls throughout.
Tue Jun 26 22:10:00 2001 Robert Collins rbtcollins@hotmail.com
* thread.cc (pthread_cond::TimedWait): Check for WAIT_TIMEOUT as well
as WAIT_ABANDONED.
(__pthread_cond_timedwait): Calculate a relative wait from the abstime
parameter.
Sun Jun 24 17:38:19 2001 Christopher Faylor <cgf@cygnus.com> Sun Jun 24 17:38:19 2001 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (interrupt_setup): Move actions from setup_handler to * exceptions.cc (interrupt_setup): Move actions from setup_handler to
@ -29,7 +40,7 @@ Thu Jun 21 22:01:39 2001 Marius Gedminas <mgedmin@delfi.lt>
2001-06-22 Robert Collins <rbbtcollins@hotmail.com> 2001-06-22 Robert Collins <rbbtcollins@hotmail.com>
* thread.cc (__pthread_cond_timedwait): Lock the waiting mutex before * thread.cc (__pthread_cond_timedwait): Lock the waiting mutex before
the condition protect mutex to avoid deadlocking. (Found by Greg Smith). the condition protect mutex to avoid deadlocking. (Found by Greg Smith).
(__pthread_cond_wait): Ditto. (__pthread_cond_wait): Ditto.

View File

@ -68,7 +68,6 @@ public:
return 1; return 1;
return strncasematch (m->native_path, path, m->native_pathlen) return strncasematch (m->native_path, path, m->native_pathlen)
&& (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]); && (path[m->native_pathlen] == '\\' || !path[m->native_pathlen]);
} }
const char *unchroot (const char *path) const char *unchroot (const char *path)
{ {

View File

@ -28,6 +28,13 @@
* malloc_usable_size(P) is equivalent to realloc(P, malloc_usable_size(P)) * malloc_usable_size(P) is equivalent to realloc(P, malloc_usable_size(P))
* *
* $Log$ * $Log$
* Revision 1.3 2001/06/26 14:47:48 cgf
* * mmap.cc: Clean up *ResourceLock calls throughout.
* * thread.cc (pthread_cond::TimedWait): Check for WAIT_TIMEOUT as well as
* WAIT_ABANDONED.
* (__pthread_cond_timedwait): Calculate a relative wait from the abstime
* parameter.
*
* Revision 1.2 2001/06/24 22:26:49 cgf * Revision 1.2 2001/06/24 22:26:49 cgf
* forced commit * forced commit
* *
@ -2001,7 +2008,7 @@ static void do_check_chunk(p) mchunkptr p;
if (!chunk_is_mmapped(p)) if (!chunk_is_mmapped(p))
{ {
INTERNAL_SIZE_T sz; INTERNAL_SIZE_T sz;
unless((char*)p >= sbrk_base, "chunk precedes sbrk_base", p); unless((char*)p >= sbrk_base, "chunk precedes sbrk_base", p);
unless((char*)p + MINSIZE <= (char*)top + chunksize(top), unless((char*)p + MINSIZE <= (char*)top + chunksize(top),
"chunk past sbrk area", p); "chunk past sbrk area", p);
@ -2057,7 +2064,7 @@ static void do_check_inuse_chunk(p) mchunkptr p;
{ {
mchunkptr next; mchunkptr next;
do_check_chunk(p); do_check_chunk(p);
if (chunk_is_mmapped(p)) if (chunk_is_mmapped(p))
return; return;
@ -2178,7 +2185,7 @@ static void do_init_freed_chunk(mchunkptr p, INTERNAL_SIZE_T freehead,
p->alloced = 0; p->alloced = 0;
memset((char *)mem - MOATWIDTH, MOATFILL, MOATWIDTH); memset((char *)mem - MOATWIDTH, MOATFILL, MOATWIDTH);
memset((char *)mem + bytes, MOATFILL, MOATWIDTH); memset((char *)mem + bytes, MOATFILL, MOATWIDTH);
/* To avoid terrible O(n^2) performance when free() repeatedly grows a free /* To avoid terrible O(n^2) performance when free() repeatedly grows a free
* chunk, it's important not to free-fill regions that are already * chunk, it's important not to free-fill regions that are already
* free-filled. * free-filled.
@ -2576,7 +2583,7 @@ static void malloc_extend_top(nb) INTERNAL_SIZE_T nb;
} }
#endif /* OTHER_SBRKS */ #endif /* OTHER_SBRKS */
} }
init_freed_chunk(top, old_top == initial_top ? old_top_size : 0, 0); init_freed_chunk(top, old_top == initial_top ? old_top_size : 0, 0);
if ((unsigned long)sbrked_mem > (unsigned long)max_sbrked_mem) if ((unsigned long)sbrked_mem > (unsigned long)max_sbrked_mem)
@ -2699,7 +2706,7 @@ Void_t* mALLOc(bytes) size_t bytes;
check_freefill(victim, victim_size, victim_size); check_freefill(victim, victim_size, victim_size);
init_malloced_chunk(victim, bytes); init_malloced_chunk(victim, bytes);
check_malloced_chunk(victim, nb); check_malloced_chunk(victim, nb);
return chunk2mem(victim); return chunk2mem(victim);
} }
@ -2952,7 +2959,7 @@ void fREe(mem) Void_t* mem;
p = mem2chunk(mem); p = mem2chunk(mem);
check_inuse_chunk(p); check_inuse_chunk(p);
hd = p->size; hd = p->size;
#if HAVE_MMAP #if HAVE_MMAP
@ -3644,7 +3651,7 @@ static void malloc_update_mallinfo(void)
INTERNAL_SIZE_T avail = chunksize(top); INTERNAL_SIZE_T avail = chunksize(top);
int navail = avail >= MINSIZE ? 1 : 0; int navail = avail >= MINSIZE ? 1 : 0;
check_freefill(top, avail, avail); check_freefill(top, avail, avail);
#if DEBUG #if DEBUG
if (lowest_chunk) if (lowest_chunk)
for (p = lowest_chunk; for (p = lowest_chunk;
@ -3652,7 +3659,7 @@ static void malloc_update_mallinfo(void)
p = next_chunk(p)) p = next_chunk(p))
check_inuse_chunk(p); check_inuse_chunk(p);
#endif #endif
for (i = 1; i < NAV; ++i) for (i = 1; i < NAV; ++i)
{ {
b = bin_at(i); b = bin_at(i);
@ -3662,9 +3669,9 @@ static void malloc_update_mallinfo(void)
check_free_chunk(p); check_free_chunk(p);
check_freefill(p, chunksize(p), chunksize(p)); check_freefill(p, chunksize(p), chunksize(p));
for (q = next_chunk(p); for (q = next_chunk(p);
q < top && inuse(q) && chunksize(q) >= MINSIZE; q < top && inuse(q) && chunksize(q) >= MINSIZE;
q = next_chunk(q)) q = next_chunk(q))
check_inuse_chunk(q); check_inuse_chunk(q);
#endif #endif
avail += chunksize(p); avail += chunksize(p);
navail++; navail++;
@ -3701,14 +3708,14 @@ void malloc_stats(void)
{ {
malloc_update_mallinfo(); malloc_update_mallinfo();
fprintf(stderr, "max system bytes = %10u\n", fprintf(stderr, "max system bytes = %10u\n",
(unsigned int)(max_total_mem)); (unsigned int)(max_total_mem));
fprintf(stderr, "system bytes = %10u\n", fprintf(stderr, "system bytes = %10u\n",
(unsigned int)(sbrked_mem + mmapped_mem)); (unsigned int)(sbrked_mem + mmapped_mem));
fprintf(stderr, "in use bytes = %10u\n", fprintf(stderr, "in use bytes = %10u\n",
(unsigned int)(current_mallinfo.uordblks + mmapped_mem)); (unsigned int)(current_mallinfo.uordblks + mmapped_mem));
#if HAVE_MMAP #if HAVE_MMAP
fprintf(stderr, "max mmap regions = %10u\n", fprintf(stderr, "max mmap regions = %10u\n",
(unsigned int)max_n_mmaps); (unsigned int)max_n_mmaps);
#endif #endif
} }
@ -3779,13 +3786,13 @@ History:
* Added anonymously donated WIN32 sbrk emulation * Added anonymously donated WIN32 sbrk emulation
* Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen
* malloc_extend_top: fix mask error that caused wastage after * malloc_extend_top: fix mask error that caused wastage after
foreign sbrks foreign sbrks
* Add linux mremap support code from HJ Liu * Add linux mremap support code from HJ Liu
V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee)
* Integrated most documentation with the code. * Integrated most documentation with the code.
* Add support for mmap, with help from * Add support for mmap, with help from
Wolfram Gloger (Gloger@lrz.uni-muenchen.de). Wolfram Gloger (Gloger@lrz.uni-muenchen.de).
* Use last_remainder in more cases. * Use last_remainder in more cases.
* Pack bins using idea from colin@nyx10.cs.du.edu * Pack bins using idea from colin@nyx10.cs.du.edu
* Use ordered bins instead of best-fit threshhold * Use ordered bins instead of best-fit threshhold
@ -3793,34 +3800,34 @@ History:
* Support another case of realloc via move into top * Support another case of realloc via move into top
* Fix error occuring when initial sbrk_base not word-aligned. * Fix error occuring when initial sbrk_base not word-aligned.
* Rely on page size for units instead of SBRK_UNIT to * Rely on page size for units instead of SBRK_UNIT to
avoid surprises about sbrk alignment conventions. avoid surprises about sbrk alignment conventions.
* Add mallinfo, mallopt. Thanks to Raymond Nijssen * Add mallinfo, mallopt. Thanks to Raymond Nijssen
(raymond@es.ele.tue.nl) for the suggestion. (raymond@es.ele.tue.nl) for the suggestion.
* Add `pad' argument to malloc_trim and top_pad mallopt parameter. * Add `pad' argument to malloc_trim and top_pad mallopt parameter.
* More precautions for cases where other routines call sbrk, * More precautions for cases where other routines call sbrk,
courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de).
* Added macros etc., allowing use in linux libc from * Added macros etc., allowing use in linux libc from
H.J. Lu (hjl@gnu.ai.mit.edu) H.J. Lu (hjl@gnu.ai.mit.edu)
* Inverted this history list * Inverted this history list
V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee)
* Re-tuned and fixed to behave more nicely with V2.6.0 changes. * Re-tuned and fixed to behave more nicely with V2.6.0 changes.
* Removed all preallocation code since under current scheme * Removed all preallocation code since under current scheme
the work required to undo bad preallocations exceeds the work required to undo bad preallocations exceeds
the work saved in good cases for most test programs. the work saved in good cases for most test programs.
* No longer use return list or unconsolidated bins since * No longer use return list or unconsolidated bins since
no scheme using them consistently outperforms those that don't no scheme using them consistently outperforms those that don't
given above changes. given above changes.
* Use best fit for very large chunks to prevent some worst-cases. * Use best fit for very large chunks to prevent some worst-cases.
* Added some support for debugging * Added some support for debugging
V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee)
* Removed footers when chunks are in use. Thanks to * Removed footers when chunks are in use. Thanks to
Paul Wilson (wilson@cs.texas.edu) for the suggestion. Paul Wilson (wilson@cs.texas.edu) for the suggestion.
V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee)
* Added malloc_trim, with help from Wolfram Gloger * Added malloc_trim, with help from Wolfram Gloger
(wmglo@Dent.MED.Uni-Muenchen.DE). (wmglo@Dent.MED.Uni-Muenchen.DE).
V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g)
@ -3836,11 +3843,11 @@ History:
V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g)
* faster bin computation & slightly different binning * faster bin computation & slightly different binning
* merged all consolidations to one part of malloc proper * merged all consolidations to one part of malloc proper
(eliminating old malloc_find_space & malloc_clean_bin) (eliminating old malloc_find_space & malloc_clean_bin)
* Scan 2 returns chunks (not just 1) * Scan 2 returns chunks (not just 1)
* Propagate failure in realloc if malloc returns 0 * Propagate failure in realloc if malloc returns 0
* Add stuff to allow compilation on non-ANSI compilers * Add stuff to allow compilation on non-ANSI compilers
from kpv@research.att.com from kpv@research.att.com
V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu)
* removed potential for odd address access in prev_chunk * removed potential for odd address access in prev_chunk
@ -3848,11 +3855,11 @@ History:
* misc cosmetics and a bit more internal documentation * misc cosmetics and a bit more internal documentation
* anticosmetics: mangled names in macros to evade debugger strangeness * anticosmetics: mangled names in macros to evade debugger strangeness
* tested on sparc, hp-700, dec-mips, rs6000 * tested on sparc, hp-700, dec-mips, rs6000
with gcc & native cc (hp, dec only) allowing with gcc & native cc (hp, dec only) allowing
Detlefs & Zorn comparison study (in SIGPLAN Notices.) Detlefs & Zorn comparison study (in SIGPLAN Notices.)
Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu)
* Based loosely on libg++-1.2X malloc. (It retains some of the overall * Based loosely on libg++-1.2X malloc. (It retains some of the overall
structure of old version, but most details differ.) structure of old version, but most details differ.)
*/ */

View File

@ -749,7 +749,7 @@ const char* forced_winenv_vars [] =
NULL NULL
}; };
#define FORCED_WINENV_SIZE (sizeof (forced_winenv_vars) / sizeof (forced_winenv_vars[0])) #define FORCED_WINENV_SIZE (sizeof (forced_winenv_vars) / sizeof (forced_winenv_vars[0]))
/* Create a Windows-style environment block, i.e. a typical character buffer /* Create a Windows-style environment block, i.e. a typical character buffer
filled with null terminated strings, terminated by double null characters. filled with null terminated strings, terminated by double null characters.

View File

@ -974,7 +974,6 @@ private:
int audiobits_; int audiobits_;
int audiochannels_; int audiochannels_;
bool setupwav(const char *pData, int nBytes); bool setupwav(const char *pData, int nBytes);
public: public:
fhandler_dev_dsp (const char *name = 0); fhandler_dev_dsp (const char *name = 0);
~fhandler_dev_dsp(); ~fhandler_dev_dsp();

View File

@ -1,11 +1,11 @@
/* fhandler_dev_dsp: code to emulate OSS sound model /dev/dsp /* fhandler_dev_dsp: code to emulate OSS sound model /dev/dsp
Copyright 2001 Red Hat, Inc Copyright 2001 Red Hat, Inc
Written by Andy Younger (andy@snoogie.demon.co.uk) Written by Andy Younger (andy@snoogie.demon.co.uk)
This file is part of Cygwin. This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the 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. */

View File

@ -189,7 +189,7 @@ fhandler_serial::raw_write (const void *ptr, size_t len)
} }
ForceCloseHandle(write_status.hEvent); ForceCloseHandle(write_status.hEvent);
return bytes_written; return bytes_written;
err: err:

View File

@ -428,7 +428,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
if ((flags & MAP_PRIVATE) && (os_being_run == winNT || (prot & ~PROT_READ))) if ((flags & MAP_PRIVATE) && (os_being_run == winNT || (prot & ~PROT_READ)))
access = FILE_MAP_COPY; access = FILE_MAP_COPY;
SetResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); SetResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
#if 0 #if 0
/* Windows 95 does not have fixed addresses */ /* Windows 95 does not have fixed addresses */
@ -452,7 +452,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM"); syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED; return MAP_FAILED;
} }
} }
@ -475,7 +475,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
{ {
set_errno (EBADF); set_errno (EBADF);
syscall_printf ("-1 = mmap(): EBADF"); syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED; return MAP_FAILED;
} }
fh = cygheap->fdtab[fd]; fh = cygheap->fdtab[fd];
@ -509,7 +509,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
off = rec->map_map (off, len); off = rec->map_map (off, len);
caddr_t ret = rec->get_address () + off; caddr_t ret = rec->get_address () + off;
syscall_printf ("%x = mmap() succeeded", ret); syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return ret; return ret;
} }
} }
@ -518,7 +518,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
{ {
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED; return MAP_FAILED;
} }
@ -541,7 +541,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
fh->munmap (h, base, gran_len); fh->munmap (h, base, gran_len);
set_errno (ENOMEM); set_errno (ENOMEM);
syscall_printf ("-1 = mmap(): ENOMEM"); syscall_printf ("-1 = mmap(): ENOMEM");
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED; return MAP_FAILED;
} }
l = mmapped_areas->add_list (l, fd); l = mmapped_areas->add_list (l, fd);
@ -552,7 +552,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
off = rec->map_map (off, len); off = rec->map_map (off, len);
caddr_t ret = rec->get_address () + off; caddr_t ret = rec->get_address () + off;
syscall_printf ("%x = mmap() succeeded", ret); syscall_printf ("%x = mmap() succeeded", ret);
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap"); ReleaseResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return ret; return ret;
} }
@ -573,13 +573,13 @@ munmap (caddr_t addr, size_t len)
return -1; return -1;
} }
SetResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," munmap"); SetResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
/* Check if a mmap'ed area was ever created */ /* Check if a mmap'ed area was ever created */
if (mmapped_areas == NULL) if (mmapped_areas == NULL)
{ {
syscall_printf ("-1 = munmap(): mmapped_areas == NULL"); syscall_printf ("-1 = munmap(): mmapped_areas == NULL");
set_errno (EINVAL); set_errno (EINVAL);
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," munmap"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
return -1; return -1;
} }
@ -605,7 +605,7 @@ munmap (caddr_t addr, size_t len)
l->erase (li); l->erase (li);
} }
syscall_printf ("0 = munmap(): %x", addr); syscall_printf ("0 = munmap(): %x", addr);
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," munmap"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
return 0; return 0;
} }
} }
@ -614,7 +614,7 @@ munmap (caddr_t addr, size_t len)
set_errno (EINVAL); set_errno (EINVAL);
syscall_printf ("-1 = munmap(): EINVAL"); syscall_printf ("-1 = munmap(): EINVAL");
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," munmap"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "munmap");
return -1; return -1;
} }
@ -636,13 +636,13 @@ msync (caddr_t addr, size_t len, int flags)
return -1; return -1;
} }
SetResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," msync"); SetResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
/* Check if a mmap'ed area was ever created */ /* Check if a mmap'ed area was ever created */
if (mmapped_areas == NULL) if (mmapped_areas == NULL)
{ {
syscall_printf ("-1 = msync(): mmapped_areas == NULL"); syscall_printf ("-1 = msync(): mmapped_areas == NULL");
set_errno (EINVAL); set_errno (EINVAL);
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," msync"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
return -1; return -1;
} }
@ -668,7 +668,7 @@ msync (caddr_t addr, size_t len, int flags)
else else
syscall_printf ("0 = msync()"); syscall_printf ("0 = msync()");
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," msync"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
return 0; return 0;
} }
} }
@ -679,7 +679,7 @@ msync (caddr_t addr, size_t len, int flags)
set_errno (ENOMEM); set_errno (ENOMEM);
syscall_printf ("-1 = msync(): ENOMEM"); syscall_printf ("-1 = msync(): ENOMEM");
ReleaseResourceLock(LOCK_MMAP_LIST,WRITE_LOCK|READ_LOCK," msync"); ReleaseResourceLock(LOCK_MMAP_LIST, WRITE_LOCK | READ_LOCK, "msync");
return -1; return -1;
} }

View File

@ -55,7 +55,7 @@ public:
~wsock_event () ~wsock_event ()
{ {
if (event) if (event)
WSACloseEvent (event); WSACloseEvent (event);
event = NULL; event = NULL;
}; };
@ -77,7 +77,7 @@ wsock_event::prepare ()
} }
else if (GetLastError () == ERROR_PROC_NOT_FOUND) /* winsock2 not available */ else if (GetLastError () == ERROR_PROC_NOT_FOUND) /* winsock2 not available */
WSASetLastError (0); WSASetLastError (0);
debug_printf ("%d = wsock_event::prepare ()", ret); debug_printf ("%d = wsock_event::prepare ()", ret);
return ret; return ret;
} }
@ -100,9 +100,9 @@ wsock_event::wait (int socket, LPDWORD flags)
{ {
debug_printf ("CancelIo() %E, fallback to blocking io"); debug_printf ("CancelIo() %E, fallback to blocking io");
WSAGetOverlappedResult(socket, &ovr, &len, TRUE, flags); WSAGetOverlappedResult(socket, &ovr, &len, TRUE, flags);
} }
else else
WSASetLastError (WSAEINTR); WSASetLastError (WSAEINTR);
break; break;
case WSA_WAIT_FAILED: case WSA_WAIT_FAILED:
break; break;
@ -470,7 +470,7 @@ static int get_inet_addr (const struct sockaddr *in, int inlen,
char buf[128]; char buf[128];
memset (buf, 0, sizeof buf); memset (buf, 0, sizeof buf);
if (read (fd, buf, sizeof buf) != -1) if (read (fd, buf, sizeof buf) != -1)
{ {
sockaddr_in sin; sockaddr_in sin;
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sscanf (buf + strlen (SOCKET_COOKIE), "%hu %08x-%08x-%08x-%08x", sscanf (buf + strlen (SOCKET_COOKIE), "%hu %08x-%08x-%08x-%08x",
@ -481,7 +481,7 @@ static int get_inet_addr (const struct sockaddr *in, int inlen,
*out = sin; *out = sin;
*outlen = sizeof sin; *outlen = sizeof sin;
ret = 1; ret = 1;
} }
_close (fd); _close (fd);
return ret; return ret;
} }
@ -526,15 +526,15 @@ cygwin_sendto (int fd,
WSABUF wsabuf = { len, (char *) buf }; WSABUF wsabuf = { len, (char *) buf };
DWORD ret = 0; DWORD ret = 0;
if (WSASendTo (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags, if (WSASendTo (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags,
to, tolen, ovr, NULL) != SOCKET_ERROR) to, tolen, ovr, NULL) != SOCKET_ERROR)
res = ret; res = ret;
else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) else if ((res = WSAGetLastError ()) != WSA_IO_PENDING)
{ {
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
} }
else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1)
set_winsock_errno (); set_winsock_errno ();
} }
syscall_printf ("%d = sendto (%d, %x, %x, %x)", res, fd, buf, len, flags); syscall_printf ("%d = sendto (%d, %x, %x, %x)", res, fd, buf, len, flags);
@ -561,7 +561,7 @@ cygwin_recvfrom (int fd,
{ {
debug_printf ("Fallback to winsock 1 recvfrom call"); debug_printf ("Fallback to winsock 1 recvfrom call");
if ((res = recvfrom (h->get_socket (), buf, len, flags, from, fromlen)) if ((res = recvfrom (h->get_socket (), buf, len, flags, from, fromlen))
== SOCKET_ERROR) == SOCKET_ERROR)
{ {
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
@ -572,15 +572,15 @@ cygwin_recvfrom (int fd,
WSABUF wsabuf = { len, (char *) buf }; WSABUF wsabuf = { len, (char *) buf };
DWORD ret = 0; DWORD ret = 0;
if (WSARecvFrom (h->get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags, if (WSARecvFrom (h->get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags,
from, fromlen, ovr, NULL) != SOCKET_ERROR) from, fromlen, ovr, NULL) != SOCKET_ERROR)
res = ret; res = ret;
else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) else if ((res = WSAGetLastError ()) != WSA_IO_PENDING)
{ {
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
} }
else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1)
set_winsock_errno (); set_winsock_errno ();
} }
syscall_printf ("%d = recvfrom (%d, %x, %x, %x)", res, fd, buf, len, flags); syscall_printf ("%d = recvfrom (%d, %x, %x, %x)", res, fd, buf, len, flags);
@ -756,7 +756,7 @@ cygwin_connect (int fd,
{ {
res = connect (sock->get_socket (), (sockaddr *) &sin, namelen); res = connect (sock->get_socket (), (sockaddr *) &sin, namelen);
if (res) if (res)
{ {
/* Special handling for connect to return the correct error code /* Special handling for connect to return the correct error code
when called to early on a non-blocking socket. */ when called to early on a non-blocking socket. */
if (WSAGetLastError () == WSAEWOULDBLOCK) if (WSAGetLastError () == WSAEWOULDBLOCK)
@ -766,37 +766,37 @@ cygwin_connect (int fd,
} }
set_winsock_errno (); set_winsock_errno ();
} }
if (sock->get_addr_family () == AF_UNIX) if (sock->get_addr_family () == AF_UNIX)
{ {
if (!res || in_progress) if (!res || in_progress)
{ {
if (!sock->create_secret_event (secret)) if (!sock->create_secret_event (secret))
{ {
secret_check_failed = TRUE; secret_check_failed = TRUE;
} }
else if (in_progress) else if (in_progress)
sock->signal_secret_event (); sock->signal_secret_event ();
} }
if (!secret_check_failed && !res) if (!secret_check_failed && !res)
{ {
if (!sock->check_peer_secret_event (&sin, secret)) if (!sock->check_peer_secret_event (&sin, secret))
{ {
debug_printf ( "accept from unauthorized server" ); debug_printf ( "accept from unauthorized server" );
secret_check_failed = TRUE; secret_check_failed = TRUE;
} }
} }
if (secret_check_failed) if (secret_check_failed)
{ {
sock->close_secret_event (); sock->close_secret_event ();
if (res) if (res)
closesocket (res); closesocket (res);
set_errno (ECONNREFUSED); set_errno (ECONNREFUSED);
res = -1; res = -1;
} }
} }
} }
return res; return res;
} }
@ -913,7 +913,7 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
in_progress = TRUE; in_progress = TRUE;
if (sock->get_addr_family () == AF_UNIX) if (sock->get_addr_family () == AF_UNIX)
{ {
if ((SOCKET) res != (SOCKET) INVALID_SOCKET || in_progress) if ((SOCKET) res != (SOCKET) INVALID_SOCKET || in_progress)
{ {
if (!sock->create_secret_event ()) if (!sock->create_secret_event ())
@ -923,25 +923,25 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
} }
if (!secret_check_failed && if (!secret_check_failed &&
(SOCKET) res != (SOCKET) INVALID_SOCKET) (SOCKET) res != (SOCKET) INVALID_SOCKET)
{ {
if (!sock->check_peer_secret_event ((struct sockaddr_in*) peer)) if (!sock->check_peer_secret_event ((struct sockaddr_in*) peer))
{ {
debug_printf ("connect from unauthorized client"); debug_printf ("connect from unauthorized client");
secret_check_failed = TRUE; secret_check_failed = TRUE;
} }
} }
if (secret_check_failed) if (secret_check_failed)
{ {
sock->close_secret_event (); sock->close_secret_event ();
if ((SOCKET) res != (SOCKET) INVALID_SOCKET) if ((SOCKET) res != (SOCKET) INVALID_SOCKET)
closesocket (res); closesocket (res);
set_errno (ECONNABORTED); set_errno (ECONNABORTED);
res = -1; res = -1;
goto done; goto done;
} }
} }
SetResourceLock (LOCK_FD_LIST, WRITE_LOCK|READ_LOCK, "accept"); SetResourceLock (LOCK_FD_LIST, WRITE_LOCK|READ_LOCK, "accept");
@ -1020,11 +1020,11 @@ cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen)
goto out; goto out;
} }
sock->set_connect_secret (); sock->set_connect_secret ();
char buf[sizeof (SOCKET_COOKIE) + 80]; char buf[sizeof (SOCKET_COOKIE) + 80];
__small_sprintf (buf, "%s%u ", SOCKET_COOKIE, sin.sin_port); __small_sprintf (buf, "%s%u ", SOCKET_COOKIE, sin.sin_port);
sock->get_connect_secret (strchr (buf, '\0')); sock->get_connect_secret (strchr (buf, '\0'));
len = strlen (buf) + 1; len = strlen (buf) + 1;
/* Note that the terminating nul is written. */ /* Note that the terminating nul is written. */
@ -1158,14 +1158,14 @@ cygwin_herror (const char *s)
switch (h_errno) switch (h_errno)
{ {
case NETDB_INTERNAL: case NETDB_INTERNAL:
h_errstr = "Resolver internal error"; h_errstr = "Resolver internal error";
break; break;
case NETDB_SUCCESS: case NETDB_SUCCESS:
h_errstr = "Resolver error 0 (no error)"; h_errstr = "Resolver error 0 (no error)";
break; break;
default: default:
h_errstr = "Unknown resolver error"; h_errstr = "Unknown resolver error";
break; break;
} }
write (2, h_errstr, strlen (h_errstr)); write (2, h_errstr, strlen (h_errstr));
write (2, "\n", 1); write (2, "\n", 1);
@ -1200,7 +1200,7 @@ cygwin_recv (int fd, void *buf, int len, unsigned int flags)
{ {
debug_printf ("Fallback to winsock 1 recv call"); debug_printf ("Fallback to winsock 1 recv call");
if ((res = recv (h->get_socket (), (char *) buf, len, flags)) if ((res = recv (h->get_socket (), (char *) buf, len, flags))
== SOCKET_ERROR) == SOCKET_ERROR)
{ {
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
@ -1252,15 +1252,15 @@ cygwin_send (int fd, const void *buf, int len, unsigned int flags)
WSABUF wsabuf = { len, (char *) buf }; WSABUF wsabuf = { len, (char *) buf };
DWORD ret = 0; DWORD ret = 0;
if (WSASend (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags, if (WSASend (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags,
ovr, NULL) != SOCKET_ERROR) ovr, NULL) != SOCKET_ERROR)
res = ret; res = ret;
else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) else if ((res = WSAGetLastError ()) != WSA_IO_PENDING)
{ {
set_winsock_errno (); set_winsock_errno ();
res = -1; res = -1;
} }
else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1)
set_winsock_errno (); set_winsock_errno ();
} }
syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags); syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags);
@ -1327,7 +1327,7 @@ get_2k_ifconf (struct ifconf *ifc, int what)
!GetIpAddrTable(ipt, &siz_ip_table, TRUE)) !GetIpAddrTable(ipt, &siz_ip_table, TRUE))
{ {
for (if_cnt = 0; if_cnt < ift->dwNumEntries; ++if_cnt) for (if_cnt = 0; if_cnt < ift->dwNumEntries; ++if_cnt)
{ {
switch (ift->table[if_cnt].dwType) switch (ift->table[if_cnt].dwType)
{ {
case MIB_IF_TYPE_ETHERNET: case MIB_IF_TYPE_ETHERNET:
@ -1351,44 +1351,44 @@ get_2k_ifconf (struct ifconf *ifc, int what)
default: default:
continue; continue;
} }
for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) for (ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt)
if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex) if (ipt->table[ip_cnt].dwIndex == ift->table[if_cnt].dwIndex)
{ {
switch (what) switch (what)
{ {
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = ipt->table[ip_cnt].dwAddr; sa->sin_addr.s_addr = ipt->table[ip_cnt].dwAddr;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFBRDADDR: case SIOCGIFBRDADDR:
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
#if 0 #if 0
/* Unfortunately, the field returns only crap. */ /* Unfortunately, the field returns only crap. */
sa->sin_addr.s_addr = ipt->table[ip_cnt].dwBCastAddr; sa->sin_addr.s_addr = ipt->table[ip_cnt].dwBCastAddr;
#else #else
lip = ipt->table[ip_cnt].dwAddr; lip = ipt->table[ip_cnt].dwAddr;
lnp = ipt->table[ip_cnt].dwMask; lnp = ipt->table[ip_cnt].dwMask;
sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_addr.s_addr = lip & lnp | ~lnp;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
#endif #endif
break; break;
case SIOCGIFNETMASK: case SIOCGIFNETMASK:
sa = (struct sockaddr_in *) &ifr->ifr_netmask; sa = (struct sockaddr_in *) &ifr->ifr_netmask;
sa->sin_addr.s_addr = ipt->table[ip_cnt].dwMask; sa->sin_addr.s_addr = ipt->table[ip_cnt].dwMask;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFHWADDR: case SIOCGIFHWADDR:
so = &ifr->ifr_hwaddr; so = &ifr->ifr_hwaddr;
for (UINT i = 0; i < IFHWADDRLEN; ++i) for (UINT i = 0; i < IFHWADDRLEN; ++i)
if (i >= ift->table[if_cnt].dwPhysAddrLen) if (i >= ift->table[if_cnt].dwPhysAddrLen)
so->sa_data[i] = '\0'; so->sa_data[i] = '\0';
else else
so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i]; so->sa_data[i] = ift->table[if_cnt].bPhysAddr[i];
so->sa_family = AF_INET; so->sa_family = AF_INET;
break; break;
case SIOCGIFMETRIC: case SIOCGIFMETRIC:
@ -1397,13 +1397,13 @@ get_2k_ifconf (struct ifconf *ifc, int what)
case SIOCGIFMTU: case SIOCGIFMTU:
ifr->ifr_mtu = ift->table[if_cnt].dwMtu; ifr->ifr_mtu = ift->table[if_cnt].dwMtu;
break; break;
} }
++cnt; ++cnt;
if ((caddr_t) ++ifr > if ((caddr_t) ++ifr >
ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq)) ifc->ifc_buf + ifc->ifc_len - sizeof (struct ifreq))
goto done; goto done;
break; break;
} }
} }
} }
done: done:
@ -1438,26 +1438,26 @@ get_nt_ifconf (struct ifconf *ifc, int what)
struct ifreq *ifr = ifc->ifc_req; struct ifreq *ifr = ifc->ifc_req;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
"SYSTEM\\" "SYSTEM\\"
"CurrentControlSet\\" "CurrentControlSet\\"
"Services\\" "Services\\"
"Tcpip\\" "Tcpip\\"
"Linkage", "Linkage",
0, KEY_READ, &key) == ERROR_SUCCESS) 0, KEY_READ, &key) == ERROR_SUCCESS)
{ {
if (RegQueryValueEx (key, "Bind", if (RegQueryValueEx (key, "Bind",
NULL, NULL, NULL, NULL,
NULL, &size) == ERROR_SUCCESS) NULL, &size) == ERROR_SUCCESS)
{ {
binding = (char *) alloca (size); binding = (char *) alloca (size);
if (RegQueryValueEx (key, "Bind", if (RegQueryValueEx (key, "Bind",
NULL, NULL, NULL, NULL,
(unsigned char *) binding, (unsigned char *) binding,
&size) != ERROR_SUCCESS) &size) != ERROR_SUCCESS)
{ {
binding = NULL; binding = NULL;
} }
} }
RegCloseKey (key); RegCloseKey (key);
} }
@ -1467,141 +1467,141 @@ get_nt_ifconf (struct ifconf *ifc, int what)
char cardkey[256], ipaddress[256], netmask[256]; char cardkey[256], ipaddress[256], netmask[256];
for (bp = binding; *bp; bp += strlen (bp) + 1) for (bp = binding; *bp; bp += strlen (bp) + 1)
{ {
bp += strlen ("\\Device\\"); bp += strlen ("\\Device\\");
strcpy (cardkey, "SYSTEM\\CurrentControlSet\\Services\\"); strcpy (cardkey, "SYSTEM\\CurrentControlSet\\Services\\");
strcat (cardkey, bp); strcat (cardkey, bp);
strcat (cardkey, "\\Parameters\\Tcpip"); strcat (cardkey, "\\Parameters\\Tcpip");
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, cardkey, if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, cardkey,
0, KEY_READ, &key) != ERROR_SUCCESS) 0, KEY_READ, &key) != ERROR_SUCCESS)
continue; continue;
if (RegQueryValueEx (key, "IPAddress", if (RegQueryValueEx (key, "IPAddress",
NULL, NULL, NULL, NULL,
(unsigned char *) ipaddress, (unsigned char *) ipaddress,
(size = 256, &size)) == ERROR_SUCCESS (size = 256, &size)) == ERROR_SUCCESS
&& RegQueryValueEx (key, "SubnetMask", && RegQueryValueEx (key, "SubnetMask",
NULL, NULL, NULL, NULL,
(unsigned char *) netmask, (unsigned char *) netmask,
(size = 256, &size)) == ERROR_SUCCESS) (size = 256, &size)) == ERROR_SUCCESS)
{ {
char *ip, *np; char *ip, *np;
char dhcpaddress[256], dhcpnetmask[256]; char dhcpaddress[256], dhcpnetmask[256];
for (ip = ipaddress, np = netmask; for (ip = ipaddress, np = netmask;
*ip && *np; *ip && *np;
ip += strlen (ip) + 1, np += strlen (np) + 1) ip += strlen (ip) + 1, np += strlen (np) + 1)
{ {
if ((caddr_t) ++ifr > ifc->ifc_buf if ((caddr_t) ++ifr > ifc->ifc_buf
+ ifc->ifc_len + ifc->ifc_len
- sizeof (struct ifreq)) - sizeof (struct ifreq))
break; break;
if (! strncmp (bp, "NdisWan", 7)) if (! strncmp (bp, "NdisWan", 7))
{ {
strcpy (ifr->ifr_name, "ppp"); strcpy (ifr->ifr_name, "ppp");
strcat (ifr->ifr_name, bp + 7); strcat (ifr->ifr_name, bp + 7);
} }
else else
{ {
++*eth; ++*eth;
strcpy (ifr->ifr_name, "eth"); strcpy (ifr->ifr_name, "eth");
strcat (ifr->ifr_name, eth); strcat (ifr->ifr_name, eth);
} }
memset (&ifr->ifr_addr, '\0', sizeof ifr->ifr_addr); memset (&ifr->ifr_addr, '\0', sizeof ifr->ifr_addr);
if (cygwin_inet_addr (ip) == 0L if (cygwin_inet_addr (ip) == 0L
&& RegQueryValueEx (key, "DhcpIPAddress", && RegQueryValueEx (key, "DhcpIPAddress",
NULL, NULL, NULL, NULL,
(unsigned char *) dhcpaddress, (unsigned char *) dhcpaddress,
(size = 256, &size)) (size = 256, &size))
== ERROR_SUCCESS == ERROR_SUCCESS
&& RegQueryValueEx (key, "DhcpSubnetMask", && RegQueryValueEx (key, "DhcpSubnetMask",
NULL, NULL, NULL, NULL,
(unsigned char *) dhcpnetmask, (unsigned char *) dhcpnetmask,
(size = 256, &size)) (size = 256, &size))
== ERROR_SUCCESS) == ERROR_SUCCESS)
{ {
switch (what) switch (what)
{ {
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = cygwin_inet_addr (dhcpaddress); sa->sin_addr.s_addr = cygwin_inet_addr (dhcpaddress);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFBRDADDR: case SIOCGIFBRDADDR:
lip = cygwin_inet_addr (dhcpaddress); lip = cygwin_inet_addr (dhcpaddress);
lnp = cygwin_inet_addr (dhcpnetmask); lnp = cygwin_inet_addr (dhcpnetmask);
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_addr.s_addr = lip & lnp | ~lnp;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFNETMASK: case SIOCGIFNETMASK:
sa = (struct sockaddr_in *) &ifr->ifr_netmask; sa = (struct sockaddr_in *) &ifr->ifr_netmask;
sa->sin_addr.s_addr = sa->sin_addr.s_addr =
cygwin_inet_addr (dhcpnetmask); cygwin_inet_addr (dhcpnetmask);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFHWADDR: case SIOCGIFHWADDR:
so = &ifr->ifr_hwaddr; so = &ifr->ifr_hwaddr;
memset (so->sa_data, 0, IFHWADDRLEN); memset (so->sa_data, 0, IFHWADDRLEN);
so->sa_family = AF_INET; so->sa_family = AF_INET;
break; break;
case SIOCGIFMETRIC: case SIOCGIFMETRIC:
ifr->ifr_metric = 1; ifr->ifr_metric = 1;
break; break;
case SIOCGIFMTU: case SIOCGIFMTU:
ifr->ifr_mtu = 1500; ifr->ifr_mtu = 1500;
break; break;
} }
} }
else else
{ {
switch (what) switch (what)
{ {
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = cygwin_inet_addr (ip); sa->sin_addr.s_addr = cygwin_inet_addr (ip);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFBRDADDR: case SIOCGIFBRDADDR:
lip = cygwin_inet_addr (ip); lip = cygwin_inet_addr (ip);
lnp = cygwin_inet_addr (np); lnp = cygwin_inet_addr (np);
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_addr.s_addr = lip & lnp | ~lnp;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFNETMASK: case SIOCGIFNETMASK:
sa = (struct sockaddr_in *) &ifr->ifr_netmask; sa = (struct sockaddr_in *) &ifr->ifr_netmask;
sa->sin_addr.s_addr = cygwin_inet_addr (np); sa->sin_addr.s_addr = cygwin_inet_addr (np);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFHWADDR: case SIOCGIFHWADDR:
so = &ifr->ifr_hwaddr; so = &ifr->ifr_hwaddr;
memset (so->sa_data, 0, IFHWADDRLEN); memset (so->sa_data, 0, IFHWADDRLEN);
so->sa_family = AF_INET; so->sa_family = AF_INET;
break; break;
case SIOCGIFMETRIC: case SIOCGIFMETRIC:
ifr->ifr_metric = 1; ifr->ifr_metric = 1;
break; break;
case SIOCGIFMTU: case SIOCGIFMTU:
ifr->ifr_mtu = 1500; ifr->ifr_mtu = 1500;
break; break;
} }
} }
++cnt; ++cnt;
} }
} }
RegCloseKey (key); RegCloseKey (key);
} }
} }
/* Set the correct length */ /* Set the correct length */
@ -1644,7 +1644,7 @@ get_95_ifconf (struct ifconf *ifc, int what)
struct ifreq *ifr = ifc->ifc_req; struct ifreq *ifr = ifc->ifc_req;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Enum\\Network\\MSTCP", if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Enum\\Network\\MSTCP",
0, KEY_READ, &key) != ERROR_SUCCESS) 0, KEY_READ, &key) != ERROR_SUCCESS)
{ {
/* Set the correct length */ /* Set the correct length */
ifc->ifc_len = cnt * sizeof (struct ifreq); ifc->ifc_len = cnt * sizeof (struct ifreq);
@ -1653,8 +1653,8 @@ get_95_ifconf (struct ifconf *ifc, int what)
for (int i = 0; for (int i = 0;
(res = RegEnumKeyEx (key, i, ifname, (res = RegEnumKeyEx (key, i, ifname,
(size = sizeof ifname, &size), (size = sizeof ifname, &size),
0, 0, 0, &update)) != ERROR_NO_MORE_ITEMS; 0, 0, 0, &update)) != ERROR_NO_MORE_ITEMS;
++i) ++i)
{ {
HKEY ifkey, subkey; HKEY ifkey, subkey;
@ -1662,62 +1662,62 @@ get_95_ifconf (struct ifconf *ifc, int what)
char adapter[256], ip[256], np[256]; char adapter[256], ip[256], np[256];
if (res != ERROR_SUCCESS if (res != ERROR_SUCCESS
|| RegOpenKeyEx (key, ifname, 0, || RegOpenKeyEx (key, ifname, 0,
KEY_READ, &ifkey) != ERROR_SUCCESS) KEY_READ, &ifkey) != ERROR_SUCCESS)
continue; continue;
if (RegQueryValueEx (ifkey, "Driver", 0, if (RegQueryValueEx (ifkey, "Driver", 0,
NULL, (unsigned char *) driver, NULL, (unsigned char *) driver,
(size = sizeof driver, &size)) != ERROR_SUCCESS) (size = sizeof driver, &size)) != ERROR_SUCCESS)
{ {
RegCloseKey (ifkey); RegCloseKey (ifkey);
continue; continue;
} }
strcpy (classname, "System\\CurrentControlSet\\Services\\Class\\"); strcpy (classname, "System\\CurrentControlSet\\Services\\Class\\");
strcat (classname, driver); strcat (classname, driver);
if ((res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, classname, if ((res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, classname,
0, KEY_READ, &subkey)) != ERROR_SUCCESS) 0, KEY_READ, &subkey)) != ERROR_SUCCESS)
{ {
RegCloseKey (ifkey); RegCloseKey (ifkey);
continue; continue;
} }
if (RegQueryValueEx (subkey, "IPAddress", 0, if (RegQueryValueEx (subkey, "IPAddress", 0,
NULL, (unsigned char *) ip, NULL, (unsigned char *) ip,
(size = sizeof ip, &size)) == ERROR_SUCCESS (size = sizeof ip, &size)) == ERROR_SUCCESS
&& RegQueryValueEx (subkey, "IPMask", 0, && RegQueryValueEx (subkey, "IPMask", 0,
NULL, (unsigned char *) np, NULL, (unsigned char *) np,
(size = sizeof np, &size)) == ERROR_SUCCESS) (size = sizeof np, &size)) == ERROR_SUCCESS)
{ {
if ((caddr_t)++ifr > ifc->ifc_buf if ((caddr_t)++ifr > ifc->ifc_buf
+ ifc->ifc_len + ifc->ifc_len
- sizeof (struct ifreq)) - sizeof (struct ifreq))
goto out; goto out;
switch (what) switch (what)
{ {
case SIOCGIFCONF: case SIOCGIFCONF:
case SIOCGIFADDR: case SIOCGIFADDR:
sa = (struct sockaddr_in *) &ifr->ifr_addr; sa = (struct sockaddr_in *) &ifr->ifr_addr;
sa->sin_addr.s_addr = cygwin_inet_addr (ip); sa->sin_addr.s_addr = cygwin_inet_addr (ip);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFBRDADDR: case SIOCGIFBRDADDR:
lip = cygwin_inet_addr (ip); lip = cygwin_inet_addr (ip);
lnp = cygwin_inet_addr (np); lnp = cygwin_inet_addr (np);
sa = (struct sockaddr_in *) &ifr->ifr_broadaddr; sa = (struct sockaddr_in *) &ifr->ifr_broadaddr;
sa->sin_addr.s_addr = lip & lnp | ~lnp; sa->sin_addr.s_addr = lip & lnp | ~lnp;
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFNETMASK: case SIOCGIFNETMASK:
sa = (struct sockaddr_in *) &ifr->ifr_netmask; sa = (struct sockaddr_in *) &ifr->ifr_netmask;
sa->sin_addr.s_addr = cygwin_inet_addr (np); sa->sin_addr.s_addr = cygwin_inet_addr (np);
sa->sin_family = AF_INET; sa->sin_family = AF_INET;
sa->sin_port = 0; sa->sin_port = 0;
break; break;
case SIOCGIFHWADDR: case SIOCGIFHWADDR:
so = &ifr->ifr_hwaddr; so = &ifr->ifr_hwaddr;
memset (so->sa_data, 0, IFHWADDRLEN); memset (so->sa_data, 0, IFHWADDRLEN);
@ -1729,61 +1729,61 @@ get_95_ifconf (struct ifconf *ifc, int what)
case SIOCGIFMTU: case SIOCGIFMTU:
ifr->ifr_mtu = 1500; ifr->ifr_mtu = 1500;
break; break;
} }
} }
RegCloseKey (subkey); RegCloseKey (subkey);
if (RegOpenKeyEx (ifkey, "Bindings", if (RegOpenKeyEx (ifkey, "Bindings",
0, KEY_READ, &subkey) != ERROR_SUCCESS) 0, KEY_READ, &subkey) != ERROR_SUCCESS)
{ {
RegCloseKey (ifkey); RegCloseKey (ifkey);
--ifr; --ifr;
continue; continue;
} }
for (int j = 0; for (int j = 0;
(res = RegEnumValue (subkey, j, bindname, (res = RegEnumValue (subkey, j, bindname,
(size = sizeof bindname, &size), (size = sizeof bindname, &size),
0, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS; 0, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS;
++j) ++j)
if (!strncasecmp (bindname, "VREDIR\\", 7)) if (!strncasecmp (bindname, "VREDIR\\", 7))
break; break;
RegCloseKey (subkey); RegCloseKey (subkey);
if (res == ERROR_SUCCESS) if (res == ERROR_SUCCESS)
{ {
strcpy (netname, "System\\CurrentControlSet\\Services\\Class\\Net\\"); strcpy (netname, "System\\CurrentControlSet\\Services\\Class\\Net\\");
strcat (netname, bindname + 7); strcat (netname, bindname + 7);
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, netname, if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, netname,
0, KEY_READ, &subkey) != ERROR_SUCCESS) 0, KEY_READ, &subkey) != ERROR_SUCCESS)
{ {
RegCloseKey (ifkey); RegCloseKey (ifkey);
--ifr; --ifr;
continue; continue;
} }
if (RegQueryValueEx (subkey, "AdapterName", 0, if (RegQueryValueEx (subkey, "AdapterName", 0,
NULL, (unsigned char *) adapter, NULL, (unsigned char *) adapter,
(size = sizeof adapter, &size)) == ERROR_SUCCESS (size = sizeof adapter, &size)) == ERROR_SUCCESS
&& strcasematch (adapter, "MS$PPP")) && strcasematch (adapter, "MS$PPP"))
{ {
++*ppp; ++*ppp;
strcpy (ifr->ifr_name, "ppp"); strcpy (ifr->ifr_name, "ppp");
strcat (ifr->ifr_name, ppp); strcat (ifr->ifr_name, ppp);
} }
else else
{ {
++*eth; ++*eth;
strcpy (ifr->ifr_name, "eth"); strcpy (ifr->ifr_name, "eth");
strcat (ifr->ifr_name, eth); strcat (ifr->ifr_name, eth);
} }
RegCloseKey (subkey); RegCloseKey (subkey);
} }
RegCloseKey (ifkey); RegCloseKey (ifkey);
@ -1863,14 +1863,14 @@ get_ifconf (struct ifconf *ifc, int what)
/* We have a win95 version... */ /* We have a win95 version... */
if (os_version_info.dwPlatformId != VER_PLATFORM_WIN32_NT if (os_version_info.dwPlatformId != VER_PLATFORM_WIN32_NT
&& (os_version_info.dwMajorVersion < 4 && (os_version_info.dwMajorVersion < 4
|| (os_version_info.dwMajorVersion == 4 || (os_version_info.dwMajorVersion == 4
&& os_version_info.dwMinorVersion == 0))) && os_version_info.dwMinorVersion == 0)))
get_95_ifconf (ifc, what); get_95_ifconf (ifc, what);
/* ...and a NT <= SP3 version... */ /* ...and a NT <= SP3 version... */
else if (os_version_info.dwPlatformId == VER_PLATFORM_WIN32_NT else if (os_version_info.dwPlatformId == VER_PLATFORM_WIN32_NT
&& (os_version_info.dwMajorVersion < 4 && (os_version_info.dwMajorVersion < 4
|| (os_version_info.dwMajorVersion == 4 || (os_version_info.dwMajorVersion == 4
&& strcmp (os_version_info.szCSDVersion, "Service Pack 4") < 0))) && strcmp (os_version_info.szCSDVersion, "Service Pack 4") < 0)))
get_nt_ifconf (ifc, what); get_nt_ifconf (ifc, what);
/* ...and finally a "modern" version for win98/ME, NT >= SP4 and W2K! */ /* ...and finally a "modern" version for win98/ME, NT >= SP4 and W2K! */
else else

View File

@ -133,8 +133,8 @@ read_etc_passwd ()
/* if we got blocked by the mutex, then etc_passwd may have been processed */ /* if we got blocked by the mutex, then etc_passwd may have been processed */
if (passwd_state != uninitialized) if (passwd_state != uninitialized)
{ {
pthread_mutex_unlock(&etc_passwd_mutex); pthread_mutex_unlock(&etc_passwd_mutex);
return; return;
} }
if (passwd_state != initializing) if (passwd_state != initializing)
@ -206,13 +206,13 @@ getpwuid (uid_t uid)
{ {
if (passwd_state <= initializing) if (passwd_state <= initializing)
read_etc_passwd (); read_etc_passwd ();
pthread_testcancel(); pthread_testcancel();
return search_for (uid, 0); return search_for (uid, 0);
} }
extern "C" int extern "C" int
getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
{ {
*result = NULL; *result = NULL;
@ -232,7 +232,7 @@ getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct
/* check needed buffer size. */ /* check needed buffer size. */
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) + size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) + strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
strlen (temppw->pw_passwd) + 5; strlen (temppw->pw_passwd) + 5;
if (needsize > bufsize) if (needsize > bufsize)
return ERANGE; return ERANGE;
@ -259,14 +259,14 @@ getpwnam (const char *name)
{ {
if (passwd_state <= initializing) if (passwd_state <= initializing)
read_etc_passwd (); read_etc_passwd ();
pthread_testcancel(); pthread_testcancel();
return search_for (0, name); return search_for (0, name);
} }
/* the max size buffer we can expect to /* the max size buffer we can expect to
* use is returned via sysconf with _SC_GETPW_R_SIZE_MAX. * use is returned via sysconf with _SC_GETPW_R_SIZE_MAX.
* This may need updating! - Rob Collins April 2001. * This may need updating! - Rob Collins April 2001.
*/ */
@ -290,11 +290,11 @@ getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, s
/* check needed buffer size. */ /* check needed buffer size. */
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) + size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) + strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
strlen (temppw->pw_passwd) + 5; strlen (temppw->pw_passwd) + 5;
if (needsize > bufsize) if (needsize > bufsize)
return ERANGE; return ERANGE;
/* make a copy of temppw */ /* make a copy of temppw */
*result = pwd; *result = pwd;
pwd->pw_uid = temppw->pw_uid; pwd->pw_uid = temppw->pw_uid;

View File

@ -27,31 +27,30 @@
/* for getpid */ /* for getpid */
#include <unistd.h> #include <unistd.h>
/* Win32 priority to UNIX priority Mapping. /* Win32 priority to UNIX priority Mapping.
For now, I'm just following the spec: any range of priorities is ok. For now, I'm just following the spec: any range of priorities is ok.
There are probably many many issues with this... There are probably many many issues with this...
We don't want process's going realtime. Well, they probably could, but the issues We don't want process's going realtime. Well, they probably could, but the issues
with avoiding the priority values 17-22 and 27-30 (not supported before win2k) with avoiding the priority values 17-22 and 27-30 (not supported before win2k)
make that inefficient. make that inefficient.
However to complicate things most unixes use lower is better priorities. However to complicate things most unixes use lower is better priorities.
So we map -14 to 15, and 15 to 1 via (16- ((n+16) >> 1)) So we map -14 to 15, and 15 to 1 via (16- ((n+16) >> 1))
we then map 1 to 15 to various process class and thread priority combinations we then map 1 to 15 to various process class and thread priority combinations
Then we need to look at the threads vi process priority. As win95 98 and NT 4 Then we need to look at the threads vi process priority. As win95 98 and NT 4
Don't support opening threads cross-process (unless a thread HANDLE is passed around) Don't support opening threads cross-process (unless a thread HANDLE is passed around)
for now, we'll just use the priority class. for now, we'll just use the priority class.
The code and logic are present to calculate the priority for thread The code and logic are present to calculate the priority for thread
, if a thread handle can be obtained. Alternatively, if the symbols wouldn't be , if a thread handle can be obtained. Alternatively, if the symbols wouldn't be
resolved until they are used resolved until they are used
we could support this on windows 2000 and ME now, and just fall back to the we could support this on windows 2000 and ME now, and just fall back to the
class only on pre win2000 machines. class only on pre win2000 machines.
Lastly, because we can't assume that the pid we're given are Windows pids, we can't Lastly, because we can't assume that the pid we're given are Windows pids, we can't
alter non-cygwin started programs. alter non-cygwin started programs.
*/ */
extern "C" extern "C"
@ -95,9 +94,9 @@ valid_sched_parameters(const struct sched_param *param)
/* get sched params for process /* get sched params for process
Note, I'm never returning EPERM, Note, I'm never returning EPERM,
Always ESRCH. This is by design (If cygwin ever looks at paranoid security Always ESRCH. This is by design (If cygwin ever looks at paranoid security
Walking the pid values is a known hole in some os's) Walking the pid values is a known hole in some os's)
*/ */
int int
sched_getparam (pid_t pid, struct sched_param *param) sched_getparam (pid_t pid, struct sched_param *param)
@ -222,7 +221,7 @@ sched_getparam (pid_t pid, struct sched_param *param)
} }
/* reverse out winpri = (16- ((unixpri+16) >> 1)) */ /* reverse out winpri = (16- ((unixpri+16) >> 1)) */
/* /*
winpri-16 = - (unixpri +16 ) >> 1 winpri-16 = - (unixpri +16 ) >> 1
-(winpri-16) = unixpri +16 >> 1 -(winpri-16) = unixpri +16 >> 1
@ -238,7 +237,7 @@ sched_getparam (pid_t pid, struct sched_param *param)
/* get the scheduler for pid /* get the scheduler for pid
All process's on WIN32 run with SCHED_FIFO. All process's on WIN32 run with SCHED_FIFO.
So we just give an answer. So we just give an answer.
(WIN32 uses a multi queue FIFO). (WIN32 uses a multi queue FIFO).
*/ */
int int
@ -255,11 +254,11 @@ sched_getscheduler (pid_t pid)
We can't return -11, errno ENOSYS, because that implies that We can't return -11, errno ENOSYS, because that implies that
sched_get_priority_max & min are also not supported (according to the spec) sched_get_priority_max & min are also not supported (according to the spec)
so some spec-driven autoconf tests will likely assume they aren't present either so some spec-driven autoconf tests will likely assume they aren't present either
returning ESRCH might confuse some applications (if they assumed that when returning ESRCH might confuse some applications (if they assumed that when
rr_get_interval is called on pid 0 it always works). rr_get_interval is called on pid 0 it always works).
If someone knows the time quanta for the various win32 platforms, then a If someone knows the time quanta for the various win32 platforms, then a
simple check for the os we're running on will finish this function simple check for the os we're running on will finish this function
*/ */
int int
@ -408,8 +407,8 @@ sched_set_thread_priority(HANDLE thread, int priority)
real_pri = 16 - ((priority + 16) >> 1); real_pri = 16 - ((priority + 16) >> 1);
if (real_pri <1 || real_pri > 15) if (real_pri <1 || real_pri > 15)
return EINVAL; return EINVAL;
if (real_pri < 4) if (real_pri < 4)
real_pri = THREAD_PRIORITY_LOWEST; real_pri = THREAD_PRIORITY_LOWEST;
else if (real_pri < 7) else if (real_pri < 7)
real_pri = THREAD_PRIORITY_BELOW_NORMAL; real_pri = THREAD_PRIORITY_BELOW_NORMAL;

View File

@ -268,9 +268,9 @@ get_logon_server_and_user_domain (char *logonserver, char *userdomain)
static BOOL static BOOL
get_user_groups (WCHAR *wlogonserver, cygsidlist &grp_list, char *user) get_user_groups (WCHAR *wlogonserver, cygsidlist &grp_list, char *user)
{ {
WCHAR wuser[UNLEN + 1]; WCHAR wuser[UNLEN + 1];
sys_mbstowcs (wuser, user, UNLEN + 1); sys_mbstowcs (wuser, user, UNLEN + 1);
LPGROUP_USERS_INFO_0 buf; LPGROUP_USERS_INFO_0 buf;
DWORD cnt, tot; DWORD cnt, tot;
NET_API_STATUS ret; NET_API_STATUS ret;
@ -443,7 +443,7 @@ get_group_sidlist (const char *logonserver, cygsidlist &grp_list,
DWORD ulen = INTERNET_MAX_HOST_NAME_LENGTH + 1; DWORD ulen = INTERNET_MAX_HOST_NAME_LENGTH + 1;
DWORD dlen = INTERNET_MAX_HOST_NAME_LENGTH + 1; DWORD dlen = INTERNET_MAX_HOST_NAME_LENGTH + 1;
SID_NAME_USE use; SID_NAME_USE use;
auth_pos = -1; auth_pos = -1;
sys_mbstowcs (wserver, logonserver, INTERNET_MAX_HOST_NAME_LENGTH + 1); sys_mbstowcs (wserver, logonserver, INTERNET_MAX_HOST_NAME_LENGTH + 1);
if (!LookupAccountSid (NULL, usersid, user, &ulen, domain, &dlen, &use)) if (!LookupAccountSid (NULL, usersid, user, &ulen, domain, &dlen, &use))
@ -625,7 +625,7 @@ get_dacl (PACL acl, cygsid usersid, cygsidlist &grp_list)
{ {
__seterrno (); __seterrno ();
return FALSE; return FALSE;
} }
if (grp_list.contains (well_known_admin_sid)) if (grp_list.contains (well_known_admin_sid))
{ {
if (!AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL, if (!AddAccessAllowedAce(acl, ACL_REVISION, GENERIC_ALL,
@ -690,7 +690,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
/* SE_CREATE_TOKEN_NAME privilege needed to call NtCreateToken. */ /* SE_CREATE_TOKEN_NAME privilege needed to call NtCreateToken. */
if ((old_priv_state = set_process_privilege (SE_CREATE_TOKEN_NAME)) < 0) if ((old_priv_state = set_process_privilege (SE_CREATE_TOKEN_NAME)) < 0)
goto out; goto out;
/* Open policy object. */ /* Open policy object. */
if ((lsa = open_local_policy ()) == INVALID_HANDLE_VALUE) if ((lsa = open_local_policy ()) == INVALID_HANDLE_VALUE)
goto out; goto out;
@ -710,7 +710,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
else else
{ {
/* Switching user context to SYSTEM doesn't inherit the authentication /* Switching user context to SYSTEM doesn't inherit the authentication
id of the user account running current process. */ id of the user account running current process. */
if (usersid != well_known_system_sid) if (usersid != well_known_system_sid)
if (!GetTokenInformation (my_token, TokenStatistics, if (!GetTokenInformation (my_token, TokenStatistics,
&stats, sizeof stats, &size)) &stats, sizeof stats, &size))
@ -719,9 +719,9 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
auth_luid = stats.AuthenticationId; auth_luid = stats.AuthenticationId;
/* Retrieving current processes group list to be able to inherit /* Retrieving current processes group list to be able to inherit
some important well known group sids. */ some important well known group sids. */
if (!GetTokenInformation (my_token, TokenGroups, NULL, 0, &size) && if (!GetTokenInformation (my_token, TokenGroups, NULL, 0, &size) &&
GetLastError () != ERROR_INSUFFICIENT_BUFFER) GetLastError () != ERROR_INSUFFICIENT_BUFFER)
debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n"); debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n");
else if (!(my_grps = (PTOKEN_GROUPS) malloc (size))) else if (!(my_grps = (PTOKEN_GROUPS) malloc (size)))
debug_printf ("malloc (my_grps) failed."); debug_printf ("malloc (my_grps) failed.");
@ -751,10 +751,10 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
{ {
grps->Groups[i].Sid = grpsids.sids[i]; grps->Groups[i].Sid = grpsids.sids[i];
grps->Groups[i].Attributes = SE_GROUP_MANDATORY | grps->Groups[i].Attributes = SE_GROUP_MANDATORY |
SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_ENABLED_BY_DEFAULT |
SE_GROUP_ENABLED; SE_GROUP_ENABLED;
if (auth_pos >= 0 && i == (DWORD) auth_pos) if (auth_pos >= 0 && i == (DWORD) auth_pos)
grps->Groups[i].Attributes |= SE_GROUP_LOGON_ID; grps->Groups[i].Attributes |= SE_GROUP_LOGON_ID;
} }
/* Retrieve list of privileges of that user. */ /* Retrieve list of privileges of that user. */
@ -780,7 +780,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
/* Convert to primary token. */ /* Convert to primary token. */
if (!DuplicateTokenEx (token, TOKEN_ALL_ACCESS, &sa, if (!DuplicateTokenEx (token, TOKEN_ALL_ACCESS, &sa,
SecurityImpersonation, TokenPrimary, SecurityImpersonation, TokenPrimary,
&primary_token)) &primary_token))
__seterrno (); __seterrno ();
@ -879,7 +879,7 @@ subauth (struct passwd *pw)
subbuf.auth.ParameterControl = 0 | (subauth_id << 24); subbuf.auth.ParameterControl = 0 | (subauth_id << 24);
/* Try to logon... */ /* Try to logon... */
ret = LsaLogonUser(lsa_hdl, (PLSA_STRING) &origin, Network, ret = LsaLogonUser(lsa_hdl, (PLSA_STRING) &origin, Network,
package_id, &subbuf, sizeof subbuf, package_id, &subbuf, sizeof subbuf,
NULL, &ts, (PVOID *)&profile, &size, NULL, &ts, (PVOID *)&profile, &size,
&luid, &user_token, &quota, &ret2); &luid, &user_token, &quota, &ret2);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
@ -892,7 +892,7 @@ subauth (struct passwd *pw)
LsaFreeReturnBuffer(profile); LsaFreeReturnBuffer(profile);
/* Convert to primary token. */ /* Convert to primary token. */
if (!DuplicateTokenEx (user_token, TOKEN_ALL_ACCESS, &sa, if (!DuplicateTokenEx (user_token, TOKEN_ALL_ACCESS, &sa,
SecurityImpersonation, TokenPrimary, SecurityImpersonation, TokenPrimary,
&primary_token)) &primary_token))
__seterrno (); __seterrno ();
@ -943,7 +943,7 @@ read_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, LPDWORD sd_size)
} }
if (!GetFileSecurity (pfile, if (!GetFileSecurity (pfile,
OWNER_SECURITY_INFORMATION OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION, | DACL_SECURITY_INFORMATION,
sd_buf, *sd_size, &len)) sd_buf, *sd_size, &len))

View File

@ -109,7 +109,7 @@ public:
BOOL add (const PSID nsid) { return add (nsid); } BOOL add (const PSID nsid) { return add (nsid); }
BOOL add (const char *sidstr) BOOL add (const char *sidstr)
{ cygsid nsi (sidstr); return add (nsi); } { cygsid nsi (sidstr); return add (nsi); }
BOOL operator+= (cygsid &si) { return add (si); } BOOL operator+= (cygsid &si) { return add (si); }
BOOL operator+= (const char *sidstr) { return add (sidstr); } BOOL operator+= (const char *sidstr) { return add (sidstr); }

View File

@ -44,6 +44,7 @@ details. */
#include "security.h" #include "security.h"
#include <semaphore.h> #include <semaphore.h>
#include <stdio.h> #include <stdio.h>
#include <sys/timeb.h>
extern int threadsafe; extern int threadsafe;
@ -396,7 +397,7 @@ pthread_cond::pthread_cond (pthread_condattr * attr):verifyable_object (PTHREAD_
NULL /* no name */); NULL /* no name */);
/* TODO: make a shared mem mutex if out attributes request shared mem cond */ /* TODO: make a shared mem mutex if out attributes request shared mem cond */
cond_access=NULL; cond_access=NULL;
if ((temperr = pthread_mutex_init (&this->cond_access, NULL))) if ((temperr = pthread_mutex_init (&this->cond_access, NULL)))
{ {
system_printf ("couldn't init mutex, this %0p errno=%d\n", this, temperr); system_printf ("couldn't init mutex, this %0p errno=%d\n", this, temperr);
/* we need the mutex for correct behaviour */ /* we need the mutex for correct behaviour */
@ -420,12 +421,12 @@ pthread_cond::BroadCast ()
if (pthread_mutex_lock (&cond_access)) if (pthread_mutex_lock (&cond_access))
system_printf ("Failed to lock condition variable access mutex, this %0p\n", this); system_printf ("Failed to lock condition variable access mutex, this %0p\n", this);
int count = waiting; int count = waiting;
if (!verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC)) if (!verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC))
{ {
if (pthread_mutex_unlock (&cond_access)) if (pthread_mutex_unlock (&cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %0p\n", this); system_printf ("Failed to unlock condition variable access mutex, this %0p\n", this);
/* This isn't and API error - users are allowed to call this when no threads /* This isn't and API error - users are allowed to call this when no threads
are waiting are waiting
system_printf ("Broadcast called with invalid mutex\n"); system_printf ("Broadcast called with invalid mutex\n");
*/ */
return; return;
@ -444,8 +445,8 @@ pthread_cond::Signal ()
if (!verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC)) if (!verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC))
{ {
if (pthread_mutex_unlock (&cond_access)) if (pthread_mutex_unlock (&cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %0p\n", system_printf ("Failed to unlock condition variable access mutex, this %0p\n",
this); this);
return; return;
} }
PulseEvent (win32_obj_id); PulseEvent (win32_obj_id);
@ -472,6 +473,7 @@ pthread_cond::TimedWait (DWORD dwMilliseconds)
case WAIT_FAILED: case WAIT_FAILED:
return 0; /* POSIX doesn't allow errors after we modify the mutex state */ return 0; /* POSIX doesn't allow errors after we modify the mutex state */
case WAIT_ABANDONED: case WAIT_ABANDONED:
case WAIT_TIMEOUT:
return ETIMEDOUT; return ETIMEDOUT;
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
return 0; /* we have been signaled */ return 0; /* we have been signaled */
@ -580,23 +582,23 @@ pthread_mutex::pthread_mutex (pthread_mutex_t *mutex, pthread_mutexattr * attr):
char stringbuf[29]; char stringbuf[29];
unsigned short id = 1; unsigned short id = 1;
while (id < 256) while (id < 256)
{ {
snprintf (stringbuf, 29, "CYGWINMUTEX0x%0x", id & 0x000f); snprintf (stringbuf, 29, "CYGWINMUTEX0x%0x", id & 0x000f);
system_printf ("name of mutex to create %s\n",stringbuf); system_printf ("name of mutex to create %s\n",stringbuf);
this->win32_obj_id =::CreateMutex (&sec_none_nih, false, stringbuf); this->win32_obj_id =::CreateMutex (&sec_none_nih, false, stringbuf);
if (this->win32_obj_id && GetLastError () != ERROR_ALREADY_EXISTS) if (this->win32_obj_id && GetLastError () != ERROR_ALREADY_EXISTS)
{ {
MT_INTERFACE->pshared_mutexs[id] = this; MT_INTERFACE->pshared_mutexs[id] = this;
pshared_mutex *pmutex=(pshared_mutex *)(mutex); pshared_mutex *pmutex=(pshared_mutex *)(mutex);
pmutex->id = id; pmutex->id = id;
pmutex->flags = SYS_BASE; pmutex->flags = SYS_BASE;
pshared = PTHREAD_PROCESS_SHARED; pshared = PTHREAD_PROCESS_SHARED;
condwaits = 0; condwaits = 0;
return; return;
} }
id++; id++;
CloseHandle (win32_obj_id); CloseHandle (win32_obj_id);
} }
magic = 0; magic = 0;
win32_obj_id = NULL; win32_obj_id = NULL;
} }
@ -605,7 +607,7 @@ pthread_mutex::pthread_mutex (pthread_mutex_t *mutex, pthread_mutexattr * attr):
this->win32_obj_id =::CreateMutex (&sec_none_nih, false, NULL); this->win32_obj_id =::CreateMutex (&sec_none_nih, false, NULL);
if (!win32_obj_id) if (!win32_obj_id)
magic = 0; magic = 0;
condwaits = 0; condwaits = 0;
pshared = PTHREAD_PROCESS_PRIVATE; pshared = PTHREAD_PROCESS_PRIVATE;
} }
@ -1636,7 +1638,7 @@ int
__pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex,
const struct timespec *abstime) const struct timespec *abstime)
{ {
// and yes cond_access here is still open to a race. (we increment, context swap, // and yes cond_access here is still open to a race. (we increment, context swap,
// broadcast occurs - we miss the broadcast. the functions aren't split properly. // broadcast occurs - we miss the broadcast. the functions aren't split properly.
int rv; int rv;
if (!abstime) if (!abstime)
@ -1654,16 +1656,23 @@ __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex,
return EINVAL; return EINVAL;
if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC)) if (!verifyable_object_isvalid (*cond, PTHREAD_COND_MAGIC))
return EINVAL; return EINVAL;
struct timeb currSysTime;
long waitlength;
ftime(&currSysTime);
waitlength = (abstime->tv_sec - currSysTime.time) * 1000;
if (waitlength < 0)
return ETIMEDOUT;
/* if the cond variable is blocked, then the above timer test maybe wrong. *shrug* */
if (pthread_mutex_lock (&(*cond)->cond_access)) if (pthread_mutex_lock (&(*cond)->cond_access))
system_printf ("Failed to lock condition variable access mutex, this %0p\n", *cond); system_printf ("Failed to lock condition variable access mutex, this %0p\n", *cond);
if ((*cond)->waiting) if ((*cond)->waiting)
if ((*cond)->mutex && ((*cond)->mutex != (*themutex))) if ((*cond)->mutex && ((*cond)->mutex != (*themutex)))
{ {
if (pthread_mutex_unlock (&(*cond)->cond_access)) if (pthread_mutex_unlock (&(*cond)->cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond); system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond);
return EINVAL; return EINVAL;
} }
InterlockedIncrement (&((*cond)->waiting)); InterlockedIncrement (&((*cond)->waiting));
@ -1671,7 +1680,7 @@ __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex,
InterlockedIncrement (&((*themutex)->condwaits)); InterlockedIncrement (&((*themutex)->condwaits));
if (pthread_mutex_unlock (&(*cond)->cond_access)) if (pthread_mutex_unlock (&(*cond)->cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond); system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond);
rv = (*cond)->TimedWait (abstime->tv_sec * 1000); rv = (*cond)->TimedWait (waitlength);
(*cond)->mutex->Lock (); (*cond)->mutex->Lock ();
if (pthread_mutex_lock (&(*cond)->cond_access)) if (pthread_mutex_lock (&(*cond)->cond_access))
system_printf ("Failed to lock condition variable access mutex, this %0p\n", *cond); system_printf ("Failed to lock condition variable access mutex, this %0p\n", *cond);
@ -1708,9 +1717,9 @@ __pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex)
if ((*cond)->waiting) if ((*cond)->waiting)
if ((*cond)->mutex && ((*cond)->mutex != (*themutex))) if ((*cond)->mutex && ((*cond)->mutex != (*themutex)))
{ {
if (pthread_mutex_unlock (&(*cond)->cond_access)) if (pthread_mutex_unlock (&(*cond)->cond_access))
system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond); system_printf ("Failed to unlock condition variable access mutex, this %0p\n", *cond);
return EINVAL; return EINVAL;
} }
InterlockedIncrement (&((*cond)->waiting)); InterlockedIncrement (&((*cond)->waiting));
@ -1856,11 +1865,11 @@ __pthread_mutex_init (pthread_mutex_t * mutex,
mutex = __pthread_mutex_getpshared ((pthread_mutex_t *) mutex); mutex = __pthread_mutex_getpshared ((pthread_mutex_t *) mutex);
if (!verifyable_object_isvalid (*mutex, PTHREAD_MUTEX_MAGIC)) if (!verifyable_object_isvalid (*mutex, PTHREAD_MUTEX_MAGIC))
{ {
delete throwaway; delete throwaway;
*mutex = NULL; *mutex = NULL;
return EAGAIN; return EAGAIN;
} }
return 0; return 0;
} }
*mutex = new pthread_mutex (attr ? (*attr) : NULL); *mutex = new pthread_mutex (attr ? (*attr) : NULL);

View File

@ -5,7 +5,7 @@
Written by Marco Fuykschot <marco@ddi.nl> Written by Marco Fuykschot <marco@ddi.nl>
Major update 2001 Robert Collins <rbtcollins@hotmail.com> Major update 2001 Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin. This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the This software is a copyrighted work licensed under the terms of the
@ -268,11 +268,11 @@ public:
int Lock (); int Lock ();
int TryLock (); int TryLock ();
int UnLock (); int UnLock ();
pthread_mutex (unsigned short); pthread_mutex (unsigned short);
pthread_mutex (pthread_mutexattr *); pthread_mutex (pthread_mutexattr *);
pthread_mutex (pthread_mutex_t *, pthread_mutexattr *); pthread_mutex (pthread_mutex_t *, pthread_mutexattr *);
~pthread_mutex (); ~pthread_mutex ();
}; };
class pthread_condattr:public verifyable_object class pthread_condattr:public verifyable_object
@ -280,8 +280,8 @@ class pthread_condattr:public verifyable_object
public: public:
int shared; int shared;
pthread_condattr (); pthread_condattr ();
~pthread_condattr (); ~pthread_condattr ();
}; };
class pthread_cond:public verifyable_object class pthread_cond:public verifyable_object