los_container_pri.h 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*
 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _LOS_CONTAINER_PRI_H
#define _LOS_CONTAINER_PRI_H

#include "los_atomic.h"
#ifdef LOSCFG_KERNEL_CONTAINER
#ifdef LOSCFG_PID_CONTAINER
#include "los_pid_container_pri.h"
#endif
#ifdef LOSCFG_UTS_CONTAINER
#include "los_uts_container_pri.h"
#endif
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
42 43 44 45 46 47
#ifdef LOSCFG_MNT_CONTAINER
#include "los_mnt_container_pri.h"
#endif
#ifdef LOSCFG_IPC_CONTAINER
#include "los_ipc_container_pri.h"
#endif
48 49 50
#ifdef LOSCFG_USER_CONTAINER
#include "los_user_container_pri.h"
#endif
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
51 52 53
#ifdef LOSCFG_TIME_CONTAINER
#include "los_time_container_pri.h"
#endif
54 55 56
#ifdef LOSCFG_NET_CONTAINER
#include "los_net_container_pri.h"
#endif
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
57 58 59

typedef enum {
    CONTAINER = 0,
60 61
    PID_CONTAINER,	//进程容器
    PID_CHILD_CONTAINER,	//子进程容器
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
62
    UTS_CONTAINER,
63
    MNT_CONTAINER,	//挂载容器
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
64
    IPC_CONTAINER,
65
    USER_CONTAINER,
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
66 67
    TIME_CONTAINER,
    TIME_CHILD_CONTAINER,
68
    NET_CONTAINER,
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
69 70
    CONTAINER_MAX,
} ContainerType;
71 72 73 74 75

typedef struct Container {
    Atomic   rc;
#ifdef LOSCFG_PID_CONTAINER
    struct PidContainer *pidContainer;
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
76
    struct PidContainer *pidForChildContainer;
77 78 79 80
#endif
#ifdef LOSCFG_UTS_CONTAINER
    struct UtsContainer *utsContainer;
#endif
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
81 82 83 84 85 86 87 88 89 90
#ifdef LOSCFG_MNT_CONTAINER
    struct MntContainer *mntContainer;
#endif
#ifdef LOSCFG_IPC_CONTAINER
    struct IpcContainer *ipcContainer;
#endif
#ifdef LOSCFG_TIME_CONTAINER
    struct TimeContainer *timeContainer;
    struct TimeContainer *timeForChildContainer;
#endif
91 92 93
#ifdef LOSCFG_NET_CONTAINER
    struct NetContainer *netContainer;
#endif
94 95
} Container;

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
typedef struct TagContainerLimit {
#ifdef LOSCFG_PID_CONTAINER
    UINT32 pidLimit;
#endif
#ifdef LOSCFG_UTS_CONTAINER
    UINT32 utsLimit;
#endif
#ifdef LOSCFG_MNT_CONTAINER
    UINT32 mntLimit;
#endif
#ifdef LOSCFG_IPC_CONTAINER
    UINT32 ipcLimit;
#endif
#ifdef LOSCFG_TIME_CONTAINER
    UINT32 timeLimit;
#endif
#ifdef LOSCFG_USER_CONTAINER
    UINT32 userLimit;
#endif
#ifdef LOSCFG_NET_CONTAINER
    UINT32 netLimit;
#endif
} ContainerLimit;

120 121 122 123 124 125
VOID OsContainerInitSystemProcess(LosProcessCB *processCB);

VOID OsInitRootContainer(VOID);

UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);

126 127
VOID OsOsContainersDestroyEarly(LosProcessCB *processCB);

128
VOID OsContainersDestroy(LosProcessCB *processCB);
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
129 130 131 132 133

VOID OsContainerFree(LosProcessCB *processCB);

UINT32 OsAllocContainerID(VOID);

134
UINT32 OsGetContainerID(LosProcessCB *processCB, ContainerType type);
鸿蒙内核源码分析's avatar
鸿蒙内核源码分析 已提交
135 136 137 138 139

INT32 OsUnshare(UINT32 flags);

INT32 OsSetNs(INT32 fd, INT32 type);

140 141 142 143 144 145 146
UINT32 OsGetContainerLimit(ContainerType type);

UINT32 OsContainerLimitCheck(ContainerType type, UINT32 *containerCount);

UINT32 OsSetContainerLimit(ContainerType type, UINT32 value);

UINT32 OsGetContainerCount(ContainerType type);
147 148
#endif
#endif /* _LOS_CONTAINER_PRI_H */