Deleted Added
full compact
imgact_elf.c (146598) imgact_elf.c (147692)
1/*-
2 * Copyright (c) 2000 David O'Brien
3 * Copyright (c) 1995-1996 S�ren Schmidt
4 * Copyright (c) 1996 Peter Wemm
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000 David O'Brien
3 * Copyright (c) 1995-1996 S�ren Schmidt
4 * Copyright (c) 1996 Peter Wemm
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/kern/imgact_elf.c 146598 2005-05-24 22:21:44Z cognet $");
32__FBSDID("$FreeBSD: head/sys/kern/imgact_elf.c 147692 2005-06-30 07:49:22Z peter $");
33
33
34#include "opt_compat.h"
35
34#include <sys/param.h>
35#include <sys/exec.h>
36#include <sys/fcntl.h>
37#include <sys/imgact.h>
38#include <sys/imgact_elf.h>
39#include <sys/kernel.h>
40#include <sys/lock.h>
41#include <sys/malloc.h>

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

61#include <vm/pmap.h>
62#include <vm/vm_map.h>
63#include <vm/vm_object.h>
64#include <vm/vm_extern.h>
65
66#include <machine/elf.h>
67#include <machine/md_var.h>
68
36#include <sys/param.h>
37#include <sys/exec.h>
38#include <sys/fcntl.h>
39#include <sys/imgact.h>
40#include <sys/imgact_elf.h>
41#include <sys/kernel.h>
42#include <sys/lock.h>
43#include <sys/malloc.h>

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

63#include <vm/pmap.h>
64#include <vm/vm_map.h>
65#include <vm/vm_object.h>
66#include <vm/vm_extern.h>
67
68#include <machine/elf.h>
69#include <machine/md_var.h>
70
71#if defined(COMPAT_IA32) && __ELF_WORD_SIZE == 32
72#include <machine/fpu.h>
73#include <compat/ia32/ia32_reg.h>
74#endif
75
69#define OLD_EI_BRAND 8
70
71static int __elfN(check_header)(const Elf_Ehdr *hdr);
72static Elf_Brandinfo *__elfN(get_brandinfo)(const Elf_Ehdr *hdr,
73 const char *interp);
74static int __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
75 u_long *entry, size_t pagesize);
76static int __elfN(load_section)(struct proc *p,

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

1113 __elfN(puthdr)(td, hdr, &off, numsegs);
1114
1115 /* Write it to the core file. */
1116 return (vn_rdwr_inchunks(UIO_WRITE, vp, hdr, hdrsize, (off_t)0,
1117 UIO_SYSSPACE, IO_UNIT | IO_DIRECT, cred, NOCRED, NULL,
1118 td)); /* XXXKSE */
1119}
1120
76#define OLD_EI_BRAND 8
77
78static int __elfN(check_header)(const Elf_Ehdr *hdr);
79static Elf_Brandinfo *__elfN(get_brandinfo)(const Elf_Ehdr *hdr,
80 const char *interp);
81static int __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
82 u_long *entry, size_t pagesize);
83static int __elfN(load_section)(struct proc *p,

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

1120 __elfN(puthdr)(td, hdr, &off, numsegs);
1121
1122 /* Write it to the core file. */
1123 return (vn_rdwr_inchunks(UIO_WRITE, vp, hdr, hdrsize, (off_t)0,
1124 UIO_SYSSPACE, IO_UNIT | IO_DIRECT, cred, NOCRED, NULL,
1125 td)); /* XXXKSE */
1126}
1127
1128#if defined(COMPAT_IA32) && __ELF_WORD_SIZE == 32
1129typedef struct prstatus32 elf_prstatus_t;
1130typedef struct prpsinfo32 elf_prpsinfo_t;
1131typedef struct fpreg32 elf_prfpregset_t;
1132typedef struct fpreg32 elf_fpregset_t;
1133typedef struct reg32 elf_gregset_t;
1134#else
1135typedef prstatus_t elf_prstatus_t;
1136typedef prpsinfo_t elf_prpsinfo_t;
1137typedef prfpregset_t elf_prfpregset_t;
1138typedef prfpregset_t elf_fpregset_t;
1139typedef gregset_t elf_gregset_t;
1140#endif
1141
1121static void
1122__elfN(puthdr)(struct thread *td, void *dst, size_t *off, int numsegs)
1123{
1124 struct {
1142static void
1143__elfN(puthdr)(struct thread *td, void *dst, size_t *off, int numsegs)
1144{
1145 struct {
1125 prstatus_t status;
1126 prfpregset_t fpregset;
1127 prpsinfo_t psinfo;
1146 elf_prstatus_t status;
1147 elf_prfpregset_t fpregset;
1148 elf_prpsinfo_t psinfo;
1128 } *tempdata;
1149 } *tempdata;
1129 prstatus_t *status;
1130 prfpregset_t *fpregset;
1131 prpsinfo_t *psinfo;
1150 elf_prstatus_t *status;
1151 elf_prfpregset_t *fpregset;
1152 elf_prpsinfo_t *psinfo;
1132 struct proc *p;
1133 struct thread *thr;
1134 size_t ehoff, noteoff, notesz, phoff;
1135
1136 p = td->td_proc;
1137
1138 ehoff = *off;
1139 *off += sizeof(Elf_Ehdr);

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

1155 tempdata = NULL;
1156 status = NULL;
1157 fpregset = NULL;
1158 psinfo = NULL;
1159 }
1160
1161 if (dst != NULL) {
1162 psinfo->pr_version = PRPSINFO_VERSION;
1153 struct proc *p;
1154 struct thread *thr;
1155 size_t ehoff, noteoff, notesz, phoff;
1156
1157 p = td->td_proc;
1158
1159 ehoff = *off;
1160 *off += sizeof(Elf_Ehdr);

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

1176 tempdata = NULL;
1177 status = NULL;
1178 fpregset = NULL;
1179 psinfo = NULL;
1180 }
1181
1182 if (dst != NULL) {
1183 psinfo->pr_version = PRPSINFO_VERSION;
1163 psinfo->pr_psinfosz = sizeof(prpsinfo_t);
1184 psinfo->pr_psinfosz = sizeof(elf_prpsinfo_t);
1164 strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname));
1165 /*
1166 * XXX - We don't fill in the command line arguments properly
1167 * yet.
1168 */
1169 strlcpy(psinfo->pr_psargs, p->p_comm,
1170 sizeof(psinfo->pr_psargs));
1171 }

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

1177 * thread, we dump the state of the thread passed to us in td first.
1178 * This is the thread that causes the core dump and thus likely to
1179 * be the right thread one wants to have selected in the debugger.
1180 */
1181 thr = td;
1182 while (thr != NULL) {
1183 if (dst != NULL) {
1184 status->pr_version = PRSTATUS_VERSION;
1185 strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname));
1186 /*
1187 * XXX - We don't fill in the command line arguments properly
1188 * yet.
1189 */
1190 strlcpy(psinfo->pr_psargs, p->p_comm,
1191 sizeof(psinfo->pr_psargs));
1192 }

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

1198 * thread, we dump the state of the thread passed to us in td first.
1199 * This is the thread that causes the core dump and thus likely to
1200 * be the right thread one wants to have selected in the debugger.
1201 */
1202 thr = td;
1203 while (thr != NULL) {
1204 if (dst != NULL) {
1205 status->pr_version = PRSTATUS_VERSION;
1185 status->pr_statussz = sizeof(prstatus_t);
1186 status->pr_gregsetsz = sizeof(gregset_t);
1187 status->pr_fpregsetsz = sizeof(fpregset_t);
1206 status->pr_statussz = sizeof(elf_prstatus_t);
1207 status->pr_gregsetsz = sizeof(elf_gregset_t);
1208 status->pr_fpregsetsz = sizeof(elf_fpregset_t);
1188 status->pr_osreldate = osreldate;
1189 status->pr_cursig = p->p_sig;
1190 status->pr_pid = thr->td_tid;
1209 status->pr_osreldate = osreldate;
1210 status->pr_cursig = p->p_sig;
1211 status->pr_pid = thr->td_tid;
1212#if defined(COMPAT_IA32) && __ELF_WORD_SIZE == 32
1213 fill_regs32(thr, &status->pr_reg);
1214 fill_fpregs32(thr, fpregset);
1215#else
1191 fill_regs(thr, &status->pr_reg);
1192 fill_fpregs(thr, fpregset);
1216 fill_regs(thr, &status->pr_reg);
1217 fill_fpregs(thr, fpregset);
1218#endif
1193 }
1194 __elfN(putnote)(dst, off, "FreeBSD", NT_PRSTATUS, status,
1195 sizeof *status);
1196 __elfN(putnote)(dst, off, "FreeBSD", NT_FPREGSET, fpregset,
1197 sizeof *fpregset);
1198 /*
1199 * Allow for MD specific notes, as well as any MD
1200 * specific preparations for writing MI notes.

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

1230 ehdr->e_ident[EI_MAG3] = ELFMAG3;
1231 ehdr->e_ident[EI_CLASS] = ELF_CLASS;
1232 ehdr->e_ident[EI_DATA] = ELF_DATA;
1233 ehdr->e_ident[EI_VERSION] = EV_CURRENT;
1234 ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
1235 ehdr->e_ident[EI_ABIVERSION] = 0;
1236 ehdr->e_ident[EI_PAD] = 0;
1237 ehdr->e_type = ET_CORE;
1219 }
1220 __elfN(putnote)(dst, off, "FreeBSD", NT_PRSTATUS, status,
1221 sizeof *status);
1222 __elfN(putnote)(dst, off, "FreeBSD", NT_FPREGSET, fpregset,
1223 sizeof *fpregset);
1224 /*
1225 * Allow for MD specific notes, as well as any MD
1226 * specific preparations for writing MI notes.

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

1256 ehdr->e_ident[EI_MAG3] = ELFMAG3;
1257 ehdr->e_ident[EI_CLASS] = ELF_CLASS;
1258 ehdr->e_ident[EI_DATA] = ELF_DATA;
1259 ehdr->e_ident[EI_VERSION] = EV_CURRENT;
1260 ehdr->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
1261 ehdr->e_ident[EI_ABIVERSION] = 0;
1262 ehdr->e_ident[EI_PAD] = 0;
1263 ehdr->e_type = ET_CORE;
1264#if defined(COMPAT_IA32) && __ELF_WORD_SIZE == 32
1265 ehdr->e_machine = EM_386;
1266#else
1238 ehdr->e_machine = ELF_ARCH;
1267 ehdr->e_machine = ELF_ARCH;
1268#endif
1239 ehdr->e_version = EV_CURRENT;
1240 ehdr->e_entry = 0;
1241 ehdr->e_phoff = phoff;
1242 ehdr->e_flags = 0;
1243 ehdr->e_ehsize = sizeof(Elf_Ehdr);
1244 ehdr->e_phentsize = sizeof(Elf_Phdr);
1245 ehdr->e_phnum = numsegs + 1;
1246 ehdr->e_shentsize = sizeof(Elf_Shdr);

--- 54 unchanged lines hidden ---
1269 ehdr->e_version = EV_CURRENT;
1270 ehdr->e_entry = 0;
1271 ehdr->e_phoff = phoff;
1272 ehdr->e_flags = 0;
1273 ehdr->e_ehsize = sizeof(Elf_Ehdr);
1274 ehdr->e_phentsize = sizeof(Elf_Phdr);
1275 ehdr->e_phnum = numsegs + 1;
1276 ehdr->e_shentsize = sizeof(Elf_Shdr);

--- 54 unchanged lines hidden ---