Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: sandbox/linux/seccomp-bpf/sandbox_bpf.h

Issue 10827223: Add basic ARM support to the seccomp-bpf sandbox. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix ARM sigcontext_t comment. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/sandbox_linux.gypi ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SANDBOX_BPF_H__ 5 #ifndef SANDBOX_BPF_H__
6 #define SANDBOX_BPF_H__ 6 #define SANDBOX_BPF_H__
7 7
8 #include <endian.h> 8 #include <endian.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Impose some reasonable maximum BPF program size. Realistically, the 77 // Impose some reasonable maximum BPF program size. Realistically, the
78 // kernel probably has much lower limits. But by limiting to less than 78 // kernel probably has much lower limits. But by limiting to less than
79 // 30 bits, we can ease requirements on some of our data types. 79 // 30 bits, we can ease requirements on some of our data types.
80 #define SECCOMP_MAX_PROGRAM_SIZE (1<<30) 80 #define SECCOMP_MAX_PROGRAM_SIZE (1<<30)
81 81
82 #if defined(__i386__) 82 #if defined(__i386__)
83 #define MIN_SYSCALL 0u 83 #define MIN_SYSCALL 0u
84 #define MAX_SYSCALL 1024u 84 #define MAX_SYSCALL 1024u
85 #define SECCOMP_ARCH AUDIT_ARCH_I386 85 #define SECCOMP_ARCH AUDIT_ARCH_I386
86 #define REG_RESULT REG_EAX 86
87 #define REG_SYSCALL REG_EAX 87 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.gregs[(_reg)])
88 #define REG_IP REG_EIP 88 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, REG_EAX)
89 #define REG_PARM1 REG_EBX 89 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, REG_EAX)
90 #define REG_PARM2 REG_ECX 90 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, REG_EIP)
91 #define REG_PARM3 REG_EDX 91 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, REG_EBX)
92 #define REG_PARM4 REG_ESI 92 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, REG_ECX)
93 #define REG_PARM5 REG_EDI 93 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, REG_EDX)
94 #define REG_PARM6 REG_EBP 94 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, REG_ESI)
95 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, REG_EDI)
96 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, REG_EBP)
97
95 #elif defined(__x86_64__) 98 #elif defined(__x86_64__)
96 #define MIN_SYSCALL 0u 99 #define MIN_SYSCALL 0u
97 #define MAX_SYSCALL 1024u 100 #define MAX_SYSCALL 1024u
98 #define SECCOMP_ARCH AUDIT_ARCH_X86_64 101 #define SECCOMP_ARCH AUDIT_ARCH_X86_64
99 #define REG_RESULT REG_RAX 102
100 #define REG_SYSCALL REG_RAX 103 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.gregs[(_reg)])
101 #define REG_IP REG_RIP 104 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, REG_RAX)
102 #define REG_PARM1 REG_RDI 105 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, REG_RAX)
103 #define REG_PARM2 REG_RSI 106 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, REG_RIP)
104 #define REG_PARM3 REG_RDX 107 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, REG_RDI)
105 #define REG_PARM4 REG_R10 108 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, REG_RSI)
106 #define REG_PARM5 REG_R8 109 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, REG_RDX)
107 #define REG_PARM6 REG_R9 110 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, REG_R10)
111 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, REG_R8)
112 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, REG_R9)
113
114 #elif defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__))
115 // ARM EABI includes "ARM private" system calls starting at |__ARM_NR_BASE|.
116 // See </arch/arm/include/asm/unistd.h> in the Linux kernel.
117 #define MIN_SYSCALL ((unsigned int)__NR_SYSCALL_BASE)
118 #define MAX_SYSCALL ((unsigned int)__ARM_NR_BASE + 16u)
119 // <linux/audit.h> includes <linux/elf-em.h>, which does not define EM_ARM.
120 // <linux/elf.h> only includes <asm/elf.h> if we're in the kernel.
121 # ifndef EM_ARM
Markus (顧孟勤) 2012/08/08 18:35:55 Julien pointed out to me, that our style guide app
Jorge Lucangeli Obes 2012/08/09 01:16:19 Done.
122 # define EM_ARM 40
123 # endif
124 #define SECCOMP_ARCH AUDIT_ARCH_ARM
125
126 // ARM sigcontext_t is different from i386/x86_64.
127 // See </arch/arm/include/asm/sigcontext.h> in the Linux kernel.
128 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.arm_##_reg)
129 // ARM EABI syscall convention.
130 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, r0)
131 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, r7)
132 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, pc)
133 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, r0)
134 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, r1)
135 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, r2)
136 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, r3)
137 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, r4)
138 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, r5)
139
108 #else 140 #else
109 #error Unsupported target platform 141 #error Unsupported target platform
142
110 #endif 143 #endif
111 144
112 struct arch_seccomp_data { 145 struct arch_seccomp_data {
113 int nr; 146 int nr;
114 uint32_t arch; 147 uint32_t arch;
115 uint64_t instruction_pointer; 148 uint64_t instruction_pointer;
116 uint64_t args[6]; 149 uint64_t args[6];
117 }; 150 };
118 151
119 struct arch_sigsys { 152 struct arch_sigsys {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 static Traps *traps_; 407 static Traps *traps_;
375 static TrapIds trapIds_; 408 static TrapIds trapIds_;
376 static ErrorCode *trapArray_; 409 static ErrorCode *trapArray_;
377 static size_t trapArraySize_; 410 static size_t trapArraySize_;
378 DISALLOW_IMPLICIT_CONSTRUCTORS(Sandbox); 411 DISALLOW_IMPLICIT_CONSTRUCTORS(Sandbox);
379 }; 412 };
380 413
381 } // namespace 414 } // namespace
382 415
383 #endif // SANDBOX_BPF_H__ 416 #endif // SANDBOX_BPF_H__
OLDNEW
« no previous file with comments | « sandbox/linux/sandbox_linux.gypi ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698