diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index 49be1e74d6..446996a06e 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -552,7 +552,11 @@ int prctl(int option, ...) { unsigned long arg4 = va_arg(ap, unsigned long); unsigned long arg5 = va_arg(ap, unsigned long); va_end(ap); + volatile unsigned char *dispatch = zr_dispatch; + unsigned char selector = dispatch != NULL ? *dispatch : 0; + if (selector) *dispatch = 0; long result = zr_sys(SYS_prctl, option, arg2, arg3, arg4, arg5); + if (selector) *dispatch = selector; if ((unsigned long)result > -4096UL) { errno = (int)-result; return -1; diff --git a/tools/tests/test_zram_preload.py b/tools/tests/test_zram_preload.py index 8996e56cc5..3d6b7d6126 100644 --- a/tools/tests/test_zram_preload.py +++ b/tools/tests/test_zram_preload.py @@ -223,7 +223,7 @@ static void *writer(void *arg) { } static volatile unsigned char dispatch_selector; -static int dispatch_traps, dispatch_done; +static int dispatch_traps, dispatch_done, dispatch_ready; static long dispatch_result = -1; static void dispatch_trap(int sig, siginfo_t *info, void *context) { @@ -248,6 +248,7 @@ static void *dispatch_signaller(void *arg) { if (!f) exit(3); fprintf(f, "2 %ld\n", 1L << 30); fclose(f); + while (!__atomic_load_n(&dispatch_ready, __ATOMIC_ACQUIRE)) usleep(1000); kill(getpid(), SIGURG); for (int i = 0; i < 1200 && dispatch_result < 0; i++) { f = fopen(ack, "r"); @@ -451,13 +452,17 @@ int main(int argc, char **argv) { pthread_t signaller; pthread_create(&signaller, NULL, dispatch_signaller, NULL); dispatch_selector = 1; + __atomic_store_n(&dispatch_ready, 1, __ATOMIC_RELEASE); while (!__atomic_load_n(&dispatch_done, __ATOMIC_ACQUIRE)) { } + char name[16] = {0}; + int named = prctl(PR_GET_NAME, name, 0, 0, 0) == 0 && name[0] != 0; dispatch_selector = 0; prctl(59, 0, 0, 0, 0); pthread_join(signaller, NULL); printf("traps %d\n", __atomic_load_n(&dispatch_traps, __ATOMIC_RELAXED)); printf("trimmed %d\n", dispatch_result >= 0); + printf("named %d\n", named); return 0; } else if (!strcmp(argv[4], "burst")) { send_request('0'); @@ -766,6 +771,7 @@ class ZramPreloadTest(unittest.TestCase): self.skipTest("kernel lacks syscall user dispatch") self.assertEqual([0], out["traps"], out) self.assertEqual([1], out["trimmed"], out) + self.assertEqual([1], out["named"], out) if __name__ == "__main__":