34 # include <sys/mman.h>
81 char *error_addr = (
char *)siginfo->si_addr;
87 if (error_addr >=
file->memory && error_addr < file->memory +
file->length) {
88 file->io_error =
true;
91 const void *mapped_memory = mmap(
92 file->memory,
file->length, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
93 if (mapped_memory == MAP_FAILED) {
94 fprintf(stderr,
"SIGBUS handler: Error replacing mapped file with zeros\n");
106 fprintf(stderr,
"Unhandled SIGBUS caught\n");
115 struct sigaction newact = {0}, oldact = {0};
118 newact.sa_flags = SA_SIGINFO;
120 if (sigaction(SIGBUS, &newact, &oldact)) {
149 void *memory, *handle =
NULL;
159 memory = mmap(
NULL,
length, PROT_READ, MAP_PRIVATE, fd, 0);
160 if (memory == MAP_FAILED) {
165 void *file_handle = (
void *)_get_osfhandle(fd);
169 handle = CreateFileMapping(file_handle,
NULL, PAGE_READONLY, 0, 0,
NULL);
170 if (handle ==
NULL) {
173 memory = MapViewOfFile(handle, FILE_MAP_READ, 0, 0, 0);
174 if (memory ==
NULL) {
182 file->memory = memory;
183 file->handle = handle;
211 __except (GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR ? EXCEPTION_EXECUTE_HANDLER :
212 EXCEPTION_CONTINUE_SEARCH) {
213 file->io_error =
true;
218 return !
file->io_error;
229 munmap((
void *)
file->memory,
file->length);
232 UnmapViewOfFile(
file->memory);
233 CloseHandle(
file->handle);
File and directory operations.
int64_t BLI_lseek(int fd, int64_t offset, int whence)
#define LISTBASE_FOREACH(type, var, list)
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
struct LinkData * BLI_genericNodeN(void *data)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static bool sigbus_handler_setup(void)
void BLI_mmap_free(BLI_mmap_file *file)
bool BLI_mmap_read(BLI_mmap_file *file, void *dest, size_t offset, size_t length)
static void sigbus_handler_remove(BLI_mmap_file *file)
static void sigbus_handler(int sig, siginfo_t *siginfo, void *ptr)
static struct error_handler_data error_handler
static void sigbus_handler_add(BLI_mmap_file *file)
BLI_mmap_file * BLI_mmap_open(int fd)
void * BLI_mmap_get_pointer(BLI_mmap_file *file)
Compatibility-like things for windows.
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void(* next_handler)(int, siginfo_t *, void *)