ld: anonymous and file-backed mmap tests
This commit is contained in:
@@ -13,11 +13,14 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/remote.h>
|
#include <sys/remote.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(const struct rosetta_bootstrap *bs)
|
int main(const struct rosetta_bootstrap *bs)
|
||||||
{
|
{
|
||||||
|
kern_logf("ld");
|
||||||
|
|
||||||
kern_handle_t task, address_space;
|
kern_handle_t task, address_space;
|
||||||
task_self(&task);
|
task_self(&task);
|
||||||
task_get_address_space(task, &address_space);
|
task_get_address_space(task, &address_space);
|
||||||
@@ -29,9 +32,9 @@ int main(const struct rosetta_bootstrap *bs)
|
|||||||
sys_remote_set(SYS_REMOTE_NSD, 0, 0);
|
sys_remote_set(SYS_REMOTE_NSD, 0, 0);
|
||||||
const char *path = "/usr/lib/libc.so";
|
const char *path = "/usr/lib/libc.so";
|
||||||
int flags = 4;
|
int flags = 4;
|
||||||
int fd = open(path, flags);
|
|
||||||
|
|
||||||
kern_logf("sending msg: open(%s, %d)", path, flags);
|
kern_logf("sending msg: open(%s, %d)", path, flags);
|
||||||
|
int fd = open(path, flags);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
kern_logf(
|
kern_logf(
|
||||||
@@ -60,5 +63,30 @@ int main(const struct rosetta_bootstrap *bs)
|
|||||||
|
|
||||||
kern_logf("data: %x %c %c %c", buf[0], buf[1], buf[2], buf[3]);
|
kern_logf("data: %x %c %c %c", buf[0], buf[1], buf[2], buf[3]);
|
||||||
|
|
||||||
|
void *p
|
||||||
|
= mmap(NULL,
|
||||||
|
0x1000,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_ANONYMOUS | MAP_PRIVATE,
|
||||||
|
-1,
|
||||||
|
0);
|
||||||
|
if (p != MAP_FAILED) {
|
||||||
|
memset(p, 0x0, 0x1000);
|
||||||
|
kern_logf("mmap'd buffer at %p", p);
|
||||||
|
} else {
|
||||||
|
kern_logf("mmap buffer failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *lib
|
||||||
|
= mmap(NULL, 0x1000, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0);
|
||||||
|
if (lib != MAP_FAILED) {
|
||||||
|
kern_logf("mmap'd %s at %p", path, lib);
|
||||||
|
unsigned char *tmp = lib;
|
||||||
|
kern_logf("data: %x %c %c %c", tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||||
|
} else {
|
||||||
|
kern_logf("mmap lib failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
kern_logf("ld finished");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user