Skip to content

Commit

Permalink
add a helper function to test if an object is on the stack
Browse files Browse the repository at this point in the history
lib/debugobjects.c has a function to test if an object is on the stack.
The block layer and ide needs it (they need to avoid DMA from/to stack
buffers).  This patch moves the function to include/linux/sched.h so that
everyone can use it.

lib/debugobjects.c uses current->stack but this patch uses a
task_stack_page() accessor, which is a preferable way to access the stack.

Signed-off-by: FUJITA Tomonori <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Andy Whitcroft <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
fujita authored and torvalds committed Jul 24, 2008
1 parent 68ad8df commit 8b05c7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,13 @@ static inline unsigned long *end_of_stack(struct task_struct *p)

#endif

static inline int object_is_on_stack(void *obj)
{
void *stack = task_stack_page(current);

return (obj >= stack) && (obj < (stack + THREAD_SIZE));
}

extern void thread_info_cache_init(void);

/* set thread flags in other task's structures
Expand Down
4 changes: 1 addition & 3 deletions lib/debugobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,13 @@ debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),

static void debug_object_is_on_stack(void *addr, int onstack)
{
void *stack = current->stack;
int is_on_stack;
static int limit;

if (limit > 4)
return;

is_on_stack = (addr >= stack && addr < (stack + THREAD_SIZE));

is_on_stack = object_is_on_stack(addr);
if (is_on_stack == onstack)
return;

Expand Down

0 comments on commit 8b05c7e

Please sign in to comment.