this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

multilib support improvements for binfmt_misc registration

+66 -8
+7 -4
src/dyld/MachOLoader.cpp
··· 49 49 50 50 char g_darwin_loader_path[PATH_MAX] = ""; 51 51 52 - extern char g_darwin_executable_path[PATH_MAX]; 52 + extern char g_darwin_executable_path[PATH_MAX], g_darwin_executable[PATH_MAX]; 53 53 extern bool g_trampoline; 54 54 extern bool g_noWeak; 55 55 extern std::set<LoaderHookFunc*> g_machoLoaderHooks; ··· 582 582 583 583 void MachOLoader::pushCurrentLoader(const char* currentLoader) 584 584 { 585 - m_loaderPath.push(currentLoader); 585 + char path[4096]; 586 + strcpy(path, currentLoader); 587 + // @loader_path contains the directory where the Mach-O file currently loading other libraries resides 588 + m_loaderPath.push(dirname(path)); 586 589 } 587 590 588 591 void MachOLoader::popCurrentLoader() ··· 757 760 758 761 void MachOLoader::run(MachO& mach, int argc, char** argv, char** envp, bool bindLazy) 759 762 { 760 - char* apple[2] = { g_darwin_executable_path, 0 }; 763 + char* apple[2] = { g_darwin_executable, 0 }; 761 764 std::vector<char*> envCopy; 762 765 763 766 //for (int i = 0; envp[i]; i++) ··· 765 768 envCopy.push_back(0); 766 769 767 770 m_mainExports = new Exports; 768 - load(mach, g_darwin_executable_path, m_mainExports, true, bindLazy); 771 + load(mach, g_darwin_executable, m_mainExports, true, bindLazy); 769 772 setupDyldData(mach); 770 773 771 774 g_file_map.addWatchDog(m_last_addr + 1);
+11 -2
src/dyld/binfmt_misc.cpp
··· 39 39 40 40 #if defined(__x86_64__) || defined(__powerpc64__) 41 41 reg << ":Mach-O 64bit:M::\\xcf\\xfa\\xed\\xfe::" << loader << ":\n"; 42 - #elif defined(__i386__) || defined(__powerpc__) 42 + #elif defined(__i386__) || defined(__powerpc__) || defined(__arm__) 43 43 reg << ":Mach-O 32bit:M::\\xce\\xfa\\xed\\xfe::" << loader << ":\n"; 44 44 #else 45 45 # error Unuspported platform ··· 47 47 reg.close(); 48 48 49 49 // In multilib environments, register FAT Mach-O files with dyld64 only 50 - #if !defined(MULTILIB) || defined(__x86_64__) 50 + #if !defined(MULTILIB) 51 51 reg.open("/proc/sys/fs/binfmt_misc/register"); 52 52 reg << ":Mach-O Universal:M::\\xca\\xfe\\xba\\xbe::" << loader << ":\n"; 53 53 reg.close(); 54 + #elif defined(__x86_64__) || defined(__powerpc64__) 55 + { 56 + std::string universalLoader = loader; 57 + universalLoader.resize(universalLoader.size() - 2); 58 + 59 + reg.open("/proc/sys/fs/binfmt_misc/register"); 60 + reg << ":Mach-O Universal:M::\\xca\\xfe\\xba\\xbe::" << universalLoader.c_str() << ":\n"; 61 + reg.close(); 62 + } 54 63 #endif 55 64 } 56 65
+45
src/dyld/dyld-multilib.c
··· 1 1 #include <sys/types.h> 2 2 #include <sys/stat.h> 3 + #include <sys/wait.h> 3 4 #include <fcntl.h> 4 5 #include <stdint.h> 5 6 #include <unistd.h> ··· 8 9 #include <string.h> 9 10 #include <stdlib.h> 10 11 #include <stdbool.h> 12 + #include <limits.h> 11 13 12 14 struct fat_arch 13 15 { ··· 20 22 21 23 void junction(const char* target, int argc, char** argv); 22 24 const char* decideFat(int fd, bool swapEndian); 25 + int registerDeregister(const char* argv0, bool reg); 26 + int registerDeregisterRun(const char* argv0, const char* bits, bool reg); 23 27 24 28 int main(int argc, char** argv) 25 29 { 26 30 uint32_t signature; 27 31 int fd; 28 32 const char* target = "64"; 33 + bool reg; 34 + 35 + if (argc == 2 && (reg = !strcmp(argv[1], "--register") || !strcmp(argv[1], "--deregister"))) 36 + return registerDeregister(argv[0], reg); 29 37 30 38 fd = open(argv[1], O_RDONLY | O_CLOEXEC); 31 39 ··· 98 106 return rv; 99 107 } 100 108 109 + int registerDeregister(const char* argv0, bool reg) 110 + { 111 + int ec, rv = 0; 112 + 113 + if ((ec = registerDeregisterRun(argv0, "64", reg))) 114 + rv = ec; 115 + if ((ec = registerDeregisterRun(argv0, "32", reg))) 116 + rv = ec; 117 + 118 + return rv; 119 + } 120 + 121 + int registerDeregisterRun(const char* argv0, const char* bits, bool reg) 122 + { 123 + char path[PATH_MAX]; 124 + const char* argument = (reg) ? "--register" : "--deregister"; 125 + 126 + strncpy(path, argv0, PATH_MAX-1); 127 + path[PATH_MAX-1] = 0; 128 + 129 + strcat(path, bits); 130 + 131 + if (!fork()) 132 + { 133 + execl(path, path, argument, NULL); 134 + exit(1); 135 + } 136 + else 137 + { 138 + int status; 139 + 140 + wait(&status); 141 + return WEXITSTATUS(status); 142 + } 143 + } 144 + 145 +
+3 -2
src/dyld/dyld.cpp
··· 38 38 #include <darwin/mach/machine.h> 39 39 40 40 char g_darwin_executable_path[4096] = ""; 41 + char g_darwin_executable[4096] = ""; 41 42 char g_dyld_path[4096] = ""; 42 43 char g_sysroot[4096] = ""; 43 44 bool g_trampoline = false; ··· 171 172 172 173 extern "C" const char* dyld_getDarwinExecutablePath() 173 174 { 174 - return g_darwin_executable_path; 175 + return g_darwin_executable; 175 176 } 176 177 177 178 extern "C" const char* dyld_getLoaderPath() ··· 189 190 return; 190 191 } 191 192 192 - // @executable_path should point to the directory containing the main executable file 193 + ::strcpy(g_darwin_executable, path); 193 194 ::strcpy(g_darwin_executable_path, dirname(path)); 194 195 LOG << "@executable_path is " << g_darwin_executable_path << std::endl; 195 196 }