1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #include "DllPrefetchExperimentRegistryInfo.h"
9 #include "mozilla/Assertions.h"
10 #include "mozilla/NativeNt.h"
11 #include "mozilla/ResultExtensions.h"
15 const wchar_t DllPrefetchExperimentRegistryInfo::kExperimentSubKeyPath
[] =
17 L
"\\" MOZ_APP_VENDOR L
"\\" MOZ_APP_BASENAME L
"\\DllPrefetchExperiment";
19 Result
<Ok
, nsresult
> DllPrefetchExperimentRegistryInfo::Open() {
26 LSTATUS result
= ::RegCreateKeyExW(
27 HKEY_CURRENT_USER
, kExperimentSubKeyPath
, 0, nullptr,
28 REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, nullptr, &rawKey
, &disposition
);
30 if (result
!= ERROR_SUCCESS
) {
31 return Err(NS_ERROR_UNEXPECTED
);
36 if (disposition
== REG_CREATED_NEW_KEY
||
37 disposition
== REG_OPENED_EXISTING_KEY
) {
41 MOZ_ASSERT_UNREACHABLE("Invalid disposition from RegCreateKeyExW");
42 return Err(NS_ERROR_UNEXPECTED
);
45 Result
<Ok
, nsresult
> DllPrefetchExperimentRegistryInfo::ReflectPrefToRegistry(
52 ::RegSetValueExW(mRegKey
.get(), mBinPath
.get(), 0, REG_DWORD
,
53 reinterpret_cast<PBYTE
>(&aVal
), sizeof(aVal
));
55 if (status
!= ERROR_SUCCESS
) {
56 return Err(NS_ERROR_UNEXPECTED
);
62 Result
<Ok
, nsresult
> DllPrefetchExperimentRegistryInfo::ReadRegistryValueData(
67 DWORD dataLen
= sizeof((ULONG
)data
);
70 ::RegQueryValueExW(mRegKey
.get(), mBinPath
.get(), nullptr, &type
,
71 reinterpret_cast<PBYTE
>(&data
), &dataLen
);
73 if (status
== ERROR_FILE_NOT_FOUND
) {
74 // The registry key has not been created, set to default 0
79 if (status
!= ERROR_SUCCESS
) {
80 return Err(NS_ERROR_UNEXPECTED
);
83 if (type
!= expectedType
) {
84 return Err(NS_ERROR_UNEXPECTED
);
91 AlteredDllPrefetchMode
92 DllPrefetchExperimentRegistryInfo::GetAlteredDllPrefetchMode() {
93 Result
<Ok
, nsresult
> result
= ReadRegistryValueData(REG_DWORD
);
96 return AlteredDllPrefetchMode::CurrentPrefetch
;
99 switch (mPrefetchMode
) {
101 return AlteredDllPrefetchMode::CurrentPrefetch
;
103 return AlteredDllPrefetchMode::NoPrefetch
;
105 return AlteredDllPrefetchMode::OptimizedPrefetch
;
108 return AlteredDllPrefetchMode::CurrentPrefetch
;
112 } // namespace mozilla