blob: c09fb8a14c81990cdba9b16413e65f08e41447a4 [file] [log] [blame]
barte8653ac2011-03-07 18:00:26 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
2/*
3 This file is part of drd, a thread error detector.
4
5 Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307, USA.
21
22 The GNU General Public License is contained in the file COPYING.
23*/
24
bart6de4f412011-03-06 12:39:12 +000025#include <stdint.h>
26#include <stdio.h>
27#include "valgrind.h"
bartab8f93d2011-03-06 16:33:08 +000028#include "drd.h"
bart6de4f412011-03-06 12:39:12 +000029#include "pub_tool_redir.h"
30
bart6de4f412011-03-06 12:39:12 +000031/*
32 * On Mac OS X shared library functions are lazily bound. The binding mechanism
bartab8f93d2011-03-06 16:33:08 +000033 * uses self-modifying code. Intercept fastBindLazySymbol() in order to suppress
bart6de4f412011-03-06 12:39:12 +000034 * the data accesses involved in this mechanism.
35 *
36 * See also the Mac OS X ABI Dynamic Loader Reference (http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/MachOReference/Reference/reference.html#//apple_ref/c/func/dyld_stub_binding_helper).
37 * See also the dyld_stub_binder() source code (http://www.opensource.apple.com/source/dyld/dyld-132.13/src/dyld_stub_binder.s).
bartab8f93d2011-03-06 16:33:08 +000038 * See also the dyld::fastBindLazySymbol() source code (http://opensource.apple.com/source/dyld/dyld-132.13/src/dyld.cpp).
bart6de4f412011-03-06 12:39:12 +000039 */
bartab8f93d2011-03-06 16:33:08 +000040void* VG_WRAP_FUNCTION_ZZ(dyld, ZuZZN4dyld18fastBindLazySymbolEPP11ImageLoaderm)
bart6de4f412011-03-06 12:39:12 +000041 (void** imageLoaderCache, uintptr_t lazyBindingInfoOffset);
bartab8f93d2011-03-06 16:33:08 +000042void* VG_WRAP_FUNCTION_ZZ(dyld, ZuZZN4dyld18fastBindLazySymbolEPP11ImageLoaderm)
bart6de4f412011-03-06 12:39:12 +000043 (void** imageLoaderCache, uintptr_t lazyBindingInfoOffset)
44{
barte8653ac2011-03-07 18:00:26 +000045 void* res;
46 OrigFn fn;
bart6de4f412011-03-06 12:39:12 +000047
barte8653ac2011-03-07 18:00:26 +000048 VALGRIND_GET_ORIG_FN(fn);
bart6de4f412011-03-06 12:39:12 +000049
barte8653ac2011-03-07 18:00:26 +000050 ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
51 CALL_FN_W_WW(res, fn, imageLoaderCache, lazyBindingInfoOffset);
52 ANNOTATE_IGNORE_READS_AND_WRITES_END();
bart6de4f412011-03-06 12:39:12 +000053
barte8653ac2011-03-07 18:00:26 +000054 return res;
bart6de4f412011-03-06 12:39:12 +000055}