add OpenHarmony 1.0 baseline
This commit is contained in:
42
syscall/Makefile
Executable file
42
syscall/Makefile
Executable file
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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 $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard *.c)
|
||||
|
||||
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/fs/include \
|
||||
-I $(LITEOSTOPDIR)/compat/posix/include \
|
||||
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include \
|
||||
-I $(LITEOSTOPDIR)/../../third_party/musl/kernel/include
|
||||
|
||||
include $(MODULE)
|
||||
1933
syscall/fs_syscall.c
Executable file
1933
syscall/fs_syscall.c
Executable file
File diff suppressed because it is too large
Load Diff
295
syscall/ipc_syscall.c
Executable file
295
syscall/ipc_syscall.c
Executable file
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "mqueue.h"
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "time_posix.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_signal.h"
|
||||
#include "los_strncpy_from_user.h"
|
||||
|
||||
mqd_t SysMqOpen(const char *mqName, int openFlag, mode_t mode, struct mq_attr *attr)
|
||||
{
|
||||
mqd_t ret;
|
||||
int retValue;
|
||||
char kMqName[PATH_MAX + 1] = { 0 };
|
||||
|
||||
retValue = LOS_StrncpyFromUser(kMqName, mqName, PATH_MAX);
|
||||
if (retValue < 0) {
|
||||
return retValue;
|
||||
}
|
||||
ret = mq_open(kMqName, openFlag, mode, attr);
|
||||
if (ret == -1) {
|
||||
return (mqd_t)-get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysMqClose(mqd_t personal)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = mq_close(personal);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysMqGetSetAttr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old)
|
||||
{
|
||||
int ret;
|
||||
struct mq_attr knew, kold;
|
||||
|
||||
if (new != NULL) {
|
||||
ret = LOS_ArchCopyFromUser(&knew, new, sizeof(struct mq_attr));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
ret = mq_getsetattr(mqd, new ? &knew : NULL, old ? &kold : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
if (old != NULL) {
|
||||
ret = LOS_ArchCopyToUser(old, &kold, sizeof(struct mq_attr));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysMqUnlink(const char *mqName)
|
||||
{
|
||||
int ret;
|
||||
int retValue;
|
||||
char kMqName[PATH_MAX + 1] = { 0 };
|
||||
|
||||
retValue = LOS_StrncpyFromUser(kMqName, mqName, PATH_MAX);
|
||||
if (retValue < 0) {
|
||||
return retValue;
|
||||
}
|
||||
|
||||
ret = mq_unlink(kMqName);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysMqTimedSend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio,
|
||||
const struct timespec *absTimeout)
|
||||
{
|
||||
int ret;
|
||||
struct timespec timeout;
|
||||
char *msgIntr = NULL;
|
||||
|
||||
if (absTimeout != NULL) {
|
||||
ret = LOS_ArchCopyFromUser(&timeout, absTimeout, sizeof(struct timespec));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
if (msgLen == 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
msgIntr = (char *)malloc(msgLen);
|
||||
if (msgIntr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
ret = LOS_ArchCopyFromUser(msgIntr, msg, msgLen);
|
||||
if (ret != 0) {
|
||||
free(msgIntr);
|
||||
return -EFAULT;
|
||||
}
|
||||
ret = mq_timedsend(personal, msgIntr, msgLen, msgPrio, absTimeout ? &timeout : NULL);
|
||||
free(msgIntr);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysMqTimedReceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio,
|
||||
const struct timespec *absTimeout)
|
||||
{
|
||||
int ret, receiveLen;
|
||||
struct timespec timeout;
|
||||
char *msgIntr = NULL;
|
||||
unsigned int kMsgPrio;
|
||||
|
||||
if (absTimeout != NULL) {
|
||||
ret = LOS_ArchCopyFromUser(&timeout, absTimeout, sizeof(struct timespec));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
if (msgLen == 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
msgIntr = (char *)malloc(msgLen);
|
||||
if (msgIntr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
receiveLen = mq_timedreceive(personal, msgIntr, msgLen, &kMsgPrio, absTimeout ? &timeout : NULL);
|
||||
if (receiveLen < 0) {
|
||||
free(msgIntr);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (msgPrio != NULL) {
|
||||
ret = LOS_ArchCopyToUser(msgPrio, &kMsgPrio, sizeof(unsigned int));
|
||||
if (ret != 0) {
|
||||
free(msgIntr);
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
ret = LOS_ArchCopyToUser(msg, msgIntr, receiveLen);
|
||||
free(msgIntr);
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
return receiveLen;
|
||||
}
|
||||
|
||||
int SysSigAction(int sig, const sigaction_t *restrict sa, sigaction_t *restrict old, size_t sigsetsize)
|
||||
{
|
||||
return OsSigAction(sig, sa, old);
|
||||
}
|
||||
|
||||
int SysSigprocMask(int how, const sigset_t_l *restrict setl, sigset_t_l *restrict oldl, size_t sigsetsize)
|
||||
{
|
||||
/* Let nxsig_procmask do all of the work */
|
||||
return OsSigprocMask(how, setl, oldl);
|
||||
}
|
||||
|
||||
int SysKill(pid_t pid, int sig)
|
||||
{
|
||||
return OsKillLock(pid, sig);
|
||||
}
|
||||
|
||||
int SysPthreadKill(pid_t pid, int sig)
|
||||
{
|
||||
return OsPthreadKill(pid, sig);
|
||||
}
|
||||
|
||||
int SysSigTimedWait(const sigset_t_l *setl, siginfo_t *info, const struct timespec *timeout, size_t sigsetsize)
|
||||
{
|
||||
sigset_t set;
|
||||
unsigned int tick;
|
||||
int retVal, ret;
|
||||
siginfo_t infoIntr;
|
||||
struct timespec timeoutIntr;
|
||||
|
||||
retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
|
||||
if (retVal != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (timeout == NULL) {
|
||||
tick = LOS_WAIT_FOREVER;
|
||||
} else {
|
||||
retVal = LOS_ArchCopyFromUser(&timeoutIntr, timeout, sizeof(struct timespec));
|
||||
if (retVal != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
if (!ValidTimeSpec(&timeoutIntr)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
tick = OsTimeSpec2Tick(&timeoutIntr);
|
||||
}
|
||||
ret = OsSigTimedWait(&set, &infoIntr, tick);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
if (info != NULL) {
|
||||
retVal = LOS_ArchCopyToUser(info, &infoIntr, sizeof(siginfo_t));
|
||||
if (retVal != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
return (ret == 0 ? infoIntr.si_signo : ret);
|
||||
}
|
||||
|
||||
int SysPause(void)
|
||||
{
|
||||
return OsPause();
|
||||
}
|
||||
|
||||
int SysSigPending(sigset_t_l *setl)
|
||||
{
|
||||
sigset_t set;
|
||||
int ret;
|
||||
|
||||
ret = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
ret = OsSigPending(&set);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
ret = LOS_ArchCopyToUser(&(setl->sig[0]), &set, sizeof(sigset_t));
|
||||
if (ret != LOS_OK) {
|
||||
return -EFAULT;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysSigSuspend(sigset_t_l *setl)
|
||||
{
|
||||
sigset_t set;
|
||||
int retVal;
|
||||
|
||||
retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t));
|
||||
if (retVal != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return OsSigSuspend(&set);
|
||||
}
|
||||
|
||||
int SysMkFifo(const char *pathName, mode_t mode)
|
||||
{
|
||||
int retValue;
|
||||
char kPathName[PATH_MAX + 1] = { 0 };
|
||||
|
||||
retValue = LOS_StrncpyFromUser(kPathName, pathName, PATH_MAX);
|
||||
if (retValue < 0) {
|
||||
return retValue;
|
||||
}
|
||||
return mkfifo(kPathName, mode);
|
||||
}
|
||||
|
||||
148
syscall/los_syscall.c
Executable file
148
syscall/los_syscall.c
Executable file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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_task_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#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"
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "fs/fs.h"
|
||||
#include "fs/file.h"
|
||||
#endif
|
||||
#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};
|
||||
|
||||
void SyscallHandleInit(void)
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
/* The SYSCALL ID is in R7 on entry. Parameters follow in R0..R6 */
|
||||
LITE_OS_SEC_TEXT UINT32 *OsArmA32SyscallHandle(UINT32 *regs)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT8 nArgs;
|
||||
UINTPTR handle;
|
||||
UINT32 cmd = regs[REG_R7];
|
||||
|
||||
if (cmd >= SYS_CALL_NUM) {
|
||||
PRINT_ERR("Syscall ID: error %d !!!\n", cmd);
|
||||
return regs;
|
||||
}
|
||||
|
||||
if (cmd == __NR_sigreturn) {
|
||||
OsRestorSignalContext(regs);
|
||||
return regs;
|
||||
}
|
||||
|
||||
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);
|
||||
regs[REG_R0] = -ENOSYS;
|
||||
return regs;
|
||||
}
|
||||
|
||||
switch (nArgs) {
|
||||
case ARG_NUM_0:
|
||||
case ARG_NUM_1:
|
||||
ret = (*(SyscallFun1)handle)(regs[REG_R0]);
|
||||
break;
|
||||
case ARG_NUM_2:
|
||||
case ARG_NUM_3:
|
||||
ret = (*(SyscallFun3)handle)(regs[REG_R0], regs[REG_R1], regs[REG_R2]);
|
||||
break;
|
||||
case ARG_NUM_4:
|
||||
case ARG_NUM_5:
|
||||
ret = (*(SyscallFun5)handle)(regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
||||
regs[REG_R4]);
|
||||
break;
|
||||
default:
|
||||
ret = (*(SyscallFun7)handle)(regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
||||
regs[REG_R4], regs[REG_R5], regs[REG_R6]);
|
||||
}
|
||||
|
||||
regs[REG_R0] = ret;
|
||||
|
||||
OsSaveSignalContext(regs);
|
||||
|
||||
/* Return the last value of curent_regs. This supports context switches on return from the exception.
|
||||
* That capability is only used with theSYS_context_switch system call.
|
||||
*/
|
||||
return regs;
|
||||
}
|
||||
262
syscall/los_syscall.h
Executable file
262
syscall/los_syscall.h
Executable file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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_typedef.h"
|
||||
#include "los_task.h"
|
||||
#include "los_mux.h"
|
||||
#include "syscall.h"
|
||||
#ifdef LOSCFG_KERNEL_DYNLOAD
|
||||
#include "los_exec_elf.h"
|
||||
#endif
|
||||
#include "sys/times.h"
|
||||
#include "sys/utsname.h"
|
||||
#include "sys/shm.h"
|
||||
#include "poll.h"
|
||||
#include "utime.h"
|
||||
#include "mqueue.h"
|
||||
#include "time.h"
|
||||
#include "sys/time.h"
|
||||
#include "sys/stat.h"
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "sys/socket.h"
|
||||
#include "dirent.h"
|
||||
#endif
|
||||
|
||||
/* process */
|
||||
extern unsigned int SysGetGroupId(void);
|
||||
extern unsigned int SysGetTid(void);
|
||||
extern void SysSchedYield(int type);
|
||||
extern int SysSchedGetScheduler(int id, int flag);
|
||||
extern int SysSchedSetScheduler(int id, int policy, int prio, int flag);
|
||||
extern int SysSchedGetParam(int id, int flag);
|
||||
extern int SysSchedSetParam(int id, unsigned int prio, int flag);
|
||||
extern int SysSetProcessPriority(int which, int who, unsigned int prio);
|
||||
extern int SysGetProcessPriority(int which, int who);
|
||||
extern int SysSchedGetPriorityMin(int policy);
|
||||
extern int SysSchedGetPriorityMax(int policy);
|
||||
extern int SysSchedRRGetInterval(int pid, struct timespec *tp);
|
||||
extern int SysWait(int pid, USER int *status, int options, void *rusage);
|
||||
extern int SysFork(void);
|
||||
extern unsigned int SysGetPID(void);
|
||||
extern unsigned int SysGetPPID(void);
|
||||
extern int SysSetGroupID(unsigned int gid);
|
||||
extern int SysGetGroupID(void);
|
||||
extern int SysGetUserID(void);
|
||||
extern int SysGetEffUserID(void);
|
||||
extern int SysGetEffGID(void);
|
||||
extern int SysSetUserID(int uid);
|
||||
extern int SysGetRealEffSaveUserID(int *ruid, int *euid, int *suid);
|
||||
extern int SysGetRealEffSaveGroupID(int *rgid, int *egid, int *sgid);
|
||||
extern int SysSetRealEffUserID(int ruid, int euid);
|
||||
extern int SysSetRealEffGroupID(int rgid, int egid);
|
||||
extern int SysSetRealEffSaveGroupID(int rgid, int egid, int sgid);
|
||||
extern int SysSetRealEffSaveUserID(int ruid, int euid, int suid);
|
||||
extern int SysGetGroups(int size, int list[]);
|
||||
extern int SysSetGroups(int size, int list[]);
|
||||
extern int SysGetCurrProcessGroupID(void);
|
||||
extern int SysGetProcessGroupID(unsigned int pid);
|
||||
extern int SysSetProcessGroupID(unsigned int pid, unsigned int gid);
|
||||
extern unsigned int SysCreateUserThread(const TSK_ENTRY_FUNC func, const UserTaskParam *userParam, bool joinable);
|
||||
extern int SysSetThreadArea(const char *area);
|
||||
extern char *SysGetThreadArea(void);
|
||||
extern int SysUserThreadSetDeatch(unsigned int taskID);
|
||||
extern int SysUserThreadDetach(unsigned int taskID);
|
||||
extern int SysThreadJoin(unsigned int taskID);
|
||||
extern void SysUserExitGroup(int status);
|
||||
extern void SysThreadExit(int status);
|
||||
extern int SysFutex(const unsigned int *uAddr, unsigned int flags, int val,
|
||||
unsigned int absTime, const unsigned int *newUserAddr);
|
||||
extern mqd_t SysMqOpen(const char *mqName, int openFlag, mode_t mode, struct mq_attr *attr);
|
||||
extern int SysMqClose(mqd_t personal);
|
||||
extern int SysMqGetSetAttr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old);
|
||||
extern int SysMqUnlink(const char *mqName);
|
||||
extern int SysMqSend(mqd_t personal, const char *msgPtr, size_t msgLen, unsigned int msgPrio);
|
||||
extern int SysMqTimedSend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio,
|
||||
const struct timespec *absTimeout);
|
||||
extern ssize_t SysMqTimedReceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio,
|
||||
const struct timespec *absTimeout);
|
||||
extern int SysSigAction(int sig, const sigaction_t *restrict sa, sigaction_t *restrict old, size_t sigsetsize);
|
||||
extern int SysSigprocMask(int how, const sigset_t_l *restrict set, sigset_t *restrict old, size_t sigsetsize);
|
||||
extern int SysKill(pid_t pid, int sig);
|
||||
extern int SysPthreadKill(pid_t pid, int sig);
|
||||
extern int SysSigTimedWait(const sigset_t *set, siginfo_t *info,
|
||||
const struct timespec *timeoutsize_t, size_t sigsetsize);
|
||||
extern int SysPause(void);
|
||||
extern int SysSigPending(sigset_t_l *setl);
|
||||
extern int SysSigSuspend(sigset_t_l *setl);
|
||||
extern int SysMkFifo(const char *pathName, mode_t mode);
|
||||
|
||||
/* net */
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
extern int SysSocket(int domain, int type, int protocol);
|
||||
extern int SysBind(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
extern int SysConnect(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
extern int SysListen(int sockfd, int backlog);
|
||||
extern int SysAccept(int socket, struct sockaddr *address, socklen_t *addressLen);
|
||||
extern int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen);
|
||||
extern int SysGetPeerName (int s, struct sockaddr *name, socklen_t *namelen);
|
||||
extern ssize_t SysSend(int s, const void *dataptr, size_t size, int flags);
|
||||
extern ssize_t SysSendTo(int s, const void *dataptr, size_t size, int flags,
|
||||
const struct sockaddr *to, socklen_t tolen);
|
||||
extern ssize_t SysRecv(int socket, void *buffer, size_t length, int flags);
|
||||
extern ssize_t SysRecvFrom(int socket, void *buffer, size_t length, int flags,
|
||||
struct sockaddr *address, socklen_t *addressLen);
|
||||
extern int SysShutdown(int socket, int how);
|
||||
extern int SysSetSockOpt(int socket, int level, int optName,
|
||||
const void *optValue, socklen_t optLen);
|
||||
extern int SysGetSockOpt(int sockfd, int level, int optName,
|
||||
void *optValue, socklen_t *optLen);
|
||||
extern ssize_t SysSendMsg(int s, const struct msghdr *message, int flags);
|
||||
extern ssize_t SysRecvMsg(int s, struct msghdr *message, int flags);
|
||||
#endif
|
||||
|
||||
/* vmm */
|
||||
extern void *SysMmap(void *addr, size_t size, int prot, int flags, int fd, size_t offset);
|
||||
extern int SysMunmap(void *addr, size_t size);
|
||||
extern int SysMprotect(vaddr_t vaddr, size_t len, int prot);
|
||||
extern vaddr_t SysMremap(vaddr_t old_address, size_t old_size, size_t new_size, int flags, vaddr_t new_addr);
|
||||
extern void *SysBrk(void *addr);
|
||||
extern int SysShmGet(key_t key, size_t size, int shmflg);
|
||||
extern void *SysShmAt(int shmid, const void *shmaddr, int shmflg);
|
||||
extern int SysShmCtl(int shmid, int cmd, struct shmid_ds *buf);
|
||||
extern int SysShmDt(const void *shmaddr);
|
||||
|
||||
/* misc */
|
||||
extern int SysUname(struct utsname *name);
|
||||
|
||||
/* time */
|
||||
extern int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||
extern clock_t SysTimes(struct tms *buf);
|
||||
extern time_t SysTime(time_t *tloc);
|
||||
extern int SysSetiTimer(int which, const struct itimerval *value, struct itimerval *ovalue);
|
||||
extern int SysGetiTimer(int which, struct itimerval *value);
|
||||
extern int SysTimerCreate(clockid_t clockID, struct sigevent *evp, timer_t *timerID);
|
||||
extern int SysTimerGettime(timer_t timerID, struct itimerspec *value);
|
||||
extern int SysTimerGetoverrun(timer_t timerID);
|
||||
extern int SysTimerDelete(timer_t timerID);
|
||||
extern int SysClockSettime(clockid_t clockID, const struct timespec *tp);
|
||||
extern int SysClockGettime(clockid_t clockID, struct timespec *tp);
|
||||
extern int SysClockGetres(clockid_t clockID, struct timespec *tp);
|
||||
extern int SysClockNanoSleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem);
|
||||
extern int SysUtime(const char *path, const struct utimbuf *ptimes);
|
||||
extern int SysTimerSettime(timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue);
|
||||
|
||||
extern int SysClockSettime64(clockid_t clockID, const struct timespec64 *tp);
|
||||
extern int SysClockGettime64(clockid_t clockID, struct timespec64 *tp);
|
||||
extern int SysClockGetres64(clockid_t clockID, struct timespec64 *tp);
|
||||
extern int SysClockNanoSleep64(clockid_t clk, int flags, const struct timespec64 *req, struct timespec64 *rem);
|
||||
extern int SysTimerGettime64(timer_t timerID, struct itimerspec64 *value);
|
||||
extern int SysTimerSettime64(timer_t timerID, int flags, const struct itimerspec64 *value, struct itimerspec64 *oldValue);
|
||||
|
||||
/* filesystem */
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
typedef int (*PollFun)(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
extern int do_open(int dirfd, const char *path, int oflags, ...);
|
||||
extern int do_unlink(int dirfd, const char *pathname);
|
||||
extern int do_mkdir(int dirfd, const char *pathname, mode_t mode);
|
||||
extern int do_rmdir(int dirfd, const char *pathname);
|
||||
extern int do_rename(int oldfd, const char *oldpath, int newfd, const char *newpath);
|
||||
extern int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
||||
struct timeval *timeout, PollFun poll);
|
||||
extern int do_readdir(int fd, struct dirent **de, unsigned int count);
|
||||
extern ssize_t preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
extern ssize_t pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset);
|
||||
extern int chattr(const char *pathname, struct IATTR *attr);
|
||||
|
||||
extern int SysClose(int fd);
|
||||
extern ssize_t SysRead(int fd, void *buf, size_t nbytes);
|
||||
extern ssize_t SysWrite(int fd, const void *buf, size_t nbytes);
|
||||
extern int SysOpen(const char *path, int oflags, ...);
|
||||
extern int SysCreat(const char *pathname, mode_t mode);
|
||||
extern int SysUnlink( const char *pathname);
|
||||
extern int SysExecve(const char *fileName, char *const *argv, char *const *envp);
|
||||
extern int SysChdir(const char *path);
|
||||
extern int SysChmod(const char *path, mode_t mode);
|
||||
extern int SysChown(const char *pathname, uid_t owner, gid_t group);
|
||||
extern off_t SysLseek(int fd, off_t offset, int whence);
|
||||
extern off64_t SysLseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence);
|
||||
extern int SysMount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
extern int SysUmount(const char *target);
|
||||
extern int SysAccess(const char *path, int amode);
|
||||
extern int SysRename(const char *oldpath, const char *newpath);
|
||||
extern int SysMkdir(const char *pathname, mode_t mode);
|
||||
extern int SysRmdir(const char *pathname);
|
||||
extern int SysDup(int fd);
|
||||
extern int SysUmount2(const char *target, int flags);
|
||||
extern int SysIoctl(int fd, int req, void *arg);
|
||||
extern int SysFcntl(int fd, int cmd, void *arg);
|
||||
extern int SysDup2(int fd1, int fd2);
|
||||
extern int SysSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
extern int SysTruncate(const char *path, off_t length);
|
||||
extern int SysFtruncate(int fd, off_t length);
|
||||
extern int SysStatfs(const char *path, struct statfs *buf);
|
||||
extern int SysStatfs64(const char *path, size_t sz, struct statfs *buf);
|
||||
|
||||
extern int SysStat(const char *path, struct stat *buf);
|
||||
extern int SysLstat(const char *path, struct stat *buffer);
|
||||
extern int SysFstat(int fildes, struct stat *buf);
|
||||
extern int SysStatx(int fd, const char *restrict path, int flag, unsigned mask, struct statx *restrict stx);
|
||||
extern int SysFsync(int fd);
|
||||
extern ssize_t SysReadv(int fd, const struct iovec *iov, int iovcnt);
|
||||
extern ssize_t SysWritev(int fd, const struct iovec *iov, int iovcnt);
|
||||
extern int SysPipe(int pipefd[2]); /* 2 : pipe fds for read and write */
|
||||
extern int SysFormat(const char *dev, int sectors, int option);
|
||||
extern int SysFstat64(int fd, struct stat64 *buf);
|
||||
extern int SysFcntl64(int fd, int cmd, void *arg);
|
||||
extern int SysPoll(struct pollfd *fds, nfds_t nfds, int timeout);
|
||||
extern int SysPrctl(int option, ...);
|
||||
extern ssize_t SysPread64(int fd, void *buf, size_t nbytes, off64_t offset);
|
||||
extern ssize_t SysPwrite64(int fd, const void *buf, size_t nbytes, off64_t offset);
|
||||
extern char *SysGetcwd(char *buf, size_t n);
|
||||
extern ssize_t SysSendFile(int outfd, int infd, off_t *offset, size_t count);
|
||||
extern int SysTruncate(const char *path, off_t length);
|
||||
extern int SysTruncate64(const char *path, off64_t length);
|
||||
extern int SysFtruncate64(int fd, off64_t length);
|
||||
extern int SysOpenat(int dirfd, const char *path, int oflags, ...);
|
||||
extern int SysMkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||
extern int SysUnlinkat(int dirfd, const char *pathname, int flag);
|
||||
extern int SysRenameat(int oldfd, const char *oldpath, int newdfd, const char *newpath);
|
||||
extern int SysFallocate(int fd, int mode, off_t offset, off_t len);
|
||||
extern int SysFallocate64(int fd, int mode, off64_t offset, off64_t len);
|
||||
extern ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
|
||||
extern ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
|
||||
extern void SysSync(void);
|
||||
extern int SysGetdents64(int fd, struct dirent *de_user, unsigned int count);
|
||||
extern int do_opendir(const char *path, int oflags);
|
||||
extern char *SysRealpath(const char *path, char *resolvedPath);
|
||||
extern int SysUmask(int mask);
|
||||
extern int SysShellExec(const char *msgName, const char *cmdString);
|
||||
#endif
|
||||
#endif /* _LOS_SYSCALL_H */
|
||||
118
syscall/misc_syscall.c
Executable file
118
syscall/misc_syscall.c
Executable file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "errno.h"
|
||||
#include "los_process_pri.h"
|
||||
#ifdef LOSCFG_SHELL
|
||||
#include "shcmd.h"
|
||||
#include "shmsg.h"
|
||||
#endif
|
||||
#include "sys/utsname.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_strncpy_from_user.h"
|
||||
#include "capability_type.h"
|
||||
#include "capability_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int SysUname(struct utsname *name)
|
||||
{
|
||||
int ret;
|
||||
struct utsname tmpName;
|
||||
ret = LOS_ArchCopyFromUser(&tmpName, name, sizeof(struct utsname));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
ret = uname(&tmpName);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = LOS_ArchCopyToUser(name, &tmpName, sizeof(struct utsname));
|
||||
if (ret != 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SHELL
|
||||
int SysShellExec(const char *msgName, const char *cmdString)
|
||||
{
|
||||
int ret;
|
||||
unsigned int uintRet;
|
||||
errno_t err;
|
||||
CmdParsed cmdParsed;
|
||||
char msgNameDup[CMD_KEY_LEN + 1] = { 0 };
|
||||
char cmdStringDup[CMD_MAX_LEN + 1] = { 0 };
|
||||
|
||||
if (!IsCapPermit(CAP_SHELL_EXEC)) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
ret = LOS_StrncpyFromUser(msgNameDup, msgName, CMD_KEY_LEN + 1);
|
||||
if (ret < 0) {
|
||||
return -EFAULT;
|
||||
} else if (ret > CMD_KEY_LEN) {
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
|
||||
ret = LOS_StrncpyFromUser(cmdStringDup, cmdString, CMD_MAX_LEN + 1);
|
||||
if (ret < 0) {
|
||||
return -EFAULT;
|
||||
} else if (ret > CMD_MAX_LEN) {
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
|
||||
err = memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));
|
||||
if (err != EOK) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
uintRet = ShellMsgTypeGet(&cmdParsed, msgNameDup);
|
||||
if (uintRet != LOS_OK) {
|
||||
PRINTK("%s:command not found\n", msgNameDup);
|
||||
return -EFAULT;
|
||||
} else {
|
||||
(void)OsCmdExec(&cmdParsed, (char *)cmdStringDup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
632
syscall/net_syscall.c
Executable file
632
syscall/net_syscall.c
Executable file
@@ -0,0 +1,632 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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_syscall.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include <stdlib.h>
|
||||
#include "los_vm_map.h"
|
||||
#include "user_copy.h"
|
||||
#include "fs_file.h"
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
|
||||
#define SOCKET_U2K(s) do { s = GetAssociatedSystemFd(s); } while (0)
|
||||
#define SOCKET_K2U(s) \
|
||||
do { \
|
||||
int fd = AllocAndAssocProcessFd(s, MIN_START_FD); \
|
||||
if (fd == -1) { \
|
||||
closesocket(s); \
|
||||
set_errno(EMFILE); \
|
||||
s = -EMFILE; \
|
||||
} else { \
|
||||
s = fd; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_ASPACE(ptr, len, ...) \
|
||||
do { \
|
||||
if (ptr != NULL && len != 0) { \
|
||||
if (!LOS_IsUserAddressRange((VADDR_T)ptr, len)) { \
|
||||
set_errno(EFAULT); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
if (CheckRegion(OsCurrProcessGet()->vmSpace, (VADDR_T)ptr, len) == -1) { \
|
||||
set_errno(EFAULT); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int CheckRegion(const LosVmSpace *space, VADDR_T ptr, size_t len)
|
||||
{
|
||||
LosVmMapRegion *region = LOS_RegionFind((LosVmSpace *)space, ptr);
|
||||
if (region == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (ptr + len <= region->range.base + region->range.size) {
|
||||
return 0;
|
||||
}
|
||||
return CheckRegion(space, region->range.base + region->range.size,
|
||||
(ptr + len) - (region->range.base + region->range.size));
|
||||
}
|
||||
|
||||
static void *DupUserMem(const void *ptr, size_t len, int needCopy)
|
||||
{
|
||||
void *p = malloc(len);
|
||||
if (p == NULL) {
|
||||
set_errno(ENOMEM);
|
||||
return NULL;
|
||||
}
|
||||
if (needCopy && LOS_ArchCopyFromUser(p, ptr, len) != 0) {
|
||||
free(p);
|
||||
set_errno(EFAULT);
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#define LEN(ptr) ((ptr) ? *(ptr) : 0)
|
||||
|
||||
#define DUP_FROM_USER_(ptr, size, copy, ...) \
|
||||
__typeof(ptr) ptr##bak = ptr; \
|
||||
if (ptr != NULL && (size) != 0) { \
|
||||
ptr = DupUserMem(ptr, size, copy); \
|
||||
if (ptr == NULL) { \
|
||||
ptr = ptr##bak; \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DUP_FROM_USER(ptr, size, ...) \
|
||||
DUP_FROM_USER_(ptr, size, 1, ##__VA_ARGS__)
|
||||
|
||||
#define DUP_FROM_USER_NOCOPY(ptr, size, ...) \
|
||||
DUP_FROM_USER_(ptr, size, 0, ##__VA_ARGS__)
|
||||
|
||||
#define DUP_TO_USER(ptr, size, ...) \
|
||||
if (ptr != NULL && (size) != 0) { \
|
||||
if (LOS_ArchCopyToUser(ptr##bak, ptr, size) != 0) { \
|
||||
set_errno(EFAULT); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FREE_DUP(ptr) \
|
||||
if (ptr != ptr##bak) { \
|
||||
free((void*)ptr); \
|
||||
ptr = ptr##bak; \
|
||||
}
|
||||
|
||||
#define CPY_FROM_USER(ptr) \
|
||||
__typeof(*ptr) ptr##cpy = {0}, *ptr##bak = ptr; \
|
||||
if (ptr != NULL) { \
|
||||
if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr, sizeof(*ptr)) != 0) { \
|
||||
set_errno(EFAULT); \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
ptr = &ptr##cpy; \
|
||||
}
|
||||
|
||||
#define CPY_TO_USER(ptr, ...) \
|
||||
if (ptr != NULL) { \
|
||||
if (LOS_ArchCopyToUser(ptr##bak, ptr, sizeof(*ptr)) != 0) { \
|
||||
set_errno(EFAULT); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/** Macros for sendmsg and recvmsg */
|
||||
|
||||
#define CONST_CAST(ptr) ((__typeof(ptr##_NONCONST))ptr)
|
||||
|
||||
#define CHECK_FIELD_ASPACE(ptr, field, len) \
|
||||
do { \
|
||||
if (ptr != NULL) { \
|
||||
CHECK_ASPACE(ptr->field, len); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_ARRAY_FIELD_ASPACE(ptr, arr, arrlen, field, len, ...) \
|
||||
do { \
|
||||
if (ptr != NULL && ptr->arr != NULL) { \
|
||||
for (size_t i = 0; i < arrlen; i++) { \
|
||||
CHECK_ASPACE(ptr->arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define DUP_FIELD_FROM_USER_(ptr, field, size, copy, ...) \
|
||||
if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
|
||||
CONST_CAST(ptr)->field = DupUserMem(ptr->field, size, copy); \
|
||||
if (ptr->field == NULL) { \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DUP_FIELD_FROM_USER(ptr, field, size, ...) \
|
||||
DUP_FIELD_FROM_USER_(ptr, field, size, 1, ##__VA_ARGS__)
|
||||
|
||||
#define DUP_FIELD_FROM_USER_NOCOPY(ptr, field, size, ...) \
|
||||
DUP_FIELD_FROM_USER_(ptr, field, size, 0, ##__VA_ARGS__)
|
||||
|
||||
#define DUP_ARRAY_FIELD_FROM_USER_(ext, ptr, arr, arrlen, field, len, ...) \
|
||||
/* backup the arr to ptr##arr */ \
|
||||
__typeof(*ptr##_NONCONST) ptr##arr##cpy = ptr##cpybak, ptr##arr##cpybak = ptr##cpybak; \
|
||||
__typeof(ptr##_NONCONST) ptr##arr = ptr ? &ptr##arr##cpy : NULL, ptr##arr##_NONCONST = NULL; \
|
||||
DUP_FIELD_FROM_USER(ptr##arr, arr, arrlen * sizeof(ptr->arr[0]), ##__VA_ARGS__); \
|
||||
if (ptr != NULL && ptr->arr != NULL) { \
|
||||
size_t i = 0; \
|
||||
for (; i < arrlen; i++) { \
|
||||
DUP_FIELD_FROM_USER##ext(ptr, arr[i].field, ptr->arr[i].len, break); \
|
||||
} \
|
||||
if (i != arrlen) { \
|
||||
FREE_DUP_ARRAY_FIELD(ptr, arr, i, field); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DUP_ARRAY_FIELD_FROM_USER(ptr, arr, arrlen, field, len, ...) \
|
||||
DUP_ARRAY_FIELD_FROM_USER_(, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
|
||||
|
||||
#define DUP_ARRAY_FIELD_FROM_USER_NOCOPY(ptr, arr, arrlen, field, len, ...) \
|
||||
DUP_ARRAY_FIELD_FROM_USER_(_NOCOPY, ptr, arr, arrlen, field, len, ##__VA_ARGS__)
|
||||
|
||||
#define FREE_DUP_FIELD(ptr, field) \
|
||||
if (ptr != NULL && ptr->field != ptr##cpybak.field) { \
|
||||
free((void*)ptr->field); \
|
||||
CONST_CAST(ptr)->field = ptr##cpybak.field; \
|
||||
}
|
||||
|
||||
#define FREE_DUP_ARRAY_FIELD(ptr, arr, arrlen, field) \
|
||||
/* use and free the backuped arr in ptr##arr */ \
|
||||
if (ptr != NULL && ptr->arr != NULL && arrlen != 0) { \
|
||||
__typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
|
||||
ptr##cpybak.arr = ptr##arr->arr; \
|
||||
for (size_t j = 0; j < arrlen; j++) { \
|
||||
FREE_DUP_FIELD(ptr, arr[j].field); \
|
||||
} \
|
||||
ptr##cpybak.arr = tmp; \
|
||||
} \
|
||||
FREE_DUP_FIELD(ptr##arr, arr);
|
||||
|
||||
#define CPY_FROM_CONST_USER(NonConstType, ptr) \
|
||||
CPY_FROM_USER(ptr); \
|
||||
NonConstType *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy; \
|
||||
(void)ptr##bak;
|
||||
|
||||
#define CPY_FROM_NONCONST_USER(ptr) \
|
||||
CPY_FROM_USER(ptr); \
|
||||
__typeof(*ptr) *ptr##_NONCONST = NULL, ptr##cpybak = ptr##cpy;
|
||||
|
||||
#define DUP_FIELD_TO_USER(ptr, field, size, ...) \
|
||||
if (ptr != NULL && ptr->field != NULL && (size) != 0) { \
|
||||
if (LOS_ArchCopyToUser(ptr##cpybak.field, ptr->field, size) != 0 || \
|
||||
LOS_ArchCopyToUser(&ptr##bak->field, &ptr##cpybak.field, sizeof(ptr##cpybak.field)) != 0) { \
|
||||
set_errno(EFAULT); \
|
||||
__VA_ARGS__; \
|
||||
return -get_errno(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DUP_ARRAY_FIELD_TO_USER(ptr, arr, arrlen, field, len, ...) \
|
||||
/* use the backuped arr from ptr##arr */ \
|
||||
if (ptr != NULL && ptr->arr != NULL) { \
|
||||
__typeof(ptr##cpybak.arr) tmp = ptr##cpybak.arr; \
|
||||
__typeof(ptr##bak) tmp2 = ptr##bak; \
|
||||
ptr##cpybak.arr = ptr##arr->arr; \
|
||||
ptr##arr->arr = tmp; \
|
||||
ptr##bak = ptr##arr; \
|
||||
for (size_t i = 0; i < arrlen; i++) { \
|
||||
DUP_FIELD_TO_USER(ptr, arr[i].field, ptr->arr[i].len, ##__VA_ARGS__); \
|
||||
} \
|
||||
ptr##bak = tmp2; \
|
||||
ptr##arr->arr = ptr##cpybak.arr; \
|
||||
ptr##cpybak.arr = tmp; \
|
||||
}
|
||||
|
||||
int SysSocket(int domain, int type, int protocol)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = socket(domain, type, protocol);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
SOCKET_K2U(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysBind(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
CHECK_ASPACE(name, namelen);
|
||||
|
||||
DUP_FROM_USER(name, namelen);
|
||||
ret = bind(s, name, namelen);
|
||||
FREE_DUP(name);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysConnect(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
CHECK_ASPACE(name, namelen);
|
||||
|
||||
DUP_FROM_USER(name, namelen);
|
||||
ret = connect(s, name, namelen);
|
||||
FREE_DUP(name);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysListen(int sockfd, int backlog)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(sockfd);
|
||||
ret = listen(sockfd, backlog);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysAccept(int socket, struct sockaddr *address,
|
||||
socklen_t *addressLen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(socket);
|
||||
|
||||
CHECK_ASPACE(addressLen, sizeof(socklen_t));
|
||||
CPY_FROM_USER(addressLen);
|
||||
|
||||
CHECK_ASPACE(address, LEN(addressLen));
|
||||
DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
|
||||
|
||||
ret = accept(socket, address, addressLen);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(address);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CPY_TO_USER(addressLen, close(ret); FREE_DUP(address));
|
||||
DUP_TO_USER(address, LEN(addressLen), close(ret); FREE_DUP(address));
|
||||
FREE_DUP(address);
|
||||
|
||||
SOCKET_K2U(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysGetSockName (int s, struct sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
|
||||
CHECK_ASPACE(namelen, sizeof(socklen_t));
|
||||
CPY_FROM_USER(namelen);
|
||||
|
||||
CHECK_ASPACE(name, LEN(namelen));
|
||||
DUP_FROM_USER_NOCOPY(name, LEN(namelen));
|
||||
|
||||
ret = getsockname(s, name, namelen);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(name);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CPY_TO_USER(namelen, FREE_DUP(name));
|
||||
DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
|
||||
FREE_DUP(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysGetPeerName (int s, struct sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
|
||||
CHECK_ASPACE(namelen, sizeof(socklen_t));
|
||||
CPY_FROM_USER(namelen);
|
||||
|
||||
CHECK_ASPACE(name, LEN(namelen));
|
||||
DUP_FROM_USER_NOCOPY(name, LEN(namelen));
|
||||
|
||||
ret = getpeername(s, name, namelen);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(name);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CPY_TO_USER(namelen, FREE_DUP(name));
|
||||
DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
|
||||
FREE_DUP(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysSend(int s, const void *dataptr, size_t size, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
CHECK_ASPACE(dataptr, size);
|
||||
|
||||
DUP_FROM_USER(dataptr, size);
|
||||
ret = send(s, dataptr, size, flags);
|
||||
FREE_DUP(dataptr);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysSendTo(int s, const void *dataptr, size_t size, int flags,
|
||||
const struct sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
CHECK_ASPACE(dataptr, size);
|
||||
CHECK_ASPACE(to, tolen);
|
||||
|
||||
DUP_FROM_USER(dataptr, size);
|
||||
DUP_FROM_USER(to, tolen, FREE_DUP(dataptr););
|
||||
ret = sendto(s, dataptr, size, flags, to, tolen);
|
||||
FREE_DUP(dataptr);
|
||||
FREE_DUP(to);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysRecv(int socket, void *buffer, size_t length, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(socket);
|
||||
CHECK_ASPACE(buffer, length);
|
||||
|
||||
DUP_FROM_USER_NOCOPY(buffer, length);
|
||||
ret = recv(socket, buffer, length, flags);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(buffer);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
DUP_TO_USER(buffer, ret, FREE_DUP(buffer));
|
||||
FREE_DUP(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysRecvFrom(int socket, void *buffer, size_t length,
|
||||
int flags, struct sockaddr *address,
|
||||
socklen_t *addressLen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(socket);
|
||||
CHECK_ASPACE(buffer, length);
|
||||
|
||||
CHECK_ASPACE(addressLen, sizeof(socklen_t));
|
||||
CPY_FROM_USER(addressLen);
|
||||
|
||||
CHECK_ASPACE(address, LEN(addressLen));
|
||||
DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
|
||||
|
||||
DUP_FROM_USER_NOCOPY(buffer, length, FREE_DUP(address));
|
||||
ret = recvfrom(socket, buffer, length, flags, address, addressLen);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(address);
|
||||
FREE_DUP(buffer);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CPY_TO_USER(addressLen, FREE_DUP(address); FREE_DUP(buffer));
|
||||
DUP_TO_USER(address, LEN(addressLen), FREE_DUP(address); FREE_DUP(buffer));
|
||||
DUP_TO_USER(buffer, ret, FREE_DUP(address); FREE_DUP(buffer));
|
||||
FREE_DUP(address);
|
||||
FREE_DUP(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysShutdown(int socket, int how)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(socket);
|
||||
ret = shutdown(socket, how);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysSetSockOpt(int socket, int level, int optName,
|
||||
const void *optValue, socklen_t optLen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(socket);
|
||||
CHECK_ASPACE(optValue, optLen);
|
||||
|
||||
DUP_FROM_USER(optValue, optLen);
|
||||
ret = setsockopt(socket, level, optName, optValue, optLen);
|
||||
FREE_DUP(optValue);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysGetSockOpt(int sockfd, int level, int optName,
|
||||
void *optValue, socklen_t *optLen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(sockfd);
|
||||
|
||||
CHECK_ASPACE(optLen, sizeof(socklen_t));
|
||||
CPY_FROM_USER(optLen);
|
||||
|
||||
CHECK_ASPACE(optValue, LEN(optLen));
|
||||
DUP_FROM_USER_NOCOPY(optValue, LEN(optLen));
|
||||
|
||||
ret = getsockopt(sockfd, level, optName, optValue, optLen);
|
||||
if (ret == -1) {
|
||||
FREE_DUP(optValue);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CPY_TO_USER(optLen, FREE_DUP(optValue));
|
||||
DUP_TO_USER(optValue, LEN(optLen), FREE_DUP(optValue));
|
||||
FREE_DUP(optValue);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysSendMsg(int s, const struct msghdr *message, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
|
||||
CHECK_ASPACE(message, sizeof(struct msghdr));
|
||||
CPY_FROM_CONST_USER(struct msghdr, message);
|
||||
|
||||
if (message && message->msg_iovlen > IOV_MAX) {
|
||||
set_errno(EMSGSIZE);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
|
||||
CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
|
||||
CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
|
||||
|
||||
DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
|
||||
CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
|
||||
FREE_DUP_FIELD(message, msg_iov));
|
||||
DUP_FIELD_FROM_USER(message, msg_name, message->msg_namelen,
|
||||
FREE_DUP_FIELD(message, msg_iov));
|
||||
DUP_FIELD_FROM_USER(message, msg_control, message->msg_controllen,
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name));
|
||||
DUP_ARRAY_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
|
||||
FREE_DUP_FIELD(message, msg_control);
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name));
|
||||
ret = sendmsg(s, message, flags);
|
||||
FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
|
||||
FREE_DUP_FIELD(message, msg_control);
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name);
|
||||
if (ret == -1) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t SysRecvMsg(int s, struct msghdr *message, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
SOCKET_U2K(s);
|
||||
|
||||
CHECK_ASPACE(message, sizeof(struct msghdr));
|
||||
CPY_FROM_NONCONST_USER(message);
|
||||
|
||||
if (message && message->msg_iovlen > IOV_MAX) {
|
||||
set_errno(EMSGSIZE);
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
|
||||
CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
|
||||
CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
|
||||
|
||||
DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec));
|
||||
CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
|
||||
FREE_DUP_FIELD(message, msg_iov));
|
||||
DUP_FIELD_FROM_USER_NOCOPY(message, msg_name, message->msg_namelen,
|
||||
FREE_DUP_FIELD(message, msg_iov));
|
||||
DUP_FIELD_FROM_USER_NOCOPY(message, msg_control, message->msg_controllen,
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name));
|
||||
DUP_ARRAY_FIELD_FROM_USER_NOCOPY(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
|
||||
FREE_DUP_FIELD(message, msg_control);
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name));
|
||||
ret = recvmsg(s, message, flags);
|
||||
if (ret == -1) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
CPY_TO_USER(message, ret = -1; goto OUT);
|
||||
DUP_FIELD_TO_USER(message, msg_control, message->msg_controllen, ret = -1; goto OUT);
|
||||
DUP_FIELD_TO_USER(message, msg_iov, message->msg_iovlen * sizeof(struct iovec), ret = -1; goto OUT);
|
||||
DUP_FIELD_TO_USER(message, msg_name, message->msg_namelen, ret = -1; goto OUT);
|
||||
DUP_ARRAY_FIELD_TO_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len, ret = -1; goto OUT);
|
||||
OUT:
|
||||
FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
|
||||
FREE_DUP_FIELD(message, msg_control);
|
||||
FREE_DUP_FIELD(message, msg_iov);
|
||||
FREE_DUP_FIELD(message, msg_name);
|
||||
return (ret == -1) ? -get_errno() : ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
1003
syscall/process_syscall.c
Executable file
1003
syscall/process_syscall.c
Executable file
File diff suppressed because it is too large
Load Diff
239
syscall/syscall_lookup.h
Executable file
239
syscall/syscall_lookup.h
Executable file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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_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_chdir, SysChdir, int, ARG_NUM_1)
|
||||
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_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)
|
||||
SYSCALL_HAND_DEF(__NR_pipe, SysPipe, int, ARG_NUM_1)
|
||||
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(82, SysSelect, int, ARG_NUM_5)
|
||||
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_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_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_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_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_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_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
|
||||
SYSCALL_HAND_DEF(__NR_mkfifo, SysMkFifo, int, ARG_NUM_2)
|
||||
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
|
||||
|
||||
SYSCALL_HAND_DEF(30, SysUtime, int, ARG_NUM_2)
|
||||
#endif
|
||||
|
||||
SYSCALL_HAND_DEF(__NR_exit, SysThreadExit, void, ARG_NUM_1)
|
||||
SYSCALL_HAND_DEF(__NR_fork, SysFork, int, ARG_NUM_0)
|
||||
SYSCALL_HAND_DEF(13, SysTime, time_t, ARG_NUM_1)
|
||||
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_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_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_4)
|
||||
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_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_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_1)
|
||||
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(254, SysSetThreadArea, int, ARG_NUM_1)
|
||||
SYSCALL_HAND_DEF(255, 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_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
|
||||
|
||||
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)
|
||||
|
||||
SYSCALL_HAND_DEF(__NR_statx, SysStatx, int, ARG_NUM_5)
|
||||
SYSCALL_HAND_DEF(403, SysClockGettime64, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(404, SysClockSettime64, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(406, SysClockGetres64, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(407, SysClockNanoSleep64, int, ARG_NUM_4)
|
||||
SYSCALL_HAND_DEF(408, SysTimerGettime64, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(409, SysTimerSettime64, int, ARG_NUM_4)
|
||||
|
||||
/* LiteOS customized syscalls, not compatible with ARM EABI */
|
||||
SYSCALL_HAND_DEF(__NR_pthread_set_detach, SysUserThreadSetDeatch, 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, SysCreateUserThread, unsigned int, ARG_NUM_3)
|
||||
586
syscall/time_syscall.c
Executable file
586
syscall/time_syscall.c
Executable file
@@ -0,0 +1,586 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "errno.h"
|
||||
#include "unistd.h"
|
||||
#include "limits.h"
|
||||
#include "utime.h"
|
||||
#include "time.h"
|
||||
#include "user_copy.h"
|
||||
#include "sys/times.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_strncpy_from_user.h"
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
int SysUtime(const char *path, const struct utimbuf *ptimes)
|
||||
{
|
||||
int ret;
|
||||
char *spath = NULL;
|
||||
struct utimbuf sptimes;
|
||||
|
||||
if (path == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
spath = LOS_MemAlloc(m_aucSysMem0, PATH_MAX + 1);
|
||||
if (spath == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = LOS_StrncpyFromUser(spath, path, PATH_MAX + 1);
|
||||
if (ret == -EFAULT) {
|
||||
LOS_MemFree(m_aucSysMem0, spath);
|
||||
return ret;
|
||||
} else if (ret > PATH_MAX) {
|
||||
LOS_MemFree(m_aucSysMem0, spath);
|
||||
PRINT_ERR("%s[%d], path exceeds maxlen: %d\n", __FUNCTION__, __LINE__, PATH_MAX);
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
spath[ret] = '\0';
|
||||
|
||||
if (ptimes && LOS_ArchCopyFromUser(&sptimes, ptimes, sizeof(struct utimbuf))) {
|
||||
LOS_MemFree(m_aucSysMem0, spath);
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = utime(spath, ptimes ? &sptimes : NULL);
|
||||
if (ret < 0) {
|
||||
ret = -get_errno();
|
||||
}
|
||||
|
||||
LOS_MemFree(m_aucSysMem0, spath);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
time_t SysTime(time_t *tloc)
|
||||
{
|
||||
int ret;
|
||||
time_t stloc;
|
||||
|
||||
ret = time(tloc ? &stloc : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (tloc && LOS_ArchCopyToUser(tloc, &stloc, sizeof(time_t))) {
|
||||
errno = EFAULT;
|
||||
ret = -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysSetiTimer(int which, const struct itimerval *value, struct itimerval *ovalue)
|
||||
{
|
||||
int ret;
|
||||
struct itimerval svalue;
|
||||
struct itimerval sovalue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerval))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = setitimer(which, &svalue, &sovalue);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (ovalue && LOS_ArchCopyToUser(ovalue, &sovalue, sizeof(struct itimerval))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysGetiTimer(int which, struct itimerval *value)
|
||||
{
|
||||
int ret;
|
||||
struct itimerval svalue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = getitimer(which, &svalue);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerval))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerCreate(clockid_t clockID, struct sigevent *evp, timer_t *timerID)
|
||||
{
|
||||
int ret;
|
||||
timer_t stimerID;
|
||||
struct sigevent sevp;
|
||||
|
||||
if (timerID == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (evp && LOS_ArchCopyFromUser(&sevp, evp, sizeof(struct sigevent))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = timer_create(clockID, evp ? &sevp : NULL, &stimerID);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyToUser(timerID, &stimerID, sizeof(timer_t))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerGettime(timer_t timerID, struct itimerspec *value)
|
||||
{
|
||||
int ret;
|
||||
struct itimerspec svalue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = timer_gettime(timerID, &svalue);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerSettime(timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
|
||||
{
|
||||
int ret;
|
||||
struct itimerspec svalue;
|
||||
struct itimerspec soldValue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = timer_settime(timerID, flags, &svalue, &soldValue);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (oldValue && LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerGetoverrun(timer_t timerID)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = timer_getoverrun(timerID);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerDelete(timer_t timerID)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = timer_delete(timerID);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockSettime(clockid_t clockID, const struct timespec *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = clock_settime(clockID, &stp);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockGettime(clockid_t clockID, struct timespec *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = clock_gettime(clockID, &stp);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockGetres(clockid_t clockID, struct timespec *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = clock_getres(clockID, &stp);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockNanoSleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
|
||||
{
|
||||
int ret;
|
||||
struct timespec sreq;
|
||||
struct timespec srem;
|
||||
|
||||
if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = clock_nanosleep(clk, flags, &sreq, rem ? &srem : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (rem && LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysNanoSleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec srqtp;
|
||||
struct timespec srmtp;
|
||||
|
||||
if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = nanosleep(&srqtp, rmtp ? &srmtp : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (rmtp && LOS_ArchCopyToUser(rmtp, &srmtp, sizeof(struct timespec))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
clock_t SysTimes(struct tms *buf)
|
||||
{
|
||||
clock_t ret;
|
||||
struct tms sbuf;
|
||||
|
||||
ret = times(buf ? &sbuf : NULL);
|
||||
|
||||
if (buf && LOS_ArchCopyToUser(buf, &sbuf, sizeof(struct tms))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockSettime64(clockid_t clockID, const struct timespec64 *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec t;
|
||||
struct timespec64 stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (stp.tv_sec > UINT32_MAX) {
|
||||
errno = ENOSYS;
|
||||
return -ENOSYS;
|
||||
}
|
||||
t.tv_sec = stp.tv_sec;
|
||||
t.tv_nsec = stp.tv_nsec;
|
||||
|
||||
ret = clock_settime(clockID, &t);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockGettime64(clockid_t clockID, struct timespec64 *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec t;
|
||||
struct timespec64 stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = clock_gettime(clockID, &t);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
stp.tv_sec = t.tv_sec;
|
||||
stp.tv_nsec = t.tv_nsec;
|
||||
|
||||
if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockGetres64(clockid_t clockID, struct timespec64 *tp)
|
||||
{
|
||||
int ret;
|
||||
struct timespec t;
|
||||
struct timespec64 stp;
|
||||
|
||||
if (tp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = clock_getres(clockID, &t);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
stp.tv_sec = t.tv_sec;
|
||||
stp.tv_nsec = t.tv_nsec;
|
||||
|
||||
if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysClockNanoSleep64(clockid_t clk, int flags, const struct timespec64 *req, struct timespec64 *rem)
|
||||
{
|
||||
int ret;
|
||||
struct timespec rq;
|
||||
struct timespec rm;
|
||||
struct timespec64 sreq;
|
||||
struct timespec64 srem;
|
||||
|
||||
if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (req != NULL) {
|
||||
rq.tv_sec = (sreq.tv_sec > UINT32_MAX) ? UINT32_MAX : sreq.tv_sec;
|
||||
rq.tv_nsec = sreq.tv_nsec;
|
||||
}
|
||||
|
||||
ret = clock_nanosleep(clk, flags, &rq, rem ? &rm : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (rem != NULL) {
|
||||
srem.tv_sec = rm.tv_sec;
|
||||
srem.tv_nsec = rm.tv_nsec;
|
||||
if (LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerGettime64(timer_t timerID, struct itimerspec64 *value)
|
||||
{
|
||||
int ret;
|
||||
struct itimerspec val;
|
||||
struct itimerspec64 svalue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = timer_gettime(timerID, &val);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
svalue.it_interval.tv_sec = val.it_interval.tv_sec;
|
||||
svalue.it_interval.tv_nsec = val.it_interval.tv_nsec;
|
||||
svalue.it_value.tv_sec = val.it_value.tv_sec;
|
||||
svalue.it_value.tv_nsec = val.it_value.tv_nsec;
|
||||
|
||||
if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysTimerSettime64(timer_t timerID, int flags, const struct itimerspec64 *value, struct itimerspec64 *oldValue)
|
||||
{
|
||||
int ret;
|
||||
struct itimerspec val;
|
||||
struct itimerspec oldVal;
|
||||
struct itimerspec64 svalue;
|
||||
struct itimerspec64 soldValue;
|
||||
|
||||
if (value == NULL) {
|
||||
errno = EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (svalue.it_interval.tv_sec > UINT32_MAX || svalue.it_value.tv_sec > UINT32_MAX) {
|
||||
errno = ENOSYS;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
val.it_interval.tv_sec = svalue.it_interval.tv_sec;
|
||||
val.it_interval.tv_nsec = svalue.it_interval.tv_nsec;
|
||||
val.it_value.tv_sec = svalue.it_value.tv_sec;
|
||||
val.it_value.tv_nsec = svalue.it_value.tv_nsec;
|
||||
|
||||
ret = timer_settime(timerID, flags, &val, oldValue ? &oldVal : NULL);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
if (oldValue != NULL) {
|
||||
soldValue.it_interval.tv_sec = oldVal.it_interval.tv_sec;
|
||||
soldValue.it_interval.tv_nsec = oldVal.it_interval.tv_nsec;
|
||||
soldValue.it_value.tv_sec = oldVal.it_value.tv_sec;
|
||||
soldValue.it_value.tv_nsec = oldVal.it_value.tv_nsec;
|
||||
|
||||
if (LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec64))) {
|
||||
errno = EFAULT;
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
125
syscall/vm_syscall.c
Executable file
125
syscall/vm_syscall.c
Executable file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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 "sys/types.h"
|
||||
#include "sys/shm.h"
|
||||
#include "errno.h"
|
||||
#include "unistd.h"
|
||||
#include "los_vm_syscall.h"
|
||||
#include "fs_file.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void *SysMmap(void *addr, size_t size, int prot, int flags, int fd, size_t offset)
|
||||
{
|
||||
/* Process fd convert to system global fd */
|
||||
fd = GetAssociatedSystemFd(fd);
|
||||
|
||||
return (void *)LOS_MMap((uintptr_t)addr, size, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
int SysMunmap(void *addr, size_t size)
|
||||
{
|
||||
return LOS_UnMMap((uintptr_t)addr, size);
|
||||
}
|
||||
|
||||
void *SysMremap(void *oldAddr, size_t oldLen, size_t newLen, int flags, void *newAddr)
|
||||
{
|
||||
return (void *)LOS_DoMremap((vaddr_t)oldAddr, oldLen, newLen, flags, (vaddr_t)newAddr);
|
||||
}
|
||||
|
||||
int SysMprotect(void *vaddr, size_t len, int prot)
|
||||
{
|
||||
return LOS_DoMprotect((uintptr_t)vaddr, len, (unsigned long)prot);
|
||||
}
|
||||
|
||||
void *SysBrk(void *addr)
|
||||
{
|
||||
return LOS_DoBrk(addr);
|
||||
}
|
||||
|
||||
int SysShmGet(key_t key, size_t size, int shmflg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ShmGet(key, size, shmflg);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *SysShmAt(int shmid, const void *shmaddr, int shmflg)
|
||||
{
|
||||
void *ret = NULL;
|
||||
|
||||
ret = ShmAt(shmid, shmaddr, shmflg);
|
||||
if (ret == (void *)-1) {
|
||||
return (void *)(intptr_t)-get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysShmCtl(int shmid, int cmd, struct shmid_ds *buf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ShmCtl(shmid, cmd, buf);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysShmDt(const void *shmaddr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ShmDt(shmaddr);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
Reference in New Issue
Block a user