sigsys_handlers.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file.
4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_
6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/basictypes.h"
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "build/build_config.h"
10c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "sandbox/linux/sandbox_export.h"
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The handlers are suitable for use in Trap() error codes. They are
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// guaranteed to be async-signal safe.
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// See sandbox/linux/seccomp-bpf/trap.h to see how they work.
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace sandbox {
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)struct arch_seccomp_data;
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will crash the currently running process. The crashing address
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// will be the number of the current system call, extracted from |args|.
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will also print to stderr the number of the crashing syscall.
23c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t
24c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux);
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The following three handlers are suitable to report failures with the
27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// clone(), prctl() and ioctl() system calls respectively.
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (clone_flags & 0xFFFFFF), where clone_flags is
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the clone(2) argument, extracted from |args|.
31c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t
32c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    SIGSYSCloneFailure(const struct arch_seccomp_data& args, void* aux);
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (option & 0xFFF), where option is the prctl(2)
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument.
35c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t
36c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    SIGSYSPrctlFailure(const struct arch_seccomp_data& args, void* aux);
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be request & 0xFFFF, where request is the ioctl(2)
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument.
39c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t
40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    SIGSYSIoctlFailure(const struct arch_seccomp_data& args, void* aux);
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace sandbox.
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_
45