From: Jeffrey Walton <noloader@gmail.com>
To: 47429@debbugs.gnu.org
Subject: bug#47429: Re 47429:allocating JIT code buffer failed: Permission denied
Date: Fri, 26 Mar 2021 19:27:18 -0400 [thread overview]
Message-ID: <CAH8yC8maA0wHnchfMnmX4uGhevMXrbu3sRenYPjg9aA7to60pg@mail.gmail.com> (raw)
In-Reply-To: <CAH8yC8m8d5uVWOAFAPdr_v5KCg_o6xAhiU+T17Way3ZaDuetDw@mail.gmail.com>
I'm looking at OS X's man page on mmap. The EACCES does not seem to
fit one of the stated reasons in the man page. Also see
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mmap.2.html.
I have two theories, both of which are guesses. Neither seems to be
very good. First, this may be related to W^X pages on OS X.
Second, the size is 0 but the wrong error code is returned. For the
second case, size=0 should result in EINVAL. I don't know what size is
so this is probably a bad guess.
I'm not sure how to get this under a debugger.
Here's a test of the first theory:
% cat mmap-test.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
int main(int argc, char* argv[])
{
size_t len = 10;
int prot = PROT_EXEC | PROT_READ | PROT_WRITE;
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
void *p = mmap (NULL, len, prot, flags, -1, 0);
int err = errno;
if (p) {
printf("p is good\n");
munmap(p, len);
}
else {
printf("p is bad (%d)\n", err);
}
return 0;
}
% clang -Wall mmap-test.c -o mmap-test.exe
% ./mmap-test.exe
p is good
Here's a test of the second theory with len = 0:
% ./mmap-test.exe
p is good
I'm out of ideas...
=========================
This is the relevant part of libguile/jit.c:
1330 static struct code_arena *
1331 allocate_code_arena (size_t size, struct code_arena *prev)
1332 {
1333 struct code_arena *ret = malloc (sizeof (struct code_arena));
1334
1335 if (!ret) return NULL;
1336
1337 memset (ret, 0, sizeof (*ret));
1338 ret->used = 0;
1339 ret->size = size;
1340 ret->prev = prev;
1341 ret->base = mmap (NULL, ret->size,
1342 PROT_EXEC | PROT_READ | PROT_WRITE,
1343 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1344
1345 if (ret->base == MAP_FAILED)
1346 {
1347 perror ("allocating JIT code buffer failed");
1348 free (ret);
1349 return NULL;
1350 }
1351
1352 INFO ("allocated code arena, %p-%p\n", ret->base, ret->base
+ ret->size);
1353
1354 return ret;
1355 }
next prev parent reply other threads:[~2021-03-26 23:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-26 22:48 bug#47429: allocating JIT code buffer failed: Permission denied Jeffrey Walton
2021-03-26 23:27 ` Jeffrey Walton [this message]
2021-03-26 23:34 ` bug#47429: Re 47429:allocating " Jeffrey Walton
2021-03-27 1:29 ` Jeffrey Walton
2021-03-27 2:39 ` Jeffrey Walton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH8yC8maA0wHnchfMnmX4uGhevMXrbu3sRenYPjg9aA7to60pg@mail.gmail.com \
--to=noloader@gmail.com \
--cc=47429@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).