diff --git a/src/asm/lexer.c b/src/asm/lexer.c index aacdb938..89c52880 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -257,6 +257,7 @@ struct LexerState { char *ptr; /* Technically `const` during the lexer's execution */ off_t size; off_t offset; + bool isReferenced; /* If a macro in this file requires not unmapping it*/ }; struct { /* Otherwise */ int fd; @@ -415,7 +416,7 @@ void lexer_DeleteState(struct LexerState *state) { if (!state->isMmapped) close(state->fd); - else if (state->isFile) + else if (state->isFile && !state->isReferenced) munmap(state->ptr, state->size); free(state); } @@ -1944,6 +1945,11 @@ void lexer_CaptureMacroBody(char **capture, size_t *size) unsigned int level = 0; int c = peek(0); + /* If the file is `mmap`ed, we need not to unmap it to keep access to the macro */ + if (lexerState->isMmapped) + /* FIXME: this is godawful, but RGBASM doesn't even clean up anything anyways. */ + lexerState->isReferenced = true; + /* * Due to parser internals, it does not read the EOL after the T_POP_MACRO before calling * this. Thus, we need to keep one in the buffer afterwards.