mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Remove __mmap() and __munmap()
This commit is contained in:
parent
01587de761
commit
fc65422660
5 changed files with 11 additions and 16 deletions
|
@ -47,8 +47,6 @@ void __maps_unlock(void);
|
||||||
void __maps_add(struct Map *);
|
void __maps_add(struct Map *);
|
||||||
struct Map *__maps_alloc(void);
|
struct Map *__maps_alloc(void);
|
||||||
void __maps_free(struct Map *);
|
void __maps_free(struct Map *);
|
||||||
int __munmap(char *, size_t, bool);
|
|
||||||
void *__mmap(char *, size_t, int, int, int, int64_t);
|
|
||||||
void __maps_stack(char *, int, int, size_t, int, intptr_t);
|
void __maps_stack(char *, int, int, size_t, int, intptr_t);
|
||||||
struct AddrSize __get_main_stack(void);
|
struct AddrSize __get_main_stack(void);
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ struct Map *__maps_alloc(void) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __munmap(char *addr, size_t size, bool untrack_only) {
|
static int __munmap(char *addr, size_t size, bool untrack_only) {
|
||||||
|
|
||||||
// validate arguments
|
// validate arguments
|
||||||
int pagesz = getpagesize();
|
int pagesz = getpagesize();
|
||||||
|
@ -479,8 +479,8 @@ static void *__mmap_impl(char *addr, size_t size, int prot, int flags, int fd,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *__mmap(char *addr, size_t size, int prot, int flags, int fd,
|
static void *__mmap(char *addr, size_t size, int prot, int flags, int fd,
|
||||||
int64_t off) {
|
int64_t off) {
|
||||||
char *res;
|
char *res;
|
||||||
int pagesz = getpagesize();
|
int pagesz = getpagesize();
|
||||||
int granularity = __granularity();
|
int granularity = __granularity();
|
||||||
|
|
|
@ -148,8 +148,8 @@ textstartup void __enable_tls(void) {
|
||||||
// if a binary needs this much thread_local storage, then it
|
// if a binary needs this much thread_local storage, then it
|
||||||
// surely must have linked the mmap() function at some point
|
// surely must have linked the mmap() function at some point
|
||||||
// we can't call mmap() because it's too early for sig block
|
// we can't call mmap() because it's too early for sig block
|
||||||
mem = _weaken(__mmap)(0, siz, PROT_READ | PROT_WRITE,
|
mem = _weaken(mmap)(0, siz, PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CosmoTib *tib = (struct CosmoTib *)(mem + siz - sizeof(*tib));
|
struct CosmoTib *tib = (struct CosmoTib *)(mem + siz - sizeof(*tib));
|
||||||
|
@ -176,8 +176,8 @@ textstartup void __enable_tls(void) {
|
||||||
// if a binary needs this much thread_local storage, then it
|
// if a binary needs this much thread_local storage, then it
|
||||||
// surely must have linked the mmap() function at some point
|
// surely must have linked the mmap() function at some point
|
||||||
// we can't call mmap() because it's too early for sig block
|
// we can't call mmap() because it's too early for sig block
|
||||||
mem = _weaken(__mmap)(0, size, PROT_READ | PROT_WRITE,
|
mem = _weaken(mmap)(0, size, PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CosmoTib *tib =
|
struct CosmoTib *tib =
|
||||||
|
|
|
@ -77,7 +77,7 @@ void *__zipos_mmap(void *addr, size_t size, int prot, int flags,
|
||||||
flags |= MAP_PRIVATE | MAP_ANONYMOUS;
|
flags |= MAP_PRIVATE | MAP_ANONYMOUS;
|
||||||
|
|
||||||
const int tempProt = !IsXnu() ? prot | PROT_WRITE : PROT_WRITE;
|
const int tempProt = !IsXnu() ? prot | PROT_WRITE : PROT_WRITE;
|
||||||
void *outAddr = __mmap(addr, size, tempProt, flags, -1, 0);
|
void *outAddr = mmap(addr, size, tempProt, flags, -1, 0);
|
||||||
if (outAddr == MAP_FAILED) {
|
if (outAddr == MAP_FAILED) {
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,18 +48,15 @@ void __zipos_drop(struct ZiposHandle *h) {
|
||||||
if (atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release))
|
if (atomic_fetch_sub_explicit(&h->refs, 1, memory_order_release))
|
||||||
return;
|
return;
|
||||||
atomic_thread_fence(memory_order_acquire);
|
atomic_thread_fence(memory_order_acquire);
|
||||||
__munmap((char *)h, h->mapsize, false);
|
munmap((char *)h, h->mapsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ZiposHandle *__zipos_alloc(struct Zipos *zipos, size_t size) {
|
static struct ZiposHandle *__zipos_alloc(struct Zipos *zipos, size_t size) {
|
||||||
size_t mapsize;
|
size_t mapsize;
|
||||||
int granularity;
|
|
||||||
struct ZiposHandle *h;
|
struct ZiposHandle *h;
|
||||||
granularity = __granularity();
|
|
||||||
mapsize = sizeof(struct ZiposHandle) + size;
|
mapsize = sizeof(struct ZiposHandle) + size;
|
||||||
mapsize = (mapsize + granularity - 1) & -granularity;
|
if ((h = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
|
||||||
if ((h = __mmap(0, mapsize, PROT_READ | PROT_WRITE,
|
-1, 0)) != MAP_FAILED) {
|
||||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) != MAP_FAILED) {
|
|
||||||
h->size = size;
|
h->size = size;
|
||||||
h->zipos = zipos;
|
h->zipos = zipos;
|
||||||
h->mapsize = mapsize;
|
h->mapsize = mapsize;
|
||||||
|
|
Loading…
Reference in a new issue