github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/kernel/auth/id_map_functions.go (about) 1 // Copyright 2018 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 auth 16 17 // idMapFunctions "implements" generic interface segment.Functions for 18 // idMapSet. An idMapSet maps non-overlapping ranges of contiguous IDs in one 19 // user namespace to non-overlapping ranges of contiguous IDs in another user 20 // namespace. Each such ID mapping is implemented as a range-to-value mapping 21 // in the set such that [range.Start(), range.End()) => [value, value + 22 // range.Length()). 23 type idMapFunctions struct{} 24 25 func (idMapFunctions) MinKey() uint32 { 26 return 0 27 } 28 29 func (idMapFunctions) MaxKey() uint32 { 30 return NoID 31 } 32 33 func (idMapFunctions) ClearValue(*uint32) {} 34 35 func (idMapFunctions) Merge(r1 idMapRange, val1 uint32, r2 idMapRange, val2 uint32) (uint32, bool) { 36 // Mapped ranges have to be contiguous. 37 if val1+r1.Length() != val2 { 38 return 0, false 39 } 40 return val1, true 41 } 42 43 func (idMapFunctions) Split(r idMapRange, val uint32, split uint32) (uint32, uint32) { 44 return val, val + (split - r.Start) 45 }