Commit graph

2410 commits

Author SHA1 Message Date
guoshichao
efa6c6823b libc: add creat function implementation
accoring to the PSE52 requirements, the creat() need to implementation
as a function.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 01:38:20 +08:00
guoshichao
4ce802900f pthead: change the pthread_equal implementation from macro to function
During the build of PSE52 VSX testcases, the pthread_equal() is accessed
in the form of a function pointer. Therefore, we have changed the
implementation of pthread_equal() from a macro to an actual function.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 01:37:38 +08:00
cuiziwei
e9bbf2928b libcxx: porting libcxx test.
porting libcxx test case to nuttx.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2026-01-15 13:40:42 -03:00
ligd
8c95e9e05c freopen: fix fdsan report error
[<0x60ddce>] __assert+0x1d/0x5c
[<0x60f2be>] android_fdsan_exchange_owner_tag+0x71/0xc0
[<0x60a14e>] close+0x19/0x64
[<0xb77b1c>] freopen+0x47/0xd8
[<0x86fe54>] test_nuttx_fs_stream01+0x4f/0x1a4
[<0xcef54e>] cmocka_run_one_test_or_fixture+0xe5/0x3cc
[<0xcefd26>] _cmocka_run_group_tests+0x41d/0xbd8
[<0x86cff2>] cmocka_fs_test_main+0x35/0x58
[<0x6a9d1a>] nxtask_startup+0x15/0x30
[<0x641e92>] nxtask_start+0x75/0x94

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-01-15 22:58:17 +08:00
pengyinjie
a8280b0eee freopen: close old file descriptor before reopening
Updated freopen function in libc stdio to close the old file descriptor before reopening the file.

Signed-off-by: pengyinjie <pengyinjie@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-01-15 22:58:17 +08:00
guoshichao
80fcbf7aa8 fsetpos: makes the fsetpos function comply with POSIX standard
Change the 'pos' parameter of fsetpos() from 'fpos_t *' to 'const fpos_t *'
in both the prototype and implementation, aligning with POSIX specification
which requires the position parameter to be const-qualified.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-15 02:22:46 +08:00
v-zhangxiaomeng5
20aea64ced libcxx: porting for Infineon TASKING compiler in cmake&make scripts.
Exclude cpp files beyong c++14 e.g. filesystem/, ryu/, variant.cpp etc.

Signed-off-by: v-zhangxiaomeng5 <v-zhangxiaomeng5@xiaomi.com>
2026-01-14 09:41:10 +08:00
v-zhangxiaomeng5
1327ce5214 libcxxabi: enable LIBCXXABI_BAREMETAL
This fix forces libcxxabi to parse typeinfo ptr in absolute relocation instead of GOT-REL.

Signed-off-by: v-zhangxiaomeng5 <v-zhangxiaomeng5@xiaomi.com>
2026-01-14 09:38:22 +08:00
v-zhangxiaomeng5
594e32c384 libcxxabi: support for Infineon TASKING compiler
This commit contains:
1) excluding c++ exception relevant cpp files
2) excluding compile options tasking doesn't support

Signed-off-by: v-zhangxiaomeng5 <v-zhangxiaomeng5@xiaomi.com>
2026-01-14 09:38:22 +08:00
cuiziwei
bb64889bef libcxxabi: remove gcc's libsupc++ from cmake/make scripts.
Both libcxxabi and libsupc++ implementat Itanium C++ ABI layer, just pick one.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2026-01-14 09:38:22 +08:00
wangmingrong1
f27f501365 libxxabi: remove redefinition in cmake/make scripts for clang
The clang unwind.h file already defines these macros:
_URC_FATAL_PHASE2_ERROR = _URC_FAILURE
_URC_FATAL_PHASE1_ERROR = _URC_FAILURE

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-01-14 09:38:22 +08:00
guoshichao
99551e78f0 wqueue: fix the config typo error
Fix typo in CMakeLists.txt: CONFIG_LIB_USRWORK → CONFIG_LIBC_USRWORK.
This ensures work_usrthread.c, work_queue.c, and work_cancel.c are compiled
when the user work queue feature is enabled.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-14 09:24:00 +08:00
buxiasen
38378149ed libs/libc/ftok: fix sizeof(char *), after tempbuffer
Catched by coverity, we change full path from stack variable to ptr.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 01:59:58 +08:00
Peter van der Perk
0fed06190b libc: Add Kconfig option to disable hex-string to float parsing
Introduce CONFIG_LIBC_DISABLE_HEXSTR_TO_FLOAT to remove support for
parsing hexadecimal floating-point constants (C99 %a) in strtod(),
strtof(), strtold(), and sscanf("%a"). This feature is rarely used in
embedded systems and its removal saves significant flash space. Decimal
float parsing remains unaffected.

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
2026-01-08 02:37:21 +08:00
dongjiuzhu1
9bcd640c49 libc/syslograwstream: Use memrchr to locate the newline character
for output to avoid log disorder.

If no newline character is found, and the buffer is full, forced output
is required; if the buffer is not full, output is performed according to
the newline character to prevent log disorder.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-01 17:03:50 +08:00
dongjiuzhu1
6802d3510b sched/clock: support using CLOCKFD to call clock_getres
This patch extends CLOCKFD support to clock_getres(), allowing
applications to query the resolution of PTP clocks through file
descriptors using the standard POSIX clock API.

Key changes include:

1. Move clock_getres() from libc to kernel:
   - Relocated from libs/libc/sched/clock_getres.c to sched/clock/
   - Enables direct kernel-level file descriptor handling
   - Maintains POSIX compliance while adding CLOCKFD support

2. CLOCKFD support in clock_getres():
   - Detects CLOCKFD-encoded clockids using CLOCKFD_TO_FD() check
   - Extracts file descriptor from clockid parameter
   - Validates file descriptor through fs_getfilep()
   - Issues PTP_CLOCK_GETRES ioctl to query clock resolution

3. PTP clock resolution query:
   - Retrieves resolution from PTP clock device via ioctl
   - Returns nanosecond-precision timing resolution
   - Enables applications to determine clock accuracy capabilities
   - Falls back to standard clock resolution for non-CLOCKFD clockids

4. Error handling:
   - Returns EINVAL for invalid CLOCKFD file descriptors
   - Properly manages file reference counting with fs_putfilep()
   - Maintains backward compatibility with existing clock types

5. Build system updates:
   - Updated libs/libc/sched/CMakeLists.txt and Make.defs
   - Updated sched/clock/CMakeLists.txt to include clock_getres.c
   - Ensures proper compilation in kernel context

Usage example:
  int fd = open("/dev/ptp0", O_RDONLY);
  struct timespec res;
  clock_getres(CLOCKFD(fd), &res);  /* Query PTP clock resolution */
  printf("Resolution: %ld.%09ld sec\n", res.tv_sec, res.tv_nsec);
  close(fd);

This completes the basic POSIX clock API support for dynamic PTP clocks,
providing applications with comprehensive clock information access.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-30 10:22:09 -03:00
chenzihan1
43b16fdb7c libc/search: add foreach api for hcreate_data
add foreach api for hash table

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
2025-12-25 09:39:03 +08:00
anjiahao
667171fbd8 lib/backtrace:need init lock before use
Locks need to be initialized when they are declared.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-22 15:23:04 +08:00
anjiahao
2969857ff2 libc/libelf:fix bug for libelf_symname
readlen maybe not equal CONFIG_LIBELF_BUFFERINCR

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-20 11:17:55 +08:00
anjiahao
7c96537a58 string:use builtin function to optimize libc function
This allows the compiler to automatically identify which string functions
can be compiled into libraries, and the compiler's internal implementation
is faster than libc functions.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-20 10:38:53 +08:00
buxiasen
4028132910 libc/localtime: rename offsetp to poffset
Fix spell check error
lib_localtime.c:1291: offsetp ==> offset

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-12-19 13:46:21 -05:00
buxiasen
bda9ab9287 libc/localtime: tz_lock/unlock should not touch tcb except FLAT
Causing kernel build report undefined reference 'g_nx_initstate'
Also protect build, as user elf have no access of kernel objects.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-12-19 13:46:21 -05:00
yangao1
011fd50bcd libc/arch_libc.c:fix bug for macro LIBC_ARCH_STRCHRNUL
config ARM64_STRCHRNUL
	bool "Enable optimized strchrnul() for ARM64"
	default n
	select LIBC_ARCH_STRCHRNUL
	depends on ARCH_TOOLCHAIN_GNU
	---help---
		Enable optimized ARM64 specific strchrnul() library function

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1
184f1ef225 libs/risc-v:add cfi for optimized compilation func
(gdb) bt
    at /home/mi/ssd/dev-system/nuttx/include/string.h:321
    ppcmd=<synthetic pointer>, vtbl=0x80069498) at nsh_parse.c:1909
    param=0x800692b8) at nsh_parse.c:2593
    cmdline=cmdline@entry=0x80069750 "hello") at nsh_parse.c:3028
    argc=argc@entry=1, argv=argv@entry=0x80068870) at nsh_session.c:246
    at nsh_consolemain.c:75
    at nsh_main.c:74
...

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1
15eb317be2 libc/arm64: add cfi for optimized func
(gdb) bt
    #0  arch_strlen () at machine/arm64/gnu/arch_strlen.S:119
    #1  0x000000004043a2c0 in strchr (s=s@entry=0x408e5e40 "HELLO WORLD", c=c@entry=87) at machine/arch_libc.c:252
    #2  0x0000000040504c6c in strchr (c=87, s=0x408e5e40 "HELLO WORLD") at /home/mi/ssd/dev-system/nuttx/include/string.h:306
    #3  test_strchr () at hello_main.c:79
    #4  hello_main (argc=argc@entry=1, argv=argv@entry=0x40b5c090) at hello_main.c:132
    #5  0x000000004043d958 in nxtask_startup (entrypt=0x40504ba0 <hello_main>, argc=argc@entry=1, argv=argv@entry=0x40b5c090) at sched/task_startup.c:72
    #6  0x00000000403f1ab4 in nxtask_start () at task/task_start.c:104
    #7  0x0000000000000000 in ?? ()

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1
34aef9cbec armv7a:add cfi instrcutions to debug
(gdb) bt
    #0  memset () at machine/arm/armv7-a/gnu/arch_memset.S:45
    #1  0x0407222e in memset (n=4, c=65, s=0x40269d94) at /home/mi/ssd/dev-system/nuttx/include/string.h:203
    #2  test_memset () at hello_main.c:57
    #3  hello_main (argc=<optimized out>, argv=<optimized out>) at hello_main.c:66
    #4  0x0403f1de in nxtask_startup (entrypt=0x40721b1 <hello_main>, argc=1, argv=0x40269628) at sched/task_startup.c:72
    #5  0x0400c66a in nxtask_start () at task/task_start.c:104
    #6  0x00000000 in ?? ()

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
ligd
5e785b14bc memset: add none NEON version support for armv7-a/r
Add memset implementation for ARMv7-A/R targets without NEON support,
ensuring proper operation on CPUs lacking NEON instructions.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2025-12-18 22:05:12 +08:00
anjiahao
b623c781c5 arch:use ARCH_64BIT to mark arch is support 64bit
Add ARCH_64BIT macro to indicate architectures with 64-bit support,
improving portability and conditional compilation.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-18 22:05:12 +08:00
ligd
8a02ca5913 memcpy: fix link failed when open kasan
riscv-none-elf-ld: /home/ligd/platform/dev-system/nuttx/staging/libc.a(arch_libc.o): in function `memcpy':
/home/ligd/platform/dev-system/nuttx/libs/libc/machine/arch_libc.c:131:(.text.memcpy+0x4e): undefined reference to `arch_memcpy'

Signed-off-by: ligd <liguiding1@xiaomi.com>
2025-12-18 22:05:12 +08:00
Petro Karashchenko
11dc1df189 libc: improve libc dependencies in case of LIBM_NONE
Currently the code for strtof, strtod and strtold is in the list
of files to compile unconditionally, but when trying to compile
kernel with toolchain without libm support (LIBM_NONE=y) compilation
fails because code refers math.h

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2025-12-14 17:57:27 -03:00
Michal Lenc
977f9ed4b8 libs/libc/obstack/lib_obstack_free.c: fix object check within chunk
The original condition incorrectly used &h->chunk instead of
h->chunk in the calculation whether the object is in the chunk. This
could lead to the wrong behavior as the first branch gave incorrect
result and thus sometimes the entire obstack was freed even though
object was not NULL.

The commit also simplifies the logic, we can use pointer arithmetic
here and just do h->chunk + 1 as it gives the same result as
(FAR char *)h->chunk + sizeof(struct _obstack_chunk). This saves
unnecessary cast and sizeof.

The second branch should be less than or equal, not just less than.
This ensures the object is correctly located in the chunk even after
previous obstack_finish was called.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
Co-authored-by: Karel Kočí <kkoci@elektroline.cz>
2025-12-13 18:13:19 -03:00
chenxiaoyi
0d757d0134 libc/machine/xtensa: add mcount implementation for gprof
Add the implementation of _mcount() to meet the requirements of gprof.

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2025-12-13 13:31:46 +08:00
Petro Karashchenko
8c3106e2a4 libs/libm: fix typo in Kconfig
fix typo in Kconfig

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2025-12-09 18:03:10 +08:00
fangxinyong
31b5ef357c libm/newlib: Include fenv sources for all ARCHs and extend x86 includes
newlib/libm/fenv/*.c are the non-functional implementation that should
be overridden by an architecture specific implementation in newlib/libm/machine/ARCH.

Make the architecture check for including shared x86 sys headers for x86 and x86_64.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2025-11-30 20:43:58 +08:00
fangxinyong
d956699f75 libm/newlib: Add duplicate filename filtering for source lists
Implement filename-based filtering to exclude duplicate files
from source lists, ensuring ARCH-specific files (ARCH_CSRCS)
take precedence over files in common or other dirs

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2025-11-30 20:43:58 +08:00
chenxiaoyi
09a71ec7c1 libs/libc/arm: add back __aeabi_mem* functions
Add back these functions since clang will use them.

This reverts "libs/libc/arm: use builtin routines instead of aliases of __aeabi_mem*"
and adds source files to cmake.

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2025-11-28 14:50:58 -03:00
Huang Qi
311f42bbac libc/unistd: Replace pipe() macro with proper function implementation
Replace the pipe() macro definition with a proper function implementation
to improve POSIX compliance and debugging capabilities. The new pipe()
function serves as a wrapper around pipe2() with flags set to 0.

Changes include:
- Convert pipe() from macro to function declaration in unistd.h
- Add lib_pipe.c implementation file with proper function documentation
- Update build system files (CMakeLists.txt and Make.defs) to include
  the new source file when CONFIG_PIPES is enabled
- Add pipe() entry to libc.csv for symbol tracking

This change allows for better debugging, proper symbol resolution,
and follows NuttX coding standards for library function implementations.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-11-26 17:18:13 +08:00
wangchengdong
ba05c7f133 sched/signal: Fix nxsig_ismember() return value behavior
nxsig_ismember() has a return type of int, but the current
implementation returns a boolean value, which is incorrect.

All callers should determine membership by checking whether
the return value is 1 or 0, which is also consistent with the POSIX sigismember() API.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-25 10:02:52 +08:00
chao an
8847389886 style/FAR: remove FAR qualifier
N/A, remove FAR qualifier from non-pointer types

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-11-10 10:56:29 +01:00
nuttxs
65e318421d netdb/lib_dnsdelserver.c: support delete the DNS server address
by index or address

 - dns_del_nameserver()
 - dns_del_nameserver_by_index()

Update the "DNS function" section in 11_network.rst, and create
the netlib API documentation in netlib/index.rst

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-11-08 16:17:40 -03:00
wangchengdong
f82f71d180 libs/libc: Fix Kconfig issue for memcpy and memset
Fix an issue on ARMv8-R where NEON is not supported.
    When NEON is disabled, the assembly-optimized implementations
    of memset and memcpy should not be used.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-07 13:04:20 +01:00
raiden00pl
3e6acfaf17 libs: remove not related comments from cmake files
remove not related comments from libs/libbuiltin/CMakeLists.txt and
libs/libxx/CMakeLists.txt. These are a copy paste from a Makefile
which doesn't make sense for these files.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-10-11 17:07:51 -04:00
raiden00pl
13ab107d67 libc: remove reference to non-existent readme
remove reference to non-existent readme in libc.

Pointing to the documentation page doesn't make sense in this case,
because it doesn't explain the use of `#undef XXX` for this case anyway.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-10-11 17:07:51 -04:00
p-szafonimateusz
c54bee0295 libc/pthread/pthread_keydelete.c: reset key value
When key is deleted, its value should also be reset.

This fixes the pthread_getspecific.c test case from
PSE52 Open Group Threads Test Suite.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-10-01 12:00:43 +08:00
Halysson
9014af9ae7 libc/crc: Add crc8rohcincr for incremental CRC8 ROHC calculation
Add crc8rohcincr() function to support byte-by-byte CRC8 calculation
using the ROHC polynomial (0x07) without XOR inversions. This is
useful for protocols that require incremental CRC accumulation,
such as GSM 07.10 (CMUX), where the CRC must be computed as frames
are parsed from circular buffers.

Changes include:
- New crc8rohcincr() function for single-byte incremental CRC
- Function takes current CRC value and returns updated CRC
- Uses same g_crc8_tab table as other ROHC functions
- No XOR inversions applied for proper accumulation

This allows protocols like CMUX to replace local CRC table
implementations with standard libc CRC functions while maintaining
correct incremental calculation behavior.

Signed-off-by: Halysson <halysson1007@gmail.com>
2025-09-30 17:30:46 -03:00
Jukka Laitinen
c9776bf8a6 libc/fclose: Validate the user provided stream pointer
Check that the provided stream pointer is really opened for the group before
closing & freeing it.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-09-09 23:51:35 +08:00
wangchengdong
7d0fb9d34f sched/semaphore: add support to customize semaphore max allowed value
Curernt implementation default semaphore max allowed value to SEM_VALUE_MAX.
  In some cases, user may want to change this, so provide a function to do this: sem_setmaxvalue

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-04 09:48:34 +08:00
wangchengdong
8cfb9d7053 libs/libc/semaphore: allow nxsem_init to negative value
Allow user to init semaphore value to negative value, this is needed in some use cases
2025-08-31 18:38:03 +08:00
p-szafonimateusz
9fd1478a99 pthread: add pthread_{get|set}concurrency support
Add support for pthread_{get|set}concurrency support.

NuttX uses 1:1 threading model (every pthread is a kernel-managed thread),
so this function has no real effect on the scheduling behavior.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-08-22 20:50:13 +08:00
p-szafonimateusz
396f5b40ce unistd: add support for confstr()
add support for POSIX defined confstr()

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-08-22 20:50:13 +08:00