mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
introduction of regset ->get() wrappers, switching ELF coredumps to those
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 <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
b3a9e3b962
commit
b4e9c9549f
@ -1821,7 +1821,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
|
|||||||
long signr, size_t *total)
|
long signr, size_t *total)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int regset0_size = regset_size(t->task, &view->regsets[0]);
|
int regset0_size;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NT_PRSTATUS is the one special case, because the regset data
|
* NT_PRSTATUS is the one special case, because the regset data
|
||||||
@ -1830,8 +1830,10 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
|
|||||||
* We assume that regset 0 is NT_PRSTATUS.
|
* We assume that regset 0 is NT_PRSTATUS.
|
||||||
*/
|
*/
|
||||||
fill_prstatus(&t->prstatus, t->task, signr);
|
fill_prstatus(&t->prstatus, t->task, signr);
|
||||||
(void) view->regsets[0].get(t->task, &view->regsets[0], 0, regset0_size,
|
regset0_size = regset_get(t->task, &view->regsets[0],
|
||||||
&t->prstatus.pr_reg, NULL);
|
sizeof(t->prstatus.pr_reg), &t->prstatus.pr_reg);
|
||||||
|
if (regset0_size < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
fill_note(&t->notes[0], "CORE", NT_PRSTATUS,
|
fill_note(&t->notes[0], "CORE", NT_PRSTATUS,
|
||||||
PRSTATUS_SIZE(t->prstatus, regset0_size), &t->prstatus);
|
PRSTATUS_SIZE(t->prstatus, regset0_size), &t->prstatus);
|
||||||
@ -1846,32 +1848,28 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
|
|||||||
*/
|
*/
|
||||||
for (i = 1; i < view->n; ++i) {
|
for (i = 1; i < view->n; ++i) {
|
||||||
const struct user_regset *regset = &view->regsets[i];
|
const struct user_regset *regset = &view->regsets[i];
|
||||||
|
int note_type = regset->core_note_type;
|
||||||
|
bool is_fpreg = note_type == NT_PRFPREG;
|
||||||
|
void *data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
do_thread_regset_writeback(t->task, regset);
|
do_thread_regset_writeback(t->task, regset);
|
||||||
if (regset->core_note_type && regset->get &&
|
if (!note_type) // not for coredumps
|
||||||
(!regset->active || regset->active(t->task, regset) > 0)) {
|
continue;
|
||||||
int ret;
|
if (regset->active && regset->active(t->task, regset) <= 0)
|
||||||
size_t size = regset_size(t->task, regset);
|
continue;
|
||||||
void *data = kzalloc(size, GFP_KERNEL);
|
|
||||||
if (unlikely(!data))
|
ret = regset_get_alloc(t->task, regset, ~0U, &data);
|
||||||
return 0;
|
if (ret < 0)
|
||||||
ret = regset->get(t->task, regset,
|
continue;
|
||||||
0, size, data, NULL);
|
|
||||||
if (unlikely(ret))
|
if (is_fpreg)
|
||||||
kfree(data);
|
SET_PR_FPVALID(&t->prstatus, 1, regset0_size);
|
||||||
else {
|
|
||||||
if (regset->core_note_type != NT_PRFPREG)
|
fill_note(&t->notes[i], is_fpreg ? "CORE" : "LINUX",
|
||||||
fill_note(&t->notes[i], "LINUX",
|
note_type, ret, data);
|
||||||
regset->core_note_type,
|
|
||||||
size, data);
|
*total += notesize(&t->notes[i]);
|
||||||
else {
|
|
||||||
SET_PR_FPVALID(&t->prstatus,
|
|
||||||
1, regset0_size);
|
|
||||||
fill_note(&t->notes[i], "CORE",
|
|
||||||
NT_PRFPREG, size, data);
|
|
||||||
}
|
|
||||||
*total += notesize(&t->notes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -353,6 +353,15 @@ static inline int user_regset_copyin_ignore(unsigned int *pos,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int regset_get(struct task_struct *target,
|
||||||
|
const struct user_regset *regset,
|
||||||
|
unsigned int size, void *data);
|
||||||
|
|
||||||
|
extern int regset_get_alloc(struct task_struct *target,
|
||||||
|
const struct user_regset *regset,
|
||||||
|
unsigned int size,
|
||||||
|
void **data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copy_regset_to_user - fetch a thread's user_regset data into user memory
|
* copy_regset_to_user - fetch a thread's user_regset data into user memory
|
||||||
* @target: thread to be examined
|
* @target: thread to be examined
|
||||||
|
@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \
|
|||||||
extable.o params.o \
|
extable.o params.o \
|
||||||
kthread.o sys_ni.o nsproxy.o \
|
kthread.o sys_ni.o nsproxy.o \
|
||||||
notifier.o ksysfs.o cred.o reboot.o \
|
notifier.o ksysfs.o cred.o reboot.o \
|
||||||
async.o range.o smpboot.o ucount.o
|
async.o range.o smpboot.o ucount.o regset.o
|
||||||
|
|
||||||
obj-$(CONFIG_MODULES) += kmod.o
|
obj-$(CONFIG_MODULES) += kmod.o
|
||||||
obj-$(CONFIG_MULTIUSER) += groups.o
|
obj-$(CONFIG_MULTIUSER) += groups.o
|
||||||
|
54
kernel/regset.c
Normal file
54
kernel/regset.c
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user