1 /* 2 * User-mode machine state access 3 * 4 * Copyright (C) 2007 Red Hat, Inc. All rights reserved. 5 * 6 * This copyrighted material is made available to anyone wishing to use, 7 * modify, copy, or redistribute it subject to the terms and conditions 8 * of the GNU General Public License v.2. 9 * 10 * Red Hat Author: Roland McGrath. 11 */ 12 13 #ifndef _LINUX_REGSET_H 14 #define _LINUX_REGSET_H 1 15 16 #include <linux/compiler.h> 17 #include <linux/types.h> 18 struct task_struct; 19 struct user_regset; 20 21 22 /** 23 * user_regset_active_fn - type of @active function in &struct user_regset 24 * @target: thread being examined 25 * @regset: regset being examined 26 * 27 * Return -%ENODEV if not available on the hardware found. 28 * Return %0 if no interesting state in this thread. 29 * Return >%0 number of @size units of interesting state. 30 * Any get call fetching state beyond that number will 31 * see the default initialization state for this data, 32 * so a caller that knows what the default state is need 33 * not copy it all out. 34 * This call is optional; the pointer is %NULL if there 35 * is no inexpensive check to yield a value < @n. 36 */ 37 typedef int user_regset_active_fn(struct task_struct *target, 38 const struct user_regset *regset); 39 40 /** 41 * user_regset_get_fn - type of @get function in &struct user_regset 42 * @target: thread being examined 43 * @regset: regset being examined 44 * @pos: offset into the regset data to access, in bytes 45 * @count: amount of data to copy, in bytes 46 * @kbuf: if not %NULL, a kernel-space pointer to copy into 47 * @ubuf: if @kbuf is %NULL, a user-space pointer to copy into 48 * 49 * Fetch register values. Return %0 on success; -%EIO or -%ENODEV 50 * are usual failure returns. The @pos and @count values are in 51 * bytes, but must be properly aligned. If @kbuf is non-null, that 52 * buffer is used and @ubuf is ignored. If @kbuf is %NULL, then 53 * ubuf gives a userland pointer to access directly, and an -%EFAULT 54 * return value is possible. 55 */ 56 typedef int user_regset_get_fn(struct task_struct *target, 57 const struct user_regset *regset, 58 unsigned int pos, unsigned int count, 59 void *kbuf, void __user *ubuf); 60 61 /** 62 * user_regset_set_fn - type of @set function in &struct user_regset 63 * @target: thread being examined 64 * @regset: regset being examined 65 * @pos: offset into the regset data to access, in bytes 66 * @count: amount of data to copy, in bytes 67 * @kbuf: if not %NULL, a kernel-space pointer to copy from 68 * @ubuf: if @kbuf is %NULL, a user-space pointer to copy from 69 * 70 * Store register values. Return %0 on success; -%EIO or -%ENODEV 71 * are usual failure returns. The @pos and @count values are in 72 * bytes, but must be properly aligned. If @kbuf is non-null, that 73 * buffer is used and @ubuf is ignored. If @kbuf is %NULL, then 74 * ubuf gives a userland pointer to access directly, and an -%EFAULT 75 * return value is possible. 76 */ 77 typedef int user_regset_set_fn(struct task_struct *target, 78 const struct user_regset *regset, 79 unsigned int pos, unsigned int count, 80 const void *kbuf, const void __user *ubuf); 81 82 /** 83 * user_regset_writeback_fn - type of @writeback function in &struct user_regset 84 * @target: thread being examined 85 * @regset: regset being examined 86 * @immediate: zero if writeback at completion of next context switch is OK 87 * 88 * This call is optional; usually the pointer is %NULL. When 89 * provided, there is some user memory associated with this regset's 90 * hardware, such as memory backing cached register data on register 91 * window machines; the regset's data controls what user memory is 92 * used (e.g. via the stack pointer value). 93 * 94 * Write register data back to user memory. If the @immediate flag 95 * is nonzero, it must be written to the user memory so uaccess or 96 * access_process_vm() can see it when this call returns; if zero, 97 * then it must be written back by the time the task completes a 98 * context switch (as synchronized with wait_task_inactive()). 99 * Return %0 on success or if there was nothing to do, -%EFAULT for 100 * a memory problem (bad stack pointer or whatever), or -%EIO for a 101 * hardware problem. 102 */ 103 typedef int user_regset_writeback_fn(struct task_struct *target, 104 const struct user_regset *regset, 105 int immediate); 106 107 /** 108 * struct user_regset - accessible thread CPU state 109 * @n: Number of slots (registers). 110 * @size: Size in bytes of a slot (register). 111 * @align: Required alignment, in bytes. 112 * @bias: Bias from natural indexing. 113 * @core_note_type: ELF note @n_type value used in core dumps. 114 * @get: Function to fetch values. 115 * @set: Function to store values. 116 * @active: Function to report if regset is active, or %NULL. 117 * @writeback: Function to write data back to user memory, or %NULL. 118 * 119 * This data structure describes a machine resource we call a register set. 120 * This is part of the state of an individual thread, not necessarily 121 * actual CPU registers per se. A register set consists of a number of 122 * similar slots, given by @n. Each slot is @size bytes, and aligned to 123 * @align bytes (which is at least @size). 124 * 125 * These functions must be called only on the current thread or on a 126 * thread that is in %TASK_STOPPED or %TASK_TRACED state, that we are 127 * guaranteed will not be woken up and return to user mode, and that we 128 * have called wait_task_inactive() on. (The target thread always might 129 * wake up for SIGKILL while these functions are working, in which case 130 * that thread's user_regset state might be scrambled.) 131 * 132 * The @pos argument must be aligned according to @align; the @count 133 * argument must be a multiple of @size. These functions are not 134 * responsible for checking for invalid arguments. 135 * 136 * When there is a natural value to use as an index, @bias gives the 137 * difference between the natural index and the slot index for the 138 * register set. For example, x86 GDT segment descriptors form a regset; 139 * the segment selector produces a natural index, but only a subset of 140 * that index space is available as a regset (the TLS slots); subtracting 141 * @bias from a segment selector index value computes the regset slot. 142 * 143 * If nonzero, @core_note_type gives the n_type field (NT_* value) 144 * of the core file note in which this regset's data appears. 145 * NT_PRSTATUS is a special case in that the regset data starts at 146 * offsetof(struct elf_prstatus, pr_reg) into the note data; that is 147 * part of the per-machine ELF formats userland knows about. In 148 * other cases, the core file note contains exactly the whole regset 149 * (@n * @size) and nothing else. The core file note is normally 150 * omitted when there is an @active function and it returns zero. 151 */ 152 struct user_regset { 153 user_regset_get_fn *get; 154 user_regset_set_fn *set; 155 user_regset_active_fn *active; 156 user_regset_writeback_fn *writeback; 157 unsigned int n; 158 unsigned int size; 159 unsigned int align; 160 unsigned int bias; 161 unsigned int core_note_type; 162 }; 163 164 /** 165 * struct user_regset_view - available regsets 166 * @name: Identifier, e.g. UTS_MACHINE string. 167 * @regsets: Array of @n regsets available in this view. 168 * @n: Number of elements in @regsets. 169 * @e_machine: ELF header @e_machine %EM_* value written in core dumps. 170 * @e_flags: ELF header @e_flags value written in core dumps. 171 * @ei_osabi: ELF header @e_ident[%EI_OSABI] value written in core dumps. 172 * 173 * A regset view is a collection of regsets (&struct user_regset, 174 * above). This describes all the state of a thread that can be seen 175 * from a given architecture/ABI environment. More than one view might 176 * refer to the same &struct user_regset, or more than one regset 177 * might refer to the same machine-specific state in the thread. For 178 * example, a 32-bit thread's state could be examined from the 32-bit 179 * view or from the 64-bit view. Either method reaches the same thread 180 * register state, doing appropriate widening or truncation. 181 */ 182 struct user_regset_view { 183 const char *name; 184 const struct user_regset *regsets; 185 unsigned int n; 186 u32 e_flags; 187 u16 e_machine; 188 u8 ei_osabi; 189 }; 190 191 /* 192 * This is documented here rather than at the definition sites because its 193 * implementation is machine-dependent but its interface is universal. 194 */ 195 /** 196 * task_user_regset_view - Return the process's native regset view. 197 * @tsk: a thread of the process in question 198 * 199 * Return the &struct user_regset_view that is native for the given process. 200 * For example, what it would access when it called ptrace(). 201 * Throughout the life of the process, this only changes at exec. 202 */ 203 const struct user_regset_view *task_user_regset_view(struct task_struct *tsk); 204 205 206 #endif /* <linux/regset.h> */ 207