tests: mem_protect/userspace: _k_neg_eagain maybe in pinned sect

If pinned section is enabled, _k_neg_eagain should be in pinned
rodata section. So add the check if pinned section is enabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-07-15 13:53:55 -07:00 committed by Christopher Friedt
commit bb1656abc6

View file

@ -288,12 +288,24 @@ extern int _k_neg_eagain;
*/
static void test_write_kernro(void)
{
bool in_rodata;
/* Try to write to kernel RO. */
const char *const ptr = (const char *const)&_k_neg_eagain;
zassert_true(ptr < _image_rodata_end &&
ptr >= _image_rodata_start,
in_rodata = ptr < _image_rodata_end &&
ptr >= _image_rodata_start;
#ifdef CONFIG_LINKER_USE_PINNED_SECTION
if (!in_rodata) {
in_rodata = ptr < lnkr_pinned_rodata_end &&
ptr >= lnkr_pinned_rodata_start;
}
#endif
zassert_true(in_rodata,
"_k_neg_eagain is not in rodata");
set_fault(K_ERR_CPU_EXCEPTION);
_k_neg_eagain = -EINVAL;