summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-11-10 15:07:31 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-11-10 15:07:31 +0100
commit0b0eada569b198aa3882cfec5874bc35a8a0fa14 (patch)
tree061ca4528bfaee38df3faae6ff1a6be6d4993fe6 /include
parent34ea8b9317afad6ed2cb702c911cbcbad9d3bf23 (diff)
parent706ef1bf6fed8dd2c75c469ad4bc758da2cb4cf3 (diff)
downloadbarebox-0b0eada569b198aa3882cfec5874bc35a8a0fa14.tar.gz
barebox-0b0eada569b198aa3882cfec5874bc35a8a0fa14.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'include')
-rw-r--r--include/zero_page.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/zero_page.h b/include/zero_page.h
new file mode 100644
index 0000000000..ad6861f240
--- /dev/null
+++ b/include/zero_page.h
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ZERO_PAGE_H
+#define __ZERO_PAGE_H
+
+#include <common.h>
+
+#if defined CONFIG_ARCH_HAS_ZERO_PAGE
+
+/*
+ * zero_page_faulting - fault when accessing the zero page
+ */
+void zero_page_faulting(void);
+
+/*
+ * zero_page_access - allow accesses to the zero page
+ *
+ * Disable the null pointer trap on the zero page if access to the zero page
+ * is actually required. Disable the trap with care and re-enable it
+ * immediately after the access to properly trap null pointers.
+ */
+void zero_page_access(void);
+
+#else
+
+static inline void zero_page_faulting(void)
+{
+}
+
+static inline void zero_page_access(void)
+{
+}
+
+#endif
+
+static inline bool zero_page_contains(unsigned long addr)
+{
+ return addr < PAGE_SIZE;
+}
+
+/*
+ * zero_page_memcpy - copy to or from an address located in the zero page
+ */
+static inline void *zero_page_memcpy(void *dest, const void *src, size_t count)
+{
+ void *ret;
+
+ zero_page_access();
+ ret = memcpy(dest, src, count);
+ zero_page_faulting();
+
+ return ret;
+}
+
+#endif /* __ZERO_PAGE_H */