ntdll: Move creation of the CPU-specific registry keys to wineboot.

This commit is contained in:
Alexandre Julliard 2009-09-24 14:22:57 +02:00
parent 7f2d50f344
commit a022062cab
2 changed files with 122 additions and 156 deletions

View File

@ -857,160 +857,6 @@ static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
} }
} }
static BOOL create_system_registry_keys( void )
{
static const WCHAR SystemW[] = {'M','a','c','h','i','n','e','\\',
'H','a','r','d','w','a','r','e','\\',
'D','e','s','c','r','i','p','t','i','o','n','\\',
'S','y','s','t','e','m',0};
static const WCHAR fpuW[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0};
static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
/* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
static const WCHAR PercentDW[] = {'%','d',0};
static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
' ','S','t','e','p','p','i','n','g',' ','%','d',0};
unsigned int i;
HANDLE hkey, system_key, cpu_key;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW, valueW;
ULONG dispos;
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.ObjectName = &nameW;
attr.Attributes = 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, SystemW );
if (NtCreateKey( &system_key, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &dispos ))
return FALSE;
if (dispos == REG_OPENED_EXISTING_KEY)
{
NtClose( system_key );
return FALSE;
}
RtlInitUnicodeString( &valueW, IdentifierW );
NtSetValueKey( system_key, &valueW, 0, REG_SZ, SysidW, sizeof(SysidW) );
attr.RootDirectory = system_key;
RtlInitUnicodeString( &nameW, fpuW );
if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL )) NtClose( hkey );
RtlInitUnicodeString( &nameW, cpuW );
if (!NtCreateKey( &cpu_key, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL ))
{
for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
{
WCHAR numW[10], idW[60];
attr.RootDirectory = cpu_key;
sprintfW( numW, PercentDW, i );
RtlInitUnicodeString( &nameW, numW );
if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL ))
{
PROCESSOR_POWER_INFORMATION power_info;
DWORD cpuMHz;
if (NtPowerInformation(ProcessorInformation, NULL, 0,
&power_info, sizeof(power_info)) == STATUS_SUCCESS)
cpuMHz = power_info.MaxMhz;
else
cpuMHz = 0;
/*TODO: report 64bit processors properly*/
RtlInitUnicodeString( &valueW, IdentifierW );
sprintfW( idW, IntelCpuDescrW,
cached_sci.Level, HIBYTE(cached_sci.Revision), LOBYTE(cached_sci.Revision) );
NtSetValueKey( hkey, &valueW, 0, REG_SZ, idW, (strlenW(idW) + 1) * sizeof(WCHAR) );
/*TODO; report amd's properly*/
RtlInitUnicodeString( &valueW, VendorIdentifierW );
NtSetValueKey( hkey, &valueW, 0, REG_SZ, VenidIntelW, sizeof(VenidIntelW) );
RtlInitUnicodeString( &valueW, mhzKeyW );
NtSetValueKey( hkey, &valueW, 0, REG_DWORD, &cpuMHz, sizeof(DWORD) );
NtClose( hkey );
}
}
NtClose( cpu_key );
}
NtClose( system_key );
return TRUE;
}
static void create_env_registry_keys( void )
{
static const WCHAR EnvironW[] = {'M','a','c','h','i','n','e','\\',
'S','y','s','t','e','m','\\',
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
'C','o','n','t','r','o','l','\\',
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
'E','n','v','i','r','o','n','m','e','n','t',0};
static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
static const WCHAR x86W[] = {'x','8','6',0};
static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
static const WCHAR PercentDW[] = {'%','d',0};
static const WCHAR Percent04XW[] = {'%','0','4','x',0};
static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
HANDLE env_key;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW, valueW;
WCHAR nProcW[10],idW[60],procLevelW[10],revW[10];
/* Create some keys under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.
* All these environment variables are processor related and will be read during process initialization and hence
* show up in the environment of that process.
*/
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.ObjectName = &nameW;
attr.Attributes = 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, EnvironW );
if (NtCreateKey( &env_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
sprintfW( nProcW, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors );
RtlInitUnicodeString( &valueW, NumProcW );
NtSetValueKey( env_key, &valueW, 0, REG_SZ, nProcW, (strlenW(nProcW) + 1) * sizeof(WCHAR) );
/* TODO: currently hardcoded x86, add different processors */
RtlInitUnicodeString( &valueW, ProcArchW );
NtSetValueKey( env_key, &valueW, 0, REG_SZ, x86W, sizeof(x86W) );
/* TODO: currently hardcoded Intel, add different processors */
sprintfW(idW, IntelCpuDescrW,
cached_sci.Level, HIBYTE(cached_sci.Revision), LOBYTE(cached_sci.Revision) );
RtlInitUnicodeString( &valueW, ProcIdW );
NtSetValueKey( env_key, &valueW, 0, REG_SZ, idW, (strlenW(idW) + 1) * sizeof(WCHAR) );
sprintfW( procLevelW, PercentDW, cached_sci.Level );
RtlInitUnicodeString( &valueW, ProcLvlW );
NtSetValueKey( env_key, &valueW, 0, REG_SZ, procLevelW, (strlenW(procLevelW) + 1) * sizeof(WCHAR) );
/* Properly report model/stepping */
sprintfW( revW, Percent04XW, cached_sci.Revision);
RtlInitUnicodeString( &valueW, ProcRevW );
NtSetValueKey( env_key, &valueW, 0, REG_SZ, revW, (strlenW(revW) + 1) * sizeof(WCHAR) );
NtClose( env_key );
}
/****************************************************************** /******************************************************************
* fill_cpu_info * fill_cpu_info
* *
@ -1384,8 +1230,6 @@ void fill_cpu_info(void)
#endif #endif
TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n", TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet); cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
if (create_system_registry_keys()) create_env_registry_keys();
} }
/****************************************************************************** /******************************************************************************

View File

@ -71,6 +71,7 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#include <windows.h> #include <windows.h>
#include <winternl.h>
#include <wine/svcctl.h> #include <wine/svcctl.h>
#include <wine/unicode.h> #include <wine/unicode.h>
#include <wine/library.h> #include <wine/library.h>
@ -157,6 +158,125 @@ done:
return ret; return ret;
} }
/* create the volatile hardware registry keys */
static void create_hardware_registry_keys(void)
{
static const WCHAR SystemW[] = {'H','a','r','d','w','a','r','e','\\',
'D','e','s','c','r','i','p','t','i','o','n','\\',
'S','y','s','t','e','m',0};
static const WCHAR fpuW[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0};
static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
/* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
static const WCHAR PercentDW[] = {'%','d',0};
static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
' ','S','t','e','p','p','i','n','g',' ','%','d',0};
unsigned int i;
HKEY hkey, system_key, cpu_key, fpu_key;
SYSTEM_CPU_INFORMATION sci;
PROCESSOR_POWER_INFORMATION power_info;
WCHAR idW[60];
NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
if (NtPowerInformation(ProcessorInformation, NULL, 0, &power_info, sizeof(power_info)))
power_info.MaxMhz = 0;
/*TODO: report 64bit processors properly*/
sprintfW( idW, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, SystemW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &system_key, NULL ))
return;
RegSetValueExW( system_key, IdentifierW, 0, REG_SZ, (const BYTE *)SysidW, sizeof(SysidW) );
if (RegCreateKeyExW( system_key, fpuW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &fpu_key, NULL ))
fpu_key = 0;
if (RegCreateKeyExW( system_key, cpuW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &cpu_key, NULL ))
cpu_key = 0;
for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
{
WCHAR numW[10];
sprintfW( numW, PercentDW, i );
if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
RegSetValueExW( hkey, IdentifierW, 0, REG_SZ,
(const BYTE *)idW, (strlenW(idW) + 1) * sizeof(WCHAR) );
/*TODO; report amd's properly*/
RegSetValueExW( hkey, VendorIdentifierW, 0, REG_SZ,
(const BYTE *)VenidIntelW, sizeof(VenidIntelW) );
RegSetValueExW( hkey, mhzKeyW, 0, REG_DWORD, (BYTE *)&power_info.MaxMhz, sizeof(DWORD) );
RegCloseKey( hkey );
}
if (!RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
RegSetValueExW( hkey, IdentifierW, 0, REG_SZ,
(const BYTE *)idW, (strlenW(idW) + 1) * sizeof(WCHAR) );
RegCloseKey( hkey );
}
}
RegCloseKey( fpu_key );
RegCloseKey( cpu_key );
RegCloseKey( system_key );
}
/* create the platform-specific environment registry keys */
static void create_environment_registry_keys( void )
{
static const WCHAR EnvironW[] = {'S','y','s','t','e','m','\\',
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
'C','o','n','t','r','o','l','\\',
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
'E','n','v','i','r','o','n','m','e','n','t',0};
static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
static const WCHAR x86W[] = {'x','8','6',0};
static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
static const WCHAR PercentDW[] = {'%','d',0};
static const WCHAR Percent04XW[] = {'%','0','4','x',0};
static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
HKEY env_key;
SYSTEM_CPU_INFORMATION sci;
WCHAR buffer[60];
NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return;
sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors );
RegSetValueExW( env_key, NumProcW, 0, REG_SZ, (BYTE *)buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
/* TODO: currently hardcoded x86, add different processors */
RegSetValueExW( env_key, ProcArchW, 0, REG_SZ, (const BYTE *)x86W, sizeof(x86W) );
/* TODO: currently hardcoded Intel, add different processors */
sprintfW( buffer, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
RegSetValueExW( env_key, ProcIdW, 0, REG_SZ, (BYTE *)buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
sprintfW( buffer, PercentDW, sci.Level );
RegSetValueExW( env_key, ProcLvlW, 0, REG_SZ, (BYTE *)buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
/* Properly report model/stepping */
sprintfW( buffer, Percent04XW, sci.Revision );
RegSetValueExW( env_key, ProcRevW, 0, REG_SZ, (BYTE *)buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
RegCloseKey( env_key );
}
/* Performs the rename operations dictated in %SystemRoot%\Wininit.ini. /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
* Returns FALSE if there was an error, or otherwise if all is ok. * Returns FALSE if there was an error, or otherwise if all is ok.
*/ */
@ -864,6 +984,8 @@ int main( int argc, char *argv[] )
ResetEvent( event ); /* in case this is a restart */ ResetEvent( event ); /* in case this is a restart */
create_hardware_registry_keys();
create_environment_registry_keys();
wininit(); wininit();
pendingRename(); pendingRename();