bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 2 | |
| 3 | /*--------------------------------------------------------------------*/ |
| 4 | /*--- Client-space code for drd. drd_gomp_intercepts.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 8 | This file is part of drd, a thread error detector. |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 9 | |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 10 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 11 | |
| 12 | This program is free software; you can redistribute it and/or |
| 13 | modify it under the terms of the GNU General Public License as |
| 14 | published by the Free Software Foundation; either version 2 of the |
| 15 | License, or (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but |
| 18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | 02111-1307, USA. |
| 26 | |
| 27 | The GNU General Public License is contained in the file COPYING. |
| 28 | */ |
| 29 | |
| 30 | /* --------------------------------------------------------------------- |
| 31 | ALL THE CODE IN THIS FILE RUNS ON THE SIMULATED CPU. |
| 32 | |
| 33 | These functions are not called directly - they're the targets of code |
| 34 | redirection or load notifications (see pub_core_redir.h for info). |
| 35 | They're named weirdly so that the intercept code can find them when the |
| 36 | shared object is initially loaded. |
| 37 | |
| 38 | Note that this filename has the "drd_" prefix because it can appear |
| 39 | in stack traces, and the "drd_" makes it a little clearer that it |
| 40 | originates from Valgrind. |
| 41 | ------------------------------------------------------------------ */ |
| 42 | |
| 43 | #include <assert.h> |
| 44 | #include "drd_clientreq.h" |
| 45 | #include "pub_tool_redir.h" |
| 46 | |
| 47 | |
| 48 | // Defines. |
| 49 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 50 | #define GOMP_FUNC(ret_ty, f, args...) \ |
| 51 | ret_ty VG_WRAP_FUNCTION_ZZ(libgompZdsoZd1Za,f)(args); \ |
| 52 | ret_ty VG_WRAP_FUNCTION_ZZ(libgompZdsoZd1Za,f)(args) |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | // Type definitions |
| 56 | |
| 57 | typedef void* gomp_barrier_t; |
| 58 | |
| 59 | |
| 60 | // Function definitions. |
| 61 | |
| 62 | GOMP_FUNC(void, gompZubarrierZuinit, // gomp_barrier_init |
| 63 | gomp_barrier_t* barrier, unsigned count) |
| 64 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 65 | int ret; |
| 66 | int res; |
| 67 | OrigFn fn; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 68 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 69 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT, |
| 70 | barrier, gomp_barrier, count, 0, 0); |
| 71 | VALGRIND_GET_ORIG_FN(fn); |
| 72 | CALL_FN_W_WW(ret, fn, barrier, count); |
| 73 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT, |
| 74 | barrier, gomp_barrier, 0, 0, 0); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | GOMP_FUNC(void, gompZubarrierZureinit, // gomp_barrier_reinit |
| 78 | gomp_barrier_t* barrier, unsigned count) |
| 79 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 80 | int ret; |
| 81 | int res; |
| 82 | OrigFn fn; |
| 83 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_INIT, |
| 84 | barrier, gomp_barrier, count, 1, 0); |
| 85 | VALGRIND_GET_ORIG_FN(fn); |
| 86 | CALL_FN_W_WW(ret, fn, barrier, count); |
| 87 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_INIT, |
| 88 | barrier, gomp_barrier, 0, 0, 0); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | GOMP_FUNC(void, gompZubarrierZudestroy, // gomp_barrier_destroy |
| 92 | gomp_barrier_t* barrier) |
| 93 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 94 | int ret; |
| 95 | int res; |
| 96 | OrigFn fn; |
| 97 | VALGRIND_GET_ORIG_FN(fn); |
| 98 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_DESTROY, |
| 99 | barrier, gomp_barrier, 0, 0, 0); |
| 100 | CALL_FN_W_W(ret, fn, barrier); |
| 101 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY, |
| 102 | barrier, gomp_barrier, 0, 0, 0); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | GOMP_FUNC(void, gompZubarrierZuwait, // gomp_barrier_wait |
| 106 | gomp_barrier_t* barrier) |
| 107 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 108 | int ret; |
| 109 | int res; |
| 110 | OrigFn fn; |
| 111 | VALGRIND_GET_ORIG_FN(fn); |
| 112 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT, |
| 113 | barrier, gomp_barrier, 0, 0, 0); |
| 114 | CALL_FN_W_W(ret, fn, barrier); |
| 115 | VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT, |
| 116 | barrier, gomp_barrier, 1, 0, 0); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 117 | } |