/* 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/. */
// Install the alternate signal stack, returns a pointer to the memory area we // mapped to store the stack only if it was installed successfully, otherwise // returns NULL. staticvoid* install_sig_alt_stack(size_t size) { void* alt_stack_mem = mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (alt_stack_mem) {
stack_t alt_stack = {
.ss_sp = alt_stack_mem,
.ss_flags = 0,
.ss_size = size,
};
int rv = sigaltstack(&alt_stack, nullptr); if (rv == 0) { return alt_stack_mem;
}
// Uninstall the alternate signal handler and unmaps it. Does nothing if // alt_stack_mem is NULL. staticvoid uninstall_sig_alt_stack(void* alt_stack_ptr) {
SigAltStack* alt_stack = static_cast<SigAltStack*>(alt_stack_ptr); if (alt_stack->mem) {
stack_t disable_alt_stack = {};
disable_alt_stack.ss_flags = SS_DISABLE;
DebugOnly<int> rv = sigaltstack(&disable_alt_stack, nullptr);
MOZ_ASSERT(rv == 0);
rv = munmap(alt_stack->mem, alt_stack->size);
MOZ_ASSERT(rv == 0);
}
}
// This replaces the routine passed to pthread_create() when a thread is // started, it handles the alternate signal stack and calls the thread's // actual routine. void* set_alt_signal_stack_and_start(PthreadCreateParams* params) { void* (*start_routine)(void*) = params->start_routine; void* arg = params->arg;
free(params);
extern"C" { // This interposer replaces libpthread's pthread_create() so that we can // inject an alternate signal stack in every new thread.
MFBT_API int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_routine)(void*), void* arg) { staticconstauto real_pthread_create = GET_REAL_SYMBOL(pthread_create);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.