gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/seccomp/precompiledseccomp/precompiled_lib.tmpl.go (about) 1 // Copyright 2023 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package precompiled does not exist. This file is used in a go:embed 16 // directive inside `precompile_gen.go`. 17 package precompiled 18 19 import ( 20 "gvisor.dev/gvisor/pkg/seccomp/precompiledseccomp" 21 "gvisor.dev/gvisor/pkg/sync" 22 ) 23 24 var ( 25 // precompiledPrograms holds registered programs. 26 // It is populated in `registerPrograms`. 27 precompiledPrograms map[string]precompiledseccomp.Program = nil 28 29 // registerPrecompiledProgramsOnce ensures that program registration 30 // happens only once. 31 registerPrecompiledProgramsOnce sync.Once 32 ) 33 34 // GetPrecompiled returns the precompiled program for the given name, 35 // and whether that program name exists. 36 func GetPrecompiled(programName string) (precompiledseccomp.Program, bool) { 37 registerPrecompiledProgramsOnce.Do(registerPrograms) 38 program, ok := precompiledPrograms[programName] 39 return program, ok 40 } 41 42 // registerPrograms registers available programs inside `precompiledPrograms`. 43 func registerPrograms() { 44 programs := make(map[string]precompiledseccomp.Program) 45 // PROGRAM_REGISTRATION_GOES_HERE_THIS_IS_A_LOAD_BEARING_COMMENT 46 precompiledPrograms = programs 47 }