1 # Copyright 2015-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 require {is_any_target i?86-*-* x86_64-*-*}
20 set default_pkru_re 0x0
21 if { [istarget *-*-linux*] } {
22 # Starting with v4.9, the linux kernel contains commit acd547b29880
23 # ("x86/pkeys: Default to a restrictive init PKRU"), which sets the
24 # pkru register to 0x55555554 by default.
25 set default_pkru_re (0x0|0x55555554)
29 set comp_flags "-I${srcdir}/../nat/"
31 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
32 [list debug additional_flags=${comp_flags}]] } {
33 untested "failed to compile x86 PKEYS test."
42 set test "probe PKRU support"
43 gdb_test_multiple "print have_pkru()" $test {
44 -re ".. = 1\r\n$gdb_prompt $" {
48 -re ".. = 0\r\n$gdb_prompt $" {
53 if { !$supports_pkru } {
54 unsupported "processor does not support protection key feature."
58 # Linux kernel versions 5.14.0 to 6.1.x contain a regression related to writing
59 # the PKRU using ptrace, see commit 4a804c4f8356 ("x86/fpu: Allow PKRU to be
60 # (once again) written by ptrace.").
62 set v [linux_kernel_version]
66 [version_compare [list 5 14 0] <= $v] \
67 && [version_compare $v < [list 6 2 0]]]
70 # Test pkru register at startup
71 gdb_test "print /x \$pkru" "= $default_pkru_re" "pkru register"
73 # Read values from pseudo registers.
74 gdb_breakpoint [ gdb_get_line_number "break here 1" ]
75 gdb_continue_to_breakpoint "break here 1" ".*break here 1.*"
78 gdb_test "info register pkru" ".*pkru.*$val1.*" "read pkru register"
81 gdb_test "print /x \$pkru = $val2" "= $val2" "set pkru value"
83 gdb_test_multiple "info register pkru" "read value after setting value" {
84 -re -wrap ".*pkru.*$val2.*" {
87 -re -wrap ".*pkru.*$val1.*" {
96 gdb_breakpoint [ gdb_get_line_number "break here 2" ]
97 gdb_continue_to_breakpoint "break here 2" ".*break here 2.*"
99 gdb_test_multiple "print /x rd_value" "variable after reading pkru" {
100 -re -wrap "= $val2" {
103 -re -wrap "= $val1" {