mirror of
https://github.com/darlinghq/darling-dyld.git
synced 2024-11-23 04:19:41 +00:00
Add Back Darling Specific Changes
This commit is contained in:
parent
5014f43344
commit
bc37c99380
14
darling-scripts/add-version-macros.sh
Executable file
14
darling-scripts/add-version-macros.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
pushd $(dirname "$0") > /dev/null
|
||||
SCRIPTDIR=$(pwd -P)
|
||||
popd > /dev/null
|
||||
|
||||
export SRCROOT="$SCRIPTDIR/.."
|
||||
export SDKROOT="$SRCROOT/../../Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
|
||||
|
||||
# copied and modified from dyld.xcodeproj
|
||||
${SRCROOT}/bin/expand.rb < "${SRCROOT}/include/mach-o/dyld_priv.h" > "${SRCROOT}/include/mach-o/dyld_priv.h.tmp"
|
||||
|
||||
mv "${SRCROOT}/include/mach-o/dyld_priv.h.tmp" "${SRCROOT}/include/mach-o/dyld_priv.h"
|
@ -61,6 +61,10 @@ extern "C" void __cxa_finalize_ranges(const __cxa_range_t ranges[], unsigned int
|
||||
|
||||
extern "C" int __cxa_atexit(void (*func)(void *), void* arg, void* dso);
|
||||
|
||||
#ifdef DARLING
|
||||
#define kdebug_is_enabled(...) 0
|
||||
#endif
|
||||
|
||||
|
||||
VIS_HIDDEN void* __ptrauth_dyld_address_auth gUseDyld3 = nullptr;
|
||||
|
||||
|
@ -751,7 +751,7 @@ void Loader::registerDOFs(const Array<DOFInfo>& dofs)
|
||||
|
||||
bool Loader::dtraceUserProbesEnabled()
|
||||
{
|
||||
#if !TARGET_OS_SIMULATOR
|
||||
#if !TARGET_OS_SIMULATOR && !defined(DARLING)
|
||||
uint8_t dofEnabled = *((uint8_t*)_COMM_PAGE_DTRACE_DOF_ENABLED);
|
||||
return ( (dofEnabled & 1) );
|
||||
#else
|
||||
|
@ -797,6 +797,7 @@ const uint8_t* MachOLoaded::trieWalk(Diagnostics& diag, const uint8_t* start, co
|
||||
void MachOLoaded::forEachCDHashOfCodeSignature(const void* codeSigStart, size_t codeSignLen,
|
||||
void (^callback)(const uint8_t cdHash[20])) const
|
||||
{
|
||||
#ifndef DARLING
|
||||
forEachCodeDirectoryBlob(codeSigStart, codeSignLen, ^(const void *cdBuffer) {
|
||||
const CS_CodeDirectory* cd = (const CS_CodeDirectory*)cdBuffer;
|
||||
uint32_t cdLength = htonl(cd->length);
|
||||
@ -839,6 +840,7 @@ void MachOLoaded::forEachCDHashOfCodeSignature(const void* codeSigStart, size_t
|
||||
return;
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,11 @@
|
||||
#include "Loading.h"
|
||||
#include "Tracing.h"
|
||||
|
||||
#ifdef DARLING
|
||||
#define kdebug_trace(...)
|
||||
#define kdebug_is_enabled(...) false
|
||||
#endif
|
||||
|
||||
// Workaround for header issues in rdar://49073930
|
||||
// #include <System/os/reason_private.h>
|
||||
extern "C" int
|
||||
|
@ -35,6 +35,10 @@
|
||||
#include <System/sys/kdebug.h>
|
||||
#include <System/sys/reason.h>
|
||||
|
||||
#ifdef DARLING
|
||||
#define kdebug_trace_string(...) ((uint64_t)-1)
|
||||
#endif
|
||||
|
||||
|
||||
#define DBG_DYLD_INTERNAL_SUBCLASS (7)
|
||||
#define DBG_DYLD_API_SUBCLASS (8)
|
||||
|
@ -38,7 +38,9 @@
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <System/sys/csr.h>
|
||||
#ifndef DARLING
|
||||
#include <rootless.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
@ -49,6 +51,10 @@
|
||||
#include "Diagnostics.h"
|
||||
#include "JSONReader.h"
|
||||
|
||||
#ifdef DARLING
|
||||
static int rootless_check_trusted(const char* path) { return -1; }
|
||||
static int rootless_check_trusted_class(const char* path, const char* cls) { return -1; }
|
||||
#endif
|
||||
|
||||
void iterateDirectoryTree(const std::string& pathPrefix, const std::string& path, bool (^dirFilter)(const std::string& path), void (^fileCallback)(const std::string& path, const struct stat&), bool processFiles, bool recurse)
|
||||
{
|
||||
|
11
hell.c
Normal file
11
hell.c
Normal file
@ -0,0 +1,11 @@
|
||||
// This file is plain wrong, broken and horrible.
|
||||
// The problem is Apple's ld fails to resolve some global variables in the static libraries we link into dyld.
|
||||
// I have confirmed the problem even on macOS.
|
||||
//
|
||||
// If the sought-after symbol is defined (really defined) in a static library, then ld fails to find it.
|
||||
// When it is defined in an object file passed on the command line, ld has no problem.
|
||||
|
||||
void* __cleanup;
|
||||
char __gdtoa_locks[32];
|
||||
void* _libkernel_functions[16];
|
||||
|
3
sandbox-dummy.c
Normal file
3
sandbox-dummy.c
Normal file
@ -0,0 +1,3 @@
|
||||
int sandbox_check(void) { return 0; }
|
||||
int SANDBOX_CHECK_NO_REPORT = 0;
|
||||
|
@ -2573,6 +2573,9 @@ uintptr_t ImageLoaderMachO::reserveAnAddressRange(size_t length, const ImageLoad
|
||||
{
|
||||
vm_address_t addr = 0;
|
||||
vm_size_t size = length;
|
||||
// In Darling, we're not the only ones doing memory mapping.
|
||||
// Therefore, we cannot dictate addresses, because we could (would!) conflict with the ELF loader.
|
||||
#ifndef DARLING
|
||||
// in PIE programs, load initial dylibs after main executable so they don't have fixed addresses either
|
||||
if ( fgNextPIEDylibAddress != 0 ) {
|
||||
// add small (0-3 pages) random padding between dylibs
|
||||
@ -2585,6 +2588,7 @@ uintptr_t ImageLoaderMachO::reserveAnAddressRange(size_t length, const ImageLoad
|
||||
}
|
||||
fgNextPIEDylibAddress = 0;
|
||||
}
|
||||
#endif
|
||||
kern_return_t r = vm_alloc(&addr, size, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_DYLIB));
|
||||
if ( r != KERN_SUCCESS )
|
||||
throw "out of address space";
|
||||
|
@ -86,7 +86,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_SIMULATOR
|
||||
#if TARGET_OS_SIMULATOR || defined(DARLING)
|
||||
enum {
|
||||
AMFI_DYLD_INPUT_PROC_IN_SIMULATOR = (1 << 0),
|
||||
};
|
||||
@ -100,6 +100,9 @@
|
||||
AMFI_DYLD_OUTPUT_ALLOW_LIBRARY_INTERPOSING = (1 << 6),
|
||||
};
|
||||
extern "C" int amfi_check_dyld_policy_self(uint64_t input_flags, uint64_t* output_flags);
|
||||
#ifdef DARLING
|
||||
int amfi_check_dyld_policy_self(uint64_t input_flags, uint64_t* output_flags) { *output_flags = 0x3F; return 0; }
|
||||
#endif
|
||||
#else
|
||||
#include <libamfi.h>
|
||||
#endif
|
||||
@ -1465,7 +1468,7 @@ static void setRunInitialzersOldWay()
|
||||
|
||||
static bool sandboxBlocked(const char* path, const char* kind)
|
||||
{
|
||||
#if TARGET_OS_SIMULATOR
|
||||
#if TARGET_OS_SIMULATOR || defined(DARLING)
|
||||
// sandbox calls not yet supported in simulator runtime
|
||||
return false;
|
||||
#else
|
||||
@ -5314,7 +5317,7 @@ static void configureProcessRestrictions(const macho_header* mainExecutableMH, c
|
||||
uint64_t amfiInputFlags = 0;
|
||||
#if TARGET_OS_SIMULATOR
|
||||
amfiInputFlags |= AMFI_DYLD_INPUT_PROC_IN_SIMULATOR;
|
||||
#elif TARGET_OS_OSX
|
||||
#elif TARGET_OS_OSX && !defined(DARLING)
|
||||
if ( hasRestrictedSegment(mainExecutableMH) )
|
||||
amfiInputFlags |= AMFI_DYLD_INPUT_PROC_HAS_RESTRICT_SEG;
|
||||
#elif TARGET_OS_IPHONE
|
||||
@ -5454,6 +5457,16 @@ void notifyKernelAboutImage(const struct macho_header* mh, const char* fileInfo)
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
static void* getProcessInfo() { return dyld::gProcessInfo; }
|
||||
#ifdef DARLING
|
||||
#undef kdebug_is_enabled
|
||||
#undef kdebug_trace
|
||||
#undef kdebug_trace_string
|
||||
static bool kdebug_is_enabled(uint32_t code) { return false; }
|
||||
static int kdebug_trace(uint32_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) { return 0;}
|
||||
static uint64_t kdebug_trace_string(uint32_t debugid, uint64_t str_id, const char *str) { return 0; }
|
||||
//int (*amfi_check_dyld_policy_self)(uint64_t input_flags, uint64_t* output_flags);
|
||||
#endif
|
||||
|
||||
static const SyscallHelpers sSysCalls = {
|
||||
14,
|
||||
// added in version 1
|
||||
@ -6869,8 +6882,10 @@ _main(const macho_header* mainExecutableMH, uintptr_t mainExecutableSlide,
|
||||
// First test to see if we forced in dyld2 via a kernel boot-arg
|
||||
if ( dyld3::BootArgs::forceDyld2() ) {
|
||||
sClosureMode = ClosureMode::Off;
|
||||
#ifndef DARLING
|
||||
} else if ( inDenyList(sExecPath) ) {
|
||||
sClosureMode = ClosureMode::Off;
|
||||
#endif
|
||||
} else if ( sEnv.hasOverride ) {
|
||||
sClosureMode = ClosureMode::Off;
|
||||
} else if ( dyld3::BootArgs::forceDyld3() ) {
|
||||
|
@ -123,6 +123,12 @@ static NSLinkEditErrors sLastErrorFileCode;
|
||||
static int sLastErrorNo;
|
||||
#endif
|
||||
|
||||
#ifdef DARLING
|
||||
extern "C" int mach_driver_get_dyld_fd(void);
|
||||
extern "C" void* elfcalls_get_pointer(void);
|
||||
extern "C" void mach_driver_set_dyld_fd(int fd);
|
||||
#endif
|
||||
|
||||
// In 10.3.x and earlier all the NSObjectFileImage API's were implemeneted in libSystem.dylib
|
||||
// Beginning in 10.4 the NSObjectFileImage API's are implemented in dyld and libSystem just forwards
|
||||
// This conditional keeps support for old libSystem's which needed some help implementing the API's
|
||||
@ -254,6 +260,9 @@ static const struct dyld_func dyld_funcs[] = {
|
||||
#if OLD_LIBSYSTEM_SUPPORT
|
||||
{"__dyld_link_module", (void*)_dyld_link_module },
|
||||
#endif
|
||||
#ifdef DARLING
|
||||
{"__dyld_get_elfcalls", (void*)elfcalls_get_pointer },
|
||||
#endif
|
||||
#pragma clang diagnostic pop
|
||||
#endif //DEPRECATED_APIS_SUPPORTED
|
||||
|
||||
|
@ -780,6 +780,7 @@ const void* address,
|
||||
size_t size,
|
||||
NSObjectFileImage *objectFileImage)
|
||||
{
|
||||
#ifndef DARLING
|
||||
// <rdar://problem/51812762> NSCreatObjectFileImageFromMemory fail opaquely if Hardened runtime is enabled
|
||||
uint32_t flags;
|
||||
if ( csops(0, CS_OPS_STATUS, &flags, sizeof(flags)) != -1 ) {
|
||||
@ -788,6 +789,7 @@ NSObjectFileImage *objectFileImage)
|
||||
return NSObjectFileImageAccess;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( gUseDyld3 )
|
||||
return dyld3::NSCreateObjectFileImageFromMemory(address, size, objectFileImage);
|
||||
|
@ -107,7 +107,9 @@ static void rebaseDyld(const dyld3::MachOLoaded* dyldMH)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#ifdef DARLING
|
||||
extern "C" void sigexc_setup(void);
|
||||
#endif
|
||||
|
||||
//
|
||||
// This is code to bootstrap dyld. This work in normally done for a program by dyld and crt.
|
||||
@ -135,6 +137,9 @@ uintptr_t start(const dyld3::MachOLoaded* appsMachHeader, int argc, const char*
|
||||
// set up random value for stack canary
|
||||
__guard_setup(apple);
|
||||
|
||||
#ifdef DARLING
|
||||
sigexc_setup();
|
||||
#endif
|
||||
#if DYLD_INITIALIZER_SUPPORT
|
||||
// run all C++ initializers inside dyld
|
||||
runDyldInitializers(argc, argv, envp, apple);
|
||||
|
@ -153,7 +153,11 @@ void* calloc(size_t count, size_t size)
|
||||
void* realloc(void *ptr, size_t size)
|
||||
{
|
||||
void* result = malloc(size);
|
||||
#ifdef DARLING
|
||||
if (ptr) { memcpy(result, ptr, size); }
|
||||
#else
|
||||
memcpy(result, ptr, size);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,11 @@ private:
|
||||
dyld_process_info_base(dyld_platform_t platform, unsigned imageCount, unsigned aotImageCount, size_t totalSize);
|
||||
void* operator new (size_t, void* buf) { return buf; }
|
||||
|
||||
#ifndef DARLING
|
||||
static bool inCache(uint64_t addr) { return (addr > SHARED_REGION_BASE) && (addr < SHARED_REGION_BASE+SHARED_REGION_SIZE); }
|
||||
#else
|
||||
static bool inCache(uint64_t addr) { return false; }
|
||||
#endif
|
||||
bool addImage(task_t task, bool sameCacheAsThisProcess, uint64_t imageAddress, uint64_t imagePath, const char* imagePathLocal);
|
||||
|
||||
bool addAotImage(dyld_aot_image_info_64 aotImageInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user