101
101
# include < intrin.h>
102
102
# include < math.h>
103
103
# include " cairo/cairo-features.h"
104
+ # include " mozilla/DllPrefetchExperimentRegistryInfo.h"
104
105
# include " mozilla/WindowsDllBlocklist.h"
105
106
# include " mozilla/WindowsProcessMitigations.h"
106
107
# include " mozilla/WinHeaderOnlyUtils.h"
@@ -1561,6 +1562,28 @@ static void RegisterApplicationRestartChanged(const char* aPref, void* aData) {
1561
1562
}
1562
1563
}
1563
1564
1565
+ static void OnAlteredPrefetchPrefChanged (const char * aPref, void * aData) {
1566
+ int32_t prefVal = Preferences::GetInt (PREF_WIN_ALTERED_DLL_PREFETCH, 0 );
1567
+
1568
+ mozilla::DllPrefetchExperimentRegistryInfo prefetchRegInfo;
1569
+ mozilla::DebugOnly<mozilla::Result<Ok, nsresult>> reflectResult =
1570
+ prefetchRegInfo.ReflectPrefToRegistry (prefVal);
1571
+
1572
+ MOZ_ASSERT (reflectResult.value .isOk ());
1573
+ }
1574
+
1575
+ static void SetupAlteredPrefetchPref () {
1576
+ mozilla::DllPrefetchExperimentRegistryInfo prefetchRegInfo;
1577
+
1578
+ mozilla::DebugOnly<mozilla::Result<Ok, nsresult>> reflectResult =
1579
+ prefetchRegInfo.ReflectPrefToRegistry (
1580
+ Preferences::GetInt (PREF_WIN_ALTERED_DLL_PREFETCH, 0 ));
1581
+ MOZ_ASSERT (reflectResult.value .isOk ());
1582
+
1583
+ Preferences::RegisterCallback (&OnAlteredPrefetchPrefChanged,
1584
+ PREF_WIN_ALTERED_DLL_PREFETCH);
1585
+ }
1586
+
1564
1587
# if defined(MOZ_LAUNCHER_PROCESS)
1565
1588
1566
1589
static void OnLauncherPrefChanged (const char * aPref, void * aData) {
@@ -3600,14 +3623,12 @@ static void ReadAheadSystemDll(const wchar_t* dllName) {
3600
3623
}
3601
3624
}
3602
3625
3603
- # ifdef NIGHTLY_BUILD
3604
3626
static void ReadAheadPackagedDll (const wchar_t * dllName,
3605
3627
const wchar_t * aGREDir) {
3606
3628
wchar_t dllPath[MAX_PATH];
3607
3629
swprintf (dllPath, MAX_PATH, L" %s\\ %s" , aGREDir, dllName);
3608
3630
ReadAheadLib (dllPath);
3609
3631
}
3610
- # endif
3611
3632
3612
3633
static void PR_CALLBACK ReadAheadDlls_ThreadStart (void * arg) {
3613
3634
UniquePtr<wchar_t []> greDir (static_cast <wchar_t *>(arg));
@@ -3618,32 +3639,32 @@ static void PR_CALLBACK ReadAheadDlls_ThreadStart(void* arg) {
3618
3639
// retention (see Bug 1640087). Before we place this within a pref,
3619
3640
// we should ensure this feature only ships to the nightly channel
3620
3641
// and monitor results from that subset.
3621
- # ifdef NIGHTLY_BUILD
3622
- // Prefetch the DLLs shipped with firefox
3623
- ReadAheadPackagedDll (L" libegl.dll" , greDir.get ());
3624
- ReadAheadPackagedDll (L" libGLESv2.dll" , greDir.get ());
3625
- ReadAheadPackagedDll (L" nssckbi.dll" , greDir.get ());
3626
- ReadAheadPackagedDll (L" freebl3.dll" , greDir.get ());
3627
- ReadAheadPackagedDll (L" softokn3.dll" , greDir.get ());
3628
-
3629
- // Prefetch the system DLLs
3630
- ReadAheadSystemDll (L" DWrite.dll" );
3631
- ReadAheadSystemDll (L" D3DCompiler_47.dll" );
3632
- # else
3633
- // Load DataExchange.dll and twinapi.appcore.dll for
3634
- // nsWindow::EnableDragDrop
3635
- ReadAheadSystemDll (L" DataExchange.dll" );
3636
- ReadAheadSystemDll (L" twinapi.appcore.dll" );
3642
+ if (greDir) {
3643
+ // Prefetch the DLLs shipped with firefox
3644
+ ReadAheadPackagedDll (L" libegl.dll" , greDir.get ());
3645
+ ReadAheadPackagedDll (L" libGLESv2.dll" , greDir.get ());
3646
+ ReadAheadPackagedDll (L" nssckbi.dll" , greDir.get ());
3647
+ ReadAheadPackagedDll (L" freebl3.dll" , greDir.get ());
3648
+ ReadAheadPackagedDll (L" softokn3.dll" , greDir.get ());
3649
+
3650
+ // Prefetch the system DLLs
3651
+ ReadAheadSystemDll (L" DWrite.dll" );
3652
+ ReadAheadSystemDll (L" D3DCompiler_47.dll" );
3653
+ } else {
3654
+ // Load DataExchange.dll and twinapi.appcore.dll for
3655
+ // nsWindow::EnableDragDrop
3656
+ ReadAheadSystemDll (L" DataExchange.dll" );
3657
+ ReadAheadSystemDll (L" twinapi.appcore.dll" );
3637
3658
3638
- // Load twinapi.dll for WindowsUIUtils::UpdateTabletModeState
3639
- ReadAheadSystemDll (L" twinapi.dll" );
3659
+ // Load twinapi.dll for WindowsUIUtils::UpdateTabletModeState
3660
+ ReadAheadSystemDll (L" twinapi.dll" );
3640
3661
3641
- // Load explorerframe.dll for WinTaskbar::Initialize
3642
- ReadAheadSystemDll (L" ExplorerFrame.dll" );
3662
+ // Load explorerframe.dll for WinTaskbar::Initialize
3663
+ ReadAheadSystemDll (L" ExplorerFrame.dll" );
3643
3664
3644
- // Load WinTypes.dll for nsOSHelperAppService::GetApplicationDescription
3645
- ReadAheadSystemDll (L" WinTypes.dll" );
3646
- # endif
3665
+ // Load WinTypes.dll for nsOSHelperAppService::GetApplicationDescription
3666
+ ReadAheadSystemDll (L" WinTypes.dll" );
3667
+ }
3647
3668
}
3648
3669
#endif
3649
3670
@@ -4335,14 +4356,29 @@ nsresult XREMain::XRE_mainRun() {
4335
4356
}
4336
4357
4337
4358
#ifdef XP_WIN
4338
- if (!PR_GetEnv (" XRE_NO_DLL_READAHEAD" )) {
4359
+ mozilla::DllPrefetchExperimentRegistryInfo prefetchRegInfo;
4360
+ mozilla::AlteredDllPrefetchMode dllPrefetchMode =
4361
+ prefetchRegInfo.GetAlteredDllPrefetchMode ();
4362
+
4363
+ if (!PR_GetEnv (" XRE_NO_DLL_READAHEAD" ) &&
4364
+ dllPrefetchMode != mozilla::AlteredDllPrefetchMode::NoPrefetch) {
4339
4365
nsCOMPtr<nsIFile> greDir = mDirProvider .GetGREDir ();
4340
4366
nsAutoString path;
4341
4367
rv = greDir->GetPath (path);
4342
4368
if (NS_SUCCEEDED(rv)) {
4343
4369
PRThread* readAheadThread;
4344
- wchar_t * pathRaw = new wchar_t [MAX_PATH];
4345
- wcscpy_s (pathRaw, MAX_PATH, path.get ());
4370
+ wchar_t * pathRaw;
4371
+
4372
+ // We use the presence of a path argument inside the thread to determine
4373
+ // which list of Dlls to use. The old list does not need access to the
4374
+ // GRE dir, so the path argument is set to a null pointer.
4375
+ if (dllPrefetchMode ==
4376
+ mozilla::AlteredDllPrefetchMode::OptimizedPrefetch) {
4377
+ pathRaw = new wchar_t [MAX_PATH];
4378
+ wcscpy_s (pathRaw, MAX_PATH, path.get ());
4379
+ } else {
4380
+ pathRaw = nullptr ;
4381
+ }
4346
4382
readAheadThread = PR_CreateThread (
4347
4383
PR_USER_THREAD, ReadAheadDlls_ThreadStart, (void *)pathRaw,
4348
4384
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0 );
@@ -4550,6 +4586,7 @@ nsresult XREMain::XRE_mainRun() {
4550
4586
#ifdef XP_WIN
4551
4587
Preferences::RegisterCallbackAndCall (RegisterApplicationRestartChanged,
4552
4588
PREF_WIN_REGISTER_APPLICATION_RESTART);
4589
+ SetupAlteredPrefetchPref ();
4553
4590
# if defined(MOZ_LAUNCHER_PROCESS)
4554
4591
SetupLauncherProcessPref ();
4555
4592
# endif // defined(MOZ_LAUNCHER_PROCESS)
0 commit comments