Bug 1666222: Rip fuzzyfox out of the timestamp classes 2/5 r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D119637
This commit is contained in:
Tom Ritter 2021-07-14 18:18:16 +00:00
parent 701266cef6
commit 42c0ec86b4
10 changed files with 20 additions and 187 deletions

View File

@ -1374,8 +1374,6 @@ pref("services.sync.prefs.sync.privacy.clearOnShutdown.offlineApps", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.sessions", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.siteSettings", true);
pref("services.sync.prefs.sync.privacy.donottrackheader.enabled", true);
pref("services.sync.prefs.sync.privacy.fuzzyfox.enabled", false);
pref("services.sync.prefs.sync.privacy.fuzzyfox.clockgrainus", false);
pref("services.sync.prefs.sync.privacy.sanitize.sanitizeOnShutdown", true);
pref("services.sync.prefs.sync.privacy.trackingprotection.enabled", true);
pref("services.sync.prefs.sync.privacy.trackingprotection.cryptomining.enabled", true);

View File

@ -666,7 +666,6 @@ struct ParamTraits<mozilla::TimeStampValue> {
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mGTC);
WriteParam(aMsg, aParam.mQPC);
WriteParam(aMsg, aParam.mUsedCanonicalNow);
WriteParam(aMsg, aParam.mIsNull);
WriteParam(aMsg, aParam.mHasQPC);
}
@ -674,36 +673,11 @@ struct ParamTraits<mozilla::TimeStampValue> {
paramType* aResult) {
return (ReadParam(aMsg, aIter, &aResult->mGTC) &&
ReadParam(aMsg, aIter, &aResult->mQPC) &&
ReadParam(aMsg, aIter, &aResult->mUsedCanonicalNow) &&
ReadParam(aMsg, aIter, &aResult->mIsNull) &&
ReadParam(aMsg, aIter, &aResult->mHasQPC));
}
};
#else
template <>
struct ParamTraits<mozilla::TimeStamp63Bit> {
typedef mozilla::TimeStamp63Bit paramType;
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mUsedCanonicalNow);
WriteParam(aMsg, aParam.mTimeStamp);
}
static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
bool success = true;
uint64_t result;
success &= ReadParam(aMsg, aIter, &result);
aResult->mUsedCanonicalNow = result & 0x01;
success &= ReadParam(aMsg, aIter, &result);
aResult->mTimeStamp = result & 0x7FFFFFFFFFFFFFFF;
return success;
}
};
#endif
template <>

View File

@ -681,11 +681,7 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer {
// monotonic because the underlying system apis produce non-monontonic
// results. (bug 1306896)
#if !defined(_WIN32)
// Do not compare timestamps unless they are both canonical or fuzzy
DebugOnly<TimeStamp> rightnow = TimeStamp::Now();
MOZ_ASSERT_IF(
(*&rightnow).UsedCanonicalNow() == aVsyncTimestamp.UsedCanonicalNow(),
aVsyncTimestamp <= *&rightnow);
MOZ_ASSERT(aVsyncTimestamp <= TimeStamp::Now());
#endif
// Let also non-RefreshDriver code to run at least for awhile if we have

View File

@ -45,29 +45,6 @@ struct TimeStampInitialization {
~TimeStampInitialization() { TimeStamp::Shutdown(); };
};
static bool sFuzzyfoxEnabled;
/* static */
bool TimeStamp::GetFuzzyfoxEnabled() { return sFuzzyfoxEnabled; }
/* static */
void TimeStamp::SetFuzzyfoxEnabled(bool aValue) { sFuzzyfoxEnabled = aValue; }
// These variables store the frozen time (as a TimeStamp) for FuzzyFox that
// will be reported if FuzzyFox is enabled.
// We overload the top bit of sCanonicalNow and sCanonicalGTC to
// indicate if a Timestamp is a fuzzed timestamp (bit set) or not
// (bit unset).
#ifdef XP_WIN
static Atomic<uint64_t> sCanonicalGTC;
static Atomic<uint64_t> sCanonicalQPC;
static Atomic<bool> sCanonicalHasQPC;
#else
static Atomic<uint64_t> sCanonicalNowTimeStamp;
#endif
static Atomic<int64_t> sCanonicalNowTime;
// This variable stores the frozen time (as ms since the epoch) for FuzzyFox
// to report if FuzzyFox is enabled.
static TimeStampInitialization sInitOnce;
MFBT_API TimeStamp TimeStamp::ProcessCreation(bool* aIsInconsistent) {
@ -113,42 +90,4 @@ void TimeStamp::RecordProcessRestart() {
sInitOnce.mProcessCreation = TimeStamp();
}
MFBT_API TimeStamp TimeStamp::NowFuzzy(TimeStampValue aValue) {
#ifdef XP_WIN
TimeStampValue canonicalNow =
TimeStampValue(sCanonicalGTC, sCanonicalQPC, sCanonicalHasQPC, true);
#else
TimeStampValue canonicalNow = TimeStampValue(sCanonicalNowTimeStamp);
#endif
if (TimeStamp::GetFuzzyfoxEnabled()) {
if (MOZ_LIKELY(!canonicalNow.IsNull())) {
return TimeStamp(canonicalNow);
}
}
// When we disable Fuzzyfox, time may goes backwards, so we need to make sure
// we don't do that.
else if (MOZ_UNLIKELY(canonicalNow > aValue)) {
return TimeStamp(canonicalNow);
}
return TimeStamp(aValue);
}
MFBT_API void TimeStamp::UpdateFuzzyTimeStamp(TimeStamp aValue) {
#ifdef XP_WIN
sCanonicalGTC = aValue.mValue.mGTC;
sCanonicalQPC = aValue.mValue.mQPC;
sCanonicalHasQPC = aValue.mValue.mHasQPC;
#else
sCanonicalNowTimeStamp = aValue.mValue.mTimeStamp;
#endif
}
MFBT_API int64_t TimeStamp::NowFuzzyTime() { return sCanonicalNowTime; }
MFBT_API void TimeStamp::UpdateFuzzyTime(int64_t aValue) {
sCanonicalNowTime = aValue;
}
} // namespace mozilla

View File

@ -30,36 +30,7 @@ struct ParamTraits;
namespace mozilla {
#ifndef XP_WIN
struct TimeStamp63Bit {
uint64_t mUsedCanonicalNow : 1;
uint64_t mTimeStamp : 63;
constexpr TimeStamp63Bit() : mUsedCanonicalNow(0), mTimeStamp(0) {}
MOZ_IMPLICIT constexpr TimeStamp63Bit(const uint64_t aValue)
: mUsedCanonicalNow(0), mTimeStamp(aValue) {}
constexpr TimeStamp63Bit(const bool aUsedCanonicalNow,
const int64_t aTimeStamp)
: mUsedCanonicalNow(aUsedCanonicalNow ? 1 : 0), mTimeStamp(aTimeStamp) {}
bool operator==(const TimeStamp63Bit aOther) const {
uint64_t here, there;
memcpy(&here, this, sizeof(TimeStamp63Bit));
memcpy(&there, &aOther, sizeof(TimeStamp63Bit));
return here == there;
}
operator uint64_t() const { return mTimeStamp; }
bool IsNull() const { return mTimeStamp == 0; }
bool UsedCanonicalNow() const { return mUsedCanonicalNow; }
void SetCanonicalNow() { mUsedCanonicalNow = 1; }
};
typedef TimeStamp63Bit TimeStampValue;
typedef uint64_t TimeStampValue;
#endif
class TimeStamp;
@ -397,7 +368,7 @@ class TimeStamp {
/**
* Initialize to the "null" moment
*/
constexpr TimeStamp() : mValue() {}
constexpr TimeStamp() : mValue(0) {}
// Default copy-constructor and assignment are OK
/**
@ -417,24 +388,20 @@ class TimeStamp {
static TimeStamp FromSystemTime(int64_t aSystemTime) {
static_assert(sizeof(aSystemTime) == sizeof(TimeStampValue),
"System timestamp should be same units as TimeStampValue");
return TimeStamp(TimeStampValue(false, aSystemTime));
return TimeStamp(aSystemTime);
}
#endif
/**
* Return true if this is the "null" moment
*/
bool IsNull() const { return mValue.IsNull(); }
bool IsNull() const { return mValue == 0; }
/**
* Return true if this is not the "null" moment, may be used in tests, e.g.:
* |if (timestamp) { ... }|
*/
explicit operator bool() const { return !IsNull(); }
bool UsedCanonicalNow() const { return mValue.UsedCanonicalNow(); }
static MFBT_API bool GetFuzzyfoxEnabled();
static MFBT_API void SetFuzzyfoxEnabled(bool aValue);
explicit operator bool() const { return mValue != 0; }
/**
* Return a timestamp reflecting the current elapsed system time. This
@ -451,9 +418,7 @@ class TimeStamp {
*/
static TimeStamp Now() { return Now(true); }
static TimeStamp NowLoRes() { return Now(false); }
static TimeStamp NowUnfuzzed() { return NowUnfuzzed(true); }
static MFBT_API int64_t NowFuzzyTime();
/**
* Return a timestamp representing the time when the current process was
* created which will be comparable with other timestamps taken with this
@ -513,10 +478,7 @@ class TimeStamp {
// (We don't check for overflow because it's not obvious what the error
// behavior should be in that case.)
if (aOther.mValue < 0 && value > mValue) {
value = TimeStampValue();
}
if (mValue.UsedCanonicalNow()) {
value.SetCanonicalNow();
value = 0;
}
mValue = value;
return *this;
@ -528,10 +490,7 @@ class TimeStamp {
// (We don't check for overflow because it's not obvious what the error
// behavior should be in that case.)
if (aOther.mValue > 0 && value > mValue) {
value = TimeStampValue();
}
if (mValue.UsedCanonicalNow()) {
value.SetCanonicalNow();
value = 0;
}
mValue = value;
return *this;
@ -576,11 +535,6 @@ class TimeStamp {
MOZ_IMPLICIT TimeStamp(TimeStampValue aValue) : mValue(aValue) {}
static MFBT_API TimeStamp Now(bool aHighResolution);
static MFBT_API TimeStamp NowUnfuzzed(bool aHighResolution);
static MFBT_API TimeStamp NowFuzzy(TimeStampValue aValue);
static MFBT_API void UpdateFuzzyTime(int64_t aValue);
static MFBT_API void UpdateFuzzyTimeStamp(TimeStamp aValue);
/**
* Computes the uptime of the current process in microseconds. The result
@ -606,8 +560,6 @@ class TimeStamp {
* When using a system clock, a value is system dependent.
*/
TimeStampValue mValue;
friend class Fuzzyfox;
};
} // namespace mozilla

View File

@ -143,11 +143,7 @@ void TimeStamp::Startup() {
void TimeStamp::Shutdown() {}
TimeStamp TimeStamp::Now(bool aHighResolution) {
return TimeStamp::NowFuzzy(TimeStampValue(false, ClockTime()));
}
TimeStamp TimeStamp::NowUnfuzzed(bool aHighResolution) {
return TimeStamp(TimeStampValue(false, ClockTime()));
return TimeStamp(ClockTime());
}
// Computes and returns the process uptime in microseconds.

View File

@ -189,11 +189,7 @@ void TimeStamp::Startup() {
void TimeStamp::Shutdown() {}
TimeStamp TimeStamp::Now(bool aHighResolution) {
return TimeStamp::NowFuzzy(TimeStampValue(false, ClockTimeNs()));
}
TimeStamp TimeStamp::NowUnfuzzed(bool aHighResolution) {
return TimeStamp(TimeStampValue(false, ClockTimeNs()));
return TimeStamp(ClockTimeNs());
}
#if defined(XP_LINUX) || defined(ANDROID)

View File

@ -255,12 +255,8 @@ static void InitResolution() {
// TimeStampValue implementation
// ----------------------------------------------------------------------------
MFBT_API
TimeStampValue::TimeStampValue(ULONGLONG aGTC, ULONGLONG aQPC, bool aHasQPC,
bool aUsedCanonicalNow)
: mGTC(aGTC),
mQPC(aQPC),
mUsedCanonicalNow(aUsedCanonicalNow),
mHasQPC(aHasQPC) {
TimeStampValue::TimeStampValue(ULONGLONG aGTC, ULONGLONG aQPC, bool aHasQPC)
: mGTC(aGTC), mQPC(aQPC), mHasQPC(aHasQPC) {
mIsNull = aGTC == 0 && aQPC == 0;
}
@ -494,14 +490,10 @@ TimeStampValue NowInternal(bool aHighResolution) {
// Both values are in [mt] units.
ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0);
ULONGLONG GTC = ms2mt(GetTickCount64());
return TimeStampValue(GTC, QPC, useQPC, false);
return TimeStampValue(GTC, QPC, useQPC);
}
MFBT_API TimeStamp TimeStamp::Now(bool aHighResolution) {
return TimeStamp::NowFuzzy(NowInternal(aHighResolution));
}
MFBT_API TimeStamp TimeStamp::NowUnfuzzed(bool aHighResolution) {
return TimeStamp(NowInternal(aHighResolution));
}

View File

@ -38,38 +38,31 @@ class TimeStampValue {
friend bool IsCanonicalTimeStamp(TimeStampValue);
friend struct IPC::ParamTraits<mozilla::TimeStampValue>;
friend class TimeStamp;
friend class Fuzzyfox;
// Both QPC and GTC are kept in [mt] units.
uint64_t mGTC;
uint64_t mQPC;
bool mUsedCanonicalNow;
bool mIsNull;
bool mHasQPC;
MFBT_API TimeStampValue(uint64_t aGTC, uint64_t aQPC, bool aHasQPC,
bool aUsedCanonicalNow);
MFBT_API TimeStampValue(uint64_t aGTC, uint64_t aQPC, bool aHasQPC);
MFBT_API uint64_t CheckQPC(const TimeStampValue& aOther) const;
constexpr MOZ_IMPLICIT TimeStampValue()
: mGTC(0),
mQPC(0),
mUsedCanonicalNow(false),
mIsNull(true),
mHasQPC(false) {}
// This struct is used to allow doing TimeStampValue a = 0 and similar
struct _SomethingVeryRandomHere;
constexpr MOZ_IMPLICIT TimeStampValue(_SomethingVeryRandomHere* aNullValue)
: mGTC(0), mQPC(0), mIsNull(true), mHasQPC(false) {}
public:
MFBT_API uint64_t operator-(const TimeStampValue& aOther) const;
TimeStampValue operator+(const int64_t aOther) const {
return TimeStampValue(mGTC + aOther, mQPC + aOther, mHasQPC,
mUsedCanonicalNow);
return TimeStampValue(mGTC + aOther, mQPC + aOther, mHasQPC);
}
TimeStampValue operator-(const int64_t aOther) const {
return TimeStampValue(mGTC - aOther, mQPC - aOther, mHasQPC,
mUsedCanonicalNow);
return TimeStampValue(mGTC - aOther, mQPC - aOther, mHasQPC);
}
MFBT_API TimeStampValue& operator+=(const int64_t aOther);
MFBT_API TimeStampValue& operator-=(const int64_t aOther);
@ -92,8 +85,6 @@ class TimeStampValue {
bool operator!=(const TimeStampValue& aOther) const {
return int64_t(*this - aOther) != 0;
}
bool UsedCanonicalNow() const { return mUsedCanonicalNow; }
void SetCanonicalNow() { mUsedCanonicalNow = true; }
bool IsNull() const { return mIsNull; }
};

View File

@ -313,7 +313,6 @@ const DEFAULT_ENVIRONMENT_PREFS = new Map([
["pdfjs.disabled", { what: RECORD_PREF_VALUE }],
["places.history.enabled", { what: RECORD_PREF_VALUE }],
["plugins.show_infobar", { what: RECORD_PREF_VALUE }],
["privacy.fuzzyfox.enabled", { what: RECORD_PREF_VALUE }],
["privacy.firstparty.isolate", { what: RECORD_PREF_VALUE }],
["privacy.resistFingerprinting", { what: RECORD_PREF_VALUE }],
["privacy.trackingprotection.enabled", { what: RECORD_PREF_VALUE }],