Commit Graph

676 Commits

Author SHA1 Message Date
Xiang Xiao b567e09c3c mm: Restore the return type of mm_lock from bool to int
Fix the issue reported here better:
https://github.com/apache/incubator-nuttx/pull/6995

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-07 10:01:52 +01:00
Xiang Xiao 4cc13c19c6 Revert "mm: Check the function result with suitable macro."
This reverts commit 460d94729a.
2022-11-07 10:01:52 +01:00
yinshengkai 85f727f232 tools: replace INCDIR to Makefile variable
In the past, header file paths were generated by the incdir command
Now they are generated by concatenating environment variables

In this way, when executing makefile, no shell command will be executed,
it will improve the speed of executing makfile
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-11-03 19:59:55 +08:00
yinshengkai 95d9abcf58 tools: replace DEFINE script to Makefile variable
In the past, predefined macros were generated by define.sh scripts
Now they are generated by concatenating environment variables

In this way, when executing makefile, no shell command will be executed,
it will improve the speed of executing makfile

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-11-03 19:59:55 +08:00
ligd 8be4bca3eb kasan: fix kasan race-condition
Change-Id: I1c729b8a85422a1f4326785e5d52cb0fc60d4822
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-03 08:58:16 +08:00
wangbowen6 fccda0c08b mm_heap: add debug assert to check the alignment problem
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2022-11-01 19:21:01 +08:00
Xiang Xiao e08c296a8e Change the type of tg_joinlock, mm_lock and md_lock from sem_t to mutex_t
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-31 10:35:53 +01:00
yinshengkai 65dc1fe0fc mm: add kmm/umm_memdump
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-10-29 11:35:27 +08:00
dongjiuzhu1 579e47347e mm/mm_heap: define MM_MASK_BIT as significant bits mask
using MM_MASK_BIT to expand different bits of preceding field to store the
block status.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-29 00:12:02 +08:00
dongjiuzhu1 5982cafbe0 mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-29 00:12:02 +08:00
dongjiuzhu1 96d8e833ed mm/mempool: support kasan check for mempool alloc/free
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
dongjiuzhu1 30bede7940 mm/mempool: fix bug about size mismatch and binary find
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
dongjiuzhu1 5828e5bb88 mm/mempool: add new api: xx_realloc and xx_alloc_size
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
dongjiuzhu1 4e179e8a85 mm/mempool: optimize alloc/free performance
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
Jiuzhu Dong 8994c8efa2 mm/mempool: support specifying alloc and free function
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
Jiuzhu Dong a01f3beefd mm/mempool: support multiple memory pool
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-10-28 21:31:35 +08:00
anjiahao e1ca516488 use SEM_INITIALIZER inside of NXSEM_INITIALIZER
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
anjiahao 5724c6b2e4 sem:remove sem default protocl
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
Xiang Xiao b9a4bedc7f fs/procfs: Change FS_PROCFS_EXCLUDE_xxx default value to DEFAULT_SMALL
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-18 15:10:26 +09:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
Fotis Panagiotopoulos c22c07ba29 Minor fix in UBSan. 2022-10-13 17:06:10 +02:00
Fotis Panagiotopoulos eec7f5da00 Fixed undefined behavior in UBSan. 2022-10-13 01:40:32 +08:00
Xiang Xiao 8a265e274d Kconfig: Remove EXPERIMENTAL for features which is been around a long time
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-19 11:39:22 -03:00
chao an afaaa780eb mm/ubsan: UBSan option should be turned on if SIM_UBSAN enabled
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-19 18:36:39 +08:00
Xiang Xiao 5253861e7e mm: Fix minor style issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-16 15:24:49 +09:00
ligd a1c9598fff kasan: use init value to avoid kasan used before bss clear
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-09-10 10:31:16 +08:00
xiangdong6 460d94729a mm: Check the function result with suitable macro.
The return value of function mm_takesemaphore will never below
than zero, DEBUGVERIFY make no effect to check it, use DEBUGASSERT
instead.

Signed-off-by: xiangdong6 <xiangdong6@xiaomi.com>
2022-09-05 21:11:01 +08:00
Huang Qi 274c085c4a UBSan: Minor typo fix to align with other place
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-09-02 19:07:09 +08:00
Huang Qi 32a21a1b67 UBSan: Allow custom the sanitizer in Kconfig
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-09-02 19:07:09 +08:00
Masayuki Ishikawa fb0cb6f270 mm: umm_heap: Do not register Umem if CONFIG_BUILD_KERNEL=y
Summary:
- In the case of CONFIG_BUILD_KERNEL=y, showing Kmem and Page
  info is enough for free command

Impact:
- CONFIG_BUILD_KERNEL=y only

Testing:
- Tested with sabre-6quad:netknsh

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-09-01 23:25:53 +02:00
Fotis Panagiotopoulos 484bdc54d3 Fixed warnings in various prints. 2022-08-30 22:53:01 +08:00
Michael Jung 1ad066955f Avoid assertion violation in case of kmm_free(NULL)
It is ok to call kmm_free with a NULL pointer.  Thus adopt the
DEBUGASSERT statement to cover this case.

Signed-off-by: Michael Jung <michael.jung@secore.ly>
2022-08-26 20:47:05 +08:00
Xiang Xiao 130b196876 Refine how to specify iob and ramlog data section
1.Remove the default value(.bss)
2.Remove !ARCH_SIM dependence

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-25 14:05:17 +02:00
Xiang Xiao f1355680ca mm/kasan: Add MM_KASAN_ALL option
so the user could disable the full image instrumentation,
but enable the instrumentation by files or directories.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-23 17:50:52 +02:00
Huang Qi 559f831005 sim: Enable ubsan in sim:kasan
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-23 17:51:20 +08:00
Huang Qi a06ec54cd0 debug: Introduce portion of UBSan
without UBSan
```
 text    data     bss     dec     hex filename
  85612     208  142258  228078   37aee nuttx
```

with UBSan:
```
   text    data     bss     dec     hex filename
 194290   98164  208634  501088   7a560 nuttx
```

```c
int main(int argc, FAR char *argv[])
{
  uint32_t ptr[32];
  printf("Hello, World!! %lu\n", ptr[64]);
  return 0;
}
```
Try to run this sample:
```
nsh> hello
ubsan_prologue: ================================================================================
ubsan_prologue: UBSAN: array-index-out-of-bounds in hello_main.c:39:37
__ubsan_handle_out_of_bounds: index 64 is out of range for type 'uint32_t [32]'
ubsan_epilogue: ================================================================================
Hello, World!! 1070182368
nsh>
```

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-22 13:57:29 +08:00
Xiang Xiao ba9486de4a iob: Remove iob_user_e enum and related code
since it is impossible to track producer and consumer
correctly if TCP/IP stack pass IOB directly to netdev

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-15 08:41:20 +03:00
luojun1 bee9dcc73a Add Kconfig option, user can specify the location of g_iob_buffer
Signed-off-by: luojun1 <luojun1@xiaomi.com>
2022-08-14 21:00:28 +08:00
luojun1 4e62772be5 modify iob to support header padding and alignment features
Signed-off-by: luojun1 <luojun1@xiaomi.com>
2022-08-14 21:00:28 +08:00
Jiuzhu Dong c18b5602e8 fs/procfs: add mempool info to proc/mempool
server> cat /proc/mempool
                   total    bsize    nused    nfree   nifree  nwaiter
       hello:        400       20       17        3        0        0

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 15:38:57 +08:00
Jiuzhu Dong e3bbbfe4d0 mm/mempool: support memory buffer pool
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 15:38:57 +08:00
chao.an 27c888854d mm_heap/kasan: poison free node after return back the heap list
The free node is still in use after kasan_poison(), the node member
access will cause the assert report by kasan.

|  (gdb) bt
|  #0  kasan_report (addr=1743265406637584896, size=140737337053680, is_write=46) at kasan/kasan.c:97
|  #1  0x0000555555607bdd in __asan_loadN_noabort (addr=140737272831420, size=4) at kasan/kasan.c:289
|  #2  0x0000555555607cd7 in __asan_load4_noabort (addr=140737272831420) at kasan/kasan.c:323
|  #3  0x00005555556061ef in gmtime_r (timep=0x7ffff3275dbc, result=0x7ffff3275e10) at time/lib_gmtimer.c:301
|  #4  0x000055555560e507 in sim_rtc_rdtime (lower=0x55555576b780 <g_sim_rtc>, rtctime=0x7ffff3275e10) at sim/up_rtc.c:77
|  #5  0x00005555555fcbdb in up_rtc_gettime (tp=0x7ffff3275ef0) at timers/arch_rtc.c:128
|  #6  0x00005555555f08b4 in clock_systime_timespec (ts=0x7ffff3275ef0) at clock/clock_systime_timespec.c:72
|  #7  0x00005555555ecc77 in note_common (tcb=0x7ffff31d2180, note=0x7ffff3275f80, length=21 '\025', type=18 '\022') at sched/sched_note.c:144
|  #8  0x00005555555ed706 in sched_note_syscall_enter (nr=1, argc=0) at sched/sched_note.c:765
|  #9  0x000055555560eb37 in __wrap_getpid () at wraps/WRAP_getpid.c:26
|  #10 0x0000555555608d1c in mm_takesemaphore (heap=0x7ffff30ae000) at mm_heap/mm_sem.c:127
|  #11 0x0000555555609477 in mm_free (heap=0x7ffff30ae000, mem=0x7ffff3265b80) at mm_heap/mm_free.c:89
|  #12 0x00005555556070c5 in free (mem=0x7ffff3265b80) at umm_heap/umm_free.c:49
|  #13 0x000055555560c3b0 in up_release_stack (dtcb=0x7ffff31e4b00, ttype=0 '\000') at sim/up_releasestack.c:67
|  #14 0x00005555555f2515 in nxsched_release_tcb (tcb=0x7ffff31e4b00, ttype=0 '\000') at sched/sched_releasetcb.c:134
|  #15 0x00005555556bdf0c in nxtask_terminate (pid=4, nonblocking=true) at task/task_terminate.c:184
|  #16 0x00005555556bdb0f in nxtask_exit () at task/task_exit.c:168
|  #17 0x000055555566e05f in up_exit (status=0) at sim/up_exit.c:64
|  #18 0x000055555564f454 in _exit (status=0) at task/exit.c:78
|  #19 0x000055555560ea89 in __wrap__exit (parm1=0) at wraps/WRAP__exit.c:27
|  #20 0x00005555555eb288 in exit (status=0) at stdlib/lib_exit.c:54
|  #21 0x00005555555fe2cc in nxtask_startup (entrypt=0x555555670c34 <critmon_start_main>, argc=1, argv=0x7ffff3265bb0) at sched/task_startup.c:70
|  #22 0x00005555555f02a0 in nxtask_start () at task/task_start.c:134
|  #23 0x0000000000000000 in ?? ()

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-02 01:45:08 +08:00
chao.an 5db0ab1e6a mm_heap/backtrace: move MM_ADD_BACKTRACE out of heap lock
move MM_ADD_BACKTRACE out of heap lock to improve the performance

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-02 01:44:48 +08:00
chao.an 87cb224b1c mm/kasan: node header should updated from unpoisoning memory
| (gdb) bt
| #0  up_assert (filename=0x7fffffffdc6c "\001", lineno=0) at sim/up_assert.c:75
| #1  0x00005555555e636b in _assert (filename=0x555555627225 "kasan/kasan.c", linenum=104) at assert/lib_assert.c:36
| #2  0x00005555555a388e in kasan_report (addr=140737284458088, size=1, is_write=true) at kasan/kasan.c:104
| #3  0x00005555555a40a1 in __asan_storeN_noabort (addr=140737284458088, size=1) at kasan/kasan.c:297
| #4  0x00005555555a4519 in __asan_store1_noabort (addr=140737284458088) at kasan/kasan.c:348
| #5  0x00005555555a26d7 in memset (s=0x7ffff3d8c668, c=0, n=63) at string/lib_memset.c:169
| #6  0x00005555555a46a4 in mm_addregion (heap=0x7ffff3d8c000, heapstart=0x7ffff3d8c648, heapsize=66058656) at mm_heap/mm_initialize.c:131
| #7  0x00005555555a4a00 in mm_initialize (name=0x555555627068 "Umem", heapstart=0x7ffff3d8c648, heapsize=67107256) at mm_heap/mm_initialize.c:231
| #8  0x00005555555a33b1 in umm_initialize (heap_start=0x7ffff3d8c000, heap_size=67108864) at umm_heap/umm_initialize.c:84
| #9  0x000055555558f17c in nx_start () at init/nx_start.c:469
| #10 0x0000555555589559 in main (argc=1, argv=0x7fffffffdf58, envp=0x7fffffffdf68) at sim/up_head.c:131
| (gdb)

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-02 01:44:48 +08:00
Xiang Xiao c26bb35843 Remove the private NULL, TRUE and FALSE macros
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-31 22:12:57 +03:00
Jiuzhu Dong 9899dd0ec0 mm/mm_heap: change CONFIG_MM_BACKTRACE to int type
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-26 23:45:31 +08:00
Jiuzhu Dong 8a1e985e71 mm/mm_heap: output memory info about each task
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-26 23:45:31 +08:00
Jiuzhu Dong 6e1244c274 mm/circbuf: add circ_peekat to read data with specified postion
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-25 13:35:26 +08:00
Jiuzhu Dong a853c70093 mm/circbuf: add circbuf_is_init to indicate circbuf state
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-07-25 13:35:26 +08:00
Fotis Panagiotopoulos 66f49c1f3c mm: Fixed the usage of CONFIG_MM_BACKTRACE & CONFIG_DEBUG_MM. 2022-07-22 00:53:02 +08:00
Gustavo Henrique Nihei ea0f60cc24 mm: Convert DEBUGASSERT(false) into more intuitive DEBUGPANIC()
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-07-14 12:08:45 +08:00
Xiang Xiao 53c6789bef mm: Add mm_uninitialize to release the resource
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-12 19:41:14 +09:00
Gustavo Henrique Nihei 183da24fc5 mm: Log name of the Heap to which the new region is being added
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-06-08 01:10:10 +08:00
Abdelatif Guettouche 4896623be2 build: Fix dependencies of kernel targets.
Targets build during the kernel phase did not have their dependencies
specified and thus they were not rebuilt after their dependencies have
changed, for example by changing options in menuconfig.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2022-05-24 10:45:39 +08:00
YAMAMOTO Takashi 5edf5e5585 mm: Add CONFIG_MM_PANIC_ON_FAILURE option
While allocation failure here is not necessarily abnormal enough to
warrant a panic in general, it can be useful in certain situations.
2022-05-21 14:28:41 +08:00
YAMAMOTO Takashi b05320cac2 mm: Move backtrace stuff into a separate option
The functionality has too much overhead for CONFIG_DEBUG_MM.
2022-05-21 14:28:41 +08:00
YAMAMOTO Takashi c546c0b647 mm: Do not abort on allocation failue with CONFIG_DEBUG_MM
When allocation failed, it isn't too uncommon for the caller
to fall back to other allocation method.
(eg. esp32 textheap code tries iram heap when an allocation from rtc heap
failed.)
DEBUGASSERT(false) is too much in that case.

This commit removes the DEBUGASSERT, and also makes the heap dump
a separate option.
2022-05-21 14:28:41 +08:00
Xiang Xiao 1fb8c13e5e Replace nxsem_timedwait_uninterruptible with nxsem_tickwait_uninterruptible
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-15 13:55:58 +03:00
Xiang Xiao 9072eecc30 sched/wqueue: Change the return type of work_notifier_teardown to void
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-14 00:35:29 +03:00
wangbowen6 d4978bfba4 mm_initialize: malloc() return aligend pointer.
malloc() should return aligned (with MM_MIN_CHUNK) pointer, but
pr #5906 destroy that, this pr find a better method to solve
these questions.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
and
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-04-11 12:46:17 +08:00
wangbowen6 1a4ccd2d70 Revert "mm_heap: heapsize align with MM_MIN_CHUNK."
This reverts commit 69e69740b5.
2022-04-11 12:46:17 +08:00
wangbowen6 69e69740b5 mm_heap: heapsize align with MM_MIN_CHUNK.
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-03-31 19:50:25 +08:00
wangbowen6 a0bde21f0f mm/mm_heap: place alloc-bit at the LSB of node->preceeding.
Heap always allocate the memory at least 2bytes alignment.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-03-31 14:43:56 +03:00
Jiuzhu Dong 2ffca6d16d mm/mm_heap: output mallinfo when malloc failed
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-03-27 13:21:48 +08:00
Jiuzhu Dong 1ab58aff55 mm/heap: add MM_BACKTRACE_DEFAULT to config backtrace record by default
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-03-27 13:21:48 +08:00
Jiuzhu Dong 709207b8d3 mm/memdump: dynamic turn on backtrace in heap when enable DEBUG_MM
default turn off.
turn on: echo on > /proc/memdump
turn off: echo off > proc/memdump

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-03-27 13:21:48 +08:00
Petro Karashchenko 68902d8732 pid_t: unify usage of special task IDs
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-03-22 21:22:32 +08:00
Xiang Xiao c2a1d0f5ae procfs: Remove mallinfo from struct procfs_meminfo_entry_s
let's call mm_mallinfo directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-17 13:59:03 -03:00
Xiang Xiao d9a442a859 mm/iob: Remove initialized static variable inside iob_initialize
since it's impossible to call iob_initialize twice

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Xiang Xiao cf2538c277 mm/shm: Initialize shm_info_s at the definition place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-12 15:06:39 -03:00
Jiuzhu Dong 018d7d605c mm/mm_malloc: dump all allocated memory info when malloc failed
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong 168074fe2e mm/memdump: fix print backtrace abnormal
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong 7ae3c572dc procfs: add heap info for every task
cat /proc/2/heap
AllocSize:  512
AllocBlks:  10

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong 2dcc4a359d mm/dump: add pid and backtrace for every memory node
usage:
echo <pid/used/free> trace > /proc/memdump
echo used > /proc/memdump //output all used memory info with backtrace
echo free > /proc/memdump //output all free memory info
echo 22 > /proc/memdump //output used memory info for task pid is 22 with backtrace

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong c5ba9261bc procfs: add memdump interface to dump used/free memory info
usage:echo <used/free> > /proc/memdump
echo used > /proc/memdump // output all used memory node info(address + size)
echo free > /proc/memdump // output all free memory node info(address + size)

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
Jiuzhu Dong 39eaeefb78 mm/mm_heap: remove the unnecessary check for memory node size
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-26 14:32:42 +08:00
ligd 419bc2fd04 mm: handle take mm sem in IRQ
This is a fix of:
0169a51220
This is caused by wrong memory sem operation in IDLE.

Fix:
Obey the original design, don't check the IDLE in mm_takesemaphore()

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-02-21 23:41:06 +08:00
Xiang Xiao 1d1bdd85a3 Remove the double blank line from source files
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-20 20:10:14 +01:00
Oki Minabe 484eb1795b fix #if condition of g_mmheap for BUILD_KERNEL. 2022-02-19 19:33:15 +08:00
Oki Minabe 979124928c fix array index range checking of gat[] in gran_alloc(). 2022-02-18 11:44:32 +08:00
chao.an 0b18cfbd9a mm/iob: add support of alloc with timeout iob_timedalloc()
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-02-17 11:55:29 -03:00
Masayuki Ishikawa 41d62033a0 mm: umm_heap: Fix umm_heap for BUILD_KERNEL & ADDRENV
Summary:
- I noticed that the user heap is corrupted
- This commit fixes this issue by reverting the change to
  the NuttX-9.0.0

Impact:
- None

Testing:
- sabre6-quad:netknsh (not merged yet)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
Co-authored-by: Oki Minabe <minabe.oki@gmail.com>
2022-02-17 11:31:01 +01:00
ligd 0169a51220 mm: handle take mm sem in IRQ
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-02-16 09:53:42 -03:00
Jiuzhu Dong 12b256f860 mm/mm_mallinfo: using mm_foreach to do mm_mallinfo
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-13 03:20:31 +08:00
Jiuzhu Dong b1a51a5b30 mm/mm_checkcorruption: using mm_foreach to do mm_checkcorruption
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-13 03:20:31 +08:00
Jiuzhu Dong eba0323eae mm/mm_heap: add mm_foreach to run handler for every memory node
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-02-13 03:20:31 +08:00
ligd b316611ef0 Revert "sem: remove limitation of irq context when do sem_trywait"
This reverts commit 7c547b3ebd.
2022-01-29 00:53:47 +08:00
Xiang Xiao 77792a1598 sched: Define CONFIG_SMP_NCPUS to 1 in no SMP case
to simplify the SMP related code logic

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-01-20 23:21:21 +08:00
Jiuzhu Dong 9fb130cdea mm/circbuf: add sanity check for resize
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-12-17 23:36:07 -06:00
ligd 5b369c5cec libs/lbc: remove CHAR_BIT = 16 support
For CEVA platform CHAR_BIT is 16, and will do lots of extra work
when use IPC.
We will not support this platform anymore, so remove all the b2c operations.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-12-13 11:08:28 -06:00
ligd 7c547b3ebd sem: remove limitation of irq context when do sem_trywait
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-17 02:20:08 -06:00
Chery Dan 8d799f2148 Fix IOB functions
The operations of struct iob_queue_s in qh_head & qh_tail are performed with interrupts disabled.

change iflags to flags

add header file ref
update for check
2021-11-11 08:47:03 -06:00
chenwei23 39cdd99d77 mm: Support the kernel address sanitizer
Signed-off-by: chenwei23 <chenwei23@xiaomi.com>
2021-11-02 13:32:47 -03:00
Xiang Xiao 5cb6b042aa mm/heap: Simplify the condition check in mm_realloc
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-02 13:32:47 -03:00
ligd 3615592e82 mm: fix realloc overwrite memcpy when use a new block
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-01 21:27:52 -05:00
Abdelatif Guettouche f86ceea099 mm/mm_heap/mm.h: Fix some typos.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-08-03 10:11:26 -07:00
YAMAMOTO Takashi 5b1f2dff5f iob_tryalloc: Fix throttled allocation
If threads are blocking for throttled allocation,
g_throttle_sem.semcount doesn't represent the number of
usable IOBs well.

Note: For non-throttled allocations, the g_iob_committed mechanism
is a rescue. But there is no equivalent for throttled allocations.
2021-08-02 11:25:55 -07:00
YAMAMOTO Takashi e96a870485 iob_tryalloc: Remove a wrong assertion 2021-08-02 11:25:55 -07:00
Masanari Iida b64e9050c4 mm: Fix a typo in Kconfig
This patch fixes a spelling typo in mm/Kconfig.

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
2021-07-30 01:31:01 -07:00
Xiang Xiao 007adc7736 Replace all __attribute__((section(x)) with locate_data(x)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-29 21:55:21 -03:00
YAMAMOTO Takashi 7a580ae3bc iob_trimhead: fix an integer truncation
I guess this fixes https://github.com/apache/incubator-nuttx/issues/4181
2021-07-20 14:20:29 +08:00
mage1 def007e2d7 add #undef for some libc function
since it's useful to redirect these functions to others
sometime(e.g. validate the memory before write).

Change-Id: I6253a9231af8809e8362f4bc5a1bd67fb094c3b0
2021-07-14 15:09:58 -03:00
Xiang Xiao 5fe51b923a mm: Simplify the semaphore handling
1.Move all special process to mm_takesemaphore
2.Remove the support of recurive lock
3.Remove mm_trysemaphore function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie216a6294ab67c5d427f31b089beb15c532f08fe
2021-07-10 16:10:32 -03:00
Xiang Xiao 76cdd5c329 mm: Remove mm_heap_impl_s struct
it's more simple to make mm_heap_s opaque outside of mm

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I5c8e435f6baba6d22b10c5f7e8d9191104fb5af2
2021-07-07 04:25:15 -07:00
chao.an ebf89ff63b mm/iob: add iob_get_queue_size() helper
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-07-05 06:20:52 -05:00
Xiang Xiao 75bfa4584c mm: Add kmm_malloc_size and mm_malloc_size
make malloc_size implementation align with malloc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I8d7781925f06e58a880437a16569dccbfd2ea035
2021-07-05 14:23:24 +09:00
Xiang Xiao ddaa3e42b9 mm: Move the real implementation of mm_sbrk to sbrk
and remove mm_sbrk and kmm_sbrk since it's wrong to expose
sbrk to other heaps except the default userspace heap.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-05 08:02:08 +09:00
Xiang Xiao 7b20a0d789 mm: Call memalign in malloc if ARCH_ADDRENV and BUILD_KERNEL are defined
to reuse the sbrk logic inside memalign

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-05 07:39:23 +09:00
Xiang Xiao 97216c220b mm: Support malloc_size function
and rename malloc_usable_size to malloc_size

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-04 18:53:44 -03:00
ligd 6685df498f mm: don't do mm_checkcorruption in IRQ
because this not safe in SMP mode

Change-Id: Ifaf49818c51ee4283f0e280ae3e4e23cbd0dba08
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-03 12:56:40 -05:00
ligd 68d66148ad mm: idle check heap use mm_trysemaphore
Change-Id: I92e1df572fa6cd801b10e5b06e7b04d450b3e3fb
Signed-off-by: ligd <liguiding1@xiaomi.com>
(cherry picked from commit bc9a5d1ca9656f6effd3a419cc2488586dfb1489)
2021-07-03 12:56:40 -05:00
Xiang Xiao b1f711f790 mm: Move procfs_register_meminfo into common place
to avoid the code duplication and ensure the consistent behaviour

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-03 09:39:32 -07:00
ligd aa43a0215d mm: fix memory corruption when loop create/exit thread in SMP mode
Root casue:
when do thread exit, need add free stack operation to mm_delaylist,
but in SMP mode, CPU0 thread1 exit, at this time, CPU1 call malloc
and free mm_delaylist.

Fix:
Divide mm_delaylist for per CPU in SMP mode.

Change-Id: Ibf7d04614ea2f99fb5b506356b7346a0d94f0590
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-07-02 04:55:46 -05:00
Xiang Xiao 187538c0b9 Move aligned_alloc, posix_memalign and valloc from mm/umm to libs/libc/stdlib
since the similar functions(e.g. strdup/strndup) put into libs/libc/string

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ifb2c0c51298b09014748e5ee8275db51213d6911
2021-07-01 11:44:38 -07:00
YAMAMOTO Takashi 314237588e Add iob_tailroom
I plan to use this for tcp.
2021-06-30 06:40:13 -05:00
YAMAMOTO Takashi 7599ca4e95 Kconfig: mention that IOB_NCHAINS is not used by TCP anymore 2021-06-30 06:40:13 -05:00
chao.an 2c51c29768 mm/iob: add an interface to support dequeue an iob from the queue
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-06-10 10:45:30 -05:00
Xiang Xiao 5b2a17b892 Include assert.h in necessary place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-08 13:06:08 -07:00
Xiang Xiao 2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Alin Jerpelea 3744eb8b5f mm: update licenses to Apache
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-05-27 08:07:25 +09:00
Jiuzhu Dong fea1da2f53 cmd/free: add nused/nfree field in command free
Change-Id: I74aa4b1e7394a17c3b117322a4cc24aa52aac3b8
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-05-25 01:01:38 -07:00
David Sidrane 85f0bc591e mm:initialize ensure alignment.
Broken by 635cfa.

   On an stm32 the heap is formed from
   const uintptr_t g_idle_topstack = HEAP_BASE;
   where HEAP_BASE is &_bss + CONFIG_IDLE_STACKSIZE.

   Both these values are not deterministic. One
   comes from the compiler, the other the system
   configurator.

   a 3 byte bss and 250 byte stack would lead to
   and unaligned address used as the heap to be.

   The compiler used clever `strd r1,r3,[r5,#8]` to
   store 2 values in one memory cycle into the
   heap_impl struct. Resulting in a hardfault.

   Change the amount of bss or the CONFIG_IDLE_STACKSIZE
   could lead to a non-functional NuttX system.
2021-05-19 21:25:08 -05:00
Brennan Ashton 3cdc0b7332 libc: Add additional checks to malloc realloc and memalign 2021-04-04 18:58:04 -07:00
Xiang Xiao 5f3a98b5a8 libc/assert: Reference the expression in all case
to avoid the warning "defined but not used"

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I55b7c092d0f2e5882fc1784987657c10cdf2d90b
2021-04-03 21:00:41 +01:00
Masayuki Ishikawa f99f590751 mm: mm_heap: Remove critical section in mm_sem.c
Summary:
- This commit removes critical section in mm_sem.c which was
  added to stabilize the NuttX SMP kernel in Mar 2018.

Impact:
- SMP only

Testing:
- Tested with ostest with the following configs
 - maix-bit:smp (QEMU), esp32-devkitc:smp (QEMU)
 - sabre-6quad:smp (QEMU), spresense:smp, sim:smp
- Tested with nxplayer with the following configs
 - spresense:wifi_smp, spresense:rndis_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-31 22:43:23 -05:00
ligd 29cdf66e1a mm/mm_heap: fix compile failed when open DEBUG_MM
Change-Id: Id21e9619e4800ec9f02f818ec86d80cdd99d9aae
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-03-30 01:14:37 -05:00
Xiang Xiao e14c458747 mm/heap: Move semaphore related declaration to private header
since other subsystem doesn't need call these function anymore

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Idfb217c412db62d9f17f427310b75bb78785dc50
2021-03-22 15:35:32 +01:00
Xiang Xiao 473bacd7a2 mm/heap: Add FAR to the pointer type
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-03-21 10:11:43 +01:00
Xiang Xiao 10e3d28372 mm/heap: Change nxsem_init to _SEM_INIT
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I84ad710c3ebe92d31d6c8dc1ddf6b63c10494ce2
2021-03-21 10:11:43 +01:00
mage1 874ecbe2f3 mm: add kconfig option to control the memory manger strategy choice.
since will will porvide more the one  strategy in future.

Change-Id: I73b900c6571f9b71b8239dd72006bdd0a68ee64d
2021-03-19 09:56:39 -07:00
mage1 635cfadc25 mm: Move mm_heap_s related stuff to private header file
since it will improve the modularity and reduce the inforamtion explosion

Change-Id: I085b36adb38993a979625a1f4c252d364a15afa1
2021-03-19 09:56:39 -07:00
YAMAMOTO Takashi f8d56b9da2 iob_trimhead.c: Fix a comment typo 2021-03-16 02:07:34 -07:00
YAMAMOTO Takashi 6b9d2fef00 mm/iob/Kconfig: Fix a typo (other other -> other) 2021-03-16 02:07:34 -07:00
Gustavo Henrique Nihei 330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
ligd 1d66d5c297 debug tools: add heap & stack check in idle thread
N/A

Change-Id: Iba6f5cdffb1336697096c71fca86c9ece584225f
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-03-04 18:38:05 -08:00
Jiuzhu Dong fecc68d1bb mm/umm_heap: move memory-related api from libc/stdlib to umm
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-02-26 11:47:11 -08:00
Jiuzhu Dong 355956fb57 umm_heap/valloc: support valloc (LEGACY)
Reference:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/valloc.html

Change-Id: Ieb425a77b0a8d758956996d201223a0050ae4920
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-02-26 11:47:11 -08:00
Gustavo Henrique Nihei 76acb32e29 Fix typos reported by codespell 2021-02-25 11:31:49 -08:00
YAMAMOTO Takashi 929e438052 procfs: Use procfs_register_meminfo for "Kmem" 2021-02-12 03:16:03 -08:00
YAMAMOTO Takashi c25f4233aa procfs: Use procfs_register_meminfo for "Umem" 2021-02-12 03:16:03 -08:00
Alin Jerpelea acb8ad4c7b mm: nxstyle fixes
Nxstyle fixes to pass CI

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-09 01:21:53 -08:00
Alin Jerpelea bcee9c391c mm: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can mograte the licenses
to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-09 01:21:53 -08:00
Xiang Xiao 0defe43282 OS internal function should indicate the error by return negative value
instead to change errno value by calling set_errno

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-12-31 09:37:29 +01:00
dongjiuzhu 642718709d mm/circbuf: fix the problem of dividing by zero.
N/A

Change-Id: I78a5cae0f782bc2c09848ebda9589dc53809e089
Signed-off-by: dongjiuzhu <dongjiuzhu1@xiaomi.com>
2020-12-01 00:02:39 -06:00
Matias N 88f1cdb915 build system: add missing --obj-path to MKDEP 2020-11-28 09:59:56 -06:00
chao.an c56785bd0d style/Makefile: remove unnecessary trailing whitespace
N/A

Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-28 12:20:30 +01:00
Matias N d5b6ec450f Parallelize depend file generation 2020-11-22 09:02:59 -03:00
YAMAMOTO Takashi 8da52c82b4 mm/mm_heap/mm_malloc.c: Fix syslog format errors 2020-11-20 22:22:53 -08:00
YAMAMOTO Takashi 7f61256b32 mm/mm_heap/mm_initialize.c: Fix syslog format errors 2020-11-20 22:22:53 -08:00
dongjiuzhu 23ddeaf3be mm/circbuf: support circular buffer managerment
N/A

Change-Id: Ib1fc009b9ce3af5815920f22221fe8a7262299ef
Signed-off-by: dongjiuzhu <dongjiuzhu1@xiaomi.com>
2020-11-20 05:33:03 -08:00
Matias N 166242c171 use "export" to expose TOPDIR to all child make instead of passing it around every time 2020-09-15 21:11:33 -07:00
ligd 6b7dd62bad mm/mm_heap/mm_initialize.c: add sem lock to mm_addregion()
Change-Id: I4a72e36fcd4504c0d8e671fe2243b14764db3b35
2020-09-15 08:50:01 +09:00
Xiang Xiao 3ea8d574fe mm: Implement malloc_usable_size
defined here:
https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I5988bb28375626188312bd0a0ba3fc12db66f644
2020-08-24 03:36:44 -07:00
SPRESENSE e249a2f82f Makefile: Fix Make.dep not updated by config changes
Make.dep file should be updated by .config changed after first make.
There are 2 cases affected for this problem:

 1) Add source files by config symbol
 2) Include header files in #ifdef directive

These 2 cases may not be included in Make.dep and this may prevent the
differential build from working correctly.
2020-07-28 03:59:45 -05:00
Brennan Ashton e87617f9fa nxstyle: fixup style issues in mm_realloc.c
Signed-off-by: Brennan Ashton <bashton@brennanashton.com>
2020-06-29 14:56:26 -07:00
Brennan Ashton fcd6e1c7eb mm: Do not memcopy more than oldsize when realloc
When realloc up from a mem area to a larger one where a new node
is needed. The the larger memory region is copied from the source
this can both leak data as well as cause memory faults accesssing
invalid data.

This was first reported by Kwonsk

Signed-off-by: Brennan Ashton <bashton@brennanashton.com>
2020-06-29 14:56:26 -07:00
YAMAMOTO Takashi 875828b698 Add a missing stdlib.h -> malloc.h change for mallinfo 2020-06-15 09:06:28 -06:00
YAMAMOTO Takashi a607e6257f Include malloc.h instead of stdlib.h for mallinfo()
This change also removes the malloc.h inclusion in stdlib.h
to break the build if there are still users of mallinfo() with stdlib.h.
2020-06-15 07:21:19 -06:00
Xiang Xiao 7e5b0f81e9 build: Replace -I with INCDIR
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-24 20:20:12 +01:00
Xiang Xiao 23668a4b9b build: Remove the empty variable assignment
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-24 08:24:13 -06:00
Xiang Xiao dd61d3d9f9 build: Remve the unnecessary .gitignore
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-23 18:00:40 +01:00
Xiang Xiao 1a95cce1a3 build: Move .config check to the top Makefile
remove the workaround to handle the inexistence of .config/Make.defs

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-20 17:57:34 +01:00
Xiang Xiao 5eae32577e build: Move INCDIROPT to common place
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-18 15:02:55 -06:00
Gregory Nutt a569006fd8 sched/: Make more naming consistent
Rename various functions per the quidelines of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions

    nxsem_setprotocol -> nxsem_set_protocol
    nxsem_getprotocol -> nxsem_get_protocol
    nxsem_getvalue -> nxsem_get_value
2020-05-17 14:01:00 -03:00
Gregory Nutt 4b44b628ea Run nxstyle against all .c and .h files modified by this PR.
All complaints fixed except for those that were not possible to fix:

- Used of Mixed case identifier in ESP32 files.  These are references to Expressif ROM functions which are outside of the scope of NuttX.
2020-05-09 14:19:08 -03:00
Gregory Nutt a4218e2144 include/nuttx/sched.h: Make naming of all internal names consistent:
1. Add internal scheduler functions should begin with nxsched_, not sched_
2. Follow the consistent naming patter of https://cwiki.apache.org/confluence/display/NUTTX/Naming+of+OS+Internal+Functions
2020-05-09 14:19:08 -03:00
Xiang Xiao d9d2fc0d0a debug: Reduce CONFIG_CPP_HAVE_VARARGS usage
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-05 08:27:58 -06:00
Xiang Xiao a2f657e4cb build: Move KDEFINE to a common place(tools/Config.mk)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-01 15:56:55 -06:00
Xiang Xiao f2aba8d9b7 build: Remove 'u' prefix from userspace library
so user needn't link the different library because the build type change

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-01 15:56:55 -06:00
Xiang Xiao f8a809eb5b Fix nxstyle issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-01 10:43:47 -03:00
Xiang Xiao eca7059785 Refine __KERNEL__ and CONFIG_BUILD_xxx usage in the code base
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-05-01 10:43:47 -03:00
Xiang Xiao ddda00ea65 Kconfig: Refine BUILD_FLAT, BUILD_PROTECTED and BUILD_KERNEL usage
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-04-29 12:16:18 -06:00
Gregory Nutt fd38623aac mm/iob/iob_clone.c: Correct newline character
Another place where /n is used where \n was intended.
2020-04-29 18:11:00 +01:00
Masayuki Ishikawa ad9db974cb mm: Fix heap corruption in protected build
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-04-22 13:45:56 +08:00
Masayuki Ishikawa 12ff2212f5 mm: mm_heap: Fix deadlock in mm_trysemaphore in SMP mode
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-04-13 12:06:07 +08:00
Gregory Nutt 67ec3d7926 Remove CONFIG_CAN_PASS_STRUCT
This commit resolves issue #620:

Remove CONFIG_CAN_PASS_STRUCTS #620

The configuration option CONFIG_CAN_PASS_STRUCTS was added many years ago to support an old version of the SDCC compiler. That compiler is currently used only with the Z80 and Z180 targets. The limitation of that old compiler was that it could not pass structures or unions as either inputs or outputs. For example:

    #ifdef CONFIG_CAN_PASS_STRUCTS
    struct mallinfo mallinfo(void);
    #else
    int      mallinfo(FAR struct mallinfo *info);
    #endif

And even leads to violation of a few POSIX interfaces like:

    #ifdef CONFIG_CAN_PASS_STRUCTS
    int  sigqueue(int pid, int signo, union sigval value);
    #else
    int  sigqueue(int pid, int signo, FAR void *sival_ptr);
    #endif

This breaks the 1st INVIOLABLES rule:

Strict POSIX compliance
-----------------------

  o Strict conformance to the portable standard OS interface as defined at
    OpenGroup.org.
  o A deeply embedded system requires some special support.  Special
    support must be minimized.
  o The portable interface must never be compromised only for the sake of
    expediency.
  o Expediency or even improved performance are not justifications for
   violation of the strict POSIX interface

Also, it appears that the current SDCC compilers have resolve this issue and so, perhaps, this is no longer a problem: z88dk/z88dk#1132

NOTE:  This commit cannot pass the PR checks because it depends on matching changes to the apps/ directory.
2020-04-11 21:19:47 +01:00
liuhaitao 459ad99373 Use EXTRAFLAGS instead of EXTRADEFINES to be used by make via command line
So call 'make EXTRAFLAGS=-Wno-cpp' could suppress the warnings with pre-processor
directive #warning in GCC.

Change-Id: Iaa618238924c9969bf91db22117b39e6d2fc9bb6
Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
2020-04-11 08:31:08 -06:00
ligd ef360394c7 mm/mm_heap: fix mm_heap not support BUILD_FLAT
1. change ifdef __KERNEL__ to:
   if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)

2. change mm_delaylist to *mm_delaylist

3. change FAR struct mm_delaynode_s *new to:
   FAR struct mm_delaynode_s *tmp

4. should check mm_trysemaphore() return values

Change-Id: I57ba991f13c3eaf56dc2d71ac946c11669e32dfa
Signed-off-by: ligd <liguiding@fishsemi.com>
2020-04-10 07:49:32 -06:00
ligd cbf31bca5c global change: fix tools/checkpatch.sh warnnings
Change-Id: I88cfa979c44bcaf3a8f6e036c6bfccd3402ca85a
Signed-off-by: ligd <liguiding@fishsemi.com>
2020-04-09 10:29:28 -06:00
ligd 1d2396353e mm/mm_heap: add mm_delaylist to mm_heap_s struct
Change-Id: I2ffaec5557bf2dd2021baa6cda84bb5318425caa
Signed-off-by: ligd <liguiding@fishsemi.com>
2020-04-09 10:29:28 -06:00
ligd 78eb9f73dd mm/mm_heap/mm_sem.c: add getpid() return check in mm_trysemaphore()
Change-Id: Ifd56e3ccc22cf0a50f52e643b7a87aab0d0dca06
Signed-off-by: ligd <liguiding@fishsemi.com>
2020-04-09 10:29:28 -06:00
Gregory Nutt 156963a903 Check return from nxsem_wait_initialize()
Resolution of Issue 619 will require multiple steps, this part of the first step in that resolution:  Every call to nxsem_wait_uninterruptible() must handle the return value from nxsem_wait_uninterruptible properly.  This commit is only for those files under fs/tmpfs and fs/spiffs.  Still do do:  The rest of fs/ and all of drivers/ and arch/.
2020-03-29 22:11:13 +01:00
Gregory Nutt 97339e47f1 Check return from nxsem_wait_initialize()
Resolution of Issue 619 will require multiple steps, this part of the first step in that resolution:  Every call to nxsem_wait_uninterruptible() must handle the return value from nxsem_wait_uninterruptible properly.  This commit is only for those files under graphics/, mm/, net/, sched/, wireless/bluetooth.

Still to do:  Files under fs/, drivers/, and arch.  The last is 116 files and will take some effort.
2020-03-29 20:11:10 +01:00
Gregory Nutt 5c0e8e88b1 Revert "Makefile: move INCDIROPT to common place (#625)"
This reverts commit b9ace36fcc.

This change was added by PR 625 but has a serious logic flaw.  It removes all occurrences of INCDIROPT and replaces it with a definition in tools/Config.mk:

    else ifeq ($(WINTOOL),y)
      DEFINE = "$(TOPDIR)/tools/define.sh"
      INCDIR = "$(TOPDIR)/tools/incdir.sh" -w

This logic flaw is the Config.mk is included in all Make.defs files BEFORE WINTOOL is defined.  As a result, the definition is wrong in many places when building under Cygwin with a Windows native toolchain.
2020-03-26 08:50:29 -07:00
Xiang Xiao b9ace36fcc
Makefile: move INCDIROPT to common place (#625) 2020-03-26 08:09:59 -06:00
Nathan Hartman a5e643b0cd Fix typos in comments and documentation. 2020-03-16 20:01:11 -06:00
Андрей Заболотный a4e0b23f4f Prevents NuttX crashing if MM_REGIONS is too small.
Added a DEBUGASSERT and a runtime check so that mm_region will not overwrite critical heap data if user incorrectly defines MM_REGIONS.
2020-03-06 10:00:44 -06:00
Gregory Nutt d1a8a803e4 Build system: Get rid of the MOVEOBJ definition
Eliminate the MOVEOBJ definition from tools/Config.mk, Makefiles, and other locations.  The MOVEOBJ definition was used to work around the case where the object output of a compile or assemble is in a different directory than the source file.  The ZDS-II tools have no command line option to perform this move; MOVEOBJ handled the move as a post-compiler operation.

MOVEOBJ is no longer needed because this the ez80 COMPILE and ASSEMBLE definitions now handle all of the object file movement cases.
2020-02-24 22:37:28 +01:00
Xiang Xiao cde88cabcc Run codespell -w with the latest dictonary again
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-02-23 22:27:46 +01:00
Gregory Nutt 2ec59121fb Fix non C89 noncompliant code that was causing the ZDS-II compile to fail. 2020-02-19 23:09:10 +01:00
Juha Niskanen ea72d84c4d /mm/mm_heap/mm_mallinfo.c: Fix assertion broken in 312ea9f9. 2020-02-17 08:06:46 -06:00
Ouss4 312ea9f99e mm/mm_heap: Fix warnings included by #266 2020-02-15 08:00:06 -06:00
YAMAMOTO Takashi 46ad645efc mm: Add a bunch of assertions 2020-02-13 08:21:18 -06:00
Gregory Nutt 1382ea5447 mm/: Coding style clean-up
Run tools/nxstyle against all C files under mm/ and correct coding standard violations.
2020-02-13 15:16:53 +01:00
YAMAMOTO Takashi 3a1515b473 mm_mallinfo: Fix a minfo printf-format 2020-02-13 15:18:53 +08:00
YAMAMOTO Takashi 710da6022d Fix comment typos 2020-02-12 20:39:47 -06:00
YAMAMOTO Takashi 23b30f7930 Fix typos in comments 2020-02-12 12:17:07 +01:00
YAMAMOTO Takashi e2ce8d5169 Fix a typo in Kconfig description 2020-02-12 12:01:18 +08:00
YAMAMOTO Takashi 342b56ae8b Revert "A workaround for macOS linker"
Unnecessary after "sim: Add -fno-common to KERNEL ARCHCPUFLAGS"

This reverts commit cc90d586c0.
2020-02-05 00:36:58 -08:00
Xiang Xiao adbff7de81 tools/Config.mk: add DEFINE macro like INCDIR 2020-02-03 15:06:11 -06:00
Xiang Xiao 5c80b94820 Replace #include <semaphore.h> to #include <nuttx/semaphore.h>
Since the kernel side should call nxsem_xxx instead and remove the unused inclusion
2020-02-01 08:27:30 -06:00
Oki Minabe 95dc647c3c mm/umm_heap/: Handle size zero in umm_malloc.c and umm_realloc.c, which causes a system freeze in kernel mode. 2020-02-01 14:03:28 +00:00
Xiang Xiao 80277d1630
Refine the preprocessor conditional guard style (#190) 2020-01-31 19:07:39 +01:00
Xiang Xiao 68951e8d72 Remove exra whitespace from files (#189)
* Remove multiple newlines at the end of files
* Remove the whitespace from the end of lines
2020-01-31 09:24:49 -06:00
minabeoki 1600980a82 fix gran_alloc() miss allocation in mm_granalloc.c. 2020-01-30 12:22:23 -03:00
YAMAMOTO Takashi cc90d586c0 A workaround for macOS linker
It seems that "ld -r" on macOS doesn't include objects from
libraries for common symbols. Because of that, sim build
ends up with undefined references to globals like g_binfmts
and g_mmheap.

	@(#)PROGRAM:ld  PROJECT:ld64-530
	BUILD 18:57:17 Dec 13 2019
	configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
	LTO support using: LLVM version 11.0.0, (clang-1100.0.33.17) (static support for 23, runtime is 23)
	TAPI support using: Apple TAPI version 11.0.0 (tapi-1100.0.11)
2020-01-29 09:03:48 +01:00
chao.an c3ba541bd2 Author: Gregory Nutt <gnutt@nuttx.org>
mm/Makefile:  Same change should be applied to mm/Makefile since the mm/ build is identical to the libc/ build.
        libs/libnx/Makefile:  Same change should be applied to libnx/Makefile since the mm/ build is identical to the libc/ build.

    Author: chao.an <anchao@xiaomi.com>

        libs/libc/Makefile:  Correct the dependents path
2020-01-21 08:02:23 -06:00
chao.an a4aa8ae491 wqueue/notifier: update the work notifier usage
usage changed after commit 90c52e6f8f

Change-Id: Ifb0d739b046a6794b5b3ac177f489fb9a1c5c799
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-01-21 14:16:19 +08:00
Xiang Xiao 346336bb9e Make the read ahead buffer unselectable
Here is the email loop talk about why it is better to remove the option:
https://groups.google.com/forum/#!topic/nuttx/AaNkS7oU6R0

Change-Id: Ib66c037752149ad4b2787ef447f966c77aa12aad
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-01-11 08:24:49 -06:00
Xiang Xiao 6a3c2aded6 Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
2020-01-02 10:54:43 -06:00
Xiang Xiao c5a7da5b7a mm/iob/Kconfig: Make the default of IOB_NCHAINS same as IOB_NBUFFERS. It is reasonable default value since iob_qentry_s is much small than iob_s and could avoid the buffer can be allocated but the chain can't: 'tcp_datahandler: ERROR: Failed to queue the I/O buffer chain: -12' 2019-11-24 10:43:45 -06:00
Nathan Hartman 366053e464 Fix typos, 1 in a #define, others in comments. This changes one definition: _MQ_TIMEDRECIEVE is changed to _MQ_TIMEDRECEIVE. It appears this symbol is not used anywhere. 2019-09-11 08:56:56 -06:00
Gregory Nutt dd2219c1db mm/iob/iob_statistics.c: Fix an error found in build testing. Must include nuttx/mm/iob.h. 2019-08-19 11:50:52 -06:00
Anthony Merlino 70404ed0dc Merged in antmerlino/nuttx/iobinstrumentation (pull request #1001)
Iobinstrumentation

* mm/iob: Introduces producer/consumer id to every iob call. This is so that the calls can be instrumented to monitor the IOB resources.

* iob instrumentation - Merges producer/consumer enumeration for simpler IOB user.

* fs/procfs: Starts adding support for /proc/iobinfo

* fs/procfs: Finishes first pass of simple IOB user stastics and /proc/iobinfo entry

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2019-08-16 22:42:25 +00:00
Nathan Hartman 68d43d3679 Fix typos. 2019-08-04 14:50:28 -06:00
Gregory Nutt 2dae0ef0db mm/mm_heap/mm_sem.c: Fix error that occurs when CONFIG_CPP_HAVE_VARARGS is not defined. In that case, the arguments to the debug macro will all be evaluated even though they are not used any variables that are references must at least be defined. 2019-06-03 09:02:55 -06:00
Gregory Nutt b21c12bd18 Fix errors found in build testing:
arch/mips/src:  Previous commit used CP0 register definitions that were not defined in the cp0.h header file.  Probably these were from the Microchip hacked up GCC toolchain but are not generally available.  Fix:  Add definitions to NuttX cp0.h header file.

mm/iob:  Eliminate some warnings about testing the value of an undefined pre-processor variable.
2019-05-25 11:45:22 -06:00
anchao bb8648e7a0 ibs/libc/Makefile, libs/libnx/Makefile, and mm/Makefile: Remove obj-path MKDEPS option since make dependency target (MT) is not supported by some toolchains. 2019-03-19 10:14:50 -06:00
Gregory Nutt 419c4cb6be A little more progress toward the implementation of per-window framebuffers. Still missing:
- Logic that generates the low lever framebuffer renderers for the per-window framebuffers,
- The logic that picks off the per-window framebuffer updates from normal graphics device updates.  This logic must update both the per-window framebuffer and the graphics device (from the framebuffer).

Squashed commit of the following:

    graphics:  Add logic to allocate the per-window framebuffer.

    graphics:  A few fragmentary thoughts on how a per-window framebuffer could be represented and allocated.
2019-03-14 11:20:14 -06:00
Gregory Nutt a2e62f557d Squashed commit of the following:
sched/init/nx_bringup.c:  Fix a naming collision.
    sched/init:  Rename os_start() to nx_start()
    sched/init:  Rename os_smp* to nx_smp*
    sched/init:  Rename os_bringup to nx_bringup
    sched/init:  rename all internal static functions to begin with nx_ vs os_
2019-02-04 16:20:35 -06:00
Gregory Nutt 90e4cf4349 mm/umm_heap: sbrk() is only available in the KERNEL build. 2019-02-04 10:32:31 -06:00
Xiang Xiao fe421022e2 sched/wqueue/kwork_notifier.c and several Kconfig files: Notifier should work with either lpwork or hpwork and other minor typo fix. 2019-01-27 11:02:56 -06:00
Xiang Xiao b6606e61b4 mm/iob/iob_copyin.c: iob_copyin() should wait for each buffer and adjust the return value of iob_copyin_internal return to simplify the code 2019-01-26 10:48:47 -06:00
Xiang Xiao 2671709e62 mm/umm_heap: Ensure all user allocation try sbrk before fail 2019-01-26 10:42:36 -06:00
Xiang Xiao 3047ef80dc mm/mm_gran/mm_graninfo.c: Fix the wrong data in g_1bit_info and make the internal function static 2019-01-26 10:30:50 -06:00
Xiang Xiao 7d813fb6d3 mm/mm_gran/mm_pgalloc.c: mm/pgalloc: shouldn't just allocate one page always. 2019-01-26 10:21:58 -06:00
Xiang Xiao 5a37ac25a9 mm/shm/shm_initialize.c: Remove some unused, #ifdef'ed out code. 2019-01-26 10:17:21 -06:00
Xiang Xiao fb4ab391f6 mm/shm/shmget.c: Should call shm_extend to allocate the physical memory 2019-01-26 10:14:42 -06:00
Xiang Xiao b5e2754d2d mm/shm: Convert bytes to pages by MM_NPAGES instead of MM_PGALIGNUP 2019-01-26 10:11:06 -06:00
Xiang Xiao 1ecc33b7db mm/iob: Miscellaneous changes and fixes from code review. 2019-01-26 09:56:27 -06:00
Xiang Xiao 0354702525 mm/iob/iob_dump.c: Format the whole line before log to avoid the multiple timestamp prefix in each line 2019-01-26 09:44:58 -06:00
Xiang Xiao ee28417246 mm/iob/iob_notifier.c: Don't check iob_navail in iob_notifier_setup to avoid a potential race condition. 2019-01-26 09:43:54 -06:00
Xiang Xiao 4721381d1c mm/iob/iob_alloc.c: iob_allocwait should decrease semcount manually. 2019-01-26 09:24:12 -06:00
Xiang Xiao 9cef84b6ad mm/kmm_heap/kmm_kernel.c: Remove unused, duplicated kmm_heapmember(). 2019-01-26 08:48:02 -06:00
Xiang Xiao e2544b7ddf mm/umm_heap/umm_sbrk.c: Pass ARCH_HEAP_VEND as maxbreak argument 2019-01-26 07:29:23 -06:00
Xiang Xiao e15670a191 mm/mm_heap/mm_sbrk.c: Fix backward conditional test. Should call mm_initialize() when brkaddr equal zero 2019-01-26 07:07:42 -06:00
Gregory Nutt 70efabd0ad mm/mm_heap/mm_calloc.c: Verify that the number of elements times the size of an element will not overflow type size_t. This is required by the SEI CERT C coding style and resolves anonymous Bitbucket Issue #139 2019-01-07 16:13:48 -06:00
Gregory Nutt 40cdc187bb mm/mm_heap/mm_sem.c and sched/task/task_getpid.c: Commits 43d37c866b and f37202cbc0 resolved some problems with the original fix of 91aa26774b. However, Those changes used an internal OS interface (sched_self()) which is not available when the the user-space memory manager is built in the PROTECTED or KERNEL builds and resulted in build failures.
This commit repartitions the logic by moving some of the changes from mm_sem.c into task_getpid.c.  The logic is equivalent for the case of mm_trysemaphore(), but no has wider impact since it potentially affects all callers of getpid().  Hence, this change may also introduce some other issues that will need to be addressed.
2018-12-30 08:41:06 -06:00
Gregory Nutt 86224f9b7e Improve some comments. 2018-12-27 09:32:47 -06:00
David Sidrane 43d37c866b mm/mm_heap/mm_sem.c: Defer freeing if mm is held by a not running task. When the holder is running we can add a holder count. If there is no holder OR it is not running we want to try to take the semaphore. There will not be a count if the task is the holder and not running because it already holds the count. This will result it the deferred free. We will take it when not held and do the free when we can get the count because there was no holder. 2018-12-20 13:39:06 -06:00
Gregory Nutt f37202cbc0 This is a candidate replacement for the reverted change 91aa26774b
This change adds a check to mm_trysemaphore() (the root implementation of both kmm_trysemaphore() and umm_trysemaphore()).  It checks if the that task that is apparently executing is marked as RUNNING.  If not, how could the non-running task be trying to get the MM semaphore?  I think only in the exact scenario that Eunbong Song has described.

So I think the solution should provide the same protection as 91aa26774b but without the horrific consequences to memory usage.
2018-12-20 10:19:52 -06:00
Petteri Aimonen fe0532c226 Merged in paimonen/nuttx/pullreq_libc_libnx_updates (pull request #757)
Pullreq libc libnx updates

* NuttX: make strerror() return 'Success' for 0

* NuttX: fix strrchr() so that it considers null terminator as part of string

    From strrchr(3) man page:
    "The terminating null byte is considered part of the string, so that if c
    is specified as '\0', these functions return a pointer to the terminator."

* NuttX: mm_free(): Add DEBUGASSERT()'s to catch memory corruption early.

    It's easier to find the source when asserts fail already when freeing
    an overflowed buffer, than if the corruption is only detected on next
    malloc().

* MM_FILL_ALLOCATIONS: Add debug option to fill all mallocs()

    This is helpful for detecting uninitialized variables,
    especially in C++ code. I seem to be forgetting to initialize
    member variables and then they just get random values..

* NuttX: nxtk_bitmapwindow: Fix warning message when bitmap is fully off-screen.

* nxfonts_getfont: Avoid unnecessary warnings for other whitespace chars also.

* NuttX: Fix kerning of 'I' in Sans17x22 font

    The I character was running together with some other
    characters, e.g. in sequence "IMI".

* NXMU: Revalidate window pointer for mouse events.

    NXMU caches the previous window pointer so that further mouse
    events can be sent to the same window. However, if the window
    is destroyed while mouse button is held down, the pointer may
    become invalid and cause a crash. This patch revalidates the
    pointer before using it.

Approved-by: GregoryN <gnutt@nuttx.org>
2018-11-12 15:36:35 +00:00
Gregory Nutt dec7ecbd56 net/tcp/tcp_recvwindow.c: In order to receive data we must not only have IOBs available, but we must also have at least one IOB chain qentry available. Otherwise, we will advertise that we an buffer a lot of data when, in fact, we cannot. This is an expermental fix to a performance problem noted by Masayuki Ishikawa. 2018-09-22 09:33:29 -06:00
Gregory Nutt 22da175629 mm/iob: Add a divider that can be used to reduce the rate of IOB notifications. 2018-09-13 06:56:29 -06:00
Gregory Nutt 76eec53e4f mm/iob: iob_navail() was returning the number of free IOB chain queue entries, not the number of free IOBs. Completely misnamed. 2018-09-12 06:40:18 -06:00
Gregory Nutt 11a635dcb3 mm/iob: IOB free notifier should accept the work queue ID as a paramter. The notification may need to run on either the high- or low- priority work queue. sched/work: Change the default priority of the low-priority work queue to 100. 2018-09-11 08:49:39 -06:00
Gregory Nutt af0ee3c8f7 sched/wqueue: Add an option to work queue notifier so that the notification can occur on different work queues. 2018-09-11 07:22:23 -06:00
Gregory Nutt 39df7ed0c0 mm/iob and sched/semaphore: Work around some issues with the IOB throttle semaphore. It has some odd behaviors that can cause assertions in sem_post(). Also, it seems to get outside of its range occasionally. Need to REVISIT this. 2018-09-10 11:32:09 -06:00
Gregory Nutt 9d3148406c Signals were not a good choice of IPC to implement the poll function for several reasons: In order to handle the asynchrnous poll-related event, a substantial amount of state information is needed. Signals are only capable of passing minimal amounts of data. There are also complexities with performing kernel space signal handlers in kernel space code that is better to avoid. So, instead of signals, the equivalent logic was converted to run via a callback that executes on the high-priority work queue.
Squashed commit of the following:

    Fix up some final compile isses.

    net/netdev:  Convert the network down notification logic to use the new wqueue-based notification factility.

    net/udp:  Convert the UDP readahead notification logic to use the new wqueue-based notification factility.

    net/tcp:  Convert the TCP readahead notification logic to use the new wqueue-based notification factility.

    mm/iob:  Convert the IOB notification logic to use the new wqueue-based notification factility.

    sched/wqueue:  Signals are not good IPCs to support the target poll functionality for several reasons including the amount of data that can be passed with a signal and in the fact that in protected and kernel modes, user threads executing signal handlers in protected, kernel memory is problematic.  Instead, convert the same logic to perform the notifications via function callback on the high priority work queue.
2018-09-09 15:01:44 -06:00
Gregory Nutt 32e3e51678 net/netdev: Add signal notification for the case where the network goes down. 2018-09-09 10:39:25 -06:00