Commit Graph

1230 Commits

Author SHA1 Message Date
hujun5 d70d406161 libc/fdsan: add fdsan protection for all file pointers
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-05-27 15:05:44 +08:00
Huang Qi 84c7a4dd69 libc.csv: Correct type of return value for strstr
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-05-25 20:09:27 +08:00
chao an e51ec54c02 stream/hexdump: add hexdump stream to dump binary to syslog
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao 0203839fa1 stream: Add syslogstream implementation
which forward the output to syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao 20ea607bd0 stream: Rename syslogstream to syslograwstream
to prepare a new stream implementation of syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an f75adacea6 stream/syslog: remove unnecessary ifdef CONFIG_SYSLOG_BUFFER
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an 0455167457 stream/syslog: use internal buffer to decoupling syslog with iob
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-24 09:53:30 +08:00
Xiang Xiao 7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
Petro Karashchenko c70b7f6b3d nuttx: improve C89 compatibility in common code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko 8d565fc0e3 libs/libc/string: remove redundant parenthesis
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Zhe Weng e7043828a7 netdb: Regard hosts file prior to DNS when resolving
- Linux: What inside /etc/hosts comes first.
- NuttX: Even if we write a domain in /etc/hosts, we still use DNS
         result instead of hosts lines. This patch change this behavior.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-18 14:50:08 -03:00
Xiang Xiao 8d56a9bbcb Remove #warning if the code already return the error code or value
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
simbit18 ba94a24c8b libs\libc\stdlib\Kconfig: Fix indentation
Remove TABs
2023-05-18 15:43:22 +03:00
simbit18 3554c5f9a5 libs\libc\misc\Kconfig: Fix indentation
Remove TABs
2023-05-18 15:43:22 +03:00
Tiago Medicci Serrano 58e97e521c libc/string: prevent libc in the kernel/userspace optionally
Add the `LIBC_PREVENT_STRING_KERNEL` and `LIBC_PREVENT_STRING_USER`
that are meant to be selected by the chip if no libc implementation
is going to be built. If selected, neither NuttX's software version
of the libc nor any architecture-specific implementation will be
built in the kernel or in the userspace, respectively. In this
case, the linker may provide a ROM-defined version of the libc
functions instead.
2023-05-17 13:58:48 +08:00
guoshichao e1096bd35c libc/regex: add regex implementation
add regex implementation for libc, the implementation are ported from
musl project

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-05-17 10:25:18 +08:00
hujun5 90387a5b41 libc/misc: add fdsan module
FD (file descriptor) is widely used in system software development,
and almost all implementations of posix os (including nuttx) use FD as an index.
the value of fd needs to be allocated starting from the minimum available value of 3, and each process has a copy,
so the same fd value is very easy to reuse in the program.

In multi threaded or multi process environments without address isolation,
If the ownership, global variables, and competition relationships of fd are not properly handled,
there may be issues with fd duplication or accidental closure.
Further leading to the following issues, which are difficult to troubleshoot.

1. Security vulnerability: the fd we wrote is not the expected fd and will be accessed by hackers to obtain data
2. Program exceptions or crashes: write or read fd failures, and program logic errors
3. The structured file XML or database is damaged: the data format written to the database is not the expected format.

The implementation principle of fdsan is based on the implementation of Android
https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-05-17 10:24:42 +08:00
simbit18 0a40287b13 libs/libc/pthread: Fix nxstyle errors
error: Long line found
2023-05-12 18:00:15 +03:00
zhangyuan21 f132edbf35 libc/sched: Return EINVAL when type incorrect at task_setcanceltype
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setcancelstate.html

The pthread_setcancelstate() function may fail if:

[EINVAL]
The specified state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.
The pthread_setcanceltype() function may fail if:

[EINVAL]
The specified type is not PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-12 01:06:23 +08:00
zhangyuan21 962dfaf651 libc/pthread: Return EINVAL when input parameter incorrect at pthread_once
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_once.html

If an implementation detects that the value specified by the once_control
argument to pthread_once() does not refer to a pthread_once_t object
initialized by PTHREAD_ONCE_INIT, it is recommended that the function
should fail and report an [EINVAL] error.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-12 01:06:23 +08:00
simbit18 eedca9d7c6 libs/libc/pthread: Fix nxstyle errors
error: Long line found
2023-05-10 13:04:35 +02:00
chao an 3403b983ec libc/qsort: fix invalid-pointer-pair if enable detect_invalid_pointer_pairs=2
=================================================================
==2920138==ERROR: AddressSanitizer: invalid-pointer-pair: 0x603000000130 0x000000000000
    #0 0x5602d3c6a89d in qsort stdlib/lib_qsort.c:180
    #1 0x5602d3c28928 in romfs_cachenode romfs/fs_romfsutil.c:503
    #2 0x5602d3c2854d in romfs_cachenode romfs/fs_romfsutil.c:486
    #3 0x5602d3c2b056 in romfs_fsconfigure romfs/fs_romfsutil.c:777
    #4 0x5602d3c24856 in romfs_bind romfs/fs_romfs.c:1111
    #5 0x5602d3bf5179 in nx_mount mount/fs_mount.c:427
    #6 0x5602d3bf5796 in mount mount/fs_mount.c:539
    #7 0x5602d3bc1154 in nsh_romfsetc apps/nshlib/nsh_romfsetc.c:110
    #8 0x5602d3b8f38d in nsh_initialize apps/nshlib/nsh_init.c:127
    #9 0x5602d3b8f2b7 in nsh_main apps/system/nsh/nsh_main.c:69
    #10 0x5602d3b7a3a6 in nxtask_startup sched/task_startup.c:70
    #11 0x5602d3b5de89 in nxtask_start task/task_start.c:134

0x603000000130 is located 0 bytes inside of 32-byte region [0x603000000130,0x603000000150)
allocated by thread T0 here:
    #0 0x7fcdac74793c in __interceptor_posix_memalign ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:226
    #1 0x5602d3c9024e in host_memalign sim/posix/sim_hostmemory.c:180
    #2 0x5602d3c907d2 in host_realloc sim/posix/sim_hostmemory.c:222
    #3 0x5602d3b8aaff in mm_realloc sim/sim_heap.c:262
    #4 0x5602d3b87a6a in realloc umm_heap/umm_realloc.c:91
    #5 0x5602d3c280c4 in romfs_cachenode romfs/fs_romfsutil.c:466
    #6 0x5602d3c2854d in romfs_cachenode romfs/fs_romfsutil.c:486
    #7 0x5602d3c2b056 in romfs_fsconfigure romfs/fs_romfsutil.c:777
    #8 0x5602d3c24856 in romfs_bind romfs/fs_romfs.c:1111
    #9 0x5602d3bf5179 in nx_mount mount/fs_mount.c:427
    #10 0x5602d3bf5796 in mount mount/fs_mount.c:539
    #11 0x5602d3bc1154 in nsh_romfsetc apps/nshlib/nsh_romfsetc.c:110
    #12 0x5602d3b8f38d in nsh_initialize apps/nshlib/nsh_init.c:127
    #13 0x5602d3b8f2b7 in nsh_main apps/system/nsh/nsh_main.c:69
    #14 0x5602d3b7a3a6 in nxtask_startup sched/task_startup.c:70
    #15 0x5602d3b5de89 in nxtask_start task/task_start.c:134

Address 0x000000000000 is a wild pointer.
SUMMARY: AddressSanitizer: invalid-pointer-pair stdlib/lib_qsort.c:180 in qsort
==2920138==ABORTING
Aborted (core dumped)

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-08 13:43:28 +02:00
Xiang Xiao 325f395300 Replace all strncpy with strlcpy
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
Xiang Xiao 6f6fce95a2 Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
Xiang Xiao 6354a742f1 libc: Add a new argument(size_t fulllen) to lib_getfullpath
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
chao an d6747dd6ad libc/armv8-m: fix build break if MVE is disabled
machine/arm/armv8-m/gnu/arch_memcpy.S: Assembler messages:
machine/arm/armv8-m/gnu/arch_memcpy.S:105: Error: bad instruction `prologue push_ip=HAVE_PAC_LEAF'
machine/arm/armv8-m/gnu/arch_memcpy.S:121: Error: bad instruction `epilogue push_ip=HAVE_PAC_LEAF'
make[1]: *** [Makefile:143: bin/arch_memcpy.o] Error

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-05 08:07:08 +02:00
zhangyuan21 73257eeda0 libs/libc: fixed armv7-m strcmp build issue
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-04 11:59:41 -04:00
zhangyuan21 884be2bdb9 assert: Distinguish between assert and exception
CURRENT_REGS may change during assert handling, so pass
in the 'regs' parameter at the entry point of _assert.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-05-03 14:49:32 +08:00
Stuart Ianna 4e2a8d4492 libc: Add setbuffer to stdio.
The setbuffer() function is a wrapper around setvbuf() which
enables full buffering on a buffer allocated by the caller, assuming
buffer is not a null pointer.
2023-05-01 11:24:41 +03:00
chao an 9fa097ab69 newlib: libc: memcpy M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-28 09:51:52 +08:00
chao an 5945f080b9 boars/spawn_proxy: remove all CONFIG_POSIX_SPAWN_PROXY_STACKSIZE
Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-27 17:35:58 +08:00
dongjiuzhu1 68d40d4a98 libc/locale: support iconv_open,iconv,iconv_close
Refs to:https://github.com/bminor/musl

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-04-25 19:12:53 +01:00
Xiang Xiao 28eca64dd5 libc: Cleanup per-thread resource in exit/quick_exit
copy from pthread_exit to avoid the resource leak

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-25 16:52:08 +03:00
hujun5 d189a86a35 system: pthread_barrierwait should be moved to kernel space
The current implementation requires the use of enter_critical_section, so the source code needs to be moved to kernel space

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-04-25 15:34:40 +08:00
hujun5 5a2bc1c015 system: pthread_barrierwait can not be preemption
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-04-25 15:34:40 +08:00
chao an 2be18a8b24 makefile: fix libc/mm files can not be compiled incrementally
Use double delim to fix windows native build and give an error:
makefile:132: *** target mode do not include“%”. stop.

In Windows environment DELIM := $(strip \) but \ has two role:
first: \ as directory, and second \ as Escape character, Reference:

https://github.com/apache/nuttx/pull/7572#discussion_r1028219229

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-24 12:43:10 +03:00
Zhe Weng d8da8dcc44 libc: Print error code for unknown errors in strerror/gai_strerror
Ref: Linux print unknown errors like "Unknown error nnn"
https://man7.org/linux/man-pages/man3/strerror.3.html#RETURN_VALUE

Note:
These interfaces are called at low freq, so a static buffer may be enough.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 01:46:39 +08:00
Stuart Ianna 4cae98674d litex: Support for kernel build with vexriscv-smp. 2023-04-22 01:40:32 +08:00
Petro Karashchenko 733807f635 libs/libc/string: make strsignal() configurable similar to strerror()
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-04-22 01:26:42 +08:00
Fotis Panagiotopoulos 098b7bbfb3 Fixes in asprintf usage. 2023-04-19 02:48:39 +08:00
XinStellaris 57df1ddcbb Add armv7m assembly strcpy.
Signed-off-by: XinStellaris <tianxin7@xiaomi.com>
2023-04-10 18:59:52 +03:00
Petro Karashchenko 3513c53a09 libs/libc/pthread: fix function name in comments
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-04-07 12:28:45 -03:00
chao an 4fbf5f7a4b libs/libc: correct config define of arch functions
Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-04 09:37:46 -03:00
chao an 3c58f5db2b syscall/libc: add more syscall/libc symbols into csv file
Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-31 21:56:50 +09:00
Stuart Ianna 01b0305ab5 risc-v: SV32 MMU support for qemu-rv. 2023-03-29 22:15:19 +09:00
Fotis Panagiotopoulos 0b1ba70ac5 asprintf: Fixed possible memory leak if print fails. 2023-03-28 14:46:07 -03:00
Gregory Nutt 717bb04cb7 Increase the number of real time signals. Two is not enough.
Refer to issue #8867 for details and rational.

Convert sigset_t to an array type so that more than 32 signals can be supported.

Why not use a uin64_t?
- Using a uin32_t is more flexible if we decide to increase the number of signals beyound 64.
- 64-bit accesses are not atomic, at least not on 32-bit ARMv7-M and similar
- Keeping the base type as uint32_t does not introduce additional overhead due to padding to achieve 64-bit alignment of uin64_t
- Some architectures still supported by NuttX do not support uin64_t
  types,

Increased the number of signals to 64. This matches Linux. This will support all xsignals defined by Linux and also 32 real time signals (also like Linux).

This is is a work in progress; a draft PR that you are encouraged to comment on.
2023-03-27 16:59:04 +03:00
Petro Karashchenko 4309c6693c libc/modlib: fix indentation issue
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-26 09:23:50 -06:00
Xiang Xiao beb38917d1 signal: Replace NuttX special SIGWORK with SIGPAGING(SIGRTMIN)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-26 08:31:36 -06:00
chao an 3428d15d04 libc/math: rename libc/math.csv to libm/libm.csv
Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-24 14:58:10 -03:00