Commit Graph

2368 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
simbit18 c324fc1cc2 libs\libxx: Fix Make style
- Remove spaces from make file

Signed-off-by: simbit18 <simbit18@gmail.com>
2026-03-23 18:16:46 -04:00
Huang Qi e3eeaefd6d style: Fix "the the" typo across the codebase.
Fix 269 occurrences of duplicate "the" word typo found in 209 files
across source code, header files, and configuration.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-23 11:07:49 +01:00
Huang Qi 228eae22a0 libs/libbuiltin: Fix spacing style in gcov.c
Add space after 'else if' keyword to follow NuttX coding style
guidelines.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-21 19:44:54 -04: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
wangmingrong1 6301af9a44 libbuitin/compiler-rt: Solve some compilation errors
1. remove_item It needs to use the full path to exclude the file, otherwise the exclusion will fail
2. No include path was added, resulting in the header file not being found

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-02-04 02:33:36 +08:00
wangmingrong1 5f7d4ddcad compiler-rt: Upgrade to version 18.1.3
Some files need to be included in a specific arch

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-02-04 02:33:36 +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
cuiziwei 94ac6b620b libstdc++: Relocate c++config.h from include/ to libstdc++ to preserve upstream integrity
- Add c++config.h to improve libstdc++ configuration support
- Update CMakeLists.txt and libsupc++.defs to integrate the new config header
- Remove the obsolete 0001-libsupc-Add-missing-header-files.patch to clean up the codebase

These changes enhance the maintainability and portability of the C++ standard library and simplify the build process.
2026-01-27 10:35:58 +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
cuiziwei f17b82bd65 libcxx/libstdc++: Add libsupc++.defs to support libsupc++
This patch adds support for building libsupc++ (the C++ runtime
support library from GCC's libstdc++-v3).

libsupc++ provides core C++ runtime support including:
- Exception handling (eh_*.cc)
- RTTI (Run-Time Type Information)
- Memory allocation operators (new/delete)
- Type info support

The implementation includes:
- libsupc++.defs for libsupc++ build integration
- support make and cmake build
- Use gthr.h, gthr-posix.h and unwind-pe.h from libgcc
- LIBSTDCXX_VERSION config option with default 14.2.0

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2026-01-24 17:33:19 +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
v-zhangxiaomeng5 c95b6b1bb6 libxx: fix __config_site for libcxx compile errors
The errors are 'No thread API' and '__ULong undefined'

Signed-off-by: v-zhangxiaomeng5 <v-zhangxiaomeng5@xiaomi.com>
2026-01-20 17:45:48 +08:00
cuiziwei 6a51857e90 libs/libxx: Add _LIBCPP_HAS_NO_CONTENTION_TABLE to reduce RAM usage
When _LIBCPP_HAS_NO_CONTENTION_TABLE is defined, libcxx will not
allocate the contention table used for semaphore implementation,
which can save significant RAM on memory-constrained embedded systems.

This optimization is particularly useful for NuttX targets where
every byte of RAM matters.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2026-01-20 01:51:12 +08:00
buxiasen f0cb80d297 libm: fix warning maybe-uninitialized
nuttx/libs/libm/openlibm/openlibm/src/k_rem_pio2.c:421:24: error: 'fq' may be used uninitialized [-Werror=maybe-uninitialized]

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-19 23:26:14 +08:00
fangxinyong 507056e870 cmake(bugfix):fix arch x86_64 cmake build openlibm warning
Building C object libs/libm/openlibm/CMakeFiles/m.dir/openlibm/src/s_clog.c.obj
In file included from /work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/src/math_private.h:22,
                 from /work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/src/s_clog.c:61:
/work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/src/s_clog.c:78:33: warning: ‘clogl’ alias between functions of incompatible types ‘_Complex long double(_Complex long double)’ and ‘_Complex double(_Complex double)’ [-Wattribute-alias=]
   78 | openlibm_strong_reference(clog, clogl);
      |                                 ^~~~~
/work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/src/cdefs-compat.h:24:50: note: in definition of macro ‘openlibm_strong_reference’
   24 |         OLM_DLLEXPORT extern __typeof (aliassym) aliassym __attribute__ ((__alias__ (#sym)));
      |                                                  ^~~~~~~~
/work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/src/s_clog.c:64:1: note: aliased declaration here
   64 | clog(double complex z)

Building C object libs/libm/openlibm/CMakeFiles/m.dir/openlibm/amd64/fenv.c.obj
In file included from /work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/include/openlibm_fenv.h:8,
                 from /work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/amd64/fenv.c:35:
/work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/include/openlibm_fenv_amd64.h:99:1: warning: declaration of ‘feclearexcept’ shadows a built-in function [-Wshadow]
   99 | feclearexcept(int __excepts)
      | ^~~~~~~~~~~~~
/work/rel-5.0/nuttx/libs/libm/openlibm/openlibm/include/openlibm_fenv_amd64.h:117:1: warning: declaration of ‘fegetexceptflag’ shadows a built-in function [-Wshadow]
  117 | fegetexceptflag(fexcept_t *__flagp, int __excepts)

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2026-01-19 23:26:14 +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
v-zhangxiaomeng5 cc1c033df2 libs/libxx: change libcxxmini to libminiabi
libcxxmini shall not stay the same layer of LIBCXX, move it down to ABI library layer.

Signed-off-by: v-zhangxiaomeng5 <v-zhangxiaomeng5@xiaomi.com>
2026-01-19 10:48:50 +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