From dfbfb5cc437f9af82d2b04503c3deb29be44ae7e Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Fri, 7 Jun 2019 07:27:06 -0700 Subject: [PATCH] Add CMake builds for the examples PiperOrigin-RevId: 252045309 Change-Id: I57ffc3debbe64010b1f20b2e6df900b9916fa37f --- CMakeLists.txt | 1 + sandboxed_api/sandbox2/CMakeLists.txt | 11 +++-- .../sandbox2/examples/CMakeLists.txt | 19 ++++++++ .../sandbox2/examples/crc4/CMakeLists.txt | 45 ++++++++++++++++++ .../examples/custom_fork/CMakeLists.txt | 47 +++++++++++++++++++ .../sandbox2/examples/static/CMakeLists.txt | 40 ++++++++++++++++ .../sandbox2/examples/tool/CMakeLists.txt | 28 +++++++++++ .../sandbox2/examples/zlib/CMakeLists.txt | 41 ++++++++++++++++ .../sandbox2/examples/zlib/zpipe_sandbox.cc | 1 + 9 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 sandboxed_api/sandbox2/examples/CMakeLists.txt create mode 100644 sandboxed_api/sandbox2/examples/crc4/CMakeLists.txt create mode 100644 sandboxed_api/sandbox2/examples/custom_fork/CMakeLists.txt create mode 100644 sandboxed_api/sandbox2/examples/static/CMakeLists.txt create mode 100644 sandboxed_api/sandbox2/examples/tool/CMakeLists.txt create mode 100644 sandboxed_api/sandbox2/examples/zlib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e8d8c62..019d16b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ find_package(gflags REQUIRED) find_package(glog REQUIRED) find_package(Protobuf REQUIRED) find_package(Libcap REQUIRED) +find_package(ZLIB REQUIRED) # Make Bazel-like includes work configure_file(cmake/libcap_capability.h.in diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index 54a68f5..1e879cb 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +add_subdirectory(examples) add_subdirectory(testcases) add_subdirectory(unwind) add_subdirectory(util) @@ -467,11 +468,11 @@ add_library(sandbox2_forkingclient STATIC forkingclient.h ) add_library(sandbox2::forkingclient ALIAS sandbox2_forkingclient) -target_link_libraries(sandbox2_forkingclient PRIVATE - absl::memory - sandbox2::client - sandbox2::forkserver - sapi::base +target_link_libraries(sandbox2_forkingclient + PRIVATE absl::memory + sandbox2::forkserver + sapi::base + PUBLIC sandbox2::client ) # sandboxed_api/sandbox2:util diff --git a/sandboxed_api/sandbox2/examples/CMakeLists.txt b/sandboxed_api/sandbox2/examples/CMakeLists.txt new file mode 100644 index 0000000..87da940 --- /dev/null +++ b/sandboxed_api/sandbox2/examples/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_subdirectory(crc4) +add_subdirectory(custom_fork) +add_subdirectory(static) +add_subdirectory(tool) +add_subdirectory(zlib) diff --git a/sandboxed_api/sandbox2/examples/crc4/CMakeLists.txt b/sandboxed_api/sandbox2/examples/crc4/CMakeLists.txt new file mode 100644 index 0000000..01d1c03 --- /dev/null +++ b/sandboxed_api/sandbox2/examples/crc4/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# sandboxed_api/sandbox2/examples/crc4:crc4sandbox +add_executable(sandbox2_crc4sandbox + crc4sandbox.cc +) +add_executable(sandbox2::crc4sandbox ALIAS sandbox2_crc4sandbox) +add_dependencies(sandbox2_crc4sandbox + sandbox2::crc4bin +) +target_link_libraries(sandbox2_crc4sandbox PRIVATE + absl::memory + sandbox2::bpf_helper + sandbox2::comms + sandbox2::runfiles + sandbox2::sandbox2 + sapi::base + sapi::flags +) + +# sandboxed_api/sandbox2/examples/crc4:crc4bin +add_executable(crc4bin + crc4bin.cc +) +add_executable(sandbox2::crc4bin ALIAS crc4bin) +target_link_libraries(crc4bin PRIVATE + absl::core_headers + sandbox2::client + sandbox2::comms + sandbox2::util + sapi::base + sapi::flags +) diff --git a/sandboxed_api/sandbox2/examples/custom_fork/CMakeLists.txt b/sandboxed_api/sandbox2/examples/custom_fork/CMakeLists.txt new file mode 100644 index 0000000..9e46d6e --- /dev/null +++ b/sandboxed_api/sandbox2/examples/custom_fork/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# sandboxed_api/sandbox2/examples/custom_fork:custom_fork_sandbox +add_executable(sandbox2_custom_fork_sandbox + custom_fork_sandbox.cc +) +add_executable(sandbox2::custom_fork_sandbox ALIAS sandbox2_custom_fork_sandbox) +add_dependencies(sandbox2_custom_fork_sandbox + sandbox2::custom_fork_bin +) +target_link_libraries(sandbox2_custom_fork_sandbox PRIVATE + absl::core_headers + absl::memory + sandbox2::comms + sandbox2::forkserver + sandbox2::runfiles + sandbox2::sandbox2 + sapi::base + sapi::flags + sapi::raw_logging +) + +# sandboxed_api/sandbox2/examples/custom_fork:custom_fork_bin +add_executable(custom_fork_bin + custom_fork_bin.cc +) +add_executable(sandbox2::custom_fork_bin ALIAS custom_fork_bin) +target_link_libraries(custom_fork_bin PRIVATE + sandbox2::comms + sandbox2::forkingclient + sandbox2::util + sapi::base + sapi::flags + sapi::raw_logging +) diff --git a/sandboxed_api/sandbox2/examples/static/CMakeLists.txt b/sandboxed_api/sandbox2/examples/static/CMakeLists.txt new file mode 100644 index 0000000..56b86e9 --- /dev/null +++ b/sandboxed_api/sandbox2/examples/static/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# sandboxed_api/sandbox2/examples/static:static_sandbox +add_executable(sandbox2_static_sandbox + static_sandbox.cc +) +add_executable(sandbox2::static_sandbox ALIAS sandbox2_static_sandbox) +add_dependencies(sandbox2_static_sandbox + sandbox2::static_bin +) +target_link_libraries(sandbox2_static_sandbox PRIVATE + absl::memory + sandbox2::bpf_helper + sandbox2::runfiles + sandbox2::sandbox2 + sapi::base + sapi::flags +) + +# sandboxed_api/sandbox2/examples/static:static_bin +add_executable(static_bin + static_bin.cc +) +add_executable(sandbox2::static_bin ALIAS static_bin) +target_link_libraries(static_bin PRIVATE + sapi::base + -static # Fully static link +) diff --git a/sandboxed_api/sandbox2/examples/tool/CMakeLists.txt b/sandboxed_api/sandbox2/examples/tool/CMakeLists.txt new file mode 100644 index 0000000..63a0b8a --- /dev/null +++ b/sandboxed_api/sandbox2/examples/tool/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# sandboxed_api/sandbox2/examples/tools:sandbox2tool +add_executable(sandbox2_sandbox2tool + sandbox2tool.cc +) +add_executable(sandbox2::sandbox2tool ALIAS sandbox2_sandbox2tool) +target_link_libraries(sandbox2_sandbox2tool PRIVATE + absl::memory + absl::strings + sandbox2::bpf_helper + sandbox2::sandbox2 + sandbox2::util + sapi::base + sapi::flags +) diff --git a/sandboxed_api/sandbox2/examples/zlib/CMakeLists.txt b/sandboxed_api/sandbox2/examples/zlib/CMakeLists.txt new file mode 100644 index 0000000..f8b6528 --- /dev/null +++ b/sandboxed_api/sandbox2/examples/zlib/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright 2019 Google LLC. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# sandboxed_api/sandbox2/examples/zlib:zpipe_sandbox +add_executable(sandbox2_zpipe_sandbox + zpipe_sandbox.cc +) +add_executable(sandbox2::zpipe_sandbox ALIAS sandbox2_zpipe_sandbox) +add_dependencies(sandbox2_zpipe_sandbox + sandbox2::zpipe +) +target_link_libraries(sandbox2_zpipe_sandbox PRIVATE + absl::memory + sandbox2::bpf_helper + sandbox2::comms + sandbox2::runfiles + sandbox2::sandbox2 + sapi::base + sapi::flags +) + +# sandboxed_api/sandbox2/examples/zlib:zpipe +add_executable(zpipe + zpipe.c +) +add_executable(sandbox2::zpipe ALIAS zpipe) +target_link_libraries(zpipe PRIVATE + ZLIB::ZLIB + -static # Fully static link +) diff --git a/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc b/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc index c50ee55..5f5abc0 100644 --- a/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc +++ b/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc @@ -58,6 +58,7 @@ std::unique_ptr GetPolicy() { .AllowSystemMalloc() .AllowExit() .EnableNamespaces() + .BlockSyscallWithErrno(__NR_access, ENOENT) .BuildOrDie(); }