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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>