From 35053ab4bb8fe09818da9421a053e2e13c7ad817 Mon Sep 17 00:00:00 2001
From: bb-cat <ningyu9@huawei.com>
Date: Wed, 2 Mar 2022 13:34:10 +0800
Subject: [PATCH 03/72] kerndat: check for rseq syscall support Signed-off-by:
 Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>

---
 criu/include/kerndat.h |  1 +
 criu/kerndat.c         | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index 80bad7f..44a6976 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -74,6 +74,7 @@ struct kerndat_s {
 	bool has_pidfd_getfd;
 	bool has_nspid;
 	bool has_nftables_concat;
+	bool has_rseq;
 };
 
 extern struct kerndat_s kdat;
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 0e88ba4..f5a4490 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -816,6 +816,20 @@ static int kerndat_x86_has_ptrace_fpu_xsave_bug(void)
 	return 0;
 }
 
+static int kerndat_has_rseq(void)
+{
+	if (syscall(__NR_rseq, NULL, 0, 0, 0) != -1) {
+		pr_err("rseq should fail\n");
+		return -1;
+	}
+	if (errno == ENOSYS)
+		pr_info("rseq syscall isn't supported\n");
+	else
+		kdat.has_rseq = true;
+
+	return 0;
+}
+
 #define KERNDAT_CACHE_FILE     KDAT_RUNDIR "/criu.kdat"
 #define KERNDAT_CACHE_FILE_TMP KDAT_RUNDIR "/.criu.kdat"
 
@@ -1360,6 +1374,10 @@ int kerndat_init(void)
 		ret = -1;
 	}
 
+	if (!ret && kerndat_has_rseq()) {
+		pr_err("kerndat_has_rseq failed when initializing kerndat.\n");
+		ret = -1;
+	}
 	kerndat_lsm();
 	kerndat_mmap_min_addr();
 	kerndat_files_stat();
-- 
2.34.1

