Commit Graph

82 Commits

Author SHA1 Message Date
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
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
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
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 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 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 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
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
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
Андрей Заболотный 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
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
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
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
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
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
Xiang Xiao 86eef8ce3a mm/: add mm_heapmember function and reimplement kmm_heapmember base on mm_heapmember since this function is very useful if multiple heaps exist. 2018-08-23 09:38:49 -06:00
Masayuki Ishikawa 1d958980bd Merged in masayuki2009/nuttx.nuttx/fix_smp_bugs (pull request #615)
Fix SMP related bugs

* sched/sched: Fix a deadlock in SMP mode

    Two months ago, I introduced sched_tasklist_lock() and
    sched_tasklist_unlock() to protect tasklists in SMP mode.
    Actually, this change works pretty well for HTTP audio
    streaming aging test with lc823450-xgevk.

    However, I found a deadlock in the scheduler when I tried
    similar aging tests with DVFS autonomous mode where CPU
    clock speed changed based on cpu load. In this case, call
    sequences were as follows;

    cpu1: sched_unlock()->sched_mergepending()->sched_addreadytorun()->up_cpu_pause()
    cpu0: sched_lock()->sched_mergepending()

    To avoid this deadlock, I added sched_tasklist_unlock() when calling
    up_cpu_pause() and sched_addreadytorun(). Also, added
    sched_tasklist_lock() after the call.

    Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

* libc: Add critical section in lib_filesem.c for SMP

    To set my_pid into fs_folder atomically in SMP mode,
    critical section API must be used.

    Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

* mm: Add critical section in mm_sem.c for SMP

    To set my_pid into mm_folder atomically in SMP mode,
    critical section API must be used.

    Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

* net: Add critical section in net_lock.c for SMP

    To set my pid (me) into fs_folder atomically in SMP mode,
    critical section API must be used.

    Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2018-03-20 12:34:38 +00:00
Gregory Nutt b54ffe858a Standardization of some function headers. 2018-03-13 09:52:27 -06:00
Dmitriy Linikov a8c58607e9 Merged in hardlulz/modem-3.0-nuttx/fix-sem-EINTR (pull request #603)
Added ECANCELED condition to DEBUGASSERT-s checking sem_wait result

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2018-02-20 18:24:53 +00:00
Gregory Nutt 7cf88d7dbd Make sure that labeling is used consistently in all function headers. 2018-02-01 10:00:02 -06:00
Gregory Nutt 3521aaf944 Squashed commit of the following:
binfmt/, configs/, grahics/, libc/, mm/, net/, sched/:  OS references to the errno variable should always use the set_errno(), get_errno() macros
    arch/arm/src/stm32 and stm32f7:  Architecture-specific code is not permitted to modify the errno variable.  drivers/ and libc/:  OS references to the errno variable should always use the set_errno(), get_errno() macros
2018-01-30 17:57:36 -06:00
Gregory Nutt fb6208fbbc mm: Fix a typo in a debug assertion. 2017-11-22 07:30:48 -06:00
Gregory Nutt 514ac3fe98 mm: Add a debug assertin to check for integer overflow in malloc. 2017-11-21 07:24:10 -06:00
Jussi Kivilinna 75b53d563b mm/mm-heap: memalign: fix heap corruption caused by using unaligned chuck size. Unaligned nodes generated by memalign later cause heap corruptions when nodes are shrink further (for example, 24 bytes -> 8 bytes, when alignment is 16 bytes). 2017-10-24 15:35:52 -06:00
Gregory Nutt 34a572b226 Update last commit... Check should really use the definition MMSIZE_MAX which is really the same thing, but guaranteed to be the correct maximum size in any present and future configuration. 2017-10-17 07:34:06 -06:00
EunBong Song 196911d4fa If size is greater than (UINT32_MAX - SIZEOF_MM_ALLOCNODE), malloc size can be overflow by MM_ALIGN_UP macro. For example, if task_create() called with stack_size == -1, up_create_stack() functions allocates SIZEOF_MM_ALLOCNODE bytes for stack.
This can cause data abort in up_stack_color() function.
2017-10-17 06:37:09 -06:00
Gregory Nutt a857cc04e4 Fix some build problems after recent separation of internal OS from application interfaces. The build problem only occurs in the PROTECTED and KERNEL builds where separate libraries are built for the applications and for use within the OS. In these cases, the correct interfaces must be used. This commit fixes a few of these, so I can get through build testing, but there are many more that need fixin'. 2017-10-08 08:13:47 -06:00