git: 7743778bf19a - stable/13 - kboot: Implement munmap(2)

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:10:57 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7743778bf19a1625ef4a2e801fee91dab3c934bb

commit 7743778bf19a1625ef4a2e801fee91dab3c934bb
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-06-27 23:49:21 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:24 +0000

    kboot: Implement munmap(2)
    
    Define host_munmap so we can use it in the x86 code to find things for
    the BIOS/CMS boot path and unmap after we find it.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit 76949f503f008b28865bd0fd026a550a3cb48619)
---
 stand/kboot/arch/amd64/syscall_nr.h     | 1 +
 stand/kboot/arch/powerpc64/syscall_nr.h | 1 +
 stand/kboot/host_syscall.h              | 1 +
 stand/kboot/host_syscalls.c             | 6 ++++++
 4 files changed, 9 insertions(+)

diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h
index c22c80ea7cb9..7813eff92890 100644
--- a/stand/kboot/arch/amd64/syscall_nr.h
+++ b/stand/kboot/arch/amd64/syscall_nr.h
@@ -4,6 +4,7 @@
 #define SYS_kexec_load		246
 #define SYS_lseek		  8
 #define SYS_mmap		  9
+#define	SYS_munmap		 11
 #define SYS_newfstat		  5
 #define SYS_newfstatat		262
 #define SYS_openat		257
diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h
index aa94e6a82bb7..9471fd48ceb2 100644
--- a/stand/kboot/arch/powerpc64/syscall_nr.h
+++ b/stand/kboot/arch/powerpc64/syscall_nr.h
@@ -5,6 +5,7 @@
 #define SYS_kexec_load		268
 #define SYS_llseek		140
 #define SYS_mmap		 90
+#define	SYS_munmap		 91
 #define SYS_newfstat		SYS_fstat
 #define SYS_newfstatat		291
 #define SYS_openat		286
diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 6ff20f7ba393..8007f29feb9d 100644
--- a/stand/kboot/host_syscall.h
+++ b/stand/kboot/host_syscall.h
@@ -96,6 +96,7 @@ int host_gettimeofday(struct host_timeval *a, void *b);
 int host_kexec_load(uint32_t start, int nsegs, uint32_t segs, uint32_t flags);
 ssize_t host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence);
 void *host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off);
+int host_munmap(void *addr, size_t len);
 int host_open(const char *path, int flags, int mode);
 ssize_t host_read(int fd, void *buf, size_t nbyte);
 int host_reboot(int, int, int, uintptr_t);
diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c
index 9cc6c6cd873e..3cfccdc0c718 100644
--- a/stand/kboot/host_syscalls.c
+++ b/stand/kboot/host_syscalls.c
@@ -57,6 +57,12 @@ host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
 	return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off);
 }
 
+int
+host_munmap(void *addr, size_t len)
+{
+	return host_syscall(SYS_munmap, (uintptr_t)addr, len);
+}
+
 int
 host_open(const char *path, int flags, int mode)
 {