Commit Graph

13597 Commits

Author SHA1 Message Date
wangjianyu3 7b5891aaf7 drivers/ioexpander: Add support for PCA9557
Datasheet: https://www.ti.com/lit/ds/symlink/pca9557.pdf

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-04-27 09:57:59 +08:00
anjiahao 38b138fa2c archivefs:support archivefs 2026-04-27 09:45:18 +08:00
Alin Jerpelea 8e7c8b6c82 fs: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2026-04-27 09:45:00 +08:00
yezhonghui 90f92a367b spinlock: add noinstrument_function to _notrace functions
Add noinstrument_function attribute to all spinlock _notrace functions
to prevent them from being instrumented when CONFIG_ARCH_INSTRUMENT_ALL
is enabled. These functions are used in the instrument callback path
and must not trigger instrumentation to avoid infinite recursion.

Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
2026-04-21 01:36:08 +08:00
yezhonghui 70c0492350 nuttx: fix sched_note api make issue with level params
Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
2026-04-21 01:36:07 +08:00
zhangyu117 3baaf08639 nuttx/atomic.h: use _Atomic define atomic_t.
1. use _atomic as wrapper because if _Atomic empty, may affects the compilation of other files:
   https://builder95.pt.miui.com/job/vela_test_task/792878/

2. for clang builtin function, it donot accept param with keyword "_Atomic"

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:36:04 +08:00
zhangyu117 2628b835b0 Revert "include/nuttx/compiler.h: add _Atomic qualifier for atomic types"
This reverts commit d2cd4e54862ab85dcabd681023895e4415020c49.

Reason for revert: use new atomic way

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:36:04 +08:00
zhangyu117 51a8e851fa Revert "nuttx/atomic.h: when clang, remove the _Atomic for semaphore."
This reverts commit ea1c54bf74fc0e4b8e3ff7c9ba4abe9f1f8d21fe.

Reason for revert:  use new atomic way

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:36:03 +08:00
yezhonghui 05ded4467d nuttx_header: add nuttx header file for dfxd
Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
2026-04-21 01:36:00 +08:00
buxiasen c0dc65b286 nuttx/atomic.h: when clang, remove the _Atomic for semaphore.
clang did not allow cast from volatile int to _Atomic int.
When we always use atomic_x API, should be the same, ignore for now.
We may revert this patch later when we change the int in semaphore.h to
atomic_t.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:58 +08:00
ligd 7176c5661a include/nuttx/compiler.h: add _Atomic qualifier for atomic types
Add atomic_t/atomic64_t typedef in compiler.h with _Atomic keyword
for C11+ environments, falls back to plain volatile for C++, pre-C11,
or platforms without atomics support.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:58 +08:00
wangmingrong1 2d4fbd91e6 kasan/unregister: Modify the logic of unpoison
1. When a region is not included in other regions, we will remove it from g_region. Unpoison is not needed afterward because mm->shadow will no longer be mapped after removal.
2. When a region is contained within other regions, we will unpoison it, The size passed in at this point is also complete. It will not be subtracted from the header of the Kasan region structure in the Kasan register.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-04-21 01:35:57 +08:00
dongjiuzhu1 691f411331 sys/socket: adjust SO_RCVTIMEO/SO_SENDTIMEO to avoid s_options overflow
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-04-21 01:35:56 +08:00
buxiasen ed798d7544 libc/misc/circbuf: add circbuf_reinit handle malloc/free not direct use.
In case the buffer is special or lock confict with memory manager,
should isolate the malloc/free API, only configure & copy.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:56 +08:00
ligd 08d8f59108 fs/procfs: fix race condition in meminfo traversal using ref counting
When Thread A is traversing the procfs meminfo linked list and gets
preempted, Thread B may exit (while in critical_section) and call
procfs_unregister_meminfo, which removes the entry and frees the
heap. When Thread A resumes and tries to access the entry's heap,
it causes a use-after-free bug.

This patch fixes the issue by:

1. Adding reference counting (refs) and a deletion flag (deleted) to
   procfs_meminfo_entry_s.

2. Using spinlock instead of mutex for list protection, since the
   unregister can happen in critical_section context.

3. Implementing a reference counting protocol:
   - Readers increment refs before accessing heap, decrement after
   - unregister sets deleted=true and removes from list
   - If refs==0 at unregister time, entry is freed immediately
   - Otherwise, the last reader (when refs becomes 0) frees the entry

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:53 +08:00
ligd 9b1b873964 fs/procfs: change procfs_register_meminfo to allocate entry dynamically
Change procfs_meminfo_entry from embedded struct to dynamically allocated
memory using kmm_zalloc/kmm_free. This prepares for adding reference
counting in subsequent patches.

Changes:
1. Update procfs_register_meminfo interface to accept individual parameters
   (name, heap, mallinfo handler, memdump handler) instead of a pre-filled
   entry struct, and return the allocated entry pointer.
2. Update procfs_unregister_meminfo to free the entry after removal.
3. Change mm_procfs field in all heap structures from embedded struct to
   pointer (struct procfs_meminfo_entry_s *mm_procfs).
4. Update all callers to use the new interface.
5. Add typedef for mm_mallinfo_handler_t and mm_memdump_handler_t.
6. Change the kmm and kumm initialize order, kmm should be intailized first
   to allow kmm_zalloc() when call kmm_initialize().

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:53 +08:00
xuxingliang 2f65beaae9 sched: move heap flags from tcb to tls
Move TCB_FLAG_HEAP_CHECK and TCB_FLAG_HEAP_DUMP from TCB flags to TLS
flags for better encapsulation and user/kernel space isolation.

Changes:
- Add tl_flags field to struct tls_info_s
- Define TLS_INFO_FLAG_HEAP_CHECK and TLS_INFO_FLAG_HEAP_DUMP macros
- Remove TCB_FLAG_HEAP_CHECK and TCB_FLAG_HEAP_DUMP from TCB flags
- Update all usage sites to use TLS API:
  * mm.h, sim_ummheap.c: Use tls_get_info() for current thread
  * mm_tlsf.c: Use tls_get_info() in memdump_backtrace
  * fs_procfsproc.c: Use nxsched_get_tls(tcb) for specific task
  * fs_procfsmeminfo.c: Use nxsched_get_tls(tcb) for heap dump control
  * irq_dispatch.c: Use tls_get_info() for interrupt heap checking

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2026-04-21 01:35:53 +08:00
ligd f8de2ae091 mm: Change mm_initialize_heap/mm_initialize_pool to return int, heap via out param
- Change mm_initialize_heap and mm_initialize_pool to return int (0 on success, <0 on error),
    and return the heap pointer via the first argument (struct mm_heap_s **heap_out).
- Update all callers to use the new interface
- This improves error handling and avoids confusion with pointer return values.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:53 +08:00
fangyibo 7f4f80cd88 nuttx/audio: add input/output dump
Signed-off-by: fangyibo <fangyibo@xiaomi.com>
2026-04-21 01:35:48 +08:00
wangchen ee10c61bf9 socket: support SO_RCVBUF and SO_SNDBUF in psock_socketlevel_option
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2026-04-21 01:35:46 +08:00
zhanghongyu 549cd8a5ff include/nuttx/net/net.h: add s_ prefix for node, list and list_tail
standardize the naming of structure members.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-04-21 01:35:46 +08:00
buxiasen 79b089ad07 gettid: debugassert if there is any tcb-> pid != tls->tid
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:43 +08:00
buxiasen 0ac474d300 gettid: use tcb->pid directly if we have to get tls from tcb
Don't have to tcb->tls->pid, will be slower.
When kernel select addrenv, tls may not able to get pid correct.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:41 +08:00
ouyangxiangzhen b19dacff64 sched/wqueue: Simplify work_timeleft.
This commit simplified work_timeleft.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2026-04-21 01:35:40 +08:00
zhangyu117 34d854ea11 nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr
Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:35:40 +08:00
zhangyu117 2f31c63d76 nuttx/atomic: use toolchain builtin atomic function
The reason for using builtin atomic is that in C++, when include <atomic> in <nuttx/atomic.h> easily conflicts with third-party function libraries. We wanted to completely separate the implementation of <nuttx/atomic.h>.

There are two points:
1. use builtin function directly.
2. Without the standard library implementation, need implement "atomic_fetch_xxx", leading conflicts with the standard library used by third-party programs, introducing redefinition issues and requiring name changes.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:35:39 +08:00
zhangyu117 82cf7c8f43 nuttx/atomic: for builtin atomic, a wrapper is used to unify the names.
1. for tasking, map __c11_atomic_xxx as tasking_atomic_xxx
2. for msvc, map  _Interlocked_xxx as msvc_atomic_xxx
3. if no special map, use gcc/clang as default as they are most widely used.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:35:39 +08:00
yangao1 8a077ede4e builtin.h:remove userspace.h to avoid circular dependency
use forward declare to prevent circular dependency

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2026-04-21 01:35:37 +08:00
dongjiuzhu1 127832d19c net: adjust the option sort of level SOL_SOCKET, to save bit of socket_conn_s:s_options
Adjust the order of all options where the level is SOL_SOCKET. If an
option occupies a bit in socket_conn_s:s_options, place it at the front.
This is to save bits for options of other levels and prevent the 32-bit
overflow of socket_conn_s:s_options.

The definition of many options for other levels uses _SO_PROTOCOL as the
base value. If _SO_PROTOCOL is relatively small, more bits will be left
for options of other levels. Before adjustment, there were 16 bits
available; after adjustment, this number has increased to 23 bits.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-04-21 01:35:36 +08:00
dongjiuzhu1 b8a3b13800 Revert "nuttx: __SO_PROTOCOL was moved from 16 to 21 to avoid conflict."
This reverts commit 86bce2a9d657c6dc7054dd82e5265d8f882b9008.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-04-21 01:35:36 +08:00
wenquan1 ca0ae45122 net/pkt: support option SO_TIMESTAMPING and MSG_ERRQUEUE
Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-04-21 01:35:35 +08:00
huojianchao 33d6f94f36 syslog compile error fix
Signed-off-by: huojianchao <huojianchao@xiaomi.com>
2026-04-21 01:35:33 +08:00
ligd 166aa65255 mutex: fix assert failed in nxrmutex_unlock()
Crash deailt:
mm_malloc()
--> nxrmutex_lock(mm_lock)
    --> nxmutex_lock()
        --> nxmutex_wait()
        --> nxmutex_add_backtrace()
            --> backtrace_record() & expend memory
                 --> mm_malloc()
                     --> nxrmutex_lock(mm_lock)
                         --> rmutex->count++
                     --> nxrmutex_unlock(mm_lock)
                         --> rmutex->count--
                         --> nxmutex_unlock() // wrong unlock here
    --> rmutex->count++
--> nxrmutex_unlock(mm_lock)
    --> Assert failed

Resolve:
move the rmutex->count++ before nxmutex_add_backtrace()

Timeseq after modify:
mm_malloc()
--> nxrmutex_lock(mm_lock)
    --> nxmutex_lock()
        --> nxmutex_wait()
    --> rmutex->count++
        --> nxmutex_add_backtrace()
            --> backtrace_record() & expend memory
                 --> mm_malloc()
                     --> nxrmutex_lock(mm_lock)
                         --> rmutex->count++
                     --> nxrmutex_unlock(mm_lock)
                         --> rmutex->count--
--> nxrmutex_unlock(mm_lock)

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:32 +08:00
yezhonghui 8de5938e6a nuttx: init note driver for mode and level
Signed-off-by: yezhonghui <yezhonghui@xiaomi.com>
2026-04-21 01:35:30 +08:00
liaoao b5204f58df signal: fix build error since _sigev_thread is defined by CONFIG_SIG_EVTHREAD
Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-04-21 01:35:25 +08:00
buxiasen 7d27b2c46e libc/sem/mutex: add LIBC_SEM_MUTEX_NOINLINE for size prefer
Add option remove all sem/mutex inline use no inline version

As a compare, in mps3-an547/nsh text size compare:
inline:   380384
noinline: 348780

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:19 +08:00
ganjing bc4124c988 (libc/pthread): rename proto to prio in pthread_mutexattr_s
Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-04-21 01:35:13 +08:00
ganjing b15cf42171 (libc/unistd): define the necessary macros for PSE52 certification testing
Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-04-21 01:35:11 +08:00
zhengyu16 3641f2a78c vfs/fs_pathcache: add pathcache framework for accelerating file open
This patch introduces a pathcache framework that caches struct file
objects to accelerate repeated file open operations. The cache uses
a hash table for O(1) lookup and LRU eviction policy for memory
management.

Key features:
- File-specific cache layer (fs_pathcache.c) for caching opened files
- Per-mountpoint cache control via "-o pathcache" options
- Automatic cache invalidation on file rename/unlink/umount
- Cache update on file close for write operations

The cache works by storing a duplicated struct file on first open,
and subsequent opens duplicate from the cached copy instead of
calling the filesystem's open function. This is particularly
beneficial for frequently accessed files on slow storage media.

Configuration options:
- CONFIG_FS_PATHCACHE: Enable pathcache
- CONFIG_FS_PATHCACHE_MAX_ENTRIES: Max cached files (default 64)
- CONFIG_FS_PATHCACHE_HASHTABLE_SIZE: Hash table size (default 32)

Currently only fatfs is supported in the allowed filesystem list.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-04-21 01:35:10 +08:00
zhengyu16 8bc754a000 libc/cache: add generic cache tools with lru
Introduce a generic LRU (Least Recently Used) cache implementation in libc/cache.
Provides cache entry management, hash table support, and LRU eviction.
API includes cache_init, cache_lookup, cache_insert, cache_remove, and more.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-04-21 01:35:10 +08:00
zhengyu16 f552100f70 hashtable.h: Add entry-based iteration macros for hash buckets
Add new macros to iterate over entries in a specific hash bucket,
which automatically apply container_of to get the containing structure.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-04-21 01:35:09 +08:00
zhengyu16 87ac2cd39c hashtable.h: add support for dynamically allocated hashtable
Previously, hashtable macros only supported statically sized arrays, relying on
sizeof(table) / sizeof((table)[0]) to calculate hashtable_size. This patch adds new macros
that accept a size parameter, enabling use of dynamically allocated hashtables.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
2026-04-21 01:35:09 +08:00
wangmingrong1 a47b97595c note/fdx: Initialize note fdx drivers directly within the array.
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-04-21 01:35:05 +08:00
wangmingrong1 7ef95a03b8 note/fdx: defconfig CONFIG_TRACE32_FDX_NOTE rename to CONFIG_DRIVERS_NOTET32FDX
Keep the driver configuration name consistent with that under driver/note

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-04-21 01:35:05 +08:00
wangmingrong1 3af1465087 note/rtt: defconfig CONFIG_NOTE_RTT rename to CONFIG_DRIVERS_NOTERTT
Keep the driver configuration name consistent with that under driver/note

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-04-21 01:35:04 +08:00
buxiasen f4a3a700f4 percpu: fix typo extra ;
should merge into one commit when pick.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-04-21 01:35:03 +08:00
hujun5 a9d5f9287e fix compile error
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-04-21 01:35:03 +08:00
hujun5 e2006b0602 gettid: inline gettid
Improved the performance of pthread lock in protected mode from 145ns to 125ns

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-04-21 01:35:03 +08:00
hujun5 1d31361856 tls: split tls.h to tls.h and tls_task.h
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-04-21 01:35:03 +08:00
zhangyu117 690a1f2282 nuttx/hwspinlock: hwspinlock should based on irq instead of spinlock_irq
Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
2026-04-21 01:35:01 +08:00