mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
* docs: research Android's child-process limit without developer options * docs: confirm the child-process gaps on the Thor * feat(session): start long-lived daemons in uncounted worker processes * feat(nativeguest): hand long-lived programs to uncounted worker processes * test(session): run the session bus block with dd_spawn * test(nativeguest): cover the exec handoff's wait and kill * feat(session): run the session root, its jobs and the gamescope chain outside the child-process count * feat(setup): the child-process limit no longer blocks Steam while the session runs in workers * feat(audio): run PulseAudio outside the child-process count * feat(nativeguest): hand off posix_spawn children and keep handed-off daemons alive * fix(nativeguest): let Steam end a handed-off game and keep process-group signals * perf(session): exec a worker as soon as its reply is in and keep two bound ahead; fix review findings * fix(nativeguest): address review findings in handoff waits, signals and spawn errors * fix(session): commit each worker launch explicitly and keep workers with the session that asked * fix(session): let a worker wait for its launch commit on the main thread * fix(session): confirm handoffs, honour wait selectors and stop spawns at teardown * fix(session): one owner per handoff exit, worker launch answers and spawn edge cases * fix(session): send a working directory outside the program's root by its real path * fix(session): recheck a taken exit's child and commit a launch only on a whole go line * fix(session): three-step launch, tagged exit reports and lock-free popen and system children * test(native): popen test shell is static, as the other hook fixtures * test(native): run the popen test program with a clean environment * test(native): skip the popen test where a spawn child cannot exec aarch64 * fix(session): confirm the hook before the worker runs, prefer a late report and free a reused pid * fix(session): tell a reused pid's old entry by start time, not the reaped flag * fix(session): silent failed launches, bounded spawn requests and held check-gone writes * test(native): check the unlisted child's status only where a child can exec aarch64 * fix(session): every exit-only waitid goes through the handoff wait * fix(handoff): exact waitid events, safe exit timer, bounded request receipt * feat(handoff): hand off shell children near Android's process limit * fix(agent): tag handed-off game windows outside the reaper * fix(handoff): a handed-off program's getppid() is its forking process * fix(handoff): exact waitid selection, kept Steam and pipe readers, held reports * fix(handoff): getppid() gives init for an exited or replaced parent * fix(handoff): keep __WALL waitid calls on the handoff path * test(handoff): require a zombie parent in the unreaped-parent case * fix(handoff): honor __WNOTHREAD and check every argument for Steam * fix(handoff): stop waiting on a held entry once its parent has exited * fix(handoff): __WNOTHREAD on waits for a pid, flags on every shim reap * fix(handoff): keep the forking thread of each child in the parent * fix(handoff): a wait that finds no child rechecks live handoffs * fix(handoff): keep a child's forking thread until its end is taken * fix(handoff): the thread selector applies to claims in progress too * fix(handoff): controlling-terminal check via /dev/tty, owned records only * fix(handoff): a child whose forking thread ended is any thread's * fix(handoff): a parent /proc cannot read is checked with kill(), then given up * fix(handoff): one-word fork records, changed only by compare-and-swap * fix(handoff): watch the forking parent through a pidfd opened at start * fix(handoff): fork records by pid, a gone thread's children go to the main one * fix(handoff): keep the parent pidfd through dup2 and check it before use * fix(handoff): no handoff without fork records, unknown thread state keeps the owner * fix(handoff): undo a pidfd move when dup fails, recheck it after the poll * fix(handoff): fresh fork records in a forked child, heir is the first live thread * fix(handoff): one lock over a pidfd move, its dup and the undo * fix(handoff): liveness check under the pidfd lock, forget only a reaped pid's record * fix(handoff): lock only dups onto the pidfd, with signals blocked * fix(handoff): fork record generations, no pidfd restore after a failed move * fix(handoff): every dup in a pidfd process locks, fork prep blocks signals * test(semaphores): tell a child hung in qemu-user from a guest deadlock * fix(handoff): fork records matched by the child's start time, never removed * test(semaphores): count only reaped children, only futex waits as emulator stalls * fix(handoff): a known-start bit in fork records * fix(handoff): dup bookkeeping before the pidfd lock, newer fork records kept * fix(handoff): a fork record stays only for the pid's current process * fix(handoff): keep a pending child's fork record when an older fork records late * fix(handoff): an unknown-start fork record never replaces a pending one * fix(handoff): self-recorded forks, ELF and wait option checks, both nofile limits * test(handoff): find the module in the namespace run under discover too * fix(handoff): a spare parent pidfd made at start, so a dup2 onto it makes no fd * test(handoff): require ENOEXEC for an ELF stub; skip the namespace run without binfmt * fix(hook): change the kept fd list under a sequence lock; readers take a copy * fix(handoff): one report per handed-off child; stops keep a claim; nested waits keep their selector * fix(hook): a table made at runtime outlives closes begun before it; unknown-start fork records kept * fix(handoff): waits look before they reap, so a handed-off fork's child is never reported * fix(hook): settle waits out earlier epochs; unknown-start fork records kept for any handoff under way * fix(handoff): generation-checked reap marks, stops taken as stops, close counts reset in a fork * fix(handoff): one given-up table at most, whole stop codes and rusage, WNOWAIT exits rechecked * fix(handoff): requests name their session; stops of handed-off programs reported; cancellable look * fix(handoff): table setup not cancellable; test spawner never runs what it cannot end * fix(handoff): job-control jobs stay counted; unnamed requests refused; cancel-safe setup * docs(phantom): job-control jobs stay counted; listed programs report no stops * fix(handoff): a listed program a shell runs as a job-control job stays counted * refactor(hook): kept descriptors in their own part, a handoff matched by another program The descriptors close(), close_range() and closefrom() leave open move from privileged.c to hook/kept.c (unchanged), so the bionic runtime's exec shim can build the handoff with them. ddh_try_as() matches DD_HANDOFF against one program and sends another: the bionic shim sends "/system/bin/linker64 PROGRAM ARGS" and lists it by PROGRAM. ddh_try() is ddh_try_as() with both the same. * feat(bionic): hand the bionic runtime's Wine programs to the app's workers The glibc session's hook never sees DroidDeck-Bionic's processes (Wine on Android's libc), so a bionic game's Wine programs all stayed counted under the worker running the tool's launch.sh. The handoff is now built into the runtime's exec shim (tools/bionic-runtime/handoff.c, part of libexecshim.so): - hook/handoff.c and hook/kept.c with what the native hook's other parts do around them: fork(), close(), close_range(), dup2(), dup3(), and exit() for the on_exit() bionic lacks - bionic's execv(), execvp(), execl*() reach the execve system call inside libc, past execshim's execve(); Wine starts its preloader with execv(), so the shim defines them on top of its execve() - a linker64 start is listed by its program - the app starts a handed-off program from the glibc root's bash, which cannot load the runtime's LD_PRELOAD/LD_LIBRARY_PATH: they go as arguments of /system/bin/env, which puts them back for the program - launch.sh keeps DD_SPAWN, DD_SPAWN_SESSION, DD_HANDOFF*, DDH_* and DDNATV_ROOT, and its /proc/N/environ reads no longer print "Permission denied" for idle workers (2>/dev/null before the redirect) Pocket FIT, DroidDeck-Bionic 14.1-r67 with this shim and launcher, handoff on: counted during Brawlhalla 25 -> 17, DiRT Showdown 24-27 -> 16, whole run 28 -> 19-20; with Android's limit on no DroidDeck process and no other app's process was killed (before: Discord, BatteryLog helpers); DiRT 75 fps either way. docs/phantom-processes.md: "The bionic runtime". * fix(bionic): hand off only starts that would succeed here; bionic's execvp fallbacks Review follow-ups on the bionic runtime's handoff (tools/bionic-runtime/handoff.c): - A start is handed to a worker only when it would get past execve() in this process: the file is a regular executable outside the app's data (Android refuses execve() there), and for a linker64 start the program it loads is a readable regular file. A start that failed in the worker failed where the caller could not see it, so Wine never tried its next candidate. The hook's own check looked at /system/bin/env, not the program. - A start whose argv[0] is not its file stays here: env starts FILE with FILE as argv[0]. linker64 and interpreter starts are unaffected (their argv[0] is the file). An empty argv stays here too. - Nothing is built for the handoff without DD_SPAWN and DD_HANDOFF. - execvp()/execvpe()/execlp() follow bionic's: an unset PATH is libc's default, an empty PATH or entry is the current directory, and a file the kernel cannot start (ENOEXEC) runs under /system/bin/sh. - close_range() refuses first > last and unknown flags before it splits the range or unshares the table. - The debug line reads the table's owner only once the table is seen published. * fix(bionic): hand off app-data starts only where SELinux lets them run; bare names stay here Follow-up to7d95564f7(review, and a Pocket FIT test of its pack): -7d95564f7kept every start of a file in the app's data here. Wine's preloader is one (a static ELF, so execshim.c cannot make it a linker64 start), and where SELinux is permissive, as on AYANEO's firmware, it runs: Wine then never reached its loader, and its programs ran here, counted again (Pocket FIT: Brawlhalla 26-28 counted vs 16-17 before). Where SELinux enforces, Android refuses the exec, here and in a worker alike, and Wine falls back to its loader, which goes as a linker64 start. Such a start is now handed off when /sys/fs/selinux/enforce reads 0, and stays here otherwise (also when the setting cannot be read). - The program a start would run is checked with the hook's own ddh_startable() (an ELF the kernel loads with its interpreter there, or a script with its interpreter): for a linker64 start, the program it loads. - A file name without '/' stays here: env would look it up in PATH, the exec here in the caller's working directory. - execvpe() skips a PATH entry whose candidate exceeds PATH_MAX (ENAMETOOLONG) instead of copying it onto the stack. * fix(handoff): spawn blocks signals and cancellation across the fork; root flag stored under the stop lock * fix(handoff): a thread that unshares its fd table keeps its own copy of the kept fds * fix(handoff): register the kept list's fork handlers before a split takes its lock * test(handoff): cover WNOHANG with a held forked child, early reaps, blocked waitid and pidfd parents; keep the counted-process exception in translations * test(handoff): exited-entry precondition, atomic checkpoints, a pidfd-only zombie check; validate the shim hold fd * test(handoff): WNOHANG with two handed-off children and for a group; a program's exit while its entry is held * test(handoff): a held exit with no free fd, with and without the parent's pidfd * test(handoff): held-exit tests require the program's own exit status * test(handoff): time held exits from the run, and only once the program is at its exit * perf(handoff): keep the asker's priority, quick tools local, workers bound ahead of a game (#3582) Three fixes that bring handoff-on speed to within 1-2 % of handoff off (AIO D3D11 same session: 3196 -> 3520 fps, 1 % low 444 -> 637) with the same counted processes (benchmark mean 18.5, peak 23): - A handed-off program keeps its asker's priority. Workers are bound from the top app with BIND_IMPORTANT, so Android boosts their main thread to THREAD_PRIORITY_TOP_APP_BOOST (-10); the program the worker execs inherited it. The asker's nice value is sent with the request and set before execve, and a watcher resets it if Android boosts it again. - Quick script tools (awk, sed, grep, cat, ...) stay where they are when the count is near the limit. Sent to a worker, the forked child waits (counted) while a worker starts; run locally it is counted for a few ms. - Workers are bound ahead when a Steam game is queued (16 for 20 s), so Wine's services do not wait on zygote forks at game start. --------- Co-authored-by: The412Banner <the412banner@users.noreply.github.com> Co-authored-by: The412Banner <205237651+The412Banner@users.noreply.github.com>
226 lines
11 KiB
C
226 lines
11 KiB
C
// Part of libddnatv-hook.so, included by ddnatv-hook.c before privileged.c, and of the bionic
|
|
// runtime's exec shim (tools/bionic-runtime/handoff.c): the descriptors close(), close_range() and
|
|
// closefrom() leave open.
|
|
|
|
// The ARM translator of x86 devices and emulators (ndk_translation, houdini) keeps memory files of
|
|
// its own open in the process (ndk_translation at descriptor 3) and needs them whenever it
|
|
// translates more code: a program that closes every descriptor it did not open (sshd at start,
|
|
// closefrom(3)) made it abort later ("CHECK failed" in mmap_posix.cc). Its memory files open when
|
|
// the hook starts survive close(), close_range() and closefrom(); phones that run ARM code
|
|
// themselves have none.
|
|
#define DDNATV_MAX_KEPT_FDS 12
|
|
static int g_kept_fds[DDNATV_MAX_KEPT_FDS]; // ascending
|
|
static int g_kept_fd_count = 0;
|
|
// Of those, the ones also kept from close-on-exec: a worker process's binder fds (hook/handoff.c),
|
|
// which must outlive the program's own execs.
|
|
static int g_cloexec_kept_fds[8]; // ascending
|
|
static int g_cloexec_kept_count = 0;
|
|
|
|
// The list can change while the program runs (hook/handoff.c keeps and lets go of its own fds): odd
|
|
// while a change is under way, which kept_change_begin() and kept_change_end() bracket. Readers take
|
|
// a whole copy (kept_snapshot()), so that another thread's close() or close_range() never works
|
|
// from a list half moved, which could close a kept fd.
|
|
static unsigned g_kept_seq;
|
|
static pthread_mutex_t g_kept_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
static __thread uint64_t t_kept_mask;
|
|
|
|
// A thread that split its descriptor table from the others' (close_range() with
|
|
// CLOSE_RANGE_UNSHARE) goes on with a copy of the list made at the split, which only it reads and
|
|
// changes: the shared list keeps describing the other threads' table, so a kept fd this thread's
|
|
// program takes over (a dup2() onto the parent's pidfd) stays kept there. A child it forks takes the
|
|
// copy over as its list (kept_forked()).
|
|
static __thread int t_kept_split;
|
|
static __thread int t_kept_fds[DDNATV_MAX_KEPT_FDS];
|
|
static __thread int t_kept_count;
|
|
// In a process forked from such a thread: numbers published for the shared table (the handoff table's)
|
|
// may name other files here, or none.
|
|
static int g_kept_split;
|
|
|
|
static int kept_snapshot(int *out) {
|
|
if (t_kept_split) {
|
|
for (int i = 0; i < t_kept_count; i++) out[i] = t_kept_fds[i];
|
|
return t_kept_count;
|
|
}
|
|
for (;;) {
|
|
unsigned seq = __atomic_load_n(&g_kept_seq, __ATOMIC_ACQUIRE);
|
|
if (seq & 1) continue;
|
|
int n = __atomic_load_n(&g_kept_fd_count, __ATOMIC_RELAXED);
|
|
if (n > DDNATV_MAX_KEPT_FDS) n = DDNATV_MAX_KEPT_FDS;
|
|
for (int i = 0; i < n; i++) out[i] = __atomic_load_n(&g_kept_fds[i], __ATOMIC_RELAXED);
|
|
__atomic_thread_fence(__ATOMIC_ACQUIRE);
|
|
if (__atomic_load_n(&g_kept_seq, __ATOMIC_RELAXED) == seq) return n;
|
|
}
|
|
}
|
|
|
|
static void kept_fork_prepare(void) { pthread_mutex_lock(&g_kept_lock); }
|
|
static void kept_fork_done(void) { pthread_mutex_unlock(&g_kept_lock); }
|
|
static void kept_register_fork(void) { pthread_atfork(kept_fork_prepare, kept_fork_done, kept_fork_done); }
|
|
|
|
// Before anything takes g_kept_lock: a fork() in another thread then waits for it to be let go.
|
|
static void kept_register_once(void) {
|
|
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
|
pthread_once(&once, kept_register_fork);
|
|
}
|
|
|
|
// Every signal blocked meanwhile, so that no handler on this thread reads the list half changed (it
|
|
// would wait for the change forever) or changes it too; a fork() waits for the change to end, so a
|
|
// child never starts with one under way.
|
|
static void kept_change_begin(void) {
|
|
kept_register_once();
|
|
uint64_t all = ~0ull;
|
|
call_orig_syscall(SYS_rt_sigprocmask, SIG_SETMASK, (unsigned long)&all, (unsigned long)&t_kept_mask, 8, 0, 0);
|
|
pthread_mutex_lock(&g_kept_lock);
|
|
__atomic_store_n(&g_kept_seq, g_kept_seq + 1, __ATOMIC_RELAXED);
|
|
__atomic_thread_fence(__ATOMIC_RELEASE);
|
|
}
|
|
|
|
static void kept_change_end(void) {
|
|
__atomic_store_n(&g_kept_seq, g_kept_seq + 1, __ATOMIC_RELEASE);
|
|
pthread_mutex_unlock(&g_kept_lock);
|
|
call_orig_syscall(SYS_rt_sigprocmask, SIG_SETMASK, (unsigned long)&t_kept_mask, 0, 8, 0, 0);
|
|
}
|
|
|
|
static int kept_any(void) {
|
|
return t_kept_split ? t_kept_count : __atomic_load_n(&g_kept_fd_count, __ATOMIC_RELAXED);
|
|
}
|
|
|
|
// The process's threads (/proc/self/stat), or 0 when it cannot be read.
|
|
static int kept_threads(void) {
|
|
char buf[512];
|
|
int fd = (int)call_orig_syscall(SYS_openat, (unsigned long)AT_FDCWD, (unsigned long)"/proc/self/stat",
|
|
O_RDONLY | O_CLOEXEC, 0, 0, 0);
|
|
if (fd < 0) return 0;
|
|
long n = call_orig_syscall(SYS_read, (unsigned long)fd, (unsigned long)buf, sizeof(buf) - 1, 0, 0, 0);
|
|
call_orig_syscall(SYS_close, (unsigned long)fd, 0, 0, 0, 0, 0);
|
|
if (n <= 0) return 0;
|
|
buf[n] = 0;
|
|
char *p = strrchr(buf, ')');
|
|
// after the name: state, then 16 fields to num_threads
|
|
for (int field = 0; p && field < 18; field++) p = strchr(p + 1, ' ');
|
|
return p ? atoi(p + 1) : 0;
|
|
}
|
|
|
|
// The calling thread's table split by split() (0, or -1 with errno), with the list copied for it in
|
|
// the same step: no keep or let-go of another thread falls between the copy and the split. A process
|
|
// with one thread keeps one table (the system copies only a shared one), and so one list. Threads that
|
|
// a thread with a table of its own starts later share that table but not its copy: not followed.
|
|
static int kept_split(int (*split)(void)) {
|
|
if (t_kept_split) return split();
|
|
kept_register_once();
|
|
uint64_t all = ~0ull, mask = 0;
|
|
call_orig_syscall(SYS_rt_sigprocmask, SIG_SETMASK, (unsigned long)&all, (unsigned long)&mask, 8, 0, 0);
|
|
pthread_mutex_lock(&g_kept_lock);
|
|
int shared = kept_threads() != 1;
|
|
int r = split();
|
|
int saved = errno;
|
|
if (r == 0 && shared) {
|
|
int n = g_kept_fd_count;
|
|
for (int i = 0; i < n; i++) t_kept_fds[i] = g_kept_fds[i];
|
|
t_kept_count = n;
|
|
t_kept_split = 1;
|
|
}
|
|
pthread_mutex_unlock(&g_kept_lock);
|
|
call_orig_syscall(SYS_rt_sigprocmask, SIG_SETMASK, (unsigned long)&mask, 0, 8, 0, 0);
|
|
errno = saved;
|
|
return r;
|
|
}
|
|
|
|
// In a forked child, whose only thread is the one that forked: a split thread's table is the child's.
|
|
static void kept_forked(void) {
|
|
if (!t_kept_split) return;
|
|
for (int i = 0; i < t_kept_count; i++) g_kept_fds[i] = t_kept_fds[i];
|
|
g_kept_fd_count = t_kept_count;
|
|
t_kept_split = 0;
|
|
g_kept_split = 1;
|
|
}
|
|
|
|
static int is_kept_fd(int fd) {
|
|
int kept[DDNATV_MAX_KEPT_FDS];
|
|
int n = kept_snapshot(kept);
|
|
for (int i = 0; i < n; i++) {
|
|
if (kept[i] == fd) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Closes under way (close(), close_range()), counted by the epoch they began in: one that looked at
|
|
// the list before a fd was added to it may still close that fd. A thread that makes and keeps a fd
|
|
// while others run (hook/handoff.c's table) moves the epoch on afterwards, waits for the closes of
|
|
// the one before (kept_settle()), and only then trusts the fd to be its own still.
|
|
static unsigned g_close_epoch;
|
|
// Per epoch, generation << 32 | count, one word: every change is one compare-and-swap, so a fork from
|
|
// a handler that interrupted a close's begin or end never splits one in two. A forked child moves the
|
|
// generation on and starts from none (kept_close_forked()): an end whose generation is gone counts
|
|
// nothing, and a begin whose swap failed takes the child's.
|
|
static uint64_t g_closers[2];
|
|
|
|
static void kept_close_end(uint64_t ticket);
|
|
|
|
// The close's ticket: generation << 1 | epoch
|
|
static uint64_t kept_close_begin(void) {
|
|
for (;;) {
|
|
unsigned epoch = __atomic_load_n(&g_close_epoch, __ATOMIC_SEQ_CST) & 1;
|
|
uint64_t word = __atomic_load_n(&g_closers[epoch], __ATOMIC_SEQ_CST);
|
|
if (!__atomic_compare_exchange_n(&g_closers[epoch], &word, word + 1, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
|
|
continue;
|
|
uint64_t ticket = (word >> 32) << 1 | epoch;
|
|
if ((__atomic_load_n(&g_close_epoch, __ATOMIC_SEQ_CST) & 1) == epoch) return ticket;
|
|
kept_close_end(ticket); // the epoch moved on meanwhile: counted in the new one instead
|
|
}
|
|
}
|
|
|
|
static void kept_close_end(uint64_t ticket) {
|
|
unsigned epoch = (unsigned)(ticket & 1);
|
|
uint64_t word = __atomic_load_n(&g_closers[epoch], __ATOMIC_SEQ_CST);
|
|
while ((word >> 32) == (ticket >> 1) && (word & 0xffffffffu) != 0 &&
|
|
!__atomic_compare_exchange_n(&g_closers[epoch], &word, word - 1, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
|
|
}
|
|
}
|
|
|
|
// In a forked child: the closes the parent's threads were making are not the child's to wait for.
|
|
// (The forking thread's own, a close a handler interrupted to fork, then goes uncounted.)
|
|
static void kept_close_forked(void) {
|
|
for (int epoch = 0; epoch < 2; epoch++) {
|
|
uint64_t word = __atomic_load_n(&g_closers[epoch], __ATOMIC_SEQ_CST);
|
|
__atomic_store_n(&g_closers[epoch], ((word >> 32) + 1) << 32, __ATOMIC_SEQ_CST);
|
|
}
|
|
}
|
|
|
|
static int kept_drained(unsigned epoch) {
|
|
for (int i = 0; i < 1000; i++) {
|
|
if ((__atomic_load_n(&g_closers[epoch], __ATOMIC_SEQ_CST) & 0xffffffffu) == 0) return 1;
|
|
struct timespec pause = {0, 1000 * 1000};
|
|
nanosleep(&pause, NULL);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// 1 once every close that began before now has ended; 0 after a second without (one interrupted by
|
|
// a signal whose handler is the caller, say): then nothing it made since can be trusted. The epoch
|
|
// moves on only once the closes of the one before it are over too, so the two counts never mix one
|
|
// that is still under way from an earlier settle that gave up with the current one.
|
|
static int kept_settle(void) {
|
|
unsigned current = __atomic_load_n(&g_close_epoch, __ATOMIC_SEQ_CST) & 1;
|
|
if (!kept_drained(current ^ 1)) return 0;
|
|
unsigned old = __atomic_fetch_add(&g_close_epoch, 1, __ATOMIC_SEQ_CST) & 1;
|
|
return kept_drained(old);
|
|
}
|
|
|
|
// Calls fn for each part of [first, last] that leaves out the descriptors in kept (ascending);
|
|
// the first nonzero answer of fn is returned, else 0.
|
|
static int for_each_range_without(unsigned int first, unsigned int last, const int *kept, int nkept,
|
|
int (*fn)(unsigned int, unsigned int, void *), void *arg) {
|
|
unsigned int from = first;
|
|
for (int i = 0; i < nkept && from <= last; i++) {
|
|
if (kept[i] < 0 || (unsigned int)kept[i] < from || (unsigned int)kept[i] > last) continue;
|
|
unsigned int k = (unsigned int)kept[i];
|
|
if (k > from) {
|
|
int r = fn(from, k - 1, arg);
|
|
if (r != 0) return r;
|
|
}
|
|
if (k == last) return 0;
|
|
from = k + 1;
|
|
}
|
|
return from <= last ? fn(from, last, arg) : 0;
|
|
}
|