mirror of
https://review.haiku-os.org/haiku
synced 2025-02-22 13:38:56 +01:00
Small test program that shows Haiku doesn't deal correctly with resizing
mmap()ed files. Also reproduces #5473. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36359 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
17aad616d2
commit
fba84f08b8
@ -47,6 +47,8 @@ SimpleTest port_wakeup_test_7 : port_wakeup_test_7.cpp ;
|
||||
SimpleTest port_wakeup_test_8 : port_wakeup_test_8.cpp ;
|
||||
SimpleTest port_wakeup_test_9 : port_wakeup_test_9.cpp ;
|
||||
|
||||
SimpleTest mmap_resize_test : mmap_resize_test.cpp ;
|
||||
|
||||
SimpleTest reserved_areas_test : reserved_areas_test.cpp ;
|
||||
|
||||
SimpleTest select_check : select_check.cpp ;
|
||||
|
61
src/tests/system/kernel/mmap_resize_test.cpp
Normal file
61
src/tests/system/kernel/mmap_resize_test.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
const char* fileName = "/tmp/mmap-resize-test-file";
|
||||
|
||||
// create file
|
||||
printf("creating file...\n");
|
||||
int fd = open(fileName, O_CREAT | O_RDWR | O_TRUNC, 0644);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Failed to open \"%s\": %s\n", fileName,
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// write half a page
|
||||
printf("writing data to file...\n");
|
||||
char buffer[2048];
|
||||
memset(buffer, 0xdd, sizeof(buffer));
|
||||
if (write(fd, buffer, sizeof(buffer)) != (ssize_t)sizeof(buffer)) {
|
||||
fprintf(stderr, "Failed to write to file!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// map the page
|
||||
printf("mapping file...\n");
|
||||
void* address = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (address == MAP_FAILED) {
|
||||
fprintf(stderr, "Failed to map the file: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// truncate the file
|
||||
printf("truncating file...\n");
|
||||
if (ftruncate(fd, 0) < 0) {
|
||||
fprintf(stderr, "Failed to truncate the file: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// touch data
|
||||
printf("touching no longer mapped data (should fail with SIGBUS)...\n");
|
||||
*(int*)address = 42;
|
||||
|
||||
printf("Shouldn't get here!!!\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user