#include <sys/types.h>
#include <sys/param.h>
#include <sys/thread.h>
#include <sys/sysmacros.h>
#include <sys/signal.h>
#include <sys/cred.h>
#include <sys/user.h>
#include <sys/errno.h>
#include <sys/vnode.h>
#include <sys/mman.h>
#include <sys/kmem.h>
#include <sys/proc.h>
#include <sys/pathname.h>
#include <sys/cmn_err.h>
#include <sys/systm.h>
#include <sys/elf.h>
#include <sys/vmsystm.h>
#include <sys/debug.h>
#include <sys/old_procfs.h>
#include <sys/auxv.h>
#include <sys/exec.h>
#include <sys/prsystm.h>
#include <vm/as.h>
#include <vm/rm.h>
#include <sys/modctl.h>
#include <sys/systeminfo.h>
#include <sys/machelf.h>
#include <sys/zone.h>
#include "elf_impl.h"
extern void oprgetstatus(kthread_t *, prstatus_t *, zone_t *);
extern void oprgetpsinfo(proc_t *, prpsinfo_t *, kthread_t *);
void
setup_old_note_header(Phdr *v, proc_t *p)
{
int nlwp = p->p_lwpcnt;
v[0].p_type = PT_NOTE;
v[0].p_flags = PF_R;
v[0].p_filesz = (sizeof (Note) * (3 + nlwp))
+ roundup(sizeof (prpsinfo_t), sizeof (Word))
+ roundup(strlen(platform) + 1, sizeof (Word))
+ roundup(__KERN_NAUXV_IMPL * sizeof (aux_entry_t),
sizeof (Word))
+ nlwp * roundup(sizeof (prstatus_t), sizeof (Word));
if (prhasfp()) {
v[0].p_filesz += nlwp * sizeof (Note) +
nlwp * roundup(sizeof (prfpregset_t), sizeof (Word));
}
}
int
write_old_elfnotes(proc_t *p, int sig, vnode_t *vp, offset_t offset,
rlim64_t rlimit, cred_t *credp)
{
union {
prpsinfo_t psinfo;
prstatus_t prstat;
prfpregset_t fpregs;
aux_entry_t auxv[__KERN_NAUXV_IMPL];
} *bigwad;
size_t bigsize = sizeof (*bigwad);
kthread_t *t;
klwp_t *lwp;
user_t *up;
int i;
int nlwp;
int error;
bigwad = kmem_alloc(bigsize, KM_SLEEP);
mutex_enter(&p->p_lock);
oprgetpsinfo(p, &bigwad->psinfo, NULL);
mutex_exit(&p->p_lock);
error = elfnote(vp, &offset, NT_PRPSINFO, sizeof (bigwad->psinfo),
(caddr_t)&bigwad->psinfo, rlimit, credp);
if (error)
goto done;
error = elfnote(vp, &offset, NT_PLATFORM, strlen(platform) + 1,
platform, rlimit, credp);
if (error)
goto done;
up = PTOU(p);
for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
bigwad->auxv[i].a_type = up->u_auxv[i].a_type;
bigwad->auxv[i].a_un.a_val = up->u_auxv[i].a_un.a_val;
}
error = elfnote(vp, &offset, NT_AUXV, sizeof (bigwad->auxv),
(caddr_t)bigwad->auxv, rlimit, credp);
if (error)
goto done;
t = curthread;
nlwp = p->p_lwpcnt;
do {
ASSERT(nlwp != 0);
nlwp--;
lwp = ttolwp(t);
mutex_enter(&p->p_lock);
if (t == curthread) {
uchar_t oldsig;
oldsig = lwp->lwp_cursig;
lwp->lwp_cursig = (uchar_t)sig;
t->t_whystop = PR_FAULTED;
oprgetstatus(t, &bigwad->prstat, p->p_zone);
bigwad->prstat.pr_why = 0;
t->t_whystop = 0;
lwp->lwp_cursig = oldsig;
} else {
oprgetstatus(t, &bigwad->prstat, p->p_zone);
}
mutex_exit(&p->p_lock);
error = elfnote(vp, &offset, NT_PRSTATUS,
sizeof (bigwad->prstat), (caddr_t)&bigwad->prstat,
rlimit, credp);
if (error)
goto done;
if (prhasfp()) {
prgetprfpregs(lwp, &bigwad->fpregs);
error = elfnote(vp, &offset, NT_PRFPREG,
sizeof (bigwad->fpregs), (caddr_t)&bigwad->fpregs,
rlimit, credp);
if (error)
goto done;
}
} while ((t = t->t_forw) != curthread);
ASSERT(nlwp == 0);
done:
kmem_free(bigwad, bigsize);
return (error);
}