Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: assert only normal thread takes a mutex #1671

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/arch/arm/include/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ vaddr_t thread_stack_start(void);
/* Returns the stack size for the current thread */
size_t thread_stack_size(void);

bool thread_is_in_normal_mode(void);

/*
* Returns true if previous exeception also was in abort mode.
*
Expand Down
1 change: 1 addition & 0 deletions core/arch/arm/kernel/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static void __mutex_lock(struct mutex *m, const char *fname, int lineno)
{
assert_have_no_spinlock();
assert(thread_get_id_may_fail() != -1);
assert(thread_is_in_normal_mode());

while (true) {
uint32_t old_itr_status;
Expand Down
22 changes: 22 additions & 0 deletions core/arch/arm/kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,28 @@ bool thread_is_from_abort_mode(struct thread_abort_regs __maybe_unused *regs)
#endif
}

#ifdef ARM32
bool thread_is_in_normal_mode(void)
{
return (read_cpsr() & ARM32_CPSR_MODE_MASK) == ARM32_CPSR_MODE_SVC;
}
#endif

#ifdef ARM64
bool thread_is_in_normal_mode(void)
{
uint32_t exceptions = thread_mask_exceptions(THREAD_EXCP_FOREIGN_INTR);
struct thread_core_local *l = thread_get_core_local();
bool ret;

/* If any bit in l->flags is set we're handling some exception. */
ret = !l->flags;
thread_unmask_exceptions(exceptions);

return ret;
}
#endif

void thread_state_free(void)
{
struct thread_core_local *l = thread_get_core_local();
Expand Down