mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Fix msync() flags on FreeBSD
This commit is contained in:
parent
ebf784d4f5
commit
fffcd98b0e
7 changed files with 95 additions and 15 deletions
|
@ -16,13 +16,17 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/msync.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/msync.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
// msync() is a difficult function to test because it doesn't do much
|
||||
|
||||
TEST(msync, changeFileMappingAndExit) {
|
||||
int ws;
|
||||
char byte;
|
||||
|
@ -33,6 +37,7 @@ TEST(msync, changeFileMappingAndExit) {
|
|||
(map = mmap(0, 4, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0)));
|
||||
if (!fork()) {
|
||||
map[0] = 1;
|
||||
// commenting this out will fail on openbsd
|
||||
ASSERT_SYS(0, 0, msync(map, 4, MS_SYNC));
|
||||
_Exit(123);
|
||||
}
|
||||
|
@ -45,3 +50,37 @@ TEST(msync, changeFileMappingAndExit) {
|
|||
ASSERT_SYS(0, 0, munmap(map, 4));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(msync, changeFileMappingAndWakeSpinLockWaiter) {
|
||||
int ws;
|
||||
char byte;
|
||||
char *map;
|
||||
atomic_char *sem = _mapshared(1);
|
||||
ASSERT_SYS(0, 3, tmpfd());
|
||||
ASSERT_SYS(0, 0, ftruncate(3, 1));
|
||||
ASSERT_NE(MAP_FAILED,
|
||||
(map = mmap(0, 1, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0)));
|
||||
if (!fork()) {
|
||||
// wait for other process to enter spin sem
|
||||
while (*sem == 0) donothing;
|
||||
// change the file mapping
|
||||
map[0] = 1;
|
||||
// openbsd fails with this line commented out
|
||||
ASSERT_SYS(0, 0, msync(map, 1, MS_ASYNC));
|
||||
// immediately wake other process
|
||||
*sem = 2;
|
||||
_Exit(123);
|
||||
}
|
||||
*sem = 1;
|
||||
while (*sem == 1) donothing;
|
||||
ASSERT_EQ(1, map[0]);
|
||||
ASSERT_SYS(0, 1, pread(3, &byte, 1, 0));
|
||||
ASSERT_EQ(1, byte);
|
||||
ASSERT_EQ(1, map[0]);
|
||||
ASSERT_NE(-1, wait(&ws));
|
||||
ASSERT_TRUE(WIFEXITED(ws));
|
||||
ASSERT_EQ(123, WEXITSTATUS(ws));
|
||||
ASSERT_SYS(0, 0, munmap(map, 1));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, munmap(sem, 1));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue