Skip to content

Commit

Permalink
Use VirtualAlloc instead of mmap on Windows; #338
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 committed Oct 11, 2018
1 parent 3fab773 commit 588e719
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions dmoj/executors/BF.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,36 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#else
# include <sys/mman.h>
#endif
int main(int argc, char **argv) {
char *p;
size_t size;
errno = 0;
if (argc != 2 || (size = strtoull(argv[1], NULL, 10), errno)) {
printf("%s <bytes to allocate>\\n", argv[0]);
fprintf(stderr, "%s <bytes to allocate>\\n", argv[0]);
return 2;
}
#ifdef WIN32
p = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!p) {
fprintf(stderr, "Failed to VirtualAlloc with %u\\n", (unsigned) GetLastError());
return 2;
}
#else
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) {
perror("mmap");
return 2;
}
#endif
{code}
}
Expand Down

0 comments on commit 588e719

Please sign in to comment.