c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/* $Id$ */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/** @file
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * IPRT Testcase - Core dump, header.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/*
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * Copyright (C) 2010 Oracle Corporation
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * available from http://www.virtualbox.org. This file is free software;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * General Public License (GPL) as published by the Free Software
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * The contents of this file may alternatively be used under the terms
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * of the Common Development and Distribution License Version 1.0
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * CDDL are applicable instead of those of the GPL.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * You may elect to license modified versions of this file under the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * terms and conditions of either the GPL or the CDDL or both.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#include <iprt/process.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#include <iprt/file.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#ifdef RT_OS_SOLARIS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# if defined(RT_ARCH_X86) && _FILE_OFFSET_BITS==64
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/*
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * Solaris' procfs cannot be used with large file environment in 32-bit.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# undef _FILE_OFFSET_BITS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# define _FILE_OFFSET_BITS 32
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <procfs.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/procfs.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/old_procfs.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# undef _FILE_OFFSET_BITS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# define _FILE_OFFSET_BITS 64
c473b29b7812ebca7a632b4a17fa3605ccb1a0cavboxsync#else
c473b29b7812ebca7a632b4a17fa3605ccb1a0cavboxsync# include <procfs.h>
c473b29b7812ebca7a632b4a17fa3605ccb1a0cavboxsync# include <sys/procfs.h>
c473b29b7812ebca7a632b4a17fa3605ccb1a0cavboxsync# include <sys/old_procfs.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#endif
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <limits.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <thread.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/auxv.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/lwp.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/zone.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/utsname.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#ifdef RT_ARCH_AMD64
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# define _ELF64
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# undef _ELF32_COMPAT
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#endif
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/machelf.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# include <sys/corectl.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#endif
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/**
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * ELF NOTE header.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef struct ELFNOTEHDR
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync Nhdr Hdr; /* Header of NOTE section */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char achName[8]; /* Name of NOTE section */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync} ELFNOTEHDR;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef ELFNOTEHDR *PELFNOTEHDR;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#ifdef RT_OS_SOLARIS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef struct VBOXSOLMAPINFO
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync prmap_t pMap; /* Proc description of this mapping */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync int fError; /* Any error reading this mapping (errno) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync struct VBOXSOLMAPINFO *pNext; /* Pointer to the next mapping */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync} VBOXSOLMAPINFO;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef VBOXSOLMAPINFO *PVBOXSOLMAPINFO;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef struct VBOXSOLTHREADINFO
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync lwpsinfo_t Info; /* Proc description of this thread */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync lwpstatus_t *pStatus; /* Proc description of this thread's status (can be NULL, zombie lwp) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync struct VBOXSOLTHREADINFO *pNext; /* Pointer to the next thread */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync} VBOXSOLTHREADINFO;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef VBOXSOLTHREADINFO *PVBOXSOLTHREADINFO;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#endif
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef int (*PFNCOREREADER)(RTFILE hFile, void *pv, size_t cb);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef int (*PFNCOREWRITER)(RTFILE hFile, const void *pcv, size_t cb);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef struct VBOXPROCESS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync RTPROCESS Process; /* The pid of the process */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char szExecPath[PATH_MAX]; /* Path of the executable */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char *pszExecName; /* Name of the executable file */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#ifdef RT_OS_SOLARIS
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync psinfo_t ProcInfo; /* Process info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync prpsinfo_t ProcInfoOld; /* Process info. Older version (for GDB compat.) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync pstatus_t ProcStatus; /* Process status info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync thread_t hCurThread; /* The current thread */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync ucontext_t *pCurThreadCtx; /* Context info. of current thread before starting to dump */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync RTFILE hAs; /* proc/<pid/as file handle */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync auxv_t *pAuxVecs; /* Aux vector of process */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync int cAuxVecs; /* Number of aux vector entries */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync PVBOXSOLMAPINFO pMapInfoHead; /* Pointer to the head of list of mappings */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync uint32_t cMappings; /* Number of mappings (count of pMapInfoHead list) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync PVBOXSOLTHREADINFO pThreadInfoHead; /* Pointer to the head of list of threads */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync uint64_t cThreads; /* Number of threads (count of pThreadInfoHead list) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char szPlatform[SYS_NMLN]; /* Platform name */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char szZoneName[ZONENAME_MAX]; /* Zone name */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync struct utsname UtsName; /* UTS name */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync void *pvCred; /* Process credential info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync size_t cbCred; /* Size of process credential info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync void *pvLdt; /* Process LDT info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync size_t cbLdt; /* Size of the LDT info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync prpriv_t *pPriv; /* Process privilege info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync size_t cbPriv; /* Size of process privilege info. */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync const priv_impl_info_t *pcPrivImpl; /* Process privilege implementation info. (opaque handle) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync core_content_t CoreContent; /* What information goes in the core */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#else
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync# error Port Me!
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#endif
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync} VBOXPROCESS;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef VBOXPROCESS *PVBOXPROCESS;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef struct VBOXCORE
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync char szCorePath[PATH_MAX]; /* Path of the core file */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync VBOXPROCESS VBoxProc; /* Current process information */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync void *pvCore; /* Pointer to memory area during dumping */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync size_t cbCore; /* Size of memory area during dumping */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync void *pvFree; /* Pointer to base of free range in preallocated memory area */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync bool fIsValid; /* Whether core information has been fully collected */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync PFNCOREREADER pfnReader; /* Reader function */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync PFNCOREWRITER pfnWriter; /* Writer function */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync RTFILE hCoreFile; /* Core file (used only while writing the core) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync RTFOFF offWrite; /* Segment/section offset (used only while writing the core) */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync} VBOXCORE;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef VBOXCORE *PVBOXCORE;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsynctypedef int (*PFNCOREACCUMULATOR)(PVBOXCORE pVBoxCOre);