this repo has no description
1
fork

Configure Feed

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

Initial work on Darling prefixes

+950 -100
+3
src/dyld/CMakeLists.txt
··· 39 39 add_executable(dyldd dyldd.cpp) 40 40 target_link_libraries(dyldd dyld darling-util mach-o) 41 41 install(TARGETS dyldd DESTINATION bin) 42 + install(PROGRAMS darling DESTINATION bin 43 + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ 44 + GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) 42 45 #endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") 43 46 44 47 install(TARGETS dyld-bin DESTINATION bin)
+90
src/dyld/darling
··· 1 + #!/bin/sh 2 + # 3 + # This file is part of Darling. 4 + # 5 + # Copyright (C) 2015 Lubos Dolezel 6 + # 7 + # Darling is free software: you can redistribute it and/or modify 8 + # it under the terms of the GNU General Public License as published by 9 + # the Free Software Foundation, either version 3 of the License, or 10 + # (at your option) any later version. 11 + # 12 + # Darling is distributed in the hope that it will be useful, 13 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + # GNU General Public License for more details. 16 + # 17 + # You should have received a copy of the GNU General Public License 18 + # along with Darling. If not, see <http://www.gnu.org/licenses/>. 19 + # 20 + 21 + SYSTEM_ROOT_NAME="system-root" 22 + BIND_DIRECTORIES="dev etc home tmp" 23 + MAKE_DIRECTORIES="Applications Volumes" 24 + 25 + if [ $# -eq 0 ]; then 26 + >&2 echo "This is Darling, a runtime environment for OS X applications." 27 + >&2 echo 28 + >&2 echo "Copyright (C) 2012-2015 Lubos Dolezel" 29 + >&2 echo "Includes software components which are Copyright (C) Apple Computer, Inc. and many others." 30 + >&2 echo 31 + >&2 echo -e "Usage:\tdarling PROGRAM [ARGUMENTS...]\tRun the specified program" 32 + >&2 echo -e "\tdarling shell\t\t\tStart bash shell in prefix" 33 + >&2 echo -e "\tdarling hdiutil\t\t\tMount DMG disk images" 34 + >&2 echo -e "\tdarling pkgutil\t\t\tInstall PKG packages" 35 + >&2 echo 36 + >&2 echo "The prefix is specified by the DPREFIX environment variable." 37 + >&2 echo "The default DPREFIX is \$HOME/.darling" 38 + exit 1 39 + fi 40 + 41 + set -e 42 + 43 + if [ -z "$DPREFIX" ]; then 44 + export DPREFIX="$HOME/.darling" 45 + fi 46 + 47 + if [ ! -d "$DPREFIX" ]; then 48 + >&2 echo "Setting up prefix at $DPREFIX" 49 + 50 + mkdir -p "${DPREFIX}" 51 + pushd "${DPREFIX}" >/dev/null 52 + 53 + ln -s / "${SYSTEM_ROOT_NAME}" 54 + for dir in ${BIND_DIRECTORIES}; do 55 + ln -s "${SYSTEM_ROOT_NAME}/${dir}" "${dir}" 56 + done 57 + 58 + for dir in ${MAKE_DIRECTORIES}; do 59 + mkdir "${dir}" 60 + done 61 + 62 + ln -s home Users 63 + 64 + # TODO: install bash and coreutils 65 + 66 + popd >/dev/null 67 + fi 68 + 69 + dyld_path="${0%darling}dyld" 70 + 71 + case "$1" in 72 + "shell") 73 + if [ $# -gt 2 ]; then 74 + exec "${dyld_path}" /usr/local/bin/bash -c "${*:2}" 75 + else 76 + exec "${dyld_path}" /usr/local/bin/bash 77 + fi 78 + ;; 79 + "hdiutil") 80 + >2& echo "Not implemented yet" 81 + exit 1 82 + ;; 83 + "pkgutil") 84 + >2& echo "Not implemented yet" 85 + exit 1 86 + ;; 87 + *) 88 + exec "${dyld_path}" "$1" "${@:2}" 89 + ;; 90 + esac
+19
src/dyld/dirstructure.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "dirstructure.h" 2 21 #include <sstream> 3 22 #include <unistd.h>
+19
src/dyld/dirstructure.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef DIRSTRUCTURE_H 2 21 #define DIRSTRUCTURE_H 3 22
+19
src/dyld/dyld-multilib.c
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include <sys/types.h> 2 21 #include <sys/stat.h> 3 22 #include <sys/wait.h>
+23 -1
src/dyld/dyld.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include <libdyld/MachOMgr.h> 2 21 #include <libdyld/MachOObject.h> 3 22 #include <iostream> ··· 10 29 #include <libdyld/arch.h> 11 30 #include <regex> 12 31 #include "dirstructure.h" 32 + #include <libdyld/VirtualPrefix.h> 13 33 14 34 static void printHelp(const char* argv0); 15 35 static std::string locateBundleExecutable(std::string bundlePath); ··· 57 77 mgr->setSysRoot(path); 58 78 if (const char* path = getenv("DYLD_TRAMPOLINE")) 59 79 mgr->setUseTrampolines(true, path); 80 + if (const char* path = getenv("DPREFIX")) 81 + __prefix_set(path); 60 82 61 - obj = new MachOObject(argv[1]); 83 + obj = new MachOObject(__prefix_translate_path(argv[1])); 62 84 if (!obj->isMainModule()) 63 85 { 64 86 throw std::runtime_error("This is not a Mach-O executable; dynamic libraries, "
+24 -1
src/dyld/dyldd.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include <libdyld/DylibSearch.h> 2 21 #include <libdyld/MachOMgr.h> 3 22 #include <libdyld/MachOObject.h> ··· 9 28 #include <unistd.h> 10 29 #include <cstdlib> 11 30 #include <cstring> 31 + #include <libdyld/VirtualPrefix.h> 12 32 13 33 #define ANSI_COLOR_RED "\x1b[31m" 14 34 #define ANSI_COLOR_GREEN "\x1b[32m" ··· 37 57 MachOMgr* mgr = MachOMgr::instance(); 38 58 39 59 mgr->detectSysRootFromPath(argv[1]); 60 + if (const char* path = getenv("DPREFIX")) 61 + __prefix_set(path); 62 + 40 63 mgr->setLoadAnyArchitecture(true); 41 64 42 - obj = new MachOObject(argv[1]); 65 + obj = new MachOObject(__prefix_translate_path(argv[1])); 43 66 44 67 mgr->add(obj, true); 45 68
+11 -1
src/kernel/emulation/linux/dirent/getdirentries.c
··· 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 5 #include <sys/dirent.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 - extern unsigned long strlen(const char* s); 8 + extern __SIZE_TYPE__ strlen(const char* s); 8 9 extern char* strcpy(char* dest, const char* src); 10 + extern int strcmp(const char* str1, const char* str2); 9 11 10 12 #ifndef min 11 13 # define min(a,b) ((a) < (b)) ? (a) : (b) ··· 49 51 bsd->d_ino = l64->d_ino; 50 52 bsd->d_type = l64->d_type; 51 53 strcpy(bsd->d_name, l64->d_name); 54 + 55 + if (strcmp(l64->d_name, __SYSTEM_ROOT+1) == 0) 56 + bsd->d_type = DT_DIR; 57 + 52 58 bsd->d_reclen = sizeof(struct bsd_dirent) + slen + 1; 53 59 bsd->d_namlen = slen; 54 60 ··· 91 97 bsd->d_ino = l64->d_ino; 92 98 bsd->d_type = l64->d_type; 93 99 strcpy(bsd->d_name, l64->d_name); 100 + 101 + if (strcmp(l64->d_name, __SYSTEM_ROOT+1) == 0) 102 + bsd->d_type = DT_DIR; 103 + 94 104 bsd->d_reclen = sizeof(struct bsd_dirent64) + slen + 1; 95 105 bsd->d_namlen = slen; 96 106 bsd->d_seekoff = 0;
+3 -3
src/kernel/emulation/linux/fcntl/open.c
··· 4 4 #include <asm/unistd.h> 5 5 //#include "../../../../platform-include/sys/fcntl.h" 6 6 #include "../../../../libc/include/fcntl.h" 7 + #include <libdyld/VirtualPrefix.h> 7 8 8 9 #ifndef O_NOFOLLOW 9 10 # define O_NOFOLLOW 0x0100 ··· 35 36 linux_flags |= LINUX_O_LARGEFILE; 36 37 } 37 38 38 - // TODO: Check filename, handle wrong case 39 - 40 39 // XNU /dev/random behaves like Linux /dev/urandom 41 40 if (strcmp(filename, "/dev/random") == 0) 42 41 filename = "/dev/urandom"; 43 42 44 - ret = LINUX_SYSCALL(__NR_open, filename, linux_flags, mode); 43 + ret = LINUX_SYSCALL(__NR_open, __prefix_translate_path(filename), 44 + linux_flags, mode); 45 45 if (ret < 0) 46 46 ret = errno_linux_to_bsd(ret); 47 47
+3 -4
src/kernel/emulation/linux/process/execve.c
··· 7 7 #include "../unistd/close.h" 8 8 #include "../unistd/readlink.h" 9 9 #include <stdint.h> 10 + #include <libdyld/VirtualPrefix.h> 10 11 11 12 #define MH_MAGIC 0xfeedface 12 13 #define MH_CIGAM 0xcefaedfe ··· 43 44 int len, i; 44 45 char** modargvp; 45 46 46 - len = sys_readlink("/proc/self/exe", dyld_path, sizeof(dyld_path)-1); 47 + len = __prefix_get_dyld_path(dyld_path, sizeof(dyld_path)-1); 47 48 if (len < 0) 48 49 goto no_macho; 49 - 50 - dyld_path[len] = '\0'; 51 50 52 51 // Remove 64 or 32 suffix if present 53 52 if (strcmp(&dyld_path[len - 2], "32") == 0 ··· 65 64 // Allocate a new argvp, execute dyld_path 66 65 modargvp = (char**) __builtin_alloca(sizeof(void*) * (len+1)); 67 66 modargvp[0] = dyld_path; 68 - modargvp[1] = fname; 67 + modargvp[1] = __prefix_translate_path(fname); 69 68 70 69 for (i = 2; i < len+1; i++) 71 70 modargvp[i] = argvp[i-1];
+9 -8
src/kernel/emulation/linux/stat/lstat.c
··· 3 3 #include "../base.h" 4 4 #include "../errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 long sys_lstat(const char* path, struct stat* stat) 8 9 { 9 10 int ret; 10 11 struct linux_stat lstat; 11 12 12 - // TODO: handle case conversion 13 - 14 13 #ifdef __NR_lstat64 15 - ret = LINUX_SYSCALL(__NR_lstat64, path, &lstat); 14 + ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat); 16 15 #else 17 - ret = LINUX_SYSCALL(__NR_lstat, path, &lstat); 16 + ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat); 18 17 #endif 19 18 20 19 if (ret < 0) 21 20 return errno_linux_to_bsd(ret); 21 + else if (__prefix_is_system_root(path)) 22 + lstat.st_mode = (lstat.st_mode & ~0120000) | 0040000; // make directory 22 23 23 24 stat_linux_to_bsd(&lstat, stat); 24 25 ··· 30 31 int ret; 31 32 struct linux_stat lstat; 32 33 33 - // TODO: handle case conversion 34 - 35 34 #ifdef __NR_lstat64 36 - ret = LINUX_SYSCALL(__NR_lstat64, path, &lstat); 35 + ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat); 37 36 #else 38 - ret = LINUX_SYSCALL(__NR_lstat, path, &lstat); 37 + ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat); 39 38 #endif 40 39 41 40 if (ret < 0) 42 41 return errno_linux_to_bsd(ret); 42 + else if (__prefix_is_system_root(path)) 43 + lstat.st_mode = (lstat.st_mode & ~0120000) | 0040000; // make directory 43 44 44 45 stat_linux_to_bsd64(&lstat, stat); 45 46
+2 -3
src/kernel/emulation/linux/stat/mkdir.c
··· 3 3 #include "../base.h" 4 4 #include "../errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 long sys_mkdir(const char* path, unsigned int mode) 8 9 { 9 10 int ret; 10 11 11 - // TODO: handle case conversion 12 - 13 - ret = LINUX_SYSCALL(__NR_mkdir, path, mode); 12 + ret = LINUX_SYSCALL(__NR_mkdir, __prefix_translate_path(path), mode); 14 13 15 14 if (ret < 0) 16 15 return errno_linux_to_bsd(ret);
+3 -3
src/kernel/emulation/linux/stat/mkfifo.c
··· 3 3 #include "../base.h" 4 4 #include "../errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 #define LINUX_S_IFIFO 0010000 8 9 ··· 10 11 { 11 12 int ret; 12 13 13 - // TODO: handle case conversion 14 - 15 - ret = LINUX_SYSCALL(__NR_mknod, path, mode | LINUX_S_IFIFO, 0); 14 + ret = LINUX_SYSCALL(__NR_mknod, __prefix_translate_path(path), 15 + mode | LINUX_S_IFIFO, 0); 16 16 17 17 if (ret < 0) 18 18 return errno_linux_to_bsd(ret);
+2 -3
src/kernel/emulation/linux/stat/rmdir.c
··· 3 3 #include "../base.h" 4 4 #include "../errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 long sys_rmdir(const char* path) 8 9 { 9 10 int ret; 10 11 11 - // TODO: handle case conversion 12 - 13 - ret = LINUX_SYSCALL(__NR_rmdir, path); 12 + ret = LINUX_SYSCALL(__NR_rmdir, __prefix_translate_path(path)); 14 13 15 14 if (ret < 0) 16 15 return errno_linux_to_bsd(ret);
+9 -8
src/kernel/emulation/linux/stat/stat.c
··· 3 3 #include "../base.h" 4 4 #include "../errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 long sys_stat(const char* path, struct stat* stat) 8 9 { 9 10 int ret; 10 11 struct linux_stat lstat; 11 12 12 - // TODO: handle case conversion 13 - 14 13 #ifdef __NR_stat64 15 - ret = LINUX_SYSCALL(__NR_stat64, path, &lstat); 14 + ret = LINUX_SYSCALL(__NR_stat64, __prefix_translate_path(path), &lstat); 16 15 #else 17 - ret = LINUX_SYSCALL(__NR_stat, path, &lstat); 16 + ret = LINUX_SYSCALL(__NR_stat, __prefix_translate_path(path), &lstat); 18 17 #endif 19 18 20 19 if (ret < 0) 21 20 return errno_linux_to_bsd(ret); 21 + else if (__prefix_is_system_root(path)) 22 + lstat.st_mode = (lstat.st_mode & ~0120000) | 0040000; // make directory 22 23 23 24 stat_linux_to_bsd(&lstat, stat); 24 25 ··· 30 31 int ret; 31 32 struct linux_stat lstat; 32 33 33 - // TODO: handle case conversion 34 - 35 34 #ifdef __NR_stat64 36 - ret = LINUX_SYSCALL(__NR_stat64, path, &lstat); 35 + ret = LINUX_SYSCALL(__NR_stat64, __prefix_translate_path(path), &lstat); 37 36 #else 38 - ret = LINUX_SYSCALL(__NR_stat, path, &lstat); 37 + ret = LINUX_SYSCALL(__NR_stat, __prefix_translate_path(path), &lstat); 39 38 #endif 40 39 41 40 if (ret < 0) 42 41 return errno_linux_to_bsd(ret); 42 + else if (__prefix_is_system_root(path)) 43 + lstat.st_mode = (lstat.st_mode & ~0120000) | 0040000; // make directory 43 44 44 45 stat_linux_to_bsd64(&lstat, stat); 45 46
+4 -2
src/kernel/emulation/linux/unistd/chdir.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_chdir(const char* path) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 - 11 + path = __prefix_translate_path(path); 12 12 ret = LINUX_SYSCALL(__NR_chdir, path); 13 13 if (ret < 0) 14 14 ret = errno_linux_to_bsd(ret); 15 + else 16 + __prefix_cwd(path); 15 17 16 18 return ret; 17 19 }
+2 -3
src/kernel/emulation/linux/unistd/chmod.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_chmod(const char* path, int mode) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 - 12 - ret = LINUX_SYSCALL(__NR_chmod, path, mode); 11 + ret = LINUX_SYSCALL(__NR_chmod, __prefix_translate_path(path), mode); 13 12 if (ret < 0) 14 13 ret = errno_linux_to_bsd(ret); 15 14
+3 -3
src/kernel/emulation/linux/unistd/chown.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_chown(const char* path, int uid, int gid) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 11 #ifdef __NR_chown32 12 - ret = LINUX_SYSCALL(__NR_chown32, path, uid, gid); 12 + ret = LINUX_SYSCALL(__NR_chown32, __prefix_translate_path(path), uid, gid); 13 13 #else 14 - ret = LINUX_SYSCALL(__NR_chown, path, uid, gid); 14 + ret = LINUX_SYSCALL(__NR_chown, __prefix_translate_path(path), uid, gid); 15 15 #endif 16 16 if (ret < 0) 17 17 ret = errno_linux_to_bsd(ret);
+3 -2
src/kernel/emulation/linux/unistd/chroot.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_chroot(const char* path) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 + // TODO: should we support chroot with virtual prefixes? 11 12 12 - ret = LINUX_SYSCALL(__NR_chroot, path); 13 + ret = LINUX_SYSCALL(__NR_chroot, __prefix_translate_path(path)); 13 14 if (ret < 0) 14 15 ret = errno_linux_to_bsd(ret); 15 16
+3
src/kernel/emulation/linux/unistd/fchdir.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_fchdir(int fd) 7 8 { ··· 10 11 ret = LINUX_SYSCALL1(__NR_fchdir, fd); 11 12 if (ret < 0) 12 13 ret = errno_linux_to_bsd(ret); 14 + else 15 + __prefix_cwd_fd(fd); 13 16 14 17 return ret; 15 18 }
+3 -3
src/kernel/emulation/linux/unistd/lchown.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_lchown(const char* path, int uid, int gid) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 11 #ifdef __NR_chown32 12 - ret = LINUX_SYSCALL(__NR_lchown32, path, uid, gid); 12 + ret = LINUX_SYSCALL(__NR_lchown32, __prefix_translate_path(path), uid, gid); 13 13 #else 14 - ret = LINUX_SYSCALL(__NR_lchown, path, uid, gid); 14 + ret = LINUX_SYSCALL(__NR_lchown, __prefix_translate_path(path), uid, gid); 15 15 #endif 16 16 if (ret < 0) 17 17 ret = errno_linux_to_bsd(ret);
+12 -2
src/kernel/emulation/linux/unistd/link.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 6 + #include "../../../../../platform-include/sys/errno.h" 7 + 8 + extern char* strcpy(char* dst, const char* src); 5 9 6 10 long sys_link(const char* path, const char* link) 7 11 { 8 12 int ret; 13 + char resolved_path[1024]; 14 + char resolved_link[1024]; 15 + 16 + if (!path || !link) 17 + return -EINVAL; 9 18 10 - // TODO: case translation 19 + strcpy(resolved_path, __prefix_translate_path(path)); 20 + strcpy(resolved_link, __prefix_translate_path(link)); 11 21 12 - ret = LINUX_SYSCALL(__NR_link, path, link); 22 + ret = LINUX_SYSCALL(__NR_link, resolved_path, resolved_link); 13 23 if (ret < 0) 14 24 ret = errno_linux_to_bsd(ret); 15 25
+2 -3
src/kernel/emulation/linux/unistd/mknod.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_mknod(const char* path, int mode, int dev) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 - 12 - ret = LINUX_SYSCALL(__NR_mknod, path, mode, dev); 11 + ret = LINUX_SYSCALL(__NR_mknod, __prefix_translate_path(path), mode, dev); 13 12 if (ret < 0) 14 13 ret = errno_linux_to_bsd(ret); 15 14
+16 -3
src/kernel/emulation/linux/unistd/readlink.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 6 + 7 + extern __SIZE_TYPE__ strlen(const char* str); 5 8 6 9 long sys_readlink(const char* path, char* buf, int count) 7 10 { 8 11 int ret; 9 12 10 - // TODO: case translation 11 - 12 - ret = LINUX_SYSCALL(__NR_readlink, path, buf, count); 13 + ret = LINUX_SYSCALL(__NR_readlink, __prefix_translate_path(path), 14 + buf, count); 13 15 if (ret < 0) 14 16 ret = errno_linux_to_bsd(ret); 17 + else 18 + { 19 + const char* xl; 20 + __SIZE_TYPE__ newlen; 21 + 22 + xl = __prefix_untranslate_path(buf, ret); 23 + newlen = strlen(xl); 24 + 25 + memcpy(buf, xl, (newlen < count) ? newlen : count); 26 + ret = newlen; 27 + } 15 28 16 29 return ret; 17 30 }
+11 -2
src/kernel/emulation/linux/unistd/rename.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include "../../../../../platform-include/sys/errno.h" 6 + 7 + extern char* strcpy(char* dst, const char* src); 5 8 6 9 long sys_rename(const char* oldpath, const char* newpath) 7 10 { 8 11 int ret; 12 + char resolved_oldpath[1024]; 13 + char resolved_newpath[1024]; 14 + 15 + if (!oldpath || !newpath) 16 + return -EINVAL; 9 17 10 - // TODO: handle case conversion 18 + strcpy(resolved_oldpath, __prefix_translate_path(oldpath)); 19 + strcpy(resolved_newpath, __prefix_translate_path(newpath)); 11 20 12 - ret = LINUX_SYSCALL(__NR_rename, oldpath, newpath); 21 + ret = LINUX_SYSCALL(__NR_rename, resolved_oldpath, resolved_newpath); 13 22 14 23 if (ret < 0) 15 24 return errno_linux_to_bsd(ret);
+13 -3
src/kernel/emulation/linux/unistd/symlink.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 6 + #include "../../../../../platform-include/sys/errno.h" 7 + 8 + extern char* strcpy(char* dst, const char* src); 5 9 6 10 long sys_symlink(const char* path, const char* link) 7 11 { 8 12 int ret; 9 - 10 - // TODO: case translation 13 + char resolved_path[1024]; 14 + char resolved_link[1024]; 15 + 16 + if (!path || !link) 17 + return -EINVAL; 18 + 19 + strcpy(resolved_path, __prefix_translate_path(path)); 20 + strcpy(resolved_link, __prefix_translate_path(link)); 11 21 12 - ret = LINUX_SYSCALL(__NR_symlink, path, link); 22 + ret = LINUX_SYSCALL(__NR_symlink, resolved_path, resolved_link); 13 23 if (ret < 0) 14 24 ret = errno_linux_to_bsd(ret); 15 25
+5 -4
src/kernel/emulation/linux/unistd/truncate.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_truncate(const char* path, long long length) 7 8 { 8 9 int ret; 9 10 10 - // TODO: translate path 11 - 12 11 #ifdef __NR_truncate64 13 - ret = LINUX_SYSCALL(__NR_truncate64, path, LL_ARG(length)); 12 + ret = LINUX_SYSCALL(__NR_truncate64, __prefix_translate_path(path), 13 + LL_ARG(length)); 14 14 #else 15 - ret = LINUX_SYSCALL(__NR_truncate, path, LL_ARG(length)); 15 + ret = LINUX_SYSCALL(__NR_truncate, __prefix_translate_path(path), 16 + LL_ARG(length)); 16 17 #endif 17 18 if (ret < 0) 18 19 ret = errno_linux_to_bsd(ret);
+2 -3
src/kernel/emulation/linux/unistd/unlink.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 long sys_unlink(const char* path) 7 8 { 8 9 int ret; 9 10 10 - // TODO: case translation 11 - 12 - ret = LINUX_SYSCALL(__NR_unlink, path); 11 + ret = LINUX_SYSCALL(__NR_unlink, __prefix_translate_path(path)); 13 12 if (ret < 0) 14 13 ret = errno_linux_to_bsd(ret); 15 14
-2
src/kernel/emulation/linux/xattr/fgetxattr.c
··· 8 8 unsigned long size, unsigned int pos, int options) 9 9 { 10 10 int ret; 11 - 12 - // TODO: handle case conversion 13 11 14 12 if (pos != 0) 15 13 return -ERANGE;
-2
src/kernel/emulation/linux/xattr/flistxattr.c
··· 7 7 { 8 8 int ret; 9 9 10 - // TODO: handle case conversion 11 - 12 10 ret = LINUX_SYSCALL(__NR_flistxattr, fd, namebuf, size); 13 11 14 12 if (ret < 0)
-2
src/kernel/emulation/linux/xattr/fremovexattr.c
··· 7 7 { 8 8 int ret; 9 9 10 - // TODO: handle case conversion 11 - 12 10 ret = LINUX_SYSCALL(__NR_fremovexattr, fd, name); 13 11 14 12 if (ret < 0)
-2
src/kernel/emulation/linux/xattr/fsetxattr.c
··· 9 9 { 10 10 int ret; 11 11 12 - // TODO: handle case conversion 13 - 14 12 if (pos != 0) 15 13 return -ERANGE; 16 14
+5 -4
src/kernel/emulation/linux/xattr/getxattr.c
··· 3 3 #include "../errno.h" 4 4 #include "../../../../../platform-include/sys/errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 #define XATTR_NOFOLLOW 1 8 9 ··· 10 11 unsigned long size, unsigned int pos, int options) 11 12 { 12 13 int ret; 13 - 14 - // TODO: handle case conversion 15 14 16 15 if (pos != 0) 17 16 return -ERANGE; 18 17 19 18 if (options & XATTR_NOFOLLOW) 20 - ret = LINUX_SYSCALL(__NR_lgetxattr, path, name, value, size); 19 + ret = LINUX_SYSCALL(__NR_lgetxattr, __prefix_translate_path(path), 20 + name, value, size); 21 21 else 22 - ret = LINUX_SYSCALL(__NR_getxattr, path, name, value, size); 22 + ret = LINUX_SYSCALL(__NR_getxattr, __prefix_translate_path(path), 23 + name, value, size); 23 24 24 25 if (ret < 0) 25 26 return errno_linux_to_bsd(ret);
+5 -4
src/kernel/emulation/linux/xattr/listxattr.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 #define XATTR_NOFOLLOW 1 7 8 ··· 9 10 { 10 11 int ret; 11 12 12 - // TODO: handle case conversion 13 - 14 13 if (options & XATTR_NOFOLLOW) 15 - ret = LINUX_SYSCALL(__NR_llistxattr, path, namebuf, size); 14 + ret = LINUX_SYSCALL(__NR_llistxattr, __prefix_translate_path(path), 15 + namebuf, size); 16 16 else 17 - ret = LINUX_SYSCALL(__NR_listxattr, path, namebuf, size); 17 + ret = LINUX_SYSCALL(__NR_listxattr, __prefix_translate_path(path), 18 + namebuf, size); 18 19 19 20 if (ret < 0) 20 21 return errno_linux_to_bsd(ret);
+5 -4
src/kernel/emulation/linux/xattr/removexattr.c
··· 2 2 #include "../base.h" 3 3 #include "../errno.h" 4 4 #include <asm/unistd.h> 5 + #include <libdyld/VirtualPrefix.h> 5 6 6 7 #define XATTR_NOFOLLOW 1 7 8 ··· 9 10 { 10 11 int ret; 11 12 12 - // TODO: handle case conversion 13 - 14 13 if (options & XATTR_NOFOLLOW) 15 - ret = LINUX_SYSCALL(__NR_lremovexattr, path, name); 14 + ret = LINUX_SYSCALL(__NR_lremovexattr, __prefix_translate_path(path), 15 + name); 16 16 else 17 - ret = LINUX_SYSCALL(__NR_removexattr, path, name); 17 + ret = LINUX_SYSCALL(__NR_removexattr, __prefix_translate_path(path), 18 + name); 18 19 19 20 if (ret < 0) 20 21 return errno_linux_to_bsd(ret);
+9 -4
src/kernel/emulation/linux/xattr/setxattr.c
··· 3 3 #include "../errno.h" 4 4 #include "../../../../../platform-include/sys/errno.h" 5 5 #include <asm/unistd.h> 6 + #include <libdyld/VirtualPrefix.h> 6 7 7 8 #define XATTR_NOFOLLOW 1 8 9 ··· 11 12 { 12 13 int ret; 13 14 14 - // TODO: handle case conversion 15 - 16 15 if (pos != 0) 17 16 return -ERANGE; 18 17 19 18 if (options & XATTR_NOFOLLOW) 20 - ret = LINUX_SYSCALL(__NR_lsetxattr, path, name, value, size); 19 + { 20 + ret = LINUX_SYSCALL(__NR_lsetxattr, __prefix_translate_path(path), 21 + name, value, size); 22 + } 21 23 else 22 - ret = LINUX_SYSCALL(__NR_setxattr, path, name, value, size); 24 + { 25 + ret = LINUX_SYSCALL(__NR_setxattr, __prefix_translate_path(path), 26 + name, value, size); 27 + } 23 28 24 29 if (ret < 0) 25 30 return errno_linux_to_bsd(ret);
+1
src/libdyld/CMakeLists.txt
··· 38 38 DylibSearch.cpp 39 39 environ.c 40 40 threads.cpp 41 + VirtualPrefix.cpp 41 42 ) 42 43 43 44 #if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
+51 -5
src/libdyld/DylibSearch.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "DylibSearch.h" 2 21 #include "darling-config.h" 3 22 #include <stdexcept> 4 23 #include <iostream> 5 24 #include "MachOObject.h" 6 25 #include "MachOMgr.h" 26 + #include "VirtualPrefix.h" 7 27 #include <regex.h> 8 28 #include <unistd.h> 9 29 #include <util/stlutils.h> ··· 101 121 return epath; 102 122 103 123 // If absolute, search in sysroot 104 - if (dylib[0] == '/' && !MachOMgr::instance()->sysRoot().empty()) 124 + if (dylib[0] == '/') 105 125 { 106 - std::vector<std::string> roots = string_explode(MachOMgr::instance()->sysRoot(), ':'); 126 + const char* prefix = __prefix_get(); 107 127 108 - for (std::string path : roots) 128 + if (!MachOMgr::instance()->sysRoot().empty()) 109 129 { 110 - path += '/'; 130 + std::vector<std::string> roots = string_explode(MachOMgr::instance()->sysRoot(), ':'); 131 + 132 + for (const std::string& in_path : roots) 133 + { 134 + std::string path; 135 + 136 + if (prefix != nullptr) 137 + path = prefix; 138 + 139 + path += in_path; 140 + path += '/'; 141 + path += dylib; 142 + 143 + epath = checkPresence(path); 144 + if (!epath.empty()) 145 + return epath; 146 + } 147 + } 148 + if (prefix != nullptr) 149 + { 150 + std::string path = prefix; 111 151 path += dylib; 112 152 113 153 epath = checkPresence(path); ··· 157 197 158 198 std::string DylibSearch::resolveInPathList(std::string name, const std::vector<std::string>& paths) 159 199 { 200 + const char* prefix = __prefix_get(); 160 201 for (const std::string& e : paths) 161 202 { 162 - std::string path = e + "/" + name; 203 + std::string path; 204 + 205 + if (prefix) 206 + path = prefix; 207 + 208 + path += e + "/" + name; 163 209 164 210 if (::access(path.c_str(), F_OK) == 0) 165 211 return path;
+19
src/libdyld/MachOMgr.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "MachOMgr.h" 2 21 #include <cassert> 3 22 #include <algorithm>
+20 -1
src/libdyld/MachOMgr.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef MACHOMGR_H 2 21 #define MACHOMGR_H 3 22 #include <stdint.h> ··· 114 133 inline bool loadAnyArchitecture() const { return m_loadAny; } 115 134 116 135 bool detectSysRootFromPath(std::string path); 117 - inline void setSysRoot(const std::string& sysroot) { m_sysroot = sysroot; } 136 + inline void setSysRoot(std::string sysroot) { m_sysroot = sysroot; } 118 137 inline const std::string& sysRoot() const { return m_sysroot; } 119 138 inline bool hasSysRoot() const { return !m_sysroot.empty(); } 120 139
+19
src/libdyld/MachOObject.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "dl_public.h" 2 21 #include "MachOObject.h" 3 22 #include <limits>
+19
src/libdyld/MachOObject.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef MACHOOBJECT_H 2 21 #define MACHOOBJECT_H 3 22 #include <libmach-o/MachO.h>
+19
src/libdyld/NativeObject.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "NativeObject.h" 2 21 #include <dlfcn.h> 3 22 #include <sstream>
+19
src/libdyld/NativeObject.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef NATIVEOBJECT_H 2 21 #define NATIVEOBJECT_H 3 22 #include <string>
+263
src/libdyld/VirtualPrefix.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "VirtualPrefix.h" 21 + #include <string> 22 + #include <cstring> 23 + #include <pthread.h> 24 + #include <list> 25 + #include <cassert> 26 + #include <unistd.h> 27 + #include <iostream> 28 + #include <cstdio> 29 + 30 + static std::string g_prefix; 31 + static std::string g_cwd; 32 + static pthread_rwlock_t g_cwdLock = PTHREAD_RWLOCK_INITIALIZER; 33 + static const char SYSTEM_ROOT[] = __SYSTEM_ROOT; 34 + 35 + static std::string canonicalize_path(const std::string& in_path); 36 + 37 + void __prefix_set(const char* path) 38 + { 39 + char cwd[256]; 40 + 41 + getcwd(cwd, sizeof(cwd)); 42 + 43 + g_prefix = path; 44 + if (g_prefix[g_prefix.length()-1] != '/') 45 + g_prefix += '/'; 46 + 47 + if (strncmp(cwd, path, strlen(path)) == 0) 48 + { 49 + g_cwd = path + strlen(path); 50 + if (g_cwd.empty()) 51 + g_cwd = "/"; 52 + } 53 + else 54 + { 55 + g_cwd = SYSTEM_ROOT; 56 + g_cwd += cwd; 57 + g_cwd += '/'; 58 + } 59 + } 60 + 61 + const char* __prefix_get(void) 62 + { 63 + if (g_prefix.empty()) 64 + return nullptr; 65 + else 66 + return g_prefix.c_str(); 67 + } 68 + 69 + const char* __prefix_translate_path(const char* path) 70 + { 71 + static thread_local char resolved_path[1024]; 72 + std::string str; 73 + 74 + if (g_prefix.empty()) 75 + return path; 76 + 77 + if (path[0] != '/') 78 + { 79 + pthread_rwlock_rdlock(&g_cwdLock); 80 + str = g_cwd; 81 + pthread_rwlock_unlock(&g_cwdLock); 82 + } 83 + str += path; 84 + 85 + // Resolve . and .. 86 + str = canonicalize_path(str); 87 + 88 + // std::cout << "CWD: " << g_cwd << std::endl; 89 + // std::cout << "Can1: " << path << " -> " << str << std::endl; 90 + if (str.compare(0, sizeof(SYSTEM_ROOT)-1, SYSTEM_ROOT) == 0) 91 + { 92 + // Leave virtual prefix 93 + str = str.substr(sizeof(SYSTEM_ROOT)-1); 94 + if (str.empty()) 95 + str = "/"; 96 + } 97 + else if (str.compare(0, 5, "/proc") != 0) 98 + { 99 + // Apply virtual prefix 100 + str = g_prefix + str; 101 + } 102 + 103 + // std::cout << "Can2: " << path << " -> " << str << std::endl; 104 + 105 + // TODO: make case insensitive 106 + 107 + strncpy(resolved_path, str.c_str(), sizeof(resolved_path)-1); 108 + resolved_path[sizeof(resolved_path)-1] = '\0'; 109 + 110 + return resolved_path; 111 + } 112 + 113 + const char* __prefix_untranslate_path(const char* path, unsigned long count) 114 + { 115 + static thread_local char resolved_path[1024]; 116 + size_t test_len; 117 + 118 + // FIXME: The following strcmp is a bit of a hack needed for isatty() 119 + // and friends. 120 + if (g_prefix.empty() || !count || path[0] != '/' 121 + || strncmp(path, "/dev/", 5) == 0) 122 + { 123 + memcpy(resolved_path, path, count); 124 + resolved_path[count] = '\0'; 125 + return resolved_path; 126 + } 127 + 128 + test_len = (path[count-1] != '/') ? (g_prefix.length()-1) 129 + : (g_prefix.length()); 130 + 131 + if (strncmp(path, g_prefix.c_str(), test_len) == 0) 132 + { 133 + size_t len = count - (g_prefix.length()-1); 134 + memcpy(resolved_path, path + g_prefix.length() - 1, 135 + count - (g_prefix.length() - 1)); 136 + 137 + if (len > 0) 138 + resolved_path[len] = '\0'; 139 + else 140 + strcpy(resolved_path, "/"); 141 + } 142 + else 143 + { 144 + size_t len = std::min<size_t>(sizeof(resolved_path) 145 + - sizeof(SYSTEM_ROOT), count); 146 + 147 + strcpy(resolved_path, SYSTEM_ROOT); 148 + strncat(resolved_path, path, len); 149 + resolved_path[len + sizeof(SYSTEM_ROOT)-1] = '\0'; 150 + } 151 + 152 + return resolved_path; 153 + } 154 + 155 + void __prefix_cwd(const char* in_path) 156 + { 157 + if (!*in_path) 158 + return; 159 + 160 + std::string path; 161 + 162 + // std::cout << "CWD to " << in_path << std::endl; 163 + 164 + pthread_rwlock_wrlock(&g_cwdLock); 165 + if (in_path[0] != '/') 166 + { 167 + path = g_cwd; 168 + path += in_path; 169 + } 170 + else 171 + path = in_path; 172 + 173 + g_cwd = canonicalize_path(path); 174 + 175 + if (g_cwd[g_cwd.length()-1] != '/') 176 + g_cwd += '/'; 177 + 178 + pthread_rwlock_unlock(&g_cwdLock); 179 + } 180 + 181 + void __prefix_cwd_fd(int fd) 182 + { 183 + char path[1024]; 184 + int count; 185 + 186 + if (g_prefix.empty()) 187 + return; 188 + 189 + sprintf(path, "/proc/self/fd/%d", fd); 190 + count = readlink(path, path, sizeof(path)-1); 191 + 192 + if (count < 0) 193 + return; 194 + 195 + __prefix_cwd(__prefix_untranslate_path(path, count)); 196 + } 197 + 198 + bool __prefix_is_system_root(const char* path) 199 + { 200 + return strcmp(__prefix_translate_path(path), "/") == 0; 201 + } 202 + 203 + int __prefix_get_dyld_path(char* buf, unsigned long size) 204 + { 205 + int len; 206 + len = readlink("/proc/self/exe", buf, size); 207 + 208 + if (len < 0) 209 + buf[0] = '\0'; 210 + else 211 + buf[len] = '\0'; 212 + 213 + return len; 214 + } 215 + 216 + std::string canonicalize_path(const std::string& in_path) 217 + { 218 + std::list<std::string> path_components; 219 + size_t pos = 0, last_pos; 220 + std::string path; 221 + 222 + assert(in_path[0] == '/'); 223 + 224 + while (pos != std::string::npos) 225 + { 226 + size_t len; 227 + last_pos = pos + 1; 228 + 229 + pos = in_path.find('/', last_pos); 230 + len = (pos == std::string::npos) ? pos : (pos - last_pos); 231 + path_components.push_back(in_path.substr(last_pos, len)); 232 + } 233 + 234 + for (std::list<std::string>::iterator it = path_components.begin(); 235 + it != path_components.end(); ) 236 + { 237 + if (*it == "." || it->empty()) 238 + { 239 + it = path_components.erase(it); 240 + } 241 + else if (*it == "..") 242 + { 243 + if (it != path_components.begin()) 244 + { 245 + it--; 246 + it = path_components.erase(it); 247 + } 248 + it = path_components.erase(it); 249 + } 250 + else 251 + it++; 252 + } 253 + 254 + path.reserve(in_path.size()); 255 + 256 + for (const std::string& comp : path_components) 257 + { 258 + path += '/'; 259 + path += comp; 260 + } 261 + 262 + return path; 263 + }
+62
src/libdyld/VirtualPrefix.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef VIRTUALPREFIX_H 21 + #define VIRTUALPREFIX_H 22 + #include <stdbool.h> 23 + 24 + #ifdef __cplusplus 25 + extern "C" { 26 + #endif 27 + 28 + #define __SYSTEM_ROOT "/system-root" 29 + 30 + // Set prefix path. Should be run only once at startup. 31 + // If this is never called, then __prefix_translate_path() 32 + // is a no-op. 33 + void __prefix_set(const char* path); 34 + 35 + // Returns the current prefix or NULL; 36 + const char* __prefix_get(void); 37 + 38 + // Translate from path in prefix to physical path. 39 + const char* __prefix_translate_path(const char* path); 40 + 41 + // Translate from physical path to path in prefix. 42 + // The path is expected to be canonical. 43 + const char* __prefix_untranslate_path(const char* path, unsigned long count); 44 + 45 + // Called whenever current working directory changes. 46 + // This is used to resolve relative paths passed to 47 + // __prefix_translate_path(). 48 + void __prefix_cwd(const char* path); 49 + 50 + void __prefix_cwd_fd(int fd); 51 + 52 + // Is the given path equivalent to __SYSTEM_ROOT? 53 + bool __prefix_is_system_root(const char* path); 54 + 55 + int __prefix_get_dyld_path(char* buf, unsigned long size); 56 + 57 + #ifdef __cplusplus 58 + } 59 + #endif 60 + 61 + #endif /* VIRTUALPREFIX_H */ 62 +
+19
src/libdyld/dl_public.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "dl_public.h" 2 21 #include "MachOMgr.h" 3 22 #include "MachOObject.h"
+19
src/libdyld/dl_public.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef DL_PUBLIC_H 2 21 #define DL_PUBLIC_H 3 22 #include <dlfcn.h>
+19
src/libdyld/dyld_priv.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "dyld_priv.h" 2 21 #include <link.h> 3 22 #include <map>
+19
src/libdyld/dyld_priv.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef DYLD_PRIV_H 2 21 #define DYLD_PRIV_H 3 22 #include <stdint.h>
+1 -1
src/libdyld/dyld_public.cpp
··· 1 1 /* 2 2 This file is part of Darling. 3 3 4 - Copyright (C) 2012-2013 Lubos Dolezel 4 + Copyright (C) 2012-2015 Lubos Dolezel 5 5 6 6 Darling is free software: you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by
+1 -1
src/libdyld/dyld_public.h
··· 1 1 /* 2 2 This file is part of Darling. 3 3 4 - Copyright (C) 2012-2013 Lubos Dolezel 4 + Copyright (C) 2012-2015 Lubos Dolezel 5 5 6 6 Darling is free software: you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by
+19
src/libdyld/threads.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #include "threads.h" 2 21 #include <pthread.h> 3 22 #include <sys/mman.h>
+19
src/libdyld/threads.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2015 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 1 20 #ifndef DYLD_THREADS_H 2 21 #define DYLD_THREADS_H 3 22 #include <stdint.h>