Commit 242dc898 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use malloc() to allocate the system processor information.

parent fe7b8d70
......@@ -2182,6 +2182,11 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
ret = STATUS_INFO_LENGTH_MISMATCH;
break;
}
if (!(sppi = calloc( out_cpus, sizeof(*sppi) )))
{
ret = STATUS_NO_MEMORY;
break;
}
else
#ifdef __APPLE__
{
......@@ -2196,8 +2201,6 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
int i;
cpus = min(cpus,out_cpus);
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
for (i = 0; i < cpus; i++)
{
sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
......@@ -2214,7 +2217,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
unsigned long clk_tck = sysconf(_SC_CLK_TCK);
unsigned long usr,nice,sys,idle,remainder[8];
int i, count;
int i, count, id;
char name[32];
char line[255];
......@@ -2230,17 +2233,12 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
for (i = 0; i + 5 < count; ++i) sys += remainder[i];
sys += idle;
usr += nice;
cpus = atoi( name + 3 ) + 1;
if (cpus > out_cpus) break;
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
if (sppi)
sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
else
sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
id = atoi( name + 3 ) + 1;
if (id > out_cpus) break;
if (id > cpus) cpus = id;
sppi[id-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
sppi[id-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
sppi[id-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
}
fclose(cpuinfo);
}
......@@ -2251,8 +2249,6 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
static int i = 1;
unsigned int n;
cpus = min(NtCurrentTeb()->Peb->NumberOfProcessors, out_cpus);
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
sppi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
/* many programs expect these values to change so fake change */
for (n = 0; n < cpus; n++)
......@@ -2264,6 +2260,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
i++;
}
len = sizeof(*sppi) * cpus;
if (size >= len)
{
if (!info) ret = STATUS_ACCESS_VIOLATION;
......@@ -2271,7 +2268,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
}
else ret = STATUS_INFO_LENGTH_MISMATCH;
RtlFreeHeap(GetProcessHeap(),0,sppi);
free( sppi );
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment