mirror of
https://github.com/darlinghq/darling.git
synced 2024-11-24 04:39:50 +00:00
Build gnumake, several fixes in virtual prefix implementation
This commit is contained in:
parent
f8eae91db8
commit
15e4bb5946
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -57,3 +57,7 @@
|
||||
path = src/external/bash
|
||||
url = ../darling-bash.git
|
||||
branch = darling
|
||||
[submodule "src/external/gnumake"]
|
||||
path = src/external/gnumake
|
||||
url = ../darling-gnumake.git
|
||||
branch = darling
|
||||
|
@ -111,6 +111,7 @@ add_subdirectory(csu)
|
||||
add_subdirectory(external/shell_cmds)
|
||||
add_subdirectory(external/file_cmds)
|
||||
add_subdirectory(external/bash)
|
||||
add_subdirectory(external/gnumake)
|
||||
|
||||
######################
|
||||
# libc++ & libc++abi #
|
||||
|
@ -24,7 +24,7 @@ DARLING_PREFIX=$(realpath "$SCRIPTPATH/..")
|
||||
|
||||
SYSTEM_ROOT_NAME="system-root"
|
||||
BIND_DIRECTORIES="dev etc home tmp"
|
||||
MAKE_DIRECTORIES="Applications Volumes"
|
||||
MAKE_DIRECTORIES="Applications Volumes usr"
|
||||
|
||||
setup_prefix() {
|
||||
>&2 echo "Setting up prefix at $1"
|
||||
@ -45,6 +45,7 @@ setup_prefix() {
|
||||
|
||||
# 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"
|
||||
|
||||
popd >/dev/null
|
||||
}
|
||||
|
1
src/external/gnumake
vendored
Submodule
1
src/external/gnumake
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 4d31af3a1956b36612625101ab760a0d0fcc90ec
|
@ -75,7 +75,7 @@ long sys_fcntl_nocancel(int fd, int cmd, long arg)
|
||||
if (len >= 0)
|
||||
((char*) arg)[len] = '\0';
|
||||
|
||||
return len;
|
||||
return 0;
|
||||
}
|
||||
// TODO: implement remaining commands
|
||||
default:
|
||||
|
@ -11,9 +11,9 @@ long sys_lstat(const char* path, struct stat* stat)
|
||||
struct linux_stat lstat;
|
||||
|
||||
#ifdef __NR_lstat64
|
||||
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat);
|
||||
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path_link(path), &lstat);
|
||||
#else
|
||||
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat);
|
||||
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path_link(path), &lstat);
|
||||
#endif
|
||||
|
||||
if (ret < 0)
|
||||
@ -32,9 +32,9 @@ long sys_lstat64(const char* path, struct stat64* stat)
|
||||
struct linux_stat lstat;
|
||||
|
||||
#ifdef __NR_lstat64
|
||||
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat);
|
||||
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path_link(path), &lstat);
|
||||
#else
|
||||
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat);
|
||||
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path_link(path), &lstat);
|
||||
#endif
|
||||
|
||||
if (ret < 0)
|
||||
|
@ -4,16 +4,17 @@
|
||||
#include <asm/unistd.h>
|
||||
#include <libdyld/VirtualPrefix.h>
|
||||
|
||||
long sys_chdir(const char* path)
|
||||
long sys_chdir(const char* in_path)
|
||||
{
|
||||
int ret;
|
||||
const char* path;
|
||||
|
||||
path = __prefix_translate_path(path);
|
||||
path = __prefix_translate_path(in_path);
|
||||
ret = LINUX_SYSCALL(__NR_chdir, path);
|
||||
if (ret < 0)
|
||||
ret = errno_linux_to_bsd(ret);
|
||||
else
|
||||
__prefix_cwd(path);
|
||||
__prefix_cwd(in_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ long sys_lchown(const char* path, int uid, int gid)
|
||||
int ret;
|
||||
|
||||
#ifdef __NR_chown32
|
||||
ret = LINUX_SYSCALL(__NR_lchown32, __prefix_translate_path(path), uid, gid);
|
||||
ret = LINUX_SYSCALL(__NR_lchown32, __prefix_translate_path_link(path), uid, gid);
|
||||
#else
|
||||
ret = LINUX_SYSCALL(__NR_lchown, __prefix_translate_path(path), uid, gid);
|
||||
ret = LINUX_SYSCALL(__NR_lchown, __prefix_translate_path_link(path), uid, gid);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
ret = errno_linux_to_bsd(ret);
|
||||
|
@ -10,7 +10,7 @@ long sys_readlink(const char* path, char* buf, int count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = LINUX_SYSCALL(__NR_readlink, __prefix_translate_path(path),
|
||||
ret = LINUX_SYSCALL(__NR_readlink, __prefix_translate_path_link(path),
|
||||
buf, count);
|
||||
if (ret < 0)
|
||||
ret = errno_linux_to_bsd(ret);
|
||||
|
@ -39,7 +39,8 @@ static std::list<std::string> explode_path(const std::string& path);
|
||||
static std::string join_path(const std::list<std::string>& path_components);
|
||||
|
||||
static std::list<std::string>& canonicalize_path(std::list<std::string>& path_components);
|
||||
static std::string resolve_path(std::list<std::string>& path_components);
|
||||
static std::string resolve_path(std::list<std::string>& path_components, bool symlink);
|
||||
static const char* translate_path_common(const char* path, bool symlink);
|
||||
|
||||
void __prefix_set(const char* path)
|
||||
{
|
||||
@ -49,6 +50,7 @@ void __prefix_set(const char* path)
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
|
||||
assert(path[0] == '/');
|
||||
assert(g_prefix.empty());
|
||||
|
||||
g_prefix = path;
|
||||
g_prefixComponents.clear();
|
||||
@ -68,9 +70,9 @@ void __prefix_set(const char* path)
|
||||
|
||||
if (strncmp(cwd, path, strlen(path)) == 0)
|
||||
{
|
||||
g_cwd = path + strlen(path);
|
||||
if (g_cwd.empty())
|
||||
g_cwd = "/";
|
||||
g_cwd = cwd + strlen(path);
|
||||
if (g_cwd.empty() || g_cwd[g_cwd.length()-1] != '/')
|
||||
g_cwd += "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -78,6 +80,8 @@ void __prefix_set(const char* path)
|
||||
g_cwd += cwd;
|
||||
g_cwd += '/';
|
||||
}
|
||||
|
||||
// std::cout << "### Prefix initialized with cwd " << g_cwd << " from " << cwd << std::endl;
|
||||
}
|
||||
|
||||
const char* __prefix_get(void)
|
||||
@ -88,16 +92,17 @@ const char* __prefix_get(void)
|
||||
return g_prefix.c_str();
|
||||
}
|
||||
|
||||
const char* __prefix_translate_path(const char* path)
|
||||
const char* translate_path_common(const char* path, bool symlink)
|
||||
{
|
||||
static thread_local char resolved_path[1024];
|
||||
std::string str;
|
||||
std::list<std::string> path_components;
|
||||
std::list<std::string>::iterator root;
|
||||
|
||||
if (g_prefix.empty())
|
||||
return path;
|
||||
|
||||
// std::cout << "\tCWD is " << g_cwd << std::endl;
|
||||
|
||||
if (path[0] != '/')
|
||||
{
|
||||
pthread_rwlock_rdlock(&g_cwdLock);
|
||||
@ -105,9 +110,10 @@ const char* __prefix_translate_path(const char* path)
|
||||
pthread_rwlock_unlock(&g_cwdLock);
|
||||
}
|
||||
str += path;
|
||||
// std::cout << "*** Before explode: " << str << std::endl;
|
||||
|
||||
path_components = explode_path(str);
|
||||
str = resolve_path(path_components);
|
||||
str = resolve_path(path_components, symlink);
|
||||
|
||||
strncpy(resolved_path, str.c_str(), sizeof(resolved_path)-1);
|
||||
resolved_path[sizeof(resolved_path)-1] = '\0';
|
||||
@ -117,6 +123,16 @@ const char* __prefix_translate_path(const char* path)
|
||||
return resolved_path;
|
||||
}
|
||||
|
||||
const char* __prefix_translate_path(const char* path)
|
||||
{
|
||||
return translate_path_common(path, false);
|
||||
}
|
||||
|
||||
const char* __prefix_translate_path_link(const char* path)
|
||||
{
|
||||
return translate_path_common(path, true);
|
||||
}
|
||||
|
||||
const char* __prefix_untranslate_path(const char* path, unsigned long count)
|
||||
{
|
||||
static thread_local char resolved_path[1024];
|
||||
@ -156,6 +172,8 @@ const char* __prefix_untranslate_path(const char* path, unsigned long count)
|
||||
resolved_path[len + sizeof(SYSTEM_ROOT)-1] = '\0';
|
||||
}
|
||||
|
||||
// std::cout << "*** UNTRANSLATE: " << path << " -> " << resolved_path << std::endl;
|
||||
|
||||
return resolved_path;
|
||||
}
|
||||
|
||||
@ -184,6 +202,8 @@ void __prefix_cwd(const char* in_path)
|
||||
if (g_cwd[g_cwd.length()-1] != '/')
|
||||
g_cwd += '/';
|
||||
|
||||
// std::cout << "\t+++ CWD In: " << in_path << "; out: " << g_cwd << std::endl;
|
||||
|
||||
pthread_rwlock_unlock(&g_cwdLock);
|
||||
}
|
||||
|
||||
@ -285,7 +305,7 @@ std::list<std::string>& canonicalize_path(std::list<std::string>& path_component
|
||||
return path_components;
|
||||
}
|
||||
|
||||
std::string resolve_path(std::list<std::string>& path_components)
|
||||
std::string resolve_path(std::list<std::string>& path_components, bool symlink)
|
||||
{
|
||||
std::string path, real_path;
|
||||
bool had_failure = false;
|
||||
@ -377,6 +397,9 @@ restart_process:
|
||||
had_failure = true;
|
||||
}
|
||||
|
||||
if (symlink && it == --path_components.end())
|
||||
isLink = false;
|
||||
|
||||
// Perform symlink resolution
|
||||
if (isLink && !is_system_root)
|
||||
{
|
||||
|
@ -38,6 +38,10 @@ const char* __prefix_get(void);
|
||||
// Translate from path in prefix to physical path.
|
||||
const char* __prefix_translate_path(const char* path);
|
||||
|
||||
// Translate from path in prefix to physical path, treat the leaf node
|
||||
// as a symlink.
|
||||
const char* __prefix_translate_path_link(const char* path);
|
||||
|
||||
// Translate from physical path to path in prefix.
|
||||
// The path is expected to be canonical.
|
||||
const char* __prefix_untranslate_path(const char* path, unsigned long count);
|
||||
|
Loading…
Reference in New Issue
Block a user