TestSharedInodeVMObject.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <sys/mman.h>
  14. #include <unistd.h>
  15. static u8* shared_ptr = nullptr;
  16. static void shared_non_empty_inode_vmobject_sync_signal_handler(int)
  17. {
  18. auto rc = msync(shared_ptr, 0x1000, MS_ASYNC);
  19. EXPECT(rc == 0);
  20. rc = munmap(shared_ptr, 0x1000);
  21. EXPECT(rc == 0);
  22. exit(0);
  23. }
  24. TEST_CASE(shared_non_empty_inode_vmobject_sync)
  25. {
  26. {
  27. struct sigaction new_action {
  28. { shared_non_empty_inode_vmobject_sync_signal_handler }, 0, 0
  29. };
  30. int rc = sigaction(SIGBUS, &new_action, nullptr);
  31. VERIFY(rc == 0);
  32. }
  33. u8 buf[0x1000];
  34. memset(buf, 0, sizeof(buf));
  35. int fd = open("/tmp/shared_non_empty_msync_test", O_RDWR | O_CREAT, 0644);
  36. VERIFY(fd >= 0);
  37. auto rc = write(fd, buf, sizeof(buf));
  38. VERIFY(rc == sizeof(buf));
  39. shared_ptr = (u8*)mmap(nullptr, 0x2000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
  40. EXPECT(shared_ptr != MAP_FAILED);
  41. rc = msync(shared_ptr, 0x2000, MS_ASYNC);
  42. EXPECT(rc == 0);
  43. shared_ptr[0x1001] = 0x1;
  44. VERIFY_NOT_REACHED();
  45. }