Serenity Operating System
at master 49 lines 1.3 kB view raw
1/* 2 * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibTest/TestCase.h> 8#include <errno.h> 9#include <fcntl.h> 10#include <signal.h> 11#include <stdio.h> 12#include <stdlib.h> 13#include <string.h> 14#include <sys/mman.h> 15#include <unistd.h> 16 17static u8* private_ptr = nullptr; 18 19static void private_non_empty_inode_vmobject_sync_signal_handler(int) 20{ 21 auto rc = msync(private_ptr, 0x1000, MS_ASYNC); 22 EXPECT(rc == 0); 23 rc = munmap(private_ptr, 0x1000); 24 EXPECT(rc == 0); 25 exit(0); 26} 27 28TEST_CASE(private_non_empty_inode_vmobject_sync) 29{ 30 { 31 struct sigaction new_action { 32 { private_non_empty_inode_vmobject_sync_signal_handler }, 0, 0 33 }; 34 int rc = sigaction(SIGBUS, &new_action, nullptr); 35 VERIFY(rc == 0); 36 } 37 u8 buf[0x1000]; 38 memset(buf, 0, sizeof(buf)); 39 int fd = open("/tmp/private_non_empty_msync_test", O_RDWR | O_CREAT, 0644); 40 VERIFY(fd >= 0); 41 auto rc = write(fd, buf, sizeof(buf)); 42 VERIFY(rc == sizeof(buf)); 43 private_ptr = (u8*)mmap(nullptr, 0x2000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0); 44 EXPECT(private_ptr != MAP_FAILED); 45 rc = msync(private_ptr, 0x2000, MS_ASYNC); 46 EXPECT(rc == 0); 47 private_ptr[0x1001] = 0x1; 48 VERIFY_NOT_REACHED(); 49}