Skip to content
Open
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
1 change: 1 addition & 0 deletions srcpkgs/electron39-devel
11 changes: 11 additions & 0 deletions srcpkgs/electron39/files/musl-patches/chromium-libc++-musl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/buildtools/third_party/libc++/__config_site
+++ b/buildtools/third_party/libc++/__config_site
@@ -25,7 +25,7 @@
#define _LIBCPP_HAS_THREADS 1
#define _LIBCPP_HAS_MONOTONIC_CLOCK 1
#define _LIBCPP_HAS_TERMINAL 1
-#define _LIBCPP_HAS_MUSL_LIBC 0
+#define _LIBCPP_HAS_MUSL_LIBC 1

#ifdef _WIN32
#define _LIBCPP_HAS_THREAD_API_PTHREAD 0
125 changes: 125 additions & 0 deletions srcpkgs/electron39/files/musl-patches/chromium-musl-sandbox.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Source: https://git.alpinelinux.org/aports/tree/community/chromium/musl-sandbox.patch
musl uses different syscalls from glibc for some functions, so the sandbox has
to account for that
--
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc ./sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
index ff5a1c0..da56b9b 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
+++ ./sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
@@ -139,21 +139,11 @@ namespace sandbox {
// present (as in newer versions of posix_spawn).
ResultExpr RestrictCloneToThreadsAndEPERMFork() {
const Arg<unsigned long> flags(0);
-
- // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2.
- const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES |
- CLONE_SIGHAND | CLONE_THREAD |
- CLONE_SYSVSEM;
- const uint64_t kObsoleteAndroidCloneMask = kAndroidCloneMask | CLONE_DETACHED;
-
- const uint64_t kGlibcPthreadFlags =
- CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD |
- CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID;
- const BoolExpr glibc_test = flags == kGlibcPthreadFlags;
-
- const BoolExpr android_test =
- AnyOf(flags == kAndroidCloneMask, flags == kObsoleteAndroidCloneMask,
- flags == kGlibcPthreadFlags);
+ const int required = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
+ CLONE_THREAD | CLONE_SYSVSEM;
+ const int safe = CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
+ CLONE_DETACHED;
+ const BoolExpr thread_clone_ok = (flags&~safe)==required;

// The following two flags are the two important flags in any vfork-emulating
// clone call. EPERM any clone call that contains both of them.
@@ -163,7 +153,7 @@ ResultExpr RestrictCloneToThreadsAndEPERMFork() {
AnyOf((flags & (CLONE_VM | CLONE_THREAD)) == 0,
(flags & kImportantCloneVforkFlags) == kImportantCloneVforkFlags);

- return If(IsAndroid() ? android_test : glibc_test, Allow())
+ return If(thread_clone_ok, Allow())
.ElseIf(is_fork_or_clone_vfork, Error(EPERM))
.Else(CrashSIGSYSClone());
}
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc ./sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
index d9d1882..0567557 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
+++ ./sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
@@ -392,6 +392,7 @@ bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
#if defined(__i386__)
case __NR_waitpid:
#endif
+ case __NR_set_tid_address:
return true;
case __NR_clone: // Should be parameter-restricted.
case __NR_setns: // Privileged.
@@ -404,7 +405,6 @@ bool SyscallSets::IsAllowedProcessStartOrDeath(int sysno) {
#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
case __NR_set_thread_area:
#endif
- case __NR_set_tid_address:
case __NR_unshare:
#if !defined(__mips__) && !defined(__aarch64__)
case __NR_vfork:
@@ -514,6 +514,8 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
case __NR_munlock:
case __NR_munmap:
case __NR_mseal:
+ case __NR_mremap:
+ case __NR_membarrier:
return true;
case __NR_madvise:
case __NR_mincore:
@@ -531,7 +533,6 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
case __NR_modify_ldt:
#endif
case __NR_mprotect:
- case __NR_mremap:
case __NR_msync:
case __NR_munlockall:
case __NR_readahead:
diff --git a/sandbox/linux/system_headers/linux_syscalls.h ./sandbox/linux/system_headers/linux_syscalls.h
index 2b78a0c..b6fedb5 100644
--- a/sandbox/linux/system_headers/linux_syscalls.h
+++ b/sandbox/linux/system_headers/linux_syscalls.h
@@ -10,6 +10,7 @@
#define SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_SYSCALLS_H_

#include "build/build_config.h"
+#include <sys/syscall.h>

#if defined(__x86_64__)
#include "sandbox/linux/system_headers/x86_64_linux_syscalls.h"
--- a/sandbox/policy/linux/bpf_renderer_policy_linux.cc
+++ b/sandbox/policy/linux/bpf_renderer_policy_linux.cc
@@ -94,6 +94,9 @@
case __NR_pwrite64:
case __NR_sched_get_priority_max:
case __NR_sched_get_priority_min:
+ case __NR_sched_getparam:
+ case __NR_sched_getscheduler:
+ case __NR_sched_setscheduler:
case __NR_sysinfo:
case __NR_times:
case __NR_uname:
--- a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
@@ -225,10 +225,15 @@
if (sysno == __NR_getpriority || sysno ==__NR_setpriority)
return RestrictGetSetpriority(current_pid);

+ // XXX: hacks for musl sandbox, calls needed?
+ if (sysno == __NR_sched_getparam || sysno == __NR_sched_getscheduler ||
+ sysno == __NR_sched_setscheduler) {
+ return Allow();
+ }
+
// The scheduling syscalls are used in threading libraries and also heavily in
// abseil. See for example https://crbug.com/1370394.
- if (sysno == __NR_sched_getaffinity || sysno == __NR_sched_getparam ||
- sysno == __NR_sched_getscheduler || sysno == __NR_sched_setscheduler) {
+ if (sysno == __NR_sched_getaffinity) {
return RestrictSchedTarget(current_pid, sysno);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Source: https://git.alpinelinux.org/aports/plain/community/chromium/musl-tid-caching.patch
the sandbox caching of thread id's only works with glibc
see: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/32356
see: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13579
--
--- a/sandbox/linux/services/namespace_sandbox.cc
+++ b/sandbox/linux/services/namespace_sandbox.cc
@@ -209,6 +209,72 @@
return base::LaunchProcess(argv, launch_options_copy);
}

+#if !defined(LIBC_GLIBC)
+#if defined(__aarch64__)
+#define TLS_ABOVE_TP
+#endif
+
+struct musl_pthread
+{
+ /* Part 1 -- these fields may be external or
+ * internal (accessed via asm) ABI. Do not change. */
+ struct pthread *self;
+#ifndef TLS_ABOVE_TP
+ uintptr_t *dtv;
+#endif
+ struct pthread *prev, *next; /* non-ABI */
+ uintptr_t sysinfo;
+#ifndef TLS_ABOVE_TP
+#ifdef CANARY_PAD
+ uintptr_t canary_pad;
+#endif
+ uintptr_t canary;
+#endif
+
+/* Part 2 -- implementation details, non-ABI. */
+ int tid;
+ int errno_val;
+ volatile int detach_state;
+ volatile int cancel;
+ volatile unsigned char canceldisable, cancelasync;
+ unsigned char tsd_used:1;
+ unsigned char dlerror_flag:1;
+ unsigned char *map_base;
+ size_t map_size;
+ void *stack;
+ size_t stack_size;
+ size_t guard_size;
+ void *result;
+ struct __ptcb *cancelbuf;
+ void **tsd;
+ struct {
+ volatile void *volatile head;
+ long off;
+ volatile void *volatile pending;
+ } robust_list;
+ int h_errno_val;
+ volatile int timer_id;
+ locale_t locale;
+ volatile int killlock[1];
+ char *dlerror_buf;
+ void *stdio_locks;
+
+ /* Part 3 -- the positions of these fields relative to
+ * the end of the structure is external and internal ABI. */
+#ifdef TLS_ABOVE_TP
+ uintptr_t canary;
+ uintptr_t *dtv;
+#endif
+};
+
+void MaybeUpdateMuslTidCache()
+{
+ pid_t real_tid = sys_gettid();
+ pid_t* cached_tid_location = &reinterpret_cast<struct musl_pthread*>(pthread_self())->tid;
+ *cached_tid_location = real_tid;
+}
+#endif
+
// static
pid_t NamespaceSandbox::ForkInNewPidNamespace(bool drop_capabilities_in_child) {
const pid_t pid =
@@ -226,6 +292,8 @@
#if defined(LIBC_GLIBC)
MaybeUpdateGlibcTidCache();
-#endif
+#else
+ MaybeUpdateMuslTidCache();
+#endif
return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Source: https://git.alpinelinux.org/aports/plain/community/chromium/no-res-ninit-nclose.patch
similar to dns-resolver.patch, musl doesn't have res_ninit and so on
--
--- a/net/dns/public/scoped_res_state.cc
+++ b/net/dns/public/scoped_res_state.cc
@@ -13,7 +13,7 @@
namespace net {

ScopedResState::ScopedResState() {
-#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA)
+#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(_GNU_SOURCE)
// Note: res_ninit in glibc always returns 0 and sets RES_INIT.
// res_init behaves the same way.
memset(&_res, 0, sizeof(_res));
@@ -25,16 +25,8 @@
}

ScopedResState::~ScopedResState() {
-#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
-
- // Prefer res_ndestroy where available.
-#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
- res_ndestroy(&res_);
-#else
- res_nclose(&res_);
-#endif // BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
-
-#endif // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
+ // musl res_init() doesn't actually do anything
+ // no destruction is necessary as no memory has been allocated
}

bool ScopedResState::IsValid() const {
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/./electron/shell/browser/ui/file_dialog.h b/./electron/shell/browser/ui/file_dialog.h
index 6cdfc7b..f7757da 100644
--- a/shell/browser/ui/file_dialog.h
+++ b/shell/browser/ui/file_dialog.h
@@ -13,10 +13,6 @@
#include "base/files/file_path.h"
#include "base/memory/raw_ptr_exclusion.h"

-#if BUILDFLAG(IS_LINUX)
-#include <bits/stdint-uintn.h>
-#endif
-
namespace electron {
class NativeWindow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--- a/build/config/rust.gni
+++ b/build/config/rust.gni
@@ -196,7 +196,18 @@
# a cargo project that dumps the `CARGO_CFG_TARGET_ABI` from its build.rs. See
# https://issues.chromium.org/u/1/issues/372512092#comment5 for an example.
rust_abi_target = ""
-if (is_linux || is_chromeos) {
+if (is_musl) {
+ if (current_cpu == "arm64") {
+ rust_abi_target = "aarch64-unknown-linux-musl"
+ cargo_target_abi = ""
+ } else if (current_cpu == "x86") {
+ rust_abi_target = "i686-unknown-linux-musl"
+ cargo_target_abi = ""
+ } else if (current_cpu == "x64") {
+ rust_abi_target = "x86_64-unknown-linux-musl"
+ cargo_target_abi = ""
+ }
+} else if (is_linux || is_chromeos) {
if (current_cpu == "arm64") {
rust_abi_target = "aarch64-unknown-linux-gnu"
cargo_target_abi = ""
--- a/build/rust/known-target-triples.txt
+++ b/build/rust/known-target-triples.txt
@@ -17,6 +17,7 @@
aarch64-pc-windows-msvc
aarch64-unknown-fuchsia
aarch64-unknown-linux-gnu
+aarch64-unknown-linux-musl
arm64e-apple-ios
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
@@ -28,6 +29,7 @@
i686-linux-android
i686-pc-windows-msvc
i686-unknown-linux-gnu
+i686-unknown-linux-musl
loongarch64-unknown-linux-gnu
riscv64-linux-android
riscv64gc-unknown-linux-gnu
@@ -41,5 +43,6 @@
x86_64-pc-windows-msvc
x86_64-unknown-fuchsia
x86_64-unknown-linux-gnu
+x86_64-unknown-linux-musl
powerpc64le-unknown-linux-gnu
s390x-unknown-linux-gnu
25 changes: 25 additions & 0 deletions srcpkgs/electron39/files/patches/chromium-140-musl-prctl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 98338d64fff786f366b209c14735ff73b2c353bd Mon Sep 17 00:00:00 2001
From: LN Liberda <[email protected]>
Date: Tue, 2 Sep 2025 23:49:49 +0200
Subject: [PATCH] musl/linux: Don't import conflicting libc and kernel headers

/usr/include/sys/prctl.h:88:8: error: redefinition of 'prctl_mm_map'
/usr/include/linux/prctl.h:134:8: note: previous definition is here
---
rtc_base/platform_thread_types.cc | 2 ++
1 file changed, 2 insertions(+)

diff --git a/third_party/webrtc/rtc_base/platform_thread_types.cc b/third_party/webrtcrtc_base/platform_thread_types.cc
index 20bf4afc44..5b26c120e4 100644
--- a/third_party/webrtc/rtc_base/platform_thread_types.cc
+++ b/third_party/webrtcrtc_base/platform_thread_types.cc
@@ -12,7 +12,9 @@

// IWYU pragma: begin_keep
#if defined(WEBRTC_LINUX)
+#if defined(__GLIBC__)
#include <linux/prctl.h>
+#endif
#include <sys/prctl.h>
#include <sys/syscall.h>

Loading