apio
586ca19b62
All checks were successful
continuous-integration/drone/push Build is passing
Only supports one-page allocations and doesn't have libc wrappers, which means it has to be invoked using syscall().
41 lines
864 B
C
41 lines
864 B
C
#include <bits/mmap-flags.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/syscall.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
void bye()
|
|
{
|
|
printf("byeee!\n");
|
|
}
|
|
|
|
int main()
|
|
{
|
|
atexit(bye);
|
|
printf("Welcome to %s!\n", "Luna");
|
|
|
|
time_t now = time(NULL);
|
|
printf("Realtime clock: %ld s\n", now);
|
|
|
|
for (int i = 0; i < atoi("8"); i++) { console_write(".", 1); }
|
|
|
|
console_write("\n", 1);
|
|
|
|
long rc = syscall(SYS_allocate_memory, 4096, PROT_READ | PROT_WRITE);
|
|
if (rc < 0)
|
|
{
|
|
printf("allocate_memory: %s\n", strerror(-rc));
|
|
return 1;
|
|
}
|
|
char* address = (char*)rc;
|
|
printf("address: %p\n", address);
|
|
printf("memory at address: %c\n", *address);
|
|
*address = 'e';
|
|
printf("memory at address: %c\n", *address);
|
|
|
|
syscall(SYS_deallocate_memory, address);
|
|
}
|