Fix clank compilation errors in the relocation_packer.
[chromium-blink-merge.git] / sandbox / linux / BUILD.gn
blobfaf25cd04c7bf6c059f25f3b710a43eb6233f7bd
1 # Copyright 2014 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.
5 import("//build/config/features.gni")
7 declare_args() {
8   compile_suid_client = is_linux
10   compile_credentials = is_linux
12   compile_seccomp_bpf_demo =
13     (is_linux && (cpu_arch == "x86" || cpu_arch == "x64"))
16 # We have two principal targets: sandbox and sandbox_linux_unittests
17 # All other targets are listed as dependencies.
18 # There is one notable exception: for historical reasons, chrome_sandbox is
19 # the setuid sandbox and is its own target.
21 group("sandbox") {
22   deps = [
23     ":sandbox_services",
24   ]
26   if (compile_suid_client) {
27     deps += [ ":suid_sandbox_client" ]
28   }
29   if (use_seccomp_bpf) {
30     deps += [
31       ":seccomp_bpf",
32       ":seccomp_bpf_helpers",
33     ]
34   }
37 source_set("sandbox_linux_test_utils") {
38   sources = [
39     "tests/sandbox_test_runner.cc",
40     "tests/sandbox_test_runner.h",
41     "tests/sandbox_test_runner_function_pointer.cc",
42     "tests/sandbox_test_runner_function_pointer.h",
43     "tests/test_utils.cc",
44     "tests/test_utils.h",
45     "tests/unit_tests.cc",
46     "tests/unit_tests.h",
47   ]
49   deps = [
50     "//testing/gtest",
51   ]
53   if (use_seccomp_bpf) {
54     sources += [
55       "seccomp-bpf/bpf_tester_compatibility_delegate.h",
56       "seccomp-bpf/bpf_tests.h",
57       "seccomp-bpf/sandbox_bpf_test_runner.cc",
58       "seccomp-bpf/sandbox_bpf_test_runner.h",
59     ]
60     deps += [
61       ":seccomp_bpf",
62     ]
63   }
66 # The main sandboxing test target.
67 test("sandbox_linux_unittests") {
68   sources = [
69     "services/broker_process_unittest.cc",
70     "services/scoped_process_unittest.cc",
71     "services/thread_helpers_unittests.cc",
72     "services/yama_unittests.cc",
73     "tests/main.cc",
74     "tests/scoped_temporary_file.cc",
75     "tests/scoped_temporary_file.h",
76     "tests/scoped_temporary_file_unittest.cc",
77     "tests/unit_tests_unittest.cc",
78   ]
80   deps = [
81     ":sandbox",
82     ":sandbox_linux_test_utils",
83     "//base",
84     "//base/test:test_support",
85     "//testing/gtest",
86   ]
88   if (compile_suid_client) {
89     sources += [
90       "suid/client/setuid_sandbox_client_unittest.cc",
91     ]
92   }
93   if (use_seccomp_bpf) {
94     sources += [
95       "seccomp-bpf-helpers/baseline_policy_unittest.cc",
96       "seccomp-bpf/bpf_tests_unittest.cc",
97       "seccomp-bpf/codegen_unittest.cc",
98       "seccomp-bpf/errorcode_unittest.cc",
99       "seccomp-bpf/sandbox_bpf_unittest.cc",
100       "seccomp-bpf/syscall_iterator_unittest.cc",
101       "seccomp-bpf/syscall_unittest.cc",
102     ]
103   }
104   if (compile_credentials) {
105     sources += [
106       "services/credentials_unittest.cc",
107       "services/unix_domain_socket_unittest.cc",
108     ]
109   }
112 # TODO(GYP) Android version of this test.
113 #    {
114 #      # This target is the shared library used by Android APK (i.e.
115 #      # JNI-friendly) tests.
116 #      "target_name": "sandbox_linux_jni_unittests",
117 #      "includes": [
118 #        "sandbox_linux_test_sources.gypi",
119 #      ],
120 #      "type": "shared_library",
121 #      "conditions": [
122 #        [ "OS == "android"", {
123 #          "dependencies": [
124 #            "../testing/android/native_test.gyp:native_test_native_code",
125 #          ],
126 #        }],
127 #      ],
128 #    },
130 component("seccomp_bpf") {
131   sources = [
132     "seccomp-bpf/basicblock.cc",
133     "seccomp-bpf/basicblock.h",
134     "seccomp-bpf/codegen.cc",
135     "seccomp-bpf/codegen.h",
136     "seccomp-bpf/die.cc",
137     "seccomp-bpf/die.h",
138     "seccomp-bpf/errorcode.cc",
139     "seccomp-bpf/errorcode.h",
140     "seccomp-bpf/instruction.h",
141     "seccomp-bpf/linux_seccomp.h",
142     "seccomp-bpf/sandbox_bpf.cc",
143     "seccomp-bpf/sandbox_bpf.h",
144     "seccomp-bpf/sandbox_bpf_compatibility_policy.h",
145     "seccomp-bpf/sandbox_bpf_policy.cc",
146     "seccomp-bpf/sandbox_bpf_policy.h",
147     "seccomp-bpf/syscall.cc",
148     "seccomp-bpf/syscall.h",
149     "seccomp-bpf/syscall_iterator.cc",
150     "seccomp-bpf/syscall_iterator.h",
151     "seccomp-bpf/trap.cc",
152     "seccomp-bpf/trap.h",
153     "seccomp-bpf/verifier.cc",
154     "seccomp-bpf/verifier.h",
155   ]
156   defines = [ "SANDBOX_IMPLEMENTATION" ]
158   deps = [
159     ":sandbox_services_headers",
160     "//base",
161   ]
164 component("seccomp_bpf_helpers") {
165   sources = [
166     "seccomp-bpf-helpers/baseline_policy.cc",
167     "seccomp-bpf-helpers/baseline_policy.h",
168     "seccomp-bpf-helpers/sigsys_handlers.cc",
169     "seccomp-bpf-helpers/sigsys_handlers.h",
170     "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
171     "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
172     "seccomp-bpf-helpers/syscall_sets.cc",
173     "seccomp-bpf-helpers/syscall_sets.h",
174   ]
175   defines = [ "SANDBOX_IMPLEMENTATION" ]
177   deps = [
178     "//base",
179     ":seccomp_bpf",
180   ]
183 if (compile_seccomp_bpf_demo) {
184   # A demonstration program for the seccomp-bpf sandbox.
185   executable("seccomp_bpf_demo") {
186     sources = [
187       "seccomp-bpf/demo.cc",
188     ]
189     deps = [
190       ":seccomp_bpf",
191     ]
192   }
195 # The setuid sandbox for Linux.
196 executable("chrome_sandbox") {
197   sources = [
198     "suid/common/sandbox.h",
199     "suid/common/suid_unsafe_environment_variables.h",
200     "suid/linux_util.c",
201     "suid/linux_util.h",
202     "suid/process_util.h",
203     "suid/process_util_linux.c",
204     "suid/sandbox.c",
205   ]
207   cflags = [
208     # For ULLONG_MAX
209     "-std=gnu99",
210     # These files have a suspicious comparison.
211     # TODO fix this and re-enable this warning.
212     "-Wno-sign-compare",
213   ]
216 component("sandbox_services") {
217   sources = [
218     "services/broker_process.cc",
219     "services/broker_process.h",
220     "services/init_process_reaper.cc",
221     "services/init_process_reaper.h",
222     "services/scoped_process.cc",
223     "services/scoped_process.h",
224     "services/thread_helpers.cc",
225     "services/thread_helpers.h",
226     "services/yama.h",
227     "services/yama.cc",
228   ]
230   defines = [ "SANDBOX_IMPLEMENTATION" ]
232   if (compile_credentials) {
233     sources += [
234       "services/credentials.cc",
235       "services/credentials.h",
236     ]
237     # For capabilities.cc.
238     configs += [ "//build/config/linux:libcap" ]
239   }
241   deps = [
242     "//base",
243   ]
246 source_set("sandbox_services_headers") {
247   sources = [
248     "services/android_arm_ucontext.h",
249     "services/android_futex.h",
250     "services/android_ucontext.h",
251     "services/android_i386_ucontext.h",
252     "services/arm_linux_syscalls.h",
253     "services/linux_syscalls.h",
254     "services/x86_32_linux_syscalls.h",
255     "services/x86_64_linux_syscalls.h",
256   ]
259 # We make this its own target so that it does not interfere with our tests.
260 source_set("libc_urandom_override") {
261   sources = [
262     "services/libc_urandom_override.cc",
263     "services/libc_urandom_override.h",
264   ]
265   deps = [
266     "//base",
267   ]
270 component("suid_sandbox_client") {
271   sources = [
272     "suid/common/sandbox.h",
273     "suid/common/suid_unsafe_environment_variables.h",
274     "suid/client/setuid_sandbox_client.cc",
275     "suid/client/setuid_sandbox_client.h",
276   ]
277   defines = [ "SANDBOX_IMPLEMENTATION" ]
279   deps = [
280     ":sandbox_services",
281     "//base",
282   ]
285 if (is_android) {
286   # TODO(GYP) enable this. Needs an android_strip wrapper python script.
287   #action("sandbox_linux_unittests_stripped") {
288   #  script = "android_stip.py"
289   #
290   #  in_file = "$root_out_dir/sandbox_linux_unittests"
291   #
292   #  out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
293   #  outputs = [ out_file ]
294   #
295   #  args = [
296   #    rebase_path(in_file, root_build_dir),
297   #    "-o", rebase_path(out_file, root_build_dir),
298   #  ]
299   #
300   #  deps = [
301   #    ":sandbox_linux_unittests",
302   #  ]
303   #}
305   # TODO(GYP) convert this.
306   #      {
307   #      'target_name': 'sandbox_linux_jni_unittests_apk',
308   #      'type': 'none',
309   #      'variables': {
310   #        'test_suite_name': 'sandbox_linux_jni_unittests',
311   #      },
312   #      'dependencies': [
313   #        'sandbox_linux_jni_unittests',
314   #      ],
315   #      'includes': [ '../../build/apk_test.gypi' ],
316   #      }