forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduction of regset ->get() wrappers, switching ELF coredumps to t…
…hose Two new helpers: given a process and regset, dump into a buffer. regset_get() takes a buffer and size, regset_get_alloc() takes size and allocates a buffer. Return value in both cases is the amount of data actually dumped in case of success or -E... on error. In both cases the size is capped by regset->n * regset->size, so ->get() is called with offset 0 and size no more than what regset expects. binfmt_elf.c callers of ->get() are switched to using those; the other caller (copy_regset_to_user()) will need some preparations to switch. Signed-off-by: Al Viro <[email protected]>
- Loading branch information
Al Viro
committed
Jul 27, 2020
1 parent
b3a9e3b
commit b4e9c95
Showing
4 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
#include <linux/export.h> | ||
#include <linux/slab.h> | ||
#include <linux/regset.h> | ||
|
||
static int __regset_get(struct task_struct *target, | ||
const struct user_regset *regset, | ||
unsigned int size, | ||
void **data) | ||
{ | ||
void *p = *data, *to_free = NULL; | ||
int res; | ||
|
||
if (!regset->get) | ||
return -EOPNOTSUPP; | ||
if (size > regset->n * regset->size) | ||
size = regset->n * regset->size; | ||
if (!p) { | ||
to_free = p = kzalloc(size, GFP_KERNEL); | ||
if (!p) | ||
return -ENOMEM; | ||
} | ||
res = regset->get(target, regset, 0, size, p, NULL); | ||
if (unlikely(res < 0)) { | ||
kfree(to_free); | ||
return res; | ||
} | ||
*data = p; | ||
if (regset->get_size) { // arm64-only kludge, will go away | ||
unsigned max_size = regset->get_size(target, regset); | ||
if (size > max_size) | ||
size = max_size; | ||
} | ||
return size; | ||
} | ||
|
||
int regset_get(struct task_struct *target, | ||
const struct user_regset *regset, | ||
unsigned int size, | ||
void *data) | ||
{ | ||
return __regset_get(target, regset, size, &data); | ||
} | ||
EXPORT_SYMBOL(regset_get); | ||
|
||
int regset_get_alloc(struct task_struct *target, | ||
const struct user_regset *regset, | ||
unsigned int size, | ||
void **data) | ||
{ | ||
*data = NULL; | ||
return __regset_get(target, regset, size, data); | ||
} | ||
EXPORT_SYMBOL(regset_get_alloc); |