blob: e8c8db2f7429ee2143eca6293be399329db436a9 [file] [log] [blame]
bart0268dfa2008-03-11 20:10:21 +00001
2/*--------------------------------------------------------------------*/
3/*--- Client-space code for drd. drd_gomp_intercepts.c ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of drd, a data race detector.
8
9 Copyright (C) 2006-2008 Bart Van Assche
10 bart.vanassche@gmail.com
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
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)
53
54
55// Type definitions
56
57typedef void* gomp_barrier_t;
58
59
60// Function definitions.
61
62GOMP_FUNC(void, gompZubarrierZuinit, // gomp_barrier_init
63 gomp_barrier_t* barrier, unsigned count)
64{
65 int ret;
66 int res;
67 OrigFn fn;
68
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);
75}
76
77GOMP_FUNC(void, gompZubarrierZureinit, // gomp_barrier_reinit
78 gomp_barrier_t* barrier, unsigned count)
79{
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);
89}
90
91GOMP_FUNC(void, gompZubarrierZudestroy, // gomp_barrier_destroy
92 gomp_barrier_t* barrier)
93{
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,
100 0, 0, 0);
101 CALL_FN_W_W(ret, fn, barrier);
102 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_DESTROY,
103 barrier, gomp_barrier, 0, 0, 0);
104}
105
106GOMP_FUNC(void, gompZubarrierZuwait, // gomp_barrier_wait
107 gomp_barrier_t* barrier)
108{
109 int ret;
110 int res;
111 OrigFn fn;
112 VALGRIND_GET_ORIG_FN(fn);
113 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_BARRIER_WAIT,
114 barrier, gomp_barrier, 0, 0, 0);
115 CALL_FN_W_W(ret, fn, barrier);
116 VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_BARRIER_WAIT,
117 barrier, gomp_barrier, 1, 0, 0);
118}