1 /* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _LOS_PID_CONTAINER_PRI_H 32 #define _LOS_PID_CONTAINER_PRI_H 33 #include "los_config.h" 34 #include "los_atomic.h" 35 #include "los_list.h" 36 37 typedef struct TagTaskCB LosTaskCB; 38 typedef struct ProcessCB LosProcessCB; 39 struct ProcessGroup; 40 struct Container; 41 42 typedef struct { 43 UINT32 vid; /* Virtual ID */ 44 UINT32 vpid; /* Virtual parent ID */ 45 UINTPTR cb; /* Control block */ 46 LosProcessCB *realParent; /* process real parent */ 47 LOS_DL_LIST node; 48 } ProcessVid; 49 50 #define PID_CONTAINER_LEVEL_LIMIT 3 51 52 typedef struct PidContainer { 53 Atomic rc; 54 Atomic level; 55 Atomic lock; 56 BOOL referenced; 57 UINT32 containerID; 58 struct PidContainer *parent; 59 struct ProcessGroup *rootPGroup; 60 LOS_DL_LIST tidFreeList; 61 ProcessVid tidArray[LOSCFG_BASE_CORE_TSK_LIMIT]; 62 LOS_DL_LIST pidFreeList; 63 ProcessVid pidArray[LOSCFG_BASE_CORE_PROCESS_LIMIT]; 64 } PidContainer; 65 66 #define OS_PID_CONTAINER_FROM_PCB(processCB) ((processCB)->container->pidContainer) 67 68 #define OS_ROOT_PGRP(processCB) (OS_PID_CONTAINER_FROM_PCB(processCB)->rootPGroup) 69 70 #define OS_PROCESS_CONTAINER_CHECK(processCB, currProcessCB) \ 71 ((processCB)->container->pidContainer != (currProcessCB)->container->pidContainer) 72 73 #define OS_PROCESS_PID_FOR_CONTAINER_CHECK(processCB) \ 74 (((processCB)->container->pidContainer != (processCB)->container->pidForChildContainer) && \ 75 ((processCB)->container->pidForChildContainer->referenced == FALSE)) 76 77 UINT32 OsAllocSpecifiedVpidUnsafe(UINT32 vpid, PidContainer *pidContainer, 78 LosProcessCB *processCB, LosProcessCB *parent); 79 80 VOID OsPidContainerDestroyAllProcess(LosProcessCB *processCB); 81 82 VOID OsPidContainerDestroy(struct Container *container, LosProcessCB *processCB); 83 84 UINT32 OsCopyPidContainer(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID); 85 86 UINT32 OsUnsharePidContainer(UINTPTR flags, LosProcessCB *curr, struct Container *newContainer); 87 88 UINT32 OsSetNsPidContainer(UINT32 flags, struct Container *container, struct Container *newContainer); 89 90 UINT32 OsInitRootPidContainer(PidContainer **pidContainer); 91 92 LosProcessCB *OsGetPCBFromVpid(UINT32 vpid); 93 94 LosTaskCB *OsGetTCBFromVtid(UINT32 vtid); 95 96 UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB); 97 98 UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB); 99 100 UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB); 101 102 VOID OsFreeVtid(LosTaskCB *taskCB); 103 104 UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB); 105 106 UINT32 OsGetPidContainerID(PidContainer *pidContainer); 107 108 BOOL OsPidContainerProcessParentIsRealParent(const LosProcessCB *processCB, const LosProcessCB *curr); 109 110 UINT32 OsGetPidContainerCount(VOID); 111 #endif /* _LOS_PID_CONTAINER_PRI_H */ 112