Skip to content

Commit

Permalink
gpkg/glibc: implementation of fakesyscall (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxython authored May 6, 2024
1 parent 544ab0e commit 5f6b1f5
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 608 deletions.
109 changes: 0 additions & 109 deletions gpkg/glibc/aarch64-arch-syscall.h.patch

This file was deleted.

161 changes: 0 additions & 161 deletions gpkg/glibc/arm-arch-syscall.h.patch

This file was deleted.

14 changes: 12 additions & 2 deletions gpkg/glibc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TERMUX_PKG_DESCRIPTION="GNU C Library"
TERMUX_PKG_LICENSE="GPL-3.0, LGPL-3.0"
TERMUX_PKG_MAINTAINER="@termux-pacman"
TERMUX_PKG_VERSION=2.39
TERMUX_PKG_REVISION=3
TERMUX_PKG_REVISION=4
TERMUX_PKG_SRCURL=https://ftp.gnu.org/gnu/libc/glibc-$TERMUX_PKG_VERSION.tar.xz
TERMUX_PKG_SHA256=f77bd47cf8170c57365ae7bf86696c118adb3b120d3259c64c502d3dc1e2d926
TERMUX_PKG_DEPENDS="linux-api-headers-glibc"
Expand All @@ -16,7 +16,7 @@ termux_step_pre_configure() {
termux_error_exit "Compilation is only possible based on glibc"
fi

for i in shmem-android.h shmat.c shmctl.c shmdt.c shmget.c mprotect.c ignore-syscall.h; do
for i in shmem-android.h shmat.c shmctl.c shmdt.c shmget.c mprotect.c syscall.c fake-syscall.h; do
install -Dm644 "${TERMUX_PKG_BUILDER_DIR}/${i}" "${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}"
done

Expand All @@ -37,6 +37,16 @@ termux_step_pre_configure() {
bash ${TERMUX_PKG_BUILDER_DIR}/gen-android-ids.sh ${TERMUX_BASE_DIR} \
${TERMUX_PKG_SRCDIR}/nss/android_ids.h \
${TERMUX_PKG_BUILDER_DIR}/android_system_user_ids.h

# `disabled-syscalls` - a file that contains a list of system calls that should be disabled
for i in aarch64 arm i386 x86_64/64; do
{
for j in $(awk '{printf "__NR_" $1 " "}' ${TERMUX_PKG_BUILDER_DIR}/disabled-syscalls); do
grep "#define ${j} " ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h || true
sed -i "/#define ${j} /d" ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/arch-syscall.h
done
} >> ${TERMUX_PKG_SRCDIR}/sysdeps/unix/sysv/linux/${i}/disabled-syscall.h
done
}

termux_step_configure() {
Expand Down
31 changes: 31 additions & 0 deletions gpkg/glibc/disabled-syscalls
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
accept
chmod
chown
chown32
clock_gettime64
clone3
close_range
epoll_pwait2
faccessat2
fchmodat2
futex_waitv
getpgrp
landlock_create_ruleset
pidfd_send_signal
recv
rmdir
rseq
send
set_robust_list
setfsgid
setfsgid32
setfsuid
setfsuid32
setgid
setgid32
setresgid
setresgid32
setuid
setuid32
statx
symlink
33 changes: 33 additions & 0 deletions gpkg/glibc/fake-syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _FAKE_SYSCALL
#define _FAKE_SYSCALL

#include <arch-syscall.h>
#include <disabled-syscall.h>

extern int close_range (unsigned int __fd, unsigned int __max_fd, int __flags) __THROW;

struct FakeSyscall {
int id;
long int (*func)(long int,
long int,
long int,
long int,
long int,
long int);
};

long int JustReturnZero() {
return 0;
}

static struct FakeSyscall FakeSyscalls[] = {
{ __NR_close_range, close_range },
{ __NR_mbind, JustReturnZero },
{ __NR_get_mempolicy, JustReturnZero },
{ __NR_set_mempolicy, JustReturnZero },
{ 1008, JustReturnZero }, // for some reason used in julia
};

#define CountFakeSyscalls (sizeof(FakeSyscalls) / sizeof(FakeSyscalls[0]))

#endif //_FAKE_SYSCALL
Loading

0 comments on commit 5f6b1f5

Please sign in to comment.