[PATCH v2 04/41] sandbox: Support unmapping a file

Simon Glass sjg at chromium.org
Sun Oct 24 01:25:58 CEST 2021


Add the opposite of mapping, so that we can unmap and avoid running out of
address space.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 arch/sandbox/cpu/os.c | 10 ++++++++++
 include/os.h          |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index b72dafca2ba..873f85ac3be 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -211,6 +211,16 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep)
 	return 0;
 }
 
+int os_unmap(void *buf, int size)
+{
+	if (munmap(buf, size)) {
+		printf("Can't unmap %p %x\n", buf, size);
+		return -EIO;
+	}
+
+	return 0;
+}
+
 /* Restore tty state when we exit */
 static struct termios orig_term;
 static bool term_setup;
diff --git a/include/os.h b/include/os.h
index 770d76e02f7..4cbcbd93a71 100644
--- a/include/os.h
+++ b/include/os.h
@@ -419,6 +419,15 @@ int os_read_file(const char *name, void **bufp, int *sizep);
  */
 int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep);
 
+/**
+ * os_unmap() - Unmap a file previously mapped
+ *
+ * @buf: Mapped address
+ * @size: Size in bytes
+ * Return:	0 if OK, -ve on error
+ */
+int os_unmap(void *buf, int size);
+
 /*
  * os_find_text_base() - Find the text section in this running process
  *
-- 
2.33.0.1079.g6e70778dc9-goog



More information about the U-Boot mailing list