EF79A016070D295200F78484 /* dyld.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = EF799FF0070D27BB00F78484 /* dyld.3 */; };
F906E2240639E96400B13DB2 /* dyld_debug.c in Sources */ = {isa = PBXBuildFile; fileRef = F906E2230639E96400B13DB2 /* dyld_debug.c */; };
F913FADA0630A8AE00B7AE9D /* dyldAPIsInLibSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F913FAD90630A8AE00B7AE9D /* dyldAPIsInLibSystem.cpp */; };
+ F918691608B16D3500E0F9DB /* dyld-interposing.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = F918691408B16D2500E0F9DB /* dyld-interposing.h */; };
F919ECB1090455AB002331E3 /* dyld-update-prebinding.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = F919ECAB09045590002331E3 /* dyld-update-prebinding.h */; };
F93075C30BA1FE4D004BCA09 /* dyld_shared_cache_server.c in Sources */ = {isa = PBXBuildFile; fileRef = F93075C10BA1FE4D004BCA09 /* dyld_shared_cache_server.c */; };
F932C2520BC32ABB0018B20D /* com.apple.dyld.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = F93075D30BA204FF004BCA09 /* com.apple.dyld.plist */; };
dstPath = "/usr/local/include/mach-o";
dstSubfolderSpec = 0;
files = (
+ F918691608B16D3500E0F9DB /* dyld-interposing.h in CopyFiles */,
F919ECB1090455AB002331E3 /* dyld-update-prebinding.h in CopyFiles */,
F93AA9A30630AE1E00301D9F /* dyld_gdb.h in CopyFiles */,
F93AA9A40630AE1E00301D9F /* dyld_priv.h in CopyFiles */,
EF799FF0070D27BB00F78484 /* dyld.3 */ = {isa = PBXFileReference; explicitFileType = text.man; fileEncoding = 30; name = dyld.3; path = doc/man/man3/dyld.3; sourceTree = SOURCE_ROOT; };
F906E2230639E96400B13DB2 /* dyld_debug.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = dyld_debug.c; path = src/dyld_debug.c; sourceTree = "<group>"; };
F913FAD90630A8AE00B7AE9D /* dyldAPIsInLibSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = dyldAPIsInLibSystem.cpp; path = src/dyldAPIsInLibSystem.cpp; sourceTree = "<group>"; };
+ F918691408B16D2500E0F9DB /* dyld-interposing.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = "dyld-interposing.h"; path = "include/mach-o/dyld-interposing.h"; sourceTree = "<group>"; };
F918691708B16D5900E0F9DB /* dyld64.exp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.exports; name = dyld64.exp; path = src/dyld64.exp; sourceTree = "<group>"; };
F919ECAB09045590002331E3 /* dyld-update-prebinding.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = "dyld-update-prebinding.h"; path = "include/mach-o/dyld-update-prebinding.h"; sourceTree = "<group>"; };
F93075C10BA1FE4D004BCA09 /* dyld_shared_cache_server.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = dyld_shared_cache_server.c; path = generated/dyld_shared_cache_server.c; sourceTree = BUILT_PRODUCTS_DIR; };
F9AC7E930B7BB67700FEB38B /* version.c */,
F9AB70590BA73A11002F6068 /* dyld_shared_cache_user.c */,
F9AB705A0BA73A11002F6068 /* dyld_shared_cache_user.h */,
+ F918691408B16D2500E0F9DB /* dyld-interposing.h */,
F906E2230639E96400B13DB2 /* dyld_debug.c */,
);
name = src;
productRefGroup = F9ED4C990630A76000DF4E74 /* Products */;
projectDirPath = "";
projectRoot = "";
+ shouldCheckCompatibility = 1;
targets = (
F9ED4C920630A73900DF4E74 /* all */,
F9ED4C970630A76000DF4E74 /* dyld */,
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#if !defined(_DYLD_INTERPOSING_H_)
+#define _DYLD_INTERPOSING_H_
+
+/*
+ * Example:
+ *
+ * static
+ * int
+ * my_open(const char* path, int flags, mode_t mode)
+ * {
+ * int value;
+ * // do stuff before open (including changing the arguments)
+ * value = open(path, flags, mode);
+ * // do stuff after open (including changing the return value(s))
+ * return value;
+ * }
+ * DYLD_INTERPOSE(my_open, open)
+ */
+
+#define DYLD_INTERPOSE(_replacment,_replacee) \
+ __attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \
+ __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
+
+#endif
void setSize(uint64_t new_size) { fSize = new_size; }
void setFileOffset(uint64_t new_off) { fFileOffset = new_off; }
void setFileSize(uint64_t new_size) { fFileSize = new_size; }
- void setWritable(bool writable) { if (writable) fPermissions |= VM_PROT_WRITE; else fPermissions &= ~VM_PROT_WRITE; }
+ void setWritable(bool w) { if (w) fPermissions |= VM_PROT_WRITE; else fPermissions &= ~VM_PROT_WRITE; }
private:
uint64_t fAddress;
uint64_t fSize;
throwf("can't open file %s, errnor=%d", it->layout->getID().name, errno);
// mark source as "don't cache"
(void)fcntl(src, F_NOCACHE, 1);
+ // verify file has not changed since dependency analysis
+ struct stat stat_buf;
+ if ( fstat(src, &stat_buf) == -1)
+ throwf("can't stat open file %s, errno=%d", path, errno);
+ if ( (it->layout->getInode() != stat_buf.st_ino) || (it->layout->getLastModTime() != stat_buf.st_mtime) )
+ throwf("aborting because OS dylib modified during cache creation: %s", path);
if ( verbose )
fprintf(stderr, "update_dyld_shared_cache: copying %s to cache\n", it->layout->getID().name);
const uint64_t segmentSrcStartOffset = it->layout->getOffsetInUniversalFile()+seg.fileOffset();
const uint64_t segmentSize = seg.fileSize();
const uint64_t segmentDstStartOffset = cacheFileOffsetForAddress(seg.newAddress());
- if ( ::pread(src, &inMemoryCache[segmentDstStartOffset], segmentSize, segmentSrcStartOffset) != segmentSize )
- throwf("read failure copying dylib errno=%d for %s", errno, it->layout->getID().name);
+ ssize_t readResult = ::pread(src, &inMemoryCache[segmentDstStartOffset], segmentSize, segmentSrcStartOffset);
+ if ( readResult != segmentSize )
+ if ( readResult == -1 )
+ throwf("read failure copying dylib errno=%d for %s", errno, it->layout->getID().name);
+ else
+ throwf("read failure copying dylib. Read of %lld bytes at file offset %lld returned %ld for %s",
+ segmentSize, segmentSrcStartOffset, readResult, it->layout->getID().name);
+ // verify __TEXT segment has no zeroed out pages
+ if ( strcmp(seg.name(), "__TEXT") == 0 ) {
+ // only scan first 128KB. Some OS dylibs have zero filled TEXT pages later in __const...
+ int scanEnd = segmentSize;
+ if ( scanEnd > 0x20000 )
+ scanEnd = 0x20000;
+ for (int pageOffset = 0; pageOffset < scanEnd; pageOffset += 4096) {
+ const uint32_t* page = (uint32_t*)(&inMemoryCache[segmentDstStartOffset+pageOffset]);
+ bool foundNonZero = false;
+ for(int p=0; p < 1024; ++p) {
+ if ( page[p] != 0 ) {
+ //fprintf(stderr, "found non-zero at pageOffset=0x%08X, p=0x%08X in memory=%p for %s\n", pageOffset, p, page, it->layout->getID().name);
+ foundNonZero = true;
+ break;
+ }
+ }
+ if ( !foundNonZero )
+ throwf("suspected bad read. Found __TEXT segment page at offset 0x%08X that is all zeros for %s in %s", pageOffset, archName(), it->layout->getID().name);
+ }
+ }
}
}
}
fprintf(stderr, "update_dyld_shared_cache[%u] for arch=%s failed: %s\n", getpid(), ArchGraph::archName(arch), msg);
return KERN_FAILURE;
}
+ // <rdar://problem/6378354> only build one cache file per life of process
+ doNothingAndDrainQueue = true;
}
return KERN_SUCCESS;
}
--- /dev/null
+/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
+*
+* Copyright (c) 2007 AppleInc. All rights reserved.
+*
+* @APPLE_LICENSE_HEADER_START@
+*
+* This file contains Original Code and/or Modifications of Original Code
+* as defined in and that are subject to the Apple Public Source License
+* Version 2.0 (the 'License'). You may not use this file except in
+* compliance with the License. Please obtain a copy of the License at
+* http://www.opensource.apple.com/apsl/ and read it before using this
+* file.
+*
+* The Original Code and all software distributed under the License are
+* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+* Please see the License for the specific language governing rights and
+* limitations under the License.
+*
+* @APPLE_LICENSE_HEADER_END@
+*/
+
--- /dev/null
+/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
+ *
+ * Copyright (c) 2007 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
}
}
else {
+ // <rdar://problem/5925940> Safe Boot should disable dyld shared cache
+ // if we are in safe-boot mode and the cache was not made during this boot cycle,
+ // delete the cache file and let it be regenerated
+ uint32_t safeBootValue = 0;
+ size_t safeBootValueSize = sizeof(safeBootValue);
+ if ( (sysctlbyname("kern.safeboot", &safeBootValue, &safeBootValueSize, NULL, 0) == 0) && (safeBootValue != 0) ) {
+ // user booted machine in safe-boot mode
+ struct stat dyldCacheStatInfo;
+ if ( ::stat(DYLD_SHARED_CACHE_DIR DYLD_SHARED_CACHE_BASE_NAME ARCH_NAME, &dyldCacheStatInfo) == 0 ) {
+ struct timeval bootTimeValue;
+ size_t bootTimeValueSize = sizeof(bootTimeValue);
+ if ( (sysctlbyname("kern.boottime", &bootTimeValue, &bootTimeValueSize, NULL, 0) == 0) && (bootTimeValue.tv_sec != 0) ) {
+ // if the cache file was created before this boot, then throw it away and let it rebuild itself
+ if ( dyldCacheStatInfo.st_mtime < bootTimeValue.tv_sec ) {
+ ::unlink(DYLD_SHARED_CACHE_DIR DYLD_SHARED_CACHE_BASE_NAME ARCH_NAME);
+ gLinkContext.sharedRegionMode = ImageLoader::kDontUseSharedRegion;
+ gSharedCacheNotFound = true;
+ return;
+ }
+ }
+ }
+ }
// map in shared cache to shared region
int fd = openSharedCacheFile();
if ( fd != -1 ) {
extern void registerImageStateSingleChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
extern void registerImageStateBatchChangeHandler(dyld_image_states state, dyld_image_state_change_handler handler);
extern void garbageCollectImages();
+ extern void registerWinImageLocator(ImageLocator);
extern int openSharedCacheFile();
extern const void* imMemorySharedCacheHeader();
+++ /dev/null
-all-check: all check
-
-check:##
-# Copyright (c) 2007 Apple Inc. All rights reserved.
-#
-# @APPLE_LICENSE_HEADER_START@
-#
-# This file contains Original Code and/or Modifications of Original Code
-# as defined in and that are subject to the Apple Public Source License
-# Version 2.0 (the 'License'). You may not use this file except in
-# compliance with the License. Please obtain a copy of the License at
-# http://www.opensource.apple.com/apsl/ and read it before using this
-# file.
-#
-# The Original Code and all software distributed under the License are
-# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
-# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
-# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
-# Please see the License for the specific language governing rights and
-# limitations under the License.
-#
-# @APPLE_LICENSE_HEADER_END@
-##
-TESTROOT = ../..
-include ${TESTROOT}/include/common.makefile
-
-
-### <rdar://problem/5504633> ADOBE: Premiere Pro crashes on quit
-###
-### libfoo depends on libfoo1 and libfoo2. main dlopens(libfoo).
-### libfoo1 has an initializer that calls dlopen(libbar).
-### libbar depends on libfoo2
-###
-
-all-check: all check
-
-check:
- ./main
-
-all: main
-
-main : main.cxx libfoo.dylib
- ${CXX} ${CCXXFLAGS} -I${TESTROOT}/include -o main main.cxx
-
-
-libfoo.dylib : foo.c libfoo1.dylib libfoo2.dylib
- ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib libfoo1.dylib libfoo2.dylib
-
-libfoo1.dylib : foo1.c libbar.dylib
- ${CC} ${CCFLAGS} -dynamiclib foo1.c -o libfoo1.dylib
-
-libfoo2.dylib : foo2.c
- ${CC} ${CCFLAGS} -dynamiclib foo2.c -o libfoo2.dylib
-
-libbar.dylib : bar.c libfoo2.dylib
- ${CC} ${CCFLAGS} -dynamiclib bar.c -o libbar.dylib libfoo2.dylib
-
-
-clean:
- ${RM} ${RMFLAGS} *~ main libbar.dylib libfoo.dylib libfoo1.dylib libfoo2.dylib
-
+++ /dev/null
-void bar() {}
+++ /dev/null
-/*
- * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <dlfcn.h>
-
-
-
-int foo()
-{
- return 10;
-}
+++ /dev/null
-/*
- * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <dlfcn.h>
-
-static void myInit() __attribute__((constructor));
-
-static void myInit()
-{
- // call dlopen to verify that initializer lock can be held recursively
- dlopen("libbar.dylib", RTLD_LAZY);
-}
-
-
-int foo1()
-{
- return 10;
-}
+++ /dev/null
-/*
- * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <dlfcn.h>
-
-static void myInit() __attribute__((constructor));
-
-static void myInit()
-{
-
-}
-
-
-int foo2()
-{
- return 10;
-}
+++ /dev/null
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <mach-o/dyld.h>
-#include <set>
-
-#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
-
-
-static void trySO(const char* path)
-{
- void* handle = dlopen(path, RTLD_LAZY);
- if ( handle == NULL ) {
- FAIL("dlopen(\"%s\") failed with: %s", path, dlerror());
- exit(0);
- }
-
- void* sym = dlsym(handle, "foo");
- if ( sym == NULL ) {
- FAIL("dlsym(handle, \"foo\") failed");
- exit(0);
- }
-
- int result = dlclose(handle);
- if ( result != 0 ) {
- if ( result == 1 ) {
- // panther dyld returns 1 if you try to dlclose() a dylib
- XFAIL("dlclose(handle) returned %d", result);
- }
- else {
- FAIL("dlclose(handle) returned %d", result);
- exit(0);
- }
- }
-
-}
-
-static std::set<const struct mach_header*> sCurrentImages;
-
-static void notify(const struct mach_header *mh, intptr_t vmaddr_slide)
-{
- //fprintf(stderr, "mh=%p\n", mh);
- if ( sCurrentImages.count(mh) != 0 ) {
- FAIL("notified twice about %p", mh);
- exit(0);
- }
- sCurrentImages.insert(mh);
-}
-
-
-
-int main()
-{
- _dyld_register_func_for_add_image(¬ify);
-
- trySO("libfoo.dylib");
-
- PASS("dlopen-init-dlopen-notify");
- return EXIT_SUCCESS;
-}
+++ /dev/null
-##
-# Copyright (c) 2007 Apple Inc. All rights reserved.
-#
-# @APPLE_LICENSE_HEADER_START@
-#
-# This file contains Original Code and/or Modifications of Original Code
-# as defined in and that are subject to the Apple Public Source License
-# Version 2.0 (the 'License'). You may not use this file except in
-# compliance with the License. Please obtain a copy of the License at
-# http://www.opensource.apple.com/apsl/ and read it before using this
-# file.
-#
-# The Original Code and all software distributed under the License are
-# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
-# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
-# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
-# Please see the License for the specific language governing rights and
-# limitations under the License.
-#
-# @APPLE_LICENSE_HEADER_END@
-##
-TESTROOT = ../..
-include ${TESTROOT}/include/common.makefile
-
-
-#
-# verify there are no leaks with dlopen/close on success and failure
-#
-
-# leaks does not work on rosetta processes
-CHECK = check-real
-ifeq "ppc" "$(ARCH)"
- MACHINE = $(shell arch)
- ifeq "i386" "$(MACHINE)"
- CHECK = check-xfail
- endif
-endif
-
-all-check: all check
-
-check: ${CHECK}
-
-check-real:
- ${TESTROOT}/bin/exit-zero-pass.pl "dlopen-leak" "dlopen-leak" "DYLD_LIBRARY_PATH=hide && ./main | grep '0 leaks for 0 total leaked bytes' > /dev/null"
- ${TESTROOT}/bin/exit-zero-pass.pl "dlopen-leak" "dlopen-leak" "./main | grep '0 leaks for 0 total leaked bytes' > /dev/null"
-
-check-xfail:
- echo "XFAIL dlopen-leak";
-
-
-all: main
-
-
-hide/libbar.dylib : bar.c
- mkdir -p hide
- ${CC} bar.c -dynamiclib -o hide/libbar.dylib -install_name libbar.dylib
-
-libfoo.dylib : foo.c hide/libbar.dylib
- ${CC} foo.c hide/libbar.dylib -dynamiclib -o libfoo.dylib
-
-main : main.c libfoo.dylib
- ${CC} ${CCFLAGS} -I${TESTROOT}/include main.c -o main
-
-
-
-clean:
- ${RM} ${RMFLAGS} *~ main libfoo.dylib hide
+++ /dev/null
-void bar()
-{
-}
+++ /dev/null
-void foo()
-{
-}
+++ /dev/null
-/*
- * Copyright (c) 2007 Apple Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <dlfcn.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-
-#include "test.h"
-
-
-int main()
-{
- for (int i=0; i < 100; ++i) {
- void* handle = dlopen("libfoo.dylib", RTLD_LAZY);
- if ( handle != NULL )
- dlclose(handle);
- dlopen("libnotthere.dylib", RTLD_LAZY);
- }
-
- // execute leaks command on myself
- char cmd[512];
- sprintf(cmd, "leaks %u\n", getpid());
- system(cmd);
-
- return EXIT_SUCCESS;
-}
+++ /dev/null
-##
-# Copyright (c) 2007 Apple Inc. All rights reserved.
-#
-# @APPLE_LICENSE_HEADER_START@
-#
-# This file contains Original Code and/or Modifications of Original Code
-# as defined in and that are subject to the Apple Public Source License
-# Version 2.0 (the 'License'). You may not use this file except in
-# compliance with the License. Please obtain a copy of the License at
-# http://www.opensource.apple.com/apsl/ and read it before using this
-# file.
-#
-# The Original Code and all software distributed under the License are
-# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
-# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
-# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
-# Please see the License for the specific language governing rights and
-# limitations under the License.
-#
-# @APPLE_LICENSE_HEADER_END@
-##
-TESTROOT = ../..
-include ${TESTROOT}/include/common.makefile
-
-
-### <rdar://problem/5565230> CFSTRs cause crashes in Leopard
-###
-### main registers for notification and then dlopens(libfoo).
-### In the notification callback, main calls NSLookupSymbolInImage(BIND)
-### which double bound libfoo
-###
-
-all-check: all check
-
-check:
- ./main
-
-all: main
-
-main : main.c libfoo.dylib
- ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c -mmacosx-version-min=10.4
-
-
-libfoo.dylib : foo.c
- ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib
-
-
-clean:
- ${RM} ${RMFLAGS} *~ main libfoo.dylib
-
+++ /dev/null
-/*
- * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <stdlib.h>
-
-
-void* externalRlocToMalloc = &malloc;
-
-void* foo()
-{
- return externalRlocToMalloc;
-}
+++ /dev/null
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include <stdio.h> // fprintf(), NULL
-#include <stdlib.h> // exit(), EXIT_SUCCESS
-#include <dlfcn.h>
-#include <mach-o/dyld.h>
-
-#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
-
-
-typedef void* (*fooProc)();
-
-
-static void notify(const struct mach_header *mh, intptr_t vmaddr_slide)
-{
- //fprintf(stderr, "mh=%p\n", mh);
- NSLookupSymbolInImage(mh, "_bar", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
-}
-
-
-int main()
-{
- _dyld_register_func_for_add_image(¬ify);
-
- void* handle = dlopen("libfoo.dylib", RTLD_LAZY);
- if ( handle == NULL ) {
- FAIL("dlopen(\"%s\") failed with: %s", "libfoo.dylib", dlerror());
- exit(0);
- }
-
- fooProc fooPtr = (fooProc)dlsym(handle, "foo");
- if ( fooPtr == NULL ) {
- FAIL("dlsym(handle, \"foo\") failed");
- exit(0);
- }
-
- void* foosMalloc = (*fooPtr)();
- //fprintf(stderr, "foo says &malloc=%p\n", foosMalloc);
- //fprintf(stderr, "&malloc=%p\n", &malloc);
-
- dlclose(handle);
-
- if ( foosMalloc == &malloc )
- PASS("dlopen-notify-bind");
- else
- FAIL("dlopen-notify-bind libfoo.dylib double bound");
- return EXIT_SUCCESS;
-}
+++ /dev/null
-##
-# Copyright (c) 2007 Apple Inc. All rights reserved.
-#
-# @APPLE_LICENSE_HEADER_START@
-#
-# This file contains Original Code and/or Modifications of Original Code
-# as defined in and that are subject to the Apple Public Source License
-# Version 2.0 (the 'License'). You may not use this file except in
-# compliance with the License. Please obtain a copy of the License at
-# http://www.opensource.apple.com/apsl/ and read it before using this
-# file.
-#
-# The Original Code and all software distributed under the License are
-# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
-# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
-# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
-# Please see the License for the specific language governing rights and
-# limitations under the License.
-#
-# @APPLE_LICENSE_HEADER_END@
-##
-TESTROOT = ../..
-include ${TESTROOT}/include/common.makefile
-
-
-#
-# verify there are no leaks with dlopen/close on success and failure
-#
-
-# leaks does not work on rosetta processes
-CHECK = check-real
-ifeq "ppc" "$(ARCH)"
- MACHINE = $(shell arch)
- ifeq "i386" "$(MACHINE)"
- CHECK = check-xfail
- endif
-endif
-
-all-check: all check
-
-check: ${CHECK}
-
-check-real:
- ${TESTROOT}/bin/exit-zero-pass.pl "dlopen_preflight-leak" "dlopen_preflight-leak" "DYLD_LIBRARY_PATH=hide && ./main | grep '0 leaks for 0 total leaked bytes' > /dev/null"
- ${TESTROOT}/bin/exit-zero-pass.pl "dlopen_preflight-leak" "dlopen_preflight-leak" "./main | grep '0 leaks for 0 total leaked bytes' > /dev/null"
-
-check-xfail:
- echo "XFAIL dlopen-leak";
-
-all: main
-
-hide/libbar.dylib : bar.c
- mkdir -p hide
- ${CC} bar.c -dynamiclib -o hide/libbar.dylib -install_name libbar.dylib
-
-libfoo.dylib : foo.c hide/libbar.dylib
- ${CC} foo.c hide/libbar.dylib -dynamiclib -o libfoo.dylib
-
-main : main.c libfoo.dylib
- ${CC} ${CCFLAGS} -I${TESTROOT}/include main.c -o main
-
-
-clean:
- ${RM} ${RMFLAGS} *~ main libfoo.dylib hide
+++ /dev/null
-void bar()
-{
-}
+++ /dev/null
-void foo()
-{
-}
+++ /dev/null
-/*
- * Copyright (c) 2007 Apple Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <dlfcn.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-
-#include "test.h"
-
-
-int main()
-{
- for (int i=0; i < 100; ++i) {
- dlopen_preflight("libfoo.dylib");
- }
-
- // execute leaks command on myself
- char cmd[512];
- sprintf(cmd, "leaks %u\n", getpid());
- system(cmd);
-
- return EXIT_SUCCESS;
-}
{
const struct mach_header *image;
- image = NSAddImage("AppKit.framework/AppKit",
+ image = NSAddImage("Carbon.framework/Carbon",
NSADDIMAGE_OPTION_RETURN_ON_ERROR | NSADDIMAGE_OPTION_WITH_SEARCHING);
if ( image != NULL )
- PASS("AppKit loaded");
+ PASS("Carbon loaded");
else
- FAIL("Could not load AppKit");
+ FAIL("Could not load Carbon");
return 0;
}
--- /dev/null
+##
+# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+##
+TESTROOT = ../..
+include ${TESTROOT}/include/common.makefile
+
+run: all
+ export DYLD_INSERT_LIBRARIES="libmystrdup.dylib" && ./main
+
+all: main libmystrdup.dylib
+
+main : main.c libfoo.dylib
+ ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c libfoo.dylib
+
+libfoo.dylib : foo.c
+ export MACOSX_DEPLOYMENT_TARGET=10.3 && ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib -prebind -seg1addr 20000
+
+libmystrdup.dylib : mystrdup.c
+ ${CC} ${CCFLAGS} -dynamiclib mystrdup.c -o libmystrdup.dylib
+
+
+
+clean:
+ ${RM} ${RMFLAGS} *~ main libmystrdup.dylib libfoo.dylib
+
\ No newline at end of file
--- /dev/null
+
+#include <stdbool.h>
+#include <string.h>
+
+bool check_dylib_interposing()
+{
+ const char* x = strdup("123");
+ const char* y = strdup("456");
+
+ return ( (strcmp(x, "hello") == 0) && (strcmp(y, "hello") == 0) );
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <stdbool.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
+
+extern bool check_dylib_interposing();
+
+int main()
+{
+ if ( check_dylib_interposing() )
+ PASS("interpose-basic");
+ else
+ FAIL("interpose-basic");
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <string.h>
+#include <mach-o/dyld-interposing.h>
+
+char* mystrdup(const char* in)
+{
+ return "hello";
+}
+
+DYLD_INTERPOSE(mystrdup, strdup)
--- /dev/null
+##
+# Copyright (c) 2005-2007 Apple Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+##
+TESTROOT = ../..
+include ${TESTROOT}/include/common.makefile
+
+run: all
+ export DYLD_INSERT_LIBRARIES="libmystrdup.dylib" && ./main
+
+all: main libmystrdup.dylib
+
+main : main.c libwrap.dylib
+ ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main libwrap.dylib main.c
+
+libwrap.dylib: wrap.c
+ ${CC} ${CCFLAGS} -dynamiclib wrap.c -o libwrap.dylib
+
+libmystrdup.dylib : mystrdup.c
+ ${CC} ${CCFLAGS} -dynamiclib mystrdup.c -o libmystrdup.dylib
+
+
+
+clean:
+ ${RM} ${RMFLAGS} *~ main libmystrdup.dylib libwrap.dylib
+
--- /dev/null
+/*
+ * Copyright (c) 2005-2007 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <string.h>
+#include <dlfcn.h>
+
+#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
+
+extern char* wrap_strdup(const char*);
+
+int main()
+{
+ const char* x = strdup("123");
+ const char* y = wrap_strdup("456");
+
+ if ( (strcmp(x, "hello") == 0) && (strcmp(y, "hello") == 0) )
+ PASS("interpose-basic");
+ else
+ FAIL("interpose-basic");
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <string.h>
+#include <mach-o/dyld-interposing.h>
+
+char* mystrdup(const char* in)
+{
+ return "hello";
+}
+
+DYLD_INTERPOSE(mystrdup, strdup)
--- /dev/null
+/*
+ * Copyright (c) 2007 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <string.h>
+
+// make a pointer statically initiallized to strdup()
+// since libwrap.dylib is staticlly linked to main
+// this verfies that interposing happens properly
+static char* (*proc)(const char*) = strdup;
+
+char* wrap_strdup(const char* str)
+{
+ return proc(str);
+}
+
--- /dev/null
+##
+# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+#
+
+#
+# This unit test verifies that multiple interposing libraries can all
+# interpose the same function and the result is that they chain together.
+# That is, each one calls through to the next.
+#
+# On Tiger (10.4.0), this test fails with infinite recursion.
+#
+# The function foo() does string appends. This allows us to check:
+# 1) every interposer was called, and 2) they were called in the
+# correct order.
+#
+
+TESTROOT = ../..
+include ${TESTROOT}/include/common.makefile
+
+run: all
+ export DYLD_INSERT_LIBRARIES="libfoo1.dylib:libfoo2.dylib:libfoo3.dylib" && ./main
+
+all: main libfoo1.dylib libfoo2.dylib libfoo3.dylib
+
+main : main.c libfoo.dylib
+ ${CC} ${CCFLAGS} -I${TESTROOT}/include main.c libfoo.dylib -o main
+
+libfoo.dylib : foo.c
+ ${CC} ${CCFLAGS} -dynamiclib foo.c -o libfoo.dylib
+
+libfoo1.dylib : foo1.c libfoo.dylib
+ ${CC} ${CCFLAGS} -dynamiclib foo1.c libfoo.dylib -o libfoo1.dylib
+
+libfoo2.dylib : foo2.c libfoo.dylib
+ ${CC} ${CCFLAGS} -dynamiclib foo2.c libfoo.dylib -o libfoo2.dylib
+
+libfoo3.dylib : foo3.c libfoo.dylib
+ ${CC} ${CCFLAGS} -dynamiclib foo3.c libfoo.dylib -o libfoo3.dylib
+
+
+
+clean:
+ ${RM} ${RMFLAGS} *~ main libfoo.dylib libfoo1.dylib libfoo2.dylib libfoo3.dylib
+
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h>
+#include "foo.h"
+
+const char* foo(const char* str)
+{
+ char* result;
+ asprintf(&result, "foo(%s)", str);
+ return result;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+extern const char* foo(const char* str);
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h>
+#include <mach-o/dyld-interposing.h>
+#include "foo.h"
+
+const char* foo1(const char* str)
+{
+ char* result;
+ asprintf(&result, "foo1(%s)", foo(str));
+ return result;
+}
+
+DYLD_INTERPOSE(foo1, foo)
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h>
+#include <mach-o/dyld-interposing.h>
+#include "foo.h"
+
+const char* foo2(const char* str)
+{
+ char* result;
+ asprintf(&result, "foo2(%s)", foo(str));
+ return result;
+}
+
+DYLD_INTERPOSE(foo2, foo)
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h>
+#include <mach-o/dyld-interposing.h>
+#include "foo.h"
+
+const char* foo3(const char* str)
+{
+ char* result;
+ asprintf(&result, "foo3(%s)", foo(str));
+ return result;
+}
+
+DYLD_INTERPOSE(foo3, foo)
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <string.h>
+
+#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
+#include "foo.h"
+
+int main()
+{
+ const char* x = foo("seed");
+
+ if ( strcmp(x, "foo3(foo2(foo1(foo(seed))))") == 0 )
+ PASS("interpose-chained");
+ else
+ FAIL("interpose-chained %s", x);
+ return EXIT_SUCCESS;
+}
--- /dev/null
+##
+# Copyright (c) 2005-2007 Apple Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+##
+TESTROOT = ../..
+include ${TESTROOT}/include/common.makefile
+
+run: all
+ export DYLD_INSERT_LIBRARIES="libmyfree.dylib" && ./main
+
+all: main libmyfree.dylib
+
+main : main.c
+ ${CC} ${CCFLAGS} -I${TESTROOT}/include -o main main.c
+
+
+libmyfree.dylib : myfree.c
+ ${CC} ${CCFLAGS} -dynamiclib myfree.c -o libmyfree.dylib
+
+
+
+clean:
+ ${RM} ${RMFLAGS} *~ main libmyfree.dylib
+
--- /dev/null
+/*
+ * Copyright (c) 2007 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <stdio.h> // fprintf(), NULL
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+#include <string.h>
+#include <dlfcn.h>
+#include <stdlib.h>
+
+#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
+
+
+int main()
+{
+ void* handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY);
+ if ( handle == NULL ) {
+ FAIL("interpose-dlsym: dlopen() error: %s", dlerror());
+ exit(0);
+ }
+ void* dlsym_free = dlsym(handle, "free");
+ if ( dlsym_free == NULL ) {
+ FAIL("interpose-dlsym: dlsym() error: %s", dlerror());
+ exit(0);
+ }
+
+ if ( dlsym_free == &free )
+ PASS("interpose-dlsym");
+ else
+ FAIL("interpose-dlsym: %p != %p", dlsym_free, &free);
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/*
+ * Copyright (c) 2007 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <stdlib.h>
+#include <mach-o/dyld-interposing.h>
+
+void myfree(void* p)
+{
+ free(p);
+}
+
+DYLD_INTERPOSE(myfree, free)