Lines Matching +full:proc +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
50 #include <sys/proc.h>
89 static int __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
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)
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);
268 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE);
297 return (-1);
314 return (-1);
321 struct proc *p;
326 if (p->p_sysent == entry->sysvec) {
340 const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header;
348 * We support four types of branding -- (1) the ELF EI_OSABI field
351 * field, and (4) the ".note.ABI-tag" ELF section.
354 /* Look for an ".note.ABI-tag" ELF section */
360 if (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)
362 if (hdr->e_machine == bi->machine && (bi->flags &
367 ret = __elfN(check_note)(imgp, bi->brand_note, osrel,
370 if (ret && bi->header_supported) {
371 ret = bi->header_supported(imgp, osrel,
385 (bi->interp_path == NULL ||
386 (strlen(bi->interp_path) + 1 != interp_name_len ||
387 strncmp(interp, bi->interp_path, interp_name_len)
402 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 ||
403 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0))
405 if (hdr->e_machine == bi->machine &&
406 (hdr->e_ident[EI_OSABI] == bi->brand ||
407 (bi->compat_3_brand != NULL &&
408 strcmp((const char *)&hdr->e_ident[OLD_EI_BRAND],
409 bi->compat_3_brand) == 0))) {
411 if (bi->header_supported == NULL ||
412 bi->header_supported(imgp, NULL, NULL)) {
418 bi->interp_path == NULL)
420 if (bi->interp_path != NULL &&
421 strlen(bi->interp_path) + 1 ==
423 bi->interp_path, interp_name_len) == 0)
436 if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY ||
437 bi->header_supported == NULL)
439 if (hdr->e_machine == bi->machine) {
440 ret = bi->header_supported(imgp, NULL, NULL);
450 if (bi == NULL || (bi->flags &
454 if (hdr->e_machine == bi->machine &&
455 bi->interp_path != NULL &&
457 strlen(bi->interp_path) + 1 == interp_name_len &&
458 strncmp(interp, bi->interp_path, interp_name_len)
459 == 0 && (bi->header_supported == NULL ||
460 bi->header_supported(imgp, NULL, NULL)))
468 if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 ||
469 (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0))
471 if (hdr->e_machine == bi->machine &&
472 __elfN(fallback_brand) == bi->brand &&
473 (bi->header_supported == NULL ||
474 bi->header_supported(imgp, NULL, NULL)))
483 return (hdr->e_phoff <= PAGE_SIZE &&
484 (u_int)hdr->e_phentsize * hdr->e_phnum <= PAGE_SIZE - hdr->e_phoff);
494 hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS ||
495 hdr->e_ident[EI_DATA] != ELF_TARG_DATA ||
496 hdr->e_ident[EI_VERSION] != EV_CURRENT ||
497 hdr->e_phentsize != sizeof(Elf_Phdr) ||
498 hdr->e_version != ELF_TARG_VER)
507 if (bi != NULL && bi->machine == hdr->e_machine)
527 vm_map_fixed(map, NULL, 0, trunc_page(start), round_page(end) -
537 off = offset - trunc_page(offset);
539 end - start);
563 offset += round_page(start) - start;
568 trunc_page(end) - start, trunc_page(end), end, prot);
580 rv = vm_map_fixed(map, NULL, 0, start, end - start,
590 off = offset - trunc_page(offset);
591 sz = end - start;
592 if (sz > PAGE_SIZE - off)
593 sz = PAGE_SIZE - off;
603 rv = vm_map_fixed(map, object, offset, start, end - start,
607 locked = VOP_ISLOCKED(imgp->vp);
608 VOP_UNLOCK(imgp->vp);
610 vn_lock(imgp->vp, locked | LK_RETRY);
613 MPASS(imgp->vp->v_object == object);
614 VOP_SET_TEXT_CHECKED(imgp->vp);
642 if ((filsz != 0 && (off_t)filsz + offset > imgp->attr->va_size) ||
648 object = imgp->object;
649 map = &imgp->proc->p_vmspace->vm_map;
662 map_len = trunc_page(offset + filsz) - file_addr;
664 map_len = round_page(offset + filsz) - file_addr;
687 copy_len = filsz == 0 ? 0 : (offset + filsz) - trunc_page(offset +
690 map_len = round_page((vm_offset_t)vmaddr + memsz) - map_addr;
733 ASSERT_VOP_LOCKED(imgp->vp, __func__);
738 for (i = 0; i < hdr->e_phnum; i++) {
778 __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
805 nd = &tempdata->nd;
806 attr = &tempdata->attr;
807 imgp = &tempdata->image_params;
812 imgp->proc = p;
813 imgp->attr = attr;
818 nd->ni_vp = NULL;
822 imgp->vp = nd->ni_vp;
835 imgp->object = nd->ni_vp->v_object;
837 hdr = (const Elf_Ehdr *)imgp->image_header;
840 if (hdr->e_type == ET_DYN)
842 else if (hdr->e_type == ET_EXEC)
855 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff);
865 if (p->p_sysent->sv_protect != NULL)
866 p->p_sysent->sv_protect(imgp, SVP_INTERP);
869 *entry = (unsigned long)hdr->e_entry + rbase;
872 if (imgp->firstpage)
875 if (nd->ni_vp) {
876 if (imgp->textset)
877 VOP_UNSET_TEXT_CHECKED(nd->ni_vp);
878 vput(nd->ni_vp);
909 res = roundup(minv, (u_long)align) + rbase % (maxv - minv);
910 res &= ~((u_long)align - 1);
912 res -= align;
938 for (i = 0; i < hdr->e_phnum; i++) {
942 seg_addr = trunc_page(phdr[i].p_vaddr + imgp->et_dyn_addr);
944 phdr[i].p_vaddr + imgp->et_dyn_addr - seg_addr);
976 PROC_LOCK(imgp->proc);
977 if (data_size > lim_cur_proc(imgp->proc, RLIMIT_DATA))
981 else if (total_size > lim_cur_proc(imgp->proc, RLIMIT_VMEM))
983 else if (racct_set(imgp->proc, RACCT_DATA, data_size) != 0)
985 else if (racct_set(imgp->proc, RACCT_VMEM, total_size) != 0)
987 PROC_UNLOCK(imgp->proc);
993 vmspace = imgp->proc->p_vmspace;
994 vmspace->vm_tsize = text_size >> PAGE_SHIFT;
995 vmspace->vm_taddr = (caddr_t)(uintptr_t)text_addr;
996 vmspace->vm_dsize = data_size >> PAGE_SHIFT;
997 vmspace->vm_daddr = (caddr_t)(uintptr_t)data_addr;
1010 KASSERT(phdr->p_type == PT_INTERP,
1011 ("%s: p_type %u != PT_INTERP", __func__, phdr->p_type));
1012 ASSERT_VOP_LOCKED(imgp->vp, __func__);
1017 if (phdr->p_filesz < 2 || phdr->p_filesz > MAXPATHLEN) {
1022 interp_name_len = phdr->p_filesz;
1023 if (phdr->p_offset > PAGE_SIZE ||
1024 interp_name_len > PAGE_SIZE - phdr->p_offset) {
1029 * try non-sleepable allocation first, and if it
1036 VOP_UNLOCK(imgp->vp);
1038 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
1041 error = vn_rdwr(UIO_READ, imgp->vp, interp,
1042 interp_name_len, phdr->p_offset,
1043 UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred,
1057 interp = __DECONST(char *, imgp->image_header) + phdr->p_offset;
1058 if (interp[interp_name_len - 1] != '\0') {
1074 if (brand_info->interp_newpath != NULL &&
1075 (brand_info->interp_path == NULL ||
1076 strcmp(interp, brand_info->interp_path) == 0)) {
1077 error = __elfN(load_file)(imgp->proc,
1078 brand_info->interp_newpath, addr, entry);
1083 error = __elfN(load_file)(imgp->proc, interp, addr, entry);
1116 hdr = (const Elf_Ehdr *)imgp->image_header;
1125 (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN))
1126 return (-1);
1129 * From here on down, we return an errno, not -1, as we've
1137 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff);
1160 for (i = MAXPAGESIZES - 1; i > 0; i--) {
1169 for (i = 0; i < hdr->e_phnum; i++) {
1197 hdr->e_phoff + hdr->e_phnum * hdr->e_phentsize <=
1199 proghdr = phdr[i].p_vaddr + hdr->e_phoff;
1215 imgp->stack_prot =
1217 if ((imgp->stack_prot & VM_PROT_RW) !=
1224 imgp->stack_sz = phdr[i].p_memsz;
1235 hdr->e_ident[EI_OSABI]);
1239 sv = brand_info->sysvec;
1240 if (hdr->e_type == ET_DYN) {
1241 if ((brand_info->flags & BI_CAN_EXEC_DYN) == 0) {
1248 * non-zero for some reason.
1251 if ((sv->sv_flags & SV_ASLR) == 0 ||
1253 imgp->et_dyn_addr = __elfN(pie_base);
1255 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) == 0) ||
1256 (imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0)
1257 imgp->et_dyn_addr = ET_DYN_ADDR_RAND;
1259 imgp->et_dyn_addr = __elfN(pie_base);
1274 VOP_UNLOCK(imgp->vp);
1283 if (imgp->credential_setid) {
1284 PROC_LOCK(imgp->proc);
1285 imgp->proc->p_flag2 &= ~(P2_ASLR_ENABLE | P2_ASLR_DISABLE |
1287 PROC_UNLOCK(imgp->proc);
1289 if ((sv->sv_flags & SV_ASLR) == 0 ||
1290 (imgp->proc->p_flag2 & P2_ASLR_DISABLE) != 0 ||
1292 KASSERT(imgp->et_dyn_addr != ET_DYN_ADDR_RAND,
1293 ("imgp->et_dyn_addr == RAND and !ASLR"));
1294 } else if ((imgp->proc->p_flag2 & P2_ASLR_ENABLE) != 0 ||
1295 (__elfN(aslr_enabled) && hdr->e_type == ET_EXEC) ||
1296 imgp->et_dyn_addr == ET_DYN_ADDR_RAND) {
1297 imgp->map_flags |= MAP_ASLR;
1305 (imgp->proc->p_flag2 & P2_ASLR_IGNSTART) != 0)
1306 imgp->map_flags |= MAP_ASLR_IGNSTART;
1308 imgp->map_flags |= MAP_ASLR_STACK;
1310 imgp->imgp_flags |= IMGP_ASLR_SHARED_PAGE;
1314 (imgp->proc->p_flag2 & P2_WXORX_DISABLE) == 0) ||
1315 (imgp->proc->p_flag2 & P2_WXORX_ENABLE_EXEC) != 0)
1316 imgp->map_flags |= MAP_WXORX;
1320 imgp->proc->p_sysent = sv;
1321 imgp->proc->p_elf_brandinfo = brand_info;
1323 vmspace = imgp->proc->p_vmspace;
1324 map = &vmspace->vm_map;
1325 maxv = sv->sv_usrstack;
1326 if ((imgp->map_flags & MAP_ASLR_STACK) == 0)
1327 maxv -= lim_max(td, RLIMIT_STACK);
1328 if (error == 0 && mapsz >= maxv - vm_map_min(map)) {
1333 if (error == 0 && imgp->et_dyn_addr == ET_DYN_ADDR_RAND) {
1334 KASSERT((map->flags & MAP_ASLR) != 0,
1339 maxv / 2, maxalign, &imgp->et_dyn_addr);
1342 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
1346 error = __elfN(load_sections)(imgp, hdr, phdr, imgp->et_dyn_addr, NULL);
1360 addr = round_page((vm_offset_t)vmspace->vm_daddr + lim_max(td,
1362 if ((map->flags & MAP_ASLR) != 0) {
1373 map->anon_loc = anon_loc;
1375 map->anon_loc = addr;
1378 entry = (u_long)hdr->e_entry + imgp->et_dyn_addr;
1379 imgp->entry_addr = entry;
1381 if (sv->sv_protect != NULL)
1382 sv->sv_protect(imgp, SVP_IMAGE);
1385 VOP_UNLOCK(imgp->vp);
1386 if ((map->flags & MAP_ASLR) != 0) {
1394 &addr, &imgp->entry_addr);
1396 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
1400 addr = imgp->et_dyn_addr;
1411 VOP_UNLOCK(imgp->vp);
1413 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
1415 elf_auxargs->execfd = -1;
1416 elf_auxargs->phdr = proghdr + imgp->et_dyn_addr;
1417 elf_auxargs->phent = hdr->e_phentsize;
1418 elf_auxargs->phnum = hdr->e_phnum;
1419 elf_auxargs->pagesz = PAGE_SIZE;
1420 elf_auxargs->base = addr;
1421 elf_auxargs->flags = 0;
1422 elf_auxargs->entry = entry;
1423 elf_auxargs->hdr_eflags = hdr->e_flags;
1425 imgp->auxargs = elf_auxargs;
1426 imgp->interpreted = 0;
1427 imgp->reloc_base = addr;
1428 imgp->proc->p_osrel = osrel;
1429 imgp->proc->p_fctl0 = fctl0;
1430 imgp->proc->p_elf_flags = hdr->e_flags;
1433 ASSERT_VOP_LOCKED(imgp->vp, "skipped relock");
1444 Elf_Auxargs *args = (Elf_Auxargs *)imgp->auxargs;
1454 vmspace = imgp->proc->p_vmspace;
1456 if (args->execfd != -1)
1457 AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
1458 AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
1459 AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
1460 AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
1461 AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
1462 AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
1463 AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
1464 AUXARGS_ENTRY(pos, AT_BASE, args->base);
1465 AUXARGS_ENTRY(pos, AT_EHDRFLAGS, args->hdr_eflags);
1466 if (imgp->execpathp != 0)
1467 AUXARGS_ENTRY_PTR(pos, AT_EXECPATH, imgp->execpathp);
1469 imgp->proc->p_ucred->cr_prison->pr_osreldate);
1470 if (imgp->canary != 0) {
1471 AUXARGS_ENTRY_PTR(pos, AT_CANARY, imgp->canary);
1472 AUXARGS_ENTRY(pos, AT_CANARYLEN, imgp->canarylen);
1475 if (imgp->pagesizes != 0) {
1476 AUXARGS_ENTRY_PTR(pos, AT_PAGESIZES, imgp->pagesizes);
1477 AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen);
1479 if ((imgp->sysent->sv_flags & SV_TIMEKEEP) != 0) {
1481 vmspace->vm_shp_base + imgp->sysent->sv_timekeep_offset);
1483 AUXARGS_ENTRY(pos, AT_STACKPROT, imgp->sysent->sv_shared_page_obj
1484 != NULL && imgp->stack_prot != 0 ? imgp->stack_prot :
1485 imgp->sysent->sv_stackprot);
1486 if (imgp->sysent->sv_hwcap != NULL)
1487 AUXARGS_ENTRY(pos, AT_HWCAP, *imgp->sysent->sv_hwcap);
1488 if (imgp->sysent->sv_hwcap2 != NULL)
1489 AUXARGS_ENTRY(pos, AT_HWCAP2, *imgp->sysent->sv_hwcap2);
1496 AUXARGS_ENTRY(pos, AT_ARGC, imgp->args->argc);
1497 AUXARGS_ENTRY_PTR(pos, AT_ARGV, imgp->argv);
1498 AUXARGS_ENTRY(pos, AT_ENVC, imgp->args->envc);
1499 AUXARGS_ENTRY_PTR(pos, AT_ENVV, imgp->envv);
1500 AUXARGS_ENTRY_PTR(pos, AT_PS_STRINGS, imgp->ps_strings);
1502 if ((imgp->sysent->sv_flags & SV_RNG_SEED_VER) != 0) {
1504 vmspace->vm_shp_base + imgp->sysent->sv_fxrng_gen_offset);
1507 if ((imgp->sysent->sv_flags & SV_DSO_SIG) != 0 && __elfN(vdso) != 0) {
1509 vmspace->vm_shp_base + imgp->sysent->sv_vdso_offset);
1511 AUXARGS_ENTRY(pos, AT_USRSTACKBASE, round_page(vmspace->vm_stacktop));
1512 stacksz = imgp->proc->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur;
1516 free(imgp->auxargs, M_TEMP);
1517 imgp->auxargs = NULL;
1518 KASSERT(pos - argarray <= AT_COUNT, ("Too many auxargs"));
1531 base--;
1532 if (elf_suword(base, imgp->args->argc) == -1)
1595 struct ucred *cred = td->td_ucred;
1617 td->td_proc->p_sysent->sv_elf_core_prepare_notes(td, &notelst, &notesz);
1630 PROC_LOCK(td->td_proc);
1631 error = racct_add(td->td_proc, RACCT_CORE, coresize);
1632 PROC_UNLOCK(td->td_proc);
1677 error = core_output((char *)(uintptr_t)php->p_vaddr,
1678 php->p_filesz, offset, &params, tmpbuf);
1681 offset += php->p_filesz;
1690 curproc->p_comm, error);
1715 Elf_Phdr *phdr = phc->phdr;
1717 phc->offset = round_page(phc->offset);
1719 phdr->p_type = PT_LOAD;
1720 phdr->p_offset = phc->offset;
1721 phdr->p_vaddr = entry->start;
1722 phdr->p_paddr = 0;
1723 phdr->p_filesz = phdr->p_memsz = entry->end - entry->start;
1724 phdr->p_align = PAGE_SIZE;
1725 phdr->p_flags = __elfN(untrans_prot)(entry->protection);
1727 phc->offset += phdr->p_filesz;
1728 phc->phdr++;
1740 ssc->count++;
1741 ssc->size += entry->end - entry->start;
1748 seginfo->count = 0;
1749 seginfo->size = 0;
1757 * caller-supplied data.
1763 struct proc *p = td->td_proc;
1764 vm_map_t map = &p->p_vmspace->vm_map;
1775 * Note that read-only segments related to the elf binary
1781 if ((entry->protection & VM_PROT_RW) !=
1785 if ((entry->protection & VM_PROT_ALL) == 0)
1796 if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0)
1798 if ((entry->eflags & MAP_ENTRY_NOCOREDUMP) != 0 &&
1801 if ((object = entry->object.vm_object) == NULL)
1804 /* Ignore memory-mapped devices and such things. */
1806 while ((backing_object = object->backing_object) != NULL) {
1811 ignore_entry = (object->flags & OBJ_FICTITIOUS) != 0;
1836 __elfN(puthdr)(p->td, hdr, hdrsize, numsegs, notesz, flags);
1843 __elfN(putnote)(p->td, ninfo, sb);
1845 sbuf_end_section(sb, -1, PAGE_SIZE, 0);
1856 struct proc *p;
1860 p = td->td_proc;
1875 size += __elfN(register_note)(td, list, -1,
1878 thr = thr == td ? TAILQ_FIRST(&p->p_threads) :
1917 bi = td->td_proc->p_elf_brandinfo;
1919 ehdr->e_ident[EI_MAG0] = ELFMAG0;
1920 ehdr->e_ident[EI_MAG1] = ELFMAG1;
1921 ehdr->e_ident[EI_MAG2] = ELFMAG2;
1922 ehdr->e_ident[EI_MAG3] = ELFMAG3;
1923 ehdr->e_ident[EI_CLASS] = ELF_CLASS;
1924 ehdr->e_ident[EI_DATA] = ELF_DATA;
1925 ehdr->e_ident[EI_VERSION] = EV_CURRENT;
1926 ehdr->e_ident[EI_OSABI] = td->td_proc->p_sysent->sv_elf_core_osabi;
1927 ehdr->e_ident[EI_ABIVERSION] = 0;
1928 ehdr->e_ident[EI_PAD] = 0;
1929 ehdr->e_type = ET_CORE;
1930 ehdr->e_machine = bi->machine;
1931 ehdr->e_version = EV_CURRENT;
1932 ehdr->e_entry = 0;
1933 ehdr->e_phoff = sizeof(Elf_Ehdr);
1934 ehdr->e_flags = td->td_proc->p_elf_flags;
1935 ehdr->e_ehsize = sizeof(Elf_Ehdr);
1936 ehdr->e_phentsize = sizeof(Elf_Phdr);
1937 ehdr->e_shentsize = sizeof(Elf_Shdr);
1938 ehdr->e_shstrndx = SHN_UNDEF;
1940 ehdr->e_phnum = numsegs + 1;
1941 ehdr->e_shnum = 0;
1943 ehdr->e_phnum = PN_XNUM;
1944 ehdr->e_shnum = 1;
1946 ehdr->e_shoff = ehdr->e_phoff +
1947 (numsegs + 1) * ehdr->e_phentsize;
1948 KASSERT(ehdr->e_shoff == hdrsize - sizeof(Elf_Shdr),
1949 ("e_shoff: %zu, hdrsize - shdr: %zu",
1950 (size_t)ehdr->e_shoff, hdrsize - sizeof(Elf_Shdr)));
1952 shdr = (Elf_Shdr *)((char *)hdr + ehdr->e_shoff);
1960 * See table 7-7 of the Solaris "Linker and Libraries Guide"
1961 * (or 12-7 depending on the version of the document) for more
1964 shdr->sh_type = SHT_NULL;
1965 shdr->sh_size = ehdr->e_shnum;
1966 shdr->sh_link = ehdr->e_shstrndx;
1967 shdr->sh_info = numsegs + 1;
1973 phdr = (Elf_Phdr *)((char *)hdr + ehdr->e_phoff);
1976 phdr->p_type = PT_NOTE;
1977 phdr->p_offset = hdrsize;
1978 phdr->p_vaddr = 0;
1979 phdr->p_paddr = 0;
1980 phdr->p_filesz = notesz;
1981 phdr->p_memsz = 0;
1982 phdr->p_flags = PF_R;
1983 phdr->p_align = ELF_NOTE_ROUNDSIZE;
2001 if (!regset->get(regset, target_td, NULL, &size) || size == 0)
2005 ninfo->type = regset->note;
2006 ninfo->regset = regset;
2007 ninfo->outarg = target_td;
2008 ninfo->outsize = size;
2011 sv = td->td_proc->p_sysent;
2013 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) +
2028 sv = td->td_proc->p_sysent;
2032 ninfo->type = type;
2033 ninfo->outfunc = out;
2034 ninfo->outarg = arg;
2035 ninfo->outsize = size;
2038 if (type == -1)
2042 roundup2(strlen(sv->sv_elf_core_abi_vendor) + 1, ELF_NOTE_ROUNDSIZE) +
2057 bzero((char *)dst + len, padded_len - len);
2072 note->n_namesz = sizeof(FREEBSD_ABI_VENDOR);
2073 note->n_descsz = size;
2074 note->n_type = type;
2099 if (ninfo->type == -1) {
2100 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize);
2104 sv = td->td_proc->p_sysent;
2106 note.n_namesz = strlen(sv->sv_elf_core_abi_vendor) + 1;
2107 note.n_descsz = ninfo->outsize;
2108 note.n_type = ninfo->type;
2112 sbuf_bcat(sb, sv->sv_elf_core_abi_vendor,
2113 strlen(sv->sv_elf_core_abi_vendor) + 1);
2118 if (ninfo->regset != NULL) {
2119 struct regset *regset = ninfo->regset;
2122 buf = malloc(ninfo->outsize, M_TEMP, M_ZERO | M_WAITOK);
2123 (void)regset->get(regset, ninfo->outarg, buf, &ninfo->outsize);
2124 sbuf_bcat(sb, buf, ninfo->outsize);
2127 ninfo->outfunc(ninfo->outarg, sb, &ninfo->outsize);
2138 * themselves, padding in a format-specific way if needed.
2141 for (i = 0; i < descsz - new_len; i++)
2145 * We can't always truncate sb -- we may have drained some
2194 struct proc *p;
2202 psinfo->pr_version = PRPSINFO_VERSION;
2203 psinfo->pr_psinfosz = sizeof(elf_prpsinfo_t);
2204 strlcpy(psinfo->pr_fname, p->p_comm, sizeof(psinfo->pr_fname));
2206 if (p->p_args != NULL) {
2207 len = sizeof(psinfo->pr_psargs) - 1;
2208 if (len > p->p_args->ar_length)
2209 len = p->p_args->ar_length;
2210 memcpy(psinfo->pr_psargs, p->p_args->ar_args, len);
2216 sbuf_new(&sbarg, psinfo->pr_psargs,
2217 sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN);
2223 len--;
2225 len = sizeof(psinfo->pr_psargs) - 1;
2229 if (error != 0 || len == 0 || (ssize_t)len == -1)
2230 strlcpy(psinfo->pr_psargs, p->p_comm,
2231 sizeof(psinfo->pr_psargs));
2233 KASSERT(len < sizeof(psinfo->pr_psargs),
2235 sizeof(psinfo->pr_psargs)));
2236 cp = psinfo->pr_psargs;
2237 end = cp + len - 1;
2239 cp = memchr(cp, '\0', end - cp);
2245 psinfo->pr_pid = p->p_pid;
2263 status->pr_version = PRSTATUS_VERSION;
2264 status->pr_statussz = sizeof(elf_prstatus_t);
2265 status->pr_gregsetsz = sizeof(elf_gregset_t);
2266 status->pr_fpregsetsz = sizeof(elf_fpregset_t);
2267 status->pr_osreldate = osreldate;
2268 status->pr_cursig = td->td_proc->p_sig;
2269 status->pr_pid = td->td_tid;
2271 fill_regs32(td, &status->pr_reg);
2273 fill_regs(td, &status->pr_reg);
2289 set_regs32(td, &status->pr_reg);
2291 set_regs(td, &status->pr_reg);
2359 strcpy(thrmisc->pr_tname, td->td_name);
2386 pl.pl_lwpid = td->td_tid;
2388 pl.pl_sigmask = td->td_sigmask;
2389 pl.pl_siglist = td->td_siglist;
2390 if (td->td_si.si_signo != 0) {
2394 siginfo_to_siginfo32(&td->td_si, &pl.pl_siginfo);
2396 pl.pl_siginfo = td->td_si;
2399 strcpy(pl.pl_tdname, td->td_name);
2400 /* XXX TODO: supply more information in struct ptrace_lwpinfo*/
2418 struct sysentvec *sv = td->td_proc->p_sysent;
2428 regsetp = sv->sv_regset_begin;
2435 regset_end = sv->sv_regset_end;
2439 if (regset->note == NT_PRSTATUS)
2480 struct proc *p;
2485 size = sizeof(structsize) + p->p_numthreads *
2507 struct proc *p;
2525 kern_proc_filedesc_out(p, sb, -1, filedesc_flags);
2534 kern_proc_filedesc_out(p, sb, *sizep - sizeof(structsize),
2544 "requested %zu, got %zu", *sizep - sizeof(structsize),
2545 sect_sz - sizeof(structsize)));
2547 for (i = 0; i < *sizep - sect_sz && sb->s_error == 0; i++)
2559 struct proc *p;
2576 kern_proc_vmmap_out(p, sb, -1, vmmap_flags);
2583 kern_proc_vmmap_out(p, sb, *sizep - sizeof(structsize),
2591 struct proc *p;
2596 size = sizeof(structsize) + p->p_ucred->cr_ngroups * sizeof(gid_t);
2601 sbuf_bcat(sb, p->p_ucred->cr_groups, p->p_ucred->cr_ngroups *
2610 struct proc *p;
2615 size = sizeof(structsize) + sizeof(p->p_pd->pd_cmask);
2618 structsize = sizeof(p->p_pd->pd_cmask);
2620 sbuf_bcat(sb, &p->p_pd->pd_cmask, sizeof(p->p_pd->pd_cmask));
2628 struct proc *p;
2651 struct proc *p;
2656 size = sizeof(structsize) + sizeof(p->p_osrel);
2659 structsize = sizeof(p->p_osrel);
2661 sbuf_bcat(sb, &p->p_osrel, sizeof(p->p_osrel));
2669 struct proc *p;
2693 struct proc *p;
2732 if (pnote == NULL || pnote->p_filesz > PAGE_SIZE)
2734 ASSERT_VOP_LOCKED(imgp->vp, "parse_notes");
2735 if (pnote->p_offset > PAGE_SIZE ||
2736 pnote->p_filesz > PAGE_SIZE - pnote->p_offset) {
2737 buf = malloc(pnote->p_filesz, M_TEMP, M_NOWAIT);
2739 VOP_UNLOCK(imgp->vp);
2740 buf = malloc(pnote->p_filesz, M_TEMP, M_WAITOK);
2741 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
2743 error = vn_rdwr(UIO_READ, imgp->vp, buf, pnote->p_filesz,
2744 pnote->p_offset, UIO_SYSSPACE, IO_NODELOCKED,
2745 curthread->td_ucred, NOCRED, NULL, curthread);
2751 note_end = (const Elf_Note *)(buf + pnote->p_filesz);
2753 note = note0 = (const Elf_Note *)(imgp->image_header +
2754 pnote->p_offset);
2755 note_end = (const Elf_Note *)(imgp->image_header +
2756 pnote->p_offset + pnote->p_filesz);
2765 if ((const char *)note_end - (const char *)note <
2770 if (note->n_namesz != checknote->n_namesz ||
2771 note->n_descsz != checknote->n_descsz ||
2772 note->n_type != checknote->n_type)
2775 if (note_name + checknote->n_namesz >=
2777 note_name, checknote->n_namesz) != 0)
2784 roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) +
2785 roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE));
2809 * Fetch the osreldate for binary from the ELF OSABI-note if
2812 *res = (arg->brandnote->flags & BN_TRANSLATE_OSREL) != 0 &&
2813 arg->brandnote->trans_osrel != NULL ?
2814 arg->brandnote->trans_osrel(note, arg->osrel) : true;
2839 p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE);
2841 *arg->has_fctl0 = true;
2842 *arg->fctl0 = desc[0];
2848 * Try to find the appropriate ABI-note section for checknote, fetch
2850 * OSABI-note. Only the first page of the image is searched, the same
2863 hdr = (const Elf_Ehdr *)imgp->image_header;
2864 phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff);
2870 for (i = 0; i < hdr->e_phnum; i++) {
2872 &brandnote->hdr, brandnote->vendor, &phdr[i], brandnote_cb,
2874 for (j = 0; j < hdr->e_phnum; j++) {