Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3534,23 +3534,37 @@ JL_DLLEXPORT void jl_image_unpack_zstd(void *handle, jl_image_buf_t *image)
image->size = ZSTD_getFrameContentSize(data, *plen);
size_t page_size = jl_getpagesize(); /* jl_page_size is not set yet when loading sysimg */
size_t aligned_size = LLT_ALIGN(image->size, page_size);
int fail = 0;
#if defined(_OS_WINDOWS_)
size_t large_page_size = GetLargePageMinimum();
if (image->size > 4 * large_page_size) {
image->data = NULL;
if (large_page_size > 0 && image->size > 4 * large_page_size) {
size_t aligned_size = LLT_ALIGN(image->size, large_page_size);
image->data = (char *)VirtualAlloc(
NULL, aligned_size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
}
else {
if (!image->data) {
/* Try small pages if large pages failed. */
image->data = (char *)VirtualAlloc(NULL, aligned_size, MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
}
fail = !image->data;
#else
image->data = (char *)mmap(NULL, aligned_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
fail = image->data == (void *)-1;
#endif
if (fail) {
const char *err;
#if defined(_OS_WINDOWS_)
char err_buf[256];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

256 bytes seems a bit conservative - maybe double it?

Also looking at the implementation of win32_formatmessage, it looks like it leaves err_buf mostly uninitialized if the buffer is too small. That could probably do with a quick fix-up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub just showed me the approval but not any of the review comments. Woops. I'll have to do this in another PR but I expect to have to touch this code soon anyway.

win32_formatmessage(GetLastError(), err_buf, sizeof(err_buf));
err = err_buf;
#else
image->data =
(char *)mmap(NULL, aligned_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
err = strerror(errno);
#endif
if (!image->data || image->data == (void *)-1) {
jl_printf(JL_STDERR, "ERROR: failed to allocate space for system image\n");
jl_printf(JL_STDERR, "ERROR: failed to allocate memory for system image: %s\n",
err);
jl_exit(1);
}

Expand Down