2020-09-08 10:21:39 +08:00
|
|
|
/*
|
2021-03-11 18:43:57 +08:00
|
|
|
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
|
|
|
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
2020-09-08 10:21:39 +08:00
|
|
|
*
|
|
|
|
* 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
|
2020-10-09 20:24:08 +08:00
|
|
|
#ifdef LOSCFG_FS_VFS
|
2021-06-15 20:55:38 +08:00
|
|
|
#include "fs/file.h"
|
2020-10-09 20:24:08 +08:00
|
|
|
#include "fs/file.h"
|
|
|
|
#endif
|
2021-05-20 16:45:43 +08:00
|
|
|
#include "los_init.h"
|
2020-10-09 20:24:08 +08:00
|
|
|
#include "los_signal.h"
|
2020-09-08 10:21:39 +08:00
|
|
|
#include "los_syscall.h"
|
|
|
|
#include "los_task_pri.h"
|
|
|
|
#include "los_process_pri.h"
|
2021-04-26 19:54:49 +08:00
|
|
|
#include "los_hw_pri.h"
|
2020-09-08 10:21:39 +08:00
|
|
|
#include "los_printf.h"
|
|
|
|
#include "time.h"
|
|
|
|
#include "utime.h"
|
|
|
|
#include "poll.h"
|
|
|
|
#include "mqueue.h"
|
|
|
|
#include "los_futex_pri.h"
|
|
|
|
#include "sys/times.h"
|
|
|
|
#include "dirent.h"
|
|
|
|
#include "fcntl.h"
|
|
|
|
#include "unistd.h"
|
|
|
|
|
|
|
|
#include "sys/mount.h"
|
|
|
|
#include "sys/resource.h"
|
|
|
|
#include "sys/mman.h"
|
|
|
|
#include "sys/uio.h"
|
|
|
|
#include "sys/prctl.h"
|
|
|
|
#include "sys/socket.h"
|
|
|
|
#include "sys/utsname.h"
|
|
|
|
#include "poll.h"
|
|
|
|
#include "sys/uio.h"
|
|
|
|
#ifdef LOSCFG_SHELL
|
|
|
|
#include "shmsg.h"
|
|
|
|
#endif
|
|
|
|
#ifdef LOSCFG_SECURITY_CAPABILITY
|
|
|
|
#include "capability_api.h"
|
|
|
|
#endif
|
|
|
|
#include "sys/shm.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define SYS_CALL_NUM (__NR_syscallend + 1)
|
|
|
|
#define NARG_BITS 4
|
|
|
|
#define NARG_MASK 0x0F
|
|
|
|
#define NARG_PER_BYTE 2
|
|
|
|
|
|
|
|
typedef UINT32 (*SyscallFun1)(UINT32);
|
|
|
|
typedef UINT32 (*SyscallFun3)(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] = {0};
|
|
|
|
static UINT8 g_syscallNArgs[(SYS_CALL_NUM + 1) / NARG_PER_BYTE] = {0};
|
|
|
|
|
2021-05-20 16:45:43 +08:00
|
|
|
void OsSyscallHandleInit(void)
|
2020-09-08 10:21:39 +08:00
|
|
|
{
|
|
|
|
#define SYSCALL_HAND_DEF(id, fun, rType, nArg) \
|
|
|
|
if ((id) < SYS_CALL_NUM) { \
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-05-20 16:45:43 +08:00
|
|
|
LOS_MODULE_INIT(OsSyscallHandleInit, LOS_INIT_LEVEL_KMOD_EXTENDED);
|
|
|
|
|
2020-09-08 10:21:39 +08:00
|
|
|
/* The SYSCALL ID is in R7 on entry. Parameters follow in R0..R6 */
|
2021-04-26 19:54:49 +08:00
|
|
|
VOID OsArmA32SyscallHandle(TaskContext *regs)
|
2020-09-08 10:21:39 +08:00
|
|
|
{
|
|
|
|
UINT32 ret;
|
|
|
|
UINT8 nArgs;
|
|
|
|
UINTPTR handle;
|
2021-05-07 19:09:10 +08:00
|
|
|
UINT32 cmd = regs->reserved2;
|
2020-09-08 10:21:39 +08:00
|
|
|
|
|
|
|
if (cmd >= SYS_CALL_NUM) {
|
|
|
|
PRINT_ERR("Syscall ID: error %d !!!\n", cmd);
|
2021-04-26 19:54:49 +08:00
|
|
|
return;
|
2020-09-08 10:21:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handle = g_syscallHandle[cmd];
|
|
|
|
nArgs = g_syscallNArgs[cmd / NARG_PER_BYTE]; /* 4bit per nargs */
|
|
|
|
nArgs = (cmd & 1) ? (nArgs >> NARG_BITS) : (nArgs & NARG_MASK);
|
|
|
|
if ((handle == 0) || (nArgs > ARG_NUM_7)) {
|
|
|
|
PRINT_ERR("Unsupport syscall ID: %d nArgs: %d\n", cmd, nArgs);
|
2021-04-26 19:54:49 +08:00
|
|
|
regs->R0 = -ENOSYS;
|
|
|
|
return;
|
2020-09-08 10:21:39 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 19:51:25 +08:00
|
|
|
OsSigIntLock();
|
2020-09-08 10:21:39 +08:00
|
|
|
switch (nArgs) {
|
|
|
|
case ARG_NUM_0:
|
|
|
|
case ARG_NUM_1:
|
2021-04-26 19:54:49 +08:00
|
|
|
ret = (*(SyscallFun1)handle)(regs->R0);
|
2020-09-08 10:21:39 +08:00
|
|
|
break;
|
|
|
|
case ARG_NUM_2:
|
|
|
|
case ARG_NUM_3:
|
2021-04-26 19:54:49 +08:00
|
|
|
ret = (*(SyscallFun3)handle)(regs->R0, regs->R1, regs->R2);
|
2020-09-08 10:21:39 +08:00
|
|
|
break;
|
|
|
|
case ARG_NUM_4:
|
|
|
|
case ARG_NUM_5:
|
2021-04-26 19:54:49 +08:00
|
|
|
ret = (*(SyscallFun5)handle)(regs->R0, regs->R1, regs->R2, regs->R3, regs->R4);
|
2020-09-08 10:21:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
2021-04-26 19:54:49 +08:00
|
|
|
ret = (*(SyscallFun7)handle)(regs->R0, regs->R1, regs->R2, regs->R3, regs->R4, regs->R5, regs->R6);
|
2020-09-08 10:21:39 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:54:49 +08:00
|
|
|
regs->R0 = ret;
|
2021-05-20 19:51:25 +08:00
|
|
|
OsSigIntUnlock();
|
2020-09-08 10:21:39 +08:00
|
|
|
|
2021-04-26 19:54:49 +08:00
|
|
|
return;
|
2020-09-08 10:21:39 +08:00
|
|
|
}
|