+ int ret;
+
+ ret = munmap(ptr, size);
+ if (ret != 0 && (size & (HUGETLB_PAGESIZE - 1))) {
+ // prehaps an autorounded hugetlb mapping?
+ size = (size + HUGETLB_PAGESIZE - 1) & ~(HUGETLB_PAGESIZE - 1);
+ ret = munmap(ptr, size);
+ }
+ if (ret != 0) {
+ fprintf(stderr,
+ "munmap(%p, %zu) failed: %d\n", ptr, size, errno);
+ }
+}
+
+int plat_mem_set_exec(void *ptr, size_t size)
+{
+ int ret = mprotect(ptr, size, PROT_READ | PROT_WRITE | PROT_EXEC);
+ if (ret != 0)
+ fprintf(stderr, "mprotect(%p, %zd) failed: %d\n",
+ ptr, size, errno);
+
+ return ret;