gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/kernel/threads_impl.go (about)

     1  // Copyright 2021 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  //go:build !false
    16  // +build !false
    17  
    18  package kernel
    19  
    20  // pidNamespaceData may contain extra per-PID-namespace data.
    21  // +stateify savable
    22  type pidNamespaceData struct {
    23  }
    24  
    25  // newPIDNamespaceData returns a new `pidNamespaceData` struct.
    26  func newPIDNamespaceData() pidNamespaceData {
    27  	return pidNamespaceData{}
    28  }
    29  
    30  // addTask adds a Task into this PIDNamespace.
    31  // It is always performed under TaskSet lock.
    32  func (ns *PIDNamespace) addTask(t *Task, tid ThreadID) error {
    33  	ns.tasks[tid] = t
    34  	ns.tids[t] = tid
    35  	if t.tg.leader == nil {
    36  		// New thread group.
    37  		ns.tgids[t.tg] = tid
    38  	}
    39  	return nil
    40  }
    41  
    42  // deleteTask deletes a Task from this PIDNamespace.
    43  // It is always performed under TaskSet lock.
    44  func (ns *PIDNamespace) deleteTask(t *Task) {
    45  	delete(ns.tasks, ns.tids[t])
    46  	delete(ns.tids, t)
    47  	if t == t.tg.leader || t.tg.leader == nil {
    48  		delete(ns.tgids, t.tg)
    49  	}
    50  }