blob: 6cf2890b73687ecf4a1920ee96b77e6e839a0fed [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
bart0268dfa2008-03-11 20:10:21 +00002
3/*--------------------------------------------------------------------*/
4/*--- Client-space code for drd. drd_gomp_intercepts.c ---*/
5/*--------------------------------------------------------------------*/
6
7/*
bart86562bd2009-02-16 19:43:56 +00008 This file is part of drd, a thread error detector.
bart0268dfa2008-03-11 20:10:21 +00009
bart86562bd2009-02-16 19:43:56 +000010 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
bart0268dfa2008-03-11 20:10:21 +000011
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
bartbedfd232009-03-26 19:07:15 +000050#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)
bart0268dfa2008-03-11 20:10:21 +000053
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{
bartbedfd232009-03-26 19:07:15 +000065 int ret;
66 int res;
67 OrigFn fn;
bart0268dfa2008-03-11 20:10:21 +000068
bartbedfd232009-03-26 19:07:15 +000069 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);
bart0268dfa2008-03-11 20:10:21 +000075}
76
77GOMP_FUNC(void, gompZubarrierZureinit, // gomp_barrier_reinit
78 gomp_barrier_t* barrier, unsigned count)
79{
bartbedfd232009-03-26 19:07:15 +000080 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);
bart0268dfa2008-03-11 20:10:21 +000089}
90
91GOMP_FUNC(void, gompZubarrierZudestroy, // gomp_barrier_destroy
92 gomp_barrier_t* barrier)
93{
bartbedfd232009-03-26 19:07:15 +000094 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);
bart0268dfa2008-03-11 20:10:21 +0000103}
104
105GOMP_FUNC(void, gompZubarrierZuwait, // gomp_barrier_wait
106 gomp_barrier_t* barrier)
107{
bartbedfd232009-03-26 19:07:15 +0000108 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);
bart0268dfa2008-03-11 20:10:21 +0000117}