Lines Matching +full:vs +full:- +full:p +full:- +full:supply
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
97 static int __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
119 int __elfN(fallback_brand) = -1;
139 ELF_ABI_NAME ": support PT_GNU_STACK for non-executable stack control");
165 if (error != 0 || req->newptr == NULL) in sysctl_pie_base()
183 * Enable ASLR by default for 64-bit non-PIE binaries. 32-bit architectures
193 * Enable ASLR by default for 64-bit PIE binaries.
246 uintptr_t p; in __elfN() local
248 p = (uintptr_t)(note + 1); in __elfN()
249 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in __elfN()
250 *osrel = *(const int32_t *)(p); in __elfN()
270 uintptr_t p; in kfreebsd_trans_osrel() local
272 p = (uintptr_t)(note + 1); in kfreebsd_trans_osrel()
273 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in kfreebsd_trans_osrel()
275 desc = (const Elf32_Word *)p; in kfreebsd_trans_osrel()
300 printf("WARNING: %s: could not insert brandinfo entry: %p\n", in __elfN()
302 return (-1); in __elfN()
319 return (-1); in __elfN()
326 struct proc *p; in __elfN() local
330 FOREACH_PROC_IN_SYSTEM(p) { in __elfN()
331 if (p->p_sysent == entry->sysvec) { in __elfN()
345 const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
353 * We support four types of branding -- (1) the ELF EI_OSABI field in __elfN()
356 * field, and (4) the ".note.ABI-tag" ELF section. in __elfN()
359 /* Look for an ".note.ABI-tag" ELF section */ in __elfN()
365 if (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0) in __elfN()
367 if (hdr->e_machine == bi->machine && (bi->flags & in __elfN()
372 ret = __elfN(check_note)(imgp, bi->brand_note, osrel, in __elfN()
375 if (ret && bi->header_supported) { in __elfN()
376 ret = bi->header_supported(imgp, osrel, in __elfN()
390 (bi->interp_path == NULL || in __elfN()
391 (strlen(bi->interp_path) + 1 != interp_name_len || in __elfN()
392 strncmp(interp, bi->interp_path, interp_name_len) in __elfN()
407 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || in __elfN()
408 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) in __elfN()
410 if (hdr->e_machine == bi->machine && in __elfN()
411 (hdr->e_ident[EI_OSABI] == bi->brand || in __elfN()
412 (bi->compat_3_brand != NULL && in __elfN()
413 strcmp((const char *)&hdr->e_ident[OLD_EI_BRAND], in __elfN()
414 bi->compat_3_brand) == 0))) { in __elfN()
416 if (bi->header_supported == NULL || in __elfN()
417 bi->header_supported(imgp, NULL, NULL)) { in __elfN()
423 bi->interp_path == NULL) in __elfN()
425 if (bi->interp_path != NULL && in __elfN()
426 strlen(bi->interp_path) + 1 == in __elfN()
428 bi->interp_path, interp_name_len) == 0) in __elfN()
441 if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY || in __elfN()
442 bi->header_supported == NULL) in __elfN()
444 if (hdr->e_machine == bi->machine) { in __elfN()
445 ret = bi->header_supported(imgp, NULL, NULL); in __elfN()
455 if (bi == NULL || (bi->flags & in __elfN()
459 if (hdr->e_machine == bi->machine && in __elfN()
460 bi->interp_path != NULL && in __elfN()
462 strlen(bi->interp_path) + 1 == interp_name_len && in __elfN()
463 strncmp(interp, bi->interp_path, interp_name_len) in __elfN()
464 == 0 && (bi->header_supported == NULL || in __elfN()
465 bi->header_supported(imgp, NULL, NULL))) in __elfN()
473 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || in __elfN()
474 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) in __elfN()
476 if (hdr->e_machine == bi->machine && in __elfN()
477 __elfN(fallback_brand) == bi->brand && in __elfN()
478 (bi->header_supported == NULL || in __elfN()
479 bi->header_supported(imgp, NULL, NULL))) in __elfN()
488 return (hdr->e_phoff <= PAGE_SIZE && in __elfN()
489 (u_int)hdr->e_phentsize * hdr->e_phnum <= PAGE_SIZE - hdr->e_phoff); in __elfN()
499 hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS || in __elfN()
500 hdr->e_ident[EI_DATA] != ELF_TARG_DATA || in __elfN()
501 hdr->e_ident[EI_VERSION] != EV_CURRENT || in __elfN()
502 hdr->e_phentsize != sizeof(Elf_Phdr) || in __elfN()
503 hdr->e_version != ELF_TARG_VER) in __elfN()
512 if (bi != NULL && bi->machine == hdr->e_machine) in __elfN()
532 vm_map_fixed(map, NULL, 0, trunc_page(start), round_page(end) - in __elfN()
542 off = offset - trunc_page(offset); in __elfN()
544 end - start); in __elfN()
568 offset += round_page(start) - start; in __elfN()
573 trunc_page(end) - start, trunc_page(end), end, prot); in __elfN()
585 rv = vm_map_fixed(map, NULL, 0, start, end - start, in __elfN()
595 off = offset - trunc_page(offset); in __elfN()
596 sz = end - start; in __elfN()
597 if (sz > PAGE_SIZE - off) in __elfN()
598 sz = PAGE_SIZE - off; in __elfN()
608 rv = vm_map_fixed(map, object, offset, start, end - start, in __elfN()
612 locked = VOP_ISLOCKED(imgp->vp); in __elfN()
613 VOP_UNLOCK(imgp->vp); in __elfN()
615 vn_lock(imgp->vp, locked | LK_RETRY); in __elfN()
618 MPASS(imgp->vp->v_object == object); in __elfN()
619 VOP_SET_TEXT_CHECKED(imgp->vp); in __elfN()
647 if ((filsz != 0 && (off_t)filsz + offset > imgp->attr->va_size) || in __elfN()
653 object = imgp->object; in __elfN()
654 map = &imgp->proc->p_vmspace->vm_map; in __elfN()
667 map_len = trunc_page(offset + filsz) - file_addr; in __elfN()
669 map_len = round_page(offset + filsz) - file_addr; in __elfN()
692 copy_len = filsz == 0 ? 0 : (offset + filsz) - trunc_page(offset + in __elfN()
695 map_len = round_page((vm_offset_t)vmaddr + memsz) - map_addr; in __elfN()
738 ASSERT_VOP_LOCKED(imgp->vp, __func__); in __elfN()
743 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
783 __elfN(load_file)(struct proc *p, const char *file, u_long *addr, in __elfN()
810 nd = &tempdata->nd; in __elfN()
811 attr = &tempdata->attr; in __elfN()
812 imgp = &tempdata->image_params; in __elfN()
817 imgp->proc = p; in __elfN()
818 imgp->attr = attr; in __elfN()
823 nd->ni_vp = NULL; in __elfN()
827 imgp->vp = nd->ni_vp; in __elfN()
840 imgp->object = nd->ni_vp->v_object; in __elfN()
842 hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
845 if (hdr->e_type == ET_DYN) in __elfN()
847 else if (hdr->e_type == ET_EXEC) in __elfN()
860 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __elfN()
870 if (p->p_sysent->sv_protect != NULL) in __elfN()
871 p->p_sysent->sv_protect(imgp, SVP_INTERP); in __elfN()
874 *entry = (unsigned long)hdr->e_entry + rbase; in __elfN()
877 if (imgp->firstpage) in __elfN()
880 if (nd->ni_vp) { in __elfN()
881 if (imgp->textset) in __elfN()
882 VOP_UNSET_TEXT_CHECKED(nd->ni_vp); in __elfN()
883 vput(nd->ni_vp); in __elfN()
914 res = roundup(minv, (u_long)align) + rbase % (maxv - minv); in __CONCAT()
915 res &= ~((u_long)align - 1); in __CONCAT()
917 res -= align; in __CONCAT()
943 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
947 seg_addr = trunc_page(phdr[i].p_vaddr + imgp->et_dyn_addr); in __elfN()
949 phdr[i].p_vaddr + imgp->et_dyn_addr - seg_addr); in __elfN()
981 PROC_LOCK(imgp->proc); in __elfN()
982 if (data_size > lim_cur_proc(imgp->proc, RLIMIT_DATA)) in __elfN()
986 else if (total_size > lim_cur_proc(imgp->proc, RLIMIT_VMEM)) in __elfN()
988 else if (racct_set(imgp->proc, RACCT_DATA, data_size) != 0) in __elfN()
990 else if (racct_set(imgp->proc, RACCT_VMEM, total_size) != 0) in __elfN()
992 PROC_UNLOCK(imgp->proc); in __elfN()
998 vmspace = imgp->proc->p_vmspace; in __elfN()
999 vmspace->vm_tsize = text_size >> PAGE_SHIFT; in __elfN()
1000 vmspace->vm_taddr = (caddr_t)(uintptr_t)text_addr; in __elfN()
1001 vmspace->vm_dsize = data_size >> PAGE_SHIFT; in __elfN()
1002 vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr; in __elfN()
1015 KASSERT(phdr->p_type == PT_INTERP, in __elfN()
1016 ("%s: p_type %u != PT_INTERP", __func__, phdr->p_type)); in __elfN()
1017 ASSERT_VOP_LOCKED(imgp->vp, __func__); in __elfN()
1022 if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) { in __elfN()
1027 interp_name_len = phdr->p_filesz; in __elfN()
1028 if (phdr->p_offset > PAGE_SIZE || in __elfN()
1029 interp_name_len > PAGE_SIZE - phdr->p_offset) { in __elfN()
1034 * try non-sleepable allocation first, and if it in __elfN()
1041 VOP_UNLOCK(imgp->vp); in __elfN()
1043 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __elfN()
1046 error = vn_rdwr(UIO_READ, imgp->vp, interp, in __elfN()
1047 interp_name_len, phdr->p_offset, in __elfN()
1048 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, in __elfN()
1062 interp = __DECONST(char *, imgp->image_header) + phdr->p_offset; in __elfN()
1063 if (interp[interp_name_len - 1] != '\0') { in __elfN()
1079 if (brand_info->interp_newpath != NULL && in __elfN()
1080 (brand_info->interp_path == NULL || in __elfN()
1081 strcmp(interp, brand_info->interp_path) == 0)) { in __elfN()
1082 error = __elfN(load_file)(imgp->proc, in __elfN()
1083 brand_info->interp_newpath, addr, entry); in __elfN()
1088 error = __elfN(load_file)(imgp->proc, interp, addr, entry); in __elfN()
1121 hdr = (const Elf_Ehdr *)imgp->image_header; in __CONCAT()
1130 (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN)) in __CONCAT()
1131 return (-1); in __CONCAT()
1134 * From here on down, we return an errno, not -1, as we've in __CONCAT()
1142 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __CONCAT()
1165 for (i = MAXPAGESIZES - 1; i > 0; i--) { in __CONCAT()
1174 for (i = 0; i < hdr->e_phnum; i++) { in __CONCAT()
1202 hdr->e_phoff + hdr->e_phnum * hdr->e_phentsize <= in __CONCAT()
1204 proghdr = phdr[i].p_vaddr + hdr->e_phoff; in __CONCAT()
1220 imgp->stack_prot = in __CONCAT()
1222 if ((imgp->stack_prot & VM_PROT_RW) != in __CONCAT()
1229 imgp->stack_sz = phdr[i].p_memsz; in __CONCAT()
1240 hdr->e_ident[EI_OSABI]); in __CONCAT()
1244 sv = brand_info->sysvec; in __CONCAT()
1245 if (hdr->e_type == ET_DYN) { in __CONCAT()
1246 if ((brand_info->flags & BI_CAN_EXEC_DYN) == 0) { in __CONCAT()
1253 * non-zero for some reason. in __CONCAT()
1256 if ((sv->sv_flags & SV_ASLR) == 0 || in __CONCAT()
1258 imgp->et_dyn_addr = __elfN(pie_base); in __CONCAT()
1260 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) == 0) || in __CONCAT()
1261 (imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0) in __CONCAT()
1262 imgp->et_dyn_addr = ET_DYN_ADDR_RAND; in __CONCAT()
1264 imgp->et_dyn_addr = __elfN(pie_base); in __CONCAT()
1279 VOP_UNLOCK(imgp->vp); in __CONCAT()
1288 if (imgp->credential_setid) { in __CONCAT()
1289 PROC_LOCK(imgp->proc); in __CONCAT()
1290 imgp->proc->p_flag2 &= ~(P2_ASLR_ENABLE | P2_ASLR_DISABLE | in __CONCAT()
1292 PROC_UNLOCK(imgp->proc); in __CONCAT()
1294 if ((sv->sv_flags & SV_ASLR) == 0 || in __CONCAT()
1295 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) != 0 || in __CONCAT()
1297 KASSERT(imgp->et_dyn_addr != ET_DYN_ADDR_RAND, in __CONCAT()
1298 ("imgp->et_dyn_addr == RAND and !ASLR")); in __CONCAT()
1299 } else if ((imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0 || in __CONCAT()
1300 (__elfN(aslr_enabled) && hdr->e_type == ET_EXEC) || in __CONCAT()
1301 imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { in __CONCAT()
1302 imgp->map_flags |= MAP_ASLR; in __CONCAT()
1310 (imgp->proc->p_flag2 & P2_ASLR_IGNSTART) != 0) in __CONCAT()
1311 imgp->map_flags |= MAP_ASLR_IGNSTART; in __CONCAT()
1313 imgp->map_flags |= MAP_ASLR_STACK; in __CONCAT()
1315 imgp->imgp_flags |= IMGP_ASLR_SHARED_PAGE; in __CONCAT()
1319 (imgp->proc->p_flag2 & P2_WXORX_DISABLE) == 0) || in __CONCAT()
1320 (imgp->proc->p_flag2 & P2_WXORX_ENABLE_EXEC) != 0) in __CONCAT()
1321 imgp->map_flags |= MAP_WXORX; in __CONCAT()
1325 imgp->proc->p_sysent = sv; in __CONCAT()
1326 imgp->proc->p_elf_brandinfo = brand_info; in __CONCAT()
1328 vmspace = imgp->proc->p_vmspace; in __CONCAT()
1329 map = &vmspace->vm_map; in __CONCAT()
1330 maxv = sv->sv_usrstack; in __CONCAT()
1331 if ((imgp->map_flags & MAP_ASLR_STACK) == 0) in __CONCAT()
1332 maxv -= lim_max(td, RLIMIT_STACK); in __CONCAT()
1333 if (error == 0 && mapsz >= maxv - vm_map_min(map)) { in __CONCAT()
1338 if (error == 0 && imgp->et_dyn_addr == ET_DYN_ADDR_RAND) { in __CONCAT()
1339 KASSERT((map->flags & MAP_ASLR) != 0, in __CONCAT()
1344 maxv / 2, maxalign, &imgp->et_dyn_addr); in __CONCAT()
1347 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1351 error = __elfN(load_sections)(imgp, hdr, phdr, imgp->et_dyn_addr, NULL); in __CONCAT()
1365 addr = round_page((vm_offset_t)vmspace->vm_daddr + lim_max(td, in __CONCAT()
1367 if ((map->flags & MAP_ASLR) != 0) { in __CONCAT()
1378 map->anon_loc = anon_loc; in __CONCAT()
1380 map->anon_loc = addr; in __CONCAT()
1383 entry = (u_long)hdr->e_entry + imgp->et_dyn_addr; in __CONCAT()
1384 imgp->entry_addr = entry; in __CONCAT()
1386 if (sv->sv_protect != NULL) in __CONCAT()
1387 sv->sv_protect(imgp, SVP_IMAGE); in __CONCAT()
1390 VOP_UNLOCK(imgp->vp); in __CONCAT()
1391 if ((map->flags & MAP_ASLR) != 0) { in __CONCAT()
1399 &addr, &imgp->entry_addr); in __CONCAT()
1401 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1405 addr = imgp->et_dyn_addr; in __CONCAT()
1416 VOP_UNLOCK(imgp->vp); in __CONCAT()
1418 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __CONCAT()
1420 elf_auxargs->execfd = -1; in __CONCAT()
1421 elf_auxargs->phdr = proghdr + imgp->et_dyn_addr; in __CONCAT()
1422 elf_auxargs->phent = hdr->e_phentsize; in __CONCAT()
1423 elf_auxargs->phnum = hdr->e_phnum; in __CONCAT()
1424 elf_auxargs->pagesz = PAGE_SIZE; in __CONCAT()
1425 elf_auxargs->base = addr; in __CONCAT()
1426 elf_auxargs->flags = 0; in __CONCAT()
1427 elf_auxargs->entry = entry; in __CONCAT()
1428 elf_auxargs->hdr_eflags = hdr->e_flags; in __CONCAT()
1430 imgp->auxargs = elf_auxargs; in __CONCAT()
1431 imgp->interpreted = 0; in __CONCAT()
1432 imgp->reloc_base = addr; in __CONCAT()
1433 imgp->proc->p_osrel = osrel; in __CONCAT()
1434 imgp->proc->p_fctl0 = fctl0; in __CONCAT()
1435 imgp->proc->p_elf_flags = hdr->e_flags; in __CONCAT()
1438 ASSERT_VOP_LOCKED(imgp->vp, "skipped relock"); in __CONCAT()
1449 Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs; in __elfN()
1459 vmspace = imgp->proc->p_vmspace; in __elfN()
1461 if (args->execfd != -1) in __elfN()
1462 AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd); in __elfN()
1463 AUXARGS_ENTRY(pos, AT_PHDR, args->phdr); in __elfN()
1464 AUXARGS_ENTRY(pos, AT_PHENT, args->phent); in __elfN()
1465 AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum); in __elfN()
1466 AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz); in __elfN()
1467 AUXARGS_ENTRY(pos, AT_FLAGS, args->flags); in __elfN()
1468 AUXARGS_ENTRY(pos, AT_ENTRY, args->entry); in __elfN()
1469 AUXARGS_ENTRY(pos, AT_BASE, args->base); in __elfN()
1470 AUXARGS_ENTRY(pos, AT_EHDRFLAGS, args->hdr_eflags); in __elfN()
1471 if (imgp->execpathp != 0) in __elfN()
1472 AUXARGS_ENTRY_PTR(pos, AT_EXECPATH, imgp->execpathp); in __elfN()
1474 imgp->proc->p_ucred->cr_prison->pr_osreldate); in __elfN()
1475 if (imgp->canary != 0) { in __elfN()
1476 AUXARGS_ENTRY_PTR(pos, AT_CANARY, imgp->canary); in __elfN()
1477 AUXARGS_ENTRY(pos, AT_CANARYLEN, imgp->canarylen); in __elfN()
1480 if (imgp->pagesizes != 0) { in __elfN()
1481 AUXARGS_ENTRY_PTR(pos, AT_PAGESIZES, imgp->pagesizes); in __elfN()
1482 AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen); in __elfN()
1484 if ((imgp->sysent->sv_flags & SV_TIMEKEEP) != 0) { in __elfN()
1486 vmspace->vm_shp_base + imgp->sysent->sv_timekeep_offset); in __elfN()
1488 AUXARGS_ENTRY(pos, AT_STACKPROT, imgp->sysent->sv_shared_page_obj in __elfN()
1489 != NULL && imgp->stack_prot != 0 ? imgp->stack_prot : in __elfN()
1490 imgp->sysent->sv_stackprot); in __elfN()
1491 if (imgp->sysent->sv_hwcap != NULL) in __elfN()
1492 AUXARGS_ENTRY(pos, AT_HWCAP, *imgp->sysent->sv_hwcap); in __elfN()
1493 if (imgp->sysent->sv_hwcap2 != NULL) in __elfN()
1494 AUXARGS_ENTRY(pos, AT_HWCAP2, *imgp->sysent->sv_hwcap2); in __elfN()
1495 if (imgp->sysent->sv_hwcap3 != NULL) in __elfN()
1496 AUXARGS_ENTRY(pos, AT_HWCAP3, *imgp->sysent->sv_hwcap3); in __elfN()
1497 if (imgp->sysent->sv_hwcap4 != NULL) in __elfN()
1498 AUXARGS_ENTRY(pos, AT_HWCAP4, *imgp->sysent->sv_hwcap4); in __elfN()
1505 AUXARGS_ENTRY(pos, AT_ARGC, imgp->args->argc); in __elfN()
1506 AUXARGS_ENTRY_PTR(pos, AT_ARGV, imgp->argv); in __elfN()
1507 AUXARGS_ENTRY(pos, AT_ENVC, imgp->args->envc); in __elfN()
1508 AUXARGS_ENTRY_PTR(pos, AT_ENVV, imgp->envv); in __elfN()
1509 AUXARGS_ENTRY_PTR(pos, AT_PS_STRINGS, imgp->ps_strings); in __elfN()
1511 if ((imgp->sysent->sv_flags & SV_RNG_SEED_VER) != 0) { in __elfN()
1513 vmspace->vm_shp_base + imgp->sysent->sv_fxrng_gen_offset); in __elfN()
1516 if ((imgp->sysent->sv_flags & SV_DSO_SIG) != 0 && __elfN(vdso) != 0) { in __elfN()
1518 vmspace->vm_shp_base + imgp->sysent->sv_vdso_offset); in __elfN()
1520 AUXARGS_ENTRY(pos, AT_USRSTACKBASE, round_page(vmspace->vm_stacktop)); in __elfN()
1521 stacksz = imgp->proc->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur; in __elfN()
1525 free(imgp->auxargs, M_TEMP); in __elfN()
1526 imgp->auxargs = NULL; in __elfN()
1527 KASSERT(pos - argarray <= AT_COUNT, ("Too many auxargs")); in __elfN()
1540 base--; in __elfN()
1541 if (elf_suword(base, imgp->args->argc) == -1) in __elfN()
1602 struct ucred *cred = td->td_ucred; in __elfN()
1624 td->td_proc->p_sysent->sv_elf_core_prepare_notes(td, ¬elst, ¬esz); in __elfN()
1636 PROC_LOCK(td->td_proc); in __elfN()
1637 error = racct_add(td->td_proc, RACCT_CORE, coresize); in __elfN()
1638 PROC_UNLOCK(td->td_proc); in __elfN()
1666 if (cdw->init_fn != NULL) { in __elfN()
1667 error = (*cdw->init_fn)(cdw, ¶ms); in __elfN()
1689 error = core_output((char *)(uintptr_t)php->p_vaddr, in __elfN()
1690 php->p_filesz, offset, ¶ms, tmpbuf); in __elfN()
1693 offset += php->p_filesz; in __elfN()
1702 curproc->p_comm, error); in __elfN()
1727 Elf_Phdr *phdr = phc->phdr; in cb_put_phdr()
1729 phc->offset = round_page(phc->offset); in cb_put_phdr()
1731 phdr->p_type = PT_LOAD; in cb_put_phdr()
1732 phdr->p_offset = phc->offset; in cb_put_phdr()
1733 phdr->p_vaddr = entry->start; in cb_put_phdr()
1734 phdr->p_paddr = 0; in cb_put_phdr()
1735 phdr->p_filesz = phdr->p_memsz = entry->end - entry->start; in cb_put_phdr()
1736 phdr->p_align = PAGE_SIZE; in cb_put_phdr()
1737 phdr->p_flags = __elfN(untrans_prot)(entry->protection); in cb_put_phdr()
1739 phc->offset += phdr->p_filesz; in cb_put_phdr()
1740 phc->phdr++; in cb_put_phdr()
1752 ssc->count++; in cb_size_segment()
1753 ssc->size += entry->end - entry->start; in cb_size_segment()
1760 seginfo->count = 0; in __elfN()
1761 seginfo->size = 0; in __elfN()
1769 * caller-supplied data.
1775 struct proc *p = td->td_proc; in each_dumpable_segment() local
1776 vm_map_t map = &p->p_vmspace->vm_map; in each_dumpable_segment()
1787 * Note that read-only segments related to the elf binary in each_dumpable_segment()
1793 if ((entry->protection & VM_PROT_RW) != in each_dumpable_segment()
1797 if ((entry->protection & VM_PROT_ALL) == 0) in each_dumpable_segment()
1808 if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) in each_dumpable_segment()
1810 if ((entry->eflags & MAP_ENTRY_NOCOREDUMP) != 0 && in each_dumpable_segment()
1813 if ((object = entry->object.vm_object) == NULL) in each_dumpable_segment()
1816 /* Ignore memory-mapped devices and such things. */ in each_dumpable_segment()
1818 while ((backing_object = object->backing_object) != NULL) { in each_dumpable_segment()
1823 ignore_entry = (object->flags & OBJ_FICTITIOUS) != 0; in each_dumpable_segment()
1838 __elfN(corehdr)(struct coredump_params *p, int numsegs, void *hdr, in __elfN()
1848 __elfN(puthdr)(p->td, hdr, hdrsize, numsegs, notesz, flags); in __elfN()
1851 sbuf_set_drain(sb, sbuf_drain_core_output, p); in __elfN()
1855 __elfN(putnote)(p->td, ninfo, sb); in __elfN()
1857 sbuf_end_section(sb, -1, PAGE_SIZE, 0); in __elfN()
1868 struct proc *p; in __elfN() local
1872 p = td->td_proc; in __elfN()
1876 __elfN(note_prpsinfo), p); in __elfN()
1887 size += __elfN(register_note)(td, list, -1, in __elfN()
1890 thr = thr == td ? TAILQ_FIRST(&p->p_threads) : in __elfN()
1897 __elfN(note_procstat_proc), p); in __elfN()
1899 note_procstat_files, p); in __elfN()
1901 note_procstat_vmmap, p); in __elfN()
1903 note_procstat_groups, p); in __elfN()
1905 note_procstat_umask, p); in __elfN()
1907 note_procstat_rlimit, p); in __elfN()
1909 note_procstat_osrel, p); in __elfN()
1911 __elfN(note_procstat_psstrings), p); in __elfN()
1913 __elfN(note_procstat_auxv), p); in __elfN()
1915 __elfN(note_procstat_kqueues), p); in __elfN()
1931 bi = td->td_proc->p_elf_brandinfo; in __elfN()
1933 ehdr->e_ident[EI_MAG0] = ELFMAG0; in __elfN()
1934 ehdr->e_ident[EI_MAG1] = ELFMAG1; in __elfN()
1935 ehdr->e_ident[EI_MAG2] = ELFMAG2; in __elfN()
1936 ehdr->e_ident[EI_MAG3] = ELFMAG3; in __elfN()
1937 ehdr->e_ident[EI_CLASS] = ELF_CLASS; in __elfN()
1938 ehdr->e_ident[EI_DATA] = ELF_DATA; in __elfN()
1939 ehdr->e_ident[EI_VERSION] = EV_CURRENT; in __elfN()
1940 ehdr->e_ident[EI_OSABI] = td->td_proc->p_sysent->sv_elf_core_osabi; in __elfN()
1941 ehdr->e_ident[EI_ABIVERSION] = 0; in __elfN()
1942 ehdr->e_ident[EI_PAD] = 0; in __elfN()
1943 ehdr->e_type = ET_CORE; in __elfN()
1944 ehdr->e_machine = bi->machine; in __elfN()
1945 ehdr->e_version = EV_CURRENT; in __elfN()
1946 ehdr->e_entry = 0; in __elfN()
1947 ehdr->e_phoff = sizeof(Elf_Ehdr); in __elfN()
1948 ehdr->e_flags = td->td_proc->p_elf_flags; in __elfN()
1949 ehdr->e_ehsize = sizeof(Elf_Ehdr); in __elfN()
1950 ehdr->e_phentsize = sizeof(Elf_Phdr); in __elfN()
1951 ehdr->e_shentsize = sizeof(Elf_Shdr); in __elfN()
1952 ehdr->e_shstrndx = SHN_UNDEF; in __elfN()
1954 ehdr->e_phnum = numsegs + 1; in __elfN()
1955 ehdr->e_shnum = 0; in __elfN()
1957 ehdr->e_phnum = PN_XNUM; in __elfN()
1958 ehdr->e_shnum = 1; in __elfN()
1960 ehdr->e_shoff = ehdr->e_phoff + in __elfN()
1961 (numsegs + 1) * ehdr->e_phentsize; in __elfN()
1962 KASSERT(ehdr->e_shoff == hdrsize - sizeof(Elf_Shdr), in __elfN()
1963 ("e_shoff: %zu, hdrsize - shdr: %zu", in __elfN()
1964 (size_t)ehdr->e_shoff, hdrsize - sizeof(Elf_Shdr))); in __elfN()
1966 shdr = (Elf_Shdr *)((char *)hdr + ehdr->e_shoff); in __elfN()
1974 * See table 7-7 of the Solaris "Linker and Libraries Guide" in __elfN()
1975 * (or 12-7 depending on the version of the document) for more in __elfN()
1978 shdr->sh_type = SHT_NULL; in __elfN()
1979 shdr->sh_size = ehdr->e_shnum; in __elfN()
1980 shdr->sh_link = ehdr->e_shstrndx; in __elfN()
1981 shdr->sh_info = numsegs + 1; in __elfN()
1987 phdr = (Elf_Phdr *)((char *)hdr + ehdr->e_phoff); in __elfN()
1990 phdr->p_type = PT_NOTE; in __elfN()
1991 phdr->p_offset = hdrsize; in __elfN()
1992 phdr->p_vaddr = 0; in __elfN()
1993 phdr->p_paddr = 0; in __elfN()
1994 phdr->p_filesz = notesz; in __elfN()
1995 phdr->p_memsz = 0; in __elfN()
1996 phdr->p_flags = PF_R; in __elfN()
1997 phdr->p_align = ELF_NOTE_ROUNDSIZE; in __elfN()
2015 if (!regset->get(regset, target_td, NULL, &size) || size == 0) in __elfN()
2019 ninfo->type = regset->note; in __elfN()
2020 ninfo->regset = regset; in __elfN()
2021 ninfo->outarg = target_td; in __elfN()
2022 ninfo->outsize = size; in __elfN()
2025 sv = td->td_proc->p_sysent; in __elfN()
2027 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + in __elfN()
2042 sv = td->td_proc->p_sysent; in __elfN()
2046 ninfo->type = type; in __elfN()
2047 ninfo->outfunc = out; in __elfN()
2048 ninfo->outarg = arg; in __elfN()
2049 ninfo->outsize = size; in __elfN()
2052 if (type == -1) in __elfN()
2056 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) + in __elfN()
2071 bzero((char *)dst + len, padded_len - len); in append_note_data()
2086 note->n_namesz = sizeof(FREEBSD_ABI_VENDOR); in __elfN()
2087 note->n_descsz = size; in __elfN()
2088 note->n_type = type; in __elfN()
2113 if (ninfo->type == -1) { in __elfN()
2114 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); in __elfN()
2118 sv = td->td_proc->p_sysent; in __elfN()
2120 note.n_namesz = strlen(sv->sv_elf_core_abi_vendor) + 1; in __elfN()
2121 note.n_descsz = ninfo->outsize; in __elfN()
2122 note.n_type = ninfo->type; in __elfN()
2126 sbuf_bcat(sb, sv->sv_elf_core_abi_vendor, in __elfN()
2127 strlen(sv->sv_elf_core_abi_vendor) + 1); in __elfN()
2132 if (ninfo->regset != NULL) { in __elfN()
2133 struct regset *regset = ninfo->regset; in __elfN()
2136 buf = malloc(ninfo->outsize, M_TEMP, M_ZERO | M_WAITOK); in __elfN()
2137 (void)regset->get(regset, ninfo->outarg, buf, &ninfo->outsize); in __elfN()
2138 sbuf_bcat(sb, buf, ninfo->outsize); in __elfN()
2141 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize); in __elfN()
2152 * themselves, padding in a format-specific way if needed. in __elfN()
2155 for (i = 0; i < descsz - new_len; i++) in __elfN()
2159 * We can't always truncate sb -- we may have drained some in __elfN()
2208 struct proc *p; in __elfN() local
2212 p = arg; in __elfN()
2216 psinfo->pr_version = PRPSINFO_VERSION; in __elfN()
2217 psinfo->pr_psinfosz = sizeof(elf_prpsinfo_t); in __elfN()
2218 strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname)); in __elfN()
2219 PROC_LOCK(p); in __elfN()
2220 if (p->p_args != NULL) { in __elfN()
2221 len = sizeof(psinfo->pr_psargs) - 1; in __elfN()
2222 if (len > p->p_args->ar_length) in __elfN()
2223 len = p->p_args->ar_length; in __elfN()
2224 memcpy(psinfo->pr_psargs, p->p_args->ar_args, len); in __elfN()
2225 PROC_UNLOCK(p); in __elfN()
2228 _PHOLD(p); in __elfN()
2229 PROC_UNLOCK(p); in __elfN()
2230 sbuf_new(&sbarg, psinfo->pr_psargs, in __elfN()
2231 sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN); in __elfN()
2232 error = proc_getargv(curthread, p, &sbarg); in __elfN()
2233 PRELE(p); in __elfN()
2237 len--; in __elfN()
2239 len = sizeof(psinfo->pr_psargs) - 1; in __elfN()
2243 if (error != 0 || len == 0 || (ssize_t)len == -1) in __elfN()
2244 strlcpy(psinfo->pr_psargs, p->p_comm, in __elfN()
2245 sizeof(psinfo->pr_psargs)); in __elfN()
2247 KASSERT(len < sizeof(psinfo->pr_psargs), in __elfN()
2248 ("len is too long: %zu vs %zu", len, in __elfN()
2249 sizeof(psinfo->pr_psargs))); in __elfN()
2250 cp = psinfo->pr_psargs; in __elfN()
2251 end = cp + len - 1; in __elfN()
2253 cp = memchr(cp, '\0', end - cp); in __elfN()
2259 psinfo->pr_pid = p->p_pid; in __elfN()
2277 status->pr_version = PRSTATUS_VERSION; in __elfN()
2278 status->pr_statussz = sizeof(elf_prstatus_t); in __elfN()
2279 status->pr_gregsetsz = sizeof(elf_gregset_t); in __elfN()
2280 status->pr_fpregsetsz = sizeof(elf_fpregset_t); in __elfN()
2281 status->pr_osreldate = osreldate; in __elfN()
2282 status->pr_cursig = td->td_proc->p_sig; in __elfN()
2283 status->pr_pid = td->td_tid; in __elfN()
2285 fill_regs32(td, &status->pr_reg); in __elfN()
2287 fill_regs(td, &status->pr_reg); in __elfN()
2303 set_regs32(td, &status->pr_reg); in __elfN()
2305 set_regs(td, &status->pr_reg); in __elfN()
2373 strcpy(thrmisc->pr_tname, td->td_name); in __elfN()
2400 pl.pl_lwpid = td->td_tid; in __elfN()
2402 pl.pl_sigmask = td->td_sigmask; in __elfN()
2403 pl.pl_siglist = td->td_siglist; in __elfN()
2404 if (td->td_si.si_signo != 0) { in __elfN()
2408 siginfo_to_siginfo32(&td->td_si, &pl.pl_siginfo); in __elfN()
2410 pl.pl_siginfo = td->td_si; in __elfN()
2413 strcpy(pl.pl_tdname, td->td_name); in __elfN()
2414 /* XXX TODO: supply more information in struct ptrace_lwpinfo*/ in __elfN()
2432 struct sysentvec *sv = td->td_proc->p_sysent; in __elfN()
2445 regsetp = sv->sv_regset_begin; in __elfN()
2452 regset_end = sv->sv_regset_end; in __elfN()
2456 if (regset->note == NT_PRSTATUS) in __elfN()
2497 struct proc *p; in __elfN() local
2501 p = arg; in __elfN()
2502 size = sizeof(structsize) + p->p_numthreads * in __elfN()
2510 PROC_LOCK(p); in __elfN()
2511 kern_proc_out(p, sb, ELF_KERN_PROC_MASK); in __elfN()
2524 struct proc *p; in note_procstat_files() local
2534 p = arg; in note_procstat_files()
2541 PROC_LOCK(p); in note_procstat_files()
2542 kern_proc_filedesc_out(p, sb, -1, filedesc_flags); in note_procstat_files()
2550 PROC_LOCK(p); in note_procstat_files()
2551 kern_proc_filedesc_out(p, sb, *sizep - sizeof(structsize), in note_procstat_files()
2561 "requested %zu, got %zu", *sizep - sizeof(structsize), in note_procstat_files()
2562 sect_sz - sizeof(structsize))); in note_procstat_files()
2564 for (i = 0; i < *sizep - sect_sz && sb->s_error == 0; i++) in note_procstat_files()
2576 struct proc *p; in note_procstat_vmmap() local
2585 p = arg; in note_procstat_vmmap()
2592 PROC_LOCK(p); in note_procstat_vmmap()
2593 kern_proc_vmmap_out(p, sb, -1, vmmap_flags); in note_procstat_vmmap()
2599 PROC_LOCK(p); in note_procstat_vmmap()
2600 kern_proc_vmmap_out(p, sb, *sizep - sizeof(structsize), in note_procstat_vmmap()
2608 struct proc *p; in note_procstat_groups() local
2612 p = arg; in note_procstat_groups()
2614 (1 + p->p_ucred->cr_ngroups) * sizeof(gid_t); in note_procstat_groups()
2619 sbuf_bcat(sb, &p->p_ucred->cr_gid, sizeof(gid_t)); in note_procstat_groups()
2620 sbuf_bcat(sb, p->p_ucred->cr_groups, p->p_ucred->cr_ngroups * in note_procstat_groups()
2629 struct proc *p; in note_procstat_umask() local
2633 p = arg; in note_procstat_umask()
2634 size = sizeof(structsize) + sizeof(p->p_pd->pd_cmask); in note_procstat_umask()
2637 structsize = sizeof(p->p_pd->pd_cmask); in note_procstat_umask()
2639 sbuf_bcat(sb, &p->p_pd->pd_cmask, sizeof(p->p_pd->pd_cmask)); in note_procstat_umask()
2647 struct proc *p; in note_procstat_rlimit() local
2652 p = arg; in note_procstat_rlimit()
2658 PROC_LOCK(p); in note_procstat_rlimit()
2660 lim_rlimit_proc(p, i, &rlim[i]); in note_procstat_rlimit()
2661 PROC_UNLOCK(p); in note_procstat_rlimit()
2670 struct proc *p; in note_procstat_osrel() local
2674 p = arg; in note_procstat_osrel()
2675 size = sizeof(structsize) + sizeof(p->p_osrel); in note_procstat_osrel()
2678 structsize = sizeof(p->p_osrel); in note_procstat_osrel()
2680 sbuf_bcat(sb, &p->p_osrel, sizeof(p->p_osrel)); in note_procstat_osrel()
2688 struct proc *p; in __elfN() local
2693 p = arg; in __elfN()
2699 ps_strings = PTROUT(PROC_PS_STRINGS(p)); in __elfN()
2701 ps_strings = PROC_PS_STRINGS(p); in __elfN()
2712 struct proc *p; in __elfN() local
2716 p = arg; in __elfN()
2723 PHOLD(p); in __elfN()
2724 proc_getauxv(curthread, p, sb); in __elfN()
2725 PRELE(p); in __elfN()
2732 PHOLD(p); in __elfN()
2733 proc_getauxv(curthread, p, sb); in __elfN()
2734 PRELE(p); in __elfN()
2741 struct proc *p; in __elfN() local
2754 p = arg; in __elfN()
2760 kern_proc_kqueues_out(p, sb, -1, compat32); in __elfN()
2768 kern_proc_kqueues_out(p, sb, *sizep - sizeof(structsize), in __elfN()
2778 "requested %zu, got %zu", *sizep - sizeof(structsize), in __elfN()
2779 sect_sz - sizeof(structsize))); in __elfN()
2781 for (i = 0; i < *sizep - sect_sz && sb->s_error == 0; i++) in __elfN()
2799 if (pnote == NULL || pnote->p_filesz > PAGE_SIZE) in __elfN()
2801 ASSERT_VOP_LOCKED(imgp->vp, "parse_notes"); in __elfN()
2802 if (pnote->p_offset > PAGE_SIZE || in __elfN()
2803 pnote->p_filesz > PAGE_SIZE - pnote->p_offset) { in __elfN()
2804 buf = malloc(pnote->p_filesz, M_TEMP, M_NOWAIT); in __elfN()
2806 VOP_UNLOCK(imgp->vp); in __elfN()
2807 buf = malloc(pnote->p_filesz, M_TEMP, M_WAITOK); in __elfN()
2808 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in __elfN()
2810 error = vn_rdwr(UIO_READ, imgp->vp, buf, pnote->p_filesz, in __elfN()
2811 pnote->p_offset, UIO_SYSSPACE, IO_NODELOCKED, in __elfN()
2812 curthread->td_ucred, NOCRED, NULL, curthread); in __elfN()
2818 note_end = (const Elf_Note *)(buf + pnote->p_filesz); in __elfN()
2820 note = note0 = (const Elf_Note *)(imgp->image_header + in __elfN()
2821 pnote->p_offset); in __elfN()
2822 note_end = (const Elf_Note *)(imgp->image_header + in __elfN()
2823 pnote->p_offset + pnote->p_filesz); in __elfN()
2832 if ((const char *)note_end - (const char *)note < in __elfN()
2837 if (note->n_namesz != checknote->n_namesz || in __elfN()
2838 note->n_descsz != checknote->n_descsz || in __elfN()
2839 note->n_type != checknote->n_type) in __elfN()
2842 if (note_name + roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + in __elfN()
2843 note->n_descsz >= (const char *)note_end || in __elfN()
2844 strncmp(note_vendor, note_name, checknote->n_namesz) != 0) in __elfN()
2851 roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + in __elfN()
2852 roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE)); in __elfN()
2876 * Fetch the osreldate for binary from the ELF OSABI-note if in brandnote_cb()
2879 *res = (arg->brandnote->flags & BN_TRANSLATE_OSREL) != 0 && in brandnote_cb()
2880 arg->brandnote->trans_osrel != NULL ? in brandnote_cb()
2881 arg->brandnote->trans_osrel(note, arg->osrel) : true; in brandnote_cb()
2902 uintptr_t p; in note_fctl_cb() local
2905 p = (uintptr_t)(note + 1); in note_fctl_cb()
2906 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); in note_fctl_cb()
2907 desc = (const Elf32_Word *)p; in note_fctl_cb()
2908 *arg->has_fctl0 = true; in note_fctl_cb()
2909 *arg->fctl0 = desc[0]; in note_fctl_cb()
2915 * Try to find the appropriate ABI-note section for checknote, fetch
2917 * OSABI-note. Only the first page of the image is searched, the same
2930 hdr = (const Elf_Ehdr *)imgp->image_header; in __elfN()
2931 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); in __elfN()
2937 for (i = 0; i < hdr->e_phnum; i++) { in __elfN()
2939 &brandnote->hdr, brandnote->vendor, &phdr[i], brandnote_cb, in __elfN()
2941 for (j = 0; j < hdr->e_phnum; j++) { in __elfN()