提交 003c6506 创建 作者: Austin Clements's avatar Austin Clements

map -> mmap everywhere

上级 52040c66
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
static int cpu; static int cpu;
static pthread_barrier_t bar; static pthread_barrier_t bar;
enum { ncore = 8 }; enum { ncore = 8 };
...@@ -27,8 +29,8 @@ vmsharing(void* arg) ...@@ -27,8 +29,8 @@ vmsharing(void* arg)
u64 i = (u64) arg; u64 i = (u64) arg;
volatile char *p = (char*)(0x40000UL + i * 4096); volatile char *p = (char*)(0x40000UL + i * 4096);
if (map((void *) p, 4096) < 0) if (mmap((void *) p, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) < 0)
die("map failed"); die("mmap failed");
if (unmap((void *) p, 4096) < 0) if (unmap((void *) p, 4096) < 0)
die("unmap failed"); die("unmap failed");
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
enum { readaccess = 1 }; enum { readaccess = 1 };
enum { verbose = 0 }; enum { verbose = 0 };
enum { npg = 1 }; enum { npg = 1 };
...@@ -33,7 +35,8 @@ thr(void *arg) ...@@ -33,7 +35,8 @@ thr(void *arg)
fprintf(1, "%d: %d ops\n", tid, i); fprintf(1, "%d: %d ops\n", tid, i);
volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000); volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000);
if (map((void *) p, npg * 4096) < 0) { if (mmap((void *) p, npg * 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) {
fprintf(1, "%d: map failed\n", tid); fprintf(1, "%d: map failed\n", tid);
exit(); exit();
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "uspinlock.h" #include "uspinlock.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
static volatile char *p; static volatile char *p;
static struct uspinlock l; static struct uspinlock l;
static volatile int state; static volatile int state;
...@@ -50,7 +52,8 @@ int ...@@ -50,7 +52,8 @@ int
main(void) main(void)
{ {
p = (char *) 0x80000; p = (char *) 0x80000;
if (map((void *) p, 8192) < 0) { if (mmap((void *) p, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) < 0) {
fprintf(1, "map failed\n"); fprintf(1, "map failed\n");
exit(); exit();
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "traps.h" #include "traps.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
char buf[2048]; char buf[2048];
char name[3]; char name[3];
const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 }; const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
...@@ -1712,17 +1714,19 @@ unmappedtest(void) ...@@ -1712,17 +1714,19 @@ unmappedtest(void)
printf("unmappedtest\n"); printf("unmappedtest\n");
for (int i = 1; i <= 8; i++) { for (int i = 1; i <= 8; i++) {
int r = map((void*)off, i*4096); void *p = mmap((void*)off, i*4096, PROT_READ|PROT_WRITE,
if (r < 0) MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
die("unmappedtest: map failed"); die("unmappedtest: map failed");
off += (i*2*4096); off += (i*2*4096);
} }
for (int i = 8; i >= 1; i--) { for (int i = 8; i >= 1; i--) {
long r = map(0, i*4096); void *p = mmap(0, i*4096, PROT_READ|PROT_WRITE,
if (r < 0) MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
die("unmappedtest: map failed"); die("unmappedtest: map failed");
r = unmap((void*)r, i*4096); int r = unmap(p, i*4096);
if (r < 0) if (r < 0)
die("unmappedtest: unmap failed"); die("unmappedtest: unmap failed");
} }
......
...@@ -149,14 +149,6 @@ sys_mmap(userptr<void> addr, size_t len, int prot, int flags, int fd, ...@@ -149,14 +149,6 @@ sys_mmap(userptr<void> addr, size_t len, int prot, int flags, int fd,
} }
//SYSCALL //SYSCALL
uptr
sys_map(userptr<void> addr, size_t len)
{
// XXX Compatibility
return (uptr)sys_mmap(addr, len, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
}
//SYSCALL
int int
sys_munmap(userptr<void> addr, size_t len) sys_munmap(userptr<void> addr, size_t len)
{ {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "lib.h" #include "lib.h"
#include "percpu.hh" #include "percpu.hh"
#include <sys/mman.h>
#define WQCHUNKSZ 8192 #define WQCHUNKSZ 8192
#define WQBLOCKSZ 128 #define WQBLOCKSZ 128
static_assert(WQCHUNKSZ%WQBLOCKSZ == 0, "Bad sizes"); static_assert(WQCHUNKSZ%WQBLOCKSZ == 0, "Bad sizes");
...@@ -17,11 +19,11 @@ percpu<wqblock*> block; ...@@ -17,11 +19,11 @@ percpu<wqblock*> block;
static bool static bool
refill(void) refill(void)
{ {
long r = map(0, WQCHUNKSZ); void *r = mmap(0, WQCHUNKSZ, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (r < 0) if (r == MAP_FAILED)
return false; return false;
for (uptr p = r; p < r+WQCHUNKSZ; p += WQBLOCKSZ) { for (char *p = (char*)r; p < (char*)r+WQCHUNKSZ; p += WQBLOCKSZ) {
wqblock* n = (wqblock*)p; wqblock* n = (wqblock*)p;
n->next = *block; n->next = *block;
*block = n; *block = n;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论