Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build-hnp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ PKGS=bash \
lz4 \
make \
ncurses \
talloc \
openssl \
zstd \
pcre2 \
libarchive \
proot \
strace \
tar \
tree \
Expand All @@ -27,14 +32,12 @@ PKGS=bash \
stream \
libevent \
tmux \
pcre2 \
fish \
elf-loader \
gmp \
mpfr \
mpc \
gcc \
zstd \
expat \
git \
aria2 \
Expand Down
31 changes: 31 additions & 0 deletions build-hnp/libarchive/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
all: download/libarchive-3.8.1.tar.gz
rm -rf temp build
mkdir -p temp build/bin
cd temp && tar xvf ../download/libarchive-3.8.1.tar.gz
cd temp/libarchive-3.8.1
cd temp && cmake -S libarchive-3.8.1 -B libarchive-3.8.1/build-ohos \
-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF \
-DCMAKE_C_COMPILER=$(OHOS_SDK_HOME)/native/llvm/bin/aarch64-unknown-linux-ohos-clang -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_TEST=OFF \
-DENABLE_PCREPOSIX=OFF \
-DENABLE_PCRE2POSIX=OFF \
-DENABLE_LIBB2=OFF \
-DENABLE_LZMA=OFF \
-DENABLE_EXPAT=OFF \
-DENABLE_LIBXML2=OFF \
-DOPENSSL_USE_STATIC_LIBS=OFF \
-DCMAKE_PREFIX_PATH=../../sysroot \
-DCMAKE_INCLUDE_PATH=../../sysroot/include \
-DOPENSSL_INCLUDE_DIR=../../sysroot/include \
-DOPENSSL_SSL_LIBRARY=../../sysroot/lib/libssl.so \
-DOPENSSL_CRYPTO_LIBRARY=../../sysroot/lib/libcrypto.so \
-DLZ4_LIBRARY=../../sysroot/lib/liblz4.so \
-DZSTD_LIBRARY=../../sysroot/lib/libzstd.so
cd temp/libarchive-3.8.1/build-ohos && make -j $(shell nproc)
cd temp/libarchive-3.8.1/build-ohos && make install DESTDIR=$(shell pwd)/build
mkdir -p ../sysroot
cp -rv build/usr/local/. ../sysroot/ | tee file.lst

download/libarchive-3.8.1.tar.gz:
mkdir -p download
cd download && wget https://www.libarchive.org/downloads/libarchive-3.8.1.tar.gz
38 changes: 38 additions & 0 deletions build-hnp/proot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include ../utils/Makefrag

all: download/proot
rm -rf temp build
mkdir -p temp build/bin
cd temp && cp -r ../download/proot proot
mkdir -p temp/proot/build
cd temp/proot/build && \
PKG_CONFIG=/opt/homebrew/bin/pkg-config \
PKG_CONFIG_PATH=../../../../sysroot/lib/pkgconfig \
CC=$(CC) \
CFLAGS="--sysroot=$(OHOS_SDK_HOME)/native/sysroot -O2 -g -pipe -fstack-protector-strong -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 $(CFLAGS)" \
LDFLAGS="--sysroot=$(OHOS_SDK_HOME)/native/sysroot -L$(OHOS_SDK_HOME)/native/sysroot/usr/lib $(LDFLAGS)" \
OBJCOPY=$(OBJCOPY) \
READELF=$(READELF) \
PKG_CONFIG_PATH=../../../../sysroot/lib/pkgconfig \
make -C ../src loader && \
PKG_CONFIG=/opt/homebrew/bin/pkg-config \
PKG_CONFIG_PATH=../../../../sysroot/lib/pkgconfig \
CC=$(CC) \
CFLAGS="--sysroot=$(OHOS_SDK_HOME)/native/sysroot -O2 -g -pipe -fstack-protector-strong -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 $(CFLAGS)" \
CPPFLAGS="-D__OHOS__" \
LDFLAGS="--sysroot=$(OHOS_SDK_HOME)/native/sysroot -L$(OHOS_SDK_HOME)/native/sysroot/usr/lib $(LDFLAGS)" \
OBJCOPY=$(OBJCOPY) \
READELF=$(READELF) \
PKG_CONFIG_PATH=../../../../sysroot/lib/pkgconfig \
make -C ../src proot
cp temp/proot/src/proot ./build/bin/
mkdir -p ../sysroot && \
cp -rv ./build/. ../sysroot | tee file.lst

download/proot:
mkdir -p download
cp queue.h ../sysroot/include
cd download && \
rm -rf proot && git clone https://github.com/termux/proot.git --recursive && \
cd proot && git checkout 60485d2646c1e09105099772da4a20deda8d020d && \
git apply ../../ohos.patch
147 changes: 147 additions & 0 deletions build-hnp/proot/ohos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
diff --git a/src/GNUmakefile b/src/GNUmakefile
index 92a4935..8b1355b 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -13,6 +13,7 @@ LD = $(CC)
STRIP ?= $(CROSS_COMPILE)strip
OBJCOPY ?= $(CROSS_COMPILE)objcopy
OBJDUMP ?= $(CROSS_COMPILE)objdump
+READELF ?= $(CROSS_COMPILE)readelf

CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I. -I$(VPATH)
CFLAGS += -Wall -Wextra -O2
@@ -235,7 +236,7 @@ $(eval $(call build_loader,-m32))
endif

loader/loader-info.c: loader/loader
- readelf -s $< | awk -f loader/loader-info.awk > $@
+ $(READELF) -s $< | awk -f loader/loader-info.awk > $@

######################################################################
# Dependencies
diff --git a/src/cli/cli.c b/src/cli/cli.c
index bbc6400..832b54c 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -47,6 +47,12 @@
#include <extension/extension.h>
#include <extension/sysvipc/sysvipc.h>

+#ifdef __OHOS__
+#include "queue.h" /* CIRCLEQ_*, */ // which is not present in ohos header
+#else
+#include <sys/queue.h> /* CIRCLEQ_*, */
+#endif
+
#include "build.h"

/**
diff --git a/src/extension/sysvipc/sysvipc_msg.c b/src/extension/sysvipc/sysvipc_msg.c
index 1fc290a..fd913b4 100644
--- a/src/extension/sysvipc/sysvipc_msg.c
+++ b/src/extension/sysvipc/sysvipc_msg.c
@@ -175,11 +175,17 @@ static int sysvipc_do_msgrcv(Tracee *tracee, struct SysVIpcConfig *config, size_
return -EINVAL;
}

+#ifdef MSG_COPY
if ((config->msgrcv_msgflg & ~(IPC_NOWAIT | MSG_NOERROR | MSG_COPY | MSG_EXCEPT)) != 0) {
return -EINVAL;
}
+#endif

+#ifdef MSG_COPY
bool copy = (config->msgrcv_msgflg & MSG_COPY) != 0;
+#else
+ bool copy = false;
+#endif
if (copy) {
if ((config->msgrcv_msgflg & IPC_NOWAIT) == 0) {
return -EINVAL;
diff --git a/src/path/binding.c b/src/path/binding.c
index c0e2f84..57a9c30 100644
--- a/src/path/binding.c
+++ b/src/path/binding.c
@@ -27,7 +27,11 @@
#include <assert.h> /* assert(3), */
#include <limits.h> /* PATH_MAX, */
#include <errno.h> /* E* */
+#ifdef __OHOS__
+#include "queue.h" /* CIRCLEQ_*, */ // which is not present in ohos header
+#else
#include <sys/queue.h> /* CIRCLEQ_*, */
+#endif
#include <talloc.h> /* talloc_*, */

#include "path/binding.h"
diff --git a/src/path/binding.h b/src/path/binding.h
index b7f8d46..c18abb2 100644
--- a/src/path/binding.h
+++ b/src/path/binding.h
@@ -26,6 +26,10 @@
#include <limits.h> /* PATH_MAX, */
#include <stdbool.h>

+#ifdef __OHOS__
+#include <queue.h> /* CIRCLEQ_*, */ // not present in ohos header
+#endif
+
#include "tracee/tracee.h"
#include "path.h"

diff --git a/src/path/temp.c b/src/path/temp.c
index 8d8aa63..e726ec2 100644
--- a/src/path/temp.c
+++ b/src/path/temp.c
@@ -172,7 +172,7 @@ static int remove_temp_directory2(const char *path)
int status;
char *cwd;

-#ifdef __ANDROID__
+#if defined(__ANDROID__) || defined(__OHOS__)
cwd = malloc(PATH_MAX);
getcwd(cwd, PATH_MAX);
#else
diff --git a/src/tracee/statx.h b/src/tracee/statx.h
index d06dfae..f7dd286 100644
--- a/src/tracee/statx.h
+++ b/src/tracee/statx.h
@@ -5,6 +5,7 @@
#include "sys/vfs.h"
#include "path/path.h"
#include "extension/extension.h"
+#include <linux/stat.h>

/*
* This structure is passed to extensions
diff --git a/src/tracee/tracee.c b/src/tracee/tracee.c
index a7082e3..9286d3f 100644
--- a/src/tracee/tracee.c
+++ b/src/tracee/tracee.c
@@ -26,7 +26,9 @@
#include <assert.h> /* assert(3), */
#include <string.h> /* bzero(3), */
#include <stdbool.h> /* bool, true, false, */
-#include <sys/queue.h> /* LIST_*, */
+#ifndef __OHOS__
+#include <sys/queue.h> /* LIST_*, */ // will interfere with added queue.h
+#endif
#include <talloc.h> /* talloc_*, */
#include <signal.h> /* kill(2), SIGKILL, */
#include <sys/ptrace.h> /* ptrace(2), PTRACE_*, */
diff --git a/src/tracee/tracee.h b/src/tracee/tracee.h
index 3dcbc7b..4291b3f 100644
--- a/src/tracee/tracee.h
+++ b/src/tracee/tracee.h
@@ -26,7 +26,11 @@
#include <sys/types.h> /* pid_t, size_t, */
#include <sys/user.h> /* struct user*, */
#include <stdbool.h> /* bool, */
+#ifdef __OHOS__
+#include <queue.h> /* CIRCLEQ_*, */ // which is not present in ohos header
+#else
#include <sys/queue.h> /* LIST_*, */
+#endif
#include <sys/ptrace.h>/* enum __ptrace_request */
#include <talloc.h> /* talloc_*, */
#include <stdint.h> /* *int*_t, */
Loading