#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <OS.h>
static const int kAreaPagesCount = 4 * 1024;
int
main()
{
while (true) {
uint8* address;
area_id area = create_area("test area", (void**)&address, B_ANY_ADDRESS,
kAreaPagesCount * B_PAGE_SIZE, B_NO_LOCK,
B_READ_AREA | B_WRITE_AREA);
if (area < 0) {
fprintf(stderr, "Creating the area failed: %s", strerror(area));
exit(1);
}
for (int i = 0; i < kAreaPagesCount / 2; i++)
address[i * B_PAGE_SIZE] = 42;
pid_t child = fork();
if (child < 0) {
perror("fork() failed");
exit(1);
}
if (child == 0) {
delete_area(area_for(address));
exit(0);
}
for (int i = kAreaPagesCount / 2; i < kAreaPagesCount; i++)
address[i * B_PAGE_SIZE] = 42;
int status;
while (wait(&status) != child);
delete_area(area);
}
return 0;
}