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

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

Issue 260793003: [MIPS] Add seccomp bpf support (Closed) Base URL: https://git.chromium.org/git/chromium/src.git@master
Patch Set: Update per code review Created 6 years, 6 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
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_LINUX_SECCOMP_BPF_SYSCALL_H__ 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ 6 #define SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "sandbox/sandbox_export.h" 10 #include "sandbox/sandbox_export.h"
11 11
12 namespace sandbox { 12 namespace sandbox {
13 13
14 // This function will return the kernel return value on success and -errno on
15 // error on all architectures.
14 // We have to make sure that we have a single "magic" return address for 16 // We have to make sure that we have a single "magic" return address for
15 // our system calls, which we can check from within a BPF filter. This 17 // our system calls, which we can check from within a BPF filter. This
16 // works by writing a little bit of asm() code that a) enters the kernel, and 18 // works by writing a little bit of asm() code that a) enters the kernel, and
17 // that also b) can be invoked in a way that computes this return address. 19 // that also b) can be invoked in a way that computes this return address.
18 // Passing "nr" as "-1" computes the "magic" return address. Passing any 20 // Passing "nr" as "-1" computes the "magic" return address. Passing any
19 // other value invokes the appropriate system call. 21 // other value invokes the appropriate system call.
20 SANDBOX_EXPORT intptr_t SandboxSyscall(int nr, 22 SANDBOX_EXPORT intptr_t SandboxSyscall(int nr,
21 intptr_t p0, 23 intptr_t p0,
22 intptr_t p1, 24 intptr_t p1,
23 intptr_t p2, 25 intptr_t p2,
24 intptr_t p3, 26 intptr_t p3,
25 intptr_t p4, 27 intptr_t p4,
26 intptr_t p5); 28 intptr_t p5);
27 29
30 #if defined(__mips__)
31 // This function basically does on MIPS what SandboxSyscall() is doing on
32 // othere architectures. However, because of specificity of MIPS regarding
33 // handelling syscall errors, SandboxSyscall() is made as a wrapper for this
34 // function in order for SandboxSyscall() to behave more like on othere
jln (very slow on Chromium) 2014/06/13 02:47:36 nit: othere -> other
nedeljko 2014/06/18 13:41:00 Done.
35 // architectures on places where return value from SandboxSyscall() is used
36 // directly (like in most tests).
37 // The syscall "nr" is called with arguments that are set in an array on which
38 // pointer "args" points to and an information weather there is an error or no
39 // is returned to SandboxSyscall() by err_stat.
40 intptr_t SandboxSyscallRaw(int nr,
41 const intptr_t *args,
jln (very slow on Chromium) 2014/06/13 02:47:36 Nit: indent (simply use "git cl format").
nedeljko 2014/06/18 13:41:00 Done.
42 intptr_t* err_stat);
43 #endif // defined(__mips__)
44
28 // System calls can take up to six parameters. Traditionally, glibc 45 // System calls can take up to six parameters. Traditionally, glibc
29 // implements this property by using variadic argument lists. This works, but 46 // implements this property by using variadic argument lists. This works, but
30 // confuses modern tools such as valgrind, because we are nominally passing 47 // confuses modern tools such as valgrind, because we are nominally passing
31 // uninitialized data whenever we call through this function and pass less 48 // uninitialized data whenever we call through this function and pass less
32 // than the full six arguments. 49 // than the full six arguments.
33 // So, instead, we use C++'s template system to achieve a very similar 50 // So, instead, we use C++'s template system to achieve a very similar
34 // effect. C++ automatically sets the unused parameters to zero for us, and 51 // effect. C++ automatically sets the unused parameters to zero for us, and
35 // it also does the correct type expansion (e.g. from 32bit to 64bit) where 52 // it also does the correct type expansion (e.g. from 32bit to 64bit) where
36 // necessary. 53 // necessary.
37 // We have to use C-style cast operators as we want to be able to accept both 54 // We have to use C-style cast operators as we want to be able to accept both
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 __attribute__((always_inline)); 156 __attribute__((always_inline));
140 SANDBOX_EXPORT inline intptr_t SandboxSyscall(int nr) { 157 SANDBOX_EXPORT inline intptr_t SandboxSyscall(int nr) {
141 return SandboxSyscall(nr, 0, 0, 0, 0, 0, 0); 158 return SandboxSyscall(nr, 0, 0, 0, 0, 0, 0);
142 } 159 }
143 160
144 #endif // Pre-C++11 161 #endif // Pre-C++11
145 162
146 } // namespace sandbox 163 } // namespace sandbox
147 164
148 #endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__ 165 #endif // SANDBOX_LINUX_SECCOMP_BPF_SYSCALL_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698