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_CONTAINER_PRI_H 32 #define _LOS_CONTAINER_PRI_H 33 34 #include "los_atomic.h" 35 #ifdef LOSCFG_KERNEL_CONTAINER 36 #ifdef LOSCFG_PID_CONTAINER 37 #include "los_pid_container_pri.h" 38 #endif 39 #ifdef LOSCFG_UTS_CONTAINER 40 #include "los_uts_container_pri.h" 41 #endif 42 #ifdef LOSCFG_MNT_CONTAINER 43 #include "los_mnt_container_pri.h" 44 #endif 45 #ifdef LOSCFG_IPC_CONTAINER 46 #include "los_ipc_container_pri.h" 47 #endif 48 #ifdef LOSCFG_USER_CONTAINER 49 #include "los_user_container_pri.h" 50 #endif 51 #ifdef LOSCFG_TIME_CONTAINER 52 #include "los_time_container_pri.h" 53 #endif 54 #ifdef LOSCFG_NET_CONTAINER 55 #include "los_net_container_pri.h" 56 #endif 57 58 typedef enum { 59 CONTAINER = 0, 60 PID_CONTAINER, 61 PID_CHILD_CONTAINER, 62 UTS_CONTAINER, 63 MNT_CONTAINER, 64 IPC_CONTAINER, 65 USER_CONTAINER, 66 TIME_CONTAINER, 67 TIME_CHILD_CONTAINER, 68 NET_CONTAINER, 69 CONTAINER_MAX, 70 } ContainerType; 71 72 typedef struct Container { 73 Atomic rc; 74 #ifdef LOSCFG_PID_CONTAINER 75 struct PidContainer *pidContainer; 76 struct PidContainer *pidForChildContainer; 77 #endif 78 #ifdef LOSCFG_UTS_CONTAINER 79 struct UtsContainer *utsContainer; 80 #endif 81 #ifdef LOSCFG_MNT_CONTAINER 82 struct MntContainer *mntContainer; 83 #endif 84 #ifdef LOSCFG_IPC_CONTAINER 85 struct IpcContainer *ipcContainer; 86 #endif 87 #ifdef LOSCFG_TIME_CONTAINER 88 struct TimeContainer *timeContainer; 89 struct TimeContainer *timeForChildContainer; 90 #endif 91 #ifdef LOSCFG_NET_CONTAINER 92 struct NetContainer *netContainer; 93 #endif 94 } Container; 95 96 typedef struct TagContainerLimit { 97 #ifdef LOSCFG_PID_CONTAINER 98 UINT32 pidLimit; 99 #endif 100 #ifdef LOSCFG_UTS_CONTAINER 101 UINT32 utsLimit; 102 #endif 103 #ifdef LOSCFG_MNT_CONTAINER 104 UINT32 mntLimit; 105 #endif 106 #ifdef LOSCFG_IPC_CONTAINER 107 UINT32 ipcLimit; 108 #endif 109 #ifdef LOSCFG_TIME_CONTAINER 110 UINT32 timeLimit; 111 #endif 112 #ifdef LOSCFG_USER_CONTAINER 113 UINT32 userLimit; 114 #endif 115 #ifdef LOSCFG_NET_CONTAINER 116 UINT32 netLimit; 117 #endif 118 } ContainerLimit; 119 120 VOID OsContainerInitSystemProcess(LosProcessCB *processCB); 121 122 VOID OsInitRootContainer(VOID); 123 124 UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID); 125 126 VOID OsOsContainersDestroyEarly(LosProcessCB *processCB); 127 128 VOID OsContainersDestroy(LosProcessCB *processCB); 129 130 VOID OsContainerFree(LosProcessCB *processCB); 131 132 UINT32 OsAllocContainerID(VOID); 133 134 UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type); 135 136 INT32 OsUnshare(UINT32 flags); 137 138 INT32 OsSetNs(INT32 fd, INT32 type); 139 140 UINT32 OsGetContainerLimit(ContainerType type); 141 142 UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount); 143 144 UINT32 OsSetContainerLimit(ContainerType type, UINT32 value); 145 146 UINT32 OsGetContainerCount(ContainerType type); 147 #endif 148 #endif /* _LOS_CONTAINER_PRI_H */ 149