提交 5569b1d1 编写于 作者: O openharmony_ci 提交者: Gitee

!558 减少对musl代码的侵入式修改

Merge pull request !558 from Caoruihong/update_musl
......@@ -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)
......
......@@ -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",
]
......
/*
* 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")));
/*
* 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
......@@ -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;
}
/*
* 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 <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#ifdef LOSCFG_FS_VFS
#include <fs/fs.h>
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
/*
* 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 <stdint.h>
#include <errno.h>
#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);
}
......@@ -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;
}
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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",
]
}
......@@ -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)
......@@ -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();
}
/* 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();
ret = _lseek64(fd, offsetHigh, offsetLow, &res, whence);
if (ret != 0) {
return ret;
}
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);
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册