test map/unmap
This commit is contained in:
@@ -1,6 +1,44 @@
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
||||
#include "../libsys/stub.h"
|
||||
#include "../libsys/string.h"
|
||||
|
||||
char* itoh(unsigned int value, char* buffer) {
|
||||
char* ptr = &buffer[11];
|
||||
*ptr = '\0'; // Nullterminator am Ende setzen
|
||||
|
||||
if (value == 0) {
|
||||
*--ptr = '0';
|
||||
return ptr;
|
||||
}
|
||||
|
||||
do {
|
||||
ptr--;
|
||||
*ptr = '0' + (value % 16);
|
||||
if(*ptr >= 0x3A)
|
||||
*ptr+=7;
|
||||
value /= 16;
|
||||
} while (value != 0);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
char* itoa(unsigned int value, char* buffer) {
|
||||
char* ptr = &buffer[11];
|
||||
*ptr = '\0'; // Nullterminator am Ende setzen
|
||||
|
||||
if (value == 0) {
|
||||
*--ptr = '0';
|
||||
return ptr;
|
||||
}
|
||||
|
||||
do {
|
||||
ptr--;
|
||||
*ptr = '0' + (value % 10);
|
||||
value /= 10;
|
||||
} while (value != 0);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
extern "C" void main() {
|
||||
// Thread 1 may be an auxiliary thread
|
||||
@@ -10,31 +48,29 @@ extern "C" void main() {
|
||||
unsigned id = sys_getpid();
|
||||
char text[] = "appX";
|
||||
text[3] = 0x30+id;
|
||||
char buf = 32;
|
||||
|
||||
write(1, text, sizeof(text), 0, (int)id);
|
||||
|
||||
uint8_t cnt = 0;
|
||||
for (unsigned i = 1;; ++i) {
|
||||
char msg[5];
|
||||
msg[0] = 0x30+cnt;
|
||||
msg[1] = 0;
|
||||
cnt=(cnt+1)%10;
|
||||
write(1, msg, 1, 6, (int)id);
|
||||
void* ptr= map(512);
|
||||
|
||||
//sprintf(&buf, "ptr address: %x \n" , ptr);
|
||||
//unmap(ptr, 512);
|
||||
//counter to see app running
|
||||
cnt=(cnt+1)%100;
|
||||
char buf[12];
|
||||
char* msg = itoa(cnt,buf);
|
||||
write(1, msg, strlen(msg), 6, (int)id);
|
||||
|
||||
// test map/unmap and print ptr
|
||||
void* ptr= map(4096);
|
||||
uint16_t* val = ((uint16_t*)ptr);
|
||||
*val = 0x1337;
|
||||
|
||||
//if(i==id){
|
||||
// //write(2, "kill", 4);
|
||||
// //write(2, &text[4], 1);
|
||||
// //write(2, " ", 1);
|
||||
// sys_exit();
|
||||
//}
|
||||
sleep(1000);
|
||||
if(id == 2)
|
||||
msg = itoh((uintptr_t)ptr,buf);
|
||||
write(1, msg, strlen(msg), 12, (int)id);
|
||||
unmap(ptr, 4096);
|
||||
|
||||
sleep(100);
|
||||
if(id == 4)
|
||||
*reinterpret_cast<uint8_t*>(0xdeadbeaf) = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user