prot_sao.c 803 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright 2016, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <sys/mman.h>
  9. #include <asm/cputable.h>
  10. #include "utils.h"
  11. #define SIZE (64 * 1024)
  12. int test_prot_sao(void)
  13. {
  14. char *p;
  15. /* 2.06 or later should support SAO */
  16. SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06));
  17. /*
  18. * Ensure we can ask for PROT_SAO.
  19. * We can't really verify that it does the right thing, but at least we
  20. * confirm the kernel will accept it.
  21. */
  22. p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE | PROT_SAO,
  23. MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  24. FAIL_IF(p == MAP_FAILED);
  25. /* Write to the mapping, to at least cause a fault */
  26. memset(p, 0xaa, SIZE);
  27. return 0;
  28. }
  29. int main(void)
  30. {
  31. return test_harness(test_prot_sao, "prot-sao");
  32. }