-
Notifications
You must be signed in to change notification settings - Fork 220
Fix unavailable MAP_ANONYMOUS #2470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cc @tekknolagi |
Nice catch. Some duplicated code - I'll check on Monday |
Might be able to define _GNU_SOURCE to fix instead |
Thanks. I'm waiting for the fix by @tekknolagi, and will release a new |
@Morriar I recommend looking into a fix with _GNU_SOURCE--it's likely the platform has MAP_ANONYMOUS but is pretending not to If not, then we should at least drop the _WIN32 branch of the ifdef (it's otherwise handled by map_memory) and inline this whole thing into map_memory |
src/util/rbs_allocator.c
Outdated
#ifdef _WIN32 | ||
ptr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | ||
if (ptr == NULL) return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef _WIN32 | |
ptr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | |
if (ptr == NULL) return NULL; |
src/util/rbs_allocator.c
Outdated
ptr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | ||
if (ptr == NULL) return NULL; | ||
#elif defined(MAP_ANONYMOUS) | ||
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | |
return mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
src/util/rbs_allocator.c
Outdated
#elif defined(MAP_ANONYMOUS) | ||
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | ||
#elif defined(MAP_ANON) | ||
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); | |
return mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); |
src/util/rbs_allocator.c
Outdated
#else | ||
/* Fallback to /dev/zero for systems without anonymous mapping */ | ||
int fd = open("/dev/zero", O_RDWR); | ||
if (fd == -1) return MAP_FAILED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Masking as MAP_FAILED is a little gross imo; have it have its own assert
a23c761
to
aa34584
Compare
Nice! |
@soutaro This PR should pass all compilation builds now 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@soutaro I've rebased this branch. It should be good to go now |
Trying fix for ruby/ruby#13237 (comment)