kernel: mem_domain: add/remove partition funcs to return errors

This changes both k_mem_domain_add_partition() and
k_mem_domain_remove_partition() to return errors instead of
asserting when errors are encountered. This gives the application
chance to recover.

The arch_mem_domain_parition_add()/_remove() will be modified
later together with all the other arch_mem_domain_*() changes
since the architecture code for partition addition and removal
functions usually cannot be separately changed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-11-10 11:11:00 -08:00 committed by Anas Nashif
commit bb595a85f1
9 changed files with 210 additions and 81 deletions

View file

@ -509,17 +509,29 @@ int main(void)
void main(void)
{
#ifdef CONFIG_USERSPACE
int ret;
/* Partition containing globals tagged with ZTEST_DMEM and ZTEST_BMEM
* macros. Any variables that user code may reference need to be
* placed in this partition if no other memory domain configuration
* is made.
*/
k_mem_domain_add_partition(&k_mem_domain_default,
&ztest_mem_partition);
ret = k_mem_domain_add_partition(&k_mem_domain_default,
&ztest_mem_partition);
if (ret != 0) {
PRINT("ERROR: failed to add ztest_mem_partition to mem domain (%d)\n",
ret);
k_oops();
}
#ifdef Z_MALLOC_PARTITION_EXISTS
/* Allow access to malloc() memory */
k_mem_domain_add_partition(&k_mem_domain_default,
&z_malloc_partition);
ret = k_mem_domain_add_partition(&k_mem_domain_default,
&z_malloc_partition);
if (ret != 0) {
PRINT("ERROR: failed to add z_malloc_partition to mem domain (%d)\n",
ret);
k_oops();
}
#endif
#endif /* CONFIG_USERSPACE */