1# Copyright (c) 2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/config/python.gni") 15import("//build/ohos.gni") 16 17template("ohos_prebuilt_seccomp") { 18 assert(defined(invoker.sources), "source must be defined for ${target_name}.") 19 assert(defined(invoker.filtername), 20 "source must be defined for ${target_name}.") 21 22 _seccomp_filter_target = "gen_${target_name}" 23 _seccomp_filter_file = target_gen_dir + "/${target_name}.c" 24 25 action(_seccomp_filter_target) { 26 script = "//base/startup/init/services/modules/seccomp/scripts/generate_code_from_policy.py" 27 28 sources = invoker.sources 29 sources += get_target_outputs( 30 "//base/startup/init/services/modules/seccomp:syscall_to_nr_arm") 31 sources += get_target_outputs( 32 "//base/startup/init/services/modules/seccomp:syscall_to_nr_arm64") 33 34 deps = [ 35 "//base/startup/init/services/modules/seccomp:syscall_to_nr_arm", 36 "//base/startup/init/services/modules/seccomp:syscall_to_nr_arm64", 37 ] 38 39 args = [] 40 foreach(source, sources) { 41 args += [ 42 "--srcfiles", 43 rebase_path(source), 44 ] 45 } 46 args += [ 47 "--dstfile", 48 rebase_path(_seccomp_filter_file), 49 "--bpfArrayName", 50 invoker.filtername, 51 ] 52 53 outputs = [ _seccomp_filter_file ] 54 } 55 56 ohos_shared_library(target_name) { 57 deps = [ ":${_seccomp_filter_target}" ] 58 sources = get_target_outputs(":${_seccomp_filter_target}") 59 60 if (defined(invoker.include_dirs)) { 61 include_dirs = invoker.include_dirs 62 } 63 64 if (defined(invoker.install_enable)) { 65 install_enable = invoker.install_enable 66 } 67 68 if (defined(invoker.part_name)) { 69 part_name = invoker.part_name 70 } 71 72 if (defined(invoker.subsystem_name)) { 73 subsystem_name = invoker.subsystem_name 74 } 75 76 if (defined(invoker.install_images)) { 77 install_images = invoker.install_images 78 } 79 } 80} 81