Commit Graph

2009 Commits

Author SHA1 Message Date
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
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
Build Documentation / build-html (push) Has been cancelled
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
Build Documentation / build-html (push) Has been cancelled
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 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
Build Documentation / build-html (push) Has been cancelled
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
p-szafonimateusz 8108aad1a4 pthread: add pthread_attr_{get|set}guardsize support
This commit adds simple implementation of guardsize for pthreads.
At this moment this option simply increases the size of allocated pthread stack.

At default pthread guard size is set to 0.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-08-22 20:50:13 +08:00
Tiago Medicci Serrano d250808c1c esp32s3/elf: Fix ELF loader on ESP32-S3 when using external PSRAM
Prior to this commit, it wasn't possible to load ELF modules from
the external PSRAM. There were two main issues about it: 1) copying
data using the instruction bus was being used instead of the data
bus (this, per si, isn't a problem, but requires special attention
regarding data alignment), and 2) the cache was not being properly
cleaned and flushed to properly access the loaded data using the
instruction bus.

Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
2025-08-20 02:23:03 +08:00
nuttxs 7b3913da60 libs/libc/netdb: Optimize the timeout calculation logic:
1. Adopt an exponential backoff strategy () to dynamically adjust the timeout
   duration, which is suitable for retry scenarios.
2. Optimize the default configuration to set the initial timeout to 5 seconds.
3. Support dynamic modification of the maximum timeout limit to adapt
   to different scenarios.
Reference: RFC 1536 (section on retransmission implementation recommendations)

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-08-06 01:58:05 +08:00
Shanmin Zhang 73cf02d63a Revert "libs/libc/stdlib/lib_exit.c: fix multiple definition of __dso_handle in msys2"
This reverts commit 8f96e59aee.

The implementation of __dso_handle is independent of the HOST OS but dependent on the specific compiler.
Therefore, this patch will cause compilation failures for other cross-compilers on the Windows platform, such as arm-none-eabi-gcc and aarch64-none-elf-gcc.
Constraints should be applied to compiler target rather than compiler host.
2025-07-31 22:10:36 +08:00
George Poulios c4541a4d4c libc/idr: Remove nodes from RB trees during destroy
Build Documentation / build-html (push) Has been cancelled
idr_destroy() would loop over the removed and alloced
RB tree nodes freeing them but not removing them from
the trees. From the perspective of the RB tree those
nodes would remain valid, while in fact, they were free
memory, potentially reallocated for other purposes, or
otherwise overwritten by the allocator with metadata.
This would cause (seemingly random) memory corruption
crashes triggered by the RB tree code trying to access
link fields from the free'd nodes.

Fix that by removing the nodes before freeing them.

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2025-07-12 14:24:32 +08:00
yinshengkai 156ef05205 libc/mcount: compatible with armv6m mcount implementation
mcount.S: Assembler messages:
mcount.S:33: Error: cannot honor width suffix -- `bic r1,lr,#1'
mcount.S:35: Error: cannot honor width suffix -- `bic r0,r0,#1'
mcount.S:37: Error: cannot honor width suffix -- `pop {r0,r1,r2,r3,ip,lr}

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2025-07-10 18:06:03 +08:00
Xiang Xiao 4c7366045c libc/semaphore: Go the fast path even arch doesn't support atomic
since the simulated atomic operation is still fast than the slow path

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-07-08 09:47:44 -03:00
Xiang Xiao fb14b54b83 libc/semaphore: Use the while loop to handle the inerrupt correctly
If atomic_try_cmpxchg_xxxx runs on LL/SC architectures (e.g.ARMv7,
ARMv8, RISC-V), the weak CAS expands to a single LDREX/STREX pair.

If the CPU takes an IRQ/FIQ/SVC between the two instructions,
hardware performs an implicit CLREX and the following STREX returns
1, therefore atomic_try_cmpxchg_xxxx return failure even though
*addr* still holds the expected value.

So let's retry atomic_try_cmpxchg_xxxx in this case.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-07-08 09:47:44 -03:00
wangmingrong1 c6da553788 kasan: kasan_reset_tag rename kasan_clear_tag
The clear tag is more explicit than the reset tag.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
Xiang Xiao 2b360c826c arch/arm: Move lib_dummy.c from arch/arm/src/common/ghs to libs/libc/machine/arm
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 5758364f10 libc/machine/arm: Move all source files out of gnu folder
and unify the file prefix to arch_xxx.c

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
yangao1 0b6188bfa2 armv8-m: Optimize cfi instructions to debug
Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao c1a37ec1fb libc/machine/arm64: Move all source files out of gnu folder
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 378f8a5c0f libc/machine/renesas: Move all source files out of gnu folder
and remove the empty CMakeLists.txt in the subdirectories.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao ae071920b4 libc/machine/riscv: Move all source files out of gnu folder
and remove the empty CMakeLists.txt in the subdirectories.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 1177ac8ee4 libc/machine/x86_64: Move all source files out of gnu folder
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
nuttxs 26e02700dd netdb/lib_dnsquery.c: In the IPv6 or IPv4 dns_query_callback() block,
if dns_recv_response() fails, dns_bind() is called again at try_stream to
create a new socket. However, the original socket descriptor sd isn't closed

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-06-23 11:56:15 -03:00
Xiang Xiao bc4041db60 libc: Move stdio/README to Documentation/components/libs/libc/stream.rst
Build Documentation / build-html (push) Has been cancelled
follow up this change:
commit 84dc88730c
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Mon Jun 9 14:39:03 2025 +0800

    libc: Move stream printf/scanf from libc/stdio to libc/stream

    to keep all related code in one place

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-22 17:07:41 -03:00
Xiang Xiao d266bfaca1 libc: lib_bsprintf reuse var instead value for string
to simplify the code logic

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-20 09:48:39 +08:00