Remove gnumake; the preffered way will be to install it from Apple's .pkg along with other tools

Integrate darling-dmg, add hdiutil
Add fake sudo and sw_vers
Add darling-installer submodule (not working yet)
This commit is contained in:
Lubos Dolezel 2016-01-19 22:34:19 +01:00
parent 15e4bb5946
commit 877d062fd4
17 changed files with 228 additions and 44 deletions

10
.gitmodules vendored
View File

@ -57,7 +57,9 @@
path = src/external/bash
url = ../darling-bash.git
branch = darling
[submodule "src/external/gnumake"]
path = src/external/gnumake
url = ../darling-gnumake.git
branch = darling
[submodule "src/external/darling-dmg"]
path = src/external/darling-dmg
url = ../darling-dmg.git
[submodule "src/external/installer"]
path = src/external/installer
url = ../darling-installer.git

View File

@ -1,5 +1,5 @@
#include "CFUtilities.h"
#include "CoreFoundation/CFPriv.h"
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFData.h>
#include <CoreFoundation/CFPropertyList.h>

View File

@ -1,15 +0,0 @@
#ifndef CFUTILITIES_H
#define CFUTILITIES_H
#include <CoreFoundation/CFBase.h>
#include <CoreFoundation/CFDictionary.h>
typedef int CFSystemVersion;
CF_EXPORT Boolean _CFExecutableLinkedOnOrAfter(CFSystemVersion version);
CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
CF_EXPORT CFDictionaryRef _CFCopyServerVersionDictionary(void);
#endif

View File

@ -0,0 +1,26 @@
#ifndef CFUTILITIES_H
#define CFUTILITIES_H
#include <stddef.h>
#include <stdio.h>
#include <CoreFoundation/CFBase.h>
#include <CoreFoundation/CFDictionary.h>
typedef int CFSystemVersion;
extern const CFStringRef _kCFSystemVersionProductNameKey;
extern const CFStringRef _kCFSystemVersionProductCopyrightKey;
extern const CFStringRef _kCFSystemVersionProductVersionKey;
extern const CFStringRef _kCFSystemVersionProductVersionExtraKey;
extern const CFStringRef _kCFSystemVersionProductUserVisibleVersionKey;
extern const CFStringRef _kCFSystemVersionBuildVersionKey;
extern const CFStringRef _kCFSystemVersionProductVersionStringKey;
extern const CFStringRef _kCFSystemVersionBuildStringKey;
CF_EXPORT Boolean _CFExecutableLinkedOnOrAfter(CFSystemVersion version);
CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
CF_EXPORT CFDictionaryRef _CFCopyServerVersionDictionary(void);
#endif

View File

@ -51,6 +51,7 @@ add_subdirectory(libmach-o)
add_subdirectory(libdyld)
add_subdirectory(dyld)
add_subdirectory(motool)
add_subdirectory(external/darling-dmg)
if (FRAMEWORK_COREAUDIO)
add_subdirectory(AudioToolbox)
@ -111,7 +112,9 @@ add_subdirectory(csu)
add_subdirectory(external/shell_cmds)
add_subdirectory(external/file_cmds)
add_subdirectory(external/bash)
add_subdirectory(external/gnumake)
add_subdirectory(tools)
#add_subdirectory(external/gnumake)
#add_subdirectory(external/ld64)
######################
# libc++ & libc++abi #

View File

@ -37,16 +37,16 @@ add_executable(dyld-bin ${dyld_SRCS})
set_target_properties(dyld-bin PROPERTIES OUTPUT_NAME dyld${SUFFIX})
target_link_libraries(dyld-bin dyld darling-util mach-o)
#if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
add_executable(dyldd dyldd.cpp)
target_link_libraries(dyldd dyld darling-util mach-o)
install(TARGETS dyldd DESTINATION bin)
install(PROGRAMS darling DESTINATION bin
install(PROGRAMS darling DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
#endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
install(TARGETS dyld-bin DESTINATION bin)
install(TARGETS dyld-bin DESTINATION bin)
if (CMAKE_INSTALL_LIBDIR STREQUAL "lib64")
add_executable(dyld-multilib dyld-multilib.c)

View File

@ -22,11 +22,11 @@ SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
DARLING_PREFIX=$(realpath "$SCRIPTPATH/..")
SYSTEM_ROOT_NAME="system-root"
BIND_DIRECTORIES="dev etc home tmp"
MAKE_DIRECTORIES="Applications Volumes usr"
setup_prefix() {
SYSTEM_ROOT_NAME="system-root"
BIND_DIRECTORIES="dev etc home tmp"
MAKE_DIRECTORIES="Applications Volumes usr usr/share"
>&2 echo "Setting up prefix at $1"
mkdir -p "$1"
@ -43,9 +43,9 @@ setup_prefix() {
ln -s home Users
# TODO: install bash and coreutils
ln -s "${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/libexec/darling/bin" "bin"
ln -s "../${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/libexec/darling/usr/bin" "usr/bin"
ln -s "/${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/share/darling" "usr/share/darling"
popd >/dev/null
}
@ -58,8 +58,8 @@ if [ $# -eq 0 ]; then
>&2 echo
>&2 echo -e "Usage:\tdarling PROGRAM [ARGUMENTS...]\tRun the specified program"
>&2 echo -e "\tdarling shell\t\t\tStart bash shell in prefix"
>&2 echo -e "\tdarling hdiutil\t\t\tMount DMG disk images"
>&2 echo -e "\tdarling pkgutil\t\t\tInstall PKG packages"
#>&2 echo -e "\tdarling hdiutil\t\t\tMount DMG disk images"
#>&2 echo -e "\tdarling pkgutil\t\t\tInstall PKG packages"
>&2 echo
>&2 echo "The prefix is specified by the DPREFIX environment variable."
>&2 echo "The default DPREFIX is \$HOME/.darling"
@ -87,14 +87,14 @@ case "$1" in
exec "${dyld_path}" "${DPREFIX}/bin/bash"
fi
;;
"hdiutil")
>2& echo "Not implemented yet"
exit 1
;;
"pkgutil")
>2& echo "Not implemented yet"
exit 1
;;
#"hdiutil")
# exec "${DPREFIX}/usr/bin/hdiutil" "${@:2}"
# exit $?
# ;;
#"pkgutil")
# >2& echo "Not implemented yet"
# exit 1
# ;;
"load")
if [ "$(id -u)" != 0 ]; then
2>&1 "You need to be root for this command."

View File

@ -53,7 +53,7 @@ int main(int argc, char** argv, char** envp)
try
{
MachOMgr* mgr = MachOMgr::instance();
std::string executable;
std::string executable, unprefixed_argv0;
executable = locateBundleExecutable(argv[1]);
argv[1] = const_cast<char*>(executable.c_str());
@ -80,7 +80,10 @@ int main(int argc, char** argv, char** envp)
if (const char* path = getenv("DYLD_TRAMPOLINE"))
mgr->setUseTrampolines(true, path);
if (const char* path = getenv("DPREFIX"))
{
__prefix_set(path);
unprefixed_argv0 = __prefix_untranslate_path(argv[1], strlen(argv[1]));
}
if (isELF(argv[1]))
{
@ -96,6 +99,8 @@ int main(int argc, char** argv, char** envp)
if (!main)
throw std::runtime_error("No entry point found in Darling-native executable");
if (!unprefixed_argv0.empty())
argv[1] = (char*) unprefixed_argv0.c_str();
exit(main(argc-1, &argv[1], envp));
}
else
@ -109,6 +114,9 @@ int main(int argc, char** argv, char** envp)
"kernel extensions and other Mach-O files cannot be executed with dyld");
}
if (!unprefixed_argv0.empty())
argv[1] = (char*) unprefixed_argv0.c_str();
obj->setCommandLine(argc-1, &argv[1], envp);
obj->load();

1
src/external/darling-dmg vendored Submodule

@ -0,0 +1 @@
Subproject commit 1548289e6547bc5fe0f5cff98c815d22ff6c3be3

@ -1 +0,0 @@
Subproject commit 4d31af3a1956b36612625101ab760a0d0fcc90ec

1
src/external/installer vendored Submodule

@ -0,0 +1 @@
Subproject commit 331ecc652eaa12645ea66ad84e49c808384ca92e

View File

@ -129,13 +129,14 @@ long sys_execve(char* fname, char** argvp, char** envp)
modargvp[i++] = interp;
if (arg != NULL)
modargvp[i++] = arg;
modargvp[i] = fname;
// Append original arguments
for (j = 0; j < len+1; j++)
for (j = 1; j < len+1; j++)
modargvp[i+j] = argvp[j];
argvp = modargvp;
fname = modargvp[0];
fname = (char*) __prefix_translate_path(modargvp[0]);
}
else
{

View File

@ -2,10 +2,16 @@
#include "../base.h"
#include "../errno.h"
#include <asm/unistd.h>
#include <stddef.h>
extern char* getenv(const char* p);
long sys_geteuid(void)
{
int ret;
if (getenv("__FAKE_SETUID_ROOT") != NULL)
return 0;
#ifdef __NR_geteuid32
ret = LINUX_SYSCALL0(__NR_geteuid32);

View File

@ -2,10 +2,16 @@
#include "../base.h"
#include "../errno.h"
#include <asm/unistd.h>
#include <stddef.h>
extern char* getenv(const char* p);
long sys_getuid(void)
{
int ret;
if (getenv("__FAKE_SETUID_ROOT") != NULL)
return 0;
#ifdef __NR_getuid32
ret = LINUX_SYSCALL0(__NR_getuid32);

31
src/tools/CMakeLists.txt Normal file
View File

@ -0,0 +1,31 @@
project(tools)
cmake_minimum_required(VERSION 2.4.0)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w -ggdb -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,--version-script=${DARLING_TOP_DIRECTORY}/darwin.map")
include_directories(${DARLING_TOP_DIRECTORY}/src/external/corefoundation/Headers)
include_directories(${CMAKE_BINARY_DIR}/src/external/corefoundation/Headers)
include_directories(${DARLING_TOP_DIRECTORY}/src/external/foundation/Headers)
include_directories(${DARLING_TOP_DIRECTORY}/src/CFF)
include(darling_exe)
if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
add_darling_executable(sw_vers sw_vers.c)
install(TARGETS sw_vers DESTINATION libexec/darling/usr/bin)
target_link_libraries(sw_vers CFF CFFExtra)
install(PROGRAMS sudo DESTINATION libexec/darling/usr/bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")

30
src/tools/sudo Normal file
View File

@ -0,0 +1,30 @@
#!/bin/sh
#
# This file is part of Darling.
#
# Copyright (C) 2015 Lubos Dolezel
#
# Darling is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Darling is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Darling. If not, see <http://www.gnu.org/licenses/>.
#
if [ $# -lt 1 ]; then
>&2 echo "This is Darling fake sudo."
>&2 echo "Processes will think they run as UID 0, but Linux kernel will still see your original UID."
>&2 echo "The purpose is to convince some tools that they can write into /."
exit 1
fi
export __FAKE_SETUID_ROOT=1
exec "${@:1}"

85
src/tools/sw_vers.c Normal file
View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2005 Finlay Dobbie
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Finlay Dobbie nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFPriv.h>
void usage(char *progname) {
fprintf(stderr, "Usage: %s [-productName|-productVersion|-buildVersion]\n", progname);
exit(1);
}
int main(int argc, char *argv[]) {
CFDictionaryRef dict= NULL;
CFStringRef str = NULL;
char cstr[256];
dict = _CFCopyServerVersionDictionary();
if (dict == NULL)
dict = _CFCopySystemVersionDictionary();
if (dict == NULL)
exit(1);
if (argc == 2) {
if (!strcmp(argv[1], "-productName"))
str = CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey);
else if (!strcmp(argv[1], "-productVersion")) {
/* On Darwin, we set MacOSXProductVersion to the corresponding OS X release.
This is for compatibility with scripts that set MACOSX_DEPLOYMENT_TARGET
based on sw_vers -productVersion */
str = CFDictionaryGetValue(dict, CFSTR("MacOSXProductVersion"));
if (str == NULL)
str = CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey);
}
else if (!strcmp(argv[1], "-buildVersion"))
str = CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey);
else
usage(argv[0]);
CFRetain(str);
} else if (argc == 1) {
str = CFStringCreateWithFormat(NULL, NULL,
CFSTR("ProductName: %@\n"
"ProductVersion: %@\n"
"BuildVersion: %@"),
CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey),
CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey),
CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey));
} else {
usage(argv[0]);
}
if (!CFStringGetCString(str, cstr, sizeof(cstr), CFStringGetSystemEncoding()))
exit(1);
printf("%s\n", cstr);
CFRelease(str);
CFRelease(dict);
return 0;
}