Lines Matching +full:dynamic +full:- +full:range +full:- +full:compressor

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
5 * Copyright (c) 2000-2001, 2003 David O'Brien
6 * Copyright (c) 1995-1996 Søren Schmidt
38 #include <sys/compressor.h>
110 int __elfN(fallback_brand) = -1;
130 …__XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE)) ": support PT_GNU_STACK for non-executable stack control…
156 if (error != 0 || req->newptr == NULL) in sysctl_pie_base()
174 * Enable ASLR by default for 64-bit non-PIE binaries. 32-bit architectures
185 * Enable ASLR by default for 64-bit PIE binaries.
244 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in __elfN()
268 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in kfreebsd_trans_osrel()
297 return (-1); in __elfN()
314 return (-1); in __elfN()
326 if (p->p_sysent == entry->sysvec) { in __elfN()
340 const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
348 * We support four types of branding -- (1) the ELF EI_OSABI field in __elfN()
351 * field, and (4) the ".note.ABI-tag" ELF section. in __elfN()
354 /* Look for an ".note.ABI-tag" ELF section */ in __elfN()
360 if (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0) in __elfN()
362 if (hdr->e_machine == bi->machine && (bi->flags & in __elfN()
367 ret = __elfN(check_note)(imgp, bi->brand_note, osrel, in __elfN()
370 if (ret && bi->header_supported) { in __elfN()
371 ret = bi->header_supported(imgp, osrel, in __elfN()
385 (bi->interp_path == NULL || in __elfN()
386 (strlen(bi->interp_path) + 1 != interp_name_len || in __elfN()
387 strncmp(interp, bi->interp_path, interp_name_len) in __elfN()
402 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || in __elfN()
403 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) in __elfN()
405 if (hdr->e_machine == bi->machine && in __elfN()
406 (hdr->e_ident[EI_OSABI] == bi->brand || in __elfN()
407 (bi->compat_3_brand != NULL && in __elfN()
408 strcmp((const char *)&hdr->e_ident[OLD_EI_BRAND], in __elfN()
409 bi->compat_3_brand) == 0))) { in __elfN()
411 if (bi->header_supported == NULL || in __elfN()
412 bi->header_supported(imgp, NULL, NULL)) { in __elfN()
418 bi->interp_path == NULL) in __elfN()
420 if (bi->interp_path != NULL && in __elfN()
421 strlen(bi->interp_path) + 1 == in __elfN()
423 bi->interp_path, interp_name_len) == 0) in __elfN()
436 if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY || in __elfN()
437 bi->header_supported == NULL) in __elfN()
439 if (hdr->e_machine == bi->machine) { in __elfN()
440 ret = bi->header_supported(imgp, NULL, NULL); in __elfN()
450 if (bi == NULL || (bi->flags & in __elfN()
454 if (hdr->e_machine == bi->machine && in __elfN()
455 bi->interp_path != NULL && in __elfN()
457 strlen(bi->interp_path) + 1 == interp_name_len && in __elfN()
458 strncmp(interp, bi->interp_path, interp_name_len) in __elfN()
459 == 0 && (bi->header_supported == NULL || in __elfN()
460 bi->header_supported(imgp, NULL, NULL))) in __elfN()
468 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || in __elfN()
469 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) in __elfN()
471 if (hdr->e_machine == bi->machine && in __elfN()
472 __elfN(fallback_brand) == bi->brand && in __elfN()
473 (bi->header_supported == NULL || in __elfN()
474 bi->header_supported(imgp, NULL, NULL))) in __elfN()
483 return (hdr->e_phoff <= PAGE_SIZE && in __elfN()
484 (u_int)hdr->e_phentsize * hdr->e_phnum <= PAGE_SIZE - hdr->e_phoff); in __elfN()
494 hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS || in __elfN()
495 hdr->e_ident[EI_DATA] != ELF_TARG_DATA || in __elfN()
496 hdr->e_ident[EI_VERSION] != EV_CURRENT || in __elfN()
497 hdr->e_phentsize != sizeof(Elf_Phdr) || in __elfN()
498 hdr->e_version != ELF_TARG_VER) in __elfN()
507 if (bi != NULL && bi->machine == hdr->e_machine) in __elfN()
527 vm_map_fixed(map, NULL, 0, trunc_page(start), round_page(end) - in __elfN()
537 off = offset - trunc_page(offset); in __elfN()
539 end - start); in __elfN()
563 offset += round_page(start) - start; in __elfN()
568 trunc_page(end) - start, trunc_page(end), end, prot); in __elfN()
580 rv = vm_map_fixed(map, NULL, 0, start, end - start, in __elfN()
590 off = offset - trunc_page(offset); in __elfN()
591 sz = end - start; in __elfN()
592 if (sz > PAGE_SIZE - off) in __elfN()
593 sz = PAGE_SIZE - off; in __elfN()
603 rv = vm_map_fixed(map, object, offset, start, end - start, in __elfN()
607 locked = VOP_ISLOCKED(imgp->vp); in __elfN()
608 VOP_UNLOCK(imgp->vp); in __elfN()
610 vn_lock(imgp->vp, locked | LK_RETRY); in __elfN()
613 MPASS(imgp->vp->v_object == object); in __elfN()
614 VOP_SET_TEXT_CHECKED(imgp->vp); in __elfN()
642 if ((filsz != 0 && (off_t)filsz + offset > imgp->attr->va_size) || in __elfN()
648 object = imgp->object; in __elfN()
649 map = &imgp->proc->p_vmspace->vm_map; in __elfN()
662 map_len = trunc_page(offset + filsz) - file_addr; in __elfN()
664 map_len = round_page(offset + filsz) - file_addr; in __elfN()
687 copy_len = filsz == 0 ? 0 : (offset + filsz) - trunc_page(offset + in __elfN()
690 map_len = round_page((vm_offset_t)vmaddr + memsz) - map_addr; in __elfN()
733 ASSERT_VOP_LOCKED(imgp->vp, __func__); in __elfN()
738 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
805 nd = &tempdata->nd; in __elfN()
806 attr = &tempdata->attr; in __elfN()
807 imgp = &tempdata->image_params; in __elfN()
812 imgp->proc = p; in __elfN()
813 imgp->attr = attr; in __elfN()
818 nd->ni_vp = NULL; in __elfN()
822 imgp->vp = nd->ni_vp; in __elfN()
835 imgp->object = nd->ni_vp->v_object; in __elfN()
837 hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
840 if (hdr->e_type == ET_DYN) in __elfN()
842 else if (hdr->e_type == ET_EXEC) in __elfN()
855 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __elfN()
865 if (p->p_sysent->sv_protect != NULL) in __elfN()
866 p->p_sysent->sv_protect(imgp, SVP_INTERP); in __elfN()
869 *entry = (unsigned long)hdr->e_entry + rbase; in __elfN()
872 if (imgp->firstpage) in __elfN()
875 if (nd->ni_vp) { in __elfN()
876 if (imgp->textset) in __elfN()
877 VOP_UNSET_TEXT_CHECKED(nd->ni_vp); in __elfN()
878 vput(nd->ni_vp); in __elfN()
887 * maxv, with specified alignment. The [minv, maxv) range must belong
893 * did not pass sanity checks for overflow and range correctness.
909 res = roundup(minv, (u_long)align) + rbase % (maxv - minv); in __CONCAT()
910 res &= ~((u_long)align - 1); in __CONCAT()
912 res -= align; in __CONCAT()
938 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
942 seg_addr = trunc_page(phdr[i].p_vaddr + imgp->et_dyn_addr); in __elfN()
944 phdr[i].p_vaddr + imgp->et_dyn_addr - seg_addr); in __elfN()
976 PROC_LOCK(imgp->proc); in __elfN()
977 if (data_size > lim_cur_proc(imgp->proc, RLIMIT_DATA)) in __elfN()
981 else if (total_size > lim_cur_proc(imgp->proc, RLIMIT_VMEM)) in __elfN()
983 else if (racct_set(imgp->proc, RACCT_DATA, data_size) != 0) in __elfN()
985 else if (racct_set(imgp->proc, RACCT_VMEM, total_size) != 0) in __elfN()
987 PROC_UNLOCK(imgp->proc); in __elfN()
993 vmspace = imgp->proc->p_vmspace; in __elfN()
994 vmspace->vm_tsize = text_size >> PAGE_SHIFT; in __elfN()
995 vmspace->vm_taddr = (caddr_t)(uintptr_t)text_addr; in __elfN()
996 vmspace->vm_dsize = data_size >> PAGE_SHIFT; in __elfN()
997 vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr; in __elfN()
1010 KASSERT(phdr->p_type == PT_INTERP, in __elfN()
1011 ("%s: p_type %u != PT_INTERP", __func__, phdr->p_type)); in __elfN()
1012 ASSERT_VOP_LOCKED(imgp->vp, __func__); in __elfN()
1017 if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) { in __elfN()
1022 interp_name_len = phdr->p_filesz; in __elfN()
1023 if (phdr->p_offset > PAGE_SIZE || in __elfN()
1024 interp_name_len > PAGE_SIZE - phdr->p_offset) { in __elfN()
1029 * try non-sleepable allocation first, and if it in __elfN()
1036 VOP_UNLOCK(imgp->vp); in __elfN()
1038 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __elfN()
1041 error = vn_rdwr(UIO_READ, imgp->vp, interp, in __elfN()
1042 interp_name_len, phdr->p_offset, in __elfN()
1043 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, in __elfN()
1057 interp = __DECONST(char *, imgp->image_header) + phdr->p_offset; in __elfN()
1058 if (interp[interp_name_len - 1] != '\0') { in __elfN()
1074 if (brand_info->interp_newpath != NULL && in __elfN()
1075 (brand_info->interp_path == NULL || in __elfN()
1076 strcmp(interp, brand_info->interp_path) == 0)) { in __elfN()
1077 error = __elfN(load_file)(imgp->proc, in __elfN()
1078 brand_info->interp_newpath, addr, entry); in __elfN()
1083 error = __elfN(load_file)(imgp->proc, interp, addr, entry); in __elfN()
1116 hdr = (const Elf_Ehdr *)imgp->image_header; in __CONCAT()
1125 (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN)) in __CONCAT()
1126 return (-1); in __CONCAT()
1129 * From here on down, we return an errno, not -1, as we've in __CONCAT()
1137 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __CONCAT()
1160 for (i = MAXPAGESIZES - 1; i > 0; i--) { in __CONCAT()
1169 for (i = 0; i < hdr->e_phnum; i++) { in __CONCAT()
1197 hdr->e_phoff + hdr->e_phnum * hdr->e_phentsize <= in __CONCAT()
1199 proghdr = phdr[i].p_vaddr + hdr->e_phoff; in __CONCAT()
1215 imgp->stack_prot = in __CONCAT()
1217 if ((imgp->stack_prot & VM_PROT_RW) != in __CONCAT()
1224 imgp->stack_sz = phdr[i].p_memsz; in __CONCAT()
1235 hdr->e_ident[EI_OSABI]); in __CONCAT()
1239 sv = brand_info->sysvec; in __CONCAT()
1240 if (hdr->e_type == ET_DYN) { in __CONCAT()
1241 if ((brand_info->flags & BI_CAN_EXEC_DYN) == 0) { in __CONCAT()
1248 * non-zero for some reason. in __CONCAT()
1251 if ((sv->sv_flags & SV_ASLR) == 0 || in __CONCAT()
1253 imgp->et_dyn_addr = __elfN(pie_base); in __CONCAT()
1255 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) == 0) || in __CONCAT()
1256 (imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0) in __CONCAT()
1257 imgp->et_dyn_addr = ET_DYN_ADDR_RAND; in __CONCAT()
1259 imgp->et_dyn_addr = __elfN(pie_base); in __CONCAT()
1274 VOP_UNLOCK(imgp->vp); in __CONCAT()
1283 if (imgp->credential_setid) { in __CONCAT()
1284 PROC_LOCK(imgp->proc); in __CONCAT()
1285 imgp->proc->p_flag2 &= ~(P2_ASLR_ENABLE | P2_ASLR_DISABLE | in __CONCAT()
1287 PROC_UNLOCK(imgp->proc); in __CONCAT()
1289 if ((sv->sv_flags & SV_ASLR) == 0 || in __CONCAT()
1290 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) != 0 || in __CONCAT()
1292 KASSERT(imgp->et_dyn_addr != ET_DYN_ADDR_RAND, in __CONCAT()
1293 ("imgp->et_dyn_addr == RAND and !ASLR")); in __CONCAT()
1294 } else if ((imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0 || in __CONCAT()
1295 (__elfN(aslr_enabled) && hdr->e_type == ET_EXEC) || in __CONCAT()
1296 imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { in __CONCAT()
1297 imgp->map_flags |= MAP_ASLR; in __CONCAT()
1305 (imgp->proc->p_flag2 & P2_ASLR_IGNSTART) != 0) in __CONCAT()
1306 imgp->map_flags |= MAP_ASLR_IGNSTART; in __CONCAT()
1308 imgp->map_flags |= MAP_ASLR_STACK; in __CONCAT()
1310 imgp->imgp_flags |= IMGP_ASLR_SHARED_PAGE; in __CONCAT()
1314 (imgp->proc->p_flag2 & P2_WXORX_DISABLE) == 0) || in __CONCAT()
1315 (imgp->proc->p_flag2 & P2_WXORX_ENABLE_EXEC) != 0) in __CONCAT()
1316 imgp->map_flags |= MAP_WXORX; in __CONCAT()
1320 imgp->proc->p_sysent = sv; in __CONCAT()
1321 imgp->proc->p_elf_brandinfo = brand_info; in __CONCAT()
1323 vmspace = imgp->proc->p_vmspace; in __CONCAT()
1324 map = &vmspace->vm_map; in __CONCAT()
1325 maxv = sv->sv_usrstack; in __CONCAT()
1326 if ((imgp->map_flags & MAP_ASLR_STACK) == 0) in __CONCAT()
1327 maxv -= lim_max(td, RLIMIT_STACK); in __CONCAT()
1328 if (error == 0 && mapsz >= maxv - vm_map_min(map)) { in __CONCAT()
1333 if (error == 0 && imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { in __CONCAT()
1334 KASSERT((map->flags & MAP_ASLR) != 0, in __CONCAT()
1339 maxv / 2, maxalign, &imgp->et_dyn_addr); in __CONCAT()
1342 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1346 error = __elfN(load_sections)(imgp, hdr, phdr, imgp->et_dyn_addr, NULL); in __CONCAT()
1355 * We load the dynamic linker where a userland call in __CONCAT()
1360 addr = round_page((vm_offset_t)vmspace->vm_daddr + lim_max(td, in __CONCAT()
1362 if ((map->flags & MAP_ASLR) != 0) { in __CONCAT()
1373 map->anon_loc = anon_loc; in __CONCAT()
1375 map->anon_loc = addr; in __CONCAT()
1378 entry = (u_long)hdr->e_entry + imgp->et_dyn_addr; in __CONCAT()
1379 imgp->entry_addr = entry; in __CONCAT()
1381 if (sv->sv_protect != NULL) in __CONCAT()
1382 sv->sv_protect(imgp, SVP_IMAGE); in __CONCAT()
1385 VOP_UNLOCK(imgp->vp); in __CONCAT()
1386 if ((map->flags & MAP_ASLR) != 0) { in __CONCAT()
1394 &addr, &imgp->entry_addr); in __CONCAT()
1396 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1400 addr = imgp->et_dyn_addr; in __CONCAT()
1411 VOP_UNLOCK(imgp->vp); in __CONCAT()
1413 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1415 elf_auxargs->execfd = -1; in __CONCAT()
1416 elf_auxargs->phdr = proghdr + imgp->et_dyn_addr; in __CONCAT()
1417 elf_auxargs->phent = hdr->e_phentsize; in __CONCAT()
1418 elf_auxargs->phnum = hdr->e_phnum; in __CONCAT()
1419 elf_auxargs->pagesz = PAGE_SIZE; in __CONCAT()
1420 elf_auxargs->base = addr; in __CONCAT()
1421 elf_auxargs->flags = 0; in __CONCAT()
1422 elf_auxargs->entry = entry; in __CONCAT()
1423 elf_auxargs->hdr_eflags = hdr->e_flags; in __CONCAT()
1425 imgp->auxargs = elf_auxargs; in __CONCAT()
1426 imgp->interpreted = 0; in __CONCAT()
1427 imgp->reloc_base = addr; in __CONCAT()
1428 imgp->proc->p_osrel = osrel; in __CONCAT()
1429 imgp->proc->p_fctl0 = fctl0; in __CONCAT()
1430 imgp->proc->p_elf_flags = hdr->e_flags; in __CONCAT()
1433 ASSERT_VOP_LOCKED(imgp->vp, "skipped relock"); in __CONCAT()
1444 Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs; in __elfN()
1454 vmspace = imgp->proc->p_vmspace; in __elfN()
1456 if (args->execfd != -1) in __elfN()
1457 AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd); in __elfN()
1458 AUXARGS_ENTRY(pos, AT_PHDR, args->phdr); in __elfN()
1459 AUXARGS_ENTRY(pos, AT_PHENT, args->phent); in __elfN()
1460 AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum); in __elfN()
1461 AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz); in __elfN()
1462 AUXARGS_ENTRY(pos, AT_FLAGS, args->flags); in __elfN()
1463 AUXARGS_ENTRY(pos, AT_ENTRY, args->entry); in __elfN()
1464 AUXARGS_ENTRY(pos, AT_BASE, args->base); in __elfN()
1465 AUXARGS_ENTRY(pos, AT_EHDRFLAGS, args->hdr_eflags); in __elfN()
1466 if (imgp->execpathp != 0) in __elfN()
1467 AUXARGS_ENTRY_PTR(pos, AT_EXECPATH, imgp->execpathp); in __elfN()
1469 imgp->proc->p_ucred->cr_prison->pr_osreldate); in __elfN()
1470 if (imgp->canary != 0) { in __elfN()
1471 AUXARGS_ENTRY_PTR(pos, AT_CANARY, imgp->canary); in __elfN()
1472 AUXARGS_ENTRY(pos, AT_CANARYLEN, imgp->canarylen); in __elfN()
1475 if (imgp->pagesizes != 0) { in __elfN()
1476 AUXARGS_ENTRY_PTR(pos, AT_PAGESIZES, imgp->pagesizes); in __elfN()
1477 AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen); in __elfN()
1479 if ((imgp->sysent->sv_flags & SV_TIMEKEEP) != 0) { in __elfN()
1481 vmspace->vm_shp_base + imgp->sysent->sv_timekeep_offset); in __elfN()
1483 AUXARGS_ENTRY(pos, AT_STACKPROT, imgp->sysent->sv_shared_page_obj in __elfN()
1484 != NULL && imgp->stack_prot != 0 ? imgp->stack_prot : in __elfN()
1485 imgp->sysent->sv_stackprot); in __elfN()
1486 if (imgp->sysent->sv_hwcap != NULL) in __elfN()
1487 AUXARGS_ENTRY(pos, AT_HWCAP, *imgp->sysent->sv_hwcap); in __elfN()
1488 if (imgp->sysent->sv_hwcap2 != NULL) in __elfN()
1489 AUXARGS_ENTRY(pos, AT_HWCAP2, *imgp->sysent->sv_hwcap2); in __elfN()
1490 if (imgp->sysent->sv_hwcap3 != NULL) in __elfN()
1491 AUXARGS_ENTRY(pos, AT_HWCAP3, *imgp->sysent->sv_hwcap3); in __elfN()
1492 if (imgp->sysent->sv_hwcap4 != NULL) in __elfN()
1493 AUXARGS_ENTRY(pos, AT_HWCAP4, *imgp->sysent->sv_hwcap4); in __elfN()
1500 AUXARGS_ENTRY(pos, AT_ARGC, imgp->args->argc); in __elfN()
1501 AUXARGS_ENTRY_PTR(pos, AT_ARGV, imgp->argv); in __elfN()
1502 AUXARGS_ENTRY(pos, AT_ENVC, imgp->args->envc); in __elfN()
1503 AUXARGS_ENTRY_PTR(pos, AT_ENVV, imgp->envv); in __elfN()
1504 AUXARGS_ENTRY_PTR(pos, AT_PS_STRINGS, imgp->ps_strings); in __elfN()
1506 if ((imgp->sysent->sv_flags & SV_RNG_SEED_VER) != 0) { in __elfN()
1508 vmspace->vm_shp_base + imgp->sysent->sv_fxrng_gen_offset); in __elfN()
1511 if ((imgp->sysent->sv_flags & SV_DSO_SIG) != 0 && __elfN(vdso) != 0) { in __elfN()
1513 vmspace->vm_shp_base + imgp->sysent->sv_vdso_offset); in __elfN()
1515 AUXARGS_ENTRY(pos, AT_USRSTACKBASE, round_page(vmspace->vm_stacktop)); in __elfN()
1516 stacksz = imgp->proc->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur; in __elfN()
1520 free(imgp->auxargs, M_TEMP); in __elfN()
1521 imgp->auxargs = NULL; in __elfN()
1522 KASSERT(pos - argarray <= AT_COUNT, ("Too many auxargs")); in __elfN()
1535 base--; in __elfN()
1536 if (elf_suword(base, imgp->args->argc) == -1) in __elfN()
1600 struct ucred *cred = td->td_ucred; in __elfN()
1622 td->td_proc->p_sysent->sv_elf_core_prepare_notes(td, &notelst, &notesz); in __elfN()
1635 PROC_LOCK(td->td_proc); in __elfN()
1636 error = racct_add(td->td_proc, RACCT_CORE, coresize); in __elfN()
1637 PROC_UNLOCK(td->td_proc); in __elfN()
1682 error = core_output((char *)(uintptr_t)php->p_vaddr, in __elfN()
1683 php->p_filesz, offset, &params, tmpbuf); in __elfN()
1686 offset += php->p_filesz; in __elfN()
1695 curproc->p_comm, error); in __elfN()
1720 Elf_Phdr *phdr = phc->phdr; in cb_put_phdr()
1722 phc->offset = round_page(phc->offset); in cb_put_phdr()
1724 phdr->p_type = PT_LOAD; in cb_put_phdr()
1725 phdr->p_offset = phc->offset; in cb_put_phdr()
1726 phdr->p_vaddr = entry->start; in cb_put_phdr()
1727 phdr->p_paddr = 0; in cb_put_phdr()
1728 phdr->p_filesz = phdr->p_memsz = entry->end - entry->start; in cb_put_phdr()
1729 phdr->p_align = PAGE_SIZE; in cb_put_phdr()
1730 phdr->p_flags = __elfN(untrans_prot)(entry->protection); in cb_put_phdr()
1732 phc->offset += phdr->p_filesz; in cb_put_phdr()
1733 phc->phdr++; in cb_put_phdr()
1745 ssc->count++; in cb_size_segment()
1746 ssc->size += entry->end - entry->start; in cb_size_segment()
1753 seginfo->count = 0; in __elfN()
1754 seginfo->size = 0; in __elfN()
1762 * caller-supplied data.
1768 struct proc *p = td->td_proc; in each_dumpable_segment()
1769 vm_map_t map = &p->p_vmspace->vm_map; in each_dumpable_segment()
1780 * Note that read-only segments related to the elf binary in each_dumpable_segment()
1786 if ((entry->protection & VM_PROT_RW) != in each_dumpable_segment()
1790 if ((entry->protection & VM_PROT_ALL) == 0) in each_dumpable_segment()
1801 if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) in each_dumpable_segment()
1803 if ((entry->eflags & MAP_ENTRY_NOCOREDUMP) != 0 && in each_dumpable_segment()
1806 if ((object = entry->object.vm_object) == NULL) in each_dumpable_segment()
1809 /* Ignore memory-mapped devices and such things. */ in each_dumpable_segment()
1811 while ((backing_object = object->backing_object) != NULL) { in each_dumpable_segment()
1816 ignore_entry = (object->flags & OBJ_FICTITIOUS) != 0; in each_dumpable_segment()
1841 __elfN(puthdr)(p->td, hdr, hdrsize, numsegs, notesz, flags); in __elfN()
1848 __elfN(putnote)(p->td, ninfo, sb); in __elfN()
1850 sbuf_end_section(sb, -1, PAGE_SIZE, 0); in __elfN()
1865 p = td->td_proc; in __elfN()
1880 size += __elfN(register_note)(td, list, -1, in __elfN()
1883 thr = thr == td ? TAILQ_FIRST(&p->p_threads) : in __elfN()
1924 bi = td->td_proc->p_elf_brandinfo; in __elfN()
1926 ehdr->e_ident[EI_MAG0] = ELFMAG0; in __elfN()
1927 ehdr->e_ident[EI_MAG1] = ELFMAG1; in __elfN()
1928 ehdr->e_ident[EI_MAG2] = ELFMAG2; in __elfN()
1929 ehdr->e_ident[EI_MAG3] = ELFMAG3; in __elfN()
1930 ehdr->e_ident[EI_CLASS] = ELF_CLASS; in __elfN()
1931 ehdr->e_ident[EI_DATA] = ELF_DATA; in __elfN()
1932 ehdr->e_ident[EI_VERSION] = EV_CURRENT; in __elfN()
1933 ehdr->e_ident[EI_OSABI] = td->td_proc->p_sysent->sv_elf_core_osabi; in __elfN()
1934 ehdr->e_ident[EI_ABIVERSION] = 0; in __elfN()
1935 ehdr->e_ident[EI_PAD] = 0; in __elfN()
1936 ehdr->e_type = ET_CORE; in __elfN()
1937 ehdr->e_machine = bi->machine; in __elfN()
1938 ehdr->e_version = EV_CURRENT; in __elfN()
1939 ehdr->e_entry = 0; in __elfN()
1940 ehdr->e_phoff = sizeof(Elf_Ehdr); in __elfN()
1941 ehdr->e_flags = td->td_proc->p_elf_flags; in __elfN()
1942 ehdr->e_ehsize = sizeof(Elf_Ehdr); in __elfN()
1943 ehdr->e_phentsize = sizeof(Elf_Phdr); in __elfN()
1944 ehdr->e_shentsize = sizeof(Elf_Shdr); in __elfN()
1945 ehdr->e_shstrndx = SHN_UNDEF; in __elfN()
1947 ehdr->e_phnum = numsegs + 1; in __elfN()
1948 ehdr->e_shnum = 0; in __elfN()
1950 ehdr->e_phnum = PN_XNUM; in __elfN()
1951 ehdr->e_shnum = 1; in __elfN()
1953 ehdr->e_shoff = ehdr->e_phoff + in __elfN()
1954 (numsegs + 1) * ehdr->e_phentsize; in __elfN()
1955 KASSERT(ehdr->e_shoff == hdrsize - sizeof(Elf_Shdr), in __elfN()
1956 ("e_shoff: %zu, hdrsize - shdr: %zu", in __elfN()
1957 (size_t)ehdr->e_shoff, hdrsize - sizeof(Elf_Shdr))); in __elfN()
1959 shdr = (Elf_Shdr *)((char *)hdr + ehdr->e_shoff); in __elfN()
1967 * See table 7-7 of the Solaris "Linker and Libraries Guide" in __elfN()
1968 * (or 12-7 depending on the version of the document) for more in __elfN()
1971 shdr->sh_type = SHT_NULL; in __elfN()
1972 shdr->sh_size = ehdr->e_shnum; in __elfN()
1973 shdr->sh_link = ehdr->e_shstrndx; in __elfN()
1974 shdr->sh_info = numsegs + 1; in __elfN()
1980 phdr = (Elf_Phdr *)((char *)hdr + ehdr->e_phoff); in __elfN()
1983 phdr->p_type = PT_NOTE; in __elfN()
1984 phdr->p_offset = hdrsize; in __elfN()
1985 phdr->p_vaddr = 0; in __elfN()
1986 phdr->p_paddr = 0; in __elfN()
1987 phdr->p_filesz = notesz; in __elfN()
1988 phdr->p_memsz = 0; in __elfN()
1989 phdr->p_flags = PF_R; in __elfN()
1990 phdr->p_align = ELF_NOTE_ROUNDSIZE; in __elfN()
2008 if (!regset->get(regset, target_td, NULL, &size) || size == 0) in __elfN()
2012 ninfo->type = regset->note; in __elfN()
2013 ninfo->regset = regset; in __elfN()
2014 ninfo->outarg = target_td; in __elfN()
2015 ninfo->outsize = size; in __elfN()
2018 sv = td->td_proc->p_sysent; in __elfN()
2020 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + in __elfN()
2035 sv = td->td_proc->p_sysent; in __elfN()
2039 ninfo->type = type; in __elfN()
2040 ninfo->outfunc = out; in __elfN()
2041 ninfo->outarg = arg; in __elfN()
2042 ninfo->outsize = size; in __elfN()
2045 if (type == -1) in __elfN()
2049 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + in __elfN()
2064 bzero((char *)dst + len, padded_len - len); in append_note_data()
2079 note->n_namesz = sizeof(FREEBSD_ABI_VENDOR); in __elfN()
2080 note->n_descsz = size; in __elfN()
2081 note->n_type = type; in __elfN()
2106 if (ninfo->type == -1) { in __elfN()
2107 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); in __elfN()
2111 sv = td->td_proc->p_sysent; in __elfN()
2113 note.n_namesz = strlen(sv->sv_elf_core_abi_vendor) + 1; in __elfN()
2114 note.n_descsz = ninfo->outsize; in __elfN()
2115 note.n_type = ninfo->type; in __elfN()
2119 sbuf_bcat(sb, sv->sv_elf_core_abi_vendor, in __elfN()
2120 strlen(sv->sv_elf_core_abi_vendor) + 1); in __elfN()
2125 if (ninfo->regset != NULL) { in __elfN()
2126 struct regset *regset = ninfo->regset; in __elfN()
2129 buf = malloc(ninfo->outsize, M_TEMP, M_ZERO | M_WAITOK); in __elfN()
2130 (void)regset->get(regset, ninfo->outarg, buf, &ninfo->outsize); in __elfN()
2131 sbuf_bcat(sb, buf, ninfo->outsize); in __elfN()
2134 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); in __elfN()
2145 * themselves, padding in a format-specific way if needed. in __elfN()
2148 for (i = 0; i < descsz - new_len; i++) in __elfN()
2152 * We can't always truncate sb -- we may have drained some in __elfN()
2209 psinfo->pr_version = PRPSINFO_VERSION; in __elfN()
2210 psinfo->pr_psinfosz = sizeof(elf_prpsinfo_t); in __elfN()
2211 strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname)); in __elfN()
2213 if (p->p_args != NULL) { in __elfN()
2214 len = sizeof(psinfo->pr_psargs) - 1; in __elfN()
2215 if (len > p->p_args->ar_length) in __elfN()
2216 len = p->p_args->ar_length; in __elfN()
2217 memcpy(psinfo->pr_psargs, p->p_args->ar_args, len); in __elfN()
2223 sbuf_new(&sbarg, psinfo->pr_psargs, in __elfN()
2224 sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN); in __elfN()
2230 len--; in __elfN()
2232 len = sizeof(psinfo->pr_psargs) - 1; in __elfN()
2236 if (error != 0 || len == 0 || (ssize_t)len == -1) in __elfN()
2237 strlcpy(psinfo->pr_psargs, p->p_comm, in __elfN()
2238 sizeof(psinfo->pr_psargs)); in __elfN()
2240 KASSERT(len < sizeof(psinfo->pr_psargs), in __elfN()
2242 sizeof(psinfo->pr_psargs))); in __elfN()
2243 cp = psinfo->pr_psargs; in __elfN()
2244 end = cp + len - 1; in __elfN()
2246 cp = memchr(cp, '\0', end - cp); in __elfN()
2252 psinfo->pr_pid = p->p_pid; in __elfN()
2270 status->pr_version = PRSTATUS_VERSION; in __elfN()
2271 status->pr_statussz = sizeof(elf_prstatus_t); in __elfN()
2272 status->pr_gregsetsz = sizeof(elf_gregset_t); in __elfN()
2273 status->pr_fpregsetsz = sizeof(elf_fpregset_t); in __elfN()
2274 status->pr_osreldate = osreldate; in __elfN()
2275 status->pr_cursig = td->td_proc->p_sig; in __elfN()
2276 status->pr_pid = td->td_tid; in __elfN()
2278 fill_regs32(td, &status->pr_reg); in __elfN()
2280 fill_regs(td, &status->pr_reg); in __elfN()
2296 set_regs32(td, &status->pr_reg); in __elfN()
2298 set_regs(td, &status->pr_reg); in __elfN()
2366 strcpy(thrmisc->pr_tname, td->td_name); in __elfN()
2393 pl.pl_lwpid = td->td_tid; in __elfN()
2395 pl.pl_sigmask = td->td_sigmask; in __elfN()
2396 pl.pl_siglist = td->td_siglist; in __elfN()
2397 if (td->td_si.si_signo != 0) { in __elfN()
2401 siginfo_to_siginfo32(&td->td_si, &pl.pl_siginfo); in __elfN()
2403 pl.pl_siginfo = td->td_si; in __elfN()
2406 strcpy(pl.pl_tdname, td->td_name); in __elfN()
2425 struct sysentvec *sv = td->td_proc->p_sysent; in __elfN()
2438 regsetp = sv->sv_regset_begin; in __elfN()
2445 regset_end = sv->sv_regset_end; in __elfN()
2449 if (regset->note == NT_PRSTATUS) in __elfN()
2495 size = sizeof(structsize) + p->p_numthreads * in __elfN()
2535 kern_proc_filedesc_out(p, sb, -1, filedesc_flags); in note_procstat_files()
2544 kern_proc_filedesc_out(p, sb, *sizep - sizeof(structsize), in note_procstat_files()
2554 "requested %zu, got %zu", *sizep - sizeof(structsize), in note_procstat_files()
2555 sect_sz - sizeof(structsize))); in note_procstat_files()
2557 for (i = 0; i < *sizep - sect_sz && sb->s_error == 0; i++) in note_procstat_files()
2586 kern_proc_vmmap_out(p, sb, -1, vmmap_flags); in note_procstat_vmmap()
2593 kern_proc_vmmap_out(p, sb, *sizep - sizeof(structsize), in note_procstat_vmmap()
2606 size = sizeof(structsize) + p->p_ucred->cr_ngroups * sizeof(gid_t); in note_procstat_groups()
2611 sbuf_bcat(sb, p->p_ucred->cr_groups, p->p_ucred->cr_ngroups * in note_procstat_groups()
2625 size = sizeof(structsize) + sizeof(p->p_pd->pd_cmask); in note_procstat_umask()
2628 structsize = sizeof(p->p_pd->pd_cmask); in note_procstat_umask()
2630 sbuf_bcat(sb, &p->p_pd->pd_cmask, sizeof(p->p_pd->pd_cmask)); in note_procstat_umask()
2666 size = sizeof(structsize) + sizeof(p->p_osrel); in note_procstat_osrel()
2669 structsize = sizeof(p->p_osrel); in note_procstat_osrel()
2671 sbuf_bcat(sb, &p->p_osrel, sizeof(p->p_osrel)); in note_procstat_osrel()
2751 kern_proc_kqueues_out(p, sb, -1, compat32); in __elfN()
2759 kern_proc_kqueues_out(p, sb, *sizep - sizeof(structsize), in __elfN()
2769 "requested %zu, got %zu", *sizep - sizeof(structsize), in __elfN()
2770 sect_sz - sizeof(structsize))); in __elfN()
2772 for (i = 0; i < *sizep - sect_sz && sb->s_error == 0; i++) in __elfN()
2790 if (pnote == NULL || pnote->p_filesz > PAGE_SIZE) in __elfN()
2792 ASSERT_VOP_LOCKED(imgp->vp, "parse_notes"); in __elfN()
2793 if (pnote->p_offset > PAGE_SIZE || in __elfN()
2794 pnote->p_filesz > PAGE_SIZE - pnote->p_offset) { in __elfN()
2795 buf = malloc(pnote->p_filesz, M_TEMP, M_NOWAIT); in __elfN()
2797 VOP_UNLOCK(imgp->vp); in __elfN()
2798 buf = malloc(pnote->p_filesz, M_TEMP, M_WAITOK); in __elfN()
2799 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __elfN()
2801 error = vn_rdwr(UIO_READ, imgp->vp, buf, pnote->p_filesz, in __elfN()
2802 pnote->p_offset, UIO_SYSSPACE, IO_NODELOCKED, in __elfN()
2803 curthread->td_ucred, NOCRED, NULL, curthread); in __elfN()
2809 note_end = (const Elf_Note *)(buf + pnote->p_filesz); in __elfN()
2811 note = note0 = (const Elf_Note *)(imgp->image_header + in __elfN()
2812 pnote->p_offset); in __elfN()
2813 note_end = (const Elf_Note *)(imgp->image_header + in __elfN()
2814 pnote->p_offset + pnote->p_filesz); in __elfN()
2823 if ((const char *)note_end - (const char *)note < in __elfN()
2828 if (note->n_namesz != checknote->n_namesz || in __elfN()
2829 note->n_descsz != checknote->n_descsz || in __elfN()
2830 note->n_type != checknote->n_type) in __elfN()
2833 if (note_name + checknote->n_namesz >= in __elfN()
2835 note_name, checknote->n_namesz) != 0) in __elfN()
2842 roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + in __elfN()
2843 roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE)); in __elfN()
2867 * Fetch the osreldate for binary from the ELF OSABI-note if in brandnote_cb()
2870 *res = (arg->brandnote->flags & BN_TRANSLATE_OSREL) != 0 && in brandnote_cb()
2871 arg->brandnote->trans_osrel != NULL ? in brandnote_cb()
2872 arg->brandnote->trans_osrel(note, arg->osrel) : true; in brandnote_cb()
2897 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in note_fctl_cb()
2899 *arg->has_fctl0 = true; in note_fctl_cb()
2900 *arg->fctl0 = desc[0]; in note_fctl_cb()
2906 * Try to find the appropriate ABI-note section for checknote, fetch
2908 * OSABI-note. Only the first page of the image is searched, the same
2921 hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
2922 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __elfN()
2928 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
2930 &brandnote->hdr, brandnote->vendor, &phdr[i], brandnote_cb, in __elfN()
2932 for (j = 0; j < hdr->e_phnum; j++) { in __elfN()