Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2011-12-22 15:02:36 +0400
committerCorinna Vinschen <corinna@vinschen.de>2011-12-22 15:02:36 +0400
commit177dc6c7f6d0608ef6540fd997d9b444e324cae2 (patch)
treea5c742c17d6bf502ffb8949365a04c18c3de62c1
parent8176232ddc752350e6d274947ad7eabb6b502276 (diff)
Throughout use wincap.allocation_granularity instead of getpagesize.
Throughout use wincap.page_size instead of getsystempagesize. Throughout use "status" as variable name to hold NTSTATUS values. * fhandler_mem.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS. Fix debug_printf output. Rectify long statements. Fix comment formatting. * fhandler_proc.cc: Ditto. (format_proc_swaps): Drop useless test for ERROR_PROC_NOT_FOUND. * fhandler_process.cc: Ditto as in fhandler_mem.cc. (get_process_state): Rearrange allocation loop. Use malloc/realloc. (get_mem_values): Fix potential NULL pointer usage. Drop unused variable. * pinfo.cc (winpids::enum_processes): Handle low memory gracefully. * sec_auth.cc (get_priv_list): Drop local variable ret. * shared.cc (memory_init): Drop outdated call to getpagesize. * syscalls.cc (getsystempagesize): Remove. * sysconf.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS. (sysinfo): Constify sizeof_stodi. Drop useless test for ERROR_PROC_NOT_FOUND. * thread.cc (pthread_getattr_np): Cast pointers to uintptr_t rather than to int for pointer arithmetic. * winsup.h (getsystempagesize): Drop declaration.
-rw-r--r--winsup/cygwin/ChangeLog27
-rw-r--r--winsup/cygwin/cygheap.cc2
-rw-r--r--winsup/cygwin/external.cc2
-rw-r--r--winsup/cygwin/fhandler_mem.cc72
-rw-r--r--winsup/cygwin/fhandler_proc.cc102
-rw-r--r--winsup/cygwin/fhandler_process.cc179
-rw-r--r--winsup/cygwin/mmap.cc99
-rw-r--r--winsup/cygwin/pinfo.cc42
-rw-r--r--winsup/cygwin/sec_auth.cc10
-rw-r--r--winsup/cygwin/shared.cc2
-rw-r--r--winsup/cygwin/syscalls.cc6
-rw-r--r--winsup/cygwin/sysconf.cc78
-rw-r--r--winsup/cygwin/thread.cc15
-rw-r--r--winsup/cygwin/winsup.h3
14 files changed, 331 insertions, 308 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 03d43a459..fbdd08fa2 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,9 +1,34 @@
+2011-12-22 Corinna Vinschen <vinschen@redhat.com>
+
+ Throughout use wincap.allocation_granularity instead of getpagesize.
+ Throughout use wincap.page_size instead of getsystempagesize.
+ Throughout use "status" as variable name to hold NTSTATUS values.
+ * fhandler_mem.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
+ Fix debug_printf output. Rectify long statements. Fix comment
+ formatting.
+ * fhandler_proc.cc: Ditto.
+ (format_proc_swaps): Drop useless test for ERROR_PROC_NOT_FOUND.
+ * fhandler_process.cc: Ditto as in fhandler_mem.cc.
+ (get_process_state): Rearrange allocation loop. Use malloc/realloc.
+ (get_mem_values): Fix potential NULL pointer usage. Drop unused
+ variable.
+ * pinfo.cc (winpids::enum_processes): Handle low memory gracefully.
+ * sec_auth.cc (get_priv_list): Drop local variable ret.
+ * shared.cc (memory_init): Drop outdated call to getpagesize.
+ * syscalls.cc (getsystempagesize): Remove.
+ * sysconf.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
+ (sysinfo): Constify sizeof_stodi. Drop useless test for
+ ERROR_PROC_NOT_FOUND.
+ * thread.cc (pthread_getattr_np): Cast pointers to uintptr_t rather
+ than to int for pointer arithmetic.
+ * winsup.h (getsystempagesize): Drop declaration.
+
2011-12-21 Christopher Faylor <me.cygwin2011@cgf.cx>
* fhandler.cc (fhandler_base_overlapped::wait_overlapped): Use correct
value in switch statement.
-2011-12-11 Corinna Vinschen <vinschen@redhat.com>
+2011-12-21 Corinna Vinschen <vinschen@redhat.com>
* dcrt0.cc (_dll_crt0): Rephrase comments. Set $ebp to NULL, as in
the pthread stack setup.
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index fabb68072..9f1a3f513 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -126,7 +126,7 @@ static void *__stdcall
_csbrk (int sbs)
{
void *prebrk = cygheap_max;
- size_t granmask = getpagesize () - 1;
+ size_t granmask = wincap.allocation_granularity () - 1;
char *newbase = nextpage (prebrk);
cygheap_max = (char *) cygheap_max + sbs;
if (!sbs || (newbase >= cygheap_max) || (cygheap_max <= _cygheap_end))
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc
index 58639fe63..947680420 100644
--- a/winsup/cygwin/external.cc
+++ b/winsup/cygwin/external.cc
@@ -371,7 +371,7 @@ cygwin_internal (cygwin_getinfo_types t, ...)
break;
case CW_GET_SHMLBA:
{
- res = getpagesize ();
+ res = wincap.allocation_granularity ();
}
break;
case CW_GET_UID_FROM_SID:
diff --git a/winsup/cygwin/fhandler_mem.cc b/winsup/cygwin/fhandler_mem.cc
index e79cf36f9..c3c442ebd 100644
--- a/winsup/cygwin/fhandler_mem.cc
+++ b/winsup/cygwin/fhandler_mem.cc
@@ -32,6 +32,8 @@ fhandler_dev_mem::~fhandler_dev_mem ()
int
fhandler_dev_mem::open (int flags, mode_t)
{
+ NTSTATUS status;
+
if (!wincap.has_physical_mem_access ())
{
set_errno (ENOENT);
@@ -41,13 +43,13 @@ fhandler_dev_mem::open (int flags, mode_t)
if (dev () == FH_MEM) /* /dev/mem */
{
- NTSTATUS ret;
SYSTEM_BASIC_INFORMATION sbi;
- if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
- sizeof sbi, NULL)) != STATUS_SUCCESS)
+ status = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
+ sizeof sbi, NULL);
+ if (NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
- debug_printf("NtQuerySystemInformation: ret %d, Dos(ret) %E", ret);
+ __seterrno_from_nt_status (status);
+ debug_printf("NtQuerySystemInformation: status %p, %E", status);
mem_size = 0;
}
else
@@ -67,7 +69,7 @@ fhandler_dev_mem::open (int flags, mode_t)
else
{
mem_size = 0;
- debug_printf ("Illegal minor number!!!");
+ debug_printf ("Illegal minor number");
}
/* Check for illegal flags. */
@@ -101,10 +103,10 @@ fhandler_dev_mem::open (int flags, mode_t)
}
HANDLE mem;
- NTSTATUS ret = NtOpenSection (&mem, section_access, &attr);
- if (!NT_SUCCESS (ret))
+ status = NtOpenSection (&mem, section_access, &attr);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
set_io_handle (NULL);
return 0;
}
@@ -130,31 +132,26 @@ fhandler_dev_mem::write (const void *ptr, size_t ulen)
ulen = mem_size - pos;
PHYSICAL_ADDRESS phys;
- NTSTATUS ret;
+ NTSTATUS status;
void *viewmem = NULL;
- DWORD len = ulen + getsystempagesize () - 1;
+ DWORD len = ulen + wincap.page_size () - 1;
phys.QuadPart = (ULONGLONG) pos;
- if ((ret = NtMapViewOfSection (get_handle (),
- INVALID_HANDLE_VALUE,
- &viewmem,
- 0L,
- len,
- &phys,
- &len,
- ViewShare,
- 0,
- PAGE_READONLY)) != STATUS_SUCCESS)
+ status = NtMapViewOfSection (get_handle (), INVALID_HANDLE_VALUE, &viewmem,
+ 0L, len, &phys, &len, ViewShare, 0,
+ PAGE_READONLY);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
return -1;
}
memcpy ((char *) viewmem + (pos - phys.QuadPart), ptr, ulen);
- if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
+ status = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
return -1;
}
@@ -182,32 +179,27 @@ fhandler_dev_mem::read (void *ptr, size_t& ulen)
ulen = mem_size - pos;
PHYSICAL_ADDRESS phys;
- NTSTATUS ret;
+ NTSTATUS status;
void *viewmem = NULL;
- DWORD len = ulen + getsystempagesize () - 1;
+ DWORD len = ulen + wincap.page_size () - 1;
phys.QuadPart = (ULONGLONG) pos;
- if ((ret = NtMapViewOfSection (get_handle (),
- INVALID_HANDLE_VALUE,
- &viewmem,
- 0L,
- len,
- &phys,
- &len,
- ViewShare,
- 0,
- PAGE_READONLY)) != STATUS_SUCCESS)
+ status = NtMapViewOfSection (get_handle (), INVALID_HANDLE_VALUE, &viewmem,
+ 0L, len, &phys, &len, ViewShare, 0,
+ PAGE_READONLY);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
ulen = (size_t) -1;
return;
}
memcpy (ptr, (char *) viewmem + (pos - phys.QuadPart), ulen);
- if (!NT_SUCCESS (ret = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem)))
+ status = NtUnmapViewOfSection (INVALID_HANDLE_VALUE, viewmem);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
ulen = (size_t) -1;
return;
}
@@ -251,7 +243,7 @@ int
fhandler_dev_mem::fstat (struct __stat64 *buf)
{
fhandler_base::fstat (buf);
- buf->st_blksize = getsystempagesize ();
+ buf->st_blksize = wincap.page_size ();
if (is_auto_device ())
{
buf->st_mode = S_IFCHR;
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index 6291eece9..3b4e6c202 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -460,7 +460,7 @@ static _off64_t
format_proc_uptime (void *, char *&destbuf)
{
unsigned long long uptime = 0ULL, idle_time = 0ULL;
- NTSTATUS ret;
+ NTSTATUS status;
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
/* Sizeof SYSTEM_PERFORMANCE_INFORMATION on 64 bit systems. It
appears to contain some trailing additional information from
@@ -470,13 +470,13 @@ format_proc_uptime (void *, char *&destbuf)
PSYSTEM_PERFORMANCE_INFORMATION spi = (PSYSTEM_PERFORMANCE_INFORMATION)
alloca (sizeof_spi);
- ret = NtQuerySystemInformation (SystemTimeOfDayInformation, &stodi,
- sizeof stodi, NULL);
- if (NT_SUCCESS (ret))
+ status = NtQuerySystemInformation (SystemTimeOfDayInformation, &stodi,
+ sizeof stodi, NULL);
+ if (NT_SUCCESS (status))
uptime = (stodi.CurrentTime.QuadPart - stodi.BootTime.QuadPart) / 100000ULL;
else
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
- "status %p", ret);
+ "status %p", status);
if (NT_SUCCESS (NtQuerySystemInformation (SystemPerformanceInformation,
spi, sizeof_spi, NULL)))
@@ -495,7 +495,7 @@ format_proc_stat (void *, char *&destbuf)
unsigned long pages_in = 0UL, pages_out = 0UL, interrupt_count = 0UL,
context_switches = 0UL, swap_in = 0UL, swap_out = 0UL;
time_t boot_time = 0;
- NTSTATUS ret;
+ NTSTATUS status;
/* Sizeof SYSTEM_PERFORMANCE_INFORMATION on 64 bit systems. It
appears to contain some trailing additional information from
what I can tell after examining the content.
@@ -510,11 +510,11 @@ format_proc_stat (void *, char *&destbuf)
char *eobuf = buf;
SYSTEM_PROCESSOR_TIMES spt[wincap.cpu_count ()];
- ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
- sizeof spt[0] * wincap.cpu_count (), NULL);
- if (!NT_SUCCESS (ret))
+ status = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
+ sizeof spt[0] * wincap.cpu_count (), NULL);
+ if (!NT_SUCCESS (status))
debug_printf ("NtQuerySystemInformation(SystemProcessorTimes), "
- "status %p", ret);
+ "status %p", status);
else
{
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
@@ -539,36 +539,32 @@ format_proc_stat (void *, char *&destbuf)
user_time, 0ULL, kernel_time, idle_time);
}
- ret = NtQuerySystemInformation (SystemPerformanceInformation,
- (PVOID) spi, sizeof_spi, NULL);
- if (!NT_SUCCESS (ret))
+ status = NtQuerySystemInformation (SystemPerformanceInformation,
+ (PVOID) spi, sizeof_spi, NULL);
+ if (!NT_SUCCESS (status))
{
debug_printf ("NtQuerySystemInformation(SystemPerformanceInformation)"
- ", status %p", ret);
+ ", status %p", status);
memset (spi, 0, sizeof_spi);
}
- ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
- (PVOID) &stodi,
- sizeof stodi, NULL);
- if (!NT_SUCCESS (ret))
+ status = NtQuerySystemInformation (SystemTimeOfDayInformation,
+ (PVOID) &stodi, sizeof stodi, NULL);
+ if (!NT_SUCCESS (status))
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
- "status %p", ret);
+ "status %p", status);
}
- if (!NT_SUCCESS (ret))
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
return 0;
}
pages_in = spi->PagesRead;
pages_out = spi->PagefilePagesWritten + spi->MappedFilePagesWritten;
- /*
- * Note: there is no distinction made in this structure between pages
- * read from the page file and pages read from mapped files, but there
- * is such a distinction made when it comes to writing. Goodness knows
- * why. The value of swap_in, then, will obviously be wrong but its our
- * best guess.
- */
+ /* Note: there is no distinction made in this structure between pages read
+ from the page file and pages read from mapped files, but there is such
+ a distinction made when it comes to writing. Goodness knows why. The
+ value of swap_in, then, will obviously be wrong but its our best guess. */
swap_in = spi->PagesRead;
swap_out = spi->PagefilePagesWritten;
context_switches = spi->ContextSwitches;
@@ -705,7 +701,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
maxf &= 0xffff;
vendor_id[3] = 0;
- // vendor identification
+ /* Vendor identification. */
bool is_amd = false, is_intel = false;
if (!strcmp ((char*)vendor_id, "AuthenticAMD"))
is_amd = true;
@@ -746,18 +742,18 @@ format_proc_cpuinfo (void *, char *&destbuf)
}
else
{
- // could implement a lookup table here if someone needs it
+ /* Could implement a lookup table here if someone needs it. */
strcpy (in_buf.s, "unknown");
}
int cache_size = -1,
tlb_size = -1,
clflush = 64,
cache_alignment = 64;
- if (features1 & (1 << 19)) // CLFSH
+ if (features1 & (1 << 19)) /* CLFSH */
clflush = ((extra_info >> 8) & 0xff) << 3;
if (is_intel && family == 15)
cache_alignment = clflush * 2;
- if (maxe >= 0x80000005) // L1 Cache and TLB Identifiers
+ if (maxe >= 0x80000005) /* L1 Cache and TLB Identifiers. */
{
unsigned data_cache, inst_cache;
cpuid (&unused, &unused, &data_cache, &inst_cache,
@@ -766,7 +762,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
cache_size = (inst_cache >> 24) + (data_cache >> 24);
tlb_size = 0;
}
- if (maxe >= 0x80000006) // L2 Cache and L2 TLB Identifiers
+ if (maxe >= 0x80000006) /* L2 Cache and L2 TLB Identifiers. */
{
unsigned tlb, l2;
cpuid (&unused, &tlb, &l2, &unused, 0x80000006);
@@ -788,7 +784,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
bufptr += __small_sprintf (bufptr, "cache size\t: %d KB\n",
cache_size);
- // Recognize multi-core CPUs
+ /* Recognize multi-core CPUs. */
if (is_amd && maxe >= 0x80000008)
{
unsigned core_info;
@@ -810,7 +806,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
apic_id, core_id, max_cores);
}
}
- // Recognize Intel Hyper-Transport CPUs
+ /* Recognize Intel Hyper-Transport CPUs. */
else if (is_intel && (features1 & (1 << 28)) && maxf >= 4)
{
/* TODO */
@@ -895,7 +891,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
if (features & (1 << 11))
print (" syscall");
- if (features & (1 << 19)) // Huh? Not in AMD64 specs.
+ if (features & (1 << 19)) /* Huh? Not in AMD64 specs. */
print (" mp");
if (features & (1 << 20))
print (" nx");
@@ -909,9 +905,9 @@ format_proc_cpuinfo (void *, char *&destbuf)
print (" rdtscp");
if (features & (1 << 29))
print (" lm");
- if (features & (1 << 30)) // 31th bit is on
+ if (features & (1 << 30)) /* 31th bit is on. */
print (" 3dnowext");
- if (features & (1 << 31)) // 32th bit (highest) is on
+ if (features & (1 << 31)) /* 32th bit (highest) is on. */
print (" 3dnow");
}
@@ -1024,7 +1020,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
clflush,
cache_alignment);
- if (maxe >= 0x80000008) // Address size
+ if (maxe >= 0x80000008) /* Address size. */
{
unsigned addr_size, phys, virt;
cpuid (&addr_size, &unused, &unused, &unused, 0x80000008);
@@ -1040,7 +1036,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
phys, virt);
}
- if (maxe >= 0x80000007) // advanced power management
+ if (maxe >= 0x80000007) /* Advanced power management. */
{
cpuid (&unused, &unused, &unused, &features2, 0x80000007);
@@ -1287,7 +1283,7 @@ format_proc_swaps (void *, char *&destbuf)
ssize_t filename_len;
PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
ULONG size = 512;
- NTSTATUS ret = STATUS_SUCCESS;
+ NTSTATUS status = STATUS_SUCCESS;
tmp_pathbuf tp;
char *buf = tp.c_get ();
@@ -1296,39 +1292,41 @@ format_proc_swaps (void *, char *&destbuf)
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
if (spi)
{
- ret = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
- size, &size);
- if (ret == STATUS_INFO_LENGTH_MISMATCH)
+ status = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
+ size, &size);
+ if (status == STATUS_INFO_LENGTH_MISMATCH)
{
free (spi);
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
if (spi)
- ret = NtQuerySystemInformation (SystemPagefileInformation,
- (PVOID) spi, size, &size);
+ status = NtQuerySystemInformation (SystemPagefileInformation,
+ (PVOID) spi, size, &size);
}
}
bufptr += __small_sprintf (bufptr,
"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
- if (spi && !ret && GetLastError () != ERROR_PROC_NOT_FOUND)
+ if (spi && NT_SUCCESS (status))
{
PSYSTEM_PAGEFILE_INFORMATION spp = spi;
do
{
- total = (unsigned long long) spp->CurrentSize * getsystempagesize ();
- used = (unsigned long long) spp->TotalUsed * getsystempagesize ();
+ total = (unsigned long long) spp->CurrentSize * wincap.page_size ();
+ used = (unsigned long long) spp->TotalUsed * wincap.page_size ();
- filename_len = cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer, filename, 0);
+ filename_len = cygwin_conv_path (CCP_WIN_W_TO_POSIX,
+ spp->FileName.Buffer, filename, 0);
filename = (char *) malloc (filename_len);
- cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer, filename, filename_len);
+ cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer,
+ filename, filename_len);
bufptr += sprintf (bufptr, "%-40s%-16s%-8llu%-8llu%-8d\n",
filename, "file", total >> 10, used >> 10, 0);
}
while (spp->NextEntryOffset
&& (spp = (PSYSTEM_PAGEFILE_INFORMATION)
- ((char *) spp + spp->NextEntryOffset)));
+ ((char *) spp + spp->NextEntryOffset)));
}
if (spi)
diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index cefc8f4df..f4fc706f7 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -88,9 +88,8 @@ static bool get_mem_values (DWORD dwProcessId, unsigned long *vmsize,
unsigned long *vmshare);
/* Returns 0 if path doesn't exist, >0 if path is a directory,
- * -1 if path is a file, -2 if path is a symlink, -3 if path is a pipe,
- * -4 if path is a socket.
- */
+ -1 if path is a file, -2 if path is a symlink, -3 if path is a pipe,
+ -4 if path is a socket. */
virtual_ftype_t
fhandler_process::exists ()
{
@@ -1021,10 +1020,10 @@ format_process_maps (void *data, char *&destbuf)
the same allocation base and effective permissions. */
bool newbase = (next.abase != cur.abase);
if (!last_pass && !newbase && next.a.word == cur.a.word)
- cur.rend = next.rend; // merge with previous
+ cur.rend = next.rend; /* merge with previous */
else
{
- // output the current region if it's "interesting"
+ /* output the current region if it's "interesting". */
if (cur.a.word)
{
size_t newlen = strlen (posix_modname) + 62;
@@ -1044,9 +1043,9 @@ format_process_maps (void *data, char *&destbuf)
len += written;
len += __small_sprintf (destbuf + len, "%s\n", posix_modname);
}
- // start of a new region (but possibly still the same allocation)
+ /* start of a new region (but possibly still the same allocation). */
cur = next;
- // if a new allocation, figure out what kind it is
+ /* if a new allocation, figure out what kind it is. */
if (newbase && !last_pass && mb.State != MEM_FREE)
{
/* If the return length pointer is missing, NtQueryVirtualMemory
@@ -1121,10 +1120,8 @@ format_process_stat (void *data, char *&destbuf)
*s = 0;
}
}
- /*
- * Note: under Windows, a _process_ is always running - it's only _threads_
- * that get suspended. Therefore the default state is R (runnable).
- */
+ /* Note: under Windows, a process is always running - it's only threads
+ that get suspended. Therefore the default state is R (runnable). */
if (p->process_state & PID_EXITED)
state = 'Z';
else if (p->process_state & PID_STOPPED)
@@ -1133,7 +1130,7 @@ format_process_stat (void *data, char *&destbuf)
state = get_process_state (p->dwProcessId);
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
- NTSTATUS ret;
+ NTSTATUS status;
HANDLE hProcess;
VM_COUNTERS vmc;
KERNEL_USER_TIMES put;
@@ -1145,25 +1142,17 @@ format_process_stat (void *data, char *&destbuf)
FALSE, p->dwProcessId);
if (hProcess != NULL)
{
- ret = NtQueryInformationProcess (hProcess,
- ProcessVmCounters,
- (PVOID) &vmc,
- sizeof vmc, NULL);
- if (ret == STATUS_SUCCESS)
- ret = NtQueryInformationProcess (hProcess,
- ProcessTimes,
- (PVOID) &put,
- sizeof put, NULL);
- if (ret == STATUS_SUCCESS)
- ret = NtQueryInformationProcess (hProcess,
- ProcessBasicInformation,
- (PVOID) &pbi,
- sizeof pbi, NULL);
- if (ret == STATUS_SUCCESS)
- ret = NtQueryInformationProcess (hProcess,
- ProcessQuotaLimits,
- (PVOID) &ql,
- sizeof ql, NULL);
+ status = NtQueryInformationProcess (hProcess, ProcessVmCounters,
+ (PVOID) &vmc, sizeof vmc, NULL);
+ if (NT_SUCCESS (status))
+ status = NtQueryInformationProcess (hProcess, ProcessTimes,
+ (PVOID) &put, sizeof put, NULL);
+ if (NT_SUCCESS (status))
+ status = NtQueryInformationProcess (hProcess, ProcessBasicInformation,
+ (PVOID) &pbi, sizeof pbi, NULL);
+ if (NT_SUCCESS (status))
+ status = NtQueryInformationProcess (hProcess, ProcessQuotaLimits,
+ (PVOID) &ql, sizeof ql, NULL);
CloseHandle (hProcess);
}
else
@@ -1173,18 +1162,16 @@ format_process_stat (void *data, char *&destbuf)
debug_printf ("OpenProcess: ret %d", error);
return 0;
}
- if (ret == STATUS_SUCCESS)
- ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
- (PVOID) &stodi,
- sizeof stodi, NULL);
- if (ret == STATUS_SUCCESS)
- ret = NtQuerySystemInformation (SystemProcessorTimes,
- (PVOID) &spt,
- sizeof spt, NULL);
- if (ret != STATUS_SUCCESS)
+ if (NT_SUCCESS (status))
+ status = NtQuerySystemInformation (SystemTimeOfDayInformation,
+ (PVOID) &stodi, sizeof stodi, NULL);
+ if (NT_SUCCESS (status))
+ status = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) &spt,
+ sizeof spt, NULL);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
- debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret);
+ __seterrno_from_nt_status (status);
+ debug_printf ("NtQueryInformationProcess: status %p, %E", status);
return 0;
}
fault_count = vmc.PageFaultCount;
@@ -1203,7 +1190,7 @@ format_process_stat (void *data, char *&destbuf)
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
#endif
priority = pbi.BasePriority;
- unsigned page_size = getsystempagesize ();
+ unsigned page_size = wincap.page_size ();
vmsize = vmc.PagefileUsage;
vmrss = vmc.WorkingSetSize / page_size;
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
@@ -1246,10 +1233,8 @@ format_process_status (void *data, char *&destbuf)
if (ascii_strcasematch (s, ".exe"))
*s = 0;
}
- /*
- * Note: under Windows, a _process_ is always running - it's only _threads_
- * that get suspended. Therefore the default state is R (runnable).
- */
+ /* Note: under Windows, a process is always running - it's only threads
+ that get suspended. Therefore the default state is R (runnable). */
if (p->process_state & PID_EXITED)
state = 'Z';
else if (p->process_state & PID_STOPPED)
@@ -1278,12 +1263,12 @@ format_process_status (void *data, char *&destbuf)
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
&vmlib, &vmshare))
return 0;
- unsigned page_size = getsystempagesize ();
+ unsigned page_size = wincap.page_size ();
vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
vmtext *= page_size; vmlib *= page_size;
- // The real uid value for *this* process is stored at cygheap->user.real_uid
- // but we can't get at the real uid value for any other process, so
- // just fake it as p->uid. Similar for p->gid.
+ /* The real uid value for *this* process is stored at cygheap->user.real_uid
+ but we can't get at the real uid value for any other process, so
+ just fake it as p->uid. Similar for p->gid. */
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
return __small_sprintf (destbuf, "Name:\t%s\n"
"State:\t%c (%s)\n"
@@ -1393,29 +1378,36 @@ format_process_mounts (void *data, char *&destbuf)
int
get_process_state (DWORD dwProcessId)
{
- /*
- * This isn't really heavy magic - just go through the processes'
- * threads one by one and return a value accordingly
- * Errors are silently ignored.
- */
- NTSTATUS ret;
- SYSTEM_PROCESSES *sp;
- ULONG n = 0x1000;
- PULONG p = new ULONG[n];
+ /* This isn't really heavy magic - just go through the processes' threads
+ one by one and return a value accordingly. Errors are silently ignored. */
+ NTSTATUS status;
+ PSYSTEM_PROCESSES p, sp;
+ ULONG n = 0x4000;
int state =' ';
- while (STATUS_INFO_LENGTH_MISMATCH ==
- (ret = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
- (PVOID) p,
- n * sizeof *p, NULL)))
- delete [] p, p = new ULONG[n *= 2];
- if (ret != STATUS_SUCCESS)
+
+ p = (PSYSTEM_PROCESSES) malloc (n);
+ if (!p)
+ return state;
+ while (true)
+ {
+ status = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
+ (PVOID) p, n, NULL);
+ if (status != STATUS_INFO_LENGTH_MISMATCH)
+ break;
+ n <<= 1;
+ PSYSTEM_PROCESSES new_p = (PSYSTEM_PROCESSES) realloc (p, n);
+ if (!new_p)
+ goto out;
+ p = new_p;
+ }
+ if (!NT_SUCCESS (status))
{
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
- ret, RtlNtStatusToDosError (ret));
+ debug_printf ("NtQuerySystemInformation: status %p, %lu",
+ status, RtlNtStatusToDosError (status));
goto out;
}
state = 'Z';
- sp = (SYSTEM_PROCESSES *) p;
+ sp = p;
for (;;)
{
if (sp->ProcessId == dwProcessId)
@@ -1438,10 +1430,10 @@ get_process_state (DWORD dwProcessId)
}
if (!sp->NextEntryDelta)
break;
- sp = (SYSTEM_PROCESSES *) ((char *) sp + sp->NextEntryDelta);
+ sp = (PSYSTEM_PROCESSES) ((char *) sp + sp->NextEntryDelta);
}
out:
- delete [] p;
+ free (p);
return state;
}
@@ -1451,15 +1443,16 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
unsigned long *vmlib, unsigned long *vmshare)
{
bool res = false;
- NTSTATUS ret;
+ NTSTATUS status;
HANDLE hProcess;
VM_COUNTERS vmc;
- MEMORY_WORKING_SET_LIST *mwsl;
+ PMEMORY_WORKING_SET_LIST p;
ULONG n = 0x4000, length;
- PMEMORY_WORKING_SET_LIST p = (PMEMORY_WORKING_SET_LIST) malloc (n);
- unsigned page_size = getsystempagesize ();
- hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
- FALSE, dwProcessId);
+
+ p = (PMEMORY_WORKING_SET_LIST) malloc (n);
+ if (!p)
+ return false;
+ hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
if (hProcess == NULL)
{
__seterrno ();
@@ -1468,9 +1461,10 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
}
while (true)
{
- ret = NtQueryVirtualMemory (hProcess, 0, MemoryWorkingSetList,
- (PVOID) p, n, (length = ULONG_MAX, &length));
- if (ret != STATUS_INFO_LENGTH_MISMATCH)
+ status = NtQueryVirtualMemory (hProcess, 0, MemoryWorkingSetList,
+ (PVOID) p, n,
+ (length = ULONG_MAX, &length));
+ if (status != STATUS_INFO_LENGTH_MISMATCH)
break;
n <<= 1;
PMEMORY_WORKING_SET_LIST new_p = (PMEMORY_WORKING_SET_LIST)
@@ -1479,23 +1473,22 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
goto out;
p = new_p;
}
- if (!NT_SUCCESS (ret))
+ if (!NT_SUCCESS (status))
{
- debug_printf ("NtQueryVirtualMemory: ret %p", ret);
- if (ret == STATUS_PROCESS_IS_TERMINATING)
+ debug_printf ("NtQueryVirtualMemory: status %p", status);
+ if (status == STATUS_PROCESS_IS_TERMINATING)
{
*vmsize = *vmrss = *vmtext = *vmdata = *vmlib = *vmshare = 0;
res = true;
}
else
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
goto out;
}
- mwsl = (MEMORY_WORKING_SET_LIST *) p;
- for (unsigned long i = 0; i < mwsl->NumberOfPages; i++)
+ for (unsigned long i = 0; i < p->NumberOfPages; i++)
{
++*vmrss;
- unsigned flags = mwsl->WorkingSetList[i] & 0x0FFF;
+ unsigned flags = p->WorkingSetList[i] & 0x0FFF;
if ((flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
== (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
++*vmlib;
@@ -1506,15 +1499,15 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
else
++*vmdata;
}
- ret = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
- sizeof vmc, NULL);
- if (!NT_SUCCESS (ret))
+ status = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
+ sizeof vmc, NULL);
+ if (!NT_SUCCESS (status))
{
- debug_printf ("NtQueryInformationProcess: ret %p", ret);
- __seterrno_from_nt_status (ret);
+ debug_printf ("NtQueryInformationProcess: status %p", status);
+ __seterrno_from_nt_status (status);
goto out;
}
- *vmsize = vmc.PagefileUsage / page_size;
+ *vmsize = vmc.PagefileUsage / wincap.page_size ();
res = true;
out:
free (p);
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index 6d75a9cea..2a22a4323 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -37,7 +37,7 @@ details. */
/* Stick with 4K pages for bookkeeping, otherwise we just get confused
when trying to do file mappings with trailing filler pages correctly. */
-#define PAGE_CNT(bytes) howmany((bytes),getsystempagesize())
+#define PAGE_CNT(bytes) howmany((bytes), wincap.page_size())
#define PGBITS (sizeof (DWORD)*8)
#define MAPSIZE(pages) howmany ((pages), PGBITS)
@@ -141,7 +141,7 @@ CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
int prot, int flags)
{
HANDLE h;
- NTSTATUS ret;
+ NTSTATUS status;
LARGE_INTEGER sectionsize = { QuadPart: len };
ULONG protect = gen_create_protect (openflags, flags);
@@ -154,8 +154,8 @@ CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
if (fhdl == INVALID_HANDLE_VALUE)
{
/* Standard anonymous mapping needs non-zero len. */
- ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa,
- &sectionsize, protect, attributes, NULL);
+ status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, &sectionsize,
+ protect, attributes, NULL);
}
else if (autogrow (flags))
{
@@ -164,13 +164,13 @@ CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
requested protection is different, we close the mapping and
reopen it again with the correct protection, if auto-grow worked. */
sectionsize.QuadPart += off;
- ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa,
- &sectionsize, PAGE_READWRITE, attributes, fhdl);
- if (NT_SUCCESS (ret) && protect != PAGE_READWRITE)
+ status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, &sectionsize,
+ PAGE_READWRITE, attributes, fhdl);
+ if (NT_SUCCESS (status) && protect != PAGE_READWRITE)
{
NtClose (h);
- ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa,
- &sectionsize, protect, attributes, fhdl);
+ status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, &sectionsize,
+ protect, attributes, fhdl);
}
}
else
@@ -178,13 +178,13 @@ CreateMapping (HANDLE fhdl, size_t len, _off64_t off, DWORD openflags,
/* Zero len creates mapping for whole file and allows
AT_EXTENDABLE_FILE mapping, if we ever use it... */
sectionsize.QuadPart = 0;
- ret = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa,
- &sectionsize, protect, attributes, fhdl);
+ status = NtCreateSection (&h, SECTION_ALL_ACCESS, &oa, &sectionsize,
+ protect, attributes, fhdl);
}
- if (!NT_SUCCESS (ret))
+ if (!NT_SUCCESS (status))
{
h = NULL;
- SetLastError (RtlNtStatusToDosError (ret));
+ SetLastError (RtlNtStatusToDosError (status));
}
return h;
}
@@ -193,7 +193,7 @@ static void *
MapView (HANDLE h, void *addr, size_t len, DWORD openflags,
int prot, int flags, _off64_t off)
{
- NTSTATUS ret;
+ NTSTATUS status;
LARGE_INTEGER offset = { QuadPart:off };
DWORD protect = gen_create_protect (openflags, flags);
void *base = addr;
@@ -208,22 +208,23 @@ MapView (HANDLE h, void *addr, size_t len, DWORD openflags,
Note: Retrying the mapping might be unnecessary, now that mmap64 checks
for a valid memory area first. */
- ret = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
- &offset, &viewsize, ViewShare, alloc_type, protect);
- if (!NT_SUCCESS (ret) && addr && !fixed (flags))
+ status = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
+ &offset, &viewsize, ViewShare, alloc_type,
+ protect);
+ if (!NT_SUCCESS (status) && addr && !fixed (flags))
{
base = NULL;
- ret = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
- &offset, &viewsize, ViewShare, 0, protect);
+ status = NtMapViewOfSection (h, NtCurrentProcess (), &base, 0, commitsize,
+ &offset, &viewsize, ViewShare, 0, protect);
}
- if (!NT_SUCCESS (ret))
+ if (!NT_SUCCESS (status))
{
base = NULL;
- SetLastError (RtlNtStatusToDosError (ret));
+ SetLastError (RtlNtStatusToDosError (status));
}
debug_printf ("%p (status %p) = NtMapViewOfSection (h:%x, addr:%x, len:%u,"
" off:%X, protect:%x, type:%x)",
- base, ret, h, addr, len, off, protect, 0);
+ base, status, h, addr, len, off, protect, 0);
return base;
}
@@ -389,7 +390,7 @@ mmap_record::match (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len)
if (filler ())
high += get_len ();
else
- high += (PAGE_CNT (get_len ()) * getsystempagesize ());
+ high += (PAGE_CNT (get_len ()) * wincap.page_size ());
high = (addr + len < high) ? addr + len : high;
if (low < high)
{
@@ -432,8 +433,8 @@ mmap_record::map_pages (_off64_t off, DWORD len)
if ((off = find_unused_pages (len)) == (DWORD)-1)
return 0L;
if (!noreserve ()
- && !VirtualProtect (get_address () + off * getsystempagesize (),
- len * getsystempagesize (), gen_protect (),
+ && !VirtualProtect (get_address () + off * wincap.page_size (),
+ len * wincap.page_size (), gen_protect (),
&old_prot))
{
__seterrno ();
@@ -442,7 +443,7 @@ mmap_record::map_pages (_off64_t off, DWORD len)
while (len-- > 0)
MAP_SET (off + len);
- return off * getsystempagesize ();
+ return off * wincap.page_size ();
}
bool
@@ -451,7 +452,7 @@ mmap_record::map_pages (caddr_t addr, DWORD len)
debug_printf ("map_pages (addr=%x, len=%u)", addr, len);
DWORD old_prot;
DWORD off = addr - get_address ();
- off /= getsystempagesize ();
+ off /= wincap.page_size ();
len = PAGE_CNT (len);
/* First check if the area is unused right now. */
for (DWORD l = 0; l < len; ++l)
@@ -461,8 +462,8 @@ mmap_record::map_pages (caddr_t addr, DWORD len)
return false;
}
if (!noreserve ()
- && !VirtualProtect (get_address () + off * getsystempagesize (),
- len * getsystempagesize (), gen_protect (),
+ && !VirtualProtect (get_address () + off * wincap.page_size (),
+ len * wincap.page_size (), gen_protect (),
&old_prot))
{
__seterrno ();
@@ -485,7 +486,7 @@ mmap_record::unmap_pages (caddr_t addr, DWORD len)
&old_prot))
debug_printf ("VirtualProtect in unmap_pages () failed, %E");
- off /= getsystempagesize ();
+ off /= wincap.page_size ();
len = PAGE_CNT (len);
for (; len-- > 0; ++off)
MAP_CLR (off);
@@ -502,7 +503,7 @@ mmap_record::access (caddr_t address)
{
if (address < get_address () || address >= get_address () + get_len ())
return 0;
- DWORD off = (address - get_address ()) / getsystempagesize ();
+ DWORD off = (address - get_address ()) / wincap.page_size ();
return MAP_ISSET (off);
}
@@ -716,7 +717,7 @@ mmap_is_attached_or_noreserve (void *addr, size_t len)
LIST_LOCK ();
mmap_list *map_list = mmapped_areas.get_list_by_fd (-1, NULL);
- size_t pagesize = getpagesize ();
+ size_t pagesize = wincap.allocation_granularity ();
caddr_t start_addr = (caddr_t) rounddown ((uintptr_t) addr, pagesize);
len += ((caddr_t) addr - start_addr);
len = roundup2 (len, pagesize);
@@ -803,7 +804,7 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
caddr_t base = NULL;
struct __stat64 st;
- DWORD pagesize = getpagesize ();
+ DWORD pagesize = wincap.allocation_granularity ();
fh_anonymous.set_io_handle (INVALID_HANDLE_VALUE);
fh_anonymous.set_access (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
@@ -966,7 +967,7 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
to get this right. Too bad. */
if (!wincap.is_wow64 ()
&& ((len > fsiz && !autogrow (flags))
- || roundup2 (len, getsystempagesize ())
+ || roundup2 (len, wincap.page_size ())
< roundup2 (len, pagesize)))
orig_len = len;
if (len > fsiz)
@@ -1069,7 +1070,7 @@ go_ahead:
#if 0
orig_len = roundup2 (orig_len, pagesize);
#endif
- len = roundup2 (len, getsystempagesize ());
+ len = roundup2 (len, wincap.page_size ());
if (orig_len - len)
{
orig_len -= len;
@@ -1140,7 +1141,7 @@ munmap (void *addr, size_t len)
set_errno (EINVAL);
return -1;
}
- size_t pagesize = getpagesize ();
+ size_t pagesize = wincap.allocation_granularity ();
if (((uintptr_t) addr % pagesize) || !len)
{
set_errno (EINVAL);
@@ -1204,7 +1205,7 @@ msync (void *addr, size_t len, int flags)
LIST_LOCK ();
- if (((uintptr_t) addr % getpagesize ())
+ if (((uintptr_t) addr % wincap.allocation_granularity ())
|| (flags & ~(MS_ASYNC | MS_SYNC | MS_INVALIDATE))
|| ((flags & (MS_ASYNC | MS_SYNC)) == (MS_ASYNC | MS_SYNC)))
{
@@ -1212,7 +1213,7 @@ msync (void *addr, size_t len, int flags)
goto out;
}
#if 0 /* If I only knew why I did that... */
- len = roundup2 (len, getpagesize ());
+ len = roundup2 (len, wincap.allocation_granularity ());
#endif
/* Iterate through the map, looking for the mmapped area.
@@ -1225,7 +1226,9 @@ msync (void *addr, size_t len, int flags)
if (rec->access ((caddr_t) addr))
{
/* Check whole area given by len. */
- for (DWORD i = getpagesize (); i < len; i += getpagesize ())
+ for (DWORD i = wincap.allocation_granularity ();
+ i < len;
+ i += wincap.allocation_granularity ())
if (!rec->access ((caddr_t) addr + i))
{
set_errno (ENOMEM);
@@ -1261,7 +1264,7 @@ mprotect (void *addr, size_t len, int prot)
syscall_printf ("mprotect (addr: %p, len %u, prot %x)", addr, len, prot);
/* See comment in mmap64 for a description. */
- size_t pagesize = getpagesize ();
+ size_t pagesize = wincap.allocation_granularity ();
if ((uintptr_t) addr % pagesize)
{
set_errno (EINVAL);
@@ -1347,7 +1350,7 @@ mlock (const void *addr, size_t len)
int ret = -1;
/* Align address and length values to page size. */
- size_t pagesize = getpagesize ();
+ size_t pagesize = wincap.allocation_granularity ();
PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize);
ULONG size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len, pagesize);
NTSTATUS status = 0;
@@ -1404,7 +1407,7 @@ munlock (const void *addr, size_t len)
int ret = -1;
/* Align address and length values to page size. */
- size_t pagesize = getpagesize ();
+ size_t pagesize = wincap.allocation_granularity ();
PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize);
ULONG size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len, pagesize);
NTSTATUS status = NtUnlockVirtualMemory (NtCurrentProcess (), &base, &size,
@@ -1708,10 +1711,10 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
section_access = SECTION_MAP_READ;
HANDLE h;
- NTSTATUS ret = NtOpenSection (&h, section_access, &attr);
- if (!NT_SUCCESS (ret))
+ NTSTATUS status = NtOpenSection (&h, section_access, &attr);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
debug_printf ("-1 = mmap(): NtOpenSection failed with %E");
return INVALID_HANDLE_VALUE;
}
@@ -1739,10 +1742,10 @@ fhandler_dev_mem::mmap (caddr_t *addr, size_t len, int prot,
int
fhandler_dev_mem::munmap (HANDLE h, caddr_t addr, size_t len)
{
- NTSTATUS ret;
- if (!NT_SUCCESS (ret = NtUnmapViewOfSection (NtCurrentProcess (), addr)))
+ NTSTATUS status;
+ if (!NT_SUCCESS (status = NtUnmapViewOfSection (NtCurrentProcess (), addr)))
{
- __seterrno_from_nt_status (ret);
+ __seterrno_from_nt_status (status);
return -1;
}
NtClose (h);
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 180e935cf..e6c62e387 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -1323,29 +1323,51 @@ winpids::enum_processes (bool winpid)
if (winpid)
{
static DWORD szprocs;
- static SYSTEM_PROCESSES *procs;
+ static PSYSTEM_PROCESSES procs;
if (!szprocs)
- procs = (SYSTEM_PROCESSES *) malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
+ {
+ procs = (PSYSTEM_PROCESSES)
+ malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
+ if (!procs)
+ {
+ system_printf ("out of memory reading system process "
+ "information");
+ return 0;
+ }
+ }
- NTSTATUS res;
for (;;)
{
- res = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
+ status =
+ NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
procs, szprocs, NULL);
- if (res == 0)
+ if (NT_SUCCESS (status))
break;
- if (res == STATUS_INFO_LENGTH_MISMATCH)
- procs = (SYSTEM_PROCESSES *) realloc (procs, szprocs += 200 * sizeof (*procs));
+ if (status == STATUS_INFO_LENGTH_MISMATCH)
+ {
+ PSYSTEM_PROCESSES new_p;
+
+ new_p = (PSYSTEM_PROCESSES)
+ realloc (procs, szprocs += 200 * sizeof (*procs));
+ if (!new_p)
+ {
+ system_printf ("out of memory reading system process "
+ "information");
+ return 0;
+ }
+ procs = new_p;
+ }
else
{
- system_printf ("error %p reading system process information", res);
+ system_printf ("error %p reading system process information",
+ status);
return 0;
}
}
- SYSTEM_PROCESSES *px = procs;
+ PSYSTEM_PROCESSES px = procs;
for (;;)
{
if (px->ProcessId)
@@ -1362,7 +1384,7 @@ winpids::enum_processes (bool winpid)
}
if (!px->NextEntryDelta)
break;
- px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
+ px = (PSYSTEM_PROCESSES) ((char *) px + px->NextEntryDelta);
}
}
diff --git a/winsup/cygwin/sec_auth.cc b/winsup/cygwin/sec_auth.cc
index d4261ff01..26f276b84 100644
--- a/winsup/cygwin/sec_auth.cc
+++ b/winsup/cygwin/sec_auth.cc
@@ -592,7 +592,6 @@ get_priv_list (LSA_HANDLE lsa, cygsid &usersid, cygsidlist &grp_list,
PLSA_UNICODE_STRING privstrs;
ULONG cnt;
PTOKEN_PRIVILEGES privs = NULL;
- NTSTATUS ret;
if (usersid == well_known_system_sid)
{
@@ -608,13 +607,12 @@ get_priv_list (LSA_HANDLE lsa, cygsid &usersid, cygsidlist &grp_list,
{
if (grp == -1)
{
- if ((ret = LsaEnumerateAccountRights (lsa, usersid, &privstrs,
- &cnt)) != STATUS_SUCCESS)
+ if (LsaEnumerateAccountRights (lsa, usersid, &privstrs, &cnt)
+ != STATUS_SUCCESS)
continue;
}
- else if ((ret = LsaEnumerateAccountRights (lsa, grp_list.sids[grp],
- &privstrs, &cnt))
- != STATUS_SUCCESS)
+ else if (LsaEnumerateAccountRights (lsa, grp_list.sids[grp],
+ &privstrs, &cnt) != STATUS_SUCCESS)
continue;
for (ULONG i = 0; i < cnt; ++i)
{
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 0f1be92af..e9f461338 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -436,8 +436,6 @@ shared_info::initialize ()
void
memory_init (bool init_cygheap)
{
- getpagesize ();
-
/* Initialize the Cygwin heap, if necessary */
if (init_cygheap)
{
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index e96116e84..6d46dd7a4 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2447,12 +2447,6 @@ getpagesize ()
return (size_t) wincap.allocation_granularity ();
}
-size_t
-getsystempagesize ()
-{
- return (size_t) wincap.page_size ();
-}
-
/* FIXME: not all values are correct... */
extern "C" long int
fpathconf (int fd, int v)
diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc
index f691b4568..f5bfe60d1 100644
--- a/winsup/cygwin/sysconf.cc
+++ b/winsup/cygwin/sysconf.cc
@@ -32,20 +32,21 @@ get_open_max (int in)
static long
get_page_size (int in)
{
- return getpagesize ();
+ return wincap.allocation_granularity ();
}
static long
get_nproc_values (int in)
{
- NTSTATUS ret;
+ NTSTATUS status;
SYSTEM_BASIC_INFORMATION sbi;
- if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
- sizeof sbi, NULL)) != STATUS_SUCCESS)
+
+ status = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
+ sizeof sbi, NULL);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
- ret);
+ __seterrno_from_nt_status (status);
+ debug_printf ("NtQuerySystemInformation: status %p, %E", status);
return -1;
}
switch (in)
@@ -63,7 +64,7 @@ get_nproc_values (int in)
}
case _SC_PHYS_PAGES:
return sbi.NumberOfPhysicalPages
- / (getpagesize () / getsystempagesize ());
+ / (wincap.allocation_granularity () / wincap.page_size ());
}
return -1;
}
@@ -71,18 +72,19 @@ get_nproc_values (int in)
static long
get_avphys (int in)
{
- NTSTATUS ret;
+ NTSTATUS status;
SYSTEM_PERFORMANCE_INFORMATION spi;
- if ((ret = NtQuerySystemInformation (SystemPerformanceInformation,
- (PVOID) &spi, sizeof spi, NULL))
- != STATUS_SUCCESS)
+
+ status = NtQuerySystemInformation (SystemPerformanceInformation,
+ (PVOID) &spi, sizeof spi, NULL);
+ if (!NT_SUCCESS (status))
{
- __seterrno_from_nt_status (ret);
- debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %E",
- ret);
+ __seterrno_from_nt_status (status);
+ debug_printf ("NtQuerySystemInformation: status %d, %E", status);
return -1;
}
- return spi.AvailablePages / (getpagesize () / getsystempagesize ());
+ return spi.AvailablePages
+ / (wincap.allocation_granularity () / wincap.page_size ());
}
enum sc_type { nsup, cons, func };
@@ -334,8 +336,8 @@ sysinfo (struct sysinfo *info)
PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
ULONG sizeof_spi = 512;
PSYSTEM_TIME_OF_DAY_INFORMATION stodi = NULL;
- ULONG sizeof_stodi = sizeof (SYSTEM_TIME_OF_DAY_INFORMATION);
- NTSTATUS ret = STATUS_SUCCESS;
+ const ULONG sizeof_stodi = sizeof (SYSTEM_TIME_OF_DAY_INFORMATION);
+ NTSTATUS status = STATUS_SUCCESS;
winpids pids ((DWORD) 0);
if (!info)
@@ -345,46 +347,46 @@ sysinfo (struct sysinfo *info)
}
stodi = (PSYSTEM_TIME_OF_DAY_INFORMATION) malloc (sizeof_stodi);
- ret = NtQuerySystemInformation (SystemTimeOfDayInformation, (PVOID) stodi,
- sizeof_stodi, NULL);
- if (NT_SUCCESS (ret))
- uptime = (stodi->CurrentTime.QuadPart - stodi->BootTime.QuadPart) / 10000000ULL;
+ status = NtQuerySystemInformation (SystemTimeOfDayInformation, (PVOID) stodi,
+ sizeof_stodi, NULL);
+ if (NT_SUCCESS (status))
+ uptime = (stodi->CurrentTime.QuadPart - stodi->BootTime.QuadPart)
+ / 10000000ULL;
else
- {
- debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
- "status %p", ret);
- }
+ debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
+ "status %p", status);
if (stodi)
free (stodi);
memory_status.dwLength = sizeof (MEMORYSTATUSEX);
GlobalMemoryStatusEx (&memory_status);
- totalram = memory_status.ullTotalPhys / getsystempagesize ();
- freeram = memory_status.ullAvailPhys / getsystempagesize ();
+ totalram = memory_status.ullTotalPhys / wincap.page_size ();
+ freeram = memory_status.ullAvailPhys / wincap.page_size ();
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (sizeof_spi);
if (spi)
{
- ret = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
- sizeof_spi, &sizeof_spi);
- if (ret == STATUS_INFO_LENGTH_MISMATCH)
+ status = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
+ sizeof_spi, &sizeof_spi);
+ if (status == STATUS_INFO_LENGTH_MISMATCH)
{
free (spi);
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (sizeof_spi);
if (spi)
- ret = NtQuerySystemInformation (SystemPagefileInformation,
- (PVOID) spi, sizeof_spi, &sizeof_spi);
+ status = NtQuerySystemInformation (SystemPagefileInformation,
+ (PVOID) spi, sizeof_spi,
+ &sizeof_spi);
}
}
- if (!spi || ret || (!ret && GetLastError () == ERROR_PROC_NOT_FOUND))
+ if (!spi || !NT_SUCCESS (status))
{
debug_printf ("NtQuerySystemInformation(SystemPagefileInformation), "
- "status %p", ret);
+ "status %p", status);
totalswap = (memory_status.ullTotalPageFile - memory_status.ullTotalPhys)
- / getsystempagesize ();
+ / wincap.page_size ();
freeswap = (memory_status.ullAvailPageFile - memory_status.ullTotalPhys)
- / getsystempagesize ();
+ / wincap.page_size ();
}
else
{
@@ -407,7 +409,7 @@ sysinfo (struct sysinfo *info)
info->totalswap = (unsigned long) totalswap;
info->freeswap = (unsigned long) freeswap;
info->procs = (unsigned short) pids.npids;
- info->mem_unit = (unsigned int) getsystempagesize ();
+ info->mem_unit = (unsigned int) wincap.page_size ();
/* FIXME: unsupported */
info->loads[0] = 0UL;
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 52bca9839..1edd566fb 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -2509,7 +2509,7 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
{
const size_t sizeof_tbi = sizeof (THREAD_BASIC_INFORMATION);
PTHREAD_BASIC_INFORMATION tbi;
- NTSTATUS ret;
+ NTSTATUS status;
if (!pthread::is_good_object (&thread))
return ESRCH;
@@ -2529,20 +2529,21 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
(*attr)->guardsize = thread->attr.guardsize;
tbi = (PTHREAD_BASIC_INFORMATION) malloc (sizeof_tbi);
- ret = NtQueryInformationThread (thread->win32_obj_id, ThreadBasicInformation,
- tbi, sizeof_tbi, NULL);
-
- if (NT_SUCCESS (ret))
+ status = NtQueryInformationThread (thread->win32_obj_id,
+ ThreadBasicInformation,
+ tbi, sizeof_tbi, NULL);
+ if (NT_SUCCESS (status))
{
PNT_TIB tib = tbi->TebBaseAddress;
(*attr)->stackaddr = tib->StackBase;
/* stack grows downwards on x86 systems */
- (*attr)->stacksize = (int)tib->StackBase - (int)tib->StackLimit;
+ (*attr)->stacksize = (uintptr_t) tib->StackBase
+ - (uintptr_t) tib->StackLimit;
}
else
{
debug_printf ("NtQueryInformationThread(ThreadBasicInformation), "
- "status %p", ret);
+ "status %p", status);
(*attr)->stackaddr = thread->attr.stackaddr;
(*attr)->stacksize = thread->attr.stacksize;
}
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index 13f2b6d46..c2f015148 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -257,9 +257,6 @@ int __stdcall stat_worker (path_conv &pc, struct __stat64 *buf) __attribute__ ((
__ino64_t __stdcall readdir_get_ino (const char *path, bool dot_dot) __attribute__ ((regparm (2)));
-/* Returns the real page size, not the allocation size. */
-size_t getsystempagesize ();
-
/* mmap functions. */
enum mmap_region_status
{