int sef_llvm_state_transfer(sef_init_info_t *info);
int sef_llvm_add_special_mem_region(void *addr, size_t len, const char* name);
int sef_llvm_del_special_mem_region_by_addr(void *addr);
+void *sef_llvm_ac_mmap(void *buf, size_t len, int prot, int flags, int fd,
+ off_t offset);
+int sef_llvm_ac_munmap(void *buf, size_t len);
int sef_llvm_ltckpt_enabled(void);
int sef_llvm_get_ltckpt_offset(void);
void *alloc_contig(size_t len, int flags, phys_bytes *phys)
{
- vir_bytes buf;
+ void* buf;
int mmapflags = MAP_PREALLOC|MAP_CONTIG|MAP_ANON;
if(flags & AC_LOWER16M)
* pre-allocated and contiguous.
*/
errno = 0;
- buf = (vir_bytes) mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0);
-
- if(buf == (vir_bytes) MAP_FAILED) {
+ buf = sef_llvm_ac_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0);
+ if(buf == MAP_FAILED) {
return NULL;
}
/* Get physical address, if requested. */
- if(phys != NULL && sys_umap(SELF, VM_D, buf, len, phys) != OK)
+ if(phys != NULL && sys_umap(SELF, VM_D, (vir_bytes)buf, len,
+ phys) != OK)
panic("sys_umap_data_fb failed");
- return (void *) buf;
+ return buf;
}
int free_contig(void *addr, size_t len)
{
- return munmap(addr, len);
+ return sef_llvm_ac_munmap(addr, len);
}
return st_del_special_mmapped_region_by_addr(addr);
}
+/*===========================================================================*
+ * sef_llvm_ac_mmap *
+ *===========================================================================*/
+void* sef_llvm_ac_mmap(void *buf, size_t len, int prot, int flags, int fd,
+ off_t offset)
+{
+ int r;
+ extern void* __attribute__((weak))
+ _magic_real_mmap(void*, size_t, int, int, int, off_t);
+ if (!_magic_real_mmap)
+ return mmap(buf, len, prot, flags, fd, offset);
+
+ /* Avoid regular dsentries for non-relocatable regions (e.g., DMA buffers).
+ */
+ buf = _magic_real_mmap(buf, len, prot, flags, fd, offset);
+ if(buf == MAP_FAILED)
+ return buf;
+ r = sef_llvm_add_special_mem_region(buf, len, NULL);
+ if(r < 0)
+ printf("sef_llvm_add_special_mem_region failed: %d\n", r);
+ return buf;
+}
+
+/*===========================================================================*
+ * sef_llvm_ac_munmap *
+ *===========================================================================*/
+int sef_llvm_ac_munmap(void *buf, size_t len)
+{
+ int r;
+ extern int __attribute__((weak)) _magic_real_munmap(void*, size_t);
+ if (!_magic_real_munmap)
+ return munmap(buf, len);
+
+ if ((r = _magic_real_munmap(buf, len)) != 0)
+ return r;
+ if ((r = sef_llvm_del_special_mem_region_by_addr(buf)) < 0)
+ printf("sef_llvm_del_special_mem_region_by_addr failed: %d\n", r);
+ return 0;
+}
+
/*===========================================================================*
* sef_llvm_ltckpt_enabled *
*===========================================================================*/