sandbox: Support unmapping a file
authorSimon Glass <sjg@chromium.org>
Sat, 23 Oct 2021 23:25:58 +0000 (17:25 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 28 Nov 2021 23:51:51 +0000 (16:51 -0700)
Add the opposite of mapping, so that we can unmap and avoid running out of
address space.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/os.c
include/os.h

index b72dafc..873f85a 100644 (file)
@@ -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;
index 770d76e..4cbcbd9 100644 (file)
@@ -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
  *