66 const char *error_addr = (
const char *)siginfo->si_addr;
72 if (error_addr >= file->memory && error_addr < file->memory + file->length) {
76 const void *mapped_memory = mmap(
77 file->memory, file->length, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
78 if (mapped_memory == MAP_FAILED) {
79 fprintf(stderr,
"SIGBUS handler: Error replacing mapped file with zeros\n");
91 fprintf(stderr,
"Unhandled SIGBUS caught\n");
100 struct sigaction newact = {0}, oldact = {0};
103 newact.sa_flags = SA_SIGINFO;
105 if (sigaction(SIGBUS, &newact, &oldact)) {
134 void *memory, *handle =
NULL;
135 const size_t length =
BLI_lseek(fd, 0, SEEK_END);
136 if (
UNLIKELY(length == (
size_t)-1)) {
147 memory = mmap(
NULL, length, PROT_READ, MAP_PRIVATE, fd, 0);
148 if (memory == MAP_FAILED) {
153 void *file_handle = (
void *)_get_osfhandle(fd);
157 handle = CreateFileMapping(file_handle,
NULL, PAGE_READONLY, 0, 0,
NULL);
158 if (handle ==
NULL) {
161 memory = MapViewOfFile(handle, FILE_MAP_READ, 0, 0, 0);
162 if (memory ==
NULL) {
170 file->memory = memory;
171 file->handle = handle;
186 if (file->io_error || (offset + length > file->length)) {
193 memcpy(dest, file->memory + offset, length);
198 memcpy(dest, file->memory + offset, length);
200 __except (GetExceptionCode() == EXCEPTION_IN_PAGE_ERROR ? EXCEPTION_EXECUTE_HANDLER :
201 EXCEPTION_CONTINUE_SEARCH)
203 file->io_error =
true;
208 return !file->io_error;
224 munmap((
void *)file->memory, file->length);
227 UnmapViewOfFile(file->memory);
228 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)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
struct LinkData * BLI_genericNodeN(void *data)
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)
BLI_mmap_file * BLI_mmap_open(int fd)
static struct error_handler_data error_handler
size_t BLI_mmap_get_length(const BLI_mmap_file *file)
static void sigbus_handler_add(BLI_mmap_file *file)
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
Return the length of the vector.
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void(* next_handler)(int, siginfo_t *, void *)