Make mmap() work better

- Mapping file offsets now works on Windows
- Mapping stack memory now works on OpenBSD
This commit is contained in:
Justine Tunney 2021-02-03 00:10:12 -08:00
parent 23a14b537c
commit 27c899af56
10 changed files with 71 additions and 56 deletions

View file

@ -21,13 +21,8 @@ THIRD_PARTY_CHIBICC_TEST_HDRS = $(filter %.h,$(THIRD_PARTY_CHIBICC_TEST_FILES))
THIRD_PARTY_CHIBICC_TEST_TESTS = $(THIRD_PARTY_CHIBICC_TEST_COMS:%=%.ok)
THIRD_PARTY_CHIBICC_TEST_COMS = \
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%.c=o/$(MODE)/%.com)
# TODO(jart): make chibicc compiled chibicc work with asan runtime
ifneq ($(MODE),dbg)
THIRD_PARTY_CHIBICC_TEST_COMS += \
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%.c=o/$(MODE)/%2.com)
endif
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%_test.c=o/$(MODE)/%_test.com) \
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%_test.c=o/$(MODE)/%_test2.com)
THIRD_PARTY_CHIBICC_TEST_OBJS = \
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%.c=o/$(MODE)/%.chibicc.o)
@ -62,21 +57,19 @@ THIRD_PARTY_CHIBICC_TEST_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x))))
$(THIRD_PARTY_CHIBICC_TEST_A): \
third_party/chibicc/test/ \
$(THIRD_PARTY_CHIBICC_TEST_A).pkg \
$(THIRD_PARTY_CHIBICC_TEST_OBJS)
o/$(MODE)/third_party/chibicc/test/common.chibicc.o
$(THIRD_PARTY_CHIBICC_TEST2_A): \
third_party/chibicc/test/ \
$(THIRD_PARTY_CHIBICC_TEST2_A).pkg \
$(THIRD_PARTY_CHIBICC_TEST2_OBJS)
o/$(MODE)/third_party/chibicc/test/common.chibicc2.o
$(THIRD_PARTY_CHIBICC_TEST_A).pkg: \
$(THIRD_PARTY_CHIBICC_TEST_OBJS) \
o/$(MODE)/third_party/chibicc/test/common.chibicc.o \
$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x)_A).pkg)
$(THIRD_PARTY_CHIBICC_TEST2_A).pkg: \
$(THIRD_PARTY_CHIBICC_TEST2_OBJS) \
o/$(MODE)/third_party/chibicc/test/common.chibicc2.o \
$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/third_party/chibicc/test/%.com.dbg: \

View file

@ -136,21 +136,16 @@ static int read_ident(char *start) {
}
}
static int from_hex(char c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
return c - 'A' + 10;
}
// Read a punctuator token from p and returns its length.
int read_punct(char *p) {
static char kw[][4] = {"<<=", ">>=", "...", "==", "!=", "<=", ">=", "->",
"+=", "-=", "*=", "/=", "++", "--", "%=", "&=",
"|=", "^=", "&&", "||", "<<", ">>", "##"};
for (int i = 0; i < sizeof(kw) / sizeof(*kw); i++) {
static const char kPunct[][4] = {
"<<=", ">>=", "...", "==", "!=", "<=", ">=", "->", "+=", "-=", "*=", "/=",
"++", "--", "%=", "&=", "|=", "^=", "&&", "||", "<<", ">>", "##",
};
for (int i = 0; i < sizeof(kPunct) / sizeof(*kPunct); i++) {
for (int j = 0;;) {
if (p[j] != kw[i][j]) break;
if (!kw[i][++j]) return j;
if (p[j] != kPunct[i][j]) break;
if (!kPunct[i][++j]) return j;
}
}
return ispunct(*p) ? 1 : 0;
@ -200,7 +195,7 @@ int read_escaped_char(char **new_pos, char *p) {
if (!isxdigit(*p)) error_at(p, "invalid hex escape sequence");
unsigned c = 0;
for (; isxdigit(*p); p++) {
c = (c << 4) + from_hex(*p); /* TODO(jart): overflow here unicode_test */
c = (c << 4) + hextoint(*p); /* TODO(jart): overflow here unicode_test */
}
*new_pos = p;
return c;
@ -628,7 +623,7 @@ static uint32_t read_universal_char(char *p, int len) {
uint32_t c = 0;
for (int i = 0; i < len; i++) {
if (!isxdigit(p[i])) return 0;
c = (c << 4) | from_hex(p[i]);
c = (c << 4) | hextoint(p[i]);
}
return c;
}