diff options
66 files changed, 1523 insertions, 865 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 236125075..3770a2ac8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -278,6 +278,348 @@ Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/sys/ipc.h: New file. * include/sys/shm.h: New file. +2002-02-27 Christopher Faylor <cgf@redhat.com> + + * include/cygwin/version.h: Bump DLL minor number. + +2002-02-23 Corinna Vinschen <corinna@vinschen.de> + + * cygwin.din (fstat64): New symbol. + (ftruncate64): Ditto. + (lseek64): Ditto. + (lstat64): Ditto. + (mmap64): Ditto. + (seekdir64): Ditto. + (stat64): Ditto. + (telldir64): Ditto. + (truncate64): Ditto. + * dir.cc (telldir64): New function. + (telldir): Call telldir64(). + (seekdir64): New function. + (seekdir): Call seekdir64(). + * fhandler.h: Redefine all methods using __off32_t to use __off64_t. + * fhandler.cc: Use __off64_t and struct __stat64 throughout. + * fhandler_clipboard.cc: Ditto. + * fhandler_disk_file.cc: Ditto. + * fhandler_dsp.cc: Ditto. + * fhandler_floppy.cc: Ditto. + * fhandler_mem.cc: Ditto. + * fhandler_random.cc: Ditto. + * fhandler_socket.cc: Ditto. + * fhandler_tape.cc: Ditto. + * fhandler_zero.cc: Ditto. + * pipe.cc: Ditto. + * glob.c: Ditto, call lstat64 and stat64 in Cygwin. + * mmap.cc: Use __off64_t throughout. + (mmap64): New function. + * sec_acl.cc (acl_worker): Use struct __stat64, call stat64 and lstat64. + * syscalls.cc (lseek64): New function. + (stat64_to_stat32): Ditto. + (fstat64): Ditto. + (stat64): Ditto. + (lstat64): Ditto. + (ftruncate64): Ditto. + (truncate64): Ditto. + (_fstat): Call fstat64. + (_stat): Call stat64. + (cygwin_lstat): Rename to avoid declaration problem. Call lstat64. + (stat_worker): Use struct __stat64. + (access): Ditto. + (ftruncate): Call ftruncate64. + (truncate): Call truncate64. + * wincap.cc: Set flag has_64bit_file_access appropriately. + * wincap.h: Add flag has_64bit_file_access. + * winsup.h (ILLEGAL_SEEK): Define as __off64_t. + (stat_dev): Declare using struct __stat64. + (stat_worker): Ditto. + * include/cygwin/stat.h (struct __stat32): Define if compiling Cygwin. + (struct __stat64): Ditto. + (struct stat): Revert definition with explicitly sized datatypes. + Eliminate sized field names. + * include/cygwin/types.h (blksize_t): New type. + (__blkcnt32_t): Ditto. + (__blkcnt64_t): Ditto. + (blkcnt_t): Ditto. + +2002-02-22 Christopher Faylor <cgf@redhat.com> + + * sync.h (new_muto): Just accept an argument which denotes the name of + the muto. Use this argument to construct static storage. + * cygheap.cc (cygheap_init): Reflect above change. + * exceptions.cc (events_init): Ditto. + * malloc.cc (malloc_init): Ditto. + * path.cc (cwdstuff::init): Ditto. + * cygheap.h (cwdstuff): Change name of lock element to make it less + generic. + * path.cc (cwdstuff::get_hash): Ditto. + (cwdstuff::get_initial): Ditto. + (cwdstuff::set): Ditto. + (cwdstuff::get): Ditto. + * sigproc.cc (proc_subproc): Ditto. + + * debug.cc (lock_debug): Change to method. Use method rather than + macro throughout. + + * tty.h (tty_min::kill_pgrp): Declare new method. + * fhandler_termios.cc (tty_min::kill_pgrp): New method. + (fhandler_termios::line_edit): Use new method for killing process. + * dcrt0.cc (do_exit): Ditto. + + * dtable.cc (dtable::get_debugger_info): New method for inheriting + dtable info from a debugger. + * tty.cc (tty_init): Attempt to grab file handle info from parent + debugger, if appropriate. + + # dtable.cc (dtable::stdio_init): Make this a method. + (dtable::init_std_file_from_handle): Don't set fd unless it's not open. + (dtable::build_fhandler_from_name): Move name setting to + dtable::build_fhandler. + (dtable::build_fhandler): Add win32 name parameter. + * dcrt0.cc (dll_crt0_1): Change to use dtable stdio_init. + * dtable.h (dtable): Reflect build_fhandler parameter change. + * mmap.cc (mmap_record::alloc_fh): Don't set name parameter in + build_fhandler. + * net.cc (fdsock): Remove set_name call since it is now handled by + build_fhandler. + + * sigproc.cc (proc_subproc): Release muto as early as possible. + +2001-02-22 Corinna Vinschen <corinna@vinschen.de> + + * smallprint.c (rn): Allow long long values. + (__small_vsprintf): Add 'D', 'U' and 'X' formats for long long + parameters. + +2002-02-19 Christopher Faylor <cgf@redhat.com> + + * fhandler.cc (fhandler_base::puts_readahead): Remove default parameter + setting. Newer gcc's complain about this. + (fhandler_base::set_readahead_valid): Ditto. + * fhandler_dsp.cc (Audio::open): Ditto. + (fhandler_dev_dsp::open): Ditto. + +2002-02-19 Christopher Faylor <cgf@redhat.com> + + * fork.cc (fork_parent): Use sec_user_nih to control process/thread + inheritance/permission. + * spawn.cc (spawn_guts): Ditto. + * security.cc (create_token): Initialize token so that it is not tested + for bogus value later. Use sec_user to control process/thread + creation. + * security.h (__sec_user): Rename declaration from sec_user. + (sec_user_nih): Declare here as inline function wrapper for __sec_user. + (sec_user): Ditto. + * sigproc.cc (czombies): Allocate a character array for zombies to + avoid constructor overhead + (extremely hackish, I know). + (cpchildren): Ditto. + (pchildren): New define. + (zombies): Ditto. + (getsem): Use sec_user_nih to control semaphore inheritance/permission. + +2002-02-16 Christopher Faylor <cgf@redhat.com> + + * times.cc (hires::prime): Restore thread priority on failure + condition. + + * uinfo.cc (uinfo_init): Use more robust method for determining if + process was invoked from a non-cygwin process. + + * sync.h (muto::init): Eliminate "inheritance" parameter. + (new_muto): Reflect removal of parameter. + * sync.cc (muto::init): Ditto. + * cygheap.cc (cygheap_init): Ditto. + * debug.cc (threadname_init): Ditto. + * exceptions.cc (events_init): Ditto. + * malloc.cc (malloc_init): Ditto. + * path.cc (cwdstuff::init): Ditto. + * sigproc.cc (sigproc_init): Ditto. + + * grp.cc (group_lock): Use different method for locking with static + member. + (read_etc_group): REALLY ensure that read lock mutex is released. + * passwd.cc (passwd_lock): Use different method for locking with static + member. + (read_etc_passwd): REALLY ensure that read lock mutex is released. + + * shared.cc (sec_user): Correct reversed inheritance test. + +2002-02-15 Christopher Faylor <cgf@redhat.com> + + * hires.h (hires::usecs): Rename from utime. Accept an argument. + * strace.cc (strace::microseconds): Use hires class for calculating + times. + * sync.h (new_muto): Use NO_COPY explicitly in declaration. + * times.cc (gettimeofday): Reflect change in usecs argument. + (hires::usecs): Ditto. Changed name from utime. + * winsup.h (NO_COPY): Add nocommon attribute to force setting aside + space for variable. + * regcomp.c (REQUIRE): Add a void cast to bypass a warning. + +2002-02-15 Christopher Faylor <cgf@redhat.com> + + * hires.h: New file. + * times.cc (gettimeofday): Use hires class for calculating current time. + (hires::prime): New method. + (hires::utime): Ditto. + +2002-02-14 Christopher Faylor <cgf@redhat.com> + + * include/sys/cygwin.h (cygwin_getinfo_types): New CW_STRACE_ACTIVE. + * external.cc (cygwin_internal): Handle CW_STRACE_ACTIVE. + +2002-02-14 Christopher Faylor <cgf@redhat.com> + + * exceptions.cc (unused_sig_wrapper): Eliminate unused parameter to + asm. + * external.cc (cygwin_internal): Change CW_STRACE_ON to + CW_STRACE_TOGGLE. + * strace.cc (strace::hello): Toggle strace on and off. + * sync.cc (muto::init): Renamed from constructor. + * sync.h (muto::new): Delete. + (muto::delete): Ditto. + (new_muto): Simplify. Use muto.init for nearly everything. + * uinfo.cc (uinfo_init): Avoid closing a NULL handle. + * include/sys/cygwin.h (cygwin_getinfo_types): Rename CW_STRACE_OFF to + CW_STRACE_TOGGLE. Delete CW_STRACE_OFF. + * include/sys/strace.h (strace): Add "inited" field. + +2001-02-12 Corinna Vinschen <corinna@vinschen.de> + + * include/cygwin/acl.h: Fix definition of aclent_t. + +2002-02-10 Christopher Faylor <cgf@redhat.com> + + * Makefile.in (DLL_OFILES): Consolidate object files. + +2002-02-10 Corinna Vinschen <corinna@vinschen.de> + + * child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc, + fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc, + fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc, + pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc, + security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright. + +2002-02-10 Corinna Vinschen <corinna@vinschen.de> + + * child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h, + fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc, + fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc, + fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc, + pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc, + security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h: + Change usage of uid_t to __uid16_t, gid_t to __gid16_t and + off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and + INVALID_SEEK instead casting -1 to the appropriate type. + * winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK. + * include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t + types. Don't declare acl functions when compiling Cygwin. + * include/cygwin/grp.h: Declare getgrgid() and getgrnam() with + correct types for internal usage. + +2002-02-10 Corinna Vinschen <corinna@vinschen.de> + + Patch suggested by Pierre A. Humblet <Pierre.Humblet@ieee.org>: + * uinfo.cc (internal_getlogin): Try evaluating user by SID even if + ntsec is off. + (uinfo_init): Set primary group even if ntsec is off. + +2002-02-09 Corinna Vinschen <corinna@vinschen.de> + + * include/cygwin/grp.h: New file. + * include/cygwin/stat.h: Ditto. + * include/cygwin/types.h: Add definitions for __off32_t, + __off64_t, off_t, __uid16_t, __uid32_t, uid_t, __gid16_t, + __gid32_t and gid_t. + * include/sys/cygwin.h: Use correct uid and gid types. + +2002-02-09 Corinna Vinschen <corinna@vinschen.de> + + * dtable.cc (dtable::dup2): Revert previous patch. + * fhandler.h: Ditto. + (fhandler_socket::recv): Define new method. + (fhandler_socket::send): Ditto. + * fhandler_socket.cc (fhandler_socket::recv): New method. + (fhandler_socket::send): Ditto. + (fhandler_socket::read): Call fhandler_socket::recv() now. + (fhandler_socket::write): Call fhandler_socket::send() now. + * net.cc (class wsock_event): Move definition to wsock_event.h. + (fdsock): Revert previous patch. + (cygwin_recv): Move implementation to fhandler_socket::recv(). + (cygwin_send): Move implementation to fhandler_socket::send(). + * wsock_event.h: New file. + +2002-02-06 Alexander Gottwald <Alexander.Gottwald@s1999.tuchemnitz.de> + + * net.cc (get_2k_ifconf): Create interface entries for tokenring cards. + +2002-02-08 Corinna Vinschen <corinna@vinschen.de> + + * dtable.cc (dtable::dup2): Store fd for fhandler_socket. + * fhandler.h (fhandler_base::set_fd): New virtual method. + (fhandler_base::get_fd): Ditto. + (fhandler_socket::set_fd): Ditto. + (fhandler_socket::get_fd): Ditto. + * fhandler_socket.cc (fhandler_socket::read): Call cygwin_recv instead + of native Winsock recv. + (fhandler_socket::write): Call cygwin_send instead of native Winsock + send. + * net.cc (fdsock): Store fd in fhandler_socket. + +2002-02-07 Corinna Vinschen <corinna@vinschen.de> + + * net.cc (cygwin_getsockname): Fix handling of NULL sun_path. + +2002-01-29 Corinna Vinschen <corinna@vinschen.de> + + * net.cc (getdomainname): Fix registry key for 9x systems, too. + +2002-01-29 Corinna Vinschen <corinna@vinschen.de> + + * net.cc (getdomainname): Fix registry key for NT systems. + +2002-01-28 Christopher Faylor <cgf@redhat.com> + + * external.cc (cygwin_internal): Initialize various internal settings + if required to allow use of some things from user loaded DLL. + (CW_STRACE_ON): Add new feature. + (CW_CYGWIN_PID_TO_WINPID): Ditto. + * pinfo.cc (set_myself): Call "strace.hello" to initiate possible + strace session. + (pinfo::init): Guard against dereferencing uninitialized myself. + * sigproc.cc (wait_sig): Call strace.hello() when __SIGTRACE "signal" + received. + * strace.cc (strace::hello): New method. + * wincap.cc (wincapc::init): Avoid initializing if already initialized. + * wincap.h (wincapc::wincapc): New method. + * include/sys/cygwin.h: Add new CW_ enums. Kludge typedefs of + {g,u}id_t if required. + * strace.h (strace::hello): Declare new method. + +2002-01-28 Earnie Boyd <earnie@users.sf.net> + + * include/sys/strace.h (_STRACE_ON): Define. + (_STRACE_OFF): Ditto. + +2002-01-24 Christopher Faylor <cgf@redhat.com> + + * speclib: Ensure that temporary def file is removed. + +2002-01-23 Christopher Faylor <cgf@redhat.com> + + * speclib: Use rm -f to remove temp file just to quiet any potential + warnings. + +2002-01-23 Corinna Vinschen <corinna@vinschen.de> + + * security.cc (create_token): Use sec_user() to create + SECURITY_ATTRIBUTES structure for primary token. Use + MAXIMUM_ALLOWED access rights instead of TOKEN_ALL_ACCESS. + +2002-01-23 Corinna Vinschen <corinna@vinschen.de> + + * path.cc (symlink): Fix check for already existing file. + 2002-01-21 Christopher Faylor <cgf@redhat.com> * cygmagic: Suppress error output when figuring out if sum takes an diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index cd2fb3442..30cf31fdd 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -117,18 +117,16 @@ MALLOC_OFILES=@MALLOC_OFILES@ DLL_IMPORTS:=$(w32api_lib)/libkernel32.a -DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o \ - cygserver_transport.o cygserver_transport_pipes.o cygserver_transport_sockets.o \ - dcrt0.o debug.o \ - delqueue.o dir.o \ - dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o exec.o \ - external.o fcntl.o fhandler.o fhandler_clipboard.o fhandler_console.o \ +# Please maintain this list in sorted order, with maximum files per line +DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o cygserver_transport.o \ + cygserver_transport_pipes.o cygserver_transport_sockets.o dcrt0.o debug.o \ + delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o \ + exec.o external.o fcntl.o fhandler.o fhandler_clipboard.o fhandler_console.o \ fhandler_disk_file.o fhandler_dsp.o fhandler_floppy.o fhandler_mem.o \ fhandler_random.o fhandler_raw.o fhandler_serial.o fhandler_socket.o \ fhandler_tape.o fhandler_termios.o fhandler_tty.o fhandler_windows.o \ - fhandler_zero.o fnmatch.o \ - fork.o glob.o grp.o heap.o init.o ioctl.o ipc.o localtime.o \ - malloc.o miscfuncs.o mmap.o net.o ntea.o passwd.o path.o \ + fhandler_zero.o fnmatch.o fork.o glob.o grp.o heap.o init.o ioctl.o ipc.o \ + localtime.o malloc.o miscfuncs.o mmap.o net.o ntea.o passwd.o path.o \ pinfo.o pipe.o poll.o pthread.o regcomp.o regerror.o regexec.o \ regfree.o registry.o resource.o scandir.o sched.o sec_acl.o \ sec_helper.o security.o select.o shared.o shm.o shortcut.o signal.o \ diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h index 4b249a808..e79ca3947 100644 --- a/winsup/cygwin/child_info.h +++ b/winsup/cygwin/child_info.h @@ -1,6 +1,6 @@ /* childinfo.h: shared child info for cygwin - Copyright 2000 Red Hat, Inc. + Copyright 2000, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -70,7 +70,7 @@ class fhandler_base; class cygheap_exec_info { public: - uid_t uid; + __uid16_t uid; char *old_title; int argc; char **argv; diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 79fb48410..5d770746b 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -197,7 +197,7 @@ _csbrk (int sbs) extern "C" void __stdcall cygheap_init () { - cygheap_protect = new_muto (FALSE, "cygheap_protect"); + new_muto (cygheap_protect); _csbrk (0); if (!cygheap->fdtab) cygheap->fdtab.init (); diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index d3025b452..ec7624bea 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -1,6 +1,6 @@ /* cygheap.h: Cygwin heap manager. - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -96,10 +96,10 @@ class cygheap_user char *pdomain; /* Logon domain of the user */ PSID psid; /* buffer for user's SID */ public: - uid_t orig_uid; /* Remains intact even after impersonation */ - uid_t orig_gid; /* Ditto */ - uid_t real_uid; /* Remains intact on seteuid, replaced by setuid */ - gid_t real_gid; /* Ditto */ + __uid16_t orig_uid; /* Remains intact even after impersonation */ + __uid16_t orig_gid; /* Ditto */ + __uid16_t real_uid; /* Remains intact on seteuid, replaced by setuid */ + __gid16_t real_gid; /* Ditto */ /* token is needed if set(e)uid should be called. It can be set by a call to `set_impersonation_token()'. */ @@ -140,7 +140,7 @@ struct cwdstuff char *posix; char *win32; DWORD hash; - muto *lock; + muto *cwd_lock; char *get (char *buf, int need_posix = 1, int with_chroot = 0, unsigned ulen = MAX_PATH); DWORD get_hash (); void init (); diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 5e472c82d..927d44395 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -304,6 +304,7 @@ fsetpos _fsetpos = fsetpos fstat _fstat = fstat +fstat64 fstatfs _fstatfs = fstatfs fsync @@ -318,6 +319,7 @@ ftime _ftime = ftime ftruncate _ftruncate = ftruncate +ftruncate64 fwrite _fwrite = fwrite gamma @@ -510,8 +512,10 @@ longjmp _longjmp = longjmp lseek _lseek = lseek -lstat -_lstat = lstat +lseek64 +lstat = cygwin_lstat +_lstat = cygwin_lstat +lstat64 malloc = export_malloc _malloc = export_malloc matherr @@ -544,6 +548,7 @@ _mktemp = mktemp mktime _mktime = mktime mmap +mmap64 mprotect msync munmap @@ -646,6 +651,7 @@ _scanf_r scanf_r = _scanf_r seekdir _seekdir = seekdir +seekdir64 setbuf _setbuf = setbuf setdtablesize @@ -745,6 +751,7 @@ _sscanf_r sscanf_r = _sscanf_r stat _stat = stat +stat64 statfs _statfs = statfs strcasecmp @@ -841,6 +848,7 @@ tcsetpgrp _tcsetpgrp = tcsetpgrp telldir _telldir = telldir +telldir64 tempnam _tempnam = tempnam time @@ -860,6 +868,7 @@ toupper _toupper = toupper truncate _truncate = truncate +truncate64 ttyname _ttyname = ttyname tzset diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index fadde6ff6..38b1df06d 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -625,7 +625,7 @@ dll_crt0_1 () } if (child_proc_info->subproc_ready) ProtectHandle (child_proc_info->subproc_ready); - if (myself->uid == USHRT_MAX) + if (myself->uid == ILLEGAL_UID) cygheap->user.set_sid (NULL); break; } @@ -723,7 +723,7 @@ dll_crt0_1 () user_data->premain[i] (__argc, __argv, user_data); /* Set up standard fds in file descriptor table. */ - stdio_init (); + cygheap->fdtab.stdio_init (); /* Set up __progname for getopt error call. */ __progname = __argv[0]; @@ -797,7 +797,6 @@ initial_env () } } - /* Wrap the real one, otherwise gdb gets confused about two symbols with the same name, but different addresses. @@ -983,7 +982,7 @@ do_exit (int status) /* CGF FIXME: This can't be right. */ if (tp->getsid () == myself->sid) - kill_pgrp (tp->getpgid (), SIGHUP); + tp->kill_pgrp (SIGHUP); } tty_terminate (); diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index 76cce92ff..abb4457d4 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -37,7 +37,7 @@ static NO_COPY thread_info threads[32] = {{0, NULL}}; // increase as necessary void threadname_init () { - threadname_lock = new_muto (FALSE, "threadname_lock"); + new_muto (threadname_lock); } void __stdcall @@ -184,18 +184,19 @@ static handle_list NO_COPY freeh[1000] = {{0, NULL, NULL, NULL, 0, 0, NULL}}; static muto NO_COPY *debug_lock = NULL; -#define lock_debug() \ - do {if (debug_lock) debug_lock->acquire (INFINITE); } while (0) - -#define unlock_debug() \ - do {if (debug_lock) debug_lock->release (); } while (0) +struct lock_debug +{ + lock_debug () {if (debug_lock) debug_lock->acquire (INFINITE);} + void unlock () {if (debug_lock) debug_lock->release ();} + ~lock_debug () {unlock ();} +}; static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL); void debug_init () { - debug_lock = new_muto (FALSE, "debug_lock"); + new_muto (debug_lock); } /* Find a registered handle in the linked list of handles. */ @@ -229,7 +230,8 @@ static handle_list * __stdcall newh () { handle_list *hl; - lock_debug (); + lock_debug here; + for (hl = freeh; hl < freeh + NFREEH; hl++) if (hl->name == NULL) goto out; @@ -242,7 +244,6 @@ newh () } out: - unlock_debug (); return hl; } @@ -251,7 +252,7 @@ void __stdcall add_handle (const char *func, int ln, HANDLE h, const char *name) { handle_list *hl; - lock_debug (); + lock_debug here; if ((hl = find_handle (h))) { @@ -260,12 +261,12 @@ add_handle (const char *func, int ln, HANDLE h, const char *name) ln, name, h); system_printf (" previously allocated by %s:%d(%s<%p>)", hl->func, hl->ln, hl->name, hl->h); - goto out; /* Already did this once */ + return; } if ((hl = newh ()) == NULL) { - unlock_debug (); + here.unlock (); system_printf ("couldn't allocate memory for %s(%d): %s(%p)", func, ln, name, h); return; @@ -278,8 +279,7 @@ add_handle (const char *func, int ln, HANDLE h, const char *name) endh->next = hl; endh = hl; -out: - unlock_debug (); + return; } static void __stdcall @@ -306,11 +306,12 @@ static bool __stdcall mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force) { handle_list *hl; - lock_debug (); + lock_debug here; + if ((hl = find_handle (h)) && !force) { hl = hl->next; - unlock_debug (); // race here + here.unlock (); // race here system_printf ("attempt to close protected handle %s:%d(%s<%p>)", hl->func, hl->ln, hl->name, hl->h); system_printf (" by %s:%d(%s<%p>)", func, ln, name, h); @@ -328,7 +329,6 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force) if (hl) delete_handle (hl); - unlock_debug (); return TRUE; } @@ -338,14 +338,13 @@ BOOL __stdcall close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) { BOOL ret; - lock_debug (); + lock_debug here; if (!mark_closed (func, ln, h, name, force)) return FALSE; ret = CloseHandle (h); - unlock_debug (); #if 0 /* Uncomment to see CloseHandle failures */ if (!ret) small_printf ("CloseHandle(%s) failed %s:%d\n", name, func, ln); @@ -353,7 +352,6 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) return ret; } -/* Add a handle to the linked list of known handles. */ int __stdcall __set_errno (const char *func, int ln, int val) { diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index 1134c45e0..0294c09ca 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -118,9 +118,8 @@ readdir (DIR *dir) return ((fhandler_base *) dir->__d_u.__d_data.__fh)->readdir (dir); } -/* telldir */ -extern "C" off_t -telldir (DIR *dir) +extern "C" __off64_t +telldir64 (DIR *dir) { if (check_null_invalid_struct_errno (dir)) return -1; @@ -130,9 +129,15 @@ telldir (DIR *dir) return ((fhandler_base *) dir->__d_u.__d_data.__fh)->telldir (dir); } -/* seekdir */ +/* telldir */ +extern "C" __off32_t +telldir (DIR *dir) +{ + return telldir64 (dir); +} + extern "C" void -seekdir (DIR *dir, off_t loc) +seekdir64 (DIR *dir, __off64_t loc) { if (check_null_invalid_struct_errno (dir)) return; @@ -142,6 +147,13 @@ seekdir (DIR *dir, off_t loc) return ((fhandler_base *) dir->__d_u.__d_data.__fh)->seekdir (dir, loc); } +/* seekdir */ +extern "C" void +seekdir (DIR *dir, __off32_t loc) +{ + seekdir64 (dir, (__off64_t)loc); +} + /* rewinddir: POSIX 5.1.2.1 */ extern "C" void rewinddir (DIR *dir) diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index f09ddec6c..f70e41599 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -34,7 +34,7 @@ details. */ #include "cygheap.h" static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, - STD_ERROR_HANDLE}; + STD_ERROR_HANDLE}; /* Set aside space for the table of fds */ void @@ -90,49 +90,75 @@ dtable::extend (int howmuch) return 1; } +void +dtable::get_debugger_info () +{ + if (IsDebuggerPresent ()) + { + char std[3][sizeof ("/dev/ttyNNNN")]; + std[0][0] = std[1][0] = std [2][0] = '\0'; + char buf[sizeof ("cYgstd %x") + 32]; + sprintf (buf, "cYgstd %x %x %x", (unsigned) &std, sizeof (std[0]), 3); + OutputDebugString (buf); + for (int i = 0; i < 3; i++) + if (std[i][0]) + { + path_conv pc; + HANDLE h = GetStdHandle (std_consts[i]); + fhandler_base *fh = build_fhandler_from_name (i, std[i], NULL, pc); + if (!fh) + continue; + if (!fh->open (&pc, (i ? O_WRONLY : O_RDONLY) | O_BINARY, 0777)) + release (i); + else + CloseHandle (h); + } + } +} + /* Initialize the file descriptor/handle mapping table. This function should only be called when a cygwin function is invoked by a non-cygwin function, i.e., it should only happen very rarely. */ void -stdio_init (void) +dtable::stdio_init () { extern void set_console_ctty (); /* Set these before trying to output anything from strace. Also, always set them even if we're to pick up our parent's fds in case they're missed. */ - if (!myself->ppid_handle && NOTSTATE (myself, PID_CYGPARENT)) - { - HANDLE in = GetStdHandle (STD_INPUT_HANDLE); - HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE); - HANDLE err = GetStdHandle (STD_ERROR_HANDLE); + if (myself->ppid_handle || ISSTATE (myself, PID_CYGPARENT)) + return; + + HANDLE in = GetStdHandle (STD_INPUT_HANDLE); + HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE); + HANDLE err = GetStdHandle (STD_ERROR_HANDLE); - cygheap->fdtab.init_std_file_from_handle (0, in, GENERIC_READ); + init_std_file_from_handle (0, in, GENERIC_READ); - /* STD_ERROR_HANDLE has been observed to be the same as - STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes - to pass data from child to parent). */ - if (out == err) + /* STD_ERROR_HANDLE has been observed to be the same as + STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes + to pass data from child to parent). */ + if (out == err) + { + /* Since this code is not invoked for forked tasks, we don't have + to worry about the close-on-exec flag here. */ + if (!DuplicateHandle (hMainProc, out, hMainProc, &err, 0, + 1, DUPLICATE_SAME_ACCESS)) { - /* Since this code is not invoked for forked tasks, we don't have - to worry about the close-on-exec flag here. */ - if (!DuplicateHandle (hMainProc, out, hMainProc, &err, 0, - 1, DUPLICATE_SAME_ACCESS)) - { - /* If that fails, do this as a fall back. */ - err = out; - system_printf ("couldn't make stderr distinct from stdout"); - } + /* If that fails, do this as a fall back. */ + err = out; + system_printf ("couldn't make stderr distinct from stdout"); } - - cygheap->fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE); - cygheap->fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE); - /* Assign the console as the controlling tty for this process if we actually - have a console and no other controlling tty has been assigned. */ - if (myself->ctty < 0 && GetConsoleCP () > 0) - set_console_ctty (); } + + init_std_file_from_handle (1, out, GENERIC_WRITE); + init_std_file_from_handle (2, err, GENERIC_WRITE); + /* Assign the console as the controlling tty for this process if we actually + have a console and no other controlling tty has been assigned. */ + if (myself->ctty < 0 && GetConsoleCP () > 0) + set_console_ctty (); } int @@ -196,6 +222,9 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) first_fd_for_open = 0; + if (!not_open (fd)) + return; + if (!handle || handle == INVALID_HANDLE_VALUE) { fds[fd] = NULL; @@ -258,14 +287,13 @@ dtable::build_fhandler_from_name (int fd, const char *name, HANDLE handle, return NULL; } - fhandler_base *fh = build_fhandler (fd, pc.get_devn (), name, pc.get_unitn ()); - fh->set_name (name, pc, pc.get_unitn ()); - return fh; + return build_fhandler (fd, pc.get_devn (), name, pc, pc.get_unitn ()); } #define cnew(name) new ((void *) ccalloc (HEAP_FHANDLER, 1, sizeof (name))) name fhandler_base * -dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit) +dtable::build_fhandler (int fd, DWORD dev, const char *unix_name, + const char *win32_name, int unit) { fhandler_base *fh; @@ -340,6 +368,20 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit) fh = NULL; } + if (unix_name) + { + char new_win32_name[strlen (unix_name) + 1]; + if (!win32_name) + { + char *p; + /* FIXME: ? Should we call win32_device_name here? + It seems like overkill, but... */ + win32_name = strcpy (new_win32_name, unix_name); + for (p = (char *) win32_name; (p = strchr (p, '/')); p++) + *p = '\\'; + } + fh->set_name (unix_name, win32_name, fh->get_unit ()); + } debug_printf ("fd %d, fh %p", fd, fh); return fd >= 0 ? (fds[fd] = fh) : fh; } diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index ebf8ab2a9..47e0a3b78 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -48,8 +48,8 @@ public: void fixup_before_exec (DWORD win_proc_id); void fixup_before_fork (DWORD win_proc_id); void fixup_after_fork (HANDLE); - fhandler_base *build_fhandler (int fd, DWORD dev, const char *name, - int unit = -1); + fhandler_base *build_fhandler (int fd, DWORD dev, const char *unix_name, + const char *win32_name = NULL, int unit = -1); fhandler_base *build_fhandler_from_name (int fd, const char *name, HANDLE h, path_conv& pc, unsigned opts = PC_SYM_FOLLOW, @@ -75,6 +75,8 @@ public: select_record *select_write (int fd, select_record *s); select_record *select_except (int fd, select_record *s); operator fhandler_base **() {return fds;} + void stdio_init (); + void get_debugger_info (); }; void dtable_init (void); diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index cf7aaa5e6..1bca810dd 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1112,7 +1112,7 @@ events_init (void) api_fatal ("can't create title mutex, %E"); ProtectHandle (title_mutex); - mask_sync = new_muto (FALSE, "mask_sync"); + new_muto (mask_sync); windows_system_directory[0] = '\0'; (void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2); char *end = strchr (windows_system_directory, '\0'); @@ -1220,14 +1220,14 @@ _sigdelayed0: \n\ pushl %%ecx \n\ pushl %%ebx \n\ pushl %%eax \n\ - pushl %7 # saved errno \n\ + pushl %6 # saved errno \n\ pushl %3 # oldmask \n\ pushl %4 # signal argument \n\ pushl $_sigreturn \n\ \n\ call _reset_signal_arrived@0 \n\ pushl %5 # signal number \n\ - pushl %8 # newmask \n\ + pushl %7 # newmask \n\ movl $0,%0 # zero the signal number as a \n\ # flag to the signal handler thread\n\ # that it is ok to set up sigsave\n\ @@ -1238,7 +1238,7 @@ _sigdelayed0: \n\ __no_sig_end: \n\ " : "=m" (sigsave.sig) : "m" (&_impure_ptr->_errno), "g" (sigsave.retaddr), "g" (sigsave.oldmask), "g" (sigsave.sig), - "g" (sigsave.func), "o" (pid_offset), "g" (sigsave.saved_errno), "g" (sigsave.newmask) + "g" (sigsave.func), "g" (sigsave.saved_errno), "g" (sigsave.newmask) ); } } diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 1589e92a1..06f131f24 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -26,6 +26,8 @@ details. */ #include "path.h" #include "dtable.h" #include "cygheap.h" +#include "wincap.h" +#include "heap.h" static external_pinfo * fillout_pinfo (pid_t pid, int winpid) @@ -121,6 +123,16 @@ cygwin_internal (cygwin_getinfo_types t, ...) { va_list arg; va_start (arg, t); + if (t != CW_USER_DATA) + { + wincap.init (); + if (!myself) + { + memory_init (); + malloc_init (); + set_myself (1); + } + } switch (t) { @@ -194,6 +206,32 @@ cygwin_internal (cygwin_getinfo_types t, ...) # undef cr } + case CW_STRACE_TOGGLE: + { + pid_t pid = va_arg (arg, pid_t); + pinfo p (pid); + if (p) + { + sig_send (p, __SIGSTRACE); + return 0; + } + else + { + set_errno (ESRCH); + return (DWORD) -1; + } + } + + case CW_STRACE_ACTIVE: + { + return strace.active; + } + + case CW_CYGWIN_PID_TO_WINPID: + { + pinfo p (va_arg (arg, pid_t)); + return p ? p->dwProcessId : 0; + } default: return (DWORD) -1; } diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index a36ef0b13..cb74ffa28 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -27,6 +27,7 @@ details. */ #include "sigproc.h" #include "pinfo.h" #include <assert.h> +#include <limits.h> static NO_COPY const int CHUNK_SIZE = 1024; /* Used for crlf conversions */ @@ -49,7 +50,7 @@ fhandler_base::operator =(fhandler_base &x) } int -fhandler_base::puts_readahead (const char *s, size_t len = (size_t) -1) +fhandler_base::puts_readahead (const char *s, size_t len) { int success = 1; while ((*s || (len != (size_t) -1 && len--)) @@ -98,7 +99,7 @@ fhandler_base::peek_readahead (int queryput) } void -fhandler_base::set_readahead_valid (int val, int ch = -1) +fhandler_base::set_readahead_valid (int val, int ch) { if (!val) ralen = raixget = raixput = 0; @@ -693,10 +694,22 @@ fhandler_base::write (const void *ptr, size_t len) return res; } -off_t -fhandler_base::lseek (off_t offset, int whence) +__off64_t +fhandler_base::lseek (__off64_t offset, int whence) { - off_t res; + __off64_t res; + + /* 9x/Me doesn't support 64bit offsets. We trap that here and return + EINVAL. It doesn't make sense to simulate bigger offsets by a + SetFilePointer sequence since FAT and FAT32 don't support file + size >= 4GB anyway. */ + if (!wincap.has_64bit_file_access () + && (offset < LONG_MIN || offset > LONG_MAX)) + { + debug_printf ("Win9x, offset not 32 bit."); + set_errno (EINVAL); + return (__off64_t)-1; + } /* Seeks on text files is tough, we rewind and read till we get to the right place. */ @@ -708,70 +721,16 @@ fhandler_base::lseek (off_t offset, int whence) set_readahead_valid (0); } - debug_printf ("lseek (%s, %d, %d)", unix_path_name, offset, whence); - -#if 0 /* lseek has no business messing about with text-mode stuff */ - - if (!get_r_binary ()) - { - int newplace; - - if (whence == 0) - { - newplace = offset; - } - else if (whence ==1) - { - newplace = rpos + offset; - } - else - { - /* Seek from the end of a file.. */ - if (rsize == -1) - { - /* Find the size of the file by reading till the end */ - - char b[CHUNK_SIZE]; - while (read (b, sizeof (b)) > 0) - ; - rsize = rpos; - } - newplace = rsize + offset; - } - - if (rpos > newplace) - { - SetFilePointer (handle, 0, 0, 0); - rpos = 0; - } - - /* You can never shrink something more than 50% by turning CRLF into LF, - so we binary chop looking for the right place */ - - while (rpos < newplace) - { - char b[CHUNK_SIZE]; - size_t span = (newplace - rpos) / 2; - if (span == 0) - span = 1; - if (span > sizeof (b)) - span = sizeof (b); - - debug_printf ("lseek (%s, %d, %d) span %d, rpos %d newplace %d", - name, offset, whence,span,rpos, newplace); - read (b, span); - } - - debug_printf ("Returning %d", newplace); - return newplace; - } -#endif /* end of deleted code dealing with text mode */ + debug_printf ("lseek (%s, %D, %d)", unix_path_name, offset, whence); DWORD win32_whence = whence == SEEK_SET ? FILE_BEGIN : (whence == SEEK_CUR ? FILE_CURRENT : FILE_END); - res = SetFilePointer (get_handle(), offset, 0, win32_whence); - if (res == -1) + LONG off_low = offset & 0xffffffff; + LONG off_high = wincap.has_64bit_file_access () ? offset >> 32 : 0; + + res = SetFilePointer (get_handle(), off_low, &off_high, win32_whence); + if (res == INVALID_SET_FILE_POINTER && GetLastError ()) { __seterrno (); } @@ -862,7 +821,7 @@ rootdir(char *full_path) } int __stdcall -fhandler_base::fstat (struct stat *buf, path_conv *) +fhandler_base::fstat (struct __stat64 *buf, path_conv *) { switch (get_device ()) { @@ -1181,7 +1140,7 @@ fhandler_base::readdir (DIR *) return NULL; } -off_t +__off64_t fhandler_base::telldir (DIR *) { set_errno (ENOTDIR); @@ -1189,7 +1148,7 @@ fhandler_base::telldir (DIR *) } void -fhandler_base::seekdir (DIR *, off_t) +fhandler_base::seekdir (DIR *, __off64_t) { set_errno (ENOTDIR); return; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 916000452..9cab1903b 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -282,19 +282,19 @@ class fhandler_base virtual int open (path_conv * real_path, int flags, mode_t mode = 0); virtual int close (); - virtual int __stdcall fstat (struct stat *buf, path_conv *) __attribute__ ((regparm (3))); + virtual int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); virtual int ioctl (unsigned int cmd, void *); virtual int fcntl (int cmd, void *); virtual char const * ttyname () { return get_name(); } virtual int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); virtual int write (const void *ptr, size_t len); - virtual off_t lseek (off_t offset, int whence); + virtual __off64_t lseek (__off64_t offset, int whence); virtual int lock (int, struct flock *); virtual void dump (); virtual int dup (fhandler_base *child); virtual HANDLE mmap (caddr_t *addr, size_t len, DWORD access, - int flags, off_t off); + int flags, __off64_t off); virtual int munmap (HANDLE h, caddr_t addr, size_t len); virtual int msync (HANDLE h, caddr_t addr, size_t len, int flags); virtual BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, @@ -347,8 +347,8 @@ class fhandler_base virtual void set_eof () {} virtual DIR *opendir (path_conv& pc); virtual dirent *readdir (DIR *); - virtual off_t telldir (DIR *); - virtual void seekdir (DIR *, off_t); + virtual __off64_t telldir (DIR *); + virtual void seekdir (DIR *, __off64_t); virtual void rewinddir (DIR *); virtual int closedir (DIR *); }; @@ -374,11 +374,15 @@ class fhandler_socket: public fhandler_base void set_shutdown_read () {FHSETF (SHUTRD);} void set_shutdown_write () {FHSETF (SHUTWR);} - int write (const void *ptr, size_t len); + int recv (void *ptr, size_t len, unsigned int flags); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + + int send (const void *ptr, size_t len, unsigned int flags); + int write (const void *ptr, size_t len); + int ioctl (unsigned int cmd, void *); int fcntl (int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } int close (); void hclose (HANDLE) {close ();} int dup (fhandler_base *child); @@ -391,8 +395,8 @@ class fhandler_socket: public fhandler_base select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); - int get_addr_family () {return addr_family;} void set_addr_family (int af) {addr_family = af;} + int get_addr_family () {return addr_family;} void set_sun_path (const char *path); char *get_sun_path () {return sun_path;} void set_connect_secret (); @@ -401,7 +405,7 @@ class fhandler_socket: public fhandler_base int check_peer_secret_event (struct sockaddr_in *peer, int *secret = NULL); void signal_secret_event (); void close_secret_event (); - int __stdcall fstat (struct stat *buf, path_conv *) __attribute__ ((regparm (3))); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); }; class fhandler_pipe: public fhandler_base @@ -413,7 +417,7 @@ class fhandler_pipe: public fhandler_base unsigned id; public: fhandler_pipe (DWORD devtype); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); select_record *select_read (select_record *s); select_record *select_write (select_record *s); select_record *select_except (select_record *s); @@ -485,7 +489,7 @@ class fhandler_dev_floppy: public fhandler_dev_raw virtual int open (path_conv *, int flags, mode_t mode = 0); virtual int close (void); - virtual off_t lseek (off_t offset, int whence); + virtual __off64_t lseek (__off64_t offset, int whence); virtual int ioctl (unsigned int cmd, void *buf); }; @@ -508,9 +512,9 @@ class fhandler_dev_tape: public fhandler_dev_raw int open (path_conv *, int flags, mode_t mode = 0); int close (void); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); - int __stdcall fstat (struct stat *buf, path_conv *) __attribute__ ((regparm (3))); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); int dup (fhandler_base *child); @@ -541,18 +545,18 @@ class fhandler_disk_file: public fhandler_base int close (); int lock (int, struct flock *); BOOL is_device () { return FALSE; } - int __stdcall fstat (struct stat *buf, path_conv *pc) __attribute__ ((regparm (3))); - int __stdcall fstat_helper (struct stat *buf) __attribute__ ((regparm (2))); + int __stdcall fstat (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); + int __stdcall fstat_helper (struct __stat64 *buf) __attribute__ ((regparm (2))); - HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, off_t off); + HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, __off64_t off); int munmap (HANDLE h, caddr_t addr, size_t len); int msync (HANDLE h, caddr_t addr, size_t len, int flags); BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, DWORD size, void *address); DIR *opendir (path_conv& pc); struct dirent *readdir (DIR *); - off_t telldir (DIR *); - void seekdir (DIR *, off_t); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); void rewinddir (DIR *); int closedir (DIR *); }; @@ -568,11 +572,11 @@ class fhandler_cygdrive: public fhandler_disk_file fhandler_cygdrive (int unit); DIR *opendir (path_conv& pc); struct dirent *readdir (DIR *); - off_t telldir (DIR *); - void seekdir (DIR *, off_t); + __off64_t telldir (DIR *); + void seekdir (DIR *, __off64_t); void rewinddir (DIR *); int closedir (DIR *); - int __stdcall fstat (struct stat *buf, path_conv *pc) __attribute__ ((regparm (3))); + int __stdcall fstat (struct __stat64 *buf, path_conv *pc) __attribute__ ((regparm (3))); }; class fhandler_serial: public fhandler_base @@ -602,7 +606,7 @@ class fhandler_serial: public fhandler_base int tcflow (int); int tcsetattr (int a, const struct termios *t); int tcgetattr (struct termios *t); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } int tcflush (int); void dump (); int is_tty () { return 1; } @@ -833,7 +837,7 @@ class fhandler_tty_slave: public fhandler_tty_common int tcflush (int); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } select_record *select_read (select_record *s); int ready_for_read (int fd, DWORD howlong); @@ -862,7 +866,7 @@ class fhandler_pty_master: public fhandler_tty_common int tcflush (int); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } char *ptsname (); void set_close_on_exec (int val); @@ -901,7 +905,7 @@ class fhandler_dev_zero: public fhandler_base int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); int close (void); void dump (); @@ -924,7 +928,7 @@ class fhandler_dev_random: public fhandler_base int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); int close (void); int dup (fhandler_base *child); @@ -936,7 +940,7 @@ class fhandler_dev_mem: public fhandler_base protected: int unit; DWORD mem_size; - DWORD pos; + __off64_t pos; public: fhandler_dev_mem (int unit); @@ -945,12 +949,12 @@ class fhandler_dev_mem: public fhandler_base int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t ulen); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); int close (void); - int __stdcall fstat (struct stat *buf, path_conv *) __attribute__ ((regparm (3))); + int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); int dup (fhandler_base *child); - HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, off_t off); + HANDLE mmap (caddr_t *addr, size_t len, DWORD access, int flags, __off64_t off); int munmap (HANDLE h, caddr_t addr, size_t len); int msync (HANDLE h, caddr_t addr, size_t len, int flags); BOOL fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, @@ -967,7 +971,7 @@ class fhandler_dev_clipboard: public fhandler_base int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); - off_t lseek (off_t offset, int whence); + __off64_t lseek (__off64_t offset, int whence); int close (void); int dup (fhandler_base *child); @@ -975,7 +979,7 @@ class fhandler_dev_clipboard: public fhandler_base void dump (); private: - off_t pos; + __off64_t pos; void *membuffer; size_t msize; bool eof; @@ -993,7 +997,7 @@ class fhandler_windows: public fhandler_base int write (const void *ptr, size_t len); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int) { return 0; } + __off64_t lseek (__off64_t, int) { return 0; } int close (void) { return 0; } void set_close_on_exec (int val); @@ -1019,7 +1023,7 @@ class fhandler_dev_dsp : public fhandler_base int write (const void *ptr, size_t len); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int ioctl (unsigned int cmd, void *); - off_t lseek (off_t, int); + __off64_t lseek (__off64_t, int); int close (void); int dup (fhandler_base * child); void dump (void); diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc index 69065865a..266114fe3 100644 --- a/winsup/cygwin/fhandler_clipboard.cc +++ b/winsup/cygwin/fhandler_clipboard.cc @@ -1,6 +1,6 @@ /* fhandler_dev_clipboard: code to access /dev/clipboard - Copyright 2000, 2001 Red Hat, Inc + Copyright 2000, 2001, 2002 Red Hat, Inc Written by Charles Wilson (cwilson@ece.gatech.edu) @@ -246,8 +246,8 @@ fhandler_dev_clipboard::read (void *ptr, size_t len) } } -off_t -fhandler_dev_clipboard::lseek (off_t offset, int whence) +__off64_t +fhandler_dev_clipboard::lseek (__off64_t offset, int whence) { /* On reads we check this at read time, not seek time. * On writes we use this to decide how to write - empty and write, or open, copy, empty diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 18887844e..c251ed3cf 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -61,12 +61,12 @@ num_entries (const char *win32_name) } int -fhandler_disk_file::fstat (struct stat *buf, path_conv *pc) +fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc) { int res = -1; int oret; - uid_t uid; - gid_t gid; + __uid16_t uid; + __gid16_t gid; int open_flags = O_RDONLY | O_BINARY | O_DIROPEN; if (!pc) @@ -132,17 +132,17 @@ fhandler_disk_file::fstat (struct stat *buf, path_conv *pc) buf->st_mode = S_IFREG; if (!pc->has_acls () || get_file_attribute (TRUE, pc->get_win32 (), - &buf->st_mode, - &buf->st_uid, &buf->st_gid)) + &buf->st_mode, &uid, &gid)) { buf->st_mode |= STD_RBITS | STD_XBITS; if (!(pc->has_attribute (FILE_ATTRIBUTE_READONLY))) buf->st_mode |= STD_WBITS; if (pc->issymlink ()) buf->st_mode |= S_IRWXU | S_IRWXG | S_IRWXO; - get_file_attribute (FALSE, pc->get_win32 (), - NULL, &buf->st_uid, &buf->st_gid); + get_file_attribute (FALSE, pc->get_win32 (), NULL, &uid, &gid); } + buf->st_uid = uid; + buf->st_gid = gid; if ((handle = FindFirstFile (pc->get_win32 (), &wfd)) != INVALID_HANDLE_VALUE) { @@ -158,9 +158,10 @@ fhandler_disk_file::fstat (struct stat *buf, path_conv *pc) buf->st_mtime = to_time_t (&wfd.ftLastWriteTime); buf->st_ctime = to_time_t (&wfd.ftCreationTime); buf->st_size = wfd.nFileSizeLow; + buf->st_size = ((__off64_t)wfd.nFileSizeHigh << 32) + + wfd.nFileSizeLow; buf->st_blksize = S_BLKSIZE; - buf->st_blocks = ((unsigned long) buf->st_size + - S_BLKSIZE-1) / S_BLKSIZE; + buf->st_blocks = (buf->st_size + S_BLKSIZE-1) / S_BLKSIZE; FindClose (handle); } res = 0; @@ -170,7 +171,7 @@ fhandler_disk_file::fstat (struct stat *buf, path_conv *pc) } int -fhandler_disk_file::fstat_helper (struct stat *buf) +fhandler_disk_file::fstat_helper (struct __stat64 *buf) { int res = 0; // avoid a compiler warning BY_HANDLE_FILE_INFORMATION local; @@ -200,7 +201,7 @@ fhandler_disk_file::fstat_helper (struct stat *buf) if (lsize == 0xffffffff && GetLastError () != NO_ERROR) buf->st_mode = S_IFCHR; else - buf->st_size = lsize; + buf->st_size = ((__off64_t)hsize << 32) + lsize; /* We expect these to fail! */ buf->st_mode |= STD_RBITS | STD_WBITS; buf->st_blksize = S_BLKSIZE; @@ -228,7 +229,8 @@ fhandler_disk_file::fstat_helper (struct stat *buf) buf->st_ctime = to_time_t (&local.ftCreationTime); buf->st_nlink = local.nNumberOfLinks; buf->st_dev = local.dwVolumeSerialNumber; - buf->st_size = local.nFileSizeLow; + buf->st_size = ((__off64_t)local.nFileSizeHigh << 32) + + local.nFileSizeLow; /* Allocate some place to determine the root directory. Need to allocate enough so that rootdir can add a trailing slash if path starts with \\. */ @@ -256,7 +258,7 @@ fhandler_disk_file::fstat_helper (struct stat *buf) } buf->st_blksize = S_BLKSIZE; - buf->st_blocks = ((unsigned long) buf->st_size + S_BLKSIZE-1) / S_BLKSIZE; + buf->st_blocks = (buf->st_size + S_BLKSIZE-1) / S_BLKSIZE; buf->st_mode = 0; /* Using a side effect: get_file_attibutes checks for @@ -267,8 +269,10 @@ fhandler_disk_file::fstat_helper (struct stat *buf) buf->st_mode = S_IFLNK; else if (get_socket_p ()) buf->st_mode = S_IFSOCK; + __uid16_t uid; + __gid16_t gid; if (get_file_attribute (has_acls (), get_win32_name (), &buf->st_mode, - &buf->st_uid, &buf->st_gid) == 0) + &uid, &gid) == 0) { /* If read-only attribute is set, modify ntsec return value */ if ((local.dwFileAttributes & FILE_ATTRIBUTE_READONLY) @@ -277,6 +281,9 @@ fhandler_disk_file::fstat_helper (struct stat *buf) if (!(buf->st_mode & S_IFMT)) buf->st_mode |= S_IFREG; + + buf->st_uid = uid; + buf->st_gid = gid; } else { @@ -331,7 +338,7 @@ fhandler_disk_file::fstat_helper (struct stat *buf) } } - syscall_printf ("0 = fstat (, %p) st_atime=%x st_size=%d, st_mode=%p, st_ino=%d, sizeof=%d", + syscall_printf ("0 = fstat (, %p) st_atime=%x st_size=%D, st_mode=%p, st_ino=%d, sizeof=%d", buf, buf->st_atime, buf->st_size, buf->st_mode, (int) buf->st_ino, sizeof (*buf)); @@ -429,10 +436,10 @@ fhandler_disk_file::close () int fhandler_disk_file::lock (int cmd, struct flock *fl) { - int win32_start; + __off64_t win32_start; int win32_len; DWORD win32_upper; - DWORD startpos; + __off64_t startpos; /* * We don't do getlck calls yet. @@ -455,7 +462,7 @@ fhandler_disk_file::lock (int cmd, struct flock *fl) startpos = 0; break; case SEEK_CUR: - if ((off_t) (startpos = lseek (0, SEEK_CUR)) == (off_t)-1) + if ((startpos = lseek (0, SEEK_CUR)) == ILLEGAL_SEEK) return -1; break; case SEEK_END: @@ -466,7 +473,8 @@ fhandler_disk_file::lock (int cmd, struct flock *fl) __seterrno (); return -1; } - startpos = finfo.nFileSizeLow; /* Nowhere to keep high word */ + startpos = ((__off64_t)finfo.nFileSizeHigh << 32) + + finfo.nFileSizeLow; break; } default: @@ -714,14 +722,14 @@ fhandler_disk_file::readdir (DIR *dir) return res; } -off_t +__off64_t fhandler_disk_file::telldir (DIR *dir) { return dir->__d_position; } void -fhandler_disk_file::seekdir (DIR *dir, off_t loc) +fhandler_disk_file::seekdir (DIR *dir, __off64_t loc) { rewinddir (dir); while (loc > dir->__d_position) @@ -771,7 +779,7 @@ fhandler_cygdrive::set_drives () } int -fhandler_cygdrive::fstat (struct stat *buf, path_conv *pc) +fhandler_cygdrive::fstat (struct __stat64 *buf, path_conv *pc) { if (!iscygdrive_root ()) return fhandler_disk_file::fstat (buf, pc); @@ -818,14 +826,14 @@ fhandler_cygdrive::readdir (DIR *dir) return dir->__d_dirent; } -off_t +__off64_t fhandler_cygdrive::telldir (DIR *dir) { return fhandler_disk_file::telldir (dir); } void -fhandler_cygdrive::seekdir (DIR *dir, off_t loc) +fhandler_cygdrive::seekdir (DIR *dir, __off64_t loc) { if (!iscygdrive_root ()) return fhandler_disk_file::seekdir (dir, loc); diff --git a/winsup/cygwin/fhandler_dsp.cc b/winsup/cygwin/fhandler_dsp.cc index e380b3e46..6ea8f3cbd 100644 --- a/winsup/cygwin/fhandler_dsp.cc +++ b/winsup/cygwin/fhandler_dsp.cc @@ -1,6 +1,6 @@ /* fhandler_dev_dsp: code to emulate OSS sound model /dev/dsp - Copyright 2001 Red Hat, Inc + Copyright 2001, 2002 Red Hat, Inc Written by Andy Younger (andy@snoogie.demon.co.uk) @@ -86,7 +86,7 @@ Audio::~Audio () } bool -Audio::open (int rate, int bits, int channels, bool bCallback = false) +Audio::open (int rate, int bits, int channels, bool bCallback) { WAVEFORMATEX format; int nDevices = waveOutGetNumDevs (); @@ -430,7 +430,7 @@ fhandler_dev_dsp::~fhandler_dev_dsp () } int -fhandler_dev_dsp::open (path_conv *, int flags, mode_t mode = 0) +fhandler_dev_dsp::open (path_conv *, int flags, mode_t mode) { // currently we only support writing if ((flags & (O_WRONLY | O_RDONLY | O_RDWR)) != O_WRONLY) @@ -482,8 +482,8 @@ fhandler_dev_dsp::read (void *ptr, size_t len) return len; } -off_t -fhandler_dev_dsp::lseek (off_t offset, int whence) +__off64_t +fhandler_dev_dsp::lseek (__off64_t offset, int whence) { return 0; } diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc index 193e75a37..43daf9d99 100644 --- a/winsup/cygwin/fhandler_floppy.cc +++ b/winsup/cygwin/fhandler_floppy.cc @@ -1,7 +1,7 @@ /* fhandler_floppy.cc. See fhandler.h for a description of the fhandler classes. - Copyright 1999, 2000, 2001 Red Hat, Inc. + Copyright 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -77,16 +77,16 @@ fhandler_dev_floppy::close (void) return fhandler_dev_raw::close (); } -off_t -fhandler_dev_floppy::lseek (off_t offset, int whence) +__off64_t +fhandler_dev_floppy::lseek (__off64_t offset, int whence) { int ret; char buf[512]; - long long drive_size = 0; - long long lloffset = offset; - long long current_position; - off_t sector_aligned_offset; - off_t bytes_left; + __off64_t drive_size = 0; + __off64_t lloffset = offset; + __off64_t current_position; + __off64_t sector_aligned_offset; + __off64_t bytes_left; DWORD low; LONG high = 0; @@ -117,11 +117,11 @@ fhandler_dev_floppy::lseek (off_t offset, int whence) debug_printf ("partition info: %ld (%ld)", pi.StartingOffset.LowPart, pi.PartitionLength.LowPart); - drive_size = (long long) pi.PartitionLength.QuadPart; + drive_size = pi.PartitionLength.QuadPart; } else { - drive_size = (long long) di.Cylinders.QuadPart * di.TracksPerCylinder * + drive_size = di.Cylinders.QuadPart * di.TracksPerCylinder * di.SectorsPerTrack * di.BytesPerSector; } debug_printf ("drive size: %ld", drive_size); @@ -140,7 +140,7 @@ fhandler_dev_floppy::lseek (off_t offset, int whence) __seterrno (); return -1; } - current_position = (long long) low + ((long long) high << 32); + current_position = low + ((__off64_t) high << 32); if (is_writing) current_position += devbufend - devbufstart; else @@ -156,18 +156,10 @@ fhandler_dev_floppy::lseek (off_t offset, int whence) set_errno (EINVAL); return -1; } - high = lloffset >> 32; - low = lloffset & 0xffffffff; - if (high || (off_t) low < 0) - { - set_errno (EFBIG); - return -1; - } - offset = (off_t) low; /* FIXME: sector can possibly be not 512 bytes long */ - sector_aligned_offset = (offset / 512) * 512; - bytes_left = offset - sector_aligned_offset; + sector_aligned_offset = (lloffset / 512) * 512; + bytes_left = lloffset - sector_aligned_offset; if (whence == SEEK_SET) { @@ -177,8 +169,10 @@ fhandler_dev_floppy::lseek (off_t offset, int whence) return ret; devbufstart = devbufend = 0; - if (SetFilePointer (get_handle (), sector_aligned_offset, NULL, FILE_BEGIN) - == INVALID_SET_FILE_POINTER) + low = sector_aligned_offset & 0xffffffff; + high = sector_aligned_offset >> 32; + if (SetFilePointer (get_handle (), low, &high, FILE_BEGIN) + == INVALID_SET_FILE_POINTER && GetLastError ()) { __seterrno (); return -1; diff --git a/winsup/cygwin/fhandler_mem.cc b/winsup/cygwin/fhandler_mem.cc index 14cdac0be..e5b99526e 100644 --- a/winsup/cygwin/fhandler_mem.cc +++ b/winsup/cygwin/fhandler_mem.cc @@ -1,6 +1,6 @@ /* fhandler_mem.cc. See fhandler.h for a description of the fhandler classes. - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -231,8 +231,8 @@ fhandler_dev_mem::close (void) return fhandler_base::close (); } -off_t -fhandler_dev_mem::lseek (off_t offset, int whence) +__off64_t +fhandler_dev_mem::lseek (__off64_t offset, int whence) { switch (whence) { @@ -251,13 +251,13 @@ fhandler_dev_mem::lseek (off_t offset, int whence) default: set_errno (EINVAL); - return (off_t) -1; + return ILLEGAL_SEEK; } if (pos > mem_size) { set_errno (EINVAL); - return (off_t) -1; + return ILLEGAL_SEEK; } return pos; @@ -265,11 +265,11 @@ fhandler_dev_mem::lseek (off_t offset, int whence) HANDLE fhandler_dev_mem::mmap (caddr_t *addr, size_t len, DWORD access, - int flags, off_t off) + int flags, __off64_t off) { - if ((DWORD) off >= mem_size + if (off >= mem_size || (DWORD) len >= mem_size - || (DWORD) off + len >= mem_size) + || off + len >= mem_size) { set_errno (EINVAL); syscall_printf ("-1 = mmap(): illegal parameter, set EINVAL"); @@ -402,7 +402,7 @@ fhandler_dev_mem::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, } int -fhandler_dev_mem::fstat (struct stat *buf, path_conv *pc) +fhandler_dev_mem::fstat (struct __stat64 *buf, path_conv *pc) { this->fhandler_base::fstat (buf, pc); buf->st_mode = S_IFCHR; diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc index 8f43b600c..33ccaddea 100644 --- a/winsup/cygwin/fhandler_random.cc +++ b/winsup/cygwin/fhandler_random.cc @@ -1,6 +1,6 @@ /* fhandler_random.cc: code to access /dev/random and /dev/urandom - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. Written by Corinna Vinschen (vinschen@cygnus.com) @@ -132,8 +132,8 @@ fhandler_dev_random::read (void *ptr, size_t len) return -1; } -off_t -fhandler_dev_random::lseek (off_t, int) +__off64_t +fhandler_dev_random::lseek (__off64_t, int) { return 0; } diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index b62a203bf..cf8ec1c24 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -31,6 +31,7 @@ #include "dtable.h" #include "cygheap.h" #include "sigproc.h" +#include "wsock_event.h" #define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x" #define ENTROPY_SOURCE_NAME "/dev/urandom" @@ -244,37 +245,97 @@ fhandler_socket::dup (fhandler_base *child) } int __stdcall -fhandler_socket::fstat (struct stat *buf, path_conv *pc) +fhandler_socket::fstat (struct __stat64 *buf, path_conv *pc) { fhandler_disk_file fh; fh.set_name (get_name (), get_win32_name ()); return fh.fstat (buf, pc); } -int __stdcall -fhandler_socket::read (void *ptr, size_t len) +int +fhandler_socket::recv (void *ptr, size_t len, unsigned int flags) { + int res = -1; + wsock_event wsock_evt; + LPWSAOVERLAPPED ovr; + sigframe thisframe (mainthread); - int res = recv (get_socket (), (char *) ptr, len, 0); - if (res == SOCKET_ERROR) - set_winsock_errno (); + if (is_nonblocking () || !(ovr = wsock_evt.prepare ())) + { + debug_printf ("Fallback to winsock 1 recv call"); + if ((res = ::recv (get_socket (), (char *) ptr, len, flags)) + == SOCKET_ERROR) + { + set_winsock_errno (); + res = -1; + } + } + else + { + WSABUF wsabuf = { len, (char *) ptr }; + DWORD ret = 0; + if (WSARecv (get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags, + ovr, NULL) != SOCKET_ERROR) + res = ret; + else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) + { + set_winsock_errno (); + res = -1; + } + else if ((res = wsock_evt.wait (get_socket (), (DWORD *)&flags)) == -1) + set_winsock_errno (); + } return res; } +int __stdcall +fhandler_socket::read (void *ptr, size_t len) +{ + return recv (ptr, len, 0); +} + int -fhandler_socket::write (const void *ptr, size_t len) +fhandler_socket::send (const void *ptr, size_t len, unsigned int flags) { + int res = -1; + wsock_event wsock_evt; + LPWSAOVERLAPPED ovr; + sigframe thisframe (mainthread); - int res = send (get_socket (), (const char *) ptr, len, 0); - if (res == SOCKET_ERROR) + if (is_nonblocking () || !(ovr = wsock_evt.prepare ())) { - set_winsock_errno (); - if (get_errno () == ECONNABORTED || get_errno () == ECONNRESET) - _raise (SIGPIPE); + debug_printf ("Fallback to winsock 1 send call"); + if ((res = ::send (get_socket (), (const char *) ptr, len, flags)) + == SOCKET_ERROR) + { + set_winsock_errno (); + res = -1; + } + } + else + { + WSABUF wsabuf = { len, (char *) ptr }; + DWORD ret = 0; + if (WSASend (get_socket (), &wsabuf, 1, &ret, (DWORD)flags, + ovr, NULL) != SOCKET_ERROR) + res = ret; + else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) + { + set_winsock_errno (); + res = -1; + } + else if ((res = wsock_evt.wait (get_socket (), (DWORD *)&flags)) == -1) + set_winsock_errno (); } return res; } +int +fhandler_socket::write (const void *ptr, size_t len) +{ + return send (ptr, len, 0); +} + /* Cygwin internal */ int fhandler_socket::close () diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index 558dc0bad..6b9bd1f4d 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -1,7 +1,7 @@ /* fhandler_tape.cc. See fhandler.h for a description of the fhandler classes. - Copyright 1999, 2000, 2001 Red Hat, Inc. + Copyright 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -147,7 +147,7 @@ fhandler_dev_tape::close (void) } int -fhandler_dev_tape::fstat (struct stat *buf, path_conv *pc) +fhandler_dev_tape::fstat (struct __stat64 *buf, path_conv *pc) { int ret; @@ -164,8 +164,8 @@ fhandler_dev_tape::fstat (struct stat *buf, path_conv *pc) return ret; } -off_t -fhandler_dev_tape::lseek (off_t offset, int whence) +__off64_t +fhandler_dev_tape::lseek (__off64_t offset, int whence) { struct mtop op; struct mtpos pos; @@ -179,7 +179,7 @@ fhandler_dev_tape::lseek (off_t offset, int whence) if (ioctl (MTIOCPOS, &pos)) { - return (off_t) -1; + return ILLEGAL_SEEK; } switch (whence) diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc index 4a8c23862..2407238e7 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -83,6 +83,25 @@ fhandler_termios::tcgetpgrp () } void +tty_min::kill_pgrp (int sig) +{ + int killself = 0; + winpids pids; + for (unsigned i = 0; i < pids.npids; i++) + { + _pinfo *p = pids[i]; + if (!proc_exists (p) || p->ctty != ntty || p->pgid != pgid) + continue; + if (p == myself) + killself++; + else + (void) sig_send (p, sig); + } + if (killself) + sig_send (myself, sig); +} + +void tty_min::set_ctty (int ttynum, int flags) { if ((myself->ctty < 0 || myself->ctty == ttynum) && !(flags & O_NOCTTY)) @@ -218,7 +237,7 @@ fhandler_termios::line_edit (const char *rptr, int nread, int always_accept) termios_printf ("got interrupt %d, sending signal %d", c, sig); eat_readahead (-1); - kill_pgrp (tc->getpgid (), sig); + tc->kill_pgrp (sig); tc->ti.c_lflag &= ~FLUSHO; sawsig = 1; goto restart_output; diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index c3c1ba607..648135012 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1024,10 +1024,10 @@ fhandler_tty_common::close () termios_printf ("CloseHandle (ioctl_request_event), %E"); if (inuse && !CloseHandle (inuse)) termios_printf ("CloseHandle (inuse), %E"); - if (!ForceCloseHandle (output_mutex)) - termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex); if (!ForceCloseHandle (input_mutex)) termios_printf ("CloseHandle (input_mutex<%p>), %E", input_mutex); + if (!ForceCloseHandle (output_mutex)) + termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex); /* Send EOF to slaves if master side is closed */ if (!get_ttyp ()->master_alive ()) diff --git a/winsup/cygwin/fhandler_zero.cc b/winsup/cygwin/fhandler_zero.cc index 93b4544f3..50b34abab 100644 --- a/winsup/cygwin/fhandler_zero.cc +++ b/winsup/cygwin/fhandler_zero.cc @@ -1,6 +1,6 @@ /* fhandler_dev_zero.cc: code to access /dev/zero - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. Written by DJ Delorie (dj@cygnus.com) @@ -41,8 +41,8 @@ fhandler_dev_zero::read (void *ptr, size_t len) return len; } -off_t -fhandler_dev_zero::lseek (off_t, int) +__off64_t +fhandler_dev_zero::lseek (__off64_t, int) { return 0; } diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 964ce6193..f7133df6b 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -473,8 +473,8 @@ fork_parent (HANDLE& hParent, dll *&first_dll, newheap = cygheap_setup_for_child (&ch,cygheap->fdtab.need_fixup_before ()); rc = CreateProcess (myself->progname, /* image to run */ myself->progname, /* what we send in arg0 */ - allow_ntsec ? sec_user (sa_buf) : &sec_none_nih, - allow_ntsec ? sec_user (sa_buf) : &sec_none_nih, + sec_user_nih (sa_buf), + sec_user_nih (sa_buf), TRUE, /* inherit handles from parent */ c_flags, NULL, /* environment filled in later */ diff --git a/winsup/cygwin/glob.c b/winsup/cygwin/glob.c index c8a6ffbaa..cdb30a855 100644 --- a/winsup/cygwin/glob.c +++ b/winsup/cygwin/glob.c @@ -94,8 +94,12 @@ __weak_alias(__globfree13,___globfree13); #ifdef __LIBC12_SOURCE__ #define STAT stat12 #else +#if defined (__INSIDE_CYGWIN__) +#define STAT __stat64 +#else #define STAT stat #endif +#endif #define DOLLAR '$' #define DOT '.' @@ -814,7 +818,11 @@ g_lstat(fn, sb, pglob) g_Ctoc(fn, buf); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_lstat)(buf, sb)); +#ifdef __INSIDE_CYGWIN__ + return(lstat64(buf, sb)); +#else return(lstat(buf, sb)); +#endif } static int @@ -828,7 +836,11 @@ g_stat(fn, sb, pglob) g_Ctoc(fn, buf); if (pglob->gl_flags & GLOB_ALTDIRFUNC) return((*pglob->gl_stat)(buf, sb)); +#ifdef __INSIDE_CYGWIN__ + return(stat64(buf, sb)); +#else return(stat(buf, sb)); +#endif } static Char * diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 93af7063e..d88deb994 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -1,6 +1,6 @@ /* grp.cc - Copyright 1996, 1997, 1998, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc. Original stubs by Jason Molenda of Cygnus Support, crash@cygnus.com First implementation by Gunther Ebert, gunther.ebert@ixos-leipzig.de @@ -31,8 +31,8 @@ details. */ /* Read /etc/group only once for better performance. This is done on the first call that needs information from it. */ -static NO_COPY const char *etc_group = "/etc/group"; -static struct group *group_buf; /* group contents in memory */ +static const char *etc_group NO_COPY = "/etc/group"; +static struct __group16 *group_buf; /* group contents in memory */ static int curr_lines; static int max_lines; @@ -46,7 +46,7 @@ static int grp_pos = 0; static pwdgrp_check group_state; static int -parse_grp (struct group &grp, const char *line) +parse_grp (struct __group16 &grp, const char *line) { int len = strlen(line); char *newline = (char *) malloc (len + 1); @@ -111,7 +111,7 @@ add_grp_line (const char *line) if (curr_lines == max_lines) { max_lines += 10; - group_buf = (struct group *) realloc (group_buf, max_lines * sizeof (struct group)); + group_buf = (struct __group16 *) realloc (group_buf, max_lines * sizeof (struct __group16)); } if (parse_grp (group_buf[curr_lines], line)) curr_lines++; @@ -119,17 +119,23 @@ add_grp_line (const char *line) class group_lock { - pthread_mutex_t mutex; + bool armed; + static NO_COPY pthread_mutex_t mutex; public: - group_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} - void arm () {pthread_mutex_lock (&mutex); } + group_lock (bool doit) + { + if (armed = doit) + pthread_mutex_lock (&mutex); + } ~group_lock () { - if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) + if (armed) pthread_mutex_unlock (&mutex); } }; +pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; + /* Cygwin internal */ /* Read in /etc/group and save contents in the group cache */ /* This sets group_in_memory_p to 1 so functions in this file can @@ -145,9 +151,7 @@ read_etc_group () strncpy (group_name, "Administrators", sizeof (group_name)); - static NO_COPY group_lock here; - if (cygwin_finished_initializing) - here.arm (); + group_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_group may have been processed */ if (group_state != uninitialized) @@ -208,10 +212,10 @@ read_etc_group () } extern "C" -struct group * -getgrgid (gid_t gid) +struct __group16 * +getgrgid (__gid16_t gid) { - struct group * default_grp = NULL; + struct __group16 * default_grp = NULL; if (group_state <= initializing) read_etc_group(); @@ -227,7 +231,7 @@ getgrgid (gid_t gid) } extern "C" -struct group * +struct __group16 * getgrnam (const char *name) { if (group_state <= initializing) @@ -249,7 +253,7 @@ endgrent() } extern "C" -struct group * +struct __group16 * getgrent() { if (group_state <= initializing) @@ -269,7 +273,7 @@ setgrent () } /* Internal function. ONLY USE THIS INTERNALLY, NEVER `getgrent'!!! */ -struct group * +struct __group16 * internal_getgrent (int pos) { if (group_state <= initializing) @@ -281,12 +285,12 @@ internal_getgrent (int pos) } int -getgroups (int gidsetsize, gid_t *grouplist, gid_t gid, const char *username) +getgroups (int gidsetsize, __gid16_t *grouplist, __gid16_t gid, const char *username) { HANDLE hToken = NULL; DWORD size; int cnt = 0; - struct group *gr; + struct __group16 *gr; if (group_state <= initializing) read_etc_group(); @@ -356,14 +360,14 @@ error: extern "C" int -getgroups (int gidsetsize, gid_t *grouplist) +getgroups (int gidsetsize, __gid16_t *grouplist) { return getgroups (gidsetsize, grouplist, myself->gid, cygheap->user.name ()); } extern "C" int -initgroups (const char *, gid_t) +initgroups (const char *, __gid16_t) { return 0; } diff --git a/winsup/cygwin/how-to-debug-cygwin.txt b/winsup/cygwin/how-to-debug-cygwin.txt index 90b1cd957..52e85c30e 100644 --- a/winsup/cygwin/how-to-debug-cygwin.txt +++ b/winsup/cygwin/how-to-debug-cygwin.txt @@ -1,22 +1,25 @@ Copyright 2001 Red Hat Inc., Egor Duda -So, your favorite program has crashed? And did you say something about -'stackdump'? Or it just prints its output from left to right and upside-down? -Well, you can file an angry bug report and wait until some of the core -developers try to reproduce your problem, try to find what's the matter -with your program and cygwin and fix the bug, if any. But you can do something -better than that. You can debug the problem yourself, and even if you can't -fix it, your analysis may be very helpful. Here's the (incomplete) howto on -cygwin debugging. - -1. The first thing you'll need to do is to build cygwin1.dll and your crashed -application from sources. To debug them you'll need debug information, which -is normally stripped from executables. +So, your favorite program has crashed? And did you say something about +'stackdump'? Or it just prints its output from left to right and +upside-down? Well, you can file an angry bug report and wait until some +of the core developers try to reproduce your problem, try to find what's +the matter with your program and cygwin and fix the bug, if any. But +you can do something better than that. You can debug the problem +yourself, and even if you can't fix it, your analysis may be very +helpful. Here's the (incomplete) howto on cygwin debugging. + +1. The first thing you'll need to do is to build cygwin1.dll and your + crashed application from sources. To debug them you'll need debug + information, which is normally stripped from executables. You probably + also want to build a version of the dll with more debugging capabilities + by reconfiguring your build directory, specifying the --enable-debugging + option to configure. 2. Create known-working cygwin debugging environment. -- create a separate directory, say, c:\cygdeb, and put known-working - cygwin1.dll and gdb.exe in it. -- create a wrapper c:\cygdeb\debug_wrapper.cmd: + - create a separate directory, say, c:\cygdeb, and put known-working + cygwin1.dll and gdb.exe in it. + - create a wrapper c:\cygdeb\debug_wrapper.cmd: ========= debug_wrapper.cmd ========= rem setting CYGWIN_TESTING environment variable makes cygwin application @@ -26,26 +29,30 @@ c:\cygdeb\gdb.exe -nw %1 %2 =================================== 3. Try to use cygwin's JIT debugging facility: -- add 'error_start=c:\cygdeb\debug_wrapper.cmd' to CYGWIN environment - variable. When some application encounters critical error, cygwin will stop - it and execute debug_wrapper.cmd, which will run gdb and make it to attach to - the crashed application. + add 'error_start=c:\cygdeb\debug_wrapper.cmd' to CYGWIN environment + variable. When some application encounters critical error, cygwin will stop + it and execute debug_wrapper.cmd, which will run gdb and make it to attach to + the crashed application. 4. Strace. - You can run your program under 'strace' utility, described if user's manual. - If you know where the problem approximately is, you can add a bunch of - additional debug_printf()s in the source code and see what they print in - strace log. There's one common problem with this method, that some bugs - may mysteriously disappear once the program is run under strace. Then the - bug is likely a race condition. strace has two useful options to deal with - such situation: -b enables buffering of output and reduces additional - timeouts introduced by strace, and -m option allows you to mask certain - classes of *_printf() functions, reducing timeouts even more. + You can run your program under 'strace' utility, described if user's manual. + If you know where the problem approximately is, you can add a bunch of + additional debug_printf()s in the source code and see what they print in + strace log. There's one common problem with this method, that some bugs + may mysteriously disappear once the program is run under strace. Then the + bug is likely a race condition. strace has two useful options to deal with + such situation: -b enables buffering of output and reduces additional + timeouts introduced by strace, and -m option allows you to mask certain + classes of *_printf() functions, reducing timeouts even more. + + Note that strace does not use the cygwin DLL and so any process that it + starts does not inherit a cygwin environment. It is equivalent to starting + a program from the command prompt. 5. Problems at early startup. - Sometimes, something crashes at the very early stages of application - initialization, when JIT debugging facility is not yet active. Ok, there's - another environment variable that may help. Create program_wrapper.cmd: + Sometimes, something crashes at the very early stages of application + initialization, when JIT debugging facility is not yet active. Ok, there's + another environment variable that may help. Create program_wrapper.cmd: ========= program_wrapper.cmd ========= rem setting CYGWIN_SLEEP environment variable makes cygwin application @@ -54,43 +61,43 @@ set CYGWIN_SLEEP=20000 c:\some\path\bad_program.exe some parameters =================================== - Now, run program_wrapper.cmd. It should print running program pid. - After starting program_wrapper.cmd you've got 20 seconds to open another - window, cd to c:\cygdeb in it, run gdb there and in gdb prompt type + Now, run program_wrapper.cmd. It should print running program pid. + After starting program_wrapper.cmd you've got 20 seconds to open another + window, cd to c:\cygdeb in it, run gdb there and in gdb prompt type - (gdb) attach <pid> + (gdb) attach <pid> - where <pid> is the pid that program_wrapper.cmd have printed. - After that you can normally step through the code in cygwin1.dll and - bad_program.exe + where <pid> is the pid that program_wrapper.cmd have printed. + After that you can normally step through the code in cygwin1.dll and + bad_program.exe 6. Heap corruption. - If your program crashes at malloc() or free() or when it references some - malloc()'ed memory, it looks like heap corruption. You can configure and - build special version of cygwin1.dll which includes heap sanity checking. - To do it, just add --enable-malloc-debugging option to configure. Be warned, - however, that this version of dll is _very_ slow (10-100 times slower than - normal), so use it only when absolutely necessary. + If your program crashes at malloc() or free() or when it references some + malloc()'ed memory, it looks like heap corruption. You can configure and + build special version of cygwin1.dll which includes heap sanity checking. + To do it, just add --enable-malloc-debugging option to configure. Be warned, + however, that this version of dll is _very_ slow (10-100 times slower than + normal), so use it only when absolutely necessary. 7. Program dies when running under strace. - If your program crashes when you run it using strace but runs ok (or has a - different problem) otherwise, then there may be a problem in one of the - strace *_printf statements. Usually this is caused by a change in arguments - resulting in a %s being used with something other than a pointer to a - string. - - To debug this scenario, do something like this: - - bash$ gdb -nw yourapp.exe - (gdb) dll cygwin1 - (gdb) l dll_crt0_1 - (gdb) bp <<first line in the function>> - (gdb) run - (gdb) set strace.active=1 - (gdb) continue - - The program will then run in "strace mode", calling each strace *_printf, - just like it does when run under the strace program. Eventually, the - program will crash, probably in small_printf. At that point, a 'bt' - command should show you the offending call to strace_printf with the - improper format string. + If your program crashes when you run it using strace but runs ok (or has a + different problem) otherwise, then there may be a problem in one of the + strace *_printf statements. Usually this is caused by a change in arguments + resulting in a %s being used with something other than a pointer to a + string. + + To debug this scenario, do something like this: + + bash$ gdb -nw yourapp.exe + (gdb) dll cygwin1 + (gdb) l dll_crt0_1 + (gdb) bp <<first line in the function>> + (gdb) run + (gdb) set strace.active=1 + (gdb) continue + + The program will then run in "strace mode", calling each strace *_printf, + just like it does when run under the strace program. Eventually, the + program will crash, probably in small_printf. At that point, a 'bt' + command should show you the offending call to strace_printf with the + improper format string. diff --git a/winsup/cygwin/include/cygwin/acl.h b/winsup/cygwin/include/cygwin/acl.h index 3248b2e68..3ea5f91e5 100644 --- a/winsup/cygwin/include/cygwin/acl.h +++ b/winsup/cygwin/include/cygwin/acl.h @@ -1,6 +1,6 @@ /* cygwin/acl.h header file for Cygwin. - Copyright 1999, 2000, 2001 Red Hat, Inc. + Copyright 1999, 2000, 2001, 2002 Red Hat, Inc. Written by C. Vinschen. This file is part of Cygwin. @@ -58,12 +58,27 @@ extern "C" { #define MASK CLASS_OBJ #define OTHER OTHER_OBJ +#ifdef __INSIDE_CYGWIN__ +typedef struct __acl16 { + int a_type; + __uid16_t a_id; + mode_t a_perm; +} __aclent16_t; + +typedef struct __acl32 { + int a_type; + __uid32_t a_id; + mode_t a_perm; +} __aclent32_t; +#else typedef struct acl { - int a_type; /* entry type */ - uid_t a_id; /* UID | GID */ - mode_t a_perm; /* permissions */ + int a_type; /* entry type */ + uid_t a_id; /* UID | GID */ + mode_t a_perm; /* permissions */ } aclent_t; +#endif +#ifndef __INSIDE_CYGWIN__ int _EXFUN(acl,(const char *path, int cmd, int nentries, aclent_t *aclbufp)); int _EXFUN(lacl,(const char *path, int cmd, int nentries, aclent_t *aclbufp)); int _EXFUN(facl,(int fd, int cmd, int nentries, aclent_t *aclbufp)); @@ -75,6 +90,7 @@ int _EXFUN(acltopbits,(aclent_t *aclbufp, int nentries, mode_t *pbitsp)); int _EXFUN(aclfrompbits,(aclent_t *aclbufp, int nentries, mode_t *pbitsp)); char *_EXFUN(acltotext,(aclent_t *aclbufp, int aclcnt)); aclent_t *_EXFUN(aclfromtext,(char *acltextp, int *aclcnt)); +#endif #ifdef __cplusplus } diff --git a/winsup/cygwin/include/cygwin/types.h b/winsup/cygwin/include/cygwin/types.h index c17eca4c6..296a11a9c 100644 --- a/winsup/cygwin/include/cygwin/types.h +++ b/winsup/cygwin/include/cygwin/types.h @@ -1,6 +1,6 @@ /* types.h - Copyright 2001 Red Hat Inc. + Copyright 2001, 2002 Red Hat Inc. Written by Robert Collins <rbtcollins@hotmail.com> This file is part of Cygwin. @@ -17,6 +17,36 @@ extern "C" #ifndef _CYGWIN_TYPES_H #define _CYGWIN_TYPES_H +typedef long __off32_t; +typedef long long __off64_t; +#ifdef __CYGWIN_USE_BIG_TYPES__ +typedef __off64_t off_t; +#else +typedef __off32_t off_t; +#endif + +typedef long blksize_t; + +typedef long __blkcnt32_t; +typedef long long __blkcnt64_t; +#ifdef __CYGWIN_USE_BIG_TYPES__ +typedef __blkcnt64_t blkcnt_t; +#else +typedef __blkcnt32_t blkcnt_t; +#endif + +typedef unsigned short __uid16_t; +typedef unsigned short __gid16_t; +typedef unsigned long __uid32_t; +typedef unsigned long __gid32_t; +#ifdef __CYGWIN_USE_BIG_TYPES__ +typedef __uid32_t uid_t; +typedef __gid32_t gid_t; +#else +typedef __uid16_t uid_t; +typedef __gid16_t gid_t; +#endif + #if !defined(__INSIDE_CYGWIN__) || !defined(__cplusplus) typedef void *pthread_t; diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index f896e7039..5bf5663dc 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -44,7 +44,7 @@ details. */ /* The current cygwin version is 1.3.6 */ #define CYGWIN_VERSION_DLL_MAJOR 1003 -#define CYGWIN_VERSION_DLL_MINOR 10 +#define CYGWIN_VERSION_DLL_MINOR 11 /* Major numbers before CYGWIN_VERSION_DLL_EPOCH are incompatible. */ diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index a4a8cf699..de3b3d4ea 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -66,7 +66,10 @@ typedef enum CW_INIT_EXCEPTIONS, CW_GET_CYGDRIVE_INFO, CW_SET_CYGWIN_REGISTRY_NAME, - CW_GET_CYGWIN_REGISTRY_NAME + CW_GET_CYGWIN_REGISTRY_NAME, + CW_STRACE_TOGGLE, + CW_STRACE_ACTIVE, + CW_CYGWIN_PID_TO_WINPID } cygwin_getinfo_types; #define CW_NEXTPID 0x80000000 // or with pid to get next one @@ -205,14 +208,19 @@ extern int cygwin_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD); #define TTY_CONSOLE 0x40000000 +#ifndef _SYS_TYPES_H +typedef unsigned short __uid16_t; +typedef unsigned short __gid16_t; +#endif + struct external_pinfo { pid_t pid; pid_t ppid; HANDLE hProcess; DWORD dwProcessId, dwSpawnedProcessId; - uid_t uid; - gid_t gid; + __uid16_t uid; + __gid16_t gid; pid_t pgid; pid_t sid; int ctty; diff --git a/winsup/cygwin/include/sys/strace.h b/winsup/cygwin/include/sys/strace.h index 87cc1d785..955d77a1e 100644 --- a/winsup/cygwin/include/sys/strace.h +++ b/winsup/cygwin/include/sys/strace.h @@ -43,7 +43,9 @@ public: int active; int lmicrosec; int execing; + int inited; strace() : version(1) {} + void hello (); void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/; void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/; void wm (int message, int word, int lon) __attribute__ ((regparm(3))); @@ -77,6 +79,13 @@ extern strace strace; #define _STRACE_MALLOC 0x20000 // trace malloc calls #define _STRACE_THREAD 0x40000 // thread-locking calls #define _STRACE_NOTALL 0x80000 // don't include if _STRACE_ALL +#if defined (DEBUGGING) +# define _STRACE_ON strace.active = 1; +# define _STRACE_OFF strace.active = 0; +#else +# define _STRACE_ON +# define _STRACE_OFF +#endif #ifdef __cplusplus extern "C" { diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc index 60c67aca8..054d77b8c 100644 --- a/winsup/cygwin/malloc_wrapper.cc +++ b/winsup/cygwin/malloc_wrapper.cc @@ -216,7 +216,7 @@ static NO_COPY muto *mprotect = NULL; void malloc_init () { - mprotect = new_muto (FALSE, "mprotect"); + new_muto (mprotect); /* Check if mallock is provided by application. If so, redirect all calls to export_malloc/free/realloc to application provided. This may happen if some other dll calls cygwin's malloc, but main code provides diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 884941ae4..57bd82795 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -1,6 +1,6 @@ /* mmap.cc - Copyright 1996, 1997, 1998, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -47,13 +47,13 @@ class mmap_record HANDLE mapping_handle_; int devtype_; DWORD access_mode_; - DWORD offset_; + __off64_t offset_; DWORD size_to_map_; caddr_t base_address_; DWORD *map_map_; public: - mmap_record (int fd, HANDLE h, DWORD ac, DWORD o, DWORD s, caddr_t b) : + mmap_record (int fd, HANDLE h, DWORD ac, __off64_t o, DWORD s, caddr_t b) : fdesc_ (fd), mapping_handle_ (h), devtype_ (0), @@ -95,7 +95,7 @@ class mmap_record void free_map () { if (map_map_) free (map_map_); } DWORD find_empty (DWORD pages); - DWORD map_map (DWORD off, DWORD len); + __off64_t map_map (__off64_t off, DWORD len); BOOL unmap_map (caddr_t addr, DWORD len); void fixup_map (void); @@ -124,8 +124,8 @@ mmap_record::find_empty (DWORD pages) return (DWORD)-1; } -DWORD -mmap_record::map_map (DWORD off, DWORD len) +__off64_t +mmap_record::map_map (__off64_t off, DWORD len) { DWORD prot, old_prot; switch (access_mode_) @@ -235,7 +235,7 @@ mmap_record::alloc_fh () the call to fork(). This requires creating a fhandler of the correct type to be sure to call the method of the correct class. */ - return cygheap->fdtab.build_fhandler (-1, get_device (), "", 0); + return cygheap->fdtab.build_fhandler (-1, get_device (), NULL); } void @@ -255,8 +255,8 @@ public: ~list (); mmap_record *add_record (mmap_record r); void erase (int i); - mmap_record *match (DWORD off, DWORD len); - off_t match (caddr_t addr, DWORD len, off_t start); + mmap_record *match (__off64_t off, DWORD len); + long match (caddr_t addr, DWORD len, long start); }; list::list () @@ -287,7 +287,7 @@ list::add_record (mmap_record r) /* Used in mmap() */ mmap_record * -list::match (DWORD off, DWORD len) +list::match (__off64_t off, DWORD len) { if (fd == -1 && !off) { @@ -307,14 +307,14 @@ list::match (DWORD off, DWORD len) } /* Used in munmap() */ -off_t -list::match (caddr_t addr, DWORD len, off_t start) +long +list::match (caddr_t addr, DWORD len, __off32_t start) { for (int i = start + 1; i < nrecs; ++i) if (addr >= recs[i].get_address () && addr + len <= recs[i].get_address () + recs[i].get_size ()) return i; - return (off_t)-1; + return -1; } void @@ -400,9 +400,9 @@ static map *mmapped_areas; extern "C" caddr_t -mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off) +mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, __off64_t off) { - syscall_printf ("addr %x, len %d, prot %x, flags %x, fd %d, off %d", + syscall_printf ("addr %x, len %d, prot %x, flags %x, fd %d, off %D", addr, len, prot, flags, fd, off); static DWORD granularity; @@ -444,7 +444,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off) fd = -1; /* Map always in multipliers of `granularity'-sized chunks. */ - DWORD gran_off = off & ~(granularity - 1); + __off64_t gran_off = off & ~(granularity - 1); DWORD gran_len = howmany (len, granularity) * granularity; fhandler_base *fh; @@ -464,7 +464,9 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off) fh = cfd; if (fh->get_device () == FH_DISK) { - DWORD fsiz = GetFileSize (fh->get_handle (), NULL); + DWORD high; + DWORD low = GetFileSize (fh->get_handle (), &high); + __off64_t fsiz = ((__off64_t)high << 32) + low; fsiz -= gran_off; if (gran_len > fsiz) gran_len = fsiz; @@ -554,6 +556,13 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off) return ret; } +extern "C" +caddr_t +mmap (caddr_t addr, size_t len, int prot, int flags, int fd, __off32_t off) +{ + return mmap64 (addr, len, prot, flags, fd, (__off64_t)off); +} + /* munmap () removes an mmapped area. It insists that base area requested is the same as that mmapped, error if not. */ @@ -589,7 +598,7 @@ munmap (caddr_t addr, size_t len) list *l = mmapped_areas->lists[it]; if (l) { - off_t li = -1; + long li = -1; if ((li = l->match(addr, len, li)) >= 0) { mmap_record *rec = l->recs + li; @@ -695,7 +704,7 @@ msync (caddr_t addr, size_t len, int flags) */ HANDLE fhandler_base::mmap (caddr_t *addr, size_t len, DWORD access, - int flags, off_t off) + int flags, __off64_t off) { set_errno (ENODEV); return INVALID_HANDLE_VALUE; @@ -726,7 +735,7 @@ fhandler_base::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, /* Implementation for disk files. */ HANDLE fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access, - int flags, off_t off) + int flags, __off64_t off) { DWORD protect; @@ -769,9 +778,10 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access, return INVALID_HANDLE_VALUE; } - void *base = MapViewOfFileEx (h, access, 0, off, len, + DWORD high = off >> 32, low = off & 0xffffffff; + void *base = MapViewOfFileEx (h, access, high, low, len, (flags & MAP_FIXED) ? *addr : NULL); - debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%d, len:%d, addr:%x)", base, h, access, off, len, (flags & MAP_FIXED) ? *addr : NULL); + debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%D, len:%d, addr:%x)", base, h, access, off, len, (flags & MAP_FIXED) ? *addr : NULL); if (!base || ((flags & MAP_FIXED) && base != *addr)) { if (!base) diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 01beab79a..2008bbe74 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -34,6 +34,7 @@ details. */ #include "sigproc.h" #include "pinfo.h" #include "registry.h" +#include "wsock_event.h" #include <sys/uio.h> extern "C" { @@ -47,23 +48,6 @@ int __stdcall rresvport (int *); int sscanf (const char *, const char *, ...); } /* End of "C" section */ -class wsock_event -{ - WSAEVENT event; - WSAOVERLAPPED ovr; -public: - wsock_event () : event (NULL) {}; - ~wsock_event () - { - if (event) - WSACloseEvent (event); - event = NULL; - }; - - LPWSAOVERLAPPED prepare (); - int wait (int socket, LPDWORD flags); -}; - LPWSAOVERLAPPED wsock_event::prepare () { @@ -524,7 +508,6 @@ fdsock (int& fd, const char *name, SOCKET soc) fhandler_socket *fh = (fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name); fh->set_io_handle ((HANDLE) soc); fh->set_flags (O_RDWR); - fh->set_name (name, name); debug_printf ("fd %d, name '%s', soc %p", fd, name, soc); return fh; } @@ -1375,12 +1358,17 @@ cygwin_getsockname (int fd, struct sockaddr *addr, int *namelen) struct sockaddr_un *sun = (struct sockaddr_un *) addr; memset (sun, 0, *namelen); sun->sun_family = AF_LOCAL; - /* According to SUSv2 "If the actual length of the address is greater - than the length of the supplied sockaddr structure, the stored - address will be truncated." We play it save here so that the - path always has a trailing 0 even if it's truncated. */ - strncpy (sun->sun_path, sock->get_sun_path (), - *namelen - sizeof *sun + sizeof sun->sun_path - 1); + + if (!sock->get_sun_path ()) + sun->sun_path[0] = '\0'; + else + /* According to SUSv2 "If the actual length of the address is + greater than the length of the supplied sockaddr structure, the + stored address will be truncated." We play it save here so + that the path always has a trailing 0 even if it's truncated. */ + strncpy (sun->sun_path, sock->get_sun_path (), + *namelen - sizeof *sun + sizeof sun->sun_path - 1); + *namelen = sizeof *sun - sizeof sun->sun_path + strlen (sun->sun_path) + 1; res = 0; @@ -1522,42 +1510,12 @@ extern "C" int cygwin_recv (int fd, void *buf, int len, unsigned int flags) { int res; - wsock_event wsock_evt; - LPWSAOVERLAPPED ovr; - fhandler_socket *h = get (fd); + fhandler_socket *fh = get (fd); - if (__check_null_invalid_struct_errno (buf, len) || !h) + if (__check_null_invalid_struct_errno (buf, len) || !fh) res = -1; else - { - sigframe thisframe (mainthread); - - if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ())) - { - debug_printf ("Fallback to winsock 1 recv call"); - if ((res = recv (h->get_socket (), (char *) buf, len, flags)) - == SOCKET_ERROR) - { - set_winsock_errno (); - res = -1; - } - } - else - { - WSABUF wsabuf = { len, (char *) buf }; - DWORD ret = 0; - if (WSARecv (h->get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags, - ovr, NULL) != SOCKET_ERROR) - res = ret; - else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } - else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); - } - } + res = fh->recv (buf, len, flags); syscall_printf ("%d = recv (%d, %x, %x, %x)", res, fd, buf, len, flags); @@ -1569,42 +1527,12 @@ extern "C" int cygwin_send (int fd, const void *buf, int len, unsigned int flags) { int res; - wsock_event wsock_evt; - LPWSAOVERLAPPED ovr; - fhandler_socket *h = get (fd); + fhandler_socket *fh = get (fd); - if (__check_invalid_read_ptr_errno (buf, len) || !h) + if (__check_invalid_read_ptr_errno (buf, len) || !fh) res = -1; else - { - sigframe thisframe (mainthread); - - if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ())) - { - debug_printf ("Fallback to winsock 1 send call"); - if ((res = send (h->get_socket (), (const char *) buf, len, flags)) - == SOCKET_ERROR) - { - set_winsock_errno (); - res = -1; - } - } - else - { - WSABUF wsabuf = { len, (char *) buf }; - DWORD ret = 0; - if (WSASend (h->get_socket (), &wsabuf, 1, &ret, (DWORD)flags, - ovr, NULL) != SOCKET_ERROR) - res = ret; - else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } - else if ((res = wsock_evt.wait (h->get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); - } - } + res = fh->send (buf, len, flags); syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags); @@ -1628,7 +1556,8 @@ getdomainname (char *domain, int len) reg_key r (HKEY_LOCAL_MACHINE, KEY_READ, (!wincap.is_winnt ()) ? "System" : "SYSTEM", "CurrentControlSet", "Services", - (!wincap.is_winnt ()) ? "MSTCP" : "Tcpip", + (!wincap.is_winnt ()) ? "VxD" : "Tcpip", + (!wincap.is_winnt ()) ? "MSTCP" : "Parameters", NULL); /* FIXME: Are registry keys case sensitive? */ @@ -1652,7 +1581,7 @@ static void get_2k_ifconf (struct ifconf *ifc, int what) { int cnt = 0; - char eth[2] = "/", ppp[2] = "/", slp[2] = "/", sub[2] = "0"; + char eth[2] = "/", ppp[2] = "/", slp[2] = "/", sub[2] = "0", tok[2] = "/"; /* Union maps buffer to correct struct */ struct ifreq *ifr = ifc->ifc_req; @@ -1685,6 +1614,11 @@ get_2k_ifconf (struct ifconf *ifc, int what) /* Setup the interface name */ switch (ift->table[if_cnt].dwType) { + case MIB_IF_TYPE_TOKENRING: + ++*tok; + strcpy (ifr->ifr_name, "tok"); + strcat (ifr->ifr_name, tok); + break; case MIB_IF_TYPE_ETHERNET: if (*sub == '0') ++*eth; diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index c18ee1601..dfabd1b7f 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -1,6 +1,6 @@ /* passwd.cc: getpwnam () and friends - Copyright 1996, 1997, 1998, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -111,17 +111,24 @@ add_pwd_line (char *line) class passwd_lock { - pthread_mutex_t mutex; + bool armed; + static NO_COPY pthread_mutex_t mutex; public: - passwd_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} - void arm () {pthread_mutex_lock (&mutex); } + passwd_lock (bool doit) + { + if (doit) + pthread_mutex_lock (&mutex); + armed = doit; + } ~passwd_lock () { - if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) + if (armed) pthread_mutex_unlock (&mutex); } }; +pthread_mutex_t NO_COPY passwd_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; + /* Read in /etc/passwd and save contents in the password cache. This sets passwd_state to loaded or emulated so functions in this file can tell that /etc/passwd has been read in or will be emulated. */ @@ -133,10 +140,7 @@ read_etc_passwd () * for non-shared mutexs in the future. Also, this function will at most be called * once from each thread, after that the passwd_state test will succeed */ - static NO_COPY passwd_lock here; - - if (cygwin_finished_initializing) - here.arm (); + passwd_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_passwd may have been processed */ if (passwd_state != uninitialized) @@ -183,7 +187,7 @@ read_etc_passwd () /* Cygwin internal */ /* If this ever becomes non-reentrant, update all the getpw*_r functions */ static struct passwd * -search_for (uid_t uid, const char *name) +search_for (__uid16_t uid, const char *name) { struct passwd *res = 0; struct passwd *default_pw = 0; @@ -214,7 +218,7 @@ search_for (uid_t uid, const char *name) } extern "C" struct passwd * -getpwuid (uid_t uid) +getpwuid (__uid16_t uid) { if (passwd_state <= initializing) read_etc_passwd (); @@ -225,7 +229,7 @@ getpwuid (uid_t uid) } extern "C" int -getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) +getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) { *result = NULL; @@ -337,7 +341,7 @@ getpwent (void) } extern "C" struct passwd * -getpwduid (uid_t) +getpwduid (__uid16_t) { return NULL; } diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index cfdd3aeda..01798209f 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2575,7 +2575,7 @@ symlink (const char *topath, const char *frompath) } win32_path.check (frompath, PC_SYM_NOFOLLOW); - if (allow_winsymlinks && !win32_path.error) + if (allow_winsymlinks && !win32_path.exists ()) { strcpy (from, frompath); strcat (from, ".lnk"); @@ -3536,9 +3536,9 @@ DWORD cwdstuff::get_hash () { DWORD hashnow; - lock->acquire (); + cwd_lock->acquire (); hashnow = hash; - lock->release (); + cwd_lock->release (); return hashnow; } @@ -3546,7 +3546,7 @@ cwdstuff::get_hash () void cwdstuff::init () { - lock = new_muto (false, "cwd"); + new_muto (cwd_lock); } /* Get initial cwd. Should only be called once in a @@ -3554,7 +3554,7 @@ cwdstuff::init () bool cwdstuff::get_initial () { - lock->acquire (); + cwd_lock->acquire (); if (win32) return 1; @@ -3571,9 +3571,9 @@ cwdstuff::get_initial () if (len == 0) { __seterrno (); - lock->release (); + cwd_lock->release (); debug_printf ("get_initial_cwd failed, %E"); - lock->release (); + cwd_lock->release (); return 0; } set (NULL); @@ -3590,7 +3590,7 @@ cwdstuff::set (const char *win32_cwd, const char *posix_cwd) if (win32_cwd) { - lock->acquire (); + cwd_lock->acquire (); win32 = (char *) crealloc (win32, strlen (win32_cwd) + 1); strcpy (win32, win32_cwd); } @@ -3606,7 +3606,7 @@ cwdstuff::set (const char *win32_cwd, const char *posix_cwd) hash = hash_path_name (0, win32); if (win32_cwd) - lock->release (); + cwd_lock->release (); return; } @@ -3651,7 +3651,7 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) strcpy (buf, "/"); } - lock->release (); + cwd_lock->release (); out: syscall_printf ("(%s) = cwdstuff::get (%p, %d, %d, %d), errno %d", diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 43e3c5aae..1bc4ac411 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -1,6 +1,6 @@ /* pinfo.cc: process table support - Copyright 1996, 1997, 1998, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -62,33 +62,14 @@ set_myself (pid_t pid, HANDLE h) myself->process_state |= PID_IN_USE; myself->start_time = time (NULL); /* Register our starting time. */ - char buf[30]; - __small_sprintf (buf, "cYg%8x %x", _STRACE_INTERFACE_ACTIVATE_ADDR, - &strace.active); - OutputDebugString (buf); - (void) GetModuleFileName (NULL, myself->progname, sizeof(myself->progname)); - if (strace.active) - { - strace.prntf (1, NULL, "**********************************************"); - strace.prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid); - strace.prntf (1, NULL, "App version: %d.%d, api: %d.%d", - user_data->dll_major, user_data->dll_minor, - user_data->api_major, user_data->api_minor); - strace.prntf (1, NULL, "DLL version: %d.%d, api: %d.%d", - cygwin_version.dll_major, cygwin_version.dll_minor, - cygwin_version.api_major, cygwin_version.api_minor); - strace.prntf (1, NULL, "DLL build: %s", cygwin_version.dll_build_date); - strace.prntf (1, NULL, "OS version: Windows %s", wincap.osname ()); - strace.prntf (1, NULL, "**********************************************"); - } - + strace.hello (); return; } /* Initialize the process table entry for the current task. - This is not called for fork'd tasks, only exec'd ones. */ + This is not called for forked tasks, only execed ones. */ void __stdcall pinfo_init (char **envp, int envc) { @@ -106,7 +87,7 @@ pinfo_init (char **envp, int envc) myself->ppid = 1; myself->pgid = myself->sid = myself->pid; myself->ctty = -1; - myself->uid = USHRT_MAX; + myself->uid = ILLEGAL_UID; environ_init (NULL, 0); /* call after myself has been set up */ } @@ -136,7 +117,7 @@ _pinfo::exit (UINT n, bool norecord) void pinfo::init (pid_t n, DWORD flag, HANDLE in_h) { - if (n == myself->pid) + if (myself && n == myself->pid) { procinfo = myself; destroy = 0; @@ -276,7 +257,7 @@ a cygwin pid.</para> extern "C" pid_t cygwin_winpid_to_pid (int winpid) { - pinfo p (winpid); + pinfo p (cygwin_pid (winpid)); if (p) return p->pid; diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index f62614d58..1bc2f7919 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -1,6 +1,6 @@ /* pinfo.h: process table info - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -65,8 +65,8 @@ public: if not found. This data resides in the shared data area (allowing tasks to store whatever they want here) so it's for informational purposes only. */ - uid_t uid; /* User ID */ - gid_t gid; /* Group ID */ + __uid16_t uid; /* User ID */ + __gid16_t gid; /* Group ID */ pid_t pgid; /* Process group ID */ pid_t sid; /* Session ID */ int ctty; /* Control tty */ diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index 6e5266d7c..b87080792 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -1,6 +1,6 @@ /* pipe.cc: pipe for Cygwin. - Copyright 1996, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -31,8 +31,8 @@ fhandler_pipe::fhandler_pipe (DWORD devtype) { } -off_t -fhandler_pipe::lseek (off_t offset, int whence) +__off64_t +fhandler_pipe::lseek (__off64_t offset, int whence) { debug_printf ("(%d, %d)", offset, whence); set_errno (ESPIPE); diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c index 34c1f2e5c..52f9037de 100644 --- a/winsup/cygwin/regex/regcomp.c +++ b/winsup/cygwin/regex/regcomp.c @@ -52,7 +52,7 @@ static char nuls[10]; /* place to point scanner in event of error */ #define NEXTn(n) (p->next += (n)) #define GETNEXT() (*p->next++) #define SETERROR(e) seterr(p, (e)) -#define REQUIRE(co, e) ((co) || SETERROR(e)) +#define REQUIRE(co, e) (void) ((co) || SETERROR(e)) #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) diff --git a/winsup/cygwin/sec_acl.cc b/winsup/cygwin/sec_acl.cc index 3a806d05e..36c31a840 100644 --- a/winsup/cygwin/sec_acl.cc +++ b/winsup/cygwin/sec_acl.cc @@ -1,6 +1,6 @@ /* secacl.cc: Sun compatible ACL functions. - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. Written by Corinna Vinschen <corinna@vinschen.de> @@ -34,8 +34,11 @@ details. */ #include "pinfo.h" #include "cygheap.h" +extern "C" int aclsort (int nentries, int, __aclent16_t *aclbufp); +extern "C" int acl (const char *path, int cmd, int nentries, __aclent16_t *aclbufp); + static int -searchace (aclent_t *aclp, int nentries, int type, int id = -1) +searchace (__aclent16_t *aclp, int nentries, int type, int id = -1) { int i; @@ -47,7 +50,7 @@ searchace (aclent_t *aclp, int nentries, int type, int id = -1) } static int -setacl (const char *file, int nentries, aclent_t *aclbufp) +setacl (const char *file, int nentries, __aclent16_t *aclbufp) { DWORD sd_size = 4096; char sd_buf[4096]; @@ -106,7 +109,7 @@ setacl (const char *file, int nentries, aclent_t *aclbufp) cygsid sid; struct passwd *pw; - struct group *gr; + struct __group16 *gr; int pos; if (!InitializeAcl (acl, 3072, ACL_REVISION)) @@ -213,7 +216,7 @@ setacl (const char *file, int nentries, aclent_t *aclbufp) } static void -getace (aclent_t &acl, int type, int id, DWORD win_ace_mask, DWORD win_ace_type) +getace (__aclent16_t &acl, int type, int id, DWORD win_ace_mask, DWORD win_ace_type) { acl.a_type = type; acl.a_id = id; @@ -238,7 +241,7 @@ getace (aclent_t &acl, int type, int id, DWORD win_ace_mask, DWORD win_ace_type) } static int -getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) +getacl (const char *file, DWORD attr, int nentries, __aclent16_t *aclbufp) { DWORD sd_size = 4096; char sd_buf[4096]; @@ -254,8 +257,8 @@ getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) PSID owner_sid; PSID group_sid; BOOL dummy; - uid_t uid; - gid_t gid; + __uid16_t uid; + __gid16_t gid; if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy)) { @@ -273,8 +276,8 @@ getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) } gid = cygsid (group_sid).get_gid (); - aclent_t lacl[MAX_ACL_ENTRIES]; - memset (&lacl, 0, MAX_ACL_ENTRIES * sizeof (aclent_t)); + __aclent16_t lacl[MAX_ACL_ENTRIES]; + memset (&lacl, 0, MAX_ACL_ENTRIES * sizeof (__aclent16_t)); lacl[0].a_type = USER_OBJ; lacl[0].a_id = uid; lacl[1].a_type = GROUP_OBJ; @@ -298,7 +301,7 @@ getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) for (pos = 0; pos < MIN_ACL_ENTRIES; ++pos) lacl[pos].a_perm = S_IRWXU | S_IRWXG | S_IRWXO; pos = nentries < MIN_ACL_ENTRIES ? nentries : MIN_ACL_ENTRIES; - memcpy (aclbufp, lacl, pos * sizeof (aclent_t)); + memcpy (aclbufp, lacl, pos * sizeof (__aclent16_t)); return pos; } @@ -389,7 +392,7 @@ getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) if (pos > nentries) pos = nentries; if (aclbufp) - memcpy (aclbufp, lacl, pos * sizeof (aclent_t)); + memcpy (aclbufp, lacl, pos * sizeof (__aclent16_t)); aclsort (pos, 0, aclbufp); syscall_printf ("%d = getacl (%s)", pos, file); return pos; @@ -398,7 +401,7 @@ getacl (const char *file, DWORD attr, int nentries, aclent_t *aclbufp) int acl_access (const char *path, int flags) { - aclent_t acls[MAX_ACL_ENTRIES]; + __aclent16_t acls[MAX_ACL_ENTRIES]; int cnt; if ((cnt = acl (path, GETACL, MAX_ACL_ENTRIES, acls)) < 1) @@ -423,7 +426,7 @@ acl_access (const char *path, int flags) cygsid owner; cygsid group; struct passwd *pw; - struct group *gr = NULL; + struct __group16 *gr = NULL; if ((pw = getpwuid (acls[i].a_id)) != NULL && owner.getfrompw (pw)) @@ -460,7 +463,7 @@ acl_access (const char *path, int flags) static int -acl_worker (const char *path, int cmd, int nentries, aclent_t *aclbufp, +acl_worker (const char *path, int cmd, int nentries, __aclent16_t *aclbufp, int nofollow) { extern suffix_info stat_suffixes[]; @@ -473,7 +476,7 @@ acl_worker (const char *path, int cmd, int nentries, aclent_t *aclbufp, } if (!real_path.has_acls ()) { - struct stat st; + struct __stat64 st; int ret = -1; switch (cmd) @@ -484,10 +487,10 @@ acl_worker (const char *path, int cmd, int nentries, aclent_t *aclbufp, case GETACL: if (nentries < 1) set_errno (EINVAL); - else if ((nofollow && !lstat (path, &st)) - || (!nofollow && !stat (path, &st))) + else if ((nofollow && !lstat64 (path, &st)) + || (!nofollow && !stat64 (path, &st))) { - aclent_t lacl[4]; + __aclent16_t lacl[4]; if (nentries > 0) { lacl[0].a_type = USER_OBJ; @@ -523,7 +526,7 @@ acl_worker (const char *path, int cmd, int nentries, aclent_t *aclbufp, if (nentries > 4) nentries = 4; if (aclbufp) - memcpy (aclbufp, lacl, nentries * sizeof (aclent_t)); + memcpy (aclbufp, lacl, nentries * sizeof (__aclent16_t)); ret = nentries; } break; @@ -561,21 +564,21 @@ acl_worker (const char *path, int cmd, int nentries, aclent_t *aclbufp, extern "C" int -acl (const char *path, int cmd, int nentries, aclent_t *aclbufp) +acl (const char *path, int cmd, int nentries, __aclent16_t *aclbufp) { return acl_worker (path, cmd, nentries, aclbufp, 0); } extern "C" int -lacl (const char *path, int cmd, int nentries, aclent_t *aclbufp) +lacl (const char *path, int cmd, int nentries, __aclent16_t *aclbufp) { return acl_worker (path, cmd, nentries, aclbufp, 1); } extern "C" int -facl (int fd, int cmd, int nentries, aclent_t *aclbufp) +facl (int fd, int cmd, int nentries, __aclent16_t *aclbufp) { cygheap_fdget cfd (fd); if (cfd < 0) @@ -596,7 +599,7 @@ facl (int fd, int cmd, int nentries, aclent_t *aclbufp) extern "C" int -aclcheck (aclent_t *aclbufp, int nentries, int *which) +aclcheck (__aclent16_t *aclbufp, int nentries, int *which) { BOOL has_user_obj = FALSE; BOOL has_group_obj = FALSE; @@ -730,7 +733,7 @@ aclcheck (aclent_t *aclbufp, int nentries, int *which) extern "C" int acecmp (const void *a1, const void *a2) { -#define ace(i) ((const aclent_t *) a##i) +#define ace(i) ((const __aclent16_t *) a##i) int ret = ace(1)->a_type - ace(2)->a_type; if (!ret) ret = ace(1)->a_id - ace(2)->a_id; @@ -740,7 +743,7 @@ int acecmp (const void *a1, const void *a2) extern "C" int -aclsort (int nentries, int, aclent_t *aclbufp) +aclsort (int nentries, int, __aclent16_t *aclbufp) { if (aclcheck (aclbufp, nentries, NULL)) return -1; @@ -749,13 +752,13 @@ aclsort (int nentries, int, aclent_t *aclbufp) set_errno (EINVAL); return -1; } - qsort((void *) aclbufp, nentries, sizeof (aclent_t), acecmp); + qsort((void *) aclbufp, nentries, sizeof (__aclent16_t), acecmp); return 0; } extern "C" int -acltomode (aclent_t *aclbufp, int nentries, mode_t *modep) +acltomode (__aclent16_t *aclbufp, int nentries, mode_t *modep) { int pos; @@ -790,7 +793,7 @@ acltomode (aclent_t *aclbufp, int nentries, mode_t *modep) extern "C" int -aclfrommode(aclent_t *aclbufp, int nentries, mode_t *modep) +aclfrommode(__aclent16_t *aclbufp, int nentries, mode_t *modep) { int pos; @@ -830,14 +833,14 @@ aclfrommode(aclent_t *aclbufp, int nentries, mode_t *modep) extern "C" int -acltopbits (aclent_t *aclbufp, int nentries, mode_t *pbitsp) +acltopbits (__aclent16_t *aclbufp, int nentries, mode_t *pbitsp) { return acltomode (aclbufp, nentries, pbitsp); } extern "C" int -aclfrompbits (aclent_t *aclbufp, int nentries, mode_t *pbitsp) +aclfrompbits (__aclent16_t *aclbufp, int nentries, mode_t *pbitsp) { return aclfrommode (aclbufp, nentries, pbitsp); } @@ -856,7 +859,7 @@ permtostr (mode_t perm) extern "C" char * -acltotext (aclent_t *aclbufp, int aclcnt) +acltotext (__aclent16_t *aclbufp, int aclcnt) { if (!aclbufp || aclcnt < 1 || aclcnt > MAX_ACL_ENTRIES || aclcheck (aclbufp, aclcnt, NULL)) @@ -932,7 +935,7 @@ permfromstr (char *perm) } extern "C" -aclent_t * +__aclent16_t * aclfromtext (char *acltextp, int *) { if (!acltextp) @@ -941,7 +944,7 @@ aclfromtext (char *acltextp, int *) return NULL; } char buf[strlen (acltextp) + 1]; - aclent_t lacl[MAX_ACL_ENTRIES]; + __aclent16_t lacl[MAX_ACL_ENTRIES]; memset (lacl, 0, sizeof lacl); int pos = 0; strcpy (buf, acltextp); @@ -993,7 +996,7 @@ aclfromtext (char *acltextp, int *) c += 5; if (isalpha (*c)) { - struct group *gr = getgrnam (c); + struct __group16 *gr = getgrnam (c); if (!gr) { set_errno (EINVAL); @@ -1038,9 +1041,9 @@ aclfromtext (char *acltextp, int *) } ++pos; } - aclent_t *aclp = (aclent_t *) malloc (pos * sizeof (aclent_t)); + __aclent16_t *aclp = (__aclent16_t *) malloc (pos * sizeof (__aclent16_t)); if (aclp) - memcpy (aclp, lacl, pos * sizeof (aclent_t)); + memcpy (aclp, lacl, pos * sizeof (__aclent16_t)); return aclp; } diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index b618cf32d..2f9b9b60c 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -1,6 +1,6 @@ /* sec_helper.cc: NT security helper functions - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. Written by Corinna Vinschen <corinna@vinschen.de> @@ -129,7 +129,7 @@ cygsid::getfrompw (const struct passwd *pw) } BOOL -cygsid::getfromgr (const struct group *gr) +cygsid::getfromgr (const struct __group16 *gr) { char *sp = (gr && gr->gr_passwd) ? gr->gr_passwd : NULL; return (*this = sp ?: "") != NULL; @@ -176,7 +176,7 @@ cygsid::get_id (BOOL search_grp, int *type) } if (search_grp || type) { - struct group *gr; + struct __group16 *gr; for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) { if (sid.getfromgr (gr) && sid == psid) @@ -226,7 +226,7 @@ cygsid::get_id (BOOL search_grp, int *type) *type = GROUP; if (id == -1) { - struct group *gr = getgrnam (account); + struct __group16 *gr = getgrnam (account); if (gr) id = gr->gr_gid; } @@ -251,13 +251,13 @@ cygsid::get_id (BOOL search_grp, int *type) } BOOL -is_grp_member (uid_t uid, gid_t gid) +is_grp_member (__uid16_t uid, __gid16_t gid) { - extern int getgroups (int, gid_t *, gid_t, const char *); + extern int getgroups (int, __gid16_t *, __gid16_t, const char *); BOOL grp_member = TRUE; struct passwd *pw = getpwuid (uid); - gid_t grps[NGROUPS_MAX]; + __gid16_t grps[NGROUPS_MAX]; int cnt = getgroups (NGROUPS_MAX, grps, pw ? pw->pw_gid : myself->gid, pw ? pw->pw_name : cygheap->user.name ()); diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 6bacfdef0..b33360d1a 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -1,6 +1,6 @@ /* security.cc: NT security functions - Copyright 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. Originaly written by Gunther Ebert, gunther.ebert@ixos-leipzig.de Completely rewritten by Corinna Vinschen <corinna@vinschen.de> @@ -42,7 +42,6 @@ details. */ #include "ntdll.h" #include "lm.h" - extern BOOL allow_ntea; BOOL allow_ntsec; /* allow_smbntsec is handled exclusively in path.cc (path_conv::check). @@ -451,7 +450,7 @@ get_user_primary_group (WCHAR *wlogonserver, const char *user, static int get_supplementary_group_sidlist (const char *username, cygsidlist &grp_list) { - struct group *gr; + struct __group16 *gr; int cnt = 0; for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) @@ -710,7 +709,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid) { sizeof sqos, SecurityImpersonation, SECURITY_STATIC_TRACKING, FALSE }; OBJECT_ATTRIBUTES oa = { sizeof oa, 0, 0, 0, 0, &sqos }; - SECURITY_ATTRIBUTES sa = { sizeof sa, NULL, TRUE }; + char sa_buf[1024]; LUID auth_luid = SYSTEM_LUID; LARGE_INTEGER exp = { QuadPart:0x7fffffffffffffffLL }; @@ -727,7 +726,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid) source.SourceIdentifier.HighPart = 0; source.SourceIdentifier.LowPart = 0x0101; - HANDLE token; + HANDLE token = INVALID_HANDLE_VALUE; HANDLE primary_token = INVALID_HANDLE_VALUE; HANDLE my_token = INVALID_HANDLE_VALUE; @@ -827,9 +826,8 @@ create_token (cygsid &usersid, cygsid &pgrpsid) } /* Convert to primary token. */ - if (!DuplicateTokenEx (token, TOKEN_ALL_ACCESS, &sa, - SecurityImpersonation, TokenPrimary, - &primary_token)) + if (!DuplicateTokenEx (token, MAXIMUM_ALLOWED, sec_user (sa_buf, usersid), + SecurityImpersonation, TokenPrimary, &primary_token)) __seterrno (); out: @@ -1087,7 +1085,7 @@ write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size) static int get_nt_attribute (const char *file, int *attribute, - uid_t *uidret, gid_t *gidret) + __uid16_t *uidret, __gid16_t *gidret) { if (!wincap.has_security ()) return 0; @@ -1125,8 +1123,8 @@ get_nt_attribute (const char *file, int *attribute, return -1; } - uid_t uid = cygsid(owner_sid).get_uid (); - gid_t gid = cygsid(group_sid).get_gid (); + __uid16_t uid = cygsid(owner_sid).get_uid (); + __gid16_t gid = cygsid(group_sid).get_gid (); if (uidret) *uidret = uid; if (gidret) @@ -1236,7 +1234,7 @@ get_nt_attribute (const char *file, int *attribute, int get_file_attribute (int use_ntsec, const char *file, - int *attribute, uid_t *uidret, gid_t *gidret) + int *attribute, __uid16_t *uidret, __gid16_t *gidret) { int res; @@ -1307,7 +1305,7 @@ add_access_denied_ace (PACL acl, int offset, DWORD attributes, } PSECURITY_DESCRIPTOR -alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute, +alloc_sd (__uid16_t uid, __gid16_t gid, const char *logsrv, int attribute, PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret) { BOOL dummy; @@ -1335,7 +1333,7 @@ alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute, /* Get SID and name of new group. */ cygsid group_sid (NO_SID); - struct group *grp = getgrgid (gid); + struct __group16 *grp = getgrgid (gid); if (grp) { if ((!grp || !group_sid.getfromgr (grp)) @@ -1576,7 +1574,7 @@ set_security_attribute (int attribute, PSECURITY_ATTRIBUTES psa, } static int -set_nt_attribute (const char *file, uid_t uid, gid_t gid, +set_nt_attribute (const char *file, __uid16_t uid, __gid16_t gid, const char *logsrv, int attribute) { if (!wincap.has_security ()) @@ -1602,7 +1600,7 @@ set_nt_attribute (const char *file, uid_t uid, gid_t gid, int set_file_attribute (int use_ntsec, const char *file, - uid_t uid, gid_t gid, + __uid16_t uid, __gid16_t gid, int attribute, const char *logsrv) { int ret = 0; diff --git a/winsup/cygwin/security.h b/winsup/cygwin/security.h index c1636aab0..220f57168 100644 --- a/winsup/cygwin/security.h +++ b/winsup/cygwin/security.h @@ -1,6 +1,6 @@ /* security.h: security declarations - Copyright 2000, 2001 Red Hat, Inc. + Copyright 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -55,7 +55,7 @@ public: inline PSID set () { return psid = (PSID) sbuf; } BOOL getfrompw (const struct passwd *pw); - BOOL getfromgr (const struct group *gr); + BOOL getfromgr (const struct __group16 *gr); int get_id (BOOL search_grp, int *type = NULL); inline int get_uid () { return get_id (FALSE); } @@ -159,14 +159,14 @@ extern BOOL allow_smbntsec; and group lists so they are somehow security related. Besides that I didn't find a better place to declare them. */ extern struct passwd *internal_getpwent (int); -extern struct group *internal_getgrent (int); +extern struct __group16 *internal_getgrent (int); /* File manipulation */ int __stdcall set_process_privileges (); int __stdcall get_file_attribute (int, const char *, int *, - uid_t * = NULL, gid_t * = NULL); + __uid16_t * = NULL, __gid16_t * = NULL); int __stdcall set_file_attribute (int, const char *, int); -int __stdcall set_file_attribute (int, const char *, uid_t, gid_t, int, const char *); +int __stdcall set_file_attribute (int, const char *, __uid16_t, __gid16_t, int, const char *); LONG __stdcall read_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, LPDWORD sd_size); LONG __stdcall write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size); BOOL __stdcall add_access_allowed_ace (PACL acl, int offset, DWORD attributes, PSID sid, size_t &len_add, DWORD inherit); @@ -186,7 +186,7 @@ void extract_nt_dom_user (const struct passwd *pw, char *domain, char *user); BOOL get_logon_server_and_user_domain (char *logonserver, char *domain); /* sec_helper.cc: Security helper functions. */ -BOOL __stdcall is_grp_member (uid_t uid, gid_t gid); +BOOL __stdcall is_grp_member (__uid16_t uid, __gid16_t gid); /* `lookup_name' should be called instead of LookupAccountName. * logsrv may be NULL, in this case only the local system is used for lookup. * The buffer for ret_sid (40 Bytes) has to be allocated by the caller! */ @@ -199,10 +199,22 @@ SECURITY_DESCRIPTOR *__stdcall get_null_sd (void); /* Various types of security attributes for use in Create* functions. */ extern SECURITY_ATTRIBUTES sec_none, sec_none_nih, sec_all, sec_all_nih; -extern SECURITY_ATTRIBUTES *__stdcall sec_user (PVOID sa_buf, PSID sid2 = NULL, BOOL inherit = TRUE); -extern SECURITY_ATTRIBUTES *__stdcall sec_user_nih (PVOID sa_buf, PSID sid2 = NULL); +extern SECURITY_ATTRIBUTES *__stdcall __sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) + __attribute__ ((regparm (3))); int __stdcall NTReadEA (const char *file, const char *attrname, char *buf, int len); BOOL __stdcall NTWriteEA (const char *file, const char *attrname, const char *buf, int len); PSECURITY_DESCRIPTOR alloc_sd (uid_t uid, gid_t gid, const char *logsrv, int attribute, PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret); + +extern inline SECURITY_ATTRIBUTES * +sec_user_nih (char sa_buf[], PSID sid = NULL) +{ + return allow_ntsec ? __sec_user (sa_buf, sid, FALSE) : &sec_none_nih; +} + +extern inline SECURITY_ATTRIBUTES * +sec_user (char sa_buf[], PSID sid = NULL) +{ + return allow_ntsec ? __sec_user (sa_buf, sid, TRUE) : &sec_none_nih; +} diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 56d818d56..ebc9c8881 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -452,7 +452,7 @@ peek_pipe (select_record *s, bool from_select) n = -1; } else if (!n || !guard_mutex) - /* no guard mutex or nothing to read fromt he pipe. */; + /* no guard mutex or nothing to read from the pipe. */; else if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0) { select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (), diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index f10fd7f10..5f1bc1fdd 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -237,11 +237,8 @@ get_null_sd () } PSECURITY_ATTRIBUTES __stdcall -sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) +__sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) { - if (! sa_buf) - return inherit ? &sec_none_nih : &sec_none; - PSECURITY_ATTRIBUTES psa = (PSECURITY_ATTRIBUTES) sa_buf; PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) ((char *) sa_buf + sizeof (*psa)); @@ -251,8 +248,8 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) if (cygheap->user.sid ()) sid = cygheap->user.sid (); - else if (! lookup_name (getlogin (), cygheap->user.logsrv (), sid)) - return inherit ? &sec_none_nih : &sec_none; + else if (!lookup_name (getlogin (), cygheap->user.logsrv (), sid)) + return inherit ? &sec_none : &sec_none_nih; size_t acl_len = sizeof (ACL) + 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD)) @@ -264,37 +261,36 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) acl_len += sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD) + GetLengthSid (sid2); - if (! InitializeAcl (acl, acl_len, ACL_REVISION)) + if (!InitializeAcl (acl, acl_len, ACL_REVISION)) debug_printf ("InitializeAcl %E"); - if (! AddAccessAllowedAce (acl, ACL_REVISION, - SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, - sid)) + if (!AddAccessAllowedAce (acl, ACL_REVISION, + SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, + sid)) debug_printf ("AddAccessAllowedAce(%s) %E", getlogin ()); - if (! AddAccessAllowedAce (acl, ACL_REVISION, - SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, - well_known_admins_sid)) + if (!AddAccessAllowedAce (acl, ACL_REVISION, + SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, + well_known_admins_sid)) debug_printf ("AddAccessAllowedAce(admin) %E"); - if (! AddAccessAllowedAce (acl, ACL_REVISION, - SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, - well_known_system_sid)) + if (!AddAccessAllowedAce (acl, ACL_REVISION, + SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, + well_known_system_sid)) debug_printf ("AddAccessAllowedAce(system) %E"); - if (! AddAccessAllowedAce (acl, ACL_REVISION, - SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, - well_known_creator_owner_sid)) + if (!AddAccessAllowedAce (acl, ACL_REVISION, + SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, + well_known_creator_owner_sid)) debug_printf ("AddAccessAllowedAce(creator_owner) %E"); if (sid2) - if (! AddAccessAllowedAce (acl, ACL_REVISION, - SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, - sid2)) + if (!AddAccessAllowedAce (acl, ACL_REVISION, + SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL, + sid2)) debug_printf ("AddAccessAllowedAce(sid2) %E"); - if (! InitializeSecurityDescriptor (psd, - SECURITY_DESCRIPTOR_REVISION)) + if (!InitializeSecurityDescriptor (psd, SECURITY_DESCRIPTOR_REVISION)) debug_printf ("InitializeSecurityDescriptor %E"); /* @@ -303,11 +299,11 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) * what it should do also if the owner isn't set. */ #if 0 - if (! SetSecurityDescriptorOwner (psd, sid, FALSE)) + if (!SetSecurityDescriptorOwner (psd, sid, FALSE)) debug_printf ("SetSecurityDescriptorOwner %E"); #endif - if (! SetSecurityDescriptorDacl (psd, TRUE, acl, FALSE)) + if (!SetSecurityDescriptorDacl (psd, TRUE, acl, FALSE)) debug_printf ("SetSecurityDescriptorDacl %E"); psa->nLength = sizeof (SECURITY_ATTRIBUTES); @@ -315,9 +311,3 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) psa->bInheritHandle = inherit; return psa; } - -SECURITY_ATTRIBUTES *__stdcall -sec_user_nih (PVOID sa_buf, PSID sid2) -{ - return sec_user (sa_buf, sid2, FALSE); -} diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index bfe5f9901..d8e5845e2 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -103,11 +103,14 @@ Static HANDLE wait_sig_inited = NULL; // Control synchronization of */ Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++ #define hchildren (events + 1) // Where the children handles begin -Static pinfo pchildren[PSIZE]; // All my children info +Static char cpchildren[PSIZE * sizeof (pinfo)]; // All my children info Static int nchildren = 0; // Number of active children -Static pinfo zombies[NZOMBIES]; // All my deceased children info +Static char czombies[NZOMBIES * sizeof (pinfo)]; // All my deceased children info Static int nzombies = 0; // Number of deceased children +#define pchildren ((pinfo *) cpchildren) +#define zombies ((pinfo *) czombies) + Static waitq waitq_head = {0, 0, 0, 0, 0, 0, 0};// Start of queue for wait'ing threads Static waitq waitq_main; // Storage for main thread @@ -315,12 +318,14 @@ proc_subproc (DWORD what, DWORD val) if (hchildren[val] != pchildren[val]->hProcess) { sigproc_printf ("pid %d[%d], reparented old hProcess %p, new %p", - pchildren[val]->pid, val, hchildren[val], pchildren[val]->hProcess); - ForceCloseHandle1 (hchildren[val], childhProc); + pchildren[val]->pid, val, hchildren[val], pchildren[val]->hProcess); + HANDLE h = hchildren[val]; hchildren[val] = pchildren[val]->hProcess; /* Filled out by child */ + sync_proc_subproc->release (); // Release the lock ASAP + ForceCloseHandle1 (h, childhProc); ProtectHandle1 (pchildren[val]->hProcess, childhProc); rc = 0; - break; // This was an exec() + goto out; // This was an exec() } sigproc_printf ("pid %d[%d] terminated, handle %p, nchildren %d, nzombies %d", @@ -587,7 +592,7 @@ sigproc_init () /* sync_proc_subproc is used by proc_subproc. It serialises * access to the children and zombie arrays. */ - sync_proc_subproc = new_muto (FALSE, "sync_proc_subproc"); + new_muto (sync_proc_subproc); /* Initialize waitq structure for main thread. A waitq structure is * allocated for each thread that executes a wait to allow multiple threads @@ -939,8 +944,8 @@ getsem (_pinfo *p, const char *str, int init, int max) char sa_buf[1024]; DWORD winpid = GetCurrentProcessId (); - h = CreateSemaphore (allow_ntsec ? sec_user_nih (sa_buf) : &sec_none_nih, - init, max, str = shared_name (str, winpid)); + h = CreateSemaphore (sec_user_nih (sa_buf), init, max, + str = shared_name (str, winpid)); p = myself; if (!h) { @@ -1182,9 +1187,9 @@ wait_sig (VOID *) /* just forcing the loop */ break; - /* Internal signal to force a flush of strace data to disk. */ + /* Internal signal to turn on stracing. */ case __SIGSTRACE: - // proc_strace (); // Dump cached strace.prntf stuff. + strace.hello (); break; /* A normal UNIX signal */ diff --git a/winsup/cygwin/smallprint.c b/winsup/cygwin/smallprint.c index d6be72a6c..97a2b6ce1 100644 --- a/winsup/cygwin/smallprint.c +++ b/winsup/cygwin/smallprint.c @@ -19,11 +19,11 @@ int __small_sprintf (char *dst, const char *fmt,...); int __small_vsprintf (char *dst, const char *fmt, va_list ap); static char * -rn (char *dst, int base, int dosign, int val, int len, int pad) +rn (char *dst, int base, int dosign, long long val, int len, int pad) { - /* longest number is 4294967295, 10 digits */ + /* longest number is ULLONG_MAX, 18446744073709551615, 20 digits */ unsigned uval; - char res[10]; + char res[20]; static const char str[16] = "0123456789ABCDEF"; int l = 0; @@ -126,9 +126,15 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap) case 'd': dst = rn (dst, 10, addsign, va_arg (ap, int), len, pad); break; + case 'D': + dst = rn (dst, 10, addsign, va_arg (ap, long long), len, pad); + break; case 'u': dst = rn (dst, 10, 0, va_arg (ap, int), len, pad); break; + case 'U': + dst = rn (dst, 10, 0, va_arg (ap, long long), len, pad); + break; case 'p': *dst++ = '0'; *dst++ = 'x'; @@ -136,6 +142,9 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap) case 'x': dst = rn (dst, 16, 0, va_arg (ap, int), len, pad); break; + case 'X': + dst = rn (dst, 16, 0, va_arg (ap, long long), len, pad); + break; case 'P': if (!GetModuleFileName (NULL, tmp, MAX_PATH)) s = "cygwin program"; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 887e69b3e..b5dc670ce 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -635,9 +635,9 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, rc = CreateProcess (runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ /* process security attrs */ - allow_ntsec ? sec_user (sa_buf) : &sec_all_nih, + sec_user_nih (sa_buf), /* thread security attrs */ - allow_ntsec ? sec_user (sa_buf) : &sec_all_nih, + sec_user_nih (sa_buf), TRUE, /* inherit handles from parent */ flags, envblock,/* environment */ @@ -656,9 +656,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, } /* Retrieve security attributes before setting psid to NULL since it's value is needed by `sec_user'. */ - PSECURITY_ATTRIBUTES sec_attribs = allow_ntsec && sid - ? sec_user (sa_buf, sid) - : &sec_all_nih; + PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf, sid); /* Remove impersonation */ if (cygheap->user.impersonated @@ -682,7 +680,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, char wstname[1024]; char dskname[1024]; - ciresrv.moreinfo->uid = USHRT_MAX; + ciresrv.moreinfo->uid = ILLEGAL_UID; hwst = GetProcessWindowStation (); SetUserObjectSecurity (hwst, &dsi, get_null_sd ()); GetUserObjectInformation (hwst, UOI_NAME, wstname, 1024, &n); diff --git a/winsup/cygwin/speclib b/winsup/cygwin/speclib index a5ce7f46b..6f8e0cd73 100755 --- a/winsup/cygwin/speclib +++ b/winsup/cygwin/speclib @@ -17,7 +17,7 @@ nm=$1; shift dlltool=$1; shift as=$1; shift def=$1; shift -trap "rm /tmp/$$.def" 0 1 2 15 +trap "rm -f /tmp/$$.def" 0 1 2 15 (echo "LIBRARY cygwin1.dll EXPORTS"; $nm --extern-only --defined-only $* | sed -e '/^[ ]*$/d' -e '/:$/d' -e 's/^.* _\(.*\)/\1/' | grep $v -f - -w $def |egrep -vi '^library|exports|^$' | sort) > /tmp/$$.def -exec $dlltool --as=$as -d /tmp/$$.def -l "$lib" +$dlltool --as=$as -d /tmp/$$.def -l "$lib" diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc index b7e0a2a32..a3a699327 100644 --- a/winsup/cygwin/strace.cc +++ b/winsup/cygwin/strace.cc @@ -17,6 +17,9 @@ details. */ #include "sync.h" #include "sigproc.h" #include "pinfo.h" +#include "perprocess.h" +#include "cygwin_version.h" +#include "hires.h" #define PROTECT(x) x[sizeof(x)-1] = 0 #define CHECK(x) if (x[sizeof(x)-1] != 0) { small_printf("array bound exceeded %d\n", __LINE__); ExitProcess(1); } @@ -28,38 +31,41 @@ class NO_COPY strace strace; #ifndef NOSTRACE -int -strace::microseconds() +void +strace::hello() { - static NO_COPY int first_microsec = 0; - static NO_COPY long long hires_frequency = 0; - static NO_COPY int hires_initted = 0; + char buf[30]; - int microsec; - - if (!hires_initted) + if (inited) { - hires_initted = 1; - QueryPerformanceFrequency ((LARGE_INTEGER *) &hires_frequency); - if (hires_frequency == 0) - hires_initted = 2; + active ^= 1; + return; } - if (hires_initted == 2) - { - int count = GetTickCount (); - microsec = count * 1000; - } - else + + __small_sprintf (buf, "cYg%8x %x", _STRACE_INTERFACE_ACTIVATE_ADDR, &active); + OutputDebugString (buf); + + if (active) { - long long thiscount; - QueryPerformanceCounter ((LARGE_INTEGER *) &thiscount); - thiscount = (long long) (((double) thiscount/(double) hires_frequency) - * 1000000.0); - microsec = thiscount; + prntf (1, NULL, "**********************************************"); + prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid); + prntf (1, NULL, "App version: %d.%d, api: %d.%d", + user_data->dll_major, user_data->dll_minor, + user_data->api_major, user_data->api_minor); + prntf (1, NULL, "DLL version: %d.%d, api: %d.%d", + cygwin_version.dll_major, cygwin_version.dll_minor, + cygwin_version.api_major, cygwin_version.api_minor); + prntf (1, NULL, "DLL build: %s", cygwin_version.dll_build_date); + prntf (1, NULL, "OS version: Windows %s", wincap.osname ()); + prntf (1, NULL, "**********************************************"); } - if (first_microsec == 0) - first_microsec = microsec; - return microsec - first_microsec; +} + +int +strace::microseconds () +{ + static hires now; + return (int) now.usecs (true); } static int __stdcall diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index 743ee02e7..333ec193c 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -28,18 +28,24 @@ muto NO_COPY muto_start; #undef WaitForSingleObject /* Constructor */ -muto::muto (int inh, const char *s) : sync (0), visits(0), waiters(-1), tid (0), next (NULL) +muto * +muto::init (const char *s) { + waiters = -1; /* Create event which is used in the fallback case when blocking is necessary */ - if (!(bruteforce = CreateEvent (inh ? &sec_all_nih : &sec_none_nih, FALSE, FALSE, name))) + if (!(bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL))) { DWORD oerr = GetLastError (); SetLastError (oerr); - return; + return NULL; } name = s; + next = muto_start.next; + muto_start.next = this; + return this; } +#if 0 /* FIXME: Do we need this? mutos aren't destroyed until process exit */ /* Destructor (racy?) */ muto::~muto () { @@ -52,6 +58,7 @@ muto::~muto () if (h) CloseHandle (h); } +#endif /* Acquire the lock. Argument is the number of milliseconds to wait for the lock. Multiple visits from the same thread are allowed and should diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h index d546b71e5..3e30cd58d 100644 --- a/winsup/cygwin/sync.h +++ b/winsup/cygwin/sync.h @@ -23,17 +23,13 @@ public: class muto *next; const char *name; - muto() {} /* The real constructor. */ - muto(int inh, const char *name); + muto *init(const char *name) __attribute__ ((regparm (3))); - void *operator new (size_t, void *p) {return p;} - void *operator new (size_t) {return ::new muto; } - void operator delete (void *) {;} /* can't handle allocated mutos - currently */ - - ~muto (); - int acquire (DWORD ms = INFINITE) __attribute__ ((regparm(1))); /* Acquire the lock. */ +#if 0 /* FIXME: See comment in sync.cc */ + ~muto () +#endif + int acquire (DWORD ms = INFINITE) __attribute__ ((regparm (1))); /* Acquire the lock. */ int release (); /* Release the lock. */ /* Return true if caller thread owns the lock. */ @@ -46,11 +42,8 @@ public: extern muto muto_start; /* Use a statically allocated buffer as the storage for a muto */ -#define new_muto(__inh, __name) \ +#define new_muto(__name) \ ({ \ - static volatile __attribute__((section(".data_cygwin_nocopy"))) muto __mbuf; \ - (void) new ((void *) &__mbuf) muto (__inh, __name); \ - __mbuf.next = muto_start.next; \ - muto_start.next = (muto *) &__mbuf; \ - (muto *) &__mbuf; \ + static muto __name##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \ + __name = __name##_storage.init (#__name); \ }) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index a8b2eb2e3..7c0672e44 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -527,10 +527,10 @@ _open (const char *unix_path, int flags, ...) return res; } -extern "C" off_t -_lseek (int fd, off_t pos, int dir) +extern "C" __off64_t +lseek64 (int fd, __off64_t pos, int dir) { - off_t res; + __off64_t res; sigframe thisframe (mainthread); if (dir != SEEK_SET && dir != SEEK_CUR && dir != SEEK_END) @@ -546,11 +546,17 @@ _lseek (int fd, off_t pos, int dir) else res = -1; } - syscall_printf ("%d = lseek (%d, %d, %d)", res, fd, pos, dir); + syscall_printf ("%d = lseek (%d, %D, %d)", res, fd, pos, dir); return res; } +extern "C" __off32_t +_lseek (int fd, __off32_t pos, int dir) +{ + return lseek64 (fd, (__off64_t) pos, dir); +} + extern "C" int _close (int fd) { @@ -744,11 +750,11 @@ done: * systems, it is only a stub that always returns zero. */ static int -chown_worker (const char *name, unsigned fmode, uid_t uid, gid_t gid) +chown_worker (const char *name, unsigned fmode, __uid16_t uid, __gid16_t gid) { int res; - uid_t old_uid; - gid_t old_gid; + __uid16_t old_uid; + __gid16_t old_gid; if (check_null_empty_str_errno (name)) return -1; @@ -785,9 +791,9 @@ chown_worker (const char *name, unsigned fmode, uid_t uid, gid_t gid) &old_gid); if (!res) { - if (uid == (uid_t) -1) + if (uid == ILLEGAL_UID) uid = old_uid; - if (gid == (gid_t) -1) + if (gid == ILLEGAL_GID) gid = old_gid; if (win32_path.isdir()) attrib |= S_IFDIR; @@ -809,21 +815,21 @@ done: } extern "C" int -chown (const char * name, uid_t uid, gid_t gid) +chown (const char * name, __uid16_t uid, __gid16_t gid) { sigframe thisframe (mainthread); return chown_worker (name, PC_SYM_FOLLOW, uid, gid); } extern "C" int -lchown (const char * name, uid_t uid, gid_t gid) +lchown (const char * name, __uid16_t uid, __gid16_t gid) { sigframe thisframe (mainthread); return chown_worker (name, PC_SYM_NOFOLLOW, uid, gid); } extern "C" int -fchown (int fd, uid_t uid, gid_t gid) +fchown (int fd, __uid16_t uid, __gid16_t gid) { sigframe thisframe (mainthread); cygheap_fdget cfd (fd); @@ -888,8 +894,8 @@ chmod (const char *path, mode_t mode) /* temporary erase read only bit, to be able to set file security */ SetFileAttributes (win32_path, (DWORD) win32_path & ~FILE_ATTRIBUTE_READONLY); - uid_t uid; - gid_t gid; + __uid16_t uid; + __gid16_t gid; if (win32_path.isdir ()) mode |= S_IFDIR; @@ -956,8 +962,26 @@ fchmod (int fd, mode_t mode) return chmod (path, mode); } +static void +stat64_to_stat32 (struct __stat64 *src, struct __stat32 *dst) +{ + dst->st_dev = src->st_dev; + dst->st_ino = src->st_ino; + dst->st_mode = src->st_mode; + dst->st_nlink = src->st_nlink; + dst->st_uid = src->st_uid; + dst->st_gid = src->st_gid; + dst->st_rdev = src->st_rdev; + dst->st_size = src->st_size; + dst->st_atime = src->st_atime; + dst->st_mtime = src->st_mtime; + dst->st_ctime = src->st_ctime; + dst->st_blksize = src->st_blksize; + dst->st_blocks = src->st_blocks; +} + extern "C" int -_fstat (int fd, struct stat *buf) +fstat64 (int fd, struct __stat64 *buf) { int res; sigframe thisframe (mainthread); @@ -967,7 +991,7 @@ _fstat (int fd, struct stat *buf) res = -1; else { - memset (buf, 0, sizeof (struct stat)); + memset (buf, 0, sizeof (struct __stat64)); res = cfd->fstat (buf, NULL); } @@ -975,6 +999,16 @@ _fstat (int fd, struct stat *buf) return res; } +extern "C" int +_fstat (int fd, struct __stat32 *buf) +{ + struct __stat64 buf64; + int ret = fstat64 (fd, &buf64); + if (!ret) + stat64_to_stat32 (&buf64, buf); + return ret; +} + /* fsync: P96 6.6.1.1 */ extern "C" int fsync (int fd) @@ -1011,7 +1045,8 @@ suffix_info stat_suffixes[] = /* Cygwin internal */ int __stdcall -stat_worker (const char *name, struct stat *buf, int nofollow, path_conv *pc) +stat_worker (const char *name, struct __stat64 *buf, int nofollow, + path_conv *pc) { int res = -1; path_conv real_path; @@ -1038,7 +1073,7 @@ stat_worker (const char *name, struct stat *buf, int nofollow, path_conv *pc) { debug_printf ("(%s, %p, %d, %p), file_attributes %d", name, buf, nofollow, pc, (DWORD) real_path); - memset (buf, 0, sizeof (struct stat)); + memset (buf, 0, sizeof (struct __stat64)); res = fh->fstat (buf, pc); } @@ -1051,22 +1086,43 @@ stat_worker (const char *name, struct stat *buf, int nofollow, path_conv *pc) } extern "C" int -_stat (const char *name, struct stat *buf) +stat64 (const char *name, struct __stat64 *buf) { sigframe thisframe (mainthread); syscall_printf ("entering"); return stat_worker (name, buf, 0); } +extern "C" int +_stat (const char *name, struct __stat32 *buf) +{ + struct __stat64 buf64; + int ret = stat64 (name, &buf64); + if (!ret) + stat64_to_stat32 (&buf64, buf); + return ret; +} + /* lstat: Provided by SVR4 and 4.3+BSD, POSIX? */ extern "C" int -lstat (const char *name, struct stat *buf) +lstat64 (const char *name, struct __stat64 *buf) { sigframe thisframe (mainthread); syscall_printf ("entering"); return stat_worker (name, buf, 1); } +/* lstat: Provided by SVR4 and 4.3+BSD, POSIX? */ +extern "C" int +cygwin_lstat (const char *name, struct __stat32 *buf) +{ + struct __stat64 buf64; + int ret = lstat64 (name, &buf64); + if (!ret) + stat64_to_stat32 (&buf64, buf); + return ret; +} + extern int acl_access (const char *, int); extern "C" int @@ -1083,7 +1139,7 @@ access (const char *fn, int flags) if (allow_ntsec) return acl_access (fn, flags); - struct stat st; + struct __stat64 st; int r = stat_worker (fn, &st, 0); if (r) return -1; @@ -1607,9 +1663,8 @@ setmode (int fd, int mode) return res; } -/* ftruncate: P96 5.6.7.1 */ extern "C" int -ftruncate (int fd, off_t length) +ftruncate64 (int fd, __off64_t length) { sigframe thisframe (mainthread); int res = -1; @@ -1626,7 +1681,7 @@ ftruncate (int fd, off_t length) if (cfd->get_handle ()) { /* remember curr file pointer location */ - off_t prev_loc = cfd->lseek (0, SEEK_CUR); + __off64_t prev_loc = cfd->lseek (0, SEEK_CUR); cfd->lseek (length, SEEK_SET); if (!SetEndOfFile (h)) @@ -1635,7 +1690,7 @@ ftruncate (int fd, off_t length) res = 0; /* restore original file pointer location */ - cfd->lseek (prev_loc, 0); + cfd->lseek (prev_loc, SEEK_SET); } } } @@ -1644,9 +1699,16 @@ ftruncate (int fd, off_t length) return res; } +/* ftruncate: P96 5.6.7.1 */ +extern "C" int +ftruncate (int fd, __off32_t length) +{ + return ftruncate64 (fd, (__off64_t)length); +} + /* truncate: Provided by SVR4 and 4.3+BSD. Not part of POSIX.1 or XPG3 */ extern "C" int -truncate (const char *pathname, off_t length) +truncate64 (const char *pathname, __off64_t length) { sigframe thisframe (mainthread); int fd; @@ -1666,6 +1728,13 @@ truncate (const char *pathname, off_t length) return res; } +/* truncate: Provided by SVR4 and 4.3+BSD. Not part of POSIX.1 or XPG3 */ +extern "C" int +truncate (const char *pathname, __off32_t length) +{ + return truncate64 (pathname, (__off64_t)length); +} + extern "C" long get_osfhandle (int fd) { @@ -1844,7 +1913,7 @@ mkfifo (const char *_path, mode_t mode) /* setgid: POSIX 4.2.2.1 */ extern "C" int -setgid (gid_t gid) +setgid (__gid16_t gid) { int ret = setegid (gid); if (!ret) @@ -1854,7 +1923,7 @@ setgid (gid_t gid) /* setuid: POSIX 4.2.2.1 */ extern "C" int -setuid (uid_t uid) +setuid (__uid16_t uid) { int ret = seteuid (uid); if (!ret) @@ -1867,7 +1936,7 @@ extern struct passwd *internal_getlogin (cygheap_user &user); /* seteuid: standards? */ extern "C" int -seteuid (uid_t uid) +seteuid (__uid16_t uid) { sigframe thisframe (mainthread); if (wincap.has_security ()) @@ -1880,7 +1949,7 @@ seteuid (uid_t uid) DWORD dlen = INTERNET_MAX_HOST_NAME_LENGTH + 1; SID_NAME_USE use; - if (uid == (uid_t) -1 || uid == myself->uid) + if (uid == ILLEGAL_UID || uid == myself->uid) { debug_printf ("new euid == current euid, nothing happens"); return 0; @@ -1935,7 +2004,7 @@ seteuid (uid_t uid) BOOL current_token_is_internal_token = FALSE; BOOL explicitely_created_token = FALSE; - struct group *gr = getgrgid (myself->gid); + struct __group16 *gr = getgrgid (myself->gid); debug_printf ("myself->gid: %d, gr: %d", myself->gid, gr); usersid.getfrompw (pw_new); @@ -2087,14 +2156,14 @@ seteuid (uid_t uid) /* setegid: from System V. */ extern "C" int -setegid (gid_t gid) +setegid (__gid16_t gid) { sigframe thisframe (mainthread); if (wincap.has_security ()) { - if (gid != (gid_t) -1) + if (gid != ILLEGAL_GID) { - struct group *gr; + struct __group16 *gr; if (!(gr = getgrgid (gid))) { @@ -2377,7 +2446,8 @@ logout (char *line) { struct utmp *ut; struct utmp ut_buf[100]; - off_t pos = 0; /* Position in file */ + /* FIXME: utmp file access is not 64 bit clean for now. */ + __off32_t pos = 0; /* Position in file */ DWORD rd; while (!res && ReadFile (ut_fd, ut_buf, sizeof ut_buf, &rd, NULL) diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 23aaa6860..5004c950e 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -1,6 +1,6 @@ /* thread.h: Locking and threading module definitions - Copyright 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. Copyright 2001 Red Hat, Inc. Written by Marco Fuykschot <marco@ddi.nl> @@ -54,7 +54,7 @@ struct _winsup_t /* Needed for the group functions */ - struct group _grp; + struct __group16 _grp; char *_namearray[2]; int _grp_pos; diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 1993c5884..9674d1031 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -24,6 +24,7 @@ details. */ #include "sync.h" #include "sigproc.h" #include "pinfo.h" +#include "hires.h" #define FACTOR (0x19db1ded53e8000LL) #define NSPERSEC 10000000LL @@ -149,34 +150,21 @@ totimeval (struct timeval *dst, FILETIME *src, int sub, int flag) dst->tv_sec = x / (long long) (1e6); } -/* gettimeofday: BSD */ +/* FIXME: Make thread safe */ extern "C" int -gettimeofday (struct timeval *p, struct timezone *z) +gettimeofday(struct timeval *tv, struct timezone *tz) { - int res = 0; - - if (p != NULL) - { - FILETIME f; - - GetSystemTimeAsFileTime (&f); - totimeval (p, &f, 0, 1); - } - - if (z != NULL) - { - tzset(); - z->tz_minuteswest = _timezone / 60; - z->tz_dsttime = _daylight; - } - - syscall_printf ("%d = gettimeofday (%x, %x)", res, p, z); + static hires gtod; + LONGLONG now = gtod.usecs (false); + if (now == (LONGLONG) -1) + return -1; - return res; + tv->tv_sec = now / 1000000; + tv->tv_usec = now % 1000000; + return 0; } -extern "C" -int +extern "C" int _gettimeofday (struct timeval *p, struct timezone *z) { return gettimeofday (p, z); @@ -569,3 +557,58 @@ void cygwin_tzset () { } + +void +hires::prime () +{ + LARGE_INTEGER ifreq; + if (!QueryPerformanceFrequency (&ifreq)) + { + inited = -1; + return; + } + + FILETIME f; + int priority = GetThreadPriority (GetCurrentThread ()); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); + if (!QueryPerformanceCounter (&primed_pc)) + { + SetThreadPriority (GetCurrentThread (), priority); + inited = -1; + return; + } + + GetSystemTimeAsFileTime (&f); + SetThreadPriority (GetCurrentThread (), priority); + + inited = 1; + primed_ft.HighPart = f.dwHighDateTime; + primed_ft.LowPart = f.dwLowDateTime; + primed_ft.QuadPart -= FACTOR; + primed_ft.QuadPart /= 10; + freq = (double) ((double) 1000000. / (double) ifreq.QuadPart); + return; +} + +LONGLONG +hires::usecs (bool justdelta) +{ + if (!inited) + prime (); + if (inited < 0) + { + set_errno (ENOSYS); + return (long long) -1; + } + + LARGE_INTEGER now; + if (!QueryPerformanceCounter (&now)) + { + set_errno (ENOSYS); + return -1; + } + + // FIXME: Use round() here? + now.QuadPart = (LONGLONG) (freq * (double) (now.QuadPart - primed_pc.QuadPart)); + return justdelta ? now.QuadPart : primed_ft.QuadPart + now.QuadPart; +} diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 60e1857a6..52ef8e43a 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -56,6 +56,9 @@ ttyslot (void) void __stdcall tty_init (void) { + if (!myself->ppid_handle && NOTSTATE (myself, PID_CYGPARENT)) + cygheap->fdtab.get_debugger_info (); + if (NOTSTATE (myself, PID_USETTY)) return; if (myself->ctty == -1) @@ -72,8 +75,8 @@ tty_init (void) void __stdcall create_tty_master (int ttynum) { - tty_master = (fhandler_tty_master *) cygheap->fdtab.build_fhandler (-1, FH_TTYM, - "/dev/ttym", ttynum); + tty_master = (fhandler_tty_master *) + cygheap->fdtab.build_fhandler (-1, FH_TTYM, "/dev/ttym", NULL, ttynum); if (tty_master->init (ttynum)) api_fatal ("Can't create master tty"); else diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index 4aa6363ae..34050d769 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -62,6 +62,7 @@ public: int getsid () {return sid;} void setsid (pid_t tsid) {sid = tsid;} void set_ctty (int ttynum, int flags); + void kill_pgrp (int sig); struct termios ti; struct winsize winsize; diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index c128d8a44..3e3513a16 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -1,6 +1,6 @@ /* uinfo.cc: user info (uid, gid, etc...) - 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. @@ -127,91 +127,90 @@ internal_getlogin (cygheap_user &user) NetApiBufferFree (ui); } - if (allow_ntsec) - { - HANDLE ptok = user.token; /* Which is INVALID_HANDLE_VALUE if no - impersonation took place. */ - DWORD siz; - cygsid tu; - int ret = 0; + HANDLE ptok = user.token; /* Which is INVALID_HANDLE_VALUE if no + impersonation took place. */ + DWORD siz; + cygsid tu; + ret = 0; - /* Try to get the SID either from already impersonated token - or from current process first. To differ that two cases is - important, because you can't rely on the user information - in a process token of a currently impersonated process. */ - if (ptok == INVALID_HANDLE_VALUE - && !OpenProcessToken (GetCurrentProcess (), - TOKEN_ADJUST_DEFAULT | TOKEN_QUERY, - &ptok)) - debug_printf ("OpenProcessToken(): %E\n"); - else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz)) - debug_printf ("GetTokenInformation(): %E"); - else if (!(ret = user.set_sid (tu))) - debug_printf ("Couldn't retrieve SID from access token!"); - /* If that failes, try to get the SID from localhost. This can only - be done if a domain is given because there's a chance that a local - and a domain user may have the same name. */ - if (!ret && user.domain ()) - { - /* Concat DOMAIN\USERNAME for the next lookup */ - strcat (strcat (strcpy (buf, user.domain ()), "\\"), user.name ()); - if (!(ret = lookup_name (buf, NULL, user.sid ()))) - debug_printf ("Couldn't retrieve SID locally!"); - } - - /* If that fails, too, as a last resort try to get the SID from - the logon server. */ - if (!ret && !(ret = lookup_name (user.name (), user.logsrv (), - user.sid ()))) - debug_printf ("Couldn't retrieve SID from '%s'!", user.logsrv ()); + /* Try to get the SID either from already impersonated token + or from current process first. To differ that two cases is + important, because you can't rely on the user information + in a process token of a currently impersonated process. */ + if (ptok == INVALID_HANDLE_VALUE + && !OpenProcessToken (GetCurrentProcess (), + TOKEN_ADJUST_DEFAULT | TOKEN_QUERY, + &ptok)) + debug_printf ("OpenProcessToken(): %E\n"); + else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz)) + debug_printf ("GetTokenInformation(): %E"); + else if (!(ret = user.set_sid (tu))) + debug_printf ("Couldn't retrieve SID from access token!"); + /* If that failes, try to get the SID from localhost. This can only + be done if a domain is given because there's a chance that a local + and a domain user may have the same name. */ + if (!ret && user.domain ()) + { + /* Concat DOMAIN\USERNAME for the next lookup */ + strcat (strcat (strcpy (buf, user.domain ()), "\\"), user.name ()); + if (!(ret = lookup_name (buf, NULL, user.sid ()))) + debug_printf ("Couldn't retrieve SID locally!"); + } - /* If we have a SID, try to get the corresponding Cygwin user name - which can be different from the Windows user name. */ - cygsid gsid (NO_SID); - if (ret) - { - cygsid psid; + /* If that fails, too, as a last resort try to get the SID from + the logon server. */ + if (!ret && !(ret = lookup_name (user.name (), user.logsrv (), + user.sid ()))) + debug_printf ("Couldn't retrieve SID from '%s'!", user.logsrv ()); - for (int pidx = 0; (pw = internal_getpwent (pidx)); ++pidx) - if (psid.getfrompw (pw) && EqualSid (user.sid (), psid)) - { - user.set_name (pw->pw_name); - struct group *gr = getgrgid (pw->pw_gid); - if (gr) - if (!gsid.getfromgr (gr)) - gsid = NO_SID; - break; - } - if (!strcasematch (user.name (), "SYSTEM") - && user.domain () && user.logsrv ()) - { - if (get_registry_hive_path (user.sid (), buf)) - setenv ("USERPROFILE", buf, 1); - else - unsetenv ("USERPROFILE"); - } - } + /* If we have a SID, try to get the corresponding Cygwin user name + which can be different from the Windows user name. */ + cygsid gsid (NO_SID); + if (ret) + { + cygsid psid; - /* If this process is started from a non Cygwin process, - set token owner to the same value as token user and - primary group to the group which is set as primary group - in /etc/passwd. */ - if (ptok != INVALID_HANDLE_VALUE && myself->ppid == 1) + for (int pidx = 0; (pw = internal_getpwent (pidx)); ++pidx) + if (psid.getfrompw (pw) && EqualSid (user.sid (), psid)) + { + user.set_name (pw->pw_name); + struct __group16 *gr = getgrgid (pw->pw_gid); + if (gr) + if (!gsid.getfromgr (gr)) + gsid = NO_SID; + break; + } + if (!strcasematch (user.name (), "SYSTEM") + && user.domain () && user.logsrv ()) { - if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu)) - debug_printf ("SetTokenInformation(TokenOwner): %E"); - if (gsid && !SetTokenInformation (ptok, TokenPrimaryGroup, - &gsid, sizeof gsid)) - debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E"); + if (get_registry_hive_path (user.sid (), buf)) + setenv ("USERPROFILE", buf, 1); + else + unsetenv ("USERPROFILE"); } + } - /* Close token only if it's a result from OpenProcessToken(). */ - if (ptok != INVALID_HANDLE_VALUE - && user.token == INVALID_HANDLE_VALUE) - CloseHandle (ptok); + /* If this process is started from a non Cygwin process, + set token owner to the same value as token user and + primary group to the group which is set as primary group + in /etc/passwd. */ + if (ptok != INVALID_HANDLE_VALUE && myself->ppid == 1) + { + if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu)) + debug_printf ("SetTokenInformation(TokenOwner): %E"); + if (gsid && !SetTokenInformation (ptok, TokenPrimaryGroup, + &gsid, sizeof gsid)) + debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E"); } + + /* Close token only if it's a result from OpenProcessToken(). */ + if (ptok != INVALID_HANDLE_VALUE + && user.token == INVALID_HANDLE_VALUE) + CloseHandle (ptok); } + debug_printf ("Cygwins Username: %s", user.name ()); + if (!pw) pw = getpwnam(user.name ()); if (!getenv ("HOME")) @@ -245,20 +244,20 @@ uinfo_init () Setting `impersonated' to TRUE seems to be wrong but it isn't. Impersonated is thought as "Current User and `token' are coincident". See seteuid() for the mechanism behind that. */ - if (cygheap->user.token != INVALID_HANDLE_VALUE) + if (cygheap->user.token != INVALID_HANDLE_VALUE && cygheap->user.token != NULL) CloseHandle (cygheap->user.token); cygheap->user.token = INVALID_HANDLE_VALUE; cygheap->user.impersonated = TRUE; - /* If uid is USHRT_MAX, the process is started from a non cygwin + /* If uid is ILLEGAL_UID, the process is started from a non cygwin process or the user context was changed in spawn.cc */ - if (myself->uid == USHRT_MAX) + if (myself->uid == ILLEGAL_UID) if ((p = internal_getlogin (cygheap->user)) != NULL) { myself->uid = p->pw_uid; - /* Set primary group only if ntsec is off or the process has been - started from a non cygwin process. */ - if (!allow_ntsec || myself->ppid == 1) + /* Set primary group only if process has been started from a + non cygwin process. */ + if (!myself->ppid_handle) myself->gid = p->pw_gid; } else @@ -278,31 +277,31 @@ getlogin (void) #ifdef _MT_SAFE char *this_username=_reent_winsup ()->_username; #else - static NO_COPY char this_username[UNLEN + 1]; + static char this_username[UNLEN + 1] NO_COPY; #endif return strcpy (this_username, cygheap->user.name ()); } -extern "C" uid_t +extern "C" __uid16_t getuid (void) { return cygheap->user.real_uid; } -extern "C" gid_t +extern "C" __gid16_t getgid (void) { return cygheap->user.real_gid; } -extern "C" uid_t +extern "C" __uid16_t geteuid (void) { return myself->uid; } -extern "C" gid_t +extern "C" __gid16_t getegid (void) { return myself->gid; diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 14211a5e8..09e95fba0 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -45,6 +45,7 @@ static NO_COPY wincaps wincap_unknown = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:false, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_95 = { @@ -81,6 +82,7 @@ static NO_COPY wincaps wincap_95 = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:false, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_95osr2 = { @@ -117,6 +119,7 @@ static NO_COPY wincaps wincap_95osr2 = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:false, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_98 = { @@ -153,6 +156,7 @@ static NO_COPY wincaps wincap_98 = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:true, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_98se = { @@ -189,6 +193,7 @@ static NO_COPY wincaps wincap_98se = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:true, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_me = { @@ -225,6 +230,7 @@ static NO_COPY wincaps wincap_me = { has_try_enter_critical_section:false, has_raw_devices:false, has_valid_processorlevel:true, + has_64bit_file_access:false, }; static NO_COPY wincaps wincap_nt3 = { @@ -261,6 +267,7 @@ static NO_COPY wincaps wincap_nt3 = { has_try_enter_critical_section:false, has_raw_devices:true, has_valid_processorlevel:true, + has_64bit_file_access:true, }; static NO_COPY wincaps wincap_nt4 = { @@ -297,6 +304,7 @@ static NO_COPY wincaps wincap_nt4 = { has_try_enter_critical_section:true, has_raw_devices:true, has_valid_processorlevel:true, + has_64bit_file_access:true, }; static NO_COPY wincaps wincap_nt4sp4 = { @@ -333,6 +341,7 @@ static NO_COPY wincaps wincap_nt4sp4 = { has_try_enter_critical_section:true, has_raw_devices:true, has_valid_processorlevel:true, + has_64bit_file_access:true, }; static NO_COPY wincaps wincap_2000 = { @@ -369,6 +378,7 @@ static NO_COPY wincaps wincap_2000 = { has_try_enter_critical_section:true, has_raw_devices:true, has_valid_processorlevel:true, + has_64bit_file_access:true, }; static NO_COPY wincaps wincap_xp = { @@ -405,6 +415,7 @@ static NO_COPY wincaps wincap_xp = { has_try_enter_critical_section:true, has_raw_devices:true, has_valid_processorlevel:true, + has_64bit_file_access:true, }; wincapc NO_COPY wincap; @@ -414,6 +425,9 @@ wincapc::init () { const char *os; + if (caps) + return; // already initialized + memset (&version, 0, sizeof version); version.dwOSVersionInfoSize = sizeof version; GetVersionEx (&version); diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index a3cd3176c..088907ad2 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -46,6 +46,7 @@ struct wincaps unsigned has_try_enter_critical_section : 1; unsigned has_raw_devices : 1; unsigned has_valid_processorlevel : 1; + unsigned has_64bit_file_access : 1; }; class wincapc @@ -55,6 +56,7 @@ class wincapc void *caps; public: + wincapc (): caps (NULL) {} void init (); void set_chunksize (DWORD nchunksize); @@ -96,6 +98,7 @@ public: bool IMPLEMENT (has_try_enter_critical_section) bool IMPLEMENT (has_raw_devices) bool IMPLEMENT (has_valid_processorlevel) + bool IMPLEMENT (has_64bit_file_access) #undef IMPLEMENT }; diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 5548e2de4..ea9251aaf 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -23,7 +23,7 @@ details. */ # define memset __builtin_memset #endif -#define NO_COPY __attribute__((section(".data_cygwin_nocopy"))) +#define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))) #ifdef EXPCGF #define DECLARE_TLS_STORAGE char **tls[4096] __attribute__ ((unused)) @@ -147,6 +147,10 @@ extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn)); /* UID/GID */ void uinfo_init (void); +#define ILLEGAL_UID ((__uid16_t)-1) +#define ILLEGAL_GID ((__gid16_t)-1) +#define ILLEGAL_SEEK ((__off64_t)-1) + /* various events */ void events_init (void); void events_terminate (void); @@ -177,7 +181,7 @@ extern int cygwin_finished_initializing; void __stdcall set_std_handle (int); int __stdcall writable_directory (const char *file); -int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *); +int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *); extern BOOL allow_ntsec; unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2))); @@ -228,7 +232,7 @@ extern "C" void __malloc_lock (struct _reent *); extern "C" void __malloc_unlock (struct _reent *); class path_conv; -int __stdcall stat_worker (const char *name, struct stat *buf, int nofollow, +int __stdcall stat_worker (const char *name, struct __stat64 *buf, int nofollow, path_conv *pc = NULL) __attribute__ ((regparm (3))); /**************************** Exports ******************************/ |