Backed out 2 changesets (bug 1752703) for mochitest failures . CLOSED TREE

Backed out changeset 4ecb79ef23ae (bug 1752703)
Backed out changeset 1701c20a5da3 (bug 1752703)
This commit is contained in:
Narcis Beleuzu 2023-05-10 00:58:30 +03:00
Родитель f9cc14ad1a
Коммит 82d0ebe862
11 изменённых файлов: 50 добавлений и 161 удалений

Просмотреть файл

@ -53,6 +53,11 @@ LOCAL_INCLUDES += [
"/xpcom/build", "/xpcom/build",
] ]
# The pthred_create() interposer needs to be linked as early as possible so
# that it will appear before libpthread when resolving symbols.
if CONFIG["OS_ARCH"] == "Linux" and CONFIG["MOZ_CRASHREPORTER"]:
USE_LIBS += ["pthread_create_interposer"]
if CONFIG["LIBFUZZER"]: if CONFIG["LIBFUZZER"]:
USE_LIBS += ["fuzzer"] USE_LIBS += ["fuzzer"]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [

Просмотреть файл

@ -16,6 +16,11 @@ else:
"MozillaRuntimeMain.cpp", "MozillaRuntimeMain.cpp",
] ]
# The pthred_create() interposer needs to be linked as early as possible so
# that it will appear before libpthread when resolving symbols.
if CONFIG["OS_ARCH"] == "Linux" and CONFIG["MOZ_CRASHREPORTER"]:
USE_LIBS += ["pthread_create_interposer"]
include("/ipc/chromium/chromium-config.mozbuild") include("/ipc/chromium/chromium-config.mozbuild")
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [

Просмотреть файл

@ -155,7 +155,6 @@ rsync_filter_list = """
+ /mozglue/baseprofiler/** + /mozglue/baseprofiler/**
+ /mozglue/build/** + /mozglue/build/**
+ /mozglue/interposers/**
+ /mozglue/misc/** + /mozglue/misc/**
+ /mozglue/moz.build + /mozglue/moz.build
+ /mozglue/static/** + /mozglue/static/**

Просмотреть файл

@ -10,6 +10,11 @@ SOURCES += [
"xpcshell.cpp", "xpcshell.cpp",
] ]
# The pthred_create() interposer needs to be linked as early as possible so
# that it will appear before libpthread when resolving symbols.
if CONFIG["OS_ARCH"] == "Linux" and CONFIG["MOZ_CRASHREPORTER"]:
USE_LIBS += ["pthread_create_interposer"]
if CONFIG["LIBFUZZER"]: if CONFIG["LIBFUZZER"]:
USE_LIBS += ["fuzzer"] USE_LIBS += ["fuzzer"]

Просмотреть файл

@ -1,66 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef InterposerHelper_h
#define InterposerHelper_h
#include <type_traits>
#ifdef MOZ_LINKER
# include "Linker.h"
#else
# include <dlfcn.h>
#endif
#include "mozilla/Assertions.h"
template <typename T>
static inline T dlsym_wrapper(void* aHandle, const char* aName) {
#ifdef MOZ_LINKER
return reinterpret_cast<T>(__wrap_dlsym(aHandle, aName));
#else
return reinterpret_cast<T>(dlsym(aHandle, aName));
#endif // MOZ_LINKER
}
template <typename T>
static T get_real_symbol(const char* aName, T aReplacementSymbol) {
// T can only be a function pointer
static_assert(std::is_function<typename std::remove_pointer<T>::type>::value);
// Find the corresponding function in the linked libraries
T real_symbol = dlsym_wrapper<T>(RTLD_NEXT, aName);
#if defined(ANDROID)
if (real_symbol == nullptr) {
// On old versions of Android the application runtime links in libc before
// we get a chance to link libmozglue, so its symbols don't appear when
// resolving them with RTLD_NEXT but rather with RTLD_DEFAULT. If RTLD_NEXT
// failed to find a symbol we try again with RTLD_DEFAULT. The checks below
// make sure that we crash in case the symbol we get matches the
// replacement one so this is safe albeit a bit weird.
real_symbol = dlsym_wrapper<T>(RTLD_DEFAULT, aName);
}
#endif
if (real_symbol == nullptr) {
MOZ_CRASH_UNSAFE_PRINTF(
"%s() interposition failed but the interposer function is "
"still being called, this won't work!",
aName);
}
if (real_symbol == aReplacementSymbol) {
MOZ_CRASH_UNSAFE_PRINTF(
"We could not obtain the real %s(). Calling the symbol we "
"got would make us enter an infinite loop so stop here instead.",
aName);
}
return real_symbol;
}
#define GET_REAL_SYMBOL(name) get_real_symbol(#name, name)
#endif // InterposerHelper_h

Просмотреть файл

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <pthread.h>
#include "InterposerHelper.h"
// The interposers in this file cover all the functions used to access the
// environment (getenv(), putenv(), setenv(), unsetenv() and clearenv()). They
// all use the mutex below for synchronization to prevent races that caused
// startup crashes, see bug 1752703.
static pthread_mutex_t gEnvLock = PTHREAD_MUTEX_INITIALIZER;
extern "C" {
MFBT_API char* getenv(const char* name) {
static const auto real_getenv = GET_REAL_SYMBOL(getenv);
pthread_mutex_lock(&gEnvLock);
char* result = real_getenv(name);
pthread_mutex_unlock(&gEnvLock);
return result;
}
MFBT_API int putenv(char* string) {
static const auto real_putenv = GET_REAL_SYMBOL(putenv);
pthread_mutex_lock(&gEnvLock);
int result = real_putenv(string);
pthread_mutex_unlock(&gEnvLock);
return result;
}
MFBT_API int setenv(const char* name, const char* value, int replace) {
static const auto real_setenv = GET_REAL_SYMBOL(setenv);
pthread_mutex_lock(&gEnvLock);
int result = real_setenv(name, value, replace);
pthread_mutex_unlock(&gEnvLock);
return result;
}
MFBT_API int unsetenv(const char* name) {
static const auto real_unsetenv = GET_REAL_SYMBOL(unsetenv);
pthread_mutex_lock(&gEnvLock);
int result = real_unsetenv(name);
pthread_mutex_unlock(&gEnvLock);
return result;
}
MFBT_API int clearenv(void) {
static const auto real_clearenv = GET_REAL_SYMBOL(clearenv);
pthread_mutex_lock(&gEnvLock);
int result = real_clearenv();
pthread_mutex_unlock(&gEnvLock);
return result;
}
} // extern "C"

Просмотреть файл

@ -1,24 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Library("interposers")
DEFINES["IMPL_MFBT"] = True
UNIFIED_SOURCES += [
"env_interposer.cpp",
]
if CONFIG["MOZ_CRASHREPORTER"]:
UNIFIED_SOURCES += [
"pthread_create_interposer.cpp",
]
if CONFIG["MOZ_LINKER"] and CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
LOCAL_INCLUDES += [
"/mozglue/linker",
]
FINAL_LIBRARY = "mozglue"

Просмотреть файл

@ -13,9 +13,6 @@ if CONFIG["MOZ_LINKER"] or CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android": if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
DIRS += ["android"] DIRS += ["android"]
if CONFIG["OS_ARCH"] == "Linux":
DIRS += ["interposers"]
DIRS += [ DIRS += [
"baseprofiler", "baseprofiler",
"build", "build",

Просмотреть файл

@ -53,6 +53,7 @@ if CONFIG["MOZ_CRASHREPORTER"]:
"google-breakpad/src/common", "google-breakpad/src/common",
"google-breakpad/src/common/linux", "google-breakpad/src/common/linux",
"google-breakpad/src/processor", "google-breakpad/src/processor",
"pthread_create_interposer",
] ]
if CONFIG["MOZ_OXIDIZED_BREAKPAD"]: if CONFIG["MOZ_OXIDIZED_BREAKPAD"]:

Просмотреть файл

@ -0,0 +1,12 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Library("pthread_create_interposer")
NoVisibilityFlags()
UNIFIED_SOURCES += [
"pthread_create_interposer.cpp",
]

Просмотреть файл

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <dlfcn.h>
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
@ -12,8 +13,6 @@
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/DebugOnly.h" #include "mozilla/DebugOnly.h"
#include "InterposerHelper.h"
using mozilla::DebugOnly; using mozilla::DebugOnly;
struct SigAltStack { struct SigAltStack {
@ -84,12 +83,30 @@ void* set_alt_signal_stack_and_start(PthreadCreateParams* params) {
return thread_rv; return thread_rv;
} }
using pthread_create_func_t = int (*)(pthread_t*, const pthread_attr_t*,
void* (*)(void*), void*);
extern "C" { extern "C" {
// This interposer replaces libpthread's pthread_create() so that we can // This interposer replaces libpthread's pthread_create() so that we can
// inject an alternate signal stack in every new thread. // inject an alternate signal stack in every new thread.
MFBT_API int pthread_create(pthread_t* thread, const pthread_attr_t* attr, __attribute__((visibility("default"))) int pthread_create(
void* (*start_routine)(void*), void* arg) { pthread_t* thread, const pthread_attr_t* attr,
static const auto real_pthread_create = GET_REAL_SYMBOL(pthread_create); void* (*start_routine)(void*), void* arg) {
// static const pthread_create_func_t real_pthread_create =
static const pthread_create_func_t real_pthread_create =
(pthread_create_func_t)dlsym(RTLD_NEXT, "pthread_create");
if (real_pthread_create == nullptr) {
MOZ_CRASH(
"pthread_create() interposition failed but the interposer function is "
"still being called, this won't work!");
}
if (real_pthread_create == pthread_create) {
MOZ_CRASH(
"We could not obtain the real pthread_create(). Calling the symbol we "
"got would make us enter an infinte loop so stop here instead.");
}
PthreadCreateParams* params = PthreadCreateParams* params =
(PthreadCreateParams*)malloc(sizeof(PthreadCreateParams)); (PthreadCreateParams*)malloc(sizeof(PthreadCreateParams));