Lines Matching refs:ptr

57 noinline int read_ptr(int *ptr)  in read_ptr()  argument
61 return *ptr; in read_ptr()
179 u64 *ptr = (u64 *)(c + i); in dump_mem() local
180 dprintf1("dump[%03d][@%p]: %016llx\n", i, ptr, *ptr); in dump_mem()
554 int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot, in mprotect_pkey() argument
562 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
564 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
580 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
582 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
591 void *ptr; member
598 void record_pkey_malloc(void *ptr, long size, int prot) in record_pkey_malloc() argument
627 (int)(rec - pkey_malloc_records), rec, ptr, size); in record_pkey_malloc()
628 rec->ptr = ptr; in record_pkey_malloc()
635 static void free_pkey_malloc(void *ptr) in free_pkey_malloc() argument
639 dprintf3("%s(%p)\n", __func__, ptr); in free_pkey_malloc()
643 ptr, i, rec, rec->ptr, rec->size); in free_pkey_malloc()
644 if ((ptr < rec->ptr) || in free_pkey_malloc()
645 (ptr >= rec->ptr + rec->size)) in free_pkey_malloc()
649 ptr, i, rec, rec->ptr, rec->size); in free_pkey_malloc()
651 ret = munmap(rec->ptr, rec->size); in free_pkey_malloc()
655 rec->ptr = NULL; in free_pkey_malloc()
664 void *ptr; in malloc_pkey_with_mprotect() local
671 ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); in malloc_pkey_with_mprotect()
672 pkey_assert(ptr != (void *)-1); in malloc_pkey_with_mprotect()
673 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); in malloc_pkey_with_mprotect()
675 record_pkey_malloc(ptr, size, prot); in malloc_pkey_with_mprotect()
678 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); in malloc_pkey_with_mprotect()
679 return ptr; in malloc_pkey_with_mprotect()
685 void *ptr; in malloc_pkey_anon_huge() local
694 ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); in malloc_pkey_anon_huge()
695 pkey_assert(ptr != (void *)-1); in malloc_pkey_anon_huge()
696 record_pkey_malloc(ptr, size, prot); in malloc_pkey_anon_huge()
697 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_anon_huge()
699 dprintf1("unaligned ptr: %p\n", ptr); in malloc_pkey_anon_huge()
700 ptr = ALIGN_PTR_UP(ptr, HPAGE_SIZE); in malloc_pkey_anon_huge()
701 dprintf1(" aligned ptr: %p\n", ptr); in malloc_pkey_anon_huge()
702 ret = madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE); in malloc_pkey_anon_huge()
704 ret = madvise(ptr, HPAGE_SIZE, MADV_WILLNEED); in malloc_pkey_anon_huge()
706 memset(ptr, 0, HPAGE_SIZE); in malloc_pkey_anon_huge()
708 dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_anon_huge()
709 return ptr; in malloc_pkey_anon_huge()
765 void *ptr; in malloc_pkey_hugetlb() local
774 ptr = mmap(NULL, size, PROT_NONE, flags, -1, 0); in malloc_pkey_hugetlb()
775 pkey_assert(ptr != (void *)-1); in malloc_pkey_hugetlb()
776 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_hugetlb()
778 record_pkey_malloc(ptr, size, prot); in malloc_pkey_hugetlb()
780 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_hugetlb()
781 return ptr; in malloc_pkey_hugetlb()
894 static void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey) in test_pkey_alloc_free_attach_pkey0() argument
934 err = sys_mprotect_pkey(ptr, size, PROT_READ, 0); in test_pkey_alloc_free_attach_pkey0()
936 err = sys_mprotect_pkey(ptr, size, PROT_WRITE, 0); in test_pkey_alloc_free_attach_pkey0()
938 err = sys_mprotect_pkey(ptr, size, PROT_EXEC, 0); in test_pkey_alloc_free_attach_pkey0()
940 err = sys_mprotect_pkey(ptr, size, PROT_READ|PROT_WRITE, 0); in test_pkey_alloc_free_attach_pkey0()
942 err = sys_mprotect_pkey(ptr, size, PROT_READ|PROT_WRITE|PROT_EXEC, 0); in test_pkey_alloc_free_attach_pkey0()
946 static void test_read_of_write_disabled_region(int *ptr, u16 pkey) in test_read_of_write_disabled_region() argument
952 ptr_contents = read_ptr(ptr); in test_read_of_write_disabled_region()
956 static void test_read_of_access_disabled_region(int *ptr, u16 pkey) in test_read_of_access_disabled_region() argument
960 dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); in test_read_of_access_disabled_region()
963 ptr_contents = read_ptr(ptr); in test_read_of_access_disabled_region()
968 static void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, in test_read_of_access_disabled_region_with_page_already_mapped() argument
974 pkey, ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
975 ptr_contents = read_ptr(ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
980 ptr_contents = read_ptr(ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
985 static void test_write_of_write_disabled_region_with_page_already_mapped(int *ptr, in test_write_of_write_disabled_region_with_page_already_mapped() argument
988 *ptr = __LINE__; in test_write_of_write_disabled_region_with_page_already_mapped()
992 *ptr = __LINE__; in test_write_of_write_disabled_region_with_page_already_mapped()
996 static void test_write_of_write_disabled_region(int *ptr, u16 pkey) in test_write_of_write_disabled_region() argument
1000 *ptr = __LINE__; in test_write_of_write_disabled_region()
1003 static void test_write_of_access_disabled_region(int *ptr, u16 pkey) in test_write_of_access_disabled_region() argument
1007 *ptr = __LINE__; in test_write_of_access_disabled_region()
1011 static void test_write_of_access_disabled_region_with_page_already_mapped(int *ptr, in test_write_of_access_disabled_region_with_page_already_mapped() argument
1014 *ptr = __LINE__; in test_write_of_access_disabled_region_with_page_already_mapped()
1018 *ptr = __LINE__; in test_write_of_access_disabled_region_with_page_already_mapped()
1022 static void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_access_disabled_region() argument
1030 ret = read(test_fd, ptr, 1); in test_kernel_write_of_access_disabled_region()
1035 static void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_write_disabled_region() argument
1041 ret = read(test_fd, ptr, 100); in test_kernel_write_of_write_disabled_region()
1048 static void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_of_access_disabled_region() argument
1060 iov.iov_base = ptr; in test_kernel_gup_of_access_disabled_region()
1070 static void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_write_to_write_disabled_region() argument
1078 *ptr = some_int; in test_kernel_gup_write_to_write_disabled_region()
1080 futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL, in test_kernel_gup_write_to_write_disabled_region()
1088 static void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) in test_pkey_syscalls_on_non_allocated_pkey() argument
1105 err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, i); in test_pkey_syscalls_on_non_allocated_pkey()
1111 static void test_pkey_syscalls_bad_args(int *ptr, u16 pkey) in test_pkey_syscalls_bad_args() argument
1117 err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, bad_pkey); in test_pkey_syscalls_bad_args()
1137 static void test_pkey_alloc_exhaust(int *ptr, u16 pkey) in test_pkey_alloc_exhaust() argument
1243 static void test_pkey_init_state(int *ptr, u16 pkey) in test_pkey_init_state() argument
1281 static void test_mprotect_with_pkey_0(int *ptr, u16 pkey) in test_mprotect_with_pkey_0() argument
1299 mprotect_pkey(ptr, size, prot, 0); in test_mprotect_with_pkey_0()
1302 mprotect_pkey(ptr, size, prot, pkey); in test_mprotect_with_pkey_0()
1305 static void test_ptrace_of_child(int *ptr, u16 pkey) in test_ptrace_of_child() argument
1353 ret = ptrace(PTRACE_PEEKDATA, child_pid, ptr, ignored); in test_ptrace_of_child()
1357 peek_result = read_ptr(ptr); in test_ptrace_of_child()
1402 static void test_executing_on_unreadable_memory(int *ptr, u16 pkey) in test_executing_on_unreadable_memory() argument
1434 static void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) in test_implicit_mprotect_exec_only_memory() argument
1483 static void test_ptrace_modifies_pkru(int *ptr, u16 pkey) in test_ptrace_modifies_pkru() argument
1606 static void test_ptrace_modifies_pkru(int *ptr, u16 pkey) in test_ptrace_modifies_pkru() argument
1683 static void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) in test_mprotect_pkey_on_unsupported_cpu() argument
1693 sret = syscall(__NR_pkey_mprotect, ptr, size, PROT_READ, pkey); in test_mprotect_pkey_on_unsupported_cpu()
1697 static void (*pkey_tests[])(int *ptr, u16 pkey) = {
1725 int *ptr; in run_tests_once() local
1738 ptr = malloc_pkey(PAGE_SIZE, prot, pkey); in run_tests_once()
1740 pkey_tests[test_nr](ptr, pkey); in run_tests_once()
1741 dprintf1("freeing test memory: %p\n", ptr); in run_tests_once()
1742 free_pkey_malloc(ptr); in run_tests_once()
1775 int *ptr; in main() local
1779 ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); in main()
1780 assert(ptr != (void *)-1); in main()
1781 test_mprotect_pkey_on_unsupported_cpu(ptr, 1); in main()