Skip to content

Commit 4a4a3be

Browse files
committed
Bug 1880373 - cache the CPU frequency in ProcInfo_win before enabling the sandbox in utility processes, r=gerard-majax.
Depends on D201884 Differential Revision: https://phabricator.services.mozilla.com/D201885
1 parent 3c7da68 commit 4a4a3be

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

ipc/glue/UtilityProcessImpl.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "mozilla/ipc/IOThreadChild.h"
99
#include "mozilla/GeckoArgs.h"
10+
#include "mozilla/ProcInfo.h"
1011

1112
#if defined(XP_WIN)
1213
# include "nsExceptionHandler.h"
@@ -90,6 +91,10 @@ bool UtilityProcessImpl::Init(int aArgc, char* aArgv[]) {
9091
// lower the sandbox in processes where the policy will prevent loading.
9192
LoadLibraryOrCrash(L"winmm.dll");
9293

94+
// Call this once before enabling the sandbox, it will cache its result
95+
// in a static variable.
96+
GetCpuFrequencyMHz();
97+
9398
if (*sandboxingKind == SandboxingKind::GENERIC_UTILITY) {
9499
// Preload audio generic libraries required for ffmpeg only
95100
UtilityAudioDecoderParent::GenericPreloadForSandbox();

toolkit/components/processtools/ProcInfo.h

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ using UtilityActorName = mozilla::dom::WebIDLUtilityActorName;
7373
// String that will be used e.g. to annotate crash reports
7474
nsCString GetUtilityActorName(const UtilityActorName aActorName);
7575

76+
#ifdef XP_WIN
77+
int GetCpuFrequencyMHz();
78+
#endif
79+
7680
/* Get the CPU frequency to use to convert cycle time values to actual time.
7781
* @returns the TSC (Time Stamp Counter) frequency in MHz, or 0 if converting
7882
* cycle time values should not be attempted. */

toolkit/components/processtools/ProcInfo_win.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,9 @@ static uint64_t ToNanoSeconds(const FILETIME& aFileTime) {
3232
return usec.QuadPart * 100;
3333
}
3434

35-
int GetCycleTimeFrequencyMHz() {
35+
int GetCpuFrequencyMHz() {
3636
static const int frequency = []() {
37-
// Having a constant TSC is required to convert cycle time to actual time.
38-
// In automation, having short CPU times reported as 0 is more of a problem
39-
// than having an imprecise value. The fallback method can't report CPU
40-
// times < 1/64s.
41-
if (!mozilla::has_constant_tsc() && !xpc::IsInAutomation()) {
42-
return 0;
43-
}
44-
45-
// Now get the nominal CPU frequency.
37+
// Get the nominal CPU frequency.
4638
HKEY key;
4739
static const WCHAR keyName[] =
4840
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
@@ -64,6 +56,22 @@ int GetCycleTimeFrequencyMHz() {
6456
return frequency;
6557
}
6658

59+
int GetCycleTimeFrequencyMHz() {
60+
static const int frequency = []() {
61+
// Having a constant TSC is required to convert cycle time to actual time.
62+
// In automation, having short CPU times reported as 0 is more of a problem
63+
// than having an imprecise value. The fallback method can't report CPU
64+
// times < 1/64s.
65+
if (!mozilla::has_constant_tsc() && !xpc::IsInAutomation()) {
66+
return 0;
67+
}
68+
69+
return GetCpuFrequencyMHz();
70+
}();
71+
72+
return frequency;
73+
}
74+
6775
nsresult GetCpuTimeSinceProcessStartInMs(uint64_t* aResult) {
6876
int frequencyInMHz = GetCycleTimeFrequencyMHz();
6977
if (frequencyInMHz) {

0 commit comments

Comments
 (0)