#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#ifdef LYNX_CORE
#include <sys/conf.h>
#include <sys/kernel.h>
#ifndef __LYNXOS
#define __LYNXOS
#endif
#include <sys/mem.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/itimer.h>
#include <sys/file.h>
#include <sys/proc.h>
struct lynx_core_struct
{
int sig;
char cmd[PNMLEN + 1];
};
#define core_hdr(bfd) ((bfd)->tdata.lynx_core_data)
#define core_signal(bfd) (core_hdr(bfd)->sig)
#define core_command(bfd) (core_hdr(bfd)->cmd)
static asection *
make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
bfd *abfd;
const char *name;
flagword flags;
bfd_size_type _raw_size;
bfd_vma vma;
file_ptr filepos;
{
asection *asect;
char *newname;
newname = bfd_alloc (abfd, (bfd_size_type) strlen (name) + 1);
if (!newname)
return NULL;
strcpy (newname, name);
asect = bfd_make_section (abfd, newname);
if (!asect)
return NULL;
asect->flags = flags;
asect->_raw_size = _raw_size;
asect->vma = vma;
asect->filepos = filepos;
asect->alignment_power = 2;
return asect;
}
const bfd_target *
lynx_core_file_p (abfd)
bfd *abfd;
{
int secnum;
struct pssentry pss;
bfd_size_type tcontext_size;
core_st_t *threadp;
int pagesize;
asection *newsect;
bfd_size_type amt;
pagesize = getpagesize ();
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
return NULL;
amt = sizeof pss;
if (bfd_bread ((void *) &pss, amt, abfd) != amt)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
amt = sizeof (struct lynx_core_struct);
core_hdr (abfd) = (struct lynx_core_struct *) bfd_zalloc (abfd, amt);
if (!core_hdr (abfd))
return NULL;
strncpy (core_command (abfd), pss.pname, PNMLEN + 1);
tcontext_size = pss.threadcnt * sizeof (core_st_t);
threadp = (core_st_t *) bfd_alloc (abfd, tcontext_size);
if (!threadp)
goto fail;
if (bfd_seek (abfd, (file_ptr) pagesize, SEEK_SET) != 0)
goto fail;
if (bfd_bread ((void *) threadp, tcontext_size, abfd) != tcontext_size)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
goto fail;
}
core_signal (abfd) = threadp->currsig;
newsect = make_bfd_asection (abfd, ".stack",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
pss.ssize,
pss.slimit,
pagesize + tcontext_size);
if (!newsect)
goto fail;
newsect = make_bfd_asection (abfd, ".data",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
pss.data_len + pss.bss_len,
pss.data_start,
pagesize + tcontext_size + pss.ssize
#if defined (SPARC) || defined (__SPARC__)
+ pss.data_start % pagesize
#endif
);
if (!newsect)
goto fail;
newsect = make_bfd_asection (abfd, ".reg",
SEC_HAS_CONTENTS,
sizeof (core_st_t),
0,
pagesize);
if (!newsect)
goto fail;
for (secnum = 0; secnum < pss.threadcnt; secnum++)
{
char secname[100];
sprintf (secname, ".reg/%d", BUILDPID (0, threadp[secnum].tid));
newsect = make_bfd_asection (abfd, secname,
SEC_HAS_CONTENTS,
sizeof (core_st_t),
0,
pagesize + secnum * sizeof (core_st_t));
if (!newsect)
goto fail;
}
return abfd->xvec;
fail:
bfd_release (abfd, core_hdr (abfd));
core_hdr (abfd) = NULL;
bfd_section_list_clear (abfd);
return NULL;
}
char *
lynx_core_file_failing_command (abfd)
bfd *abfd;
{
return core_command (abfd);
}
int
lynx_core_file_failing_signal (abfd)
bfd *abfd;
{
return core_signal (abfd);
}
bfd_boolean
lynx_core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd, *exec_bfd;
{
return TRUE;
}
#endif