Re: k_thread_user_mode_enter() usage


Boie, Andrew P
 

Andy,

Can you take a look at this? Seems to be rooted in the privileged stack mechanism..

-----Original Message-----
From: Vakul Garg [mailto:vakul.garg@nxp.com]
Sent: Tuesday, March 20, 2018 11:26 PM
To: Boie, Andrew P <andrew.p.boie@intel.com>; zephyr-users@lists.zephyrproject.org
Cc: Andy Gross <andy.gross@linaro.org>
Subject: RE: k_thread_user_mode_enter() usage
Importance: High

Hi Andrew

I am using nxp frdm_k64f (has cortex M4 core).
In my application, I have a printf() at beginning. This is causing bus fault.
Replacing it with an infinite while(1) loop hides the bus fault but stack check still remains.

Further I tried running zephyr/tests/kernel/mem_protect/userspace.
It passes successfully.

However if I introduce a printf() in function userspace/src/main.c: umode_enter_func() under the condition when is_user_context is true, it also crashes.
But here it is different exception !!

***** USAGE FAULT *****
Executing thread ID (thread): 0x200002ec
Faulting instruction address: 0x61a0
Attempt to execute undefined instruction Caught system error -- reason 0

Further decoding faulting instruction address 0x61a0 using 'addr2line' takes me to userspace/build/frdm_k64f/zephyr/priv_stacks_hash.gperf:32
The given line number is inside following function (at the location where variable map is being dereferenced to get priv_stack_addr).

u8_t *_k_priv_stack_find(void *obj)
{
const struct _k_priv_stack_map *map =
_k_priv_stack_map_lookup((const char *)obj, sizeof(void *));
return map->priv_stack_addr;
}

I tried increasing MAIN/PREVILEDGED stack sizes in project config, but result is same.

Regards

Vakul

-----Original Message-----
From: Boie, Andrew P [mailto:andrew.p.boie@intel.com]
Sent: Tuesday, March 20, 2018 8:16 PM
To: Vakul Garg <vakul.garg@nxp.com>; zephyr-
users@lists.zephyrproject.org
Cc: Andy Gross <andy.gross@linaro.org>
Subject: RE: k_thread_user_mode_enter() usage

It looks like you are getting two exceptions in a row.
Were you able to determine the source of the bus fault? That seems
like the real issue.
What platform is this on?

Andrew

-----Original Message-----
From: zephyr-users-bounces@lists.zephyrproject.org
[mailto:zephyr-users- bounces@lists.zephyrproject.org] On Behalf Of
Vakul Garg
Sent: Tuesday, March 20, 2018 3:57 AM
To: zephyr-users@lists.zephyrproject.org
Subject: [Zephyr-users] k_thread_user_mode_enter() usage

Hi

I want my application auto-launched at zephyr startup to drop its
privileges to become user mode app.
So I moved my applications entry point to app_main() and invoked it
from k_thread_user_mode_enter(app_main, NULL, NULL, NULL) from
function void main().

Now, before app_main() could get called, I get following error:

***** BUS FAULT *****
Executing thread ID (thread): 0x20002eec
Faulting instruction address: 0x12da
Precise data bus error
Address: 0x20011208
Fatal fault in thread 0x20002eec! Aborting.
***** Stack Check Fail! *****
Current thread ID = 0x20002eec
Faulting instruction address = 0x2a290

I checked that the stack sentinel check is failing in function
_check_stack_sentinel().

Can someone advise what I am doing wrong?

Regards

Vakul

_______________________________________________
Zephyr-users mailing list
Zephyr-users@lists.zephyrproject.org
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flis
t
s.zephyrproject.org%2Fmailman%2Flistinfo%2Fzephyr-
users&data=02%7C01%7Cvakul.garg%40nxp.com%7Cee6448f50f03472d438
908d58e7162a5%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63
6571540048549904&sdata=7%2B4eiwFRT0gglTQxGjYUNbVXu1PEoF9cp4tgK
FaIg70%3D&reserved=0

Join users@lists.zephyrproject.org to automatically receive all group messages.