[U-Boot] [PATCH 01/15] sandbox: Unprotect DATA regions in bus tests
Simon Glass
sjg at chromium.org
Sun Sep 23 22:47:13 UTC 2018
On my Ubuntu 18.04.1 machine two driver-model bus tests have started
failing recently. The problem appears to be that the DATA region of the
executable is protected. This does not seem correct, but perhaps there
is a reason.
To work around it, unprotect the regions in these tests before accessing
them.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
arch/sandbox/cpu/os.c | 11 +++++++++++
include/os.h | 11 +++++++++++
test/dm/bus.c | 12 ++++++++++++
3 files changed, 34 insertions(+)
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 5839932b005..8b860959f05 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -651,3 +651,14 @@ void os_longjmp(ulong *jmp, int ret)
{
longjmp((struct __jmp_buf_tag *)jmp, ret);
}
+
+int os_mprotect_allow(void *start, size_t len)
+{
+ int page_size = getpagesize();
+
+ /* Move start to the start of a page, len to the end */
+ start = (void *)(((ulong)start) & ~(page_size - 1));
+ len = (len + page_size * 2) & ~(page_size - 1);
+
+ return mprotect(start, len, PROT_READ | PROT_WRITE);
+}
diff --git a/include/os.h b/include/os.h
index c8e0f52d306..54b6044df29 100644
--- a/include/os.h
+++ b/include/os.h
@@ -351,4 +351,15 @@ int os_setjmp(ulong *jmp, int size);
*/
void os_longjmp(ulong *jmp, int ret);
+/**
+ * os_mprotect_allow() - Remove write-protection on a region of memory
+ *
+ * The start and length will be page-aligned before use.
+ *
+ * @start: Region start
+ * @len: Region length in bytes
+ * @return 0 if OK, -1 on error from mprotect()
+ */
+int os_mprotect_allow(void *start, size_t len);
+
#endif
diff --git a/test/dm/bus.c b/test/dm/bus.c
index e9a4028f047..08137a2216a 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -4,6 +4,9 @@
*/
#include <common.h>
+#ifdef CONFIG_SANDBOX
+#include <os.h>
+#endif
#include <dm.h>
#include <dm/device-internal.h>
#include <dm/test.h>
@@ -297,6 +300,11 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
size = drv->per_child_auto_alloc_size;
+
+#ifdef CONFIG_SANDBOX
+ os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+ os_mprotect_allow(drv, sizeof(*drv));
+#endif
bus->uclass->uc_drv->per_child_auto_alloc_size = size;
drv->per_child_auto_alloc_size = 0;
ret = test_bus_parent_data(uts);
@@ -440,6 +448,10 @@ static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
size = drv->per_child_platdata_auto_alloc_size;
+#ifdef CONFIG_SANDBOX
+ os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+ os_mprotect_allow(drv, sizeof(*drv));
+#endif
bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
drv->per_child_platdata_auto_alloc_size = 0;
ret = test_bus_parent_platdata(uts);
--
2.19.0.444.g18242da7ef-goog
More information about the U-Boot
mailing list