userspace: zero app memory bss earlier

Some init tasks may use some bss app memory areas and
expect them to be zeroed out. Do this much earlier
in the boot process, before any of the init tasks
run.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-02-27 17:24:46 -08:00 committed by Anas Nashif
commit 62fad96802
3 changed files with 13 additions and 5 deletions

View file

@ -185,6 +185,14 @@ extern FUNC_NORETURN void _arch_syscall_oops(void *ssf);
* @return Length of the string, not counting NULL byte, up to maxsize
*/
extern size_t z_arch_user_string_nlen(const char *s, size_t maxsize, int *err);
/**
* @brief Zero out BSS sections for application shared memory
*
* This isn't handled by any platform bss zeroing, and is called from
* _Cstart() if userspace is enabled.
*/
extern void z_app_shmem_bss_zero(void);
#endif /* CONFIG_USERSPACE */
/**

View file

@ -496,6 +496,10 @@ FUNC_NORETURN void _Cstart(void)
_current = &dummy_thread;
#endif
#ifdef CONFIG_USERSPACE
z_app_shmem_bss_zero();
#endif
/* perform basic hardware initialization */
_sys_device_do_config_level(_SYS_INIT_LEVEL_PRE_KERNEL_1);
_sys_device_do_config_level(_SYS_INIT_LEVEL_PRE_KERNEL_2);

View file

@ -737,7 +737,7 @@ out:
extern char __app_shmem_regions_start[];
extern char __app_shmem_regions_end[];
static int app_shmem_bss_zero(struct device *unused)
void z_app_shmem_bss_zero(void)
{
struct z_app_region *region, *end;
@ -747,12 +747,8 @@ static int app_shmem_bss_zero(struct device *unused)
for ( ; region < end; region++) {
(void)memset(region->bss_start, 0, region->bss_size);
}
return 0;
}
SYS_INIT(app_shmem_bss_zero, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
/*
* Default handlers if otherwise unimplemented
*/