Loading...
--- dyld/dyld-551.4/dyld3/libdyldEntryVector.cpp
+++ dyld/dyld-750.5/dyld3/libdyldEntryVector.cpp
@@ -22,17 +22,19 @@
*/
#include <stdarg.h>
+#include <mach-o/dyld_priv.h>
+#include <mach-o/dyld_images.h>
-#include "dyld_priv.h"
#include "libdyldEntryVector.h"
#include "AllImages.h"
+#include "Array.h"
+#include "Loading.h"
#include "Logging.h"
#include "PathOverrides.h"
-#include "LaunchCacheFormat.h"
-#include "start_glue.h"
+#include "StartGlue.h"
+#include "dyld_process_info_internal.h"
-extern "C" void start();
-
+extern "C" char start;
VIS_HIDDEN const char** appleParams;
@@ -90,33 +92,41 @@
gAllImages.setOldAllImageInfo(old);
}
-static void entry_setInitialImageList(const launch_cache::binary_format::Closure* closure,
- const void* dyldCacheLoadAddress, const char* dyldCachePath,
- const dyld3::launch_cache::DynArray<loader::ImageInfo>& initialImages,
- const mach_header* libSystemMH, const launch_cache::binary_format::Image* libSystemImage)
+static void entry_setNotifyMonitoringDyldMain(void (*notifyMonitoringDyldMain)()) {
+#if !TARGET_OS_DRIVERKIT
+ setNotifyMonitoringDyldMain(notifyMonitoringDyldMain);
+#endif
+}
+
+static void entry_setNotifyMonitoringDyld(void (*notifyMonitoringDyld)(bool unloading,unsigned imageCount,
+ const struct mach_header* loadAddresses[],
+ const char* imagePaths[])) {
+#if !TARGET_OS_DRIVERKIT
+ setNotifyMonitoringDyld(notifyMonitoringDyld);
+#endif
+}
+
+static void entry_setInitialImageList(const closure::LaunchClosure* closure,
+ const DyldSharedCache* dyldCacheLoadAddress, const char* dyldCachePath,
+ const Array<LoadedImage>& initialImages, LoadedImage& libSystem)
{
gAllImages.init(closure, dyldCacheLoadAddress, dyldCachePath, initialImages);
- gAllImages.applyInterposingToDyldCache(closure, initialImages);
-
- const char* mainPath = _simple_getenv(appleParams, "executable_path");
- if ( (mainPath != nullptr) && (mainPath[0] == '/') )
- gAllImages.setMainPath(mainPath);
-
- // ok to call before malloc is ready because 4 slots are reserved.
- gAllImages.setInitialGroups();
+ gAllImages.applyInterposingToDyldCache(closure);
// run initializer for libSytem.B.dylib
// this calls back into _dyld_initializer which calls gAllIimages.addImages()
- gAllImages.runLibSystemInitializer(libSystemMH, libSystemImage);
+ gAllImages.runLibSystemInitializer(libSystem);
// now that malloc is available, parse DYLD_ env vars
- gPathOverrides.setEnvVars((const char**)environ);
+ closure::gPathOverrides.setEnvVars((const char**)environ, gAllImages.mainExecutable(), gAllImages.mainExecutableImage()->path());
}
static void entry_runInitialzersBottomUp(const mach_header* mainExecutableImageLoadAddress)
{
- gAllImages.runInitialzersBottomUp(mainExecutableImageLoadAddress);
+ gAllImages.runStartupInitialzers();
+#if !TARGET_OS_DRIVERKIT
gAllImages.notifyMonitorMain();
+#endif
}
static void entry_setChildForkFunction(void (*func)() )
@@ -124,24 +134,62 @@
sChildForkFunction = func;
}
-typedef void (*StartFunc)();
+static void entry_setRestrictions(bool allowAtPaths, bool allowEnvPaths, bool allowFallbackPaths)
+{
+ gAllImages.setRestrictions(allowAtPaths, allowEnvPaths);
+ closure::gPathOverrides.setFallbackPathHandling(allowFallbackPaths ?
+ dyld3::closure::PathOverrides::FallbackPathMode::classic :
+ dyld3::closure::PathOverrides::FallbackPathMode::restricted);
+}
+
+static void entry_setHasCacheOverrides(bool someCacheImageOverriden)
+{
+ gAllImages.setHasCacheOverrides(someCacheImageOverriden);
+}
+
+
+static void entry_setProgramVars(ProgramVars* progVars)
+{
+ gAllImages.setProgramVars((AllImages::ProgramVars*)progVars);
+}
+
+static_assert((closure::kFormatVersion & LibDyldEntryVector::kBinaryFormatVersionMask) == closure::kFormatVersion, "binary format version overflow");
const LibDyldEntryVector entryVectorForDyld = {
LibDyldEntryVector::kCurrentVectorVersion,
- launch_cache::binary_format::kFormatVersion,
+ closure::kFormatVersion,
&entry_setVars,
&entry_setHaltFunction,
&entry_setOldAllImageInfo,
&entry_setInitialImageList,
&entry_runInitialzersBottomUp,
- (StartFunc)address_of_start,
+ (__typeof(LibDyldEntryVector::startFunc))address_of_start,
&entry_setChildForkFunction,
&entry_setLogFunction,
+ &entry_setRestrictions,
+ &entry_setNotifyMonitoringDyldMain,
+ &entry_setNotifyMonitoringDyld,
+ &entry_setHasCacheOverrides,
+ &entry_setProgramVars,
};
+
+VIS_HIDDEN void _dyld_atfork_prepare()
+{
+ gAllImages.takeLockBeforeFork();
+}
+
+VIS_HIDDEN void _dyld_atfork_parent()
+{
+ gAllImages.releaseLockInForkParent();
+}
VIS_HIDDEN void _dyld_fork_child()
{
+ // Note the child fork function updates the data structures inside dyld
(*sChildForkFunction)();
+
+ // And we then need to update the structures for dyld3 in libdyld
+ gAllImages.resetLockInForkChild();
}