TestEmptySharedInodeVMObject.cpp 1023 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9. #include <signal.h>
  10. #include <sys/mman.h>
  11. static u8* shared_ptr = nullptr;
  12. static void shared_zero_length_inode_vmobject_sync_signal_handler(int)
  13. {
  14. auto rc = msync(shared_ptr, 0x1000, MS_ASYNC);
  15. EXPECT(rc == 0);
  16. rc = munmap(shared_ptr, 0x1000);
  17. EXPECT(rc == 0);
  18. exit(0);
  19. }
  20. TEST_CASE(shared_zero_length_inode_vmobject_sync)
  21. {
  22. {
  23. struct sigaction new_action {
  24. { shared_zero_length_inode_vmobject_sync_signal_handler }, 0, 0
  25. };
  26. int rc = sigaction(SIGBUS, &new_action, nullptr);
  27. VERIFY(rc == 0);
  28. }
  29. int fd = open("/tmp/shared_msync_test", O_RDWR | O_CREAT, 0644);
  30. VERIFY(fd >= 0);
  31. shared_ptr = (u8*)mmap(nullptr, 0x1000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
  32. EXPECT(shared_ptr != MAP_FAILED);
  33. shared_ptr[0] = 0x1;
  34. VERIFY_NOT_REACHED();
  35. }