sigsys_handlers.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 6#define SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 7 8#include "base/basictypes.h" 9#include "build/build_config.h" 10#include "sandbox/linux/bpf_dsl/bpf_dsl.h" 11#include "sandbox/sandbox_export.h" 12 13// The handlers are suitable for use in Trap() error codes. They are 14// guaranteed to be async-signal safe. 15// See sandbox/linux/seccomp-bpf/trap.h to see how they work. 16 17namespace sandbox { 18 19struct arch_seccomp_data; 20 21// This handler will crash the currently running process. The crashing address 22// will be the number of the current system call, extracted from |args|. 23// This handler will also print to stderr the number of the crashing syscall. 24SANDBOX_EXPORT intptr_t 25 CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux); 26 27// The following three handlers are suitable to report failures with the 28// clone(), prctl() and ioctl() system calls respectively. 29 30// The crashing address will be (clone_flags & 0xFFFFFF), where clone_flags is 31// the clone(2) argument, extracted from |args|. 32SANDBOX_EXPORT intptr_t 33 SIGSYSCloneFailure(const struct arch_seccomp_data& args, void* aux); 34// The crashing address will be (option & 0xFFF), where option is the prctl(2) 35// argument. 36SANDBOX_EXPORT intptr_t 37 SIGSYSPrctlFailure(const struct arch_seccomp_data& args, void* aux); 38// The crashing address will be request & 0xFFFF, where request is the ioctl(2) 39// argument. 40SANDBOX_EXPORT intptr_t 41 SIGSYSIoctlFailure(const struct arch_seccomp_data& args, void* aux); 42// The crashing address will be (pid & 0xFFF), where pid is the first 43// argument (and can be a tid). 44SANDBOX_EXPORT intptr_t 45 SIGSYSKillFailure(const struct arch_seccomp_data& args, void* aux); 46// The crashing address will be (op & 0xFFF), where op is the second 47// argument. 48SANDBOX_EXPORT intptr_t 49 SIGSYSFutexFailure(const struct arch_seccomp_data& args, void* aux); 50 51// Variants of the above functions for use with bpf_dsl. 52SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYS(); 53SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSClone(); 54SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSPrctl(); 55SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSIoctl(); 56SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSKill(); 57SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSFutex(); 58 59// Following four functions return substrings of error messages used 60// in the above four functions. They are useful in death tests. 61SANDBOX_EXPORT const char* GetErrorMessageContentForTests(); 62SANDBOX_EXPORT const char* GetCloneErrorMessageContentForTests(); 63SANDBOX_EXPORT const char* GetPrctlErrorMessageContentForTests(); 64SANDBOX_EXPORT const char* GetIoctlErrorMessageContentForTests(); 65SANDBOX_EXPORT const char* GetKillErrorMessageContentForTests(); 66SANDBOX_EXPORT const char* GetFutexErrorMessageContentForTests(); 67 68} // namespace sandbox. 69 70#endif // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 71