summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2018-06-27 10:44:16 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-06-27 22:07:11 -0700
commit69153048757481a312c0f9f4747ed45565a30c1e (patch)
tree10c237eae0b168408d36580edafdd848bed71e58
parent18e57ccbdad61867a241a5c44f56aa0e603b63c6 (diff)
downloadchrome-ec-69153048757481a312c0f9f4747ed45565a30c1e.tar.gz
core/host: Fall back to udelay when task is invalid
When running fuzzing tests, the sanitizer library may call usleep from the main thread, and our implementation thinks that usleep is called from idle task (task_id == 0), and just waits for an event that will never arrive. Make sure the default task id is invalid, and fall back to udelay if we are in an invalid task. BRANCH=none BUG=chromium:854975 TEST=Fuzzing tests do not fail with strange errors. Change-Id: Icc3fdce30b54dfb06913a3d6cbabaa07e1266ba6 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1116623 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--core/host/task.c3
-rw-r--r--core/host/timer.c2
2 files changed, 3 insertions, 2 deletions
diff --git a/core/host/task.c b/core/host/task.c
index 7a17e13e89..500e18413d 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -54,7 +54,8 @@ static int generator_sleeping;
static timestamp_t generator_sleep_deadline;
static int has_interrupt_generator = 1;
-static __thread task_id_t my_task_id; /* thread local task id */
+/* thread local task id */
+static __thread task_id_t my_task_id = TASK_ID_INVALID;
static void task_enable_all_tasks_callback(void);
diff --git a/core/host/timer.c b/core/host/timer.c
index 1c1fe01457..b29786b007 100644
--- a/core/host/timer.c
+++ b/core/host/timer.c
@@ -39,7 +39,7 @@ static int time_set;
void usleep(unsigned us)
{
- if (!task_start_called()) {
+ if (!task_start_called() || task_get_current() == TASK_ID_INVALID) {
udelay(us);
return;
}