From: Lorenzo Ferrillo lorenzofersteam@live.it
--- dlls/kernelbase/main.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/dlls/kernelbase/main.c b/dlls/kernelbase/main.c index 60173ba6513..4c373f06e57 100644 --- a/dlls/kernelbase/main.c +++ b/dlls/kernelbase/main.c @@ -301,6 +301,29 @@ ULONG WINAPI PerfSetCounterSetInfo( HANDLE handle, PERF_COUNTERSET_INFO *templat return STATUS_SUCCESS; }
+ +static unsigned int get_performance_counter_index(PERF_COUNTERSET_INSTANCE *instance, ULONG counter_id, struct counterset_template ** out_template,struct counterset_instance ** out_instance) +{ + unsigned int i; + struct counterset_template *template; + struct counterset_instance *inst; + + inst = CONTAINING_RECORD(instance, struct counterset_instance, instance); + template = inst->template; + + *out_instance = inst; + *out_template = template; + + for (i = 0; i < template->counterset.NumCounters; ++i) + if (template->counter[i].CounterId == counter_id) return i; + return template->counterset.NumCounters; +} + +static BYTE* get_performance_counter_address(struct counterset_template* template, struct counterset_instance* instance, unsigned int counter_index) +{ + return (BYTE*) &instance->instance + sizeof(PERF_COUNTERSET_INSTANCE) + template->counter[counter_index].Offset; +} + /*********************************************************************** * PerfSetCounterRefValue (KERNELBASE.@) */ @@ -310,21 +333,17 @@ ULONG WINAPI PerfSetCounterRefValue(HANDLE provider, PERF_COUNTERSET_INSTANCE *i struct perf_provider *prov = perf_provider_from_handle( provider ); struct counterset_template *template; struct counterset_instance *inst; - unsigned int i; + unsigned int counter_index;;
FIXME( "provider %p, instance %p, counterid %lu, address %p semi-stub.\n", provider, instance, counterid, address );
if (!prov || !instance || !address) return ERROR_INVALID_PARAMETER;
- inst = CONTAINING_RECORD(instance, struct counterset_instance, instance); - template = inst->template; - - for (i = 0; i < template->counterset.NumCounters; ++i) - if (template->counter[i].CounterId == counterid) break; + counter_index = get_performance_counter_index(instance, counterid, &template, &inst);
- if (i == template->counterset.NumCounters) return ERROR_NOT_FOUND; - *(void **)((BYTE *)&inst->instance + sizeof(PERF_COUNTERSET_INSTANCE) + template->counter[i].Offset) = address; + if (counter_index== template->counterset.NumCounters) return ERROR_NOT_FOUND; + *(void **)(get_performance_counter_address(template,inst, counter_index)) = address;
return STATUS_SUCCESS; }