diff options
author | Christopher Faylor <cgf@redhat.com> | 2003-03-09 20:53:45 +0000 |
---|---|---|
committer | Christopher Faylor <cgf@redhat.com> | 2003-03-09 20:53:45 +0000 |
commit | 50646e099d8afadb38e279369ed3750ffcb95942 (patch) | |
tree | 7e1a52e50df9a4fe01f543dcb2bd89b51c6bc558 | |
parent | 8bc4e3ad8c3a393ce489fdeba08e811608e80a72 (diff) | |
download | gdb-50646e099d8afadb38e279369ed3750ffcb95942.tar.gz |
merge from trunk
-rw-r--r-- | winsup/cygwin/ChangeLog | 27 | ||||
-rw-r--r-- | winsup/cygwin/autoload.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/fcntl.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_proc.cc | 468 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_serial.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 48 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_virtual.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/include/cygwin/version.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/mmap.cc | 31 | ||||
-rw-r--r-- | winsup/cygwin/net.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/ntdll.h | 392 | ||||
-rw-r--r-- | winsup/cygwin/ntea.cc | 325 | ||||
-rw-r--r-- | winsup/cygwin/poll.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/pwdgrp.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/sec_acl.cc | 75 | ||||
-rw-r--r-- | winsup/cygwin/sec_helper.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/security.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/security.h | 4 | ||||
-rw-r--r-- | winsup/cygwin/select.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/string.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/strsep.cc | 64 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/syslog.cc | 9 | ||||
-rw-r--r-- | winsup/cygwin/tty.cc | 9 | ||||
-rw-r--r-- | winsup/cygwin/wait.cc | 129 |
26 files changed, 1460 insertions, 152 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index bd7e2754c75..cf25d35fb1d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,17 +1,30 @@ 2003-03-09 Christopher Faylor <cgf@redhat.com> - * syscalls.cc (unlink): Attempt to be more clever about setting - attributes of file. Only open file in query mode to avoid having to - mess with security stuff for reading. + * include/cygwin/version.h: Bump DLL minor number to 21. -2003-03-09 Corinna Vinschen <corinna@vinschen.de> +2003-03-09 Christopher Faylor <cgf@redhat.com> - * rmsym: Fix regular expression. + Do some minor reformatting of 'extern "C"' use throughout. + +2003-03-06 Christopher January <chris@atomice.net> + + * autoload.cc (GetSystemTimes): Define new autoload function. + * fhandler_proc.cc (proc_listing): Add cpuinfo and partitions entries. + (fhandler_proc::fill_filebuf): Add PROC_CPUINFO and PROC_PARTITIONS + cases. + (format_proc_uptime): Use GetSystemTimes if available. + (read_value): New macro. + (print): New macro. + (cpuid): New function. + (can_set_flag): New function. + (format_proc_cpuinfo): New function. + (format_proc_partitions): New function. 2003-03-09 Christopher Faylor <cgf@redhat.com> - * Makefile.in: Change from using new-* to cygwin0 for temporary - targets. + * syscalls.cc (unlink): Attempt to be more clever about setting + attributes of file. Only open file in query mode to avoid having to + mess with security stuff for reading. 2003-03-09 Corinna Vinschen <corinna@vinschen.de> diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index b29c9d26908..659ca2be210 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -501,6 +501,7 @@ LoadDLLfuncEx (CreateHardLinkA, 12, kernel32, 1) LoadDLLfuncEx (CreateToolhelp32Snapshot, 8, kernel32, 1) LoadDLLfuncEx2 (GetCompressedFileSizeA, 8, kernel32, 1, 0xffffffff) LoadDLLfuncEx (GetConsoleWindow, 0, kernel32, 1) +LoadDLLfuncEx (GetSystemTimes, 12, kernel32, 1) LoadDLLfuncEx2 (IsDebuggerPresent, 0, kernel32, 1, 1) LoadDLLfuncEx (Process32First, 8, kernel32, 1) LoadDLLfuncEx (Process32Next, 8, kernel32, 1) diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc index 6d99a98c4b7..f99dd2d2b7c 100644 --- a/winsup/cygwin/fcntl.cc +++ b/winsup/cygwin/fcntl.cc @@ -20,8 +20,7 @@ details. */ #include "cygheap.h" #include "thread.h" -extern "C" -int +extern "C" int _fcntl (int fd, int cmd,...) { void *arg = NULL; diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index b47937cfbe5..667f160ff28 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -646,7 +646,7 @@ fhandler_disk_file::opendir () dir->__d_dirent->d_version = __DIRENT_VERSION; cygheap_fdnew fd; if (fd >= 0) - { + { fd = this; fd->set_nohandle (true); dir->__d_dirent->d_fd = fd; diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index a5fbab53b56..11685443f22 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -8,6 +8,8 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#define _WIN32_WINNT 0x0501 + #include "winsup.h" #include <errno.h> #include <unistd.h> @@ -25,6 +27,7 @@ details. */ #include <sys/utsname.h> #include <sys/param.h> #include "ntdll.h" +#include <winioctl.h> #define _COMPILING_NEWLIB #include <dirent.h> @@ -36,6 +39,8 @@ static const int PROC_REGISTRY = 4; // /proc/registry static const int PROC_STAT = 5; // /proc/stat static const int PROC_VERSION = 6; // /proc/version static const int PROC_UPTIME = 7; // /proc/uptime +static const int PROC_CPUINFO = 8; // /proc/cpuinfo +static const int PROC_PARTITIONS = 9; // /proc/partitions /* names of objects in /proc */ static const char *proc_listing[] = { @@ -47,6 +52,8 @@ static const char *proc_listing[] = { "stat", "version", "uptime", + "cpuinfo", + "partitions", NULL }; @@ -63,7 +70,9 @@ static const DWORD proc_fhandlers[PROC_LINK_COUNT] = { FH_REGISTRY, FH_PROC, FH_PROC, - FH_PROC + FH_PROC, + FH_PROC, + FH_PROC, }; /* name of the /proc filesystem */ @@ -73,11 +82,12 @@ const int proc_len = sizeof (proc) - 1; static __off64_t format_proc_meminfo (char *destbuf, size_t maxsize); static __off64_t format_proc_stat (char *destbuf, size_t maxsize); static __off64_t format_proc_uptime (char *destbuf, size_t maxsize); +static __off64_t format_proc_cpuinfo (char *destbuf, size_t maxsize); +static __off64_t format_proc_partitions (char *destbuf, size_t maxsize); -/* auxillary function that returns the fhandler associated with the given path - * this is where it would be nice to have pattern matching in C - polymorphism - * just doesn't cut it - */ +/* Auxillary function that returns the fhandler associated with the given path + this is where it would be nice to have pattern matching in C - polymorphism + just doesn't cut it. */ DWORD fhandler_proc::get_proc_fhandler (const char *path) { @@ -120,8 +130,7 @@ fhandler_proc::get_proc_fhandler (const char *path) } /* Returns 0 if path doesn't exist, >0 if path is a directory, - * <0 if path is a file. - */ + <0 if path is a file. */ int fhandler_proc::exists () { @@ -357,6 +366,18 @@ fhandler_proc::fill_filebuf () filesize = format_proc_meminfo (filebuf, bufalloc); break; } + case PROC_CPUINFO: + { + filebuf = (char *) realloc (filebuf, bufalloc = 16384); + filesize = format_proc_cpuinfo (filebuf, bufalloc); + break; + } + case PROC_PARTITIONS: + { + filebuf = (char *) realloc (filebuf, bufalloc = 4096); + filesize = format_proc_partitions (filebuf, bufalloc); + break; + } } return true; } @@ -397,24 +418,30 @@ format_proc_uptime (char *destbuf, size_t maxsize) unsigned long long uptime = 0ULL, idle_time = 0ULL; SYSTEM_PROCESSOR_TIMES spt; - NTSTATUS ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) &spt, - sizeof spt, NULL); - if (!ret && GetLastError () == ERROR_PROC_NOT_FOUND) - uptime = GetTickCount () / 10; - else if (ret != STATUS_SUCCESS) + if (!GetSystemTimes ((FILETIME *) &spt.IdleTime, (FILETIME *) &spt.KernelTime, + (FILETIME *) &spt.UserTime) + && GetLastError () == ERROR_PROC_NOT_FOUND) { - __seterrno_from_win_error (RtlNtStatusToDosError (ret)); - debug_printf("NtQuerySystemInformation: ret = %d, " - "Dos(ret) = %d", - ret, RtlNtStatusToDosError (ret)); - return 0; - } - else - { - idle_time = spt.IdleTime.QuadPart / 100000ULL; - uptime = (spt.KernelTime.QuadPart + - spt.UserTime.QuadPart) / 100000ULL; + NTSTATUS ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) &spt, + sizeof spt, NULL); + if (!ret && GetLastError () == ERROR_PROC_NOT_FOUND) + { + uptime = GetTickCount () / 10; + goto out; + } + else if (ret != STATUS_SUCCESS) + { + __seterrno_from_win_error (RtlNtStatusToDosError (ret)); + debug_printf("NtQuerySystemInformation: ret = %d, " + "Dos(ret) = %d", + ret, RtlNtStatusToDosError (ret)); + return 0; + } } + idle_time = spt.IdleTime.QuadPart / 100000ULL; + uptime = (spt.KernelTime.QuadPart + + spt.UserTime.QuadPart) / 100000ULL; +out: return __small_sprintf (destbuf, "%U.%02u %U.%02u\n", uptime / 100, long (uptime % 100), @@ -494,3 +521,398 @@ format_proc_stat (char *destbuf, size_t maxsize) context_switches, boot_time); } + +#define read_value(x,y) \ + do {\ + dwCount = BUFSIZE; \ + if ((dwError = RegQueryValueEx (hKey, x, NULL, &dwType, (BYTE *) szBuffer, &dwCount)), \ + (dwError != ERROR_SUCCESS && dwError != ERROR_MORE_DATA)) \ + { \ + __seterrno_from_win_error (dwError); \ + debug_printf ("RegQueryValueEx failed retcode %d", dwError); \ + return 0; \ + } \ + if (dwType != y) \ + { \ + debug_printf ("Value %s had an unexpected type (expected %d, found %d)", y, dwType); \ + return 0; \ + }\ + } while (0) + +#define print(x) \ + do { \ + strcpy (bufptr, x), \ + bufptr += sizeof (x) - 1; \ + } while (0) + +static inline void +cpuid (unsigned *a, unsigned *b, unsigned *c, unsigned *d, unsigned in) +{ + asm ("cpuid" + : "=a" (*a), + "=b" (*b), + "=c" (*c), + "=d" (*d) + : "a" (in)); +} + +static inline bool +can_set_flag (unsigned flag) +{ + unsigned r1, r2; + asm("pushfl\n" + "popl %0\n" + "movl %0, %1\n" + "xorl %2, %0\n" + "pushl %0\n" + "popfl\n" + "pushfl\n" + "popl %0\n" + "pushl %1\n" + "popfl\n" + : "=&r" (r1), "=&r" (r2) + : "ir" (flag) + ); + return ((r1 ^ r2) & flag) != 0; +} + +static __off64_t +format_proc_cpuinfo (char *destbuf, size_t maxsize) +{ + SYSTEM_INFO siSystemInfo; + HKEY hKey; + DWORD dwError, dwCount, dwType; + DWORD dwOldThreadAffinityMask; + int cpu_number; + const int BUFSIZE = 256; + CHAR szBuffer[BUFSIZE]; + char *bufptr = destbuf; + + GetSystemInfo (&siSystemInfo); + + for (cpu_number = 0;;cpu_number++) + { + __small_sprintf (szBuffer, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d", cpu_number); + + if ((dwError = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_QUERY_VALUE, &hKey)) != ERROR_SUCCESS) + { + if (dwError == ERROR_FILE_NOT_FOUND) + break; + __seterrno_from_win_error (dwError); + debug_printf ("RegOpenKeyEx failed retcode %d", dwError); + return 0; + } + + dwOldThreadAffinityMask = SetThreadAffinityMask (GetCurrentThread (), 1 << cpu_number); + if (dwOldThreadAffinityMask == 0) + debug_printf ("SetThreadAffinityMask failed %E"); + // I'm not sure whether the thread changes processor immediately + // and I'm not sure whether this function will cause the thread to be rescheduled + low_priority_sleep (0); + + bool has_cpuid = false; + + if (!can_set_flag (0x00040000)) + debug_printf ("386 processor - no cpuid"); + else + { + debug_printf ("486 processor"); + if (can_set_flag (0x00200000)) + { + debug_printf ("processor supports CPUID instruction"); + has_cpuid = true; + } + else + debug_printf ("processor does not support CPUID instruction"); + } + + if (!has_cpuid) + { + bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number); + read_value ("VendorIdentifier", REG_SZ); + bufptr += __small_sprintf (bufptr, "vendor id : %s\n", szBuffer); + read_value ("Identifier", REG_SZ); + bufptr += __small_sprintf (bufptr, "identifier : %s\n", szBuffer); + read_value ("~Mhz", REG_DWORD); + bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", *(DWORD *) szBuffer); + + print ("flags :"); + if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)) + print (" 3dnow"); + if (IsProcessorFeaturePresent (PF_COMPARE_EXCHANGE_DOUBLE)) + print (" cx8"); + if (!IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED)) + print (" fpu"); + if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) + print (" mmx"); + if (IsProcessorFeaturePresent (PF_PAE_ENABLED)) + print (" pae"); + if (IsProcessorFeaturePresent (PF_RDTSC_INSTRUCTION_AVAILABLE)) + print (" tsc"); + if (IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE)) + print (" sse"); + if (IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE)) + print (" sse2"); + } + else + { + bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number); + unsigned maxf, vendor_id[4], unused; + cpuid (&maxf, &vendor_id[0], &vendor_id[1], &vendor_id[2], 0); + maxf &= 0xffff; + vendor_id[3] = 0; + bufptr += __small_sprintf (bufptr, "vendor id : %s\n", (char *)vendor_id); + read_value ("~Mhz", REG_DWORD); + unsigned cpu_mhz = *(DWORD *)szBuffer; + if (maxf >= 1) + { + unsigned features2, features1, extra_info, cpuid_sig; + cpuid (&cpuid_sig, &extra_info, &features2, &features1, 1); + /* unsigned extended_family = (cpuid_sig & 0x0ff00000) >> 20, + extended_model = (cpuid_sig & 0x000f0000) >> 16; */ + unsigned type = (cpuid_sig & 0x00003000) >> 12, + family = (cpuid_sig & 0x00000f00) >> 8, + model = (cpuid_sig & 0x000000f0) >> 4, + stepping = cpuid_sig & 0x0000000f; + unsigned brand_id = extra_info & 0x0000000f, + cpu_count = (extra_info & 0x00ff0000) >> 16, + apic_id = (extra_info & 0xff000000) >> 24; + const char *type_str; + switch (type) + { + case 0: + type_str = "primary processor"; + break; + case 1: + type_str = "overdrive processor"; + break; + case 2: + type_str = "secondary processor"; + break; + case 3: + default: + type_str = "reserved"; + break; + } + unsigned maxe = 0; + cpuid (&maxe, &unused, &unused, &unused, 0x80000000); + if (maxe >= 0x80000004) + { + unsigned *model_name = (unsigned *) szBuffer; + cpuid (&model_name[0], &model_name[1], &model_name[2], &model_name[3], 0x80000002); + cpuid (&model_name[4], &model_name[5], &model_name[6], &model_name[7], 0x80000003); + cpuid (&model_name[8], &model_name[9], &model_name[10], &model_name[11], 0x80000004); + model_name[12] = 0; + } + else + { + // could implement a lookup table here if someone needs it + strcpy (szBuffer, "unknown"); + } + bufptr += __small_sprintf (bufptr, "type : %s\n" + "cpu family : %d\n" + "model : %d\n" + "model name : %s\n" + "stepping : %d\n" + "brand id : %d\n" + "cpu count : %d\n" + "apic id : %d\n" + "cpu MHz : %d\n" + "fpu : %s\n", + type_str, + family, + model, + szBuffer, + stepping, + brand_id, + cpu_count, + apic_id, + cpu_mhz, + IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED) ? "no" : "yes"); + print ("flags :"); + if (features1 & (1 << 0)) + print (" fpu"); + if (features1 & (1 << 1)) + print (" vme"); + if (features1 & (1 << 2)) + print (" de"); + if (features1 & (1 << 3)) + print (" pse"); + if (features1 & (1 << 4)) + print (" tsc"); + if (features1 & (1 << 5)) + print (" msr"); + if (features1 & (1 << 6)) + print (" pae"); + if (features1 & (1 << 7)) + print (" mce"); + if (features1 & (1 << 8)) + print (" cx8"); + if (features1 & (1 << 9)) + print (" apic"); + if (features1 & (1 << 11)) + print (" sep"); + if (features1 & (1 << 12)) + print (" mtrr"); + if (features1 & (1 << 13)) + print (" pge"); + if (features1 & (1 << 14)) + print (" mca"); + if (features1 & (1 << 15)) + print (" cmov"); + if (features1 & (1 << 16)) + print (" pat"); + if (features1 & (1 << 17)) + print (" pse36"); + if (features1 & (1 << 18)) + print (" psn"); + if (features1 & (1 << 19)) + print (" clfl"); + if (features1 & (1 << 21)) + print (" dtes"); + if (features1 & (1 << 22)) + print (" acpi"); + if (features1 & (1 << 23)) + print (" mmx"); + if (features1 & (1 << 24)) + print (" fxsr"); + if (features1 & (1 << 25)) + print (" sse"); + if (features1 & (1 << 26)) + print (" sse2"); + if (features1 & (1 << 27)) + print (" ss"); + if (features1 & (1 << 28)) + print (" htt"); + if (features1 & (1 << 29)) + print (" tmi"); + if (features1 & (1 << 30)) + print (" ia-64"); + if (features1 & (1 << 31)) + print (" pbe"); + if (features2 & (1 << 0)) + print (" sse3"); + if (features2 & (1 << 3)) + print (" mon"); + if (features2 & (1 << 4)) + print (" dscpl"); + if (features2 & (1 << 8)) + print (" tm2"); + if (features2 & (1 << 10)) + print (" cid"); + } + else + { + bufptr += __small_sprintf (bufptr, "cpu MHz : %d\n" + "fpu : %s\n", + cpu_mhz, + IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED) ? "no" : "yes"); + } + } + if (dwOldThreadAffinityMask != 0) + SetThreadAffinityMask (GetCurrentThread (), dwOldThreadAffinityMask); + + RegCloseKey (hKey); + bufptr += __small_sprintf (bufptr, "\n"); + } + + return bufptr - destbuf; +} + +#undef read_value + +static __off64_t +format_proc_partitions (char *destbuf, size_t maxsize) +{ + char *bufptr = destbuf; + print ("major minor #blocks name\n\n"); + + if (wincap.is_winnt ()) + { + for (int drive_number=0;;drive_number++) + { + CHAR szDriveName[MAX_PATH]; + __small_sprintf (szDriveName, "\\\\.\\PHYSICALDRIVE%d", drive_number); + HANDLE hDevice; + hDevice = CreateFile (szDriveName, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); + if (hDevice == INVALID_HANDLE_VALUE) + { + if (GetLastError () == ERROR_PATH_NOT_FOUND) + break; + __seterrno (); + debug_printf ("CreateFile %d %E", GetLastError ()); + break; + } + else + { + DWORD dwBytesReturned, dwRetCode; + DISK_GEOMETRY dg; + int buf_size = 4096; + char buf[buf_size]; + dwRetCode = DeviceIoControl (hDevice, + IOCTL_DISK_GET_DRIVE_GEOMETRY, + NULL, + 0, + &dg, + sizeof (dg), + &dwBytesReturned, + NULL); + if (!dwRetCode) + debug_printf ("DeviceIoControl %E"); + else + { + bufptr += __small_sprintf (bufptr, "%5d %5d %9U sd%c\n", + FH_FLOPPY, + drive_number * 16 + 32, + (long long)((dg.Cylinders.QuadPart * dg.TracksPerCylinder * + dg.SectorsPerTrack * dg.BytesPerSector) >> 6), + drive_number + 'a'); + } + while (dwRetCode = DeviceIoControl (hDevice, + IOCTL_DISK_GET_DRIVE_LAYOUT, + NULL, + 0, + (DRIVE_LAYOUT_INFORMATION *) buf, + buf_size, + &dwBytesReturned, + NULL), + !dwRetCode && GetLastError () == ERROR_INSUFFICIENT_BUFFER) + buf_size *= 2; + if (!dwRetCode) + debug_printf ("DeviceIoControl %E"); + else + { + DRIVE_LAYOUT_INFORMATION *dli = (DRIVE_LAYOUT_INFORMATION *) buf; + for (unsigned partition = 0; partition < dli->PartitionCount; partition++) + { + if (dli->PartitionEntry[partition].PartitionLength.QuadPart == 0) + continue; + bufptr += __small_sprintf (bufptr, "%5d %5d %9U sd%c%d\n", + FH_FLOPPY, + drive_number * 16 + partition + 33, + (long long)(dli->PartitionEntry[partition].PartitionLength.QuadPart >> 6), + drive_number + 'a', + partition + 1); + } + } + + CloseHandle (hDevice); + } + } + } + else + { + // not worth the effort + // you need a 16 bit thunk DLL to access the partition table on Win9x + // and then you have to decode it yourself + } + return bufptr - destbuf; +} + +#undef print diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index 932a4b0ccb6..eec4735e1ec 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -835,7 +835,7 @@ fhandler_serial::tcsetattr (int action, const struct termios *t) } debug_printf ("ReadTotalTimeoutConstant %d, ReadIntervalTimeout %d, ReadTotalTimeoutMultiplier %d", - to.ReadTotalTimeoutConstant, to.ReadIntervalTimeout, to.ReadTotalTimeoutMultiplier); + to.ReadTotalTimeoutConstant, to.ReadIntervalTimeout, to.ReadTotalTimeoutMultiplier); if (!SetCommTimeouts(get_handle (), &to)) { diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 39777caa30a..55348e405ef 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -62,24 +62,24 @@ get_inet_addr (const struct sockaddr *in, int inlen, { path_conv pc (in->sa_data, PC_SYM_FOLLOW); if (pc.error) - { + { set_errno (pc.error); return 0; } if (!pc.exists ()) - { + { set_errno (ENOENT); return 0; } if (!pc.issocket ()) - { + { set_errno (EBADF); return 0; } HANDLE fh = CreateFile (pc, GENERIC_READ, wincap.shared (), &sec_none, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (fh == INVALID_HANDLE_VALUE) - { + { __seterrno (); return 0; } @@ -88,7 +88,7 @@ get_inet_addr (const struct sockaddr *in, int inlen, char buf[128]; memset (buf, 0, sizeof buf); if (ReadFile (fh, buf, 128, &len, 0)) - { + { sockaddr_in sin; sin.sin_family = AF_INET; sscanf (buf + strlen (SOCKET_COOKIE), "%hu %08x-%08x-%08x-%08x", @@ -125,11 +125,11 @@ public: bool load (SOCKET sock, int type_bit) { if ((ev[0] = WSACreateEvent ()) == WSA_INVALID_EVENT) - return false; + return false; evt_sock = sock; evt_type_bit = type_bit; if (WSAEventSelect (evt_sock, ev[0], 1 << evt_type_bit)) - { + { WSACloseEvent (ev[0]); ev[0] = WSA_INVALID_EVENT; return false; @@ -142,7 +142,7 @@ public: int wait_result = WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, FALSE); if (wait_result == WSA_WAIT_EVENT_0) - WSAEnumNetworkEvents (evt_sock, ev[0], &sock_event); + WSAEnumNetworkEvents (evt_sock, ev[0], &sock_event); /* Cleanup, Revert to blocking. */ WSAEventSelect (evt_sock, ev[0], 0); @@ -151,12 +151,12 @@ public: ioctlsocket (evt_sock, FIONBIO, &nonblocking); switch (wait_result) - { + { case WSA_WAIT_EVENT_0: if ((sock_event.lNetworkEvents & (1 << evt_type_bit)) - && sock_event.iErrorCode[evt_type_bit]) + && sock_event.iErrorCode[evt_type_bit]) { - WSASetLastError (sock_event.iErrorCode[evt_type_bit]); + WSASetLastError (sock_event.iErrorCode[evt_type_bit]); set_winsock_errno (); return -1; } @@ -452,25 +452,25 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen) path_conv pc (un_addr->sun_path, PC_SYM_FOLLOW); if (pc.error) - { - set_errno (pc.error); + { + set_errno (pc.error); goto out; } if (pc.exists ()) - { + { set_errno (EADDRINUSE); goto out; } mode_t mode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~cygheap->umask; DWORD attr = FILE_ATTRIBUTE_SYSTEM; if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH))) - attr |= FILE_ATTRIBUTE_READONLY; + attr |= FILE_ATTRIBUTE_READONLY; SECURITY_ATTRIBUTES sa = sec_none; if (allow_ntsec && pc.has_acls ()) - set_security_attribute (mode, &sa, alloca (4096), 4096); + set_security_attribute (mode, &sa, alloca (4096), 4096); HANDLE fh = CreateFile (pc, GENERIC_WRITE, 0, &sa, CREATE_NEW, attr, 0); if (fh == INVALID_HANDLE_VALUE) - { + { if (GetLastError () == ERROR_ALREADY_EXISTS) set_errno (EADDRINUSE); else @@ -484,13 +484,13 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen) get_connect_secret (strchr (buf, '\0')); DWORD blen = strlen (buf) + 1; if (!WriteFile (fh, buf, blen, &blen, 0)) - { + { __seterrno (); CloseHandle (fh); DeleteFile (pc); } else - { + { CloseHandle (fh); set_sun_path (un_addr->sun_path); res = 0; @@ -644,12 +644,12 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) { sock_event evt; if (!evt.load (get_socket (), FD_ACCEPT_BIT)) - { + { set_winsock_errno (); return -1; } switch (evt.wait ()) - { + { case 1: /* Signal */ return -1; case 0: @@ -709,7 +709,7 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) res = res_fd; } else - { + { closesocket (res); res = -1; } @@ -815,9 +815,9 @@ fhandler_socket::recvfrom (void *ptr, size_t len, int flags, if (res == SOCKET_ERROR) { /* According to SUSv3, errno isn't set in that case and no error - condition is returned. */ + condition is returned. */ if (WSAGetLastError () == WSAEMSGSIZE) - return len; + return len; res = -1; set_winsock_errno (); diff --git a/winsup/cygwin/fhandler_virtual.cc b/winsup/cygwin/fhandler_virtual.cc index 420544d6152..19d0b89fe8f 100644 --- a/winsup/cygwin/fhandler_virtual.cc +++ b/winsup/cygwin/fhandler_virtual.cc @@ -75,7 +75,7 @@ fhandler_virtual::opendir () dir->__d_dirent->d_version = __DIRENT_VERSION; cygheap_fdnew fd; if (fd >= 0) - { + { fd = this; fd->set_nohandle (true); dir->__d_dirent->d_fd = fd; diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 306f3197225..89cd8b03b2d 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -42,7 +42,7 @@ details. */ changes to the DLL and is mainly informative in nature. */ #define CYGWIN_VERSION_DLL_MAJOR 1003 -#define CYGWIN_VERSION_DLL_MINOR 21 +#define CYGWIN_VERSION_DLL_MINOR 22 /* Major numbers before CYGWIN_VERSION_DLL_EPOCH are incompatible. */ diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index f28721ac8b8..b50a15c343b 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -123,7 +123,7 @@ mmap_record::alloc_map (__off64_t off, DWORD len) off -= offset_; len = PAGE_CNT (len) * getpagesize (); if (off > 0 && - !VirtualProtect (base_address_, off, PAGE_NOACCESS, &old_prot)) + !VirtualProtect (base_address_, off, PAGE_NOACCESS, &old_prot)) syscall_printf ("VirtualProtect(%x,%d) failed: %E", base_address_, off); if (off + len < size_to_map_ && !VirtualProtect (base_address_ + off + len, @@ -143,7 +143,7 @@ mmap_record::map_map (__off64_t off, DWORD len) { /* Used ONLY if this mapping matches into the chunk of another already performed mapping in a special case of MAP_ANON|MAP_PRIVATE. - + Otherwise it's job is now done by alloc_map(). */ DWORD prot, old_prot; switch (access_mode_) @@ -422,8 +422,7 @@ map::erase (int i) static map *mmapped_areas; -extern "C" -caddr_t +extern "C" caddr_t 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", @@ -584,8 +583,7 @@ mmap64 (caddr_t addr, size_t len, int prot, int flags, int fd, __off64_t off) return ret; } -extern "C" -caddr_t +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); @@ -594,8 +592,7 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, __off32_t off) /* munmap () removes an mmapped area. It insists that base area requested is the same as that mmapped, error if not. */ -extern "C" -int +extern "C" int munmap (caddr_t addr, size_t len) { syscall_printf ("munmap (addr %x, len %d)", addr, len); @@ -655,8 +652,7 @@ munmap (caddr_t addr, size_t len) /* Sync file with memory. Ignore flags for now. */ -extern "C" -int +extern "C" int msync (caddr_t addr, size_t len, int flags) { syscall_printf ("addr = %x, len = %d, flags = %x", @@ -776,11 +772,11 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access, switch (access) { case FILE_MAP_WRITE: - protect = PAGE_READWRITE; - break; + protect = PAGE_READWRITE; + break; case FILE_MAP_READ: - protect = PAGE_READONLY; - break; + protect = PAGE_READONLY; + break; default: protect = PAGE_WRITECOPY; break; @@ -879,8 +875,7 @@ fhandler_disk_file::fixup_mmap_after_fork (HANDLE h, DWORD access, DWORD offset, /* Set memory protection */ -extern "C" -int +extern "C" int mprotect (caddr_t addr, size_t len, int prot) { DWORD old_prot; @@ -995,7 +990,7 @@ fixup_mmaps_after_fork (HANDLE parent) || !wincap.virtual_protect_works_on_shared_pages ()) { system_printf ("ReadProcessMemory failed for " - "MAP_PRIVATE address %p, %E", + "MAP_PRIVATE address %p, %E", rec->get_address ()); return -1; } @@ -1019,7 +1014,7 @@ fixup_mmaps_after_fork (HANDLE parent) address, getpagesize (), old_prot, &dummy_prot)) system_printf ("WARNING: VirtualProtectEx to " - "return to previous state " + "return to previous state " "in parent failed for " "MAP_PRIVATE address %p, %E", rec->get_address ()); diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index b6aacb8245c..c013fc64360 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2190,7 +2190,7 @@ socketpair (int family, int type, int protocol, int *sb) if (res == -1) { - closesocket (insock); + closesocket (insock); closesocket (outsock); } } diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h new file mode 100644 index 00000000000..220cf3e821d --- /dev/null +++ b/winsup/cygwin/ntdll.h @@ -0,0 +1,392 @@ +/* ntdll.h. Contains ntdll specific stuff not defined elsewhere. + + Copyright 2000, 2001, 2002, 2003 Red Hat, Inc. + + This file is part of Cygwin. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS) 0xc0000004) +#define FILE_SYNCHRONOUS_IO_NONALERT 32 +#define PDI_MODULES 0x01 +#define PDI_HEAPS 0x04 +#define LDRP_IMAGE_DLL 0x00000004 +#define WSLE_PAGE_READONLY 0x001 +#define WSLE_PAGE_EXECUTE 0x002 +#define WSLE_PAGE_EXECUTE_READ 0x003 +#define WSLE_PAGE_READWRITE 0x004 +#define WSLE_PAGE_WRITECOPY 0x005 +#define WSLE_PAGE_EXECUTE_READWRITE 0x006 +#define WSLE_PAGE_EXECUTE_WRITECOPY 0x007 +#define WSLE_PAGE_SHARE_COUNT_MASK 0x0E0 +#define WSLE_PAGE_SHAREABLE 0x100 + +typedef ULONG KAFFINITY; + +typedef enum _SYSTEM_INFORMATION_CLASS +{ + SystemBasicInformation = 0, + SystemPerformanceInformation = 2, + SystemTimeOfDayInformation = 3, + SystemProcessesAndThreadsInformation = 5, + SystemProcessorTimes = 8, + /* There are a lot more of these... */ +} SYSTEM_INFORMATION_CLASS; + +typedef struct _SYSTEM_BASIC_INFORMATION +{ + ULONG Unknown; + ULONG MaximumIncrement; + ULONG PhysicalPageSize; + ULONG NumberOfPhysicalPages; + ULONG LowestPhysicalPage; + ULONG HighestPhysicalPage; + ULONG AllocationGranularity; + ULONG LowestUserAddress; + ULONG HighestUserAddress; + ULONG ActiveProcessors; + UCHAR NumberProcessors; +} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION; + +typedef struct __attribute__ ((aligned (8))) _SYSTEM_PROCESSOR_TIMES +{ + LARGE_INTEGER IdleTime; + LARGE_INTEGER KernelTime; + LARGE_INTEGER UserTime; + LARGE_INTEGER DpcTime; + LARGE_INTEGER InterruptTime; + ULONG InterruptCount; +} SYSTEM_PROCESSOR_TIMES, *PSYSTEM_PROCESSOR_TIMES; + +typedef LONG KPRIORITY; +typedef struct _VM_COUNTERS +{ + ULONG PeakVirtualSize; + ULONG VirtualSize; + ULONG PageFaultCount; + ULONG PeakWorkingSetSize; + ULONG WorkingSetSize; + ULONG QuotaPeakPagedPoolUsage; + ULONG QuotaPagedPoolUsage; + ULONG QuotaPeakNonPagedPoolUsage; + ULONG QuotaNonPagedPoolUsage; + ULONG PagefileUsage; + ULONG PeakPagefileUsage; +} VM_COUNTERS, *PVM_COUNTERS; + +typedef struct _CLIENT_ID +{ + HANDLE UniqueProcess; + HANDLE UniqueThread; +} CLIENT_ID, *PCLIENT_ID; + +typedef enum +{ + StateInitialized, + StateReady, + StateRunning, + StateStandby, + StateTerminated, + StateWait, + StateTransition, + StateUnknown, +} THREAD_STATE; + +typedef enum +{ + Executive, + FreePage, + PageIn, + PoolAllocation, + DelayExecution, + Suspended, + UserRequest, + WrExecutive, + WrFreePage, + WrPageIn, + WrPoolAllocation, + WrDelayExecution, + WrSuspended, + WrUserRequest, + WrEventPair, + WrQueue, + WrLpcReceive, + WrLpcReply, + WrVirtualMemory, + WrPageOut, + WrRendezvous, + Spare2, + Spare3, + Spare4, + Spare5, + Spare6, + WrKernel, + MaximumWaitReason +} KWAIT_REASON; + +typedef struct _SYSTEM_THREADS +{ + LARGE_INTEGER KernelTime; + LARGE_INTEGER UserTime; + LARGE_INTEGER CreateTime; + ULONG WaitTime; + PVOID StartAddress; + CLIENT_ID ClientId; + KPRIORITY Priority; + KPRIORITY BasePriority; + ULONG ContextSwitchCount; + THREAD_STATE State; + KWAIT_REASON WaitReason; + DWORD Reserved; +} SYSTEM_THREADS, *PSYSTEM_THREADS; + +typedef struct _SYSTEM_PROCESSES +{ + ULONG NextEntryDelta; + ULONG ThreadCount; + ULONG Reserved1[6]; + LARGE_INTEGER CreateTime; + LARGE_INTEGER UserTime; + LARGE_INTEGER KernelTime; + UNICODE_STRING ProcessName; + KPRIORITY BasePriority; + ULONG ProcessId; + ULONG InheritedFromProcessId; + ULONG HandleCount; + ULONG Reserved2[2]; + VM_COUNTERS VmCounters; + IO_COUNTERS IoCounters; + SYSTEM_THREADS Threads[1]; +} SYSTEM_PROCESSES, *PSYSTEM_PROCESSES; + +typedef struct _IO_STATUS_BLOCK +{ + NTSTATUS Status; + ULONG Information; +} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; + +typedef struct _SYSTEM_PERFORMANCE_INFORMATION +{ + LARGE_INTEGER IdleTime; + LARGE_INTEGER ReadTransferCount; + LARGE_INTEGER WriteTransferCount; + LARGE_INTEGER OtherTransferCount; + ULONG ReadOperationCount; + ULONG WriteOperationCount; + ULONG OtherOperationCount; + ULONG AvailablePages; + ULONG TotalCommittedPages; + ULONG TotalCommitLimit; + ULONG PeakCommitment; + ULONG PageFaults; + ULONG WriteCopyFaults; + ULONG TransitionFaults; + ULONG Reserved1; + ULONG DemandZeroFaults; + ULONG PagesRead; + ULONG PageReadIos; + ULONG Reserved2[2]; + ULONG PagefilePagesWritten; + ULONG PagefilePageWriteIos; + ULONG MappedFilePagesWritten; + ULONG MappedFilePageWriteIos; + ULONG PagedPoolUsage; + ULONG NonPagedPoolUsage; + ULONG PagedPoolAllocs; + ULONG PagedPoolFrees; + ULONG NonPagedPoolAllocs; + ULONG NonPagedPoolFrees; + ULONG TotalFreeSystemPtes; + ULONG SystemCodePage; + ULONG TotalSystemDriverPages; + ULONG TotalSystemCodePages; + ULONG SmallNonPagedLookasideListAllocateHits; + ULONG SmallPagedLookasideListAllocateHits; + ULONG Reserved3; + ULONG MmSystemCachePage; + ULONG PagedPoolPage; + ULONG SystemDriverPage; + ULONG FastReadNoWait; + ULONG FastReadWait; + ULONG FastReadResourceMiss; + ULONG FastReadNotPossible; + ULONG FastMdlReadNoWait; + ULONG FastMdlReadWait; + ULONG FastMdlReadResourceMiss; + ULONG FastMdlReadNotPossible; + ULONG MapDataNoWait; + ULONG MapDataWait; + ULONG MapDataNoWaitMiss; + ULONG MapDataWaitMiss; + ULONG PinMappedDataCount; + ULONG PinReadNoWait; + ULONG PinReadWait; + ULONG PinReadNoWaitMiss; + ULONG PinReadWaitMiss; + ULONG CopyReadNoWait; + ULONG CopyReadWait; + ULONG CopyReadNoWaitMiss; + ULONG CopyReadWaitMiss; + ULONG MdlReadNoWait; + ULONG MdlReadWait; + ULONG MdlReadNoWaitMiss; + ULONG MdlReadWaitMiss; + ULONG ReadAheadIos; + ULONG LazyWriteIos; + ULONG LazyWritePages; + ULONG DataFlushes; + ULONG DataPages; + ULONG ContextSwitches; + ULONG FirstLevelTbFills; + ULONG SecondLevelTbFills; + ULONG SystemCalls; +} SYSTEM_PERFORMANCE_INFORMATION, *PSYSTEM_PERFORMANCE_INFORMATION; + +typedef struct __attribute__ ((aligned(8))) _SYSTEM_TIME_OF_DAY_INFORMATION +{ + LARGE_INTEGER BootTime; + LARGE_INTEGER CurrentTime; + LARGE_INTEGER TimeZoneBias; + ULONG CurrentTimeZoneId; +} SYSTEM_TIME_OF_DAY_INFORMATION, *PSYSTEM_TIME_OF_DAY_INFORMATION; + +typedef enum _PROCESSINFOCLASS +{ + ProcessBasicInformation = 0, + ProcessQuotaLimits = 1, + ProcessVmCounters = 3, + ProcessTimes =4, +} PROCESSINFOCLASS; + +typedef struct _DEBUG_BUFFER +{ + HANDLE SectionHandle; + PVOID SectionBase; + PVOID RemoteSectionBase; + ULONG SectionBaseDelta; + HANDLE EventPairHandle; + ULONG Unknown[2]; + HANDLE RemoteThreadHandle; + ULONG InfoClassMask; + ULONG SizeOfInfo; + ULONG AllocatedSize; + ULONG SectionSize; + PVOID ModuleInformation; + PVOID BackTraceInformation; + PVOID HeapInformation; + PVOID LockInformation; + PVOID Reserved[9]; +} DEBUG_BUFFER, *PDEBUG_BUFFER; + +typedef struct _DEBUG_HEAP_INFORMATION +{ + ULONG Base; + ULONG Flags; + USHORT Granularity; + USHORT Unknown; + ULONG Allocated; + ULONG Committed; + ULONG TagCount; + ULONG BlockCount; + ULONG Reserved[7]; + PVOID Tags; + PVOID Blocks; +} DEBUG_HEAP_INFORMATION, *PDEBUG_HEAP_INFORMATION; + +typedef struct _DEBUG_MODULE_INFORMATION +{ + ULONG Reserved[2]; + ULONG Base; + ULONG Size; + ULONG Flags; + USHORT Index; + USHORT Unknown; + USHORT LoadCount; + USHORT ModuleNameOffset; + CHAR ImageName[256]; +} DEBUG_MODULE_INFORMATION, *PDEBUG_MODULE_INFORMATION; + +typedef struct _KERNEL_USER_TIMES +{ + LARGE_INTEGER CreateTime; + LARGE_INTEGER ExitTime; + LARGE_INTEGER KernelTime; + LARGE_INTEGER UserTime; +} KERNEL_USER_TIMES, *PKERNEL_USER_TIMES; + +typedef void *PPEB; + +typedef struct _PROCESS_BASIC_INFORMATION +{ + NTSTATUS ExitStatus; + PPEB PebBaseAddress; + KAFFINITY AffinityMask; + KPRIORITY BasePriority; + ULONG UniqueProcessId; + ULONG InheritedFromUniqueProcessId; +} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; + +typedef enum _MEMORY_INFORMATION_CLASS +{ + MemoryBasicInformation, + MemoryWorkingSetList, + MemorySectionName, + MemoryBasicVlmInformation +} MEMORY_INFORMATION_CLASS; + +typedef struct _MEMORY_WORKING_SET_LIST +{ + ULONG NumberOfPages; + ULONG WorkingSetList[1]; +} MEMORY_WORKING_SET_LIST, *PMEMORY_WORKING_SET_LIST; + +typedef struct _FILE_NAME_INFORMATION +{ + DWORD FileNameLength; + WCHAR FileName[MAX_PATH + 100]; +} FILE_NAME_INFORMATION; + +typedef enum _OBJECT_INFORMATION_CLASS +{ + ObjectBasicInformation = 0, + ObjectNameInformation = 1, + ObjectHandleInformation = 4 + // and many more +} OBJECT_INFORMATION_CLASS; + +typedef struct _OBJECT_NAME_INFORMATION +{ + UNICODE_STRING Name; +} OBJECT_NAME_INFORMATION; + +/* Function declarations for ntdll.dll. These don't appear in any + standard Win32 header. */ +extern "C" +{ + NTSTATUS NTAPI NtCreateToken (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, + TOKEN_TYPE, PLUID, PLARGE_INTEGER, PTOKEN_USER, + PTOKEN_GROUPS, PTOKEN_PRIVILEGES, PTOKEN_OWNER, + PTOKEN_PRIMARY_GROUP, PTOKEN_DEFAULT_DACL, + PTOKEN_SOURCE); + NTSTATUS NTAPI NtMapViewOfSection (HANDLE, HANDLE, PVOID *, ULONG, ULONG, + PLARGE_INTEGER, PULONG, SECTION_INHERIT, + ULONG, ULONG); + NTSTATUS NTAPI NtOpenFile (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, + PIO_STATUS_BLOCK, ULONG, ULONG); + NTSTATUS NTAPI NtOpenSection (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES); + NTSTATUS NTAPI NtQueryInformationFile (HANDLE, IO_STATUS_BLOCK *, VOID *, + DWORD, DWORD); + NTSTATUS NTAPI NtQueryInformationProcess (HANDLE, PROCESSINFOCLASS, + PVOID, ULONG, PULONG); + NTSTATUS NTAPI NtQueryObject (HANDLE, OBJECT_INFORMATION_CLASS, VOID *, + ULONG, ULONG *); + NTSTATUS NTAPI NtQuerySystemInformation (SYSTEM_INFORMATION_CLASS, + PVOID, ULONG, PULONG); + NTSTATUS NTAPI NtQueryVirtualMemory (HANDLE, PVOID, MEMORY_INFORMATION_CLASS, + PVOID, ULONG, PULONG); + NTSTATUS NTAPI NtUnmapViewOfSection (HANDLE, PVOID); + VOID NTAPI RtlInitUnicodeString (PUNICODE_STRING, PCWSTR); + ULONG NTAPI RtlNtStatusToDosError (NTSTATUS); +} diff --git a/winsup/cygwin/ntea.cc b/winsup/cygwin/ntea.cc new file mode 100644 index 00000000000..7ddff77707c --- /dev/null +++ b/winsup/cygwin/ntea.cc @@ -0,0 +1,325 @@ +/* ntea.cc: code for manipulating NTEA information + + Copyright 1997, 1998, 2000, 2001 Red Hat, Inc. + + Written by Sergey S. Okhapkin (sos@prospect.com.ru) + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include "winsup.h" +#include <stdio.h> +#include <stdlib.h> +#include "security.h" + +/* Default to not using NTEA information */ +BOOL allow_ntea; + +/* +From Windows NT DDK: + +FILE_FULL_EA_INFORMATION provides extended attribute information. +This structure is used primarily by network drivers. + +Members + +NextEntryOffset +The offset of the next FILE_FULL_EA_INFORMATION-type entry. This member is +zero if no other entries follow this one. + +Flags +Can be zero or can be set with FILE_NEED_EA, indicating that the file to which +the EA belongs cannot be interpreted without understanding the associated +extended attributes. + +EaNameLength +The length in bytes of the EaName array. This value does not include a +zero-terminator to EaName. + +EaValueLength +The length in bytes of each EA value in the array. + +EaName +An array of characters naming the EA for this entry. + +Comments +This structure is longword-aligned. If a set of FILE_FULL_EA_INFORMATION +entries is buffered, NextEntryOffset value in each entry, except the last, +falls on a longword boundary. +The value(s) associated with each entry follows the EaName array. That is, an +EA's values are located at EaName + (EaNameLength + 1). +*/ + +typedef struct _FILE_FULL_EA_INFORMATION { + ULONG NextEntryOffset; + UCHAR Flags; + UCHAR EaNameLength; + USHORT EaValueLength; + CHAR EaName[1]; +} FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION; + +/* Functions prototypes */ + +int NTReadEA (const char *file, const char *attrname, char *buf, int len); +static PFILE_FULL_EA_INFORMATION NTReadEARaw (HANDLE file, int *len); +BOOL NTWriteEA(const char *file, const char *attrname, char *buf, int len); + +/* + * NTReadEA - read file's Extended Attribute. + * + * Parameters: + * file - pointer to filename + * attrname- pointer to EA name (case insensitivy. EAs are sored in upper + * case). + * attrbuf - pointer to buffer to store EA's value. + * len - length of attrbuf. + * Return value: + * 0 - if file or attribute "attrname" not found. + * N - number of bytes stored in attrbuf if succes. + * -1 - attrbuf too small for EA value. + */ + +int __stdcall +NTReadEA (const char *file, const char *attrname, char *attrbuf, int len) +{ + HANDLE hFileSource; + int eafound = 0; + PFILE_FULL_EA_INFORMATION ea, sea; + int easize; + + hFileSource = CreateFile (file, FILE_READ_EA, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, // sa + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + + if (hFileSource == INVALID_HANDLE_VALUE) + return 0; + + /* Read in raw array of EAs */ + ea = sea = NTReadEARaw (hFileSource, &easize); + + /* Search for requested attribute */ + while (sea) + { + if (strcasematch (ea->EaName, attrname)) /* EA found */ + { + if (ea->EaValueLength > len) + { + eafound = -1; /* buffer too small */ + break; + } + memcpy (attrbuf, ea->EaName + (ea->EaNameLength + 1), + ea->EaValueLength); + eafound = ea->EaValueLength; + break; + } + if ((ea->NextEntryOffset == 0) || ((int) ea->NextEntryOffset > easize)) + break; + ea = (PFILE_FULL_EA_INFORMATION) ((char *) ea + ea->NextEntryOffset); + } + + if (sea) + free (sea); + CloseHandle (hFileSource); + + return eafound; +} + +/* + * NTReadEARaw - internal routine to read EAs array to malloced buffer. The + * caller should free this buffer after usage. + * Parameters: + * hFileSource - handle to file. This handle should have FILE_READ_EA + * rights. + * len - pointer to int variable where length of buffer will + * be stored. + * Return value: + * pointer to buffer with file's EAs, or NULL if any error occured. + */ + +static PFILE_FULL_EA_INFORMATION +NTReadEARaw (HANDLE hFileSource, int *len) +{ + WIN32_STREAM_ID StreamId; + DWORD dwBytesWritten; + LPVOID lpContext; + DWORD StreamSize; + PFILE_FULL_EA_INFORMATION eafound = NULL; + + lpContext = NULL; + StreamSize = sizeof (WIN32_STREAM_ID) - sizeof (WCHAR**); + + /* Read the WIN32_STREAM_ID in */ + + while (BackupRead (hFileSource, (LPBYTE) &StreamId, StreamSize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + { + DWORD sl,sh; + + if (dwBytesWritten == 0) /* No more Stream IDs */ + break; + /* skip StreamName */ + if (StreamId.dwStreamNameSize) + { + unsigned char *buf; + buf = (unsigned char *) malloc (StreamId.dwStreamNameSize); + + if (buf == NULL) + break; + + if (!BackupRead (hFileSource, buf, // buffer to read + StreamId.dwStreamNameSize, // num bytes to read + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) // Stream name read error + { + free (buf); + break; + } + free (buf); + } + + /* Is it EA stream? */ + if (StreamId.dwStreamId == BACKUP_EA_DATA) + { + unsigned char *buf; + buf = (unsigned char *) malloc (StreamId.Size.LowPart); + + if (buf == NULL) + break; + if (!BackupRead (hFileSource, buf, // buffer to read + StreamId.Size.LowPart, // num bytes to write + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + { + free (buf); /* EA read error */ + break; + } + eafound = (PFILE_FULL_EA_INFORMATION) buf; + *len = StreamId.Size.LowPart; + break; + } + /* Skip current stream */ + if (!BackupSeek (hFileSource, + StreamId.Size.LowPart, + StreamId.Size.HighPart, + &sl, + &sh, + &lpContext)) + break; + } + + /* free context */ + BackupRead ( + hFileSource, + NULL, // buffer to write + 0, // number of bytes to write + &dwBytesWritten, + TRUE, // abort + FALSE, // don't process security + &lpContext); + + return eafound; +} + +/* + * NTWriteEA - write file's Extended Attribute. + * + * Parameters: + * file - pointer to filename + * attrname- pointer to EA name (case insensitivy. EAs are sored in upper + * case). + * buf - pointer to buffer with EA value. + * len - length of buf. + * Return value: + * TRUE if success, FALSE otherwice. + * Note: if len=0 given EA will be deleted. + */ + +BOOL __stdcall +NTWriteEA (const char *file, const char *attrname, const char *buf, int len) +{ + HANDLE hFileSource; + WIN32_STREAM_ID StreamId; + DWORD dwBytesWritten; + LPVOID lpContext; + DWORD StreamSize, easize; + BOOL bSuccess=FALSE; + PFILE_FULL_EA_INFORMATION ea; + + hFileSource = CreateFile (file, FILE_WRITE_EA, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &sec_none_nih, // sa + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + + if (hFileSource == INVALID_HANDLE_VALUE) + return FALSE; + + lpContext = NULL; + StreamSize = sizeof (WIN32_STREAM_ID) - sizeof (WCHAR**); + + /* FILE_FULL_EA_INFORMATION structure is longword-aligned */ + easize = sizeof (*ea) - sizeof (WCHAR**) + strlen (attrname) + 1 + len + + (sizeof (DWORD) - 1); + easize &= ~(sizeof (DWORD) - 1); + + if ((ea = (PFILE_FULL_EA_INFORMATION) malloc (easize)) == NULL) + goto cleanup; + + memset (ea, 0, easize); + ea->EaNameLength = strlen (attrname); + ea->EaValueLength = len; + strcpy (ea->EaName, attrname); + memcpy (ea->EaName + (ea->EaNameLength + 1), buf, len); + + StreamId.dwStreamId = BACKUP_EA_DATA; + StreamId.dwStreamAttributes = 0; + StreamId.Size.HighPart = 0; + StreamId.Size.LowPart = easize; + StreamId.dwStreamNameSize = 0; + + if (!BackupWrite (hFileSource, (LPBYTE) &StreamId, StreamSize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + goto cleanup; + + if (!BackupWrite (hFileSource, (LPBYTE) ea, easize, + &dwBytesWritten, + FALSE, // don't abort yet + FALSE, // don't process security + &lpContext)) + goto cleanup; + + bSuccess = TRUE; + /* free context */ + +cleanup: + BackupRead (hFileSource, + NULL, // buffer to write + 0, // number of bytes to write + &dwBytesWritten, + TRUE, // abort + FALSE, // don't process security + &lpContext); + + CloseHandle (hFileSource); + if (ea) + free (ea); + + return bSuccess; +} diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc index da2f80b0d3c..35d02a83da0 100644 --- a/winsup/cygwin/poll.cc +++ b/winsup/cygwin/poll.cc @@ -26,8 +26,7 @@ #include "cygheap.h" #include "sigproc.h" -extern "C" -int +extern "C" int poll (struct pollfd *fds, unsigned int nfds, int timeout) { int max_fd = 0; diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 40b1eeb6f85..aea340d507e 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -72,7 +72,7 @@ public: if (!check && initialized) return; if (pglock->acquire () == 1 && - (!initialized || (check && etc::file_changed (etc_ix)))) + (!initialized || (check && etc::file_changed (etc_ix)))) (this->*read) (); pglock->release (); } diff --git a/winsup/cygwin/sec_acl.cc b/winsup/cygwin/sec_acl.cc index 932afc7aaa9..7455fd14d7d 100644 --- a/winsup/cygwin/sec_acl.cc +++ b/winsup/cygwin/sec_acl.cc @@ -126,7 +126,7 @@ setacl (const char *file, int nentries, __aclent32_t *aclbufp) if (aclbufp[i].a_perm & S_IROTH) allow |= FILE_GENERIC_READ; if (aclbufp[i].a_perm & S_IWOTH) - { + { allow |= STANDARD_RIGHTS_WRITE | FILE_GENERIC_WRITE; /* Owner gets DELETE right, too. */ if ((aclbufp[i].a_type & ~ACL_DEFAULT) == USER_OBJ) @@ -413,8 +413,7 @@ getacl (const char *file, DWORD attr, int nentries, __aclent32_t *aclbufp) return pos; } -static -int +static int acl_worker (const char *path, int cmd, int nentries, __aclent32_t *aclbufp, int nofollow) { @@ -493,22 +492,19 @@ acl_worker (const char *path, int cmd, int nentries, __aclent32_t *aclbufp, return -1; } -extern "C" -int +extern "C" int acl32 (const char *path, int cmd, int nentries, __aclent32_t *aclbufp) { return acl_worker (path, cmd, nentries, aclbufp, 0); } -extern "C" -int +extern "C" int lacl32 (const char *path, int cmd, int nentries, __aclent32_t *aclbufp) { return acl_worker (path, cmd, nentries, aclbufp, 1); } -extern "C" -int +extern "C" int facl32 (int fd, int cmd, int nentries, __aclent32_t *aclbufp) { cygheap_fdget cfd (fd); @@ -528,8 +524,7 @@ facl32 (int fd, int cmd, int nentries, __aclent32_t *aclbufp) return acl_worker (path, cmd, nentries, aclbufp, 0); } -extern "C" -int +extern "C" int aclcheck32 (__aclent32_t *aclbufp, int nentries, int *which) { BOOL has_user_obj = FALSE; @@ -661,8 +656,8 @@ aclcheck32 (__aclent32_t *aclbufp, int nentries, int *which) return 0; } -static -int acecmp (const void *a1, const void *a2) +static int +acecmp (const void *a1, const void *a2) { #define ace(i) ((const __aclent32_t *) a##i) int ret = ace (1)->a_type - ace (2)->a_type; @@ -672,8 +667,7 @@ int acecmp (const void *a1, const void *a2) #undef ace } -extern "C" -int +extern "C" int aclsort32 (int nentries, int, __aclent32_t *aclbufp) { if (aclcheck32 (aclbufp, nentries, NULL)) @@ -687,8 +681,7 @@ aclsort32 (int nentries, int, __aclent32_t *aclbufp) return 0; } -extern "C" -int +extern "C" int acltomode32 (__aclent32_t *aclbufp, int nentries, mode_t *modep) { int pos; @@ -727,8 +720,7 @@ acltomode32 (__aclent32_t *aclbufp, int nentries, mode_t *modep) return 0; } -extern "C" -int +extern "C" int aclfrommode32 (__aclent32_t *aclbufp, int nentries, mode_t *modep) { int pos; @@ -765,15 +757,13 @@ aclfrommode32 (__aclent32_t *aclbufp, int nentries, mode_t *modep) return 0; } -extern "C" -int +extern "C" int acltopbits32 (__aclent32_t *aclbufp, int nentries, mode_t *pbitsp) { return acltomode32 (aclbufp, nentries, pbitsp); } -extern "C" -int +extern "C" int aclfrompbits32 (__aclent32_t *aclbufp, int nentries, mode_t *pbitsp) { return aclfrommode32 (aclbufp, nentries, pbitsp); @@ -791,8 +781,7 @@ permtostr (mode_t perm) return pbuf; } -extern "C" -char * +extern "C" char * acltotext32 (__aclent32_t *aclbufp, int aclcnt) { if (!aclbufp || aclcnt < 1 || aclcnt > MAX_ACL_ENTRIES @@ -868,8 +857,7 @@ permfromstr (char *perm) return mode; } -extern "C" -__aclent32_t * +extern "C" __aclent32_t * aclfromtext32 (char *acltextp, int *) { if (!acltextp) @@ -992,79 +980,68 @@ acl16to32 (__aclent16_t *aclbufp, int nentries) return aclbufp32; } -extern "C" -int +extern "C" int acl (const char *path, int cmd, int nentries, __aclent16_t *aclbufp) { return acl32 (path, cmd, nentries, acl16to32 (aclbufp, nentries)); } -extern "C" -int +extern "C" int facl (int fd, int cmd, int nentries, __aclent16_t *aclbufp) { return facl32 (fd, cmd, nentries, acl16to32 (aclbufp, nentries)); } -extern "C" -int +extern "C" int lacl (const char *path, int cmd, int nentries, __aclent16_t *aclbufp) { return lacl32 (path, cmd, nentries, acl16to32 (aclbufp, nentries)); } -extern "C" -int +extern "C" int aclcheck (__aclent16_t *aclbufp, int nentries, int *which) { return aclcheck32 (acl16to32 (aclbufp, nentries), nentries, which); } -extern "C" -int +extern "C" int aclsort (int nentries, int i, __aclent16_t *aclbufp) { return aclsort32 (nentries, i, acl16to32 (aclbufp, nentries)); } -extern "C" -int +extern "C" int acltomode (__aclent16_t *aclbufp, int nentries, mode_t *modep) { return acltomode32 (acl16to32 (aclbufp, nentries), nentries, modep); } -extern "C" -int +extern "C" int aclfrommode (__aclent16_t *aclbufp, int nentries, mode_t *modep) { return aclfrommode32 ((__aclent32_t *)aclbufp, nentries, modep); } -extern "C" -int +extern "C" int acltopbits (__aclent16_t *aclbufp, int nentries, mode_t *pbitsp) { return acltopbits32 (acl16to32 (aclbufp, nentries), nentries, pbitsp); } -extern "C" -int +extern "C" int aclfrompbits (__aclent16_t *aclbufp, int nentries, mode_t *pbitsp) { return aclfrompbits32 ((__aclent32_t *)aclbufp, nentries, pbitsp); } -extern "C" -char * +extern "C" char * acltotext (__aclent16_t *aclbufp, int aclcnt) { return acltotext32 (acl16to32 (aclbufp, aclcnt), aclcnt); } -extern "C" -__aclent16_t * +extern "C" __aclent16_t * aclfromtext (char *acltextp, int * aclcnt) { return (__aclent16_t *) aclfromtext32 (acltextp, aclcnt); diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index 95c851ae4bc..b50a4c8c51a 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -83,7 +83,7 @@ cygpsid::get_id (BOOL search_grp, int *type) else if ((gr = internal_getgrsid (*this))) id = gr->gr_gid; if (id != ILLEGAL_UID) - { + { if (type) *type = GROUP; return id; @@ -97,7 +97,7 @@ cygpsid::get_id (BOOL search_grp, int *type) else if ((pw = internal_getpwsid (*this))) id = pw->pw_uid; if (id != ILLEGAL_UID && type) - *type = USER; + *type = USER; } return id; } diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 620c4ff6fbf..35aced2eb34 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -96,7 +96,7 @@ extract_nt_dom_user (const struct passwd *pw, char *domain, char *user) else if (u - d <= INTERNET_MAX_HOST_NAME_LENGTH + 2) strlcpy (domain, d + 2, u - d - 1); if (c - u <= UNLEN + 1) - strlcpy (user, u + 1, c - u); + strlcpy (user, u + 1, c - u); } if (domain[0]) return; diff --git a/winsup/cygwin/security.h b/winsup/cygwin/security.h index a859526d7f6..2965b1dec59 100644 --- a/winsup/cygwin/security.h +++ b/winsup/cygwin/security.h @@ -115,7 +115,7 @@ public: BOOL add (const PSID nsi) /* Only with auto for now */ { if (count >= maxcount) - { + { cygsid *tmp = new cygsid [ 2 * maxcount]; if (!tmp) return FALSE; @@ -176,7 +176,7 @@ public: void clear_supp () { if (issetgroups ()) - { + { sgsids.free_sids (); ischanged = TRUE; } diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index e468144d7dc..02c843218e5 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -95,8 +95,7 @@ typedef long fd_mask; /* The main select code. */ -extern "C" -int +extern "C" int cygwin_select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *to) { diff --git a/winsup/cygwin/string.h b/winsup/cygwin/string.h index 0ac9745adf3..1ad90213488 100644 --- a/winsup/cygwin/string.h +++ b/winsup/cygwin/string.h @@ -85,7 +85,7 @@ cygwin_strcasematch (const char *cs, const char *ct) jmp 4f \n\ 3: xor %0,%0 \n\ 4:" - :"=a" (__res), "=&S" (d0), "=&D" (d1) + :"=a" (__res), "=&S" (d0), "=&D" (d1) : "1" (cs), "2" (ct)); return __res; diff --git a/winsup/cygwin/strsep.cc b/winsup/cygwin/strsep.cc new file mode 100644 index 00000000000..f03df3d94f4 --- /dev/null +++ b/winsup/cygwin/strsep.cc @@ -0,0 +1,64 @@ +/* strsep.cc: strsep call */ + +#include <stdio.h> + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +extern "C" char * +strsep (char **stringp, + const char *delim) +{ + register char *s; + register const char *spanp; + register int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 64f56787e86..22a73df67d5 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -165,7 +165,6 @@ unlink (const char *ourname) } } - /* Try a delete with attributes reset */ if (DeleteFile (win32_name)) { diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc index 67629b2f900..cf3931ffe76 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -60,8 +60,7 @@ static int process_logmask = LOG_UPTO (LOG_DEBUG); * openlog: save the passed args. Don't open the * system log (NT) or log file (95) yet. */ -extern "C" -void +extern "C" void openlog (const char *ident, int logopt, int facility) { debug_printf ("openlog called with (%s, %d, %d)", @@ -208,8 +207,7 @@ pass_handler::print_va (const char *fmt, va_list list) * always point to that. */ -extern "C" -void +extern "C" void syslog (int priority, const char *message, ...) { debug_printf ("%x %s", priority, message); @@ -410,8 +408,7 @@ syslog (int priority, const char *message, ...) } } -extern "C" -void +extern "C" void closelog (void) { ; diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index bb644b2e5d3..01d3f5250ec 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -28,22 +28,19 @@ details. */ extern fhandler_tty_master *tty_master; -extern "C" -int +extern "C" int grantpt (int fd) { return 0; } -extern "C" -int +extern "C" int unlockpt (int fd) { return 0; } -extern "C" -int +extern "C" int ttyslot (void) { if (NOTSTATE (myself, PID_USETTY)) diff --git a/winsup/cygwin/wait.cc b/winsup/cygwin/wait.cc new file mode 100644 index 00000000000..3b6427ad927 --- /dev/null +++ b/winsup/cygwin/wait.cc @@ -0,0 +1,129 @@ +/* wait.cc: Posix wait routines. + + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include "winsup.h" +#include <sys/wait.h> +#include <stdlib.h> +#include <errno.h> +#include "cygerrno.h" +#include "sigproc.h" +#include "perthread.h" +#include "thread.h" + +/* This is called _wait and not wait because the real wait is defined + in libc/syscalls/syswait.c. It calls us. */ + +extern "C" pid_t +wait (int *status) +{ + return wait4 (-1, status, 0, NULL); +} + +extern "C" pid_t +waitpid (pid_t intpid, int *status, int options) +{ + return wait4 (intpid, status, options, NULL); +} + +extern "C" pid_t +wait3 (int *status, int options, struct rusage *r) +{ + return wait4 (-1, status, options, r); +} + +/* Wait for any child to complete. + * Note: this is not thread safe. Use of wait in multiple threads will + * not work correctly. + */ + +extern "C" pid_t +wait4 (int intpid, int *status, int options, struct rusage *r) +{ + int res; + waitq *w; + HANDLE waitfor; + bool sawsig; + + pthread_testcancel (); + + while (1) + { + sig_dispatch_pending (0); + sigframe thisframe (mainthread); + sawsig = 0; + if (options & ~(WNOHANG | WUNTRACED)) + { + set_errno (EINVAL); + return -1; + } + + if (r) + memset (r, 0, sizeof (*r)); + + if ((w = (waitq *) waitq_storage.get ()) == NULL) + w = (waitq *) waitq_storage.create (); + + w->pid = intpid; + w->options = options; + w->rusage = r; + sigproc_printf ("calling proc_subproc, pid %d, options %d", + w->pid, w->options); + if (!proc_subproc (PROC_WAIT, (DWORD)w)) + { + set_errno (ENOSYS); + paranoid_printf ("proc_subproc returned 0"); + res = -1; + goto done; + } + + if ((waitfor = w->ev) == NULL) + goto nochildren; + + res = pthread::cancelable_wait (waitfor, INFINITE); + + sigproc_printf ("%d = WaitForSingleObject (...)", res); + + if (w->ev == NULL) + { + nochildren: + /* found no children */ + set_errno (ECHILD); + res = -1; + goto done; + } + + if (w->status == -1) + { + set_sig_errno (EINTR); + sawsig = 1; + res = -1; + } + else if (res != WAIT_OBJECT_0) + { + /* We shouldn't set errno to any random value if we can help it. + See the Posix manual for a list of valid values for `errno'. */ + set_errno (EINVAL); + res = -1; + } + else if ((res = w->pid) != 0 && status) + *status = w->status; + + done: + if (!sawsig || !thisframe.call_signal_handler ()) + break; + } + + sigproc_printf ("intpid %d, status %p, w->status %d, options %d, res %d", + intpid, status, w->status, options, res); + w->status = -1; + if (res < 0) + sigproc_printf ("*** errno = %d", get_errno ()); + return res; +} |