2017-03-28 16:16:01 +02:00
|
|
|
/*
|
2018-02-27 05:21:26 +01:00
|
|
|
* Copyright 2016 Michael Müller
|
2017-03-28 16:16:01 +02:00
|
|
|
* Copyright 2017 Andrey Gusev
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-15 13:57:04 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2018-10-26 08:50:15 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2017-10-05 03:20:42 +02:00
|
|
|
#include "windows.h"
|
|
|
|
#include "appmodel.h"
|
2019-05-15 13:57:04 +02:00
|
|
|
#include "shlwapi.h"
|
2019-06-25 13:09:34 +02:00
|
|
|
#include "perflib.h"
|
2019-09-09 13:44:53 +02:00
|
|
|
#include "winternl.h"
|
2017-10-05 03:20:42 +02:00
|
|
|
|
2017-03-28 16:16:01 +02:00
|
|
|
#include "wine/debug.h"
|
2019-09-09 13:44:53 +02:00
|
|
|
#include "kernelbase.h"
|
2019-12-11 22:21:17 +01:00
|
|
|
#include "wine/heap.h"
|
2021-11-22 15:07:58 +01:00
|
|
|
#include "wine/list.h"
|
2017-03-28 16:16:01 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(kernelbase);
|
|
|
|
|
2019-06-12 22:38:09 +02:00
|
|
|
|
2019-11-12 22:01:27 +01:00
|
|
|
BOOL is_wow64 = FALSE;
|
2019-10-04 21:48:32 +02:00
|
|
|
|
2019-09-09 13:44:53 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
|
|
|
{
|
|
|
|
if (reason == DLL_PROCESS_ATTACH)
|
|
|
|
{
|
|
|
|
DisableThreadLibraryCalls( hinst );
|
2019-11-12 22:01:27 +01:00
|
|
|
IsWow64Process( GetCurrentProcess(), &is_wow64 );
|
2019-11-20 22:46:44 +01:00
|
|
|
init_locale();
|
2019-09-09 13:44:53 +02:00
|
|
|
init_startup_info( NtCurrentTeb()->Peb->ProcessParameters );
|
2020-08-13 16:02:04 +02:00
|
|
|
init_console();
|
2019-09-09 13:44:53 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-12 22:38:09 +02:00
|
|
|
/*************************************************************
|
|
|
|
* DllMainCRTStartup
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMainCRTStartup( HANDLE inst, DWORD reason, LPVOID reserved )
|
|
|
|
{
|
2019-09-09 13:44:53 +02:00
|
|
|
return DllMain( inst, reason, reserved );
|
2019-06-12 22:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 13:18:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* MulDiv (kernelbase.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI MulDiv( INT a, INT b, INT c )
|
|
|
|
{
|
|
|
|
LONGLONG ret;
|
|
|
|
|
|
|
|
if (!c) return -1;
|
|
|
|
|
|
|
|
/* We want to deal with a positive divisor to simplify the logic. */
|
|
|
|
if (c < 0)
|
|
|
|
{
|
|
|
|
a = -a;
|
|
|
|
c = -c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the result is positive, we "add" to round. else, we subtract to round. */
|
|
|
|
if ((a < 0 && b < 0) || (a >= 0 && b >= 0))
|
|
|
|
ret = (((LONGLONG)a * b) + (c / 2)) / c;
|
|
|
|
else
|
|
|
|
ret = (((LONGLONG)a * b) - (c / 2)) / c;
|
|
|
|
|
|
|
|
if (ret > 2147483647 || ret < -2147483647) return -1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-11-11 11:01:26 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* AppPolicyGetMediaFoundationCodecLoading (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
LONG WINAPI AppPolicyGetMediaFoundationCodecLoading(HANDLE token, AppPolicyMediaFoundationCodecLoading *policy)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", token, policy);
|
|
|
|
|
|
|
|
if(policy)
|
|
|
|
*policy = AppPolicyMediaFoundationCodecLoading_All;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-10-05 03:20:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* AppPolicyGetProcessTerminationMethod (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
LONG WINAPI AppPolicyGetProcessTerminationMethod(HANDLE token, AppPolicyProcessTerminationMethod *policy)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", token, policy);
|
|
|
|
|
|
|
|
if(policy)
|
|
|
|
*policy = AppPolicyProcessTerminationMethod_ExitProcess;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-10-05 03:20:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* AppPolicyGetThreadInitializationType (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
LONG WINAPI AppPolicyGetThreadInitializationType(HANDLE token, AppPolicyThreadInitializationType *policy)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", token, policy);
|
|
|
|
|
|
|
|
if(policy)
|
|
|
|
*policy = AppPolicyThreadInitializationType_None;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-10-06 02:08:57 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* AppPolicyGetShowDeveloperDiagnostic (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
LONG WINAPI AppPolicyGetShowDeveloperDiagnostic(HANDLE token, AppPolicyShowDeveloperDiagnostic *policy)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", token, policy);
|
|
|
|
|
|
|
|
if(policy)
|
|
|
|
*policy = AppPolicyShowDeveloperDiagnostic_ShowUI;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-10-06 02:08:58 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* AppPolicyGetWindowingModel (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
LONG WINAPI AppPolicyGetWindowingModel(HANDLE token, AppPolicyWindowingModel *policy)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", token, policy);
|
|
|
|
|
|
|
|
if(policy)
|
|
|
|
*policy = AppPolicyWindowingModel_ClassicDesktop;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2017-10-06 02:08:57 +02:00
|
|
|
|
2021-11-22 15:07:57 +01:00
|
|
|
struct counterset_template
|
|
|
|
{
|
|
|
|
PERF_COUNTERSET_INFO counterset;
|
|
|
|
PERF_COUNTER_INFO counter[1];
|
|
|
|
};
|
|
|
|
|
2021-11-22 15:07:58 +01:00
|
|
|
struct counterset_instance
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
struct counterset_template *template;
|
|
|
|
PERF_COUNTERSET_INSTANCE instance;
|
|
|
|
};
|
|
|
|
|
2021-11-22 15:07:56 +01:00
|
|
|
struct perf_provider
|
|
|
|
{
|
|
|
|
GUID guid;
|
|
|
|
PERFLIBREQUEST callback;
|
2021-11-22 15:07:57 +01:00
|
|
|
struct counterset_template **countersets;
|
|
|
|
unsigned int counterset_count;
|
2021-11-22 15:07:58 +01:00
|
|
|
|
|
|
|
struct list instance_list;
|
2021-11-22 15:07:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct perf_provider *perf_provider_from_handle(HANDLE prov)
|
|
|
|
{
|
|
|
|
return (struct perf_provider *)prov;
|
|
|
|
}
|
|
|
|
|
2019-06-25 13:09:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* PerfCreateInstance (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:58 +01:00
|
|
|
PERF_COUNTERSET_INSTANCE WINAPI *PerfCreateInstance( HANDLE handle, const GUID *guid,
|
|
|
|
const WCHAR *name, ULONG id )
|
2019-06-25 13:09:34 +02:00
|
|
|
{
|
2021-11-22 15:07:58 +01:00
|
|
|
struct perf_provider *prov = perf_provider_from_handle( handle );
|
|
|
|
struct counterset_template *template;
|
|
|
|
struct counterset_instance *inst;
|
|
|
|
unsigned int i;
|
|
|
|
ULONG size;
|
|
|
|
|
|
|
|
FIXME( "handle %p, guid %s, name %s, id %u semi-stub.\n", handle, debugstr_guid(guid), debugstr_w(name), id );
|
|
|
|
|
|
|
|
if (!prov || !guid || !name)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < prov->counterset_count; ++i)
|
|
|
|
if (IsEqualGUID(guid, &prov->countersets[i]->counterset.CounterSetGuid)) break;
|
|
|
|
|
|
|
|
if (i == prov->counterset_count)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_FOUND );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
template = prov->countersets[i];
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(inst, &prov->instance_list, struct counterset_instance, entry)
|
|
|
|
{
|
|
|
|
if (inst->template == template && inst->instance.InstanceId == id)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = (sizeof(PERF_COUNTERSET_INSTANCE) + template->counterset.NumCounters * sizeof(UINT64)
|
|
|
|
+ (lstrlenW( name ) + 1) * sizeof(WCHAR) + 7) & ~7;
|
|
|
|
inst = heap_alloc_zero( offsetof(struct counterset_instance, instance) + size );
|
|
|
|
if (!inst)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inst->template = template;
|
|
|
|
inst->instance.CounterSetGuid = *guid;
|
|
|
|
inst->instance.dwSize = size;
|
|
|
|
inst->instance.InstanceId = id;
|
|
|
|
inst->instance.InstanceNameOffset = sizeof(PERF_COUNTERSET_INSTANCE)
|
|
|
|
+ template->counterset.NumCounters * sizeof(UINT64);
|
|
|
|
inst->instance.InstanceNameSize = (lstrlenW( name ) + 1) * sizeof(WCHAR);
|
|
|
|
memcpy( (BYTE *)&inst->instance + inst->instance.InstanceNameOffset, name, inst->instance.InstanceNameSize );
|
|
|
|
list_add_tail( &prov->instance_list, &inst->entry );
|
|
|
|
|
|
|
|
return &inst->instance;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfDeleteInstance (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:58 +01:00
|
|
|
ULONG WINAPI PerfDeleteInstance(HANDLE provider, PERF_COUNTERSET_INSTANCE *block)
|
2019-06-25 13:09:34 +02:00
|
|
|
{
|
2021-11-22 15:07:58 +01:00
|
|
|
struct perf_provider *prov = perf_provider_from_handle( provider );
|
|
|
|
struct counterset_instance *inst;
|
|
|
|
|
|
|
|
TRACE( "provider %p, block %p.\n", provider, block );
|
|
|
|
|
|
|
|
if (!prov || !block) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
inst = CONTAINING_RECORD(block, struct counterset_instance, instance);
|
|
|
|
list_remove( &inst->entry );
|
|
|
|
heap_free( inst );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfSetCounterSetInfo (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:57 +01:00
|
|
|
ULONG WINAPI PerfSetCounterSetInfo( HANDLE handle, PERF_COUNTERSET_INFO *template, ULONG size )
|
2019-06-25 13:09:34 +02:00
|
|
|
{
|
2021-11-22 15:07:57 +01:00
|
|
|
struct perf_provider *prov = perf_provider_from_handle( handle );
|
|
|
|
struct counterset_template **new_array;
|
|
|
|
struct counterset_template *new;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
FIXME( "handle %p, template %p, size %u semi-stub.\n", handle, template, size );
|
|
|
|
|
|
|
|
if (!prov || !template) return ERROR_INVALID_PARAMETER;
|
|
|
|
if (!template->NumCounters) return ERROR_INVALID_PARAMETER;
|
|
|
|
if (size < sizeof(*template) || (size - (sizeof(*template))) / sizeof(PERF_COUNTER_INFO) < template->NumCounters)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
for (i = 0; i < prov->counterset_count; ++i)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( &template->CounterSetGuid, &prov->countersets[i]->counterset.CounterSetGuid ))
|
|
|
|
return ERROR_ALREADY_EXISTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = offsetof( struct counterset_template, counter[template->NumCounters] );
|
|
|
|
if (!(new = heap_alloc( size ))) return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (prov->counterset_count)
|
|
|
|
new_array = heap_realloc( prov->countersets, sizeof(*prov->countersets) * (prov->counterset_count + 1) );
|
|
|
|
else
|
|
|
|
new_array = heap_alloc( sizeof(*prov->countersets) );
|
|
|
|
|
|
|
|
if (!new_array)
|
|
|
|
{
|
|
|
|
heap_free( new );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy( new, template, size );
|
2021-11-22 15:07:58 +01:00
|
|
|
for (i = 0; i < template->NumCounters; ++i)
|
|
|
|
new->counter[i].Offset = i * sizeof(UINT64);
|
2021-11-22 15:07:57 +01:00
|
|
|
new_array[prov->counterset_count++] = new;
|
|
|
|
prov->countersets = new_array;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfSetCounterRefValue (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:59 +01:00
|
|
|
ULONG WINAPI PerfSetCounterRefValue(HANDLE provider, PERF_COUNTERSET_INSTANCE *instance,
|
2019-06-25 13:09:34 +02:00
|
|
|
ULONG counterid, void *address)
|
|
|
|
{
|
2021-11-22 15:07:59 +01:00
|
|
|
struct perf_provider *prov = perf_provider_from_handle( provider );
|
|
|
|
struct counterset_template *template;
|
|
|
|
struct counterset_instance *inst;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
FIXME( "provider %p, instance %p, counterid %u, 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;
|
|
|
|
|
|
|
|
if (i == template->counterset.NumCounters) return ERROR_NOT_FOUND;
|
|
|
|
*(void **)((BYTE *)&inst->instance + sizeof(PERF_COUNTERSET_INSTANCE) + template->counter[i].Offset) = address;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfStartProvider (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:56 +01:00
|
|
|
ULONG WINAPI PerfStartProvider( GUID *guid, PERFLIBREQUEST callback, HANDLE *provider )
|
2019-06-25 13:09:34 +02:00
|
|
|
{
|
2021-11-22 15:07:56 +01:00
|
|
|
PERF_PROVIDER_CONTEXT ctx;
|
|
|
|
|
|
|
|
FIXME( "guid %s, callback %p, provider %p semi-stub.\n", debugstr_guid(guid), callback, provider );
|
|
|
|
|
|
|
|
memset( &ctx, 0, sizeof(ctx) );
|
|
|
|
ctx.ContextSize = sizeof(ctx);
|
|
|
|
ctx.ControlCallback = callback;
|
|
|
|
|
|
|
|
return PerfStartProviderEx( guid, &ctx, provider );
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfStartProviderEx (KERNELBASE.@)
|
|
|
|
*/
|
2021-11-22 15:07:56 +01:00
|
|
|
ULONG WINAPI PerfStartProviderEx( GUID *guid, PERF_PROVIDER_CONTEXT *context, HANDLE *provider )
|
2019-06-25 13:09:34 +02:00
|
|
|
{
|
2021-11-22 15:07:56 +01:00
|
|
|
struct perf_provider *prov;
|
|
|
|
|
|
|
|
FIXME( "guid %s, context %p, provider %p semi-stub.\n", debugstr_guid(guid), context, provider );
|
|
|
|
|
|
|
|
if (!guid || !context || !provider) return ERROR_INVALID_PARAMETER;
|
|
|
|
if (context->ContextSize < sizeof(*context)) return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2021-11-22 15:07:58 +01:00
|
|
|
if (context->MemAllocRoutine || context->MemFreeRoutine)
|
|
|
|
FIXME("Memory allocation routine is not supported.\n");
|
|
|
|
|
2021-11-22 15:07:56 +01:00
|
|
|
if (!(prov = heap_alloc_zero( sizeof(*prov) ))) return ERROR_OUTOFMEMORY;
|
2021-11-22 15:07:58 +01:00
|
|
|
list_init( &prov->instance_list );
|
2021-11-22 15:07:56 +01:00
|
|
|
memcpy( &prov->guid, guid, sizeof(prov->guid) );
|
|
|
|
prov->callback = context->ControlCallback;
|
|
|
|
*provider = prov;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PerfStopProvider (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI PerfStopProvider(HANDLE handle)
|
|
|
|
{
|
2021-11-22 15:07:56 +01:00
|
|
|
struct perf_provider *prov = perf_provider_from_handle( handle );
|
2021-11-22 15:07:58 +01:00
|
|
|
struct counterset_instance *inst, *next;
|
2021-11-22 15:07:57 +01:00
|
|
|
unsigned int i;
|
2021-11-22 15:07:56 +01:00
|
|
|
|
|
|
|
TRACE( "handle %p.\n", handle );
|
|
|
|
|
2021-11-22 15:07:58 +01:00
|
|
|
if (!list_empty( &prov->instance_list ))
|
|
|
|
WARN( "Stopping provider with active counter instances.\n" );
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(inst, next, &prov->instance_list, struct counterset_instance, entry)
|
|
|
|
{
|
|
|
|
list_remove( &inst->entry );
|
|
|
|
heap_free( inst );
|
|
|
|
}
|
|
|
|
|
2021-11-22 15:07:57 +01:00
|
|
|
for (i = 0; i < prov->counterset_count; ++i)
|
|
|
|
heap_free( prov->countersets[i] );
|
|
|
|
heap_free( prov->countersets );
|
2021-11-22 15:07:56 +01:00
|
|
|
heap_free( prov );
|
|
|
|
return STATUS_SUCCESS;
|
2019-06-25 13:09:34 +02:00
|
|
|
}
|
|
|
|
|
2018-02-27 05:21:26 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* QuirkIsEnabled (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QuirkIsEnabled(void *arg)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", arg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-28 16:16:01 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* QuirkIsEnabled3 (KERNELBASE.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QuirkIsEnabled3(void *unk1, void *unk2)
|
|
|
|
{
|
2017-12-15 09:54:21 +01:00
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME("(%p, %p) stub!\n", unk1, unk2);
|
|
|
|
|
2017-03-28 16:16:01 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-26 08:50:15 +02:00
|
|
|
|
2019-05-15 13:57:04 +02:00
|
|
|
HRESULT WINAPI QISearch(void *base, const QITAB *table, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
const QITAB *ptr;
|
|
|
|
IUnknown *unk;
|
|
|
|
|
|
|
|
TRACE("%p, %p, %s, %p\n", base, table, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
for (ptr = table; ptr->piid; ++ptr)
|
|
|
|
{
|
|
|
|
TRACE("trying (offset %d) %s\n", ptr->dwOffset, debugstr_guid(ptr->piid));
|
|
|
|
if (IsEqualIID(riid, ptr->piid))
|
|
|
|
{
|
|
|
|
unk = (IUnknown *)((BYTE *)base + ptr->dwOffset);
|
|
|
|
TRACE("matched, returning (%p)\n", unk);
|
|
|
|
*obj = unk;
|
|
|
|
IUnknown_AddRef(unk);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
unk = (IUnknown *)((BYTE *)base + table->dwOffset);
|
|
|
|
TRACE("returning first for IUnknown (%p)\n", unk);
|
|
|
|
*obj = unk;
|
|
|
|
IUnknown_AddRef(unk);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Not found %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2019-05-23 13:20:22 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI GetAcceptLanguagesA(LPSTR langbuf, DWORD *buflen)
|
|
|
|
{
|
|
|
|
DWORD buflenW, convlen;
|
|
|
|
WCHAR *langbufW;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %p, *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
|
|
|
|
|
|
|
|
if (!langbuf || !buflen || !*buflen)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
buflenW = *buflen;
|
|
|
|
langbufW = heap_alloc(sizeof(WCHAR) * buflenW);
|
|
|
|
hr = GetAcceptLanguagesW(langbufW, &buflenW);
|
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, *buflen, NULL, NULL);
|
|
|
|
convlen--; /* do not count the terminating 0 */
|
|
|
|
}
|
|
|
|
else /* copy partial string anyway */
|
|
|
|
{
|
|
|
|
convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, *buflen, langbuf, *buflen, NULL, NULL);
|
|
|
|
if (convlen < *buflen)
|
|
|
|
{
|
|
|
|
langbuf[convlen] = 0;
|
|
|
|
convlen--; /* do not count the terminating 0 */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
convlen = *buflen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buflen = buflenW ? convlen : 0;
|
|
|
|
|
|
|
|
heap_free(langbufW);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT lcid_to_rfc1766(LCID lcid, WCHAR *rfc1766, INT len)
|
|
|
|
{
|
|
|
|
WCHAR buffer[6 /* MAX_RFC1766_NAME */];
|
|
|
|
INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, ARRAY_SIZE(buffer));
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
i = PRIMARYLANGID(lcid);
|
|
|
|
if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
|
|
|
|
(SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
|
|
|
|
(SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
|
|
|
|
|
|
|
|
buffer[n - 1] = '-';
|
|
|
|
i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, ARRAY_SIZE(buffer) - n);
|
|
|
|
if (!i)
|
|
|
|
buffer[n - 1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
|
|
|
|
return ((n + i) > len) ? E_INVALIDARG : S_OK;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI GetAcceptLanguagesW(WCHAR *langbuf, DWORD *buflen)
|
|
|
|
{
|
|
|
|
DWORD mystrlen, mytype;
|
|
|
|
WCHAR *mystr;
|
|
|
|
LCID mylcid;
|
|
|
|
HKEY mykey;
|
|
|
|
LONG lres;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
TRACE("%p, %p, *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
|
|
|
|
|
|
|
|
if (!langbuf || !buflen || !*buflen)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
mystrlen = (*buflen > 20) ? *buflen : 20 ;
|
|
|
|
len = mystrlen * sizeof(WCHAR);
|
|
|
|
mystr = heap_alloc(len);
|
|
|
|
mystr[0] = 0;
|
2020-03-09 19:59:27 +01:00
|
|
|
RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\International",
|
|
|
|
0, KEY_QUERY_VALUE, &mykey);
|
|
|
|
lres = RegQueryValueExW(mykey, L"AcceptLanguage", 0, &mytype, (PBYTE)mystr, &len);
|
2019-05-23 13:20:22 +02:00
|
|
|
RegCloseKey(mykey);
|
|
|
|
len = lstrlenW(mystr);
|
|
|
|
|
|
|
|
if (!lres && (*buflen > len))
|
|
|
|
{
|
|
|
|
lstrcpyW(langbuf, mystr);
|
|
|
|
*buflen = len;
|
|
|
|
heap_free(mystr);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did not find a value in the registry or the user buffer is too small */
|
|
|
|
mylcid = GetUserDefaultLCID();
|
|
|
|
lcid_to_rfc1766(mylcid, mystr, mystrlen);
|
|
|
|
len = lstrlenW(mystr);
|
|
|
|
|
|
|
|
memcpy(langbuf, mystr, min(*buflen, len + 1)*sizeof(WCHAR));
|
|
|
|
heap_free(mystr);
|
|
|
|
|
|
|
|
if (*buflen > len)
|
|
|
|
{
|
|
|
|
*buflen = len;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*buflen = 0;
|
|
|
|
return E_NOT_SUFFICIENT_BUFFER;
|
|
|
|
}
|