Commit Graph

2012 Commits

Author SHA1 Message Date
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
shichunma 900998fe20 netdb/dns: validate nameserver input in dns_add_nameserver
It can't be zero or broadcast addr for a valid dns server.

Signed-off-by: shichunma <masc2008@gmail.com>
2026-04-07 16:43:14 +08:00
Huang Qi e09048cc88 style: Fix "is is" typo across the codebase.
Correct duplicate "is is" word found in 181 files throughout the
codebase.
In most cases "is is" was changed to "is", but in contexts like
"MCU is is sleep mode" it was corrected to "MCU in sleep mode".

Also fixes a "the the" typo in net/inet/inet_sockif.c.

This is a pure style/documentation fix that improves code readability.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-24 09:39:26 +08:00
chenzhaoxiang 3fb1a40a4b libs/libc: add configurable skip count for mutex backtrace addresses
This commit introduces a new Kconfig option LIBC_MUTEX_BACKTRACE_SKIP tocontrol the
number of initial addresses skipped when generating mutex backtraces.

Key changes:
1. Add LIBC_MUTEX_BACKTRACE_SKIP Kconfig entry (depends on
LIBC_MUTEX_BACKTRACE > 0), defaulting to 2. This option lets users configure
how many leading addresses are omitted from the mutex backtrace output.

2. Modify the nxmutex_add_backtrace() function to pass the new config value
as the skip parameter to sched_backtrace(), replacing the hardcoded 0.

This enhancement improves the usability of mutex backtraces by allowing removalof uninformative
initial stack frames (e.g., backtrace helper functions ormutex acquisition wrappers), making the
relevant call stack entries more visiblefor debugging lock-related issues.

The default value (2) maintains sensibleout-of-the-box behavior while enabling customization for specific use cases.

Signed-off-by: chao an <anchao.archer@bytedance.com>
2026-02-27 19:54:37 +08:00
wangchengdong 5060ee80d1 libs/pthread: disable pthread_kill when no signals
pthread_kill depends on signasl, so when all signals are disabled
 disable pthread_kill too

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2026-02-26 20:03:05 +08:00
SPRESENSE 72b67832ea Makefile: Remove make depend files by make distclean
Intermediate files of make depend like .ddc and .dds may remain
when make is interrupted. Remove them using make distclean.

Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com>
2026-02-16 16:27:57 +01:00
yinshengkai 54040c6888 libs/libc/machine/arm: add Cortex-M0/M23 support to arch_mcount
Add support for ARMv6-M and ARMv8-M Baseline architectures
(Cortex-M0/M0+/M23) in the mcount profiling function. These cores
only support limited Thumb-1 instruction set and require different
assembly instructions compared to ARMv7-M and higher.

Changes:
- Use MOVS+BICS instead of BIC for bit clearing on M0/M23
- Separate register restore for limited push/pop instructions
- Use BX instead of direct POP to PC on M0/M23

Signed-off-by: yinshengkai <yinshengkai@bytedance.com>
2026-02-04 03:03:45 +08:00
anjiahao 871a9b3261 libc_bsd:add missing SPDX-License
Just add SPDX-License, no code changes

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-02-04 03:02:04 +08:00
anjiahao 4db4252a7c libc/string: Add BSD-optimized memset implementation.
Add lib_bsdmemset.c from newlib (Red Hat BSD license) which provides
an optimized memset using word-aligned writes and loop unrolling for
improved performance on larger buffers.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-02-04 03:02:04 +08:00
anjiahao 8ecbdf9164 cmake:add lib_psa_set/getstackaddr file to CMakeLists.txt
CMake forgot to compile these two files, so add them.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-02-03 14:40:00 +01:00
fangxinyong a724a5f4f4 sched/cancelpt: Fix MISRA C 2012 Rule 10.4 violations
Fix violations of MISRA C:2012 Rule 10.4 (operand of unsigned and signed)
in cancellation point handling code.

Changed all CANCEL_FLAG_* macro definitions and their usage to use unsigned
literals (1u instead of 1) to ensure consistent unsigned arithmetic when
performing bitwise operations. This eliminates mixed signed/unsigned operand
violations in:

- CANCEL_FLAG_NONCANCELABLE
- CANCEL_FLAG_CANCEL_ASYNC
- CANCEL_FLAG_CANCEL_PENDING

The changes affect cancellation point entry/exit logic, cancellation state
management, and cancellation type handling across both kernel and libc
implementations.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2026-02-02 21:09:40 +08:00
hujun5 2ec1bff4e3 lib_stackchk.c: a duplicate implementation error reported during compilation
Mark __stack_chk_guard and __stack_chk_fail as weak symbols to prevent linker
conflicts when multiple definitions of these stack protection symbols exist
across different compilation units.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-02-02 13:22:07 +08:00
hujun5 a3da45e1dc libc/tls: update preprocessor condition comment to match implementation
Update the closing preprocessor comment in tls_getinfo.c to accurately reflect
the simplified conditional compilation check. The comment now correctly represents
the actual guard condition used for the tls_get_info function implementation.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-31 02:49:10 +08:00
hujun5 71b7493a86 tls_getinfo.c: tls_get_info needs to be compiled in most cases.
Build Documentation / build-html (push) Has been cancelled
Simplify the compilation condition for tls_get_info() by removing the
CONFIG_TLS_ALIGNED check and adding an undef directive to ensure the function
is available in most cases rather than being limited to kernel or non-aligned TLS builds.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-30 20:13:28 +08:00
yukangzhi 31b0d79b44 libs/crc: implement AUTOSAR-compatible CRC algorithm
This patch adds an AUTOSAR-style CRC library used by E2E functionality.
It introduces multiple CRC variants (CRC8, CRC16, CRC32, CRC64) and the
corresponding public headers and implementation files.

Key changes:
- Public headers: `include/nuttx/crc8.h`, `include/nuttx/crc16.h`,
  `include/nuttx/crc32.h`, `include/nuttx/crc64.h` with new APIs for
  specific polynomial variants and incremental (part) helpers.
- Implementations added under `libs/libc/misc/` for several polynomials:
  - `lib_crc16h1021.c` (CRC-16 CCITT-FALSE)
  - `lib_crc16h8005.c`
  - `lib_crc32h04c11db7.c`
  - `lib_crc32hf4acfb13.c`
  - `lib_crc64emac.c`
  - `lib_crc8h1d.c`
  - `lib_crc8h2f.c`
- Build files updated to include the new sources.

This addition provides low-level CRC primitives required by higher-level
protocols and test suites.

Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
2026-01-30 17:32:15 +08:00
hujun5 a89b7f7add clock: remove 64-bit perf support for 32-bit systems
Remove atomic64-based 64-bit perf counter support for 32-bit systems
where atomic64 operations are unavailable, simplifying userspace perf
implementation to avoid unsupported atomic operations.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-26 21:14:38 +08:00
Yanfeng Liu 8f0e30b07c libc/perf: userspace PMU access
Add ARCH_HAVE_PERF_EVENTS_USER_ACCESS capability to allow applications
to directly access hardware perf counters via perf_gettime() from
userspace, enabling performance monitoring and profiling without syscalls.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2026-01-26 21:14:38 +08:00
anjiahao fea492cf6f libc/spawn:support get/set priority
support get/set priority

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-01-26 21:01:01 +08:00
hujun5 6e8ae12ef1 pthread: make PTHREAD_MUTEX_DEFAULT_UNSAFE default true
Change the default pthread mutex robustness from ROBUST to UNSAFE when
CONFIG_PTHREAD_MUTEX_BOTH is enabled. This reflects the practical default
and allows removal of tracking code for non-robust mutexes, improving
performance and reducing memory overhead.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-26 20:56:12 +08:00
hujun5 082a3d3085 pthread: remove tl_lock
This lock is currently used in three places,
mainly to protect tls->tl_mhead. Among them,
pthread_mutex_add and pthread_mutex_remove involve
writing to tls->tl_mhead, and there is
certainly no conflict within the same thread.
As for pthread_mutex_inconsistent, it involves reading. Currently,
it can only be called when the TCB task corresponding to
this tls exits, and the TCB corresponding to the
tls can no longer continue to run.
It seems that adding the lock serves no real purpose.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-26 20:56:12 +08:00
hujun5 217e685beb pthread: move pthread_cond to userspace
Move pthread condition variable implementation from kernel (sched/pthread)
to userspace library (libs/libc/pthread). This allows userspace to handle
condition variable operations directly, reducing syscall overhead and
improving performance for pthread applications.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-26 16:26:39 +08:00
yukangzhi 8cdf58d124 libs/libc/regex: remove logically dead code in regcomp.c
This change removes redundant and unreachable checks of `status != REG_OK`
that were reported by static code scanning. Two occurrences were fixed in
`libs/libc/regex/regcomp.c`

Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
2026-01-24 19:28:56 +08:00
yukangzhi 1b22f8c65b driver/note: Fix compilation error when CONFIG_SYSLOG_TO_SCHED_NOTE=y
Add compilation condition for 'nx_vsyslog' syscall.
Export 'sched_note_printf_ip' syscall when CONFIG_SYSLOG_TO_SCHED_NOTE=y
Put the implementation of sched_note_printf_ip in libc/misc/lib_note.c

Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
2026-01-23 07:48:08 -03:00
hujun5 5f92db54a6 sched: fix regression from PR #18040 by adding NULL pointer safety
Replace DEBUGASSERT checks with proper NULL pointer validation in getpid() and
task_get_info() functions. Return IDLE_PROCESS_ID or -ESRCH on NULL conditions
instead of asserting, improving robustness during early system startup and error conditions.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-23 16:59:55 +08:00
hujun5 5051721298 sched/pthread: move pthread mutex from syscall to user-space
Move pthread mutex operations from kernel-space syscall
interface to user-space implementations
to reduce syscall overhead. Relocate mutex holder list
tracking from task control block (tcb) to
thread local storage (tls) to improve memory layout and
cache efficiency. Add helper macros for
conditional mutex implementations and update syscall
interface accordingly.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-22 12:40:49 -03:00
wangzhi16 abe70c37a2 libc/shmfs: Ensure uniqueness of memfd.
Use mktemp to create unique path for memfd, so other thread can't find file by path.

If don't do this, error will ocurr in this case:

thread 1:                             thread2:
open() -- refs = 1
					open() -- refs = 2
					unlink()
unlink()

thread1 and thread2 will map one buffer by using file path but not fd or address of buffer.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
2026-01-22 22:11:17 +08:00
fangxinyong d38078b778 libs/libc: posix_spawnattr_init zero-initialize attr
Zero-initialize posix_spawnattr_t in posix_spawnattr_init().
Prevent use of uninitialized fields reported by Coverity.
Preserve existing default flag initialization.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2026-01-21 20:31:35 +08:00
hujun5 66f9ced0cb arch: default enable TLS_ALIGNED when BUILD_PROTECTED=y
Change TLS_ALIGNED default configuration to enable when either BUILD_KERNEL
or BUILD_PROTECTED is selected. Protected mode requires stack alignment to
properly handle TLS data structure at stack base.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-21 00:20:13 +08:00
liwenxiang1 2645e06c86 arch/x86_64: Add gprof
add gprof tool

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
2026-01-20 22:43:38 +08:00
hujun5 8bb6758490 sched: move process ID from kernel to TLS for faster access
Add pid field to task_info_s and move getpid() implementation to user
space TLS access. Remove getpid from syscall interface as it now returns
cached PID from thread local storage instead of kernel lookup.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-20 22:33:45 +08:00
xuxin19 6fa3031d9b cmake(feat):define elf option and enable apps module build
1.define elf option setting function ext;
2.unify loadable elf and kernel elf build config

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19 b7582b8da1 cmake(feat):implements KERNEL mode in CMake build
1.add application link dependencies for all elf
2.add a global custom target to hold proptry in the toolchain file
3.add startup obj target
4.fix cpp lds error with kernel mod link elf lds

usage:
./build.sh qemu-armv7a:knsh --cmake
elf install in ${CMAKE_BINARY_DIR}/bin

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
wangchengdong faf864b04f sched/signal: Add support for disabling all signal functions
Signals in NuttX serve two primary purposes:

      1. Synchronization and wake-up:
        Signals can be used to block threads on specific signal sets and later
        wake them up by delivering the corresponding signals to those threads.

      2. Asynchronous notification:
        Signals can also be used to install callback handlers for specific signals, allowing threads to
        asynchronously invoke those handlers when the signals are delivered.

    This change introduces the ability to  disable all signal functionality to reduce footprint for NuttX.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2026-01-18 08:24:13 -03:00
wangchengdong 0ea686bc5b sched/signal: Add support for partially disabling signals
Signals in NuttX serve two primary purposes:

    1. Synchronization and wake-up:
    Signals can be used to block threads on specific signal sets and later
    wake them up by delivering the corresponding signals to those threads.

    2. Asynchronous notification:
    Signals can also be used to install callback handlers for specific signals, allowing threads to
    asynchronously invoke those handlers when the signals are delivered.

This change introduces the ability to partially disable signal functionality: to disable only signal functions for
Asynchronous notification, keeping functions for Synchronization and wake-up.
This enables finer-grained control over signal usage while preserving existing behavior for supported use cases.

Co-authored-by: Guo Shichao guoshichao@xiaomi.com
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2026-01-18 08:24:13 -03:00
hujun5 acc833b07d libs/libc: replace critical section with spinlock in hostname operations
Replace global enter_critical_section() with lightweight spinlock in
gethostname() and sethostname() to reduce interrupt latency while protecting
access to the shared hostname string.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-17 14:13:07 +08:00
hujun5 2a08860a08 arch/arm64: fix backtrace register access and gdbstub config guard
Fix arm64_backtrace to access TCB register context directly instead of using
running_regs(), which may not reflect the actual context being backtraced.
Add CONFIG_ARCH_HAVE_DEBUG guard to prevent undefined references in non-debug builds.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-16 08:55:47 -03:00
hujun5 f3f9b7ecae libs/libc/gdbstub: fix smpcall called in irq context
Replace synchronous nxsched_smp_call with asynchronous nxsched_smp_call_async
in gdb debugpoint operations to prevent deadlocks when called from IRQ handlers.
Use static smp_call_data_s for async communication between SMP cores safely.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-16 08:55:47 -03:00
guoshichao b945c7b505 limits: add _POSIX_PTHREAD_ constant for pthread management
Add three POSIX‑required pthread‑related constants to limits.h:
- _POSIX_THREAD_DESTRUCTOR_ITERATIONS
- _POSIX_THREAD_KEYS_MAX
- _POSIX_THREAD_THREADS_MAX

These constants are needed for full POSIX pthread compatibility and are
required by certain PSE52 test suites and applications.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 16:15:35 +08:00
guoshichao ab572fe1cf lib_ulimit: fix the variable uninit coverity issue
Build Documentation / build-html (push) Has been cancelled
Initialize the rlim_max field in the rlp structure when handling
UL_SETFSIZE command in ulimit(), resolving an uninitialized variable
warning from Coverity static analysis.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 10:03:53 +08:00
guoshichao 71889ff22e ulimit: add ulimit implementation
implement the ulimit() based on getrlimit/setrlimit function.
the ulimit() function is requiredd by vsx testset

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 10:03:53 +08:00
guoshichao ba63a4d234 ghs: fix the UsageFault:INVSTATE error triggered by exception_common
when we build with greenhills compiler, if the exception_common function
is put into a separate section: ".text.exception_common", then the
address of exception_common function is an even number, for example "0x16a6c",
in this case, it will trigger the UsageFaults:INVSTATE error.
The reason for this error is that in the GHS compiler, a section declared
through the ".section" directive must specify at least the "a" attribute.
Otherwise, this section will not be linked into the final file, and this
is why the address of exception_common function is invalid.
The following is the official explanation in the GHS compiler documentation:
"The reason for this error is that in the GHS compiler, a section
declared through the .section directive must specify at least the "a"
attribute. Otherwise, this section will not be linked into the final
file. The following is the official explanation in the documentation:
"Sections that are intended be part of the final linked output should
have at least the `a` attribute"
and for GHS compiler, the .text section is recommended specify the
attribute of `ax`.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 09:41:13 +08:00
daichuan c7386775a7 libc/netdb: avoid unnecessary DNS notify if nameserver exists
If the nameserver already exists, return directly without calling dns_notify_nameserver to prevent cyclic notifications and high CPU usage.

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-15 16:20:44 -03:00
guoshichao 117c28990a fpathconf: add _POSIX_PRIO_IO defintion
fix the /tset/rt.os/files/fpathconf/T.fpathconf{1}:
_POSIX_ASYNC_IO is not defined

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-15 16:10:51 -03:00
tengshuangshuang 9335f7f7e6 fpathcof: _PC_PRIO_IO value of -1 means that unsupported
pse52 test error:fpathconf failed, errno = 38 (ENOSYS)

Signed-off-by: tengshuangshuang <tengshuangshuang@xiaomi.com>
2026-01-15 16:10:51 -03:00
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
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
Build Documentation / build-html (push) Has been cancelled
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
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