From 9549f5ebd075314a9c089cfaf1829cc2ab1abe89 Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Wed, 18 Aug 2021 00:24:50 +0800 Subject: [PATCH] chore(musl): reduce the modifications of musl Signed-off-by: Caoruihong Change-Id: I32b820bc0eb7465bf54d506e7f5e759ef64101e2 --- Makefile | 3 - compat/posix/BUILD.gn | 4 + compat/posix/src/errno.c | 51 ++++++++++++ compat/posix/src/malloc.c | 145 +++++++++++++++++++++++++++++++++++ compat/posix/src/sched.c | 5 ++ compat/posix/src/stdio.c | 121 +++++++++++++++++++++++++++++ compat/posix/src/stdlib.c | 71 +++++++++++++++++ compat/posix/src/time.c | 16 ++++ fs/fat/Makefile | 1 - fs/nfs/Makefile | 1 - fs/ramfs/Makefile | 1 - lib/libc/BUILD.gn | 19 ++++- lib/libc/Makefile | 1 + syscall/fs_syscall.c | 85 +++----------------- tools/build/mk/los_config.mk | 3 +- 15 files changed, 442 insertions(+), 85 deletions(-) create mode 100644 compat/posix/src/errno.c create mode 100644 compat/posix/src/malloc.c create mode 100644 compat/posix/src/stdio.c create mode 100644 compat/posix/src/stdlib.c diff --git a/Makefile b/Makefile index 980d0713..20d0bad7 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,6 @@ FSTYPE = jffs2 endif ROOTFS_DIR = $(OUT)/rootfs ROOTFS_ZIP = $(OUT)/rootfs.zip -VERSION = define HELP = ------------------------------------------------------- @@ -117,8 +116,6 @@ Targets: $(LITEOS_LIBS_TARGET): compile all kernel modules (libraries) $(LITEOS_TARGET): make liteos kernel image update_config: update product kernel config (use menuconfig) - test: make the testsuits_app and put it into the rootfs dir - test_apps: make a rootfs img with the testsuits_app in it Parameters: FSTYPE: value should be one of (jffs2 vfat yaffs2) diff --git a/compat/posix/BUILD.gn b/compat/posix/BUILD.gn index d145e64f..31210665 100644 --- a/compat/posix/BUILD.gn +++ b/compat/posix/BUILD.gn @@ -33,6 +33,8 @@ module_switch = defined(LOSCFG_COMPAT_POSIX) module_name = get_path_info(rebase_path("."), "name") kernel_module(module_name) { sources = [ + "src/errno.c", + "src/malloc.c", "src/map_error.c", "src/misc.c", "src/mqueue.c", @@ -44,6 +46,8 @@ kernel_module(module_name) { "src/sched.c", "src/semaphore.c", "src/socket.c", + "src/stdio.c", + "src/stdlib.c", "src/time.c", ] diff --git a/compat/posix/src/errno.c b/compat/posix/src/errno.c new file mode 100644 index 00000000..ca487216 --- /dev/null +++ b/compat/posix/src/errno.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 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_errno.h" +#include "los_task_pri.h" + +/* the specific errno get or set in interrupt service routine */ +static int errno_isr; + +int *__errno_location(void) +{ + LosTaskCB *runTask = NULL; + + if (OS_INT_INACTIVE) { + runTask = OsCurrTaskGet(); + return &runTask->errorNo; + } else { + return &errno_isr; + } +} + +int *__errno(void) __attribute__((__weak__, __alias__("__errno_location"))); diff --git a/compat/posix/src/malloc.c b/compat/posix/src/malloc.c new file mode 100644 index 00000000..20047a0a --- /dev/null +++ b/compat/posix/src/malloc.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 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 "stdlib.h" +#include "string.h" +#include "los_vm_map.h" + +/* + * Allocates the requested memory and returns a pointer to it. The requested + * size is nitems each size bytes long (total memory requested is nitems*size). + * The space is initialized to all zero bits. + */ + +void *calloc(size_t nitems, size_t size) +{ /*lint !e578*/ + size_t real_size; + void *ptr = NULL; + + if (nitems == 0 || size == 0) { + return NULL; + } + + real_size = (size_t)(nitems * size); + ptr = LOS_KernelMalloc((UINT32) real_size); + if (ptr != NULL) { + (void) memset_s((void *) ptr, real_size, 0, real_size); + } + return ptr; +} + +/* + * Deallocates the memory previously allocated by a call to calloc, malloc, or + * realloc. The argument ptr points to the space that was previously allocated. + * If ptr points to a memory block that was not allocated with calloc, malloc, + * or realloc, or is a space that has been deallocated, then the result is undefined. + */ + +void free(void *ptr) +{ + if (ptr == NULL) { + return; + } + + LOS_KernelFree(ptr); +} + +/* + * Allocates the requested memory and returns a pointer to it. The requested + * size is size bytes. The value of the space is indeterminate. + */ + +void *malloc(size_t size) +{ /*lint !e31 !e10*/ + if (size == 0) { + return NULL; + } + + return LOS_KernelMalloc((UINT32) size); +} + +void *zalloc(size_t size) +{ /*lint !e10*/ + void *ptr = NULL; + + if (size == 0) { + return NULL; + } + + ptr = LOS_KernelMalloc((UINT32) size); + if (ptr != NULL) { + (void) memset_s(ptr, size, 0, size); + } + return ptr; +} + +/* + * allocates a block of size bytes whose address is a multiple of boundary. + * The boundary must be a power of two! + */ + +void *memalign(size_t boundary, size_t size) +{ + if (size == 0) { + return NULL; + } + + return LOS_KernelMallocAlign((UINT32) size, (UINT32) boundary); +} + +/* + * Attempts to resize the memory block pointed to by ptr that was previously + * allocated with a call to malloc or calloc. The contents pointed to by ptr are + * unchanged. If the value of size is greater than the previous size of the + * block, then the additional bytes have an undeterminate value. If the value + * of size is less than the previous size of the block, then the difference of + * bytes at the end of the block are freed. If ptr is null, then it behaves like + * malloc. If ptr points to a memory block that was not allocated with calloc + * or malloc, or is a space that has been deallocated, then the result is + * undefined. If the new space cannot be allocated, then the contents pointed + * to by ptr are unchanged. If size is zero, then the memory block is completely + * freed. + */ + +void *realloc(void *ptr, size_t size) +{ + if (ptr == NULL) { + ptr = malloc(size); + return ptr; + } + + if (size == 0) { + free(ptr); + return NULL; + } + + return LOS_KernelRealloc(ptr, (UINT32) size); +} \ No newline at end of file diff --git a/compat/posix/src/sched.c b/compat/posix/src/sched.c index ece7752f..7ff7a5a5 100644 --- a/compat/posix/src/sched.c +++ b/compat/posix/src/sched.c @@ -138,3 +138,8 @@ int __sched_cpucount(size_t set_size, const cpu_set_t* set) return count; } +int sched_yield() +{ + (void)LOS_TaskYield(); + return 0; +} diff --git a/compat/posix/src/stdio.c b/compat/posix/src/stdio.c new file mode 100644 index 00000000..f2182d44 --- /dev/null +++ b/compat/posix/src/stdio.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 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 +#include +#include +#ifdef LOSCFG_FS_VFS +#include + +off_t _lseek(int fd, off_t offset, int whence) +{ + int ret; + struct file *filep = NULL; + + /* Get the file structure corresponding to the file descriptor. */ + ret = fs_getfilep(fd, &filep); + if (ret < 0) { + /* The errno value has already been set */ + return (off_t)-get_errno(); + } + + /* libc seekdir function should set the whence to SEEK_SET, so we can discard + * the whence argument here */ + if (filep->f_oflags & O_DIRECTORY) { + /* defensive coding */ + if (filep->f_dir == NULL) { + return (off_t)-EINVAL; + } + if (offset == 0) { + rewinddir(filep->f_dir); + } else { + seekdir(filep->f_dir, offset); + } + ret = telldir(filep->f_dir); + if (ret < 0) { + return (off_t)-get_errno(); + } + return ret; + } + + /* Then let file_seek do the real work */ + ret = file_seek(filep, offset, whence); + if (ret < 0) { + return -get_errno(); + } + return ret; +} + +off64_t _lseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence) +{ + off64_t ret; + struct file *filep = NULL; + off64_t offset = ((off64_t)offsetHigh << 32) + (uint)offsetLow; /* 32: offsetHigh is high 32 bits */ + + /* Get the file structure corresponding to the file descriptor. */ + ret = fs_getfilep(fd, &filep); + if (ret < 0) { + /* The errno value has already been set */ + return (off64_t)-get_errno(); + } + + /* libc seekdir function should set the whence to SEEK_SET, so we can discard + * the whence argument here */ + if (filep->f_oflags & O_DIRECTORY) { + /* defensive coding */ + if (filep->f_dir == NULL) { + return (off64_t)-EINVAL; + } + if (offsetLow == 0) { + rewinddir(filep->f_dir); + } else { + seekdir(filep->f_dir, offsetLow); + } + ret = telldir(filep->f_dir); + if (ret < 0) { + return (off64_t)-get_errno(); + } + goto out; + } + + /* Then let file_seek do the real work */ + ret = file_seek64(filep, offset, whence); + if (ret < 0) { + return (off64_t)-get_errno(); + } + +out: + *result = ret; + + return 0; +} + +#endif diff --git a/compat/posix/src/stdlib.c b/compat/posix/src/stdlib.c new file mode 100644 index 00000000..f4a90263 --- /dev/null +++ b/compat/posix/src/stdlib.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 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 +#include +#include +#include "los_printf.h" +#include "los_exc.h" + +char *getenv(const char *name) +{ + return NULL; +} + +void srand(unsigned s) +{ + return srandom(s); +} + +int rand(void) +{ + return random(); +} + +void _exit(int status) +{ + PRINT_ERR("%s NOT SUPPORT\n", __FUNCTION__); + errno = ENOSYS; + while (1); +} + +void exit(int status) +{ + PRINT_ERR("%s NOT SUPPORT\n", __FUNCTION__); + errno = ENOSYS; + while (1); +} + +void abort(void) +{ + LOS_Panic("System was being aborted\n"); + while (1); +} diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c index b71ee130..692d5d0a 100644 --- a/compat/posix/src/time.c +++ b/compat/posix/src/time.c @@ -1135,3 +1135,19 @@ VOID OsVdsoTimeGet(VdsoDataPage *vdsoDataPage) } #endif +time_t time(time_t *t) +{ + struct timeval tp; + int ret; + + /* Get the current time from the system */ + ret = gettimeofday(&tp, (struct timezone *)NULL); + if (ret == LOS_OK) { + /* Return the seconds since the epoch */ + if (t) { + *t = tp.tv_sec; + } + return tp.tv_sec; + } + return (time_t)OS_ERROR; +} diff --git a/fs/fat/Makefile b/fs/fat/Makefile index b4e3e624..72b987f3 100644 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -39,7 +39,6 @@ LOCAL_INCLUDE := \ -I $(LITEOSTOPDIR)/fs/fat/os_adapt \ -I $(LITEOSTOPDIR)/fs/fat/virpart/include \ -I $(LITEOSTOPDIR)/fs/vfs \ - -I $(LITEOSTHIRDPARTY)/NuttX/include LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile index 21c1369d..5b999391 100644 --- a/fs/nfs/Makefile +++ b/fs/nfs/Makefile @@ -32,7 +32,6 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/nfs/*.c) -LOCAL_INCLUDE := -I $(wildcard $(LITEOSTHIRDPARTY)/NuttX/include) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/ramfs/Makefile b/fs/ramfs/Makefile index 2c2ccbc4..4f8e3b9f 100644 --- a/fs/ramfs/Makefile +++ b/fs/ramfs/Makefile @@ -32,7 +32,6 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/tmpfs/*.c) -LOCAL_INCLUDE := -I $(wildcard $(LITEOSTHIRDPARTY)/NuttX/include) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/lib/libc/BUILD.gn b/lib/libc/BUILD.gn index 7d7d9dfc..b2978cba 100644 --- a/lib/libc/BUILD.gn +++ b/lib/libc/BUILD.gn @@ -60,6 +60,8 @@ kernel_module(module_name) { "$OPTRTDIR/string/arm/strcmp.S", "$OPTRTDIR/string/arm/strcpy.c", "$OPTRTDIR/string/arm/strlen-armv6t2.S", + ] + sources += [ "src/arch/arm/memset.S", "src/arch/arm/memcmp.S", ] @@ -70,12 +72,20 @@ kernel_module(module_name) { ] } + include_dirs = [ + "$MUSLPORTINGDIR/src/include", + "$MUSLPORTINGDIR/src/internal", + ] + public_configs = [ ":public" ] configs += [ ":private" ] } config("public") { - include_dirs = [ "$MUSLPORTINGDIR/include" ] + cflags = [ + "-isystem", + rebase_path("$MUSLPORTINGDIR/include"), + ] } config("private") { @@ -92,8 +102,9 @@ config("private") { ] } - include_dirs = [ - "$MUSLPORTINGDIR/src/include", - "$MUSLPORTINGDIR/src/internal", + cflags += [ + "-Wno-shift-op-parentheses", + "-Wno-logical-op-parentheses", + "-Wno-bitwise-op-parentheses", ] } diff --git a/lib/libc/Makefile b/lib/libc/Makefile index eb9fc557..18908813 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -53,5 +53,6 @@ LOCAL_FLAGS +=-Wno-char-subscripts -Wno-unknown-pragmas else LOCAL_FLAGS += -frounding-math -Wno-unused-but-set-variable -Wno-unknown-pragmas endif +LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses include $(MODULE) diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 2063a27d..94e42e10 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -149,7 +149,7 @@ static int UserIovCopy(struct iovec **iovBuf, const struct iovec *iov, const int { int ret; int bufLen = iovcnt * sizeof(struct iovec); - if (bufLen <= 0) { + if (bufLen < 0) { return -EINVAL; } @@ -528,90 +528,27 @@ OUT: off_t SysLseek(int fd, off_t offset, int whence) { - int ret; - struct file *filep = NULL; - /* Process fd convert to system global fd */ fd = GetAssociatedSystemFd(fd); - /* Get the file structure corresponding to the file descriptor. */ - ret = fs_getfilep(fd, &filep); - if (ret < 0) { - /* The errno value has already been set */ - return (off_t)-get_errno(); - } - - /* libc seekdir function should set the whence to SEEK_SET, so we can discard - * the whence argument here */ - if (filep->f_oflags & O_DIRECTORY) { - /* defensive coding */ - if (filep->f_dir == NULL) { - return (off_t)-EINVAL; - } - if (offset == 0) { - rewinddir(filep->f_dir); - } else { - seekdir(filep->f_dir, offset); - } - ret = telldir(filep->f_dir); - if (ret < 0) { - return (off_t)-get_errno(); - } - return ret; - } - - /* Then let file_seek do the real work */ - ret = file_seek(filep, offset, whence); - if (ret < 0) { - return -get_errno(); - } - return ret; + return _lseek(fd, offset, whence); } off64_t SysLseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence) { off64_t ret; + off64_t res; int retVal; - struct file *filep = NULL; - off64_t offset = ((off64_t)((UINT64)offsetHigh << 32)) + (uint)offsetLow; /* 32: offsetHigh is high 32 bits */ /* Process fd convert to system global fd */ fd = GetAssociatedSystemFd(fd); - /* Get the file structure corresponding to the file descriptor. */ - ret = fs_getfilep(fd, &filep); - if (ret < 0) { - /* The errno value has already been set */ - return (off64_t)-get_errno(); + ret = _lseek64(fd, offsetHigh, offsetLow, &res, whence); + if (ret != 0) { + return ret; } - /* libc seekdir function should set the whence to SEEK_SET, so we can discard - * the whence argument here */ - if (filep->f_oflags & O_DIRECTORY) { - /* defensive coding */ - if (filep->f_dir == NULL) { - return (off64_t)-EINVAL; - } - if (offsetLow == 0) { - rewinddir(filep->f_dir); - } else { - seekdir(filep->f_dir, offsetLow); - } - ret = telldir(filep->f_dir); - if (ret < 0) { - return (off64_t)-get_errno(); - } - goto out; - } - - /* Then let file_seek do the real work */ - ret = file_seek64(filep, offset, whence); - if (ret < 0) { - return (off64_t)-get_errno(); - } - -out: - retVal = LOS_ArchCopyToUser(result, &ret, sizeof(off64_t)); + retVal = LOS_ArchCopyToUser(result, &res, sizeof(off64_t)); if (retVal != 0) { return -EFAULT; } @@ -1399,9 +1336,11 @@ ssize_t SysWritev(int fd, const struct iovec *iov, int iovcnt) /* Process fd convert to system global fd */ int sysfd = GetAssociatedSystemFd(fd); - if ((iov == NULL) || (iovcnt <= 0) || (iovcnt > IOV_MAX)) { - ret = writev(sysfd, iov, iovcnt); - return -get_errno(); + if ((iovcnt < 0) || (iovcnt > IOV_MAX)) { + return -EINVAL; + } + if (iov == NULL) { + return -EFAULT; } ret = UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt); diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk index 9ea202d9..5cf6b208 100644 --- a/tools/build/mk/los_config.mk +++ b/tools/build/mk/los_config.mk @@ -213,8 +213,7 @@ ifeq ($(LOSCFG_LIB_LIBC), y) LIB_SUBDIRS += lib/libc LITEOS_BASELIB += -lc LITEOS_LIBC_INCLUDE += \ - -I $(LITEOSTOPDIR)/lib/libc/include \ - -I $(LITEOSTHIRDPARTY)/musl/porting/liteos_a/kernel/include \ + -isystem $(LITEOSTHIRDPARTY)/musl/porting/liteos_a/kernel/include LIB_SUBDIRS += lib/libsec LITEOS_BASELIB += -lsec