-
-
Save Madsy/c5233202965839584dc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SCM_PAGE_SIZE 4096 | |
static char* | |
map_file_contents (int fd, size_t len, int *is_read_only) | |
#define FUNC_NAME "load-thunk-from-file" | |
{ | |
char *data; | |
#ifdef HAVE_SYS_MMAN_H | |
data = mmap (NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); | |
if (data == MAP_FAILED) | |
SCM_SYSERROR; | |
*is_read_only = 1; | |
#else | |
if (lseek (fd, 0, SEEK_START) < 0) | |
{ | |
int errno_save = errno; | |
(void) close (fd); | |
errno = errno_save; | |
SCM_SYSERROR; | |
} | |
/* Given that we are using the read fallback, optimistically assume | |
that the .go files were made with 8-byte alignment. | |
alignment. */ | |
data = malloc (end); | |
if (!data) | |
{ | |
(void) close (fd); | |
scm_misc_error (FUNC_NAME, "failed to allocate ~A bytes", | |
scm_list_1 (scm_from_size_t (end))); | |
} | |
if (full_read (fd, data, end) != end) | |
{ | |
int errno_save = errno; | |
(void) close (fd); | |
errno = errno_save; | |
if (errno) | |
SCM_SYSERROR; | |
scm_misc_error (FUNC_NAME, "short read while loading objcode", | |
SCM_EOL); | |
} | |
/* If our optimism failed, fall back. */ | |
{ | |
unsigned alignment = sniff_elf_alignment (data, end); | |
if (alignment != 8) | |
{ | |
char *copy = copy_and_align_elf_data (data, end, alignment); | |
free (data); | |
data = copy; | |
} | |
} | |
*is_read_only = 0; | |
#endif | |
return data; | |
} | |
#undef FUNC_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment