| 1 | /* |
| 2 | * urcu-checker.c |
| 3 | * |
| 4 | * Userspace RCU library checker |
| 5 | * |
| 6 | * Copyright (c) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #include <string.h> |
| 24 | #include <assert.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <urcu/urcu-checker.h> |
| 28 | #include <urcu/tls-compat.h> |
| 29 | |
| 30 | #define URCU_DEBUG_STACK_LEN 10 |
| 31 | |
| 32 | struct urcu_debug_entry { |
| 33 | void *ip; |
| 34 | int depth; |
| 35 | }; |
| 36 | |
| 37 | struct urcu_debug_stack { |
| 38 | struct urcu_debug_entry stack[URCU_DEBUG_STACK_LEN]; |
| 39 | int stackend; |
| 40 | }; |
| 41 | |
| 42 | static DEFINE_URCU_TLS(struct urcu_debug_stack, rcu_debug_stack); |
| 43 | |
| 44 | void rcu_read_lock_debug(void) |
| 45 | { |
| 46 | struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); |
| 47 | |
| 48 | r->stack[r->stackend++].ip = __builtin_return_address(0); |
| 49 | } |
| 50 | |
| 51 | void rcu_read_unlock_debug(void) |
| 52 | { |
| 53 | struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); |
| 54 | |
| 55 | assert(r->stackend != 0); |
| 56 | r->stack[--r->stackend].ip = NULL; |
| 57 | } |
| 58 | |
| 59 | void rcu_read_ongoing_check_debug(const char *func) |
| 60 | { |
| 61 | struct urcu_debug_stack *r = &URCU_TLS(rcu_debug_stack); |
| 62 | |
| 63 | if (r->stackend == 0) { |
| 64 | fprintf(stderr, "URCU LOCKED CHECK failure: %p\n", |
| 65 | __builtin_return_address(0)); |
| 66 | abort(); |
| 67 | } |
| 68 | } |