Skip to content

Commit 6ffed14

Browse files
committed
Rewrite memory manager
Actually Portable Executable now supports Android. Cosmo's old mmap code required a 47 bit address space. The new implementation is very agnostic and supports both smaller address spaces (e.g. embedded) and even modern 56-bit PML5T paging for x86 which finally came true on Zen4 Threadripper Cosmopolitan no longer requires UNIX systems to observe the Windows 64kb granularity; i.e. sysconf(_SC_PAGE_SIZE) will now report the host native page size. This fixes a longstanding POSIX conformance issue, concerning file mappings that overlap the end of file. Other aspects of conformance have been improved too, such as the subtleties of address assignment and and the various subtleties surrounding MAP_FIXED and MAP_FIXED_NOREPLACE On Windows, mappings larger than 100 megabytes won't be broken down into thousands of independent 64kb mappings. Support for MAP_STACK is removed by this change; please use NewCosmoStack() instead. Stack overflow avoidance is now being implemented using the POSIX thread APIs. Please use GetStackBottom() and GetStackAddr(), instead of the old error-prone GetStackAddr() and HaveStackMemory() APIs which are removed.
1 parent 7f6d0b8 commit 6ffed14

File tree

150 files changed

+1893
-5634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1893
-5634
lines changed

ape/aarch64.lds

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*-*- mode: ld-script; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-│
22
vi: set et sts=2 sw=2 fenc=utf-8 :vi │
33
╚─────────────────────────────────────────────────────────────────────────────*/
4+
#include "libc/sysv/consts/prot.h"
45
#include "libc/thread/tls.h"
56

67
ENTRY(_start)
@@ -285,9 +286,13 @@ SECTIONS {
285286

286287
ape_stack_vaddr = DEFINED(ape_stack_vaddr) ? ape_stack_vaddr : 0x700000000000;
287288
ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : 8 * 1024 * 1024;
288-
ape_stack_align = DEFINED(ape_stack_align) ? ape_stack_align : 16;
289+
ape_stack_align = DEFINED(ape_stack_align) ? MAX(ape_stack_align, 16) : 16;
290+
ape_stack_prot = PROT_READ | PROT_WRITE;
289291
ape_stack_round = -ape_stack_align;
290292

293+
ASSERT(ape_stack_align < 1048576, "stack align too big");
294+
ASSERT(!(ape_stack_align & (ape_stack_align - 1)), "stack align must be two power");
295+
291296
_tls_size = _tbss_end - _tdata_start;
292297
_tdata_size = _tdata_end - _tdata_start;
293298
_tbss_size = _tbss_end - _tbss_start;

ape/ape.lds

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,12 @@ ape_stack_vaddr = DEFINED(ape_stack_vaddr) ? ape_stack_vaddr : 0x700000000000;
588588
ape_stack_paddr = ape_ram_paddr + ape_ram_filesz;
589589
ape_stack_filesz = 0;
590590
ape_stack_memsz = DEFINED(ape_stack_memsz) ? ape_stack_memsz : 8 * 1024 * 1024;
591-
ape_stack_align = DEFINED(ape_stack_align) ? ape_stack_align : 16;
591+
ape_stack_align = DEFINED(ape_stack_align) ? MAX(ape_stack_align, 16) : 16;
592592
ape_stack_round = -ape_stack_align;
593593

594+
ASSERT(ape_stack_align < 1048576, "stack align too big");
595+
ASSERT(!(ape_stack_align & (ape_stack_align - 1)), "stack align must be two power");
596+
594597
ape_note_offset = ape_cod_offset + (ape_note - ape_cod_vaddr);
595598
ape_note_filesz = ape_note_end - ape_note;
596599
ape_note_memsz = ape_note_filesz;

ctl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This package provides an STL alternative that's designed to:
1212

1313
This code is experimental and mostly for Justine to save herself from
1414
the STL trainwreck. That doesn't mean cosmocc users aren't welcome to
15-
use tihs too. You shouldn't expect the design to not change later on.
15+
use this too. You shouldn't expect the design to not change later on.
1616

1717
## Rationale
1818

examples/nesemu1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct Action {
137137

138138
struct Audio {
139139
size_t i;
140-
int16_t p[FRAMESIZE];
140+
int16_t p[65536];
141141
};
142142

143143
struct Status {

libc/calls/finddebugbinary.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "libc/elf/tinyelf.internal.h"
2828
#include "libc/errno.h"
2929
#include "libc/intrin/directmap.internal.h"
30-
#include "libc/intrin/kprintf.h"
3130
#include "libc/nt/memory.h"
3231
#include "libc/nt/runtime.h"
3332
#include "libc/runtime/runtime.h"

libc/calls/virtualmax.S

Lines changed: 0 additions & 37 deletions
This file was deleted.

libc/integral/normalize.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
#endif
8585

8686
#ifdef _COSMO_SOURCE
87-
#define FRAMESIZE 65536
8887
#define _PAGESIZE 4096
8988
#endif
9089

libc/intrin/BUILD.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ o/$(MODE)/libc/intrin/asan.o: private \
6666
CFLAGS += \
6767
-O2 \
6868
-finline \
69-
-finline-functions \
70-
-fpatchable-function-entry=0,0
69+
-finline-functions
7170

7271
o//libc/intrin/memmove.o: private \
7372
CFLAGS += \

0 commit comments

Comments
 (0)