blob: f70adc38238bcf73b4effbe34819e8e2aa6c28fc [file] [log] [blame]
barte8653ac2011-03-07 18:00:26 +00001/*
2 This file is part of drd, a thread error detector.
3
Elliott Hughesed398002017-06-21 14:41:24 -07004 Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
barte8653ac2011-03-07 18:00:26 +00005
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA.
20
21 The GNU General Public License is contained in the file COPYING.
22*/
23
bart6de4f412011-03-06 12:39:12 +000024#include <stdint.h>
25#include <stdio.h>
florian1a046d52013-09-16 20:56:35 +000026#include "pub_tool_clreq.h"
bartab8f93d2011-03-06 16:33:08 +000027#include "drd.h"
bart6de4f412011-03-06 12:39:12 +000028#include "pub_tool_redir.h"
29
bart6de4f412011-03-06 12:39:12 +000030/*
31 * On Mac OS X shared library functions are lazily bound. The binding mechanism
bartab8f93d2011-03-06 16:33:08 +000032 * uses self-modifying code. Intercept fastBindLazySymbol() in order to suppress
bart6de4f412011-03-06 12:39:12 +000033 * the data accesses involved in this mechanism.
34 *
35 * 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).
36 * 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 +000037 * 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 +000038 */
bartab8f93d2011-03-06 16:33:08 +000039void* VG_WRAP_FUNCTION_ZZ(dyld, ZuZZN4dyld18fastBindLazySymbolEPP11ImageLoaderm)
bart6de4f412011-03-06 12:39:12 +000040 (void** imageLoaderCache, uintptr_t lazyBindingInfoOffset);
bartab8f93d2011-03-06 16:33:08 +000041void* VG_WRAP_FUNCTION_ZZ(dyld, ZuZZN4dyld18fastBindLazySymbolEPP11ImageLoaderm)
bart6de4f412011-03-06 12:39:12 +000042 (void** imageLoaderCache, uintptr_t lazyBindingInfoOffset)
43{
barte8653ac2011-03-07 18:00:26 +000044 void* res;
45 OrigFn fn;
bartf7a5b3f2011-12-11 20:34:03 +000046
barte8653ac2011-03-07 18:00:26 +000047 VALGRIND_GET_ORIG_FN(fn);
bart6de4f412011-03-06 12:39:12 +000048
barte8653ac2011-03-07 18:00:26 +000049 ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
50 CALL_FN_W_WW(res, fn, imageLoaderCache, lazyBindingInfoOffset);
51 ANNOTATE_IGNORE_READS_AND_WRITES_END();
bart6de4f412011-03-06 12:39:12 +000052
barte8653ac2011-03-07 18:00:26 +000053 return res;
bart6de4f412011-03-06 12:39:12 +000054}