* 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.
This commit is contained in:
Christopher Faylor 2005-08-24 04:38:39 +00:00
parent db7f135b03
commit 14c4d65ef1
11 changed files with 954 additions and 891 deletions

View File

@ -1,3 +1,26 @@
2005-08-24 Christopher Faylor <cgf@timesys.com>
* 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.
2005-08-23 Christopher Faylor <cgf@timesys.com> 2005-08-23 Christopher Faylor <cgf@timesys.com>
* sigproc.h (set_signal_mask): Remove default on second parameter and * sigproc.h (set_signal_mask): Remove default on second parameter and

View File

@ -20,6 +20,7 @@ enum cygheap_types
HEAP_SIGS, HEAP_SIGS,
HEAP_ARCHETYPES, HEAP_ARCHETYPES,
HEAP_TLS, HEAP_TLS,
HEAP_COMMUNE,
HEAP_1_START, HEAP_1_START,
HEAP_1_HOOK, HEAP_1_HOOK,
HEAP_1_STR, HEAP_1_STR,

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,7 @@ enum fh_devices
FH_FS = FHDEV (0, 247), /* filesystem based device */ FH_FS = FHDEV (0, 247), /* filesystem based device */
FH_NETDRIVE= FHDEV (0, 246), FH_NETDRIVE= FHDEV (0, 246),
FH_DEV = FHDEV (0, 245),
DEV_FLOPPY_MAJOR = 2, DEV_FLOPPY_MAJOR = 2,
FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0), FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0),

View File

@ -24,6 +24,11 @@ const device dev_proc_storage =
const device dev_netdrive_storage = const device dev_netdrive_storage =
{"", {FH_NETDRIVE}, ""}; {"", {FH_NETDRIVE}, ""};
#if 0
const device dev_dev_storage =
{"/dev", {FH_DEV}, "/dev"};
#endif
const device dev_registry_storage = const device dev_registry_storage =
{"", {FH_REGISTRY}, ""}; {"", {FH_REGISTRY}, ""};
@ -82,6 +87,7 @@ const device dev_bad_storage =
"/dev/sd%{a-z}s", BRACK(FH_SD{uc $1}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition0" "/dev/sd%{a-z}s", BRACK(FH_SD{uc $1}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition0"
"/dev/sd%{a-z}s%(1-15)d", BRACK(FH_SD{uc $1} | {$2}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition{$2 % 16}" "/dev/sd%{a-z}s%(1-15)d", BRACK(FH_SD{uc $1} | {$2}), "\\Device\\Harddisk{ord($1) - ord('a')}\\Partition{$2 % 16}"
"/dev/kmsg", BRACK(FH_KMSG), "\\\\.\\mailslot\\cygwin\\dev\\kmsg" "/dev/kmsg", BRACK(FH_KMSG), "\\\\.\\mailslot\\cygwin\\dev\\kmsg"
"/dev", BRACK(FH_DEV), "/dev"
%other {return NULL;} %other {return NULL;}
%% %%
#undef BRACK #undef BRACK

View File

@ -342,7 +342,7 @@ fhandler_proc::fill_filebuf ()
uname (&uts_name); uname (&uts_name);
bufalloc = strlen (uts_name.sysname) + 1 + strlen (uts_name.release) + bufalloc = strlen (uts_name.sysname) + 1 + strlen (uts_name.release) +
1 + strlen (uts_name.version) + 2; 1 + strlen (uts_name.version) + 2;
filebuf = (char *) realloc (filebuf, bufalloc); filebuf = (char *) crealloc (filebuf, bufalloc);
filesize = __small_sprintf (filebuf, "%s %s %s\n", uts_name.sysname, filesize = __small_sprintf (filebuf, "%s %s %s\n", uts_name.sysname,
uts_name.release, uts_name.version); uts_name.release, uts_name.version);
} }
@ -350,13 +350,13 @@ fhandler_proc::fill_filebuf ()
} }
case PROC_UPTIME: case PROC_UPTIME:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 80); filebuf = (char *) crealloc (filebuf, bufalloc = 80);
filesize = format_proc_uptime (filebuf, bufalloc); filesize = format_proc_uptime (filebuf, bufalloc);
break; break;
} }
case PROC_STAT: case PROC_STAT:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 16384); filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
filesize = format_proc_stat (filebuf, bufalloc); filesize = format_proc_stat (filebuf, bufalloc);
break; break;
} }
@ -367,32 +367,32 @@ fhandler_proc::fill_filebuf ()
* Windows 95/98/me does have the KERNEL/CPUUsage performance counter * Windows 95/98/me does have the KERNEL/CPUUsage performance counter
* which is similar. * which is similar.
*/ */
filebuf = (char *) realloc (filebuf, bufalloc = 16); filebuf = (char *) crealloc (filebuf, bufalloc = 16);
filesize = __small_sprintf (filebuf, "%u.%02u %u.%02u %u.%02u\n", filesize = __small_sprintf (filebuf, "%u.%02u %u.%02u %u.%02u\n",
0, 0, 0, 0, 0, 0); 0, 0, 0, 0, 0, 0);
break; break;
} }
case PROC_MEMINFO: case PROC_MEMINFO:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 2048); filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_proc_meminfo (filebuf, bufalloc); filesize = format_proc_meminfo (filebuf, bufalloc);
break; break;
} }
case PROC_CPUINFO: case PROC_CPUINFO:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 16384); filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
filesize = format_proc_cpuinfo (filebuf, bufalloc); filesize = format_proc_cpuinfo (filebuf, bufalloc);
break; break;
} }
case PROC_PARTITIONS: case PROC_PARTITIONS:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 4096); filebuf = (char *) crealloc (filebuf, bufalloc = 4096);
filesize = format_proc_partitions (filebuf, bufalloc); filesize = format_proc_partitions (filebuf, bufalloc);
break; break;
} }
case PROC_SELF: case PROC_SELF:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 32); filebuf = (char *) crealloc (filebuf, bufalloc = 32);
filesize = __small_sprintf (filebuf, "%d", getpid ()); filesize = __small_sprintf (filebuf, "%d", getpid ());
} }
} }

View File

@ -351,13 +351,13 @@ fhandler_process::fill_filebuf ()
if (!fdp || *++fdp == 'f') /* The "fd" directory itself. */ if (!fdp || *++fdp == 'f') /* The "fd" directory itself. */
{ {
if (filebuf) if (filebuf)
free (filebuf); cfree (filebuf);
filebuf = p->fds (fs); filebuf = p->fds (fs);
} }
else else
{ {
if (filebuf) if (filebuf)
free (filebuf); cfree (filebuf);
int fd = atoi (fdp); int fd = atoi (fdp);
if (fd < 0 || (fd == 0 && !isdigit (*fdp))) if (fd < 0 || (fd == 0 && !isdigit (*fdp)))
{ {
@ -381,7 +381,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_CTTY: case PROCESS_CTTY:
case PROCESS_PPID: case PROCESS_PPID:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 40); filebuf = (char *) crealloc (filebuf, bufalloc = 40);
int num; int num;
switch (fileid) switch (fileid)
{ {
@ -416,7 +416,10 @@ fhandler_process::fill_filebuf ()
case PROCESS_CMDLINE: case PROCESS_CMDLINE:
{ {
if (filebuf) if (filebuf)
free (filebuf); {
cfree (filebuf);
filebuf = NULL;
}
size_t fs; size_t fs;
switch (fileid) switch (fileid)
{ {
@ -433,7 +436,7 @@ fhandler_process::fill_filebuf ()
filesize = fs; filesize = fs;
if (!filebuf || !*filebuf) if (!filebuf || !*filebuf)
{ {
filebuf = strdup ("<defunct>"); filebuf = cstrdup ("<defunct>");
filesize = strlen (filebuf) + 1; filesize = strlen (filebuf) + 1;
} }
break; break;
@ -441,7 +444,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_EXENAME: case PROCESS_EXENAME:
case PROCESS_EXE: 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) if (p->process_state & PID_EXITED)
strcpy (filebuf, "<defunct>"); strcpy (filebuf, "<defunct>");
else else
@ -460,7 +463,7 @@ fhandler_process::fill_filebuf ()
} }
case PROCESS_WINPID: case PROCESS_WINPID:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 40); filebuf = (char *) crealloc (filebuf, bufalloc = 40);
__small_sprintf (filebuf, "%d\n", p->dwProcessId); __small_sprintf (filebuf, "%d\n", p->dwProcessId);
filesize = strlen (filebuf); filesize = strlen (filebuf);
break; break;
@ -468,7 +471,7 @@ fhandler_process::fill_filebuf ()
case PROCESS_WINEXENAME: case PROCESS_WINEXENAME:
{ {
int len = strlen (p->progname); int len = strlen (p->progname);
filebuf = (char *) realloc (filebuf, bufalloc = (len + 2)); filebuf = (char *) crealloc (filebuf, bufalloc = (len + 2));
strcpy (filebuf, p->progname); strcpy (filebuf, p->progname);
filebuf[len] = '\n'; filebuf[len] = '\n';
filesize = len + 1; filesize = len + 1;
@ -476,25 +479,25 @@ fhandler_process::fill_filebuf ()
} }
case PROCESS_STATUS: case PROCESS_STATUS:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 2048); filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_status (*p, filebuf, bufalloc); filesize = format_process_status (*p, filebuf, bufalloc);
break; break;
} }
case PROCESS_STAT: case PROCESS_STAT:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 2048); filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_stat (*p, filebuf, bufalloc); filesize = format_process_stat (*p, filebuf, bufalloc);
break; break;
} }
case PROCESS_STATM: case PROCESS_STATM:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 2048); filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_statm (*p, filebuf, bufalloc); filesize = format_process_statm (*p, filebuf, bufalloc);
break; break;
} }
case PROCESS_MAPS: case PROCESS_MAPS:
{ {
filebuf = (char *) realloc (filebuf, bufalloc = 2048); filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_process_maps (*p, filebuf, bufalloc); filesize = format_process_maps (*p, filebuf, bufalloc);
break; break;
} }
@ -560,7 +563,7 @@ format_process_maps (_pinfo *p, char *&destbuf, size_t maxsize)
st.st_ino = 0; st.st_ino = 0;
} }
if (len + strlen (posix_modname) + 62 > maxsize - 1) if (len + strlen (posix_modname) + 62 > maxsize - 1)
destbuf = (char *) realloc (destbuf, maxsize += 2048); destbuf = (char *) crealloc (destbuf, maxsize += 2048);
if (workingset) if (workingset)
for (unsigned i = 1; i <= wset_size; ++i) 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; VM_COUNTERS vmc;
MEMORY_WORKING_SET_LIST *mwsl; MEMORY_WORKING_SET_LIST *mwsl;
ULONG n = 0x1000, length; ULONG n = 0x1000, length;
PULONG p = new ULONG[n]; PULONG p = (PULONG) malloc (sizeof (ULONG) * n);
unsigned page_size = getpagesize (); unsigned page_size = getpagesize ();
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
FALSE, dwProcessId); FALSE, dwProcessId);
@ -930,8 +933,9 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
(PVOID) p, (PVOID) p,
n * sizeof *p, &length)), n * sizeof *p, &length)),
(ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) && (ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) &&
length >= n * sizeof *p) length >= (n * sizeof (*p)))
delete [] p, p = new ULONG[n *= 2]; p = (PULONG) realloc (p, n *= (2 * sizeof (ULONG)));
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
debug_printf ("NtQueryVirtualMemory: ret %d, Dos(ret) %d", debug_printf ("NtQueryVirtualMemory: ret %d, Dos(ret) %d",
@ -953,9 +957,7 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
else else
++*vmdata; ++*vmdata;
} }
ret = NtQueryInformationProcess (hProcess, ret = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
ProcessVmCounters,
(PVOID) &vmc,
sizeof vmc, NULL); sizeof vmc, NULL);
if (ret != STATUS_SUCCESS) if (ret != STATUS_SUCCESS)
{ {
@ -966,7 +968,7 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
} }
*vmsize = vmc.PagefileUsage / page_size; *vmsize = vmc.PagefileUsage / page_size;
out: out:
delete [] p; free (p);
CloseHandle (hProcess); CloseHandle (hProcess);
return res; return res;
} }

View File

@ -539,7 +539,10 @@ fhandler_registry::close ()
} }
} }
if (!hExeced && value_name) if (!hExeced && value_name)
{
cfree (value_name); cfree (value_name);
value_name = NULL;
}
return res; return res;
} }
@ -562,7 +565,7 @@ fhandler_registry::fill_filebuf ()
goto value_not_found; goto value_not_found;
} }
bufalloc = size; bufalloc = size;
filebuf = (char *) malloc (bufalloc); filebuf = (char *) cmalloc (HEAP_BUF, bufalloc);
error = error =
RegQueryValueEx (handle, value_name, NULL, NULL, (BYTE *) filebuf, RegQueryValueEx (handle, value_name, NULL, NULL, (BYTE *) filebuf,
&size); &size);
@ -579,7 +582,7 @@ fhandler_registry::fill_filebuf ()
do do
{ {
bufalloc += 1000; bufalloc += 1000;
filebuf = (char *) realloc (filebuf, bufalloc); filebuf = (char *) crealloc (filebuf, bufalloc);
size = bufalloc; size = bufalloc;
error = RegQueryValueEx (handle, value_name, NULL, &type, error = RegQueryValueEx (handle, value_name, NULL, &type,
(BYTE *) filebuf, &size); (BYTE *) filebuf, &size);

View File

@ -33,14 +33,15 @@ fhandler_virtual::fhandler_virtual ():
fhandler_virtual::~fhandler_virtual () fhandler_virtual::~fhandler_virtual ()
{ {
if (filebuf) if (filebuf)
free (filebuf); {
cfree (filebuf);
filebuf = NULL; filebuf = NULL;
}
} }
void void
fhandler_virtual::fixup_after_exec () fhandler_virtual::fixup_after_exec ()
{ {
close ();
} }
DIR * DIR *
@ -154,7 +155,7 @@ fhandler_virtual::dup (fhandler_base * child)
if (!ret) if (!ret)
{ {
fhandler_virtual *fhproc_child = (fhandler_virtual *) child; fhandler_virtual *fhproc_child = (fhandler_virtual *) child;
fhproc_child->filebuf = (char *) malloc (filesize); fhproc_child->filebuf = (char *) cmalloc (HEAP_BUF, filesize);
fhproc_child->bufalloc = fhproc_child->filesize = filesize; fhproc_child->bufalloc = fhproc_child->filesize = filesize;
fhproc_child->position = position; fhproc_child->position = position;
memcpy (fhproc_child->filebuf, filebuf, filesize); memcpy (fhproc_child->filebuf, filebuf, filesize);
@ -168,8 +169,7 @@ fhandler_virtual::close ()
{ {
if (!hExeced) if (!hExeced)
{ {
if (filebuf) cfree (filebuf);
free (filebuf);
filebuf = NULL; filebuf = NULL;
bufalloc = (size_t) -1; bufalloc = (size_t) -1;
} }

View File

@ -634,11 +634,17 @@ path_conv::check (const char *src, unsigned opt,
fileattr = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY; fileattr = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY;
else else
{ {
dev.devn = FH_FS;
fileattr = GetFileAttributes (this->path); fileattr = GetFileAttributes (this->path);
dev.devn = FH_FS;
} }
goto out; goto out;
} }
else if (dev == FH_DEV)
{
fileattr = FILE_ATTRIBUTE_DIRECTORY;
dev.devn = FH_FS;
goto out;
}
else if (isvirtual_dev (dev.devn)) else if (isvirtual_dev (dev.devn))
{ {
/* FIXME: Calling build_fhandler here is not the right way to handle this. */ /* FIXME: Calling build_fhandler here is not the right way to handle this. */

View File

@ -727,9 +727,9 @@ _pinfo::commune_send (DWORD code, ...)
res.s = NULL; res.s = NULL;
else else
{ {
res.s = (char *) malloc (n); res.s = (char *) cmalloc (HEAP_COMMUNE, n);
char *p; char *p;
for (p = res.s; ReadFile (fromthem, p, n, &nr, NULL); p += nr) for (p = res.s; n && ReadFile (fromthem, p, n, &nr, NULL); p += nr, n -= nr)
continue; continue;
if ((unsigned) (p - res.s) != n) if ((unsigned) (p - res.s) != n)
{ {
@ -817,9 +817,9 @@ _pinfo::fd (int fd, size_t &n)
{ {
cygheap_fdget cfd (fd); cygheap_fdget cfd (fd);
if (cfd < 0) if (cfd < 0)
s = strdup (""); s = cstrdup ("");
else else
s = cfd->get_proc_fd_name ((char *) malloc (CYG_MAX_PATH)); s = cfd->get_proc_fd_name ((char *) cmalloc (HEAP_COMMUNE, CYG_MAX_PATH));
n = strlen (s) + 1; n = strlen (s) + 1;
} }
return s; return s;
@ -845,7 +845,7 @@ _pinfo::fds (size_t &n)
while ((fd = cfd.next ()) >= 0) while ((fd = cfd.next ()) >= 0)
n += sizeof (int); n += sizeof (int);
cfd.rewind (); cfd.rewind ();
s = (char *) malloc (n); s = (char *) cmalloc (HEAP_COMMUNE, n);
int *p = (int *) s; int *p = (int *) s;
while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n) while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n)
*p++ = fd; *p++ = fd;
@ -868,9 +868,9 @@ _pinfo::root (size_t& n)
else else
{ {
if (cygheap->root.exists ()) if (cygheap->root.exists ())
s = strdup (cygheap->root.posix_path ()); s = cstrdup (cygheap->root.posix_path ());
else else
s = strdup ("/"); s = cstrdup ("/");
n = strlen (s) + 1; n = strlen (s) + 1;
} }
return s; return s;
@ -890,7 +890,7 @@ _pinfo::cwd (size_t& n)
} }
else else
{ {
s = (char *) malloc (CYG_MAX_PATH); s = (char *) cmalloc (HEAP_COMMUNE, CYG_MAX_PATH);
cygheap->cwd.get (s, 1, 1, CYG_MAX_PATH); cygheap->cwd.get (s, 1, 1, CYG_MAX_PATH);
n = strlen (s) + 1; n = strlen (s) + 1;
} }
@ -915,7 +915,7 @@ _pinfo::cmdline (size_t& n)
for (char **a = __argv; *a; a++) for (char **a = __argv; *a; a++)
n += strlen (*a) + 1; n += strlen (*a) + 1;
char *p; char *p;
p = s = (char *) malloc (n); p = s = (char *) cmalloc (HEAP_COMMUNE, n);
for (char **a = __argv; *a; a++) for (char **a = __argv; *a; a++)
{ {
strcpy (p, *a); strcpy (p, *a);