* 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>
* sigproc.h (set_signal_mask): Remove default on second parameter and

View File

@ -20,6 +20,7 @@ enum cygheap_types
HEAP_SIGS,
HEAP_ARCHETYPES,
HEAP_TLS,
HEAP_COMMUNE,
HEAP_1_START,
HEAP_1_HOOK,
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_NETDRIVE= FHDEV (0, 246),
FH_DEV = FHDEV (0, 245),
DEV_FLOPPY_MAJOR = 2,
FH_FLOPPY = FHDEV (DEV_FLOPPY_MAJOR, 0),

View File

@ -24,6 +24,11 @@ const device dev_proc_storage =
const device dev_netdrive_storage =
{"", {FH_NETDRIVE}, ""};
#if 0
const device dev_dev_storage =
{"/dev", {FH_DEV}, "/dev"};
#endif
const device dev_registry_storage =
{"", {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%(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", BRACK(FH_DEV), "/dev"
%other {return NULL;}
%%
#undef BRACK

View File

@ -342,7 +342,7 @@ fhandler_proc::fill_filebuf ()
uname (&uts_name);
bufalloc = strlen (uts_name.sysname) + 1 + strlen (uts_name.release) +
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,
uts_name.release, uts_name.version);
}
@ -350,13 +350,13 @@ fhandler_proc::fill_filebuf ()
}
case PROC_UPTIME:
{
filebuf = (char *) realloc (filebuf, bufalloc = 80);
filebuf = (char *) crealloc (filebuf, bufalloc = 80);
filesize = format_proc_uptime (filebuf, bufalloc);
break;
}
case PROC_STAT:
{
filebuf = (char *) realloc (filebuf, bufalloc = 16384);
filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
filesize = format_proc_stat (filebuf, bufalloc);
break;
}
@ -367,32 +367,32 @@ fhandler_proc::fill_filebuf ()
* Windows 95/98/me does have the KERNEL/CPUUsage performance counter
* 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",
0, 0, 0, 0, 0, 0);
break;
}
case PROC_MEMINFO:
{
filebuf = (char *) realloc (filebuf, bufalloc = 2048);
filebuf = (char *) crealloc (filebuf, bufalloc = 2048);
filesize = format_proc_meminfo (filebuf, bufalloc);
break;
}
case PROC_CPUINFO:
{
filebuf = (char *) realloc (filebuf, bufalloc = 16384);
filebuf = (char *) crealloc (filebuf, bufalloc = 16384);
filesize = format_proc_cpuinfo (filebuf, bufalloc);
break;
}
case PROC_PARTITIONS:
{
filebuf = (char *) realloc (filebuf, bufalloc = 4096);
filebuf = (char *) crealloc (filebuf, bufalloc = 4096);
filesize = format_proc_partitions (filebuf, bufalloc);
break;
}
case PROC_SELF:
{
filebuf = (char *) realloc (filebuf, bufalloc = 32);
filebuf = (char *) crealloc (filebuf, bufalloc = 32);
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 (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;
}

View File

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

View File

@ -33,14 +33,15 @@ fhandler_virtual::fhandler_virtual ():
fhandler_virtual::~fhandler_virtual ()
{
if (filebuf)
free (filebuf);
filebuf = NULL;
{
cfree (filebuf);
filebuf = NULL;
}
}
void
fhandler_virtual::fixup_after_exec ()
{
close ();
}
DIR *
@ -154,7 +155,7 @@ fhandler_virtual::dup (fhandler_base * child)
if (!ret)
{
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->position = position;
memcpy (fhproc_child->filebuf, filebuf, filesize);
@ -168,8 +169,7 @@ fhandler_virtual::close ()
{
if (!hExeced)
{
if (filebuf)
free (filebuf);
cfree (filebuf);
filebuf = NULL;
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;
else
{
dev.devn = FH_FS;
fileattr = GetFileAttributes (this->path);
dev.devn = FH_FS;
}
goto out;
}
else if (dev == FH_DEV)
{
fileattr = FILE_ATTRIBUTE_DIRECTORY;
dev.devn = FH_FS;
goto out;
}
else if (isvirtual_dev (dev.devn))
{
/* 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;
else
{
res.s = (char *) malloc (n);
res.s = (char *) cmalloc (HEAP_COMMUNE, n);
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;
if ((unsigned) (p - res.s) != n)
{
@ -817,9 +817,9 @@ _pinfo::fd (int fd, size_t &n)
{
cygheap_fdget cfd (fd);
if (cfd < 0)
s = strdup ("");
s = cstrdup ("");
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;
}
return s;
@ -845,7 +845,7 @@ _pinfo::fds (size_t &n)
while ((fd = cfd.next ()) >= 0)
n += sizeof (int);
cfd.rewind ();
s = (char *) malloc (n);
s = (char *) cmalloc (HEAP_COMMUNE, n);
int *p = (int *) s;
while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n)
*p++ = fd;
@ -868,9 +868,9 @@ _pinfo::root (size_t& n)
else
{
if (cygheap->root.exists ())
s = strdup (cygheap->root.posix_path ());
s = cstrdup (cygheap->root.posix_path ());
else
s = strdup ("/");
s = cstrdup ("/");
n = strlen (s) + 1;
}
return s;
@ -890,7 +890,7 @@ _pinfo::cwd (size_t& n)
}
else
{
s = (char *) malloc (CYG_MAX_PATH);
s = (char *) cmalloc (HEAP_COMMUNE, CYG_MAX_PATH);
cygheap->cwd.get (s, 1, 1, CYG_MAX_PATH);
n = strlen (s) + 1;
}
@ -915,7 +915,7 @@ _pinfo::cmdline (size_t& n)
for (char **a = __argv; *a; a++)
n += strlen (*a) + 1;
char *p;
p = s = (char *) malloc (n);
p = s = (char *) cmalloc (HEAP_COMMUNE, n);
for (char **a = __argv; *a; a++)
{
strcpy (p, *a);