diff --git a/Kconfig b/Kconfig index 359ec54c3511420b28b2cfea74ced01df4767e57..dadbeb5a44c4cbd737fa067916bd7492408354f6 100644 --- a/Kconfig +++ b/Kconfig @@ -1,5 +1,5 @@ # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 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: @@ -600,7 +600,6 @@ endmenu ######################## config options os security ####################### menu "Security" -osource "security/Kconfig" config SECURE_TRUSTZONE bool "Enable ARM TrustZone" default n @@ -615,6 +614,13 @@ config SECURE_STACK_DEFAULT_SIZE depends on SECURE_TRUSTZONE help The secure stack must be allocated before the task calls non-secure functions. +config SECURE + bool "Enable Security" + default n + select MPU_ENABLE +config MPU_ENABLE + bool "Enable MPU" + default n endmenu menu "Test" diff --git a/arch/arm/cortex-m4/gcc/los_arch_context.h b/arch/arm/cortex-m4/gcc/los_arch_context.h index fa8bc209db9e8d515bf88f429589a4478527b67b..16659b4112f1ed9889dccbb9c90490311e6ac93f 100644 --- a/arch/arm/cortex-m4/gcc/los_arch_context.h +++ b/arch/arm/cortex-m4/gcc/los_arch_context.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -121,6 +121,29 @@ typedef struct TagTskContext { */ extern VOID HalStartToRun(VOID); +#if (LOSCFG_SECURE == 1) +/** + * @ingroup los_config + * @brief: User Task Stack Initialize. + * + * @par Description: + * This API is used to init a user task stack. + * + * @attention: + * + * + * @param: context [IN] Task context. + * @param: taskEntry [IN] Task entry function address. + * @param: stack [IN] Task stack address. + * + * @retval None. + * + * @par Dependency: + * @see None. + */ +extern VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack); +#endif + #ifdef __cplusplus #if __cplusplus } diff --git a/arch/arm/cortex-m4/gcc/los_context.c b/arch/arm/cortex-m4/gcc/los_context.c index 78c383d4eb77d538a0912e7e285f491c57ef3774..d7192d639d5e4cf194653bd9c6cabafb547281b9 100644 --- a/arch/arm/cortex-m4/gcc/los_context.c +++ b/arch/arm/cortex-m4/gcc/los_context.c @@ -148,6 +148,15 @@ VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandl return (VOID *)context; } +#if (LOSCFG_SECURE == 1) +VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack) +{ + context->uwR0 = stack; + context->uwPC = (UINT32)taskEntry; + context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */ +} +#endif + LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID) { (VOID)LOS_IntLock(); diff --git a/arch/arm/cortex-m4/gcc/los_dispatch.S b/arch/arm/cortex-m4/gcc/los_dispatch.S index d21b274d5afa8ca3b76665f19aa6291cd7d84023..64c41a2414e6a6ce0bacce22f74f0d98ad56bf09 100644 --- a/arch/arm/cortex-m4/gcc/los_dispatch.S +++ b/arch/arm/cortex-m4/gcc/los_dispatch.S @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -40,6 +40,12 @@ .equ OS_NVIC_PENDSV_PRI, 0xF0F00000 .equ OS_NVIC_PENDSVSET, 0x10000000 .equ OS_TASK_STATUS_RUNNING, 0x0010 +.equ OS_CONTROL_FPCA_ENABLE, 0x4 +.equ OS_CONTROL_KERNEL_MODE, 0x2 +#if (LOSCFG_SECURE == 1) +.equ OS_CONTROL_USER_MODE, 0x3 +.equ OS_TASK_FLAG_USER_TASK, 0x0200 +#endif .section .text .thumb @@ -63,7 +69,7 @@ HalStartToRun: ldr r5, =OS_NVIC_PENDSV_PRI str r5, [r4] - mov r0, #2 + mov r0, #OS_CONTROL_KERNEL_MODE msr CONTROL, r0 ldr r1, =g_losTask @@ -141,7 +147,7 @@ ArchTaskSchedule: bx lr dsb isb - .fnend + .fnend .type HalPendSV, %function .global HalPendSV @@ -194,6 +200,14 @@ SignalContextRestore: vldmia r1!, {d8-d15} __DisabledFPU2: +#if (LOSCFG_SECURE == 1) + ldrh r7, [r0, #4] + tst r7, #OS_TASK_FLAG_USER_TASK + ite eq + moveq r3, #OS_CONTROL_KERNEL_MODE + movne r3, #OS_CONTROL_USER_MODE + msr CONTROL, r3 +#endif ldmfd r1!, {r4-r12} msr psp, r1 diff --git a/arch/arm/cortex-m4/gcc/los_exc.S b/arch/arm/cortex-m4/gcc/los_exc.S index 761f6c4446d79d5f29db1690c1d960f810716026..a54e706c1725377b0e1299f0bc65163faeb0c4bc 100644 --- a/arch/arm/cortex-m4/gcc/los_exc.S +++ b/arch/arm/cortex-m4/gcc/los_exc.S @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -57,15 +57,15 @@ .equ FLAG_ADDR_VALID, 0x10000 .equ FLAG_HWI_ACTIVE, 0x20000 -.equ FLAG_NO_FLOAT, 0x10000000 +.equ FLAG_NO_FLOAT, 0x10000000 -.equ OS_NVIC_FSR , 0xE000ED28 //include BusFault/MemFault/UsageFault State Register -.equ OS_NVIC_HFSR , 0xE000ED2C //HardFault State Register -.equ OS_NVIC_BFAR , 0xE000ED38 -.equ OS_NVIC_MMAR , 0xE000ED34 -.equ OS_NVIC_ACT_BASE , 0xE000E300 -.equ OS_NVIC_SHCSRS , 0xE000ED24 -.equ OS_NVIC_SHCSR_MASK , 0xC00 +.equ OS_NVIC_FSR, 0xE000ED28 //include BusFault/MemFault/UsageFault State Register +.equ OS_NVIC_HFSR, 0xE000ED2C //HardFault State Register +.equ OS_NVIC_BFAR, 0xE000ED38 +.equ OS_NVIC_MMAR, 0xE000ED34 +.equ OS_NVIC_ACT_BASE, 0xE000E300 +.equ OS_NVIC_SHCSRS, 0xE000ED24 +.equ OS_NVIC_SHCSR_MASK, 0xC00 .type HalExcNMI, %function .global HalExcNMI @@ -155,10 +155,25 @@ HalExcSvcCall: .cantunwind TST LR, #0x4 ITE EQ - MRSEQ R0, MSP - MRSNE R0, PSP - LDR R1, [R0,#24] - LDRB R0, [R1,#-2] + MRSEQ R1, MSP + BNE _svcCallFromPsp + B _svcCall +_svcCallFromPsp: +#ifdef LOSCFG_SECURE + PUSH {R0-R12, LR} + MOV R0, SP + CPSIE I + BL OsSyscallHandle + CPSID I + MRS R12, PSP + STM R12, {R0-R1} + POP {R0-R12, LR} + BX LR +#endif + MRS R1, PSP +_svcCall: + LDR R0, [R1,#24] + LDRB R0, [R0,#-2] MOV R1, #0 B osExcDispatch .fnend @@ -284,7 +299,7 @@ _ExcInMSP: PUSH {R4-R12} // store message-->exc: {R4-R12} VPUSH {D8-D15} // FPU B _handleEntry - .fnend + .fnend .type _NoFloatInMsp, %function .global _NoFloatInMsp @@ -298,7 +313,7 @@ _NoFloatInMsp: PUSH {R4-R12} // store message-->exc: {R4-R12} ORR R0, R0, #FLAG_NO_FLOAT B _handleEntry - .fnend + .fnend .type _hwiActiveCheckNext, %function .global _hwiActiveCheckNext @@ -347,7 +362,7 @@ _hwiActiveCheckNext: VSTMDB R2!, {D8-D15} // FPU STMFD R2!, {R4-R11} B _handleEntry - .fnend + .fnend .type _NoFloatInPsp, %function .global _NoFloatInPsp @@ -367,7 +382,7 @@ _NoFloatInPsp: LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task) STMFD R2!, {R4-R11} ORR R0, R0, #FLAG_NO_FLOAT - .fnend + .fnend .type _handleEntry, %function .global _handleEntry @@ -380,4 +395,4 @@ _handleEntry: B HalExcHandleEntry NOP - .fnend + .fnend diff --git a/arch/arm/cortex-m7/gcc/los_dispatch.S b/arch/arm/cortex-m7/gcc/los_dispatch.S index 4e1393ae62fe2ec1f1fa2c24dccd70855a3dbec8..88e56fa29639e27e696436ca0386399f198f4e85 100644 --- a/arch/arm/cortex-m7/gcc/los_dispatch.S +++ b/arch/arm/cortex-m7/gcc/los_dispatch.S @@ -137,7 +137,7 @@ ArchTaskSchedule: dsb isb bx lr - .fnend + .fnend .type HalPendSV, %function .global HalPendSV @@ -178,7 +178,7 @@ TaskContextSwitch: str r0, [r5] ldr r1, [r0] - SignalContextRestore: +SignalContextRestore: #if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined(__FPU_USED) && (__FPU_USED == 1U))) vldmia r1!, {d8-d15} diff --git a/arch/arm/cortex-m7/gcc/los_exc.S b/arch/arm/cortex-m7/gcc/los_exc.S index 74cfaa988b5eb56edaf2bd7506e5bf948101ba50..054fa80c0bf17e8ac5a2110646e58b83f701de14 100644 --- a/arch/arm/cortex-m7/gcc/los_exc.S +++ b/arch/arm/cortex-m7/gcc/los_exc.S @@ -29,9 +29,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - .syntax unified - .arch armv7e-m - .thumb +.syntax unified +.arch armv7e-m +.thumb .fpu fpv5-d16 .section .text @@ -284,7 +284,7 @@ _ExcInMSP: PUSH {R4-R12} // store message-->exc: {R4-R12} VPUSH {D8-D15} B _handleEntry - .fnend + .fnend .type _NoFloatInMsp, %function .global _NoFloatInMsp @@ -298,7 +298,7 @@ _NoFloatInMsp: PUSH {R4-R12} // store message-->exc: {R4-R12} ORR R0, R0, #FLAG_NO_FLOAT B _handleEntry - .fnend + .fnend .type _hwiActiveCheckNext, %function .global _hwiActiveCheckNext @@ -347,7 +347,7 @@ _hwiActiveCheckNext: VSTMDB R2!, {D8-D15} STMFD R2!, {R4-R11} B _handleEntry - .fnend + .fnend .type _NoFloatInPsp, %function .global _NoFloatInPsp @@ -367,7 +367,7 @@ _NoFloatInPsp: LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task) STMFD R2!, {R4-R11} ORR R0, R0, #FLAG_NO_FLOAT - .fnend + .fnend .type _handleEntry, %function .global _handleEntry @@ -380,5 +380,5 @@ _handleEntry: B HalExcHandleEntry NOP - .fnend + .fnend diff --git a/components/BUILD.gn b/components/BUILD.gn index b957e43f60c84e364c3f5675b4a0537ff9258529..513e77a82ae9d26568c7ffc69abd4c9f15978e56 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -1,5 +1,5 @@ # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 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: @@ -41,6 +41,7 @@ group("components") { "lms", "net", "power", + "security", "shell", "signal", "trace", @@ -57,6 +58,7 @@ config("public") { "fs:public", "net:public", "power:public", + "security:public", "shell:public", "trace:public", "lmk:public", diff --git a/components/security/BUILD.gn b/components/security/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8f603596ac5c6447afdeaf5be09ad673b48f0f96 --- /dev/null +++ b/components/security/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2022-2022 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. + +import("//kernel/liteos_m/liteos.gni") + +module_name = get_path_info(rebase_path("."), "name") +module_group(module_name) { + modules = [ + "box", + "syscall", + "userlib", + ] +} diff --git a/components/security/box/BUILD.gn b/components/security/box/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..46d6872a3609269cad1c52deafdae4c445a58d9b --- /dev/null +++ b/components/security/box/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2022-2022 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. + +import("//kernel/liteos_m/liteos.gni") + +module_switch = defined(LOSCFG_SECURE) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { + sources = [ "los_box.c" ] +} + +config("public") { + include_dirs = [ "./" ] +} diff --git a/components/security/box/los_box.c b/components/security/box/los_box.c new file mode 100644 index 0000000000000000000000000000000000000000..55c6879048e63bacf66db28c4244e0977f9d52d9 --- /dev/null +++ b/components/security/box/los_box.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2022-2022 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. + */ + +#include "los_box.h" +#include "los_task.h" +#include "los_context.h" +#include "los_arch_context.h" +#include "los_debug.h" + +static UserTaskCB g_UserTaskCBArray[LOSCFG_BASE_CORE_TSK_LIMIT] = { 0 }; +static LosBoxCB g_boxCB[1]; + +VOID OsUserTaskInit(UINT32 taskID, UINTPTR entry, UINTPTR userArea, UINTPTR userSp) +{ + LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID); + taskCB->taskStatus |= OS_TASK_FLAG_USER_TASK; + HalUserTaskStackInit(taskCB->stackPointer, entry, userSp); + + g_UserTaskCBArray[taskID].userArea = userArea; + g_UserTaskCBArray[taskID].userSp = userSp; + g_UserTaskCBArray[taskID].boxID = g_UserTaskCBArray[g_losTask.runTask->taskID].boxID; +} + +VOID OsUserTaskDelete(UINT32 taskID) +{ + memset_s(&g_UserTaskCBArray[taskID], sizeof(UserTaskCB), 0, sizeof(UserTaskCB)); +} + +UserTaskCB *OsGetUserTaskCB(UINT32 taskID) +{ + return &g_UserTaskCBArray[taskID]; +} + +static UINT32 BoxInit(VOID) +{ + UINT32 count = sizeof(g_boxCB) / sizeof(LosBoxCB); + for (UINT32 i = 0; i < count; i++) { + LosBoxCB *box = &g_boxCB[i]; + box->boxStackAddr = box->boxStartAddr + box->boxSize - box->boxStackSize; + } + + return LOS_OK; +} + +VOID OsBoxStart(VOID) +{ + UINT32 ret, taskID; + UINT32 count = sizeof(g_boxCB) / sizeof(LosBoxCB); + TSK_INIT_PARAM_S taskInitParam = { 0 }; + + for (UINT32 i = 0; i < count; i++) { + LosBoxCB *box = &g_boxCB[i]; + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)box->boxStartAddr; + taskInitParam.uwStackSize = 0x1000; + taskInitParam.pcName = "BoxMainTask"; + taskInitParam.usTaskPrio = LOSCFG_BOX_PRIO; + taskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE; + ret = LOS_TaskCreateOnly(&taskID, &taskInitParam); + if (ret != LOS_OK) { + PRINT_ERR("Create box %u main task failed, Error 0x%x\n", i, ret); + return; + } + + OsUserTaskInit(taskID, (UINTPTR)_ulibc_start, 0, box->boxStackAddr + box->boxStackSize); + g_UserTaskCBArray[taskID].boxID = i; + + ret = LOS_TaskResume(taskID); + if (ret != LOS_OK) { + PRINT_ERR("Box(%u) resume task %u failed, Error 0x%x\n", i, taskID, ret); + return; + } + } +} + +UINT32 LOS_BoxStart(VOID) +{ + UINT32 ret, taskID; + TSK_INIT_PARAM_S taskInitParam = { 0 }; + + ret = BoxInit(); + if (ret != LOS_OK) { + PRINT_ERR("Box init failed! Error 0x%x\n", ret); + return ret; + } + + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsBoxStart; + taskInitParam.uwStackSize = 0x1000; + taskInitParam.pcName = "BoxStart"; + taskInitParam.usTaskPrio = LOSCFG_BOX_START_PRIO; + taskInitParam.uwResved = 0; + return LOS_TaskCreate(&taskID, &taskInitParam); +} diff --git a/components/security/box/los_box.h b/components/security/box/los_box.h new file mode 100644 index 0000000000000000000000000000000000000000..83398768249ee4fec1ffd6fa747d75cd548578bc --- /dev/null +++ b/components/security/box/los_box.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022-2022 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_BOX_H +#define _LOS_BOX_H + +#include "los_compiler.h" + +#define LOSCFG_BOX_START_PRIO 5 +#define LOSCFG_BOX_PRIO 10 + +/* + * -------------------- boxStartAddr(main) + * | .text | + * | ----------------- + * | .data | + * | ----------------- boxHeapAddr + * | .heap | + * | ----------------- boxStackAddr + * | boxStackSize | + * -------------------- + */ +typedef struct { + UINTPTR boxStartAddr; + UINTPTR boxSize; + UINTPTR boxHeapAddr; + UINTPTR boxHeapSize; + UINTPTR boxStackAddr; /* box main task stack addr */ + UINTPTR boxStackSize; +} LosBoxCB; + +typedef struct { + unsigned long userArea; + unsigned long userSp; + unsigned int boxID; +} UserTaskCB; + +VOID OsUserTaskInit(UINT32 taskID, UINTPTR entry, UINTPTR userArea, UINTPTR userSp); +VOID OsUserTaskDelete(UINT32 taskID); +UserTaskCB *OsGetUserTaskCB(UINT32 taskID); +UINT32 LOS_BoxStart(VOID); + +extern INT32 _ulibc_start(UINTPTR main); + +#endif diff --git a/components/security/syscall/BUILD.gn b/components/security/syscall/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cd642b15ef1d40ac1bc96f51917ade0c54ec937f --- /dev/null +++ b/components/security/syscall/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2022-2022 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. + +import("//kernel/liteos_m/liteos.gni") + +module_switch = defined(LOSCFG_SECURE) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { + sources = [ + "los_syscall.c", + "pthread_syscall.c", + ] +} + +config("public") { + include_dirs = [ "./" ] +} diff --git a/components/security/syscall/los_syscall.c b/components/security/syscall/los_syscall.c new file mode 100644 index 0000000000000000000000000000000000000000..c5376120da78a03e7e2802de7b865151c7a75122 --- /dev/null +++ b/components/security/syscall/los_syscall.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022-2022 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. + */ + +#define GNU_SOURCE +#include "los_syscall.h" +#include "los_context.h" +#include "los_task.h" +#include "los_debug.h" +#include "unistd.h" +#include "errno.h" + +#define SYS_CALL_NUM_LIMIT (__NR_syscallend + 1) +#define SYS_CALL_NUM_REG_OFFSET 7 +#define NARG_BITS 4 +#define NARG_MASK 0x0F +#define NARG_PER_BYTE 2 + +typedef UINT32 (*SyscallFun1)(UINT32); +typedef UINT32 (*SyscallFun2)(UINT32, UINT32); +typedef UINT32 (*SyscallFun3)(UINT32, UINT32, UINT32); +typedef UINT32 (*SyscallFun4)(UINT32, UINT32, UINT32, UINT32); +typedef UINT32 (*SyscallFun5)(UINT32, UINT32, UINT32, UINT32, UINT32); +typedef UINT32 (*SyscallFun7)(UINT32, UINT32, UINT32, UINT32, UINT32, UINT32, UINT32); + +static UINTPTR g_syscallHandle[SYS_CALL_NUM_LIMIT] = {0}; +static UINT8 g_syscallNArgs[(SYS_CALL_NUM_LIMIT + 1) / NARG_PER_BYTE] = {0}; + +void OsSyscallHandleInit(void) +{ +#define SYSCALL_HAND_DEF(id, fun, rType, nArg) \ + if ((id) < SYS_CALL_NUM_LIMIT) { \ + g_syscallHandle[(id)] = (UINTPTR)(fun); \ + g_syscallNArgs[(id) / NARG_PER_BYTE] |= ((id) & 1) ? (nArg) << NARG_BITS : (nArg); \ + } \ + +#include "syscall_lookup.h" +#undef SYSCALL_HAND_DEF +} + +/* The SYSCALL ID is in R7 on entry. Parameters follow in R0..R6 */ +VOID OsSyscallHandle(UINT32 *args) +{ + UINT32 ret; + UINT8 nArgs; + UINTPTR handle; + UINT32 svcNum = (UINT32)args[SYS_CALL_NUM_REG_OFFSET]; + + if (svcNum >= SYS_CALL_NUM_LIMIT) { + PRINT_ERR("Syscall ID: error %d !!!\n", svcNum); + return; + } + + handle = g_syscallHandle[svcNum]; + nArgs = g_syscallNArgs[svcNum / NARG_PER_BYTE]; /* 4bit per nargs */ + nArgs = (svcNum & 1) ? (nArgs >> NARG_BITS) : (nArgs & NARG_MASK); + if ((handle == 0) || (nArgs > ARG_NUM_7)) { + PRINT_ERR("Unsupported syscall ID: %d nArgs: %d\n", svcNum, nArgs); + args[ARG_NUM_0] = -ENOSYS; + return; + } + + switch (nArgs) { + case ARG_NUM_0: + case ARG_NUM_1: + ret = (*(SyscallFun1)handle)(args[ARG_NUM_0]); + break; + case ARG_NUM_2: + ret = (*(SyscallFun2)handle)(args[ARG_NUM_0], args[ARG_NUM_1]); + break; + case ARG_NUM_3: + ret = (*(SyscallFun3)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2]); + break; + case ARG_NUM_4: + ret = (*(SyscallFun4)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3]); + break; + case ARG_NUM_5: + ret = (*(SyscallFun5)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3], \ + args[ARG_NUM_4]); + break; + default: + ret = (*(SyscallFun7)handle)(args[ARG_NUM_0], args[ARG_NUM_1], args[ARG_NUM_2], args[ARG_NUM_3], \ + args[ARG_NUM_4], args[ARG_NUM_5], args[ARG_NUM_6]); + } + + args[ARG_NUM_0] = ret; + + return; +} \ No newline at end of file diff --git a/components/security/syscall/los_syscall.h b/components/security/syscall/los_syscall.h new file mode 100644 index 0000000000000000000000000000000000000000..e89837f4fe1d469286b61547aef35e88ace9e50b --- /dev/null +++ b/components/security/syscall/los_syscall.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022-2022 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_SYSCALL_H +#define _LOS_SYSCALL_H + +#include "los_arch_context.h" +#include "los_task.h" +#include "syscall.h" + +void OsSyscallHandleInit(void); +void OsSyscallHandle(UINT32 *regs); + +/* pthread */ +int SysUserTaskCreate(unsigned long entry, unsigned long userArea, unsigned long userSp, BOOL joinable); +int SysSchedSetScheduler(unsigned int tid, int policy, int priority); +int *SysSchedGetArea(unsigned int tid); +int SysSetThreadArea(const char *area); +char *SysGetThreadArea(void); +int SysFutex(const unsigned int *uAddr, unsigned int flags, int val, + unsigned int absTime, const unsigned int *newUserAddr); + +#endif /* _LOS_SYSCALL_H */ diff --git a/components/security/syscall/pthread_syscall.c b/components/security/syscall/pthread_syscall.c new file mode 100644 index 0000000000000000000000000000000000000000..5c168e3cda619d73b46c7cb9c75626f7b1963751 --- /dev/null +++ b/components/security/syscall/pthread_syscall.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022-2022 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. + */ + +#include "los_task.h" +#include "securec.h" +#include "los_config.h" +#include "los_debug.h" +#include "los_hook.h" +#include "los_interrupt.h" +#include "los_memory.h" +#include "los_mpu.h" +#include "los_sched.h" +#include "los_mux.h" +#include "los_sem.h" +#include "los_timer.h" +#include "los_arch_context.h" +#include "los_box.h" +#include "los_syscall.h" + +int SysUserTaskCreate(unsigned long entry, unsigned long userArea, unsigned long userSp, BOOL joinable) +{ + UINT32 ret, taskID; + TSK_INIT_PARAM_S taskInitParam = { 0 }; + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)entry; + taskInitParam.uwStackSize = 0x1000; + taskInitParam.pcName = "UserTask"; + taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST; + taskInitParam.stackAddr = userSp; + if (joinable) { + taskInitParam.uwResved |= LOS_TASK_ATTR_JOINABLE; + } + ret = LOS_TaskCreateOnly(&taskID, &taskInitParam); + if (ret != LOS_OK) { + return -EINVAL; + } + + OsUserTaskInit(taskID, entry, userArea, userSp); + return taskID; +} + +int SysSchedSetScheduler(unsigned int tid, int policy, int priority) +{ + if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { + return EINVAL; + } + + if (policy != 0) { + return EINVAL; + } + + if ((priority <= 0) || (priority > OS_TASK_PRIORITY_LOWEST)) { + return EINVAL; + } + + UINT32 ret = LOS_TaskPriSet((UINT32)tid, (UINT16)priority); + if (ret != LOS_OK) { + return EINVAL; + } + + return 0; +} + +int *SysSchedGetArea(unsigned int tid) +{ + unsigned int intSave; + int *area = NULL; + + if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { + return NULL; + } + + intSave = LOS_IntLock(); + area = (int *)OsGetUserTaskCB(tid)->userArea; + LOS_IntRestore(intSave); + return area; +} + +int SysSetThreadArea(const char *area) +{ + unsigned int intSave; + + intSave = LOS_IntLock(); + LosTaskCB *runTask = g_losTask.runTask; + OsGetUserTaskCB(runTask->taskID)->userArea = (unsigned long)(uintptr_t)area; + LOS_IntRestore(intSave); + return 0; +} + +char *SysGetThreadArea(void) +{ + unsigned int intSave; + char *area = NULL; + + intSave = LOS_IntLock(); + LosTaskCB *runTask = g_losTask.runTask; + area = (char *)OsGetUserTaskCB(runTask->taskID)->userArea; + LOS_IntRestore(intSave); + return area; +} diff --git a/components/security/syscall/syscall_lookup.h b/components/security/syscall/syscall_lookup.h new file mode 100644 index 0000000000000000000000000000000000000000..3bd4dfedc1ce4ed5518a5b619862a1037b6152bf --- /dev/null +++ b/components/security/syscall/syscall_lookup.h @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2022-2022 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. + */ + +/* SYSCALL_HAND_DEF must be defined before including this file. */ +/* SYSCALL_HAND_DEF(id, fun, rtype, narg); note if we have 64bit arg, narg should be ARG_NUM_7 */ + +// #ifdef LOSCFG_FS_VFS +// SYSCALL_HAND_DEF(__NR_read, SysRead, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_write, SysWrite, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_open, SysOpen, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_close, SysClose, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_creat, SysCreat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_link, SysLink, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_readlink, SysReadlink, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_symlink, SysSymlink, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_unlink, SysUnlink, int, ARG_NUM_1) + +// #ifdef LOSCFG_KERNEL_DYNLOAD +// SYSCALL_HAND_DEF(__NR_execve, SysExecve, int, ARG_NUM_3) +// #endif + +// SYSCALL_HAND_DEF(__NR_sysinfo, SysInfo, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_fchdir, SysFchdir, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_chdir, SysChdir, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_fchmodat, SysFchmodat, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_fchmod, SysFchmod, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_chmod, SysChmod, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_lseek, SysLseek, off_t, ARG_NUM_7) /* current only support 32bit max 4G file */ +// SYSCALL_HAND_DEF(__NR_mount, SysMount, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_umount, SysUmount, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_access, SysAccess, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_faccessat, SysFaccessat, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_sync, SysSync, void, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_rename, SysRename, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_mkdir, SysMkdir, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_rmdir, SysRmdir, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_dup, SysDup, int, ARG_NUM_1) +// #ifdef LOSCFG_KERNEL_PIPE +// SYSCALL_HAND_DEF(__NR_pipe, SysPipe, int, ARG_NUM_1) +// #endif +// SYSCALL_HAND_DEF(__NR_umount2, SysUmount2, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_ioctl, SysIoctl, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_fcntl, SysFcntl, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_dup2, SysDup2, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_truncate, SysTruncate, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_ftruncate, SysFtruncate, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_statfs, SysStatfs, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fstatfs, SysFstatfs, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fstatfs64, SysFstatfs64, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_stat, SysStat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_lstat, SysLstat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fstat, SysFstat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fstatat64, SysFstatat64, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_fsync, SysFsync, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR__llseek, SysLseek64, off64_t, ARG_NUM_5) /* current only support 32bit max 4G file */ +// SYSCALL_HAND_DEF(__NR__newselect, SysSelect, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_pselect6, SysPselect6, int, ARG_NUM_6) +// SYSCALL_HAND_DEF(__NR_readv, SysReadv, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_writev, SysWritev, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_poll, SysPoll, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_ppoll, SysPpoll, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_prctl, SysPrctl, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_pread64, SysPread64, ssize_t, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_pwrite64, SysPwrite64, ssize_t, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_epoll_create, SysEpollCreate, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_epoll_create1, SysEpollCreate1, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_epoll_ctl, SysEpollCtl, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_epoll_wait, SysEpollWait, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_epoll_pwait, SysEpollPwait, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_getcwd, SysGetcwd, char *, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_sendfile, SysSendFile, ssize_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_truncate64, SysTruncate64, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_ftruncate64, SysFtruncate64, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_stat64, SysStat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_lstat64, SysLstat, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fstat64, SysFstat64, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_fcntl64, SysFcntl64, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_sendfile64, SysSendFile, ssize_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_preadv, SysPreadv, ssize_t, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_pwritev, SysPwritev, ssize_t, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_fallocate, SysFallocate64, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_getdents64, SysGetdents64, int, ARG_NUM_3) + +// #ifdef LOSCFG_FS_FAT +// SYSCALL_HAND_DEF(__NR_format, SysFormat, int, ARG_NUM_3) +// #endif + +// SYSCALL_HAND_DEF(__NR_linkat, SysLinkat, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_symlinkat, SysSymlinkat, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_readlinkat, SysReadlinkat, ssize_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_unlinkat, SysUnlinkat, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_renameat, SysRenameat, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_openat, SysOpenat, int, ARG_NUM_7) +// SYSCALL_HAND_DEF(__NR_mkdirat, SysMkdirat, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_statfs64, SysStatfs64, int, ARG_NUM_3) +// #ifdef LOSCFG_DEBUG_VERSION +// SYSCALL_HAND_DEF(__NR_dumpmemory, LOS_DumpMemRegion, void, ARG_NUM_1) +// #endif +// #ifdef LOSCFG_KERNEL_PIPE +// SYSCALL_HAND_DEF(__NR_mkfifo, SysMkFifo, int, ARG_NUM_2) +// #endif +// SYSCALL_HAND_DEF(__NR_mqclose, SysMqClose, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_realpath, SysRealpath, char *, ARG_NUM_2) + +// #ifdef LOSCFG_SHELL +// SYSCALL_HAND_DEF(__NR_shellexec, SysShellExec, UINT32, ARG_NUM_2) +// #endif +// #endif + +// SYSCALL_HAND_DEF(__NR_exit, SysThreadExit, void, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_fork, SysFork, int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_vfork, SysVfork, int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_getpid, SysGetPID, unsigned int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_pause, SysPause, int, ARG_NUM_0) + +// SYSCALL_HAND_DEF(__NR_kill, SysKill, int, ARG_NUM_2) + +// SYSCALL_HAND_DEF(__NR_reboot, SysReboot, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_times, SysTimes, clock_t, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_brk, SysBrk, void *, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_setgid, SysSetGroupID, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_getgid, SysGetGroupID, int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_setpgid, SysSetProcessGroupID, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_getppid, SysGetPPID, unsigned int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_getpgrp, SysGetProcessGroupID, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_munmap, SysMunmap, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_getpriority, SysGetProcessPriority, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setpriority, SysSetProcessPriority, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_setitimer, SysSetiTimer, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_getitimer, SysGetiTimer, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_wait4, SysWait, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_waitid, SysWaitid, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_uname, SysUname, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_mprotect, SysMprotect, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_getpgid, SysGetProcessGroupID, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_sched_setparam, SysSchedSetParam, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_sched_getparam, SysSchedGetParam, int, ARG_NUM_2) +SYSCALL_HAND_DEF(__NR_sched_setscheduler, SysSchedSetScheduler, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_sched_getscheduler, SysSchedGetScheduler, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_sched_yield, SysSchedYield, void, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_sched_get_priority_max, SysSchedGetPriorityMax, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_sched_get_priority_min, SysSchedGetPriorityMin, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_sched_setaffinity, SysSchedSetAffinity, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_sched_getaffinity, SysSchedGetAffinity, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_sched_rr_get_interval, SysSchedRRGetInterval, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_nanosleep, SysNanoSleep, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_mremap, SysMremap, void *, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_umask, SysUmask, mode_t, ARG_NUM_1) + +// SYSCALL_HAND_DEF(__NR_rt_sigaction, SysSigAction, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_rt_sigprocmask, SysSigprocMask, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_rt_sigpending, SysSigPending, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_rt_sigtimedwait, SysSigTimedWait, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_rt_sigsuspend, SysSigSuspend, int, ARG_NUM_1) + +// SYSCALL_HAND_DEF(__NR_fchownat, SysFchownat, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_fchown32, SysFchown, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_chown, SysChown, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_chown32, SysChown, int, ARG_NUM_3) +// #ifdef LOSCFG_SECURITY_CAPABILITY +// SYSCALL_HAND_DEF(__NR_ohoscapget, SysCapGet, UINT32, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_ohoscapset, SysCapSet, UINT32, ARG_NUM_1) +// #endif + +// SYSCALL_HAND_DEF(__NR_mmap2, SysMmap, void*, ARG_NUM_6) +// SYSCALL_HAND_DEF(__NR_getuid32, SysGetUserID, int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_getgid32, SysGetGroupID, unsigned int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_geteuid32, SysGetEffUserID, int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_getegid32, SysGetEffGID, unsigned int, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_getresuid32, SysGetRealEffSaveUserID, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_getresgid32, SysGetRealEffSaveGroupID, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_setresuid32, SysSetRealEffSaveUserID, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_setresgid32, SysSetRealEffSaveGroupID, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_setreuid32, SysSetRealEffUserID, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setregid32, SysSetRealEffGroupID, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setgroups32, SysSetGroups, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_getgroups32, SysGetGroups, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setuid32, SysSetUserID, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_setgid32, SysSetGroupID, int, ARG_NUM_1) + +// SYSCALL_HAND_DEF(__NR_gettid, SysGetTid, unsigned int, ARG_NUM_0) + +// SYSCALL_HAND_DEF(__NR_tkill, SysPthreadKill, int, ARG_NUM_2) + +// SYSCALL_HAND_DEF(__NR_futex, SysFutex, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_exit_group, SysUserExitGroup, void, ARG_NUM_1) +SYSCALL_HAND_DEF(__NR_set_thread_area, SysSetThreadArea, int, ARG_NUM_1) +SYSCALL_HAND_DEF(__NR_get_thread_area, SysGetThreadArea, char *, ARG_NUM_0) +// SYSCALL_HAND_DEF(__NR_timer_create, SysTimerCreate, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_timer_settime32, SysTimerSettime, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_timer_gettime32, SysTimerGettime, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_timer_getoverrun, SysTimerGetoverrun, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_timer_delete, SysTimerDelete, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_clock_settime32, SysClockSettime, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_clock_gettime32, SysClockGettime, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_clock_getres_time32, SysClockGetres, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_clock_nanosleep_time32, SysClockNanoSleep, int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_mq_open, SysMqOpen, mqd_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_mq_unlink, SysMqUnlink, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_mq_timedsend, SysMqTimedSend, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_mq_timedreceive, SysMqTimedReceive, ssize_t, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_mq_notify, SysMqNotify, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_mq_getsetattr, SysMqGetSetAttr, int, ARG_NUM_3) + +// #ifdef LOSCFG_NET_LWIP_SACK +// SYSCALL_HAND_DEF(__NR_socket, SysSocket, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_bind, SysBind, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_connect, SysConnect, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_listen, SysListen, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_accept, SysAccept, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_getsockname, SysGetSockName, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_getpeername, SysGetPeerName, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_send, SysSend, ssize_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_sendto, SysSendTo, ssize_t, ARG_NUM_6) +// SYSCALL_HAND_DEF(__NR_recv, SysRecv, ssize_t, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_recvfrom, SysRecvFrom, ssize_t, ARG_NUM_6) +// SYSCALL_HAND_DEF(__NR_shutdown, SysShutdown, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setsockopt, SysSetSockOpt, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_getsockopt, SysGetSockOpt, int, ARG_NUM_5) +// SYSCALL_HAND_DEF(__NR_sendmsg, SysSendMsg, ssize_t, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_recvmsg, SysRecvMsg, ssize_t, ARG_NUM_3) +// #endif + +// #ifdef LOSCFG_KERNEL_SHM +// SYSCALL_HAND_DEF(__NR_shmat, SysShmAt, void *, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_shmdt, SysShmDt, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_shmget, SysShmGet, int, ARG_NUM_3) +// SYSCALL_HAND_DEF(__NR_shmctl, SysShmCtl, int, ARG_NUM_3) +// #endif + +// SYSCALL_HAND_DEF(__NR_statx, SysStatx, int, ARG_NUM_5) + +// /* LiteOS customized syscalls, not compatible with ARM EABI */ +// SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDetach, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_pthread_join, SysThreadJoin, int, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_pthread_deatch, SysUserThreadDetach, int, ARG_NUM_1) +SYSCALL_HAND_DEF(__NR_creat_user_thread, SysUserTaskCreate, unsigned int, ARG_NUM_4) +// SYSCALL_HAND_DEF(__NR_getrusage, SysGetrusage, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_sysconf, SysSysconf, long, ARG_NUM_1) +// SYSCALL_HAND_DEF(__NR_ugetrlimit, SysUgetrlimit, int, ARG_NUM_2) +// SYSCALL_HAND_DEF(__NR_setrlimit, SysSetrlimit, int, ARG_NUM_2) diff --git a/components/security/userlib/BUILD.gn b/components/security/userlib/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..efc57507eee8ce98921a7fdda4150399853d8f97 --- /dev/null +++ b/components/security/userlib/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022-2022 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. + +import("//kernel/liteos_m/liteos.gni") + +module_switch = defined(LOSCFG_SECURE) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { + sources = [] + + deps = [ "//third_party/musl/porting/liteos_m/user" ] +} diff --git a/kernel/include/los_task.h b/kernel/include/los_task.h index a5091bc21a8e9be01a9e5a8e68e5a6287ddfd84e..ec05e2163e98c8d0fb6486cddfe4db5f2652286c 100644 --- a/kernel/include/los_task.h +++ b/kernel/include/los_task.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -1277,6 +1277,16 @@ extern UINT32 LOS_TaskDetach(UINT32 taskID); */ #define OS_TASK_STATUS_EXIT 0x0100 +#if (LOSCFG_SECURE == 1) +/** + * @ingroup los_task + * Flag that indicates the task or task control block status. + * + * This task is a user mode task. + */ +#define OS_TASK_FLAG_USER_TASK 0x0200 +#endif + /** * @ingroup los_task * Flag that indicates the task or task control block status. diff --git a/kernel/src/los_init.c b/kernel/src/los_init.c index 012cf2db19ee1228424f883e5203c81e047f04c1..8cf81c2d5fecf13f0608f8172468d820069e95cb 100644 --- a/kernel/src/los_init.c +++ b/kernel/src/los_init.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -82,6 +82,11 @@ #include "los_signal.h" #endif +#if (LOSCFG_SECURE == 1) +#include "los_syscall.h" +#include "los_box.h" +#endif + /***************************************************************************** Function : LOS_Reboot Description : system exception, die in here, wait for watchdog. @@ -262,6 +267,11 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID) } #endif +#if (LOSCFG_SECURE == 1) + OsSyscallHandleInit(); + LOS_BoxStart(); +#endif + return LOS_OK; } diff --git a/kernel/src/los_task.c b/kernel/src/los_task.c index 7695f683faa0e3907bd4eb959f9a8fb7868ecdd7..16ccff5debbf8da4ee86d9d01d7313b68365938a 100644 --- a/kernel/src/los_task.c +++ b/kernel/src/los_task.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -164,7 +164,7 @@ STATIC VOID OsRecyleFinishedTask(VOID) stackPtr = 0; OsRecycleTaskResources(taskCB, &stackPtr); LOS_IntRestore(intSave); - + (VOID)LOS_MemFree(OS_TASK_STACK_ADDR, (VOID *)stackPtr); intSave = LOS_IntLock(); } diff --git a/kernel/src/mm/los_memory.c b/kernel/src/mm/los_memory.c index 9794d810f2668536066541a0e12a4e01e7ef504d..19429965849e67bea9001e162be08c0a81d85f4e 100644 --- a/kernel/src/mm/los_memory.c +++ b/kernel/src/mm/los_memory.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2022 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: @@ -2288,7 +2288,7 @@ UINT32 OsMemSystemInit(VOID) #endif ret = LOS_MemInit(m_aucSysMem0, LOSCFG_SYS_HEAP_SIZE); - PRINT_INFO("LiteOS heap memory address:%p, size:0x%lx\n", m_aucSysMem0, LOSCFG_SYS_HEAP_SIZE); + PRINT_INFO("LiteOS heap memory address:%p, size:0x%lx\n", m_aucSysMem0, (unsigned long int)LOSCFG_SYS_HEAP_SIZE); return ret; }