coredump: Support threads

Change-Id: Id75ade6c87b15abcff5d772d90f77950376a32c1
Refs: #1219
This commit is contained in:
Masamichi Takagi
2019-02-19 17:08:39 +09:00
parent 12aef0b578
commit 11ef2f8092
33 changed files with 1438 additions and 76 deletions

View File

@ -1922,7 +1922,10 @@ int release_user_space(uintptr_t start, uintptr_t len)
* \param chunks The number of chunks which make a core file image in the whole.
*/
static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks,
unsigned long cmdline_rphys, unsigned long cmdline_len)
{
char *fn = NULL;
struct file *file;
struct coretable *coretable;
int i, tablesize, error = 0;
@ -1931,22 +1934,43 @@ static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
unsigned long phys, tablephys, rphys;
ihk_device_t dev = ihk_os_to_dev(os);
char *pt;
unsigned long cmdline_phys;
char *cmdline;
dprintk("coredump called as a pseudo syscall\n");
fn = kmalloc(PATH_MAX, GFP_ATOMIC);
if (!fn) {
dprintk("%s: ERROR: allocating file name\n", __func__);
error = -ENOMEM;
goto fail;
}
if (chunks <= 0) {
dprintk("no core data found!(%d)\n", chunks);
error = -EINVAL;
goto fail;
}
cmdline_phys = ihk_device_map_memory(dev, cmdline_rphys, cmdline_len);
cmdline = ihk_device_map_virtual(dev, cmdline_phys, cmdline_len, NULL,
0);
sprintf(fn, "mccore-%s.%d",
strrchr(cmdline, '/') ?
strrchr(cmdline, '/') + 1 : cmdline,
task_tgid_vnr(current));
pr_info("%s: fn=%s\n", __func__, fn);
ihk_device_unmap_virtual(dev, cmdline, cmdline_len);
ihk_device_unmap_memory(dev, cmdline_phys, cmdline_len);
/* Every Linux documentation insists we should not
* open a file in the kernel module, but our karma
* leads us here. Precisely, Here we emulate the core
* dump routine of the Linux kernel in linux/fs/exec.c.
* So we have a legitimate reason to do this.
*/
file = filp_open("core", O_CREAT | O_RDWR | O_LARGEFILE | O_TRUNC, 0600);
file = filp_open(fn, O_CREAT | O_RDWR | O_LARGEFILE | O_TRUNC, 0600);
if (IS_ERR(file) || !file->f_op) {
dprintk("cannot open core file\n");
error = PTR_ERR(file);
@ -2016,6 +2040,7 @@ fail:
/* make sure we do not travel to user land */
error = -EINVAL;
}
kfree(fn);
return error;
}
@ -2071,7 +2096,8 @@ int __do_in_kernel_syscall(ihk_os_t os, struct ikc_scd_packet *packet)
}
case __NR_coredump:
ret = writecore(os, sc->args[1], sc->args[0]);
ret = writecore(os, sc->args[1], sc->args[0], sc->args[2],
sc->args[3]);
break;
case __NR_sched_setparam: {