elfcore.c (1d73ef97901e0d16f966b34d782bc7abb31098e3) elfcore.c (7f08176ee8b672feebd8a12572b43dddcb88046e)
1/*-
2 * Copyright (c) 2007 Sandvine Incorporated
3 * Copyright (c) 1998 John D. Polstra
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 270 unchanged lines hidden (view full) ---

279
280/*
281 * Generate the ELF coredump header into the buffer at "dst". "dst" may
282 * be NULL, in which case the header is sized but not actually generated.
283 */
284static void
285elf_puthdr(pid_t pid, vm_map_entry_t map, void *dst, size_t *off, int numsegs)
286{
1/*-
2 * Copyright (c) 2007 Sandvine Incorporated
3 * Copyright (c) 1998 John D. Polstra
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 270 unchanged lines hidden (view full) ---

279
280/*
281 * Generate the ELF coredump header into the buffer at "dst". "dst" may
282 * be NULL, in which case the header is sized but not actually generated.
283 */
284static void
285elf_puthdr(pid_t pid, vm_map_entry_t map, void *dst, size_t *off, int numsegs)
286{
287 struct ptrace_lwpinfo lwpinfo;
287 struct {
288 prstatus_t status;
289 prfpregset_t fpregset;
290 prpsinfo_t psinfo;
288 struct {
289 prstatus_t status;
290 prfpregset_t fpregset;
291 prpsinfo_t psinfo;
292 thrmisc_t thrmisc;
291 } *tempdata;
292 size_t ehoff;
293 size_t phoff;
294 size_t noteoff;
295 size_t notesz;
296 size_t threads;
297 lwpid_t *tids;
298 int i;
299
300 prstatus_t *status;
301 prfpregset_t *fpregset;
302 prpsinfo_t *psinfo;
293 } *tempdata;
294 size_t ehoff;
295 size_t phoff;
296 size_t noteoff;
297 size_t notesz;
298 size_t threads;
299 lwpid_t *tids;
300 int i;
301
302 prstatus_t *status;
303 prfpregset_t *fpregset;
304 prpsinfo_t *psinfo;
305 thrmisc_t *thrmisc;
303
304 ehoff = *off;
305 *off += sizeof(Elf_Ehdr);
306
307 phoff = *off;
308 *off += (numsegs + 1) * sizeof(Elf_Phdr);
309
310 noteoff = *off;
311
312 if (dst != NULL) {
313 if ((tempdata = calloc(1, sizeof(*tempdata))) == NULL)
314 errx(1, "out of memory");
315 status = &tempdata->status;
316 fpregset = &tempdata->fpregset;
317 psinfo = &tempdata->psinfo;
306
307 ehoff = *off;
308 *off += sizeof(Elf_Ehdr);
309
310 phoff = *off;
311 *off += (numsegs + 1) * sizeof(Elf_Phdr);
312
313 noteoff = *off;
314
315 if (dst != NULL) {
316 if ((tempdata = calloc(1, sizeof(*tempdata))) == NULL)
317 errx(1, "out of memory");
318 status = &tempdata->status;
319 fpregset = &tempdata->fpregset;
320 psinfo = &tempdata->psinfo;
321 thrmisc = &tempdata->thrmisc;
318 } else {
319 tempdata = NULL;
320 status = NULL;
321 fpregset = NULL;
322 psinfo = NULL;
322 } else {
323 tempdata = NULL;
324 status = NULL;
325 fpregset = NULL;
326 psinfo = NULL;
327 thrmisc = NULL;
323 }
324
325 errno = 0;
326 threads = ptrace(PT_GETNUMLWPS, pid, NULL, 0);
327 if (errno)
328 err(1, "PT_GETNUMLWPS");
329
330 if (dst != NULL) {

--- 20 unchanged lines hidden (view full) ---

351 status->pr_statussz = sizeof(prstatus_t);
352 status->pr_gregsetsz = sizeof(gregset_t);
353 status->pr_fpregsetsz = sizeof(fpregset_t);
354 status->pr_osreldate = __FreeBSD_version;
355 status->pr_pid = tids[i];
356
357 ptrace(PT_GETREGS, tids[i], (void *)&status->pr_reg, 0);
358 ptrace(PT_GETFPREGS, tids[i], (void *)fpregset, 0);
328 }
329
330 errno = 0;
331 threads = ptrace(PT_GETNUMLWPS, pid, NULL, 0);
332 if (errno)
333 err(1, "PT_GETNUMLWPS");
334
335 if (dst != NULL) {

--- 20 unchanged lines hidden (view full) ---

356 status->pr_statussz = sizeof(prstatus_t);
357 status->pr_gregsetsz = sizeof(gregset_t);
358 status->pr_fpregsetsz = sizeof(fpregset_t);
359 status->pr_osreldate = __FreeBSD_version;
360 status->pr_pid = tids[i];
361
362 ptrace(PT_GETREGS, tids[i], (void *)&status->pr_reg, 0);
363 ptrace(PT_GETFPREGS, tids[i], (void *)fpregset, 0);
364 ptrace(PT_LWPINFO, tids[i], (void *)&lwpinfo,
365 sizeof(lwpinfo));
366 memset(&thrmisc->_pad, 0, sizeof(thrmisc->_pad));
367 strcpy(thrmisc->pr_tname, lwpinfo.pl_tdname);
359 }
360 elf_putnote(dst, off, "FreeBSD", NT_PRSTATUS, status,
361 sizeof *status);
362 elf_putnote(dst, off, "FreeBSD", NT_FPREGSET, fpregset,
363 sizeof *fpregset);
368 }
369 elf_putnote(dst, off, "FreeBSD", NT_PRSTATUS, status,
370 sizeof *status);
371 elf_putnote(dst, off, "FreeBSD", NT_FPREGSET, fpregset,
372 sizeof *fpregset);
373 elf_putnote(dst, off, "FreeBSD", NT_THRMISC, thrmisc,
374 sizeof *thrmisc);
364 }
365
366 notesz = *off - noteoff;
367
368 if (dst != NULL) {
369 free(tids);
370 free(tempdata);
371 }

--- 152 unchanged lines hidden ---
375 }
376
377 notesz = *off - noteoff;
378
379 if (dst != NULL) {
380 free(tids);
381 free(tempdata);
382 }

--- 152 unchanged lines hidden ---