Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: user_regset user-copy helpers

This defines two new inlines in linux/regset.h, for use in arch_ptrace
implementations and the like. These provide simplified wrappers for using
the user_regset interfaces to copy thread regset data into the caller's
user-space memory. The inlines are trivial, but make the common uses in
places such as ptrace implementation much more concise, easier to read, and
less prone to code-copying errors.

Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Roland McGrath and committed by
Ingo Molnar
5bde4d18 b9d36d5d

+46
+46
include/linux/regset.h
··· 318 318 return 0; 319 319 } 320 320 321 + /** 322 + * copy_regset_to_user - fetch a thread's user_regset data into user memory 323 + * @target: thread to be examined 324 + * @view: &struct user_regset_view describing user thread machine state 325 + * @setno: index in @view->regsets 326 + * @offset: offset into the regset data, in bytes 327 + * @size: amount of data to copy, in bytes 328 + * @data: user-mode pointer to copy into 329 + */ 330 + static inline int copy_regset_to_user(struct task_struct *target, 331 + const struct user_regset_view *view, 332 + unsigned int setno, 333 + unsigned int offset, unsigned int size, 334 + void __user *data) 335 + { 336 + const struct user_regset *regset = &view->regsets[setno]; 337 + 338 + if (!access_ok(VERIFY_WRITE, data, size)) 339 + return -EIO; 340 + 341 + return regset->get(target, regset, offset, size, NULL, data); 342 + } 343 + 344 + /** 345 + * copy_regset_from_user - store into thread's user_regset data from user memory 346 + * @target: thread to be examined 347 + * @view: &struct user_regset_view describing user thread machine state 348 + * @setno: index in @view->regsets 349 + * @offset: offset into the regset data, in bytes 350 + * @size: amount of data to copy, in bytes 351 + * @data: user-mode pointer to copy from 352 + */ 353 + static inline int copy_regset_from_user(struct task_struct *target, 354 + const struct user_regset_view *view, 355 + unsigned int setno, 356 + unsigned int offset, unsigned int size, 357 + const void __user *data) 358 + { 359 + const struct user_regset *regset = &view->regsets[setno]; 360 + 361 + if (!access_ok(VERIFY_READ, data, size)) 362 + return -EIO; 363 + 364 + return regset->set(target, regset, offset, size, NULL, data); 365 + } 366 + 321 367 322 368 #endif /* <linux/regset.h> */