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:
authorChristopher Faylor <me@cgf.cx>2005-08-24 08:38:39 +0400
committerChristopher Faylor <me@cgf.cx>2005-08-24 08:38:39 +0400
commit14c4d65ef1240b1c18db06c3030b4e0830b0c701 (patch)
tree0a651de83d4520bb1c08dd334792733560733975 /winsup/cygwin/fhandler_process.cc
parentdb7f135b03afa5f8ee870f87d1727d69dade30ce (diff)
* cygheap.h (cygheap_types): Add HEAP_COMMUNE.
* fhandler_proc.cc: Use cygheap rather than user heap for allocation of filebuf throughout. * fhandler_registry.cc: Ditto. * fhandler_virtual.cc: Ditto. * fhandler_process.cc: Ditto. (get_mem_values): Use malloc/realloc/free rather than new. * pinfo.cc (_pinfo::commune_send): Allocate on cygwin heap rather than user heap. Avoid calling ReadFile when correct number of characters have been read or suffer buffer corruption. (_pinfo::fd): Allocate on cygwin heap rather than user heap. (_pinfo::fds): Ditto. (_pinfo::root): Ditto. (_pinfo::cwd): Ditto. (_pinfo::cmdline): Ditto. * devices.h (FH_DEV): New define. * devices.in: Detect lone /dev. * devices.cc: Regenerate. * path.cc (path_conv::check): Treat FH_DEV as a special case.
Diffstat (limited to 'winsup/cygwin/fhandler_process.cc')
-rw-r--r--winsup/cygwin/fhandler_process.cc50
1 files changed, 26 insertions, 24 deletions
diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index 1585c2fea..09af49708 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -351,13 +351,13 @@ fhandler_process::fill_filebuf ()
if (!fdp || *++fdp == 'f') /* The "fd" directory itself. */
{
if (filebuf)
- free (filebuf);
+ cfree (filebuf);
filebuf = p->fds (fs);
}
else
{
if (filebuf)
- free (filebuf);
+ cfree (filebuf);
int fd = atoi (fdp);
if (fd < 0 || (fd == 0 && !isdigit (*fdp)))
{
@@ -381,7 +381,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_CTTY:
case PROCESS_PPID:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 40);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 40);
int num;
switch (fileid)
{
@@ -416,7 +416,10 @@ fhandler_process::fill_filebuf ()
case PROCESS_CMDLINE:
{
if (filebuf)
- free (filebuf);
+ {
+ cfree (filebuf);
+ filebuf = NULL;
+ }
size_t fs;
switch (fileid)
{
@@ -433,7 +436,7 @@ fhandler_process::fill_filebuf ()
filesize = fs;
if (!filebuf || !*filebuf)
{
- filebuf = strdup ("<defunct>");
+ filebuf = cstrdup ("<defunct>");
filesize = strlen (filebuf) + 1;
}
break;
@@ -441,7 +444,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_EXENAME:
case PROCESS_EXE:
{
- filebuf = (char *) realloc (filebuf, bufalloc = CYG_MAX_PATH);
+ filebuf = (char *) crealloc (filebuf, bufalloc = CYG_MAX_PATH);
if (p->process_state & PID_EXITED)
strcpy (filebuf, "<defunct>");
else
@@ -460,7 +463,7 @@ fhandler_process::fill_filebuf ()
}
case PROCESS_WINPID:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 40);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 40);
__small_sprintf (filebuf, "%d\n", p->dwProcessId);
filesize = strlen (filebuf);
break;
@@ -468,7 +471,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_WINEXENAME:
{
int len = strlen (p->progname);
- filebuf = (char *) realloc (filebuf, bufalloc = (len + 2));
+ filebuf = (char *) crealloc (filebuf, bufalloc = (len + 2));
strcpy (filebuf, p->progname);
filebuf[len] = '\n';
filesize = len + 1;
@@ -476,25 +479,25 @@ fhandler_process::fill_filebuf ()
}
case PROCESS_STATUS:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 2048);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_status (*p, filebuf, bufalloc);
break;
}
case PROCESS_STAT:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 2048);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_stat (*p, filebuf, bufalloc);
break;
}
case PROCESS_STATM:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 2048);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_statm (*p, filebuf, bufalloc);
break;
}
case PROCESS_MAPS:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 2048);
+ filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_maps (*p, filebuf, bufalloc);
break;
}
@@ -560,7 +563,7 @@ format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize)
st.st_ino = 0;
}
if (len + strlen (posix_modname) + 62 > maxsize - 1)
- destbuf = (char *) realloc (destbuf, maxsize += 2048);
+ destbuf = (char *) crealloc (destbuf, maxsize += 2048);
if (workingset)
for (unsigned i = 1; i <= wset_size; ++i)
{
@@ -914,7 +917,7 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
VM_COUNTERS vmc;
MEMORY_WORKING_SET_LIST *mwsl;
ULONG n = 0x1000, length;
- PULONG p = new ULONG[n];
+ PULONG p = (PULONG) malloc (sizeof (ULONG) * n);
unsigned page_size = getpagesize ();
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
FALSE, dwProcessId);
@@ -930,8 +933,9 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
(PVOID) p,
n * sizeof *p, &length)),
(ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) &&
- length >= n * sizeof *p)
- delete [] p, p = new ULONG[n *= 2];
+ length >= (n * sizeof (*p)))
+ p = (PULONG) realloc (p, n *= (2 * sizeof (ULONG)));
+
if (ret != STATUS_SUCCESS)
{
debug_printf ("NtQueryVirtualMemory: ret %d, Dos(ret) %d",
@@ -945,17 +949,15 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
++*vmrss;
unsigned flags = mwsl->WorkingSetList[i] & 0x0FFF;
if (flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE) == (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
- ++*vmlib;
+ ++*vmlib;
else if (flags & WSLE_PAGE_SHAREABLE)
- ++*vmshare;
+ ++*vmshare;
else if (flags & WSLE_PAGE_EXECUTE)
- ++*vmtext;
+ ++*vmtext;
else
- ++*vmdata;
+ ++*vmdata;
}
- ret = NtQueryInformationProcess (hProcess,
- ProcessVmCounters,
- (PVOID) &vmc,
+ ret = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
sizeof vmc, NULL);
if (ret != STATUS_SUCCESS)
{
@@ -966,7 +968,7 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
}
*vmsize = vmc.PagefileUsage / page_size;
out:
- delete [] p;
+ free (p);
CloseHandle (hProcess);
return res;
}