Skip to content

Commit 3b87f9a

Browse files
lxc/rexec.c: fixed memfd-rexec on android
not enabled by default Signed-off-by: DreamConnected <1487442471@qq.com>
1 parent 9c15a90 commit 3b87f9a

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

.github/workflows/code-test.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
meson setup build \
3030
-Dprefix=/data/share \
31-
-Dinit-script=sysvinit \
31+
-Dinit-script=monitd \
3232
-Druntime-path=/data/local/tmp \
3333
-Dstrip=true \
3434
-Dd_lto=true \
@@ -48,3 +48,15 @@ jobs:
4848
--cross-file aarch64-android-api30.txt
4949
5050
meson compile -C build
51+
52+
- name: Upload artifacts sysroot
53+
uses: actions/upload-artifact@v4.3.1
54+
with:
55+
name: android-aarch64-deps-shared-api30
56+
path: /data/sysroot/*
57+
58+
- name: Upload artifacts lxc
59+
uses: actions/upload-artifact@v4.3.1
60+
with:
61+
name: android-aarch64-lxc-shared-api30
62+
path: /data/share/*

src/lxc/rexec.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name)
9696
tmpfd = -EBADF;
9797
int ret;
9898
ssize_t bytes_sent = 0;
99+
#if IS_BIONIC && __ANDROID_API__ >= 30
100+
off_t fd_size = -1;
101+
#else
102+
#error "memfd_create() not implemented under Android 30"
99103
struct stat st = {0};
104+
#endif
100105

101106
memfd = memfd_create(memfd_name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
102107
if (memfd < 0) {
@@ -121,15 +126,32 @@ static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name)
121126
return;
122127

123128
/* sendfile() handles up to 2GB. */
129+
#if IS_BIONIC
130+
fd_size = lseek(fd, 0, SEEK_END);
131+
if (fd_size < 0) {
132+
return;
133+
}
134+
135+
lseek(fd, 0, SEEK_SET);
136+
#else
124137
ret = fstat(fd, &st);
125138
if (ret)
126139
return;
140+
#endif
127141

142+
#if IS_BIONIC
143+
while (bytes_sent < fd_size) {
144+
#else
128145
while (bytes_sent < st.st_size) {
146+
#endif
129147
ssize_t sent;
130148

131149
sent = lxc_sendfile_nointr(memfd >= 0 ? memfd : tmpfd, fd, NULL,
150+
#if IS_BIONIC
151+
fd_size - (off_t)bytes_sent);
152+
#else
132153
st.st_size - bytes_sent);
154+
#endif
133155
if (sent < 0) {
134156
/*
135157
* Fallback to shoveling data between kernel- and
@@ -166,7 +188,11 @@ static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name)
166188
if (execfd < 0)
167189
return;
168190

191+
#if IS_BIONIC
192+
execveat(execfd, "", argv, envp, AT_EMPTY_PATH);
193+
#else
169194
fexecve(execfd, argv, envp);
195+
#endif
170196
}
171197

172198
/*

0 commit comments

Comments
 (0)