From aed39dbbafc2f1cacfdce4382f22b06ab0224aae Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sun, 9 Oct 2011 12:27:35 +0000 Subject: [PATCH] Protect the move operation of buflib against IRQs. This makes accessing the buffers with core_get_data() from interrupt context safe, other buflib functions aren't really safe (yet). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30736 a1c6a512-1295-4272-9138-f99709370657 --- firmware/buflib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/firmware/buflib.c b/firmware/buflib.c index 3b4f522dcf..d82acd77d3 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c @@ -206,16 +206,26 @@ move_block(struct buflib_context* ctx, union buflib_data* block, int shift) handle, shift, shift*sizeof(union buflib_data)); new_block = block + shift; new_start = tmp->alloc + shift*sizeof(union buflib_data); + + /* disable IRQs to make accessing the buffer from interrupt context safe. */ + /* protect the move callback, as a cached global pointer might be updated + * in it. and protect "tmp->alloc = new_start" for buflib_get_data() */ + disable_irq(); /* call the callback before moving */ if (ops) { if (ops->move_callback(handle, tmp->alloc, new_start) == BUFLIB_CB_CANNOT_MOVE) + { + enable_irq(); return false; + } } + tmp->alloc = new_start; /* update handle table */ memmove(new_block, block, block->val * sizeof(union buflib_data)); + enable_irq(); return true; }