diff --git a/cddl/contrib/opensolaris/cmd/zdb/zdb.c b/cddl/contrib/opensolaris/cmd/zdb/zdb.c index 6ca504783a19..f588caaf205b 100644 --- a/cddl/contrib/opensolaris/cmd/zdb/zdb.c +++ b/cddl/contrib/opensolaris/cmd/zdb/zdb.c @@ -3724,7 +3724,7 @@ zdb_embedded_block(char *thing) { blkptr_t bp = { 0 }; unsigned long long *words = (void *)&bp; - char buf[SPA_MAXBLOCKSIZE]; + char *buf; int err; err = sscanf(thing, "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx:" @@ -3738,12 +3738,15 @@ zdb_embedded_block(char *thing) exit(1); } ASSERT3U(BPE_GET_LSIZE(&bp), <=, SPA_MAXBLOCKSIZE); + buf = malloc(SPA_MAXBLOCKSIZE); err = decode_embedded_bp(&bp, buf, BPE_GET_LSIZE(&bp)); if (err != 0) { (void) printf("decode failed: %u\n", err); + free(buf); exit(1); } zdb_dump_block_raw(buf, BPE_GET_LSIZE(&bp), 0); + free(buf); } static boolean_t diff --git a/contrib/binutils/bfd/ihex.c b/contrib/binutils/bfd/ihex.c index 9f765b33f770..67ac720a6ebd 100644 --- a/contrib/binutils/bfd/ihex.c +++ b/contrib/binutils/bfd/ihex.c @@ -320,7 +320,7 @@ ihex_scan (bfd *abfd) { if (! ISHEX (buf[i])) { - ihex_bad_byte (abfd, lineno, hdr[i], error); + ihex_bad_byte (abfd, lineno, buf[i], error); goto error_return; } } diff --git a/contrib/binutils/bfd/peXXigen.c b/contrib/binutils/bfd/peXXigen.c index f96825f687e8..954d68ef9037 100644 --- a/contrib/binutils/bfd/peXXigen.c +++ b/contrib/binutils/bfd/peXXigen.c @@ -448,6 +448,17 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd, { int idx; + /* PR 17512: Corrupt PE binaries can cause seg-faults. */ + if (a->NumberOfRvaAndSizes > 16) + { + (*_bfd_error_handler) + (_("%B: aout header specifies an invalid number of data-directory entries: %d"), + abfd, a->NumberOfRvaAndSizes); + /* Paranoia: If the number is corrupt, then assume that the + actual entries themselves might be corrupt as well. */ + a->NumberOfRvaAndSizes = 0; + } + for (idx = 0; idx < 16; idx++) { /* If data directory is empty, rva also should be 0. */ @@ -1428,6 +1439,15 @@ pe_print_edata (bfd * abfd, void * vfile) } } + /* PR 17512: Handle corrupt PE binaries. */ + if (datasize < 36) + { + fprintf (file, + _("\nThere is an export table in %s, but it is too small (%d)\n"), + section->name, (int) datasize); + return TRUE; + } + fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"), section->name, (unsigned long) addr); diff --git a/share/examples/bhyve/vmrun.sh b/share/examples/bhyve/vmrun.sh index c5f8006b27d2..7deb4b361ffd 100755 --- a/share/examples/bhyve/vmrun.sh +++ b/share/examples/bhyve/vmrun.sh @@ -46,7 +46,7 @@ errmsg() { usage() { local msg=$1 - echo "Usage: vmrun.sh [-aEhiTv] [-c ] [-C ] [-d ]" + echo "Usage: vmrun.sh [-aAEhiTv] [-c ] [-C ] [-d ]" echo " [-e ] [-f ] [-F ]" echo " [-g ] [-H ]" echo " [-I ] [-l ]" @@ -55,6 +55,7 @@ usage() { echo "" echo " -h: display this help message" echo " -a: force memory mapped local APIC access" + echo " -A: use AHCI disk emulation instead of virtio" echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})" echo " -C: console device (default is ${DEFAULT_CONSOLE})" echo " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})" @@ -99,6 +100,7 @@ console=${DEFAULT_CONSOLE} cpus=${DEFAULT_CPUS} tap_total=0 disk_total=0 +disk_emulation="virtio-blk" gdbport=0 loader_opt="" bhyverun_opt="-H -A -P" @@ -113,11 +115,14 @@ vncport=5900 fbsize="w=1024,h=768" tablet="" -while getopts ac:C:d:e:Ef:F:g:hH:iI:l:m:p:P:t:Tuvw c ; do +while getopts aAc:C:d:e:Ef:F:g:hH:iI:l:m:p:P:t:Tuvw c ; do case $c in a) bhyverun_opt="${bhyverun_opt} -a" ;; + A) + disk_emulation="ahci-hd" + ;; c) cpus=${OPTARG} ;; @@ -316,7 +321,7 @@ while [ 1 ]; do eval "disk=\$disk_dev${i}" eval "opts=\$disk_opts${i}" make_and_check_diskdev "${disk}" - devargs="$devargs -s $nextslot:0,virtio-blk,${disk}${opts} " + devargs="$devargs -s $nextslot:0,$disk_emulation,${disk}${opts} " nextslot=$(($nextslot + 1)) i=$(($i + 1)) done diff --git a/stand/common/load_elf.c b/stand/common/load_elf.c index 679842b9423e..cccd585860a3 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -456,7 +456,7 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) * think the rule is going to have to be that you must strip a * file to remove symbols before gzipping it. */ - chunk = ehdr->e_shnum * ehdr->e_shentsize; + chunk = (size_t)ehdr->e_shnum * (size_t)ehdr->e_shentsize; if (chunk == 0 || ehdr->e_shoff == 0) goto nosyms; shdr = alloc_pread(ef->fd, ehdr->e_shoff, chunk); @@ -747,7 +747,7 @@ __elfN(load_modmetadata)(struct preloaded_file *fp, u_int64_t dest) goto out; } - size = ef.ehdr->e_shnum * ef.ehdr->e_shentsize; + size = (size_t)ef.ehdr->e_shnum * (size_t)ef.ehdr->e_shentsize; shdr = alloc_pread(ef.fd, ef.ehdr->e_shoff, size); if (shdr == NULL) { err = ENOMEM; diff --git a/stand/userboot/test/test.c b/stand/userboot/test/test.c index bacde565ec3b..1cee79ce1049 100644 --- a/stand/userboot/test/test.c +++ b/stand/userboot/test/test.c @@ -422,7 +422,7 @@ int main(int argc, char** argv) { void *h; - void (*func)(struct loader_callbacks *, void *, int, int); + void (*func)(struct loader_callbacks *, void *, int, int) __dead2; int opt; char *disk_image = NULL; const char *userboot_obj = "/boot/userboot.so"; diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 3175616d0ce0..0c16da1327dc 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -604,7 +604,6 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) regs->tf_fs = _ufssel; regs->tf_gs = _ugssel; regs->tf_flags = TF_HASSEGS; - td->td_retval[1] = 0; /* * Reset the hardware debug registers if they were in use. diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c index 79131f3f561c..b1fc8debc1f9 100644 --- a/sys/amd64/ia32/ia32_signal.c +++ b/sys/amd64/ia32/ia32_signal.c @@ -967,5 +967,4 @@ ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack) /* Return via doreti so that we can change to a different %cs */ set_pcb_flags(pcb, PCB_32BIT | PCB_FULL_IRET); - td->td_retval[1] = 0; } diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 8b0a35ea0bfa..1a0dc1c954b7 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -832,7 +832,6 @@ exec_linux_setregs(struct thread *td, struct image_params *imgp, u_long stack) /* Do full restore on return so that we can change to a different %cs */ set_pcb_flags(pcb, PCB_32BIT | PCB_FULL_IRET); - td->td_retval[1] = 0; } /* diff --git a/sys/amd64/vmm/amd/amdvi_hw.c b/sys/amd64/vmm/amd/amdvi_hw.c index 22d4a12e3210..3478262a7346 100644 --- a/sys/amd64/vmm/amd/amdvi_hw.c +++ b/sys/amd64/vmm/amd/amdvi_hw.c @@ -582,7 +582,7 @@ amdvi_decode_evt_flag(uint16_t flag) { flag &= AMDVI_EVENT_FLAG_MASK; - printf("0x%b]\n", flag, + printf(" 0x%b]\n", flag, "\020" "\001GN" "\002NX" @@ -692,7 +692,7 @@ amdvi_decode_evt(struct amdvi_event *evt) case AMDVI_EVENT_ILLEGAL_CMD: /* FALL THROUGH */ case AMDVI_EVENT_CMD_HW_ERROR: - printf("\t[%s EVT]", (evt->opcode == AMDVI_EVENT_ILLEGAL_CMD) ? + printf("\t[%s EVT]\n", (evt->opcode == AMDVI_EVENT_ILLEGAL_CMD) ? "ILLEGAL CMD" : "CMD HW ERR"); cmd = (struct amdvi_cmd *)PHYS_TO_DMAP(evt->addr); printf("\tCMD opcode= 0x%x 0x%x 0x%x 0x%lx\n", @@ -700,13 +700,14 @@ amdvi_decode_evt(struct amdvi_event *evt) break; case AMDVI_EVENT_IOTLB_TIMEOUT: - printf("\t[IOTLB_INV_TIMEOUT devid:0x%x addr:0x%lx", + printf("\t[IOTLB_INV_TIMEOUT devid:0x%x addr:0x%lx]\n", evt->devid, evt->addr); break; case AMDVI_EVENT_INVALID_DTE_REQ: - printf("\t[INV_DTE devid:0x%x addr:0x%lx", - evt->devid, evt->addr); + printf("\t[INV_DTE devid:0x%x addr:0x%lx type:0x%x tr:%d]\n", + evt->devid, evt->addr, evt->flag >> 9, + (evt->flag >> 8) & 1); break; case AMDVI_EVENT_INVALID_PPR_REQ: @@ -715,7 +716,7 @@ amdvi_decode_evt(struct amdvi_event *evt) break; default: - printf("Unsupported AMD-Vi event:%d", evt->opcode); + printf("Unsupported AMD-Vi event:%d\n", evt->opcode); } } @@ -988,15 +989,12 @@ amdvi_add_sysctl(struct amdvi_softc *softc) &softc->event_intr_cnt, "Event interrupt count"); SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "command_count", CTLFLAG_RD, &softc->total_cmd, "Command submitted count"); - SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "pci_rid", CTLFLAG_RD, - (int *)&softc->pci_rid, 0, - "IOMMU RID"); - SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "start_dev_rid", CTLFLAG_RD, - (int *)&softc->start_dev_rid, 0, - "Start of device under this IOMMU"); - SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "end_dev_rid", CTLFLAG_RD, - (int *)&softc->end_dev_rid, 0, - "End of device under this IOMMU"); + SYSCTL_ADD_U16(ctx, child, OID_AUTO, "pci_rid", CTLFLAG_RD, + &softc->pci_rid, 0, "IOMMU RID"); + SYSCTL_ADD_U16(ctx, child, OID_AUTO, "start_dev_rid", CTLFLAG_RD, + &softc->start_dev_rid, 0, "Start of device under this IOMMU"); + SYSCTL_ADD_U16(ctx, child, OID_AUTO, "end_dev_rid", CTLFLAG_RD, + &softc->end_dev_rid, 0, "End of device under this IOMMU"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "command_head", CTLTYPE_UINT | CTLFLAG_RD, softc, 0, amdvi_handle_sysctl, "IU", "Command head"); diff --git a/sys/amd64/vmm/amd/amdvi_priv.h b/sys/amd64/vmm/amd/amdvi_priv.h index c292d3ef9881..8d4553fe1a3c 100755 --- a/sys/amd64/vmm/amd/amdvi_priv.h +++ b/sys/amd64/vmm/amd/amdvi_priv.h @@ -230,8 +230,8 @@ struct amdvi_ctrl { uint64_t :45; uint32_t evt_tail:19; uint64_t :45; - uint64_t :56; - uint8_t status:8; + uint32_t status:19; + uint64_t :45; uint64_t pad2; uint8_t :4; uint16_t ppr_head:15; diff --git a/sys/amd64/vmm/amd/ivrs_drv.c b/sys/amd64/vmm/amd/ivrs_drv.c index dc47717006a0..bc30d83c6ca5 100755 --- a/sys/amd64/vmm/amd/ivrs_drv.c +++ b/sys/amd64/vmm/amd/ivrs_drv.c @@ -88,7 +88,7 @@ ivrs_hdr_iterate_tbl(ivhd_iter_t iter, void *arg) if (!iter(ivrs_hdr, arg)) return; break; - + case ACPI_IVRS_TYPE_MEMORY1: case ACPI_IVRS_TYPE_MEMORY2: case ACPI_IVRS_TYPE_MEMORY3: @@ -96,7 +96,7 @@ ivrs_hdr_iterate_tbl(ivhd_iter_t iter, void *arg) return; break; - + default: printf("AMD-Vi:Not IVHD/IVMD type(%d)", ivrs_hdr->Type); @@ -186,7 +186,8 @@ ivhd_dev_add_entry(struct amdvi_softc *softc, uint32_t start_id, static int ivhd_dev_parse(ACPI_IVRS_HARDWARE * ivhd, struct amdvi_softc *softc) { - ACPI_IVRS_DE_HEADER *de, *end; + ACPI_IVRS_DE_HEADER *de; + uint8_t *p, *end; int range_start_id = 0, range_end_id = 0; uint32_t *extended; uint8_t all_data = 0, range_data = 0; @@ -195,12 +196,15 @@ ivhd_dev_parse(ACPI_IVRS_HARDWARE * ivhd, struct amdvi_softc *softc) softc->start_dev_rid = ~0; softc->end_dev_rid = 0; - de = (ACPI_IVRS_DE_HEADER *) ((uint8_t *)ivhd + - sizeof(ACPI_IVRS_HARDWARE)); - end = (ACPI_IVRS_DE_HEADER *) ((uint8_t *)ivhd + - ivhd->Header.Length); + /* + * XXX The following actually depends on Header.Type and + * is only true for 0x10. + */ + p = (uint8_t *)ivhd + sizeof(ACPI_IVRS_HARDWARE); + end = (uint8_t *)ivhd + ivhd->Header.Length; - while (de < (ACPI_IVRS_DE_HEADER *) end) { + while (p < end) { + de = (ACPI_IVRS_DE_HEADER *)p; softc->start_dev_rid = MIN(softc->start_dev_rid, de->Id); softc->end_dev_rid = MAX(softc->end_dev_rid, de->Id); switch (de->Type) { @@ -263,7 +267,15 @@ ivhd_dev_parse(ACPI_IVRS_HARDWARE * ivhd, struct amdvi_softc *softc) "WARN Too many device entries.\n"); return (EINVAL); } - de++; + if (de->Type < 0x40) + p += sizeof(ACPI_IVRS_DEVICE4); + else if (de->Type < 0x80) + p += sizeof(ACPI_IVRS_DEVICE8A); + else { + printf("Variable size IVHD type 0x%x not supported\n", + de->Type); + break; + } } KASSERT((softc->end_dev_rid >= softc->start_dev_rid), diff --git a/sys/arm/allwinner/clkng/aw_ccung.c b/sys/arm/allwinner/clkng/aw_ccung.c index 416a3c08bcf9..41ee55b4baf2 100644 --- a/sys/arm/allwinner/clkng/aw_ccung.c +++ b/sys/arm/allwinner/clkng/aw_ccung.c @@ -76,6 +76,10 @@ __FBSDID("$FreeBSD$"); #include #endif +#if defined(SOC_ALLWINNER_A83T) +#include +#endif + #include "clkdev_if.h" #include "hwreset_if.h" @@ -102,6 +106,10 @@ static struct resource_spec aw_ccung_spec[] = { #define A13_CCU 6 #endif +#if defined(SOC_ALLWINNER_A83T) +#define A83T_CCU 7 +#endif + static struct ofw_compat_data compat_data[] = { #if defined(SOC_ALLWINNER_A31) { "allwinner,sun5i-a13-ccu", A13_CCU}, @@ -116,6 +124,9 @@ static struct ofw_compat_data compat_data[] = { #if defined(SOC_ALLWINNER_A64) { "allwinner,sun50i-a64-ccu", A64_CCU }, { "allwinner,sun50i-a64-r-ccu", A64_R_CCU }, +#endif +#if defined(SOC_ALLWINNER_A83T) + { "allwinner,sun8i-a83t-ccu", A83T_CCU }, #endif {NULL, 0 } }; @@ -358,6 +369,11 @@ aw_ccung_attach(device_t dev) case A64_R_CCU: ccu_sun8i_r_register_clocks(sc); break; +#endif +#if defined(SOC_ALLWINNER_A83T) + case A83T_CCU: + ccu_a83t_register_clocks(sc); + break; #endif } diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index 689f7686d4c9..04fd482170e7 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -518,6 +518,16 @@ set_mcontext(struct thread *td, mcontext_t *mcp) mcontext_vfp_t mc_vfp, *vfp; struct trapframe *tf = td->td_frame; const __greg_t *gr = mcp->__gregs; + int spsr; + + /* + * Make sure the processor mode has not been tampered with and + * interrupts have not been disabled. + */ + spsr = gr[_REG_CPSR]; + if ((spsr & PSR_MODE) != PSR_USR32_MODE || + (spsr & (PSR_I | PSR_F)) != 0) + return (EINVAL); #ifdef WITNESS if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_size != sizeof(mc_vfp)) { @@ -677,22 +687,16 @@ sys_sigreturn(td, uap) } */ *uap; { ucontext_t uc; - int spsr; + int error; if (uap == NULL) return (EFAULT); if (copyin(uap->sigcntxp, &uc, sizeof(uc))) return (EFAULT); - /* - * Make sure the processor mode has not been tampered with and - * interrupts have not been disabled. - */ - spsr = uc.uc_mcontext.__gregs[_REG_CPSR]; - if ((spsr & PSR_MODE) != PSR_USR32_MODE || - (spsr & (PSR_I | PSR_F)) != 0) - return (EINVAL); /* Restore register context. */ - set_mcontext(td, &uc.uc_mcontext); + error = set_mcontext(td, &uc.uc_mcontext); + if (error != 0) + return (error); /* Restore signal mask. */ kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0); diff --git a/sys/arm/cloudabi32/cloudabi32_sysvec.c b/sys/arm/cloudabi32/cloudabi32_sysvec.c index a0bebcc99641..eeeb93c188c7 100644 --- a/sys/arm/cloudabi32/cloudabi32_sysvec.c +++ b/sys/arm/cloudabi32/cloudabi32_sysvec.c @@ -61,7 +61,7 @@ cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp, * tpidrurw to the TCB. */ regs = td->td_frame; - regs->tf_r0 = td->td_retval[0] = + regs->tf_r0 = stack + roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t)); (void)cpu_set_user_tls(td, (void *)stack); } diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index 886792a9681d..452f224797af 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -211,7 +211,8 @@ set_regs(struct thread *td, struct reg *regs) frame->tf_sp = regs->sp; frame->tf_lr = regs->lr; frame->tf_elr = regs->elr; - frame->tf_spsr = regs->spsr; + frame->tf_spsr &= ~PSR_FLAGS; + frame->tf_spsr |= regs->spsr & PSR_FLAGS; memcpy(frame->tf_x, regs->x, sizeof(frame->tf_x)); @@ -310,12 +311,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) memset(tf, 0, sizeof(struct trapframe)); - /* - * We need to set x0 for init as it doesn't call - * cpu_set_syscall_retval to copy the value. We also - * need to set td_retval for the cases where we do. - */ - tf->tf_x[0] = td->td_retval[0] = stack; + tf->tf_x[0] = stack; tf->tf_sp = STACKALIGN(stack); tf->tf_lr = imgp->entry_addr; tf->tf_elr = imgp->entry_addr; @@ -354,6 +350,12 @@ int set_mcontext(struct thread *td, mcontext_t *mcp) { struct trapframe *tf = td->td_frame; + uint32_t spsr; + + spsr = mcp->mc_gpregs.gp_spsr; + if ((spsr & PSR_M_MASK) != PSR_M_EL0t || + (spsr & (PSR_F | PSR_I | PSR_A | PSR_D)) != 0) + return (EINVAL); memcpy(tf->tf_x, mcp->mc_gpregs.gp_x, sizeof(tf->tf_x)); @@ -530,19 +532,16 @@ int sys_sigreturn(struct thread *td, struct sigreturn_args *uap) { ucontext_t uc; - uint32_t spsr; + int error; if (uap == NULL) return (EFAULT); if (copyin(uap->sigcntxp, &uc, sizeof(uc))) return (EFAULT); - spsr = uc.uc_mcontext.mc_gpregs.gp_spsr; - if ((spsr & PSR_M_MASK) != PSR_M_EL0t || - (spsr & (PSR_F | PSR_I | PSR_A | PSR_D)) != 0) - return (EINVAL); - - set_mcontext(td, &uc.uc_mcontext); + error = set_mcontext(td, &uc.uc_mcontext); + if (error != 0) + return (error); set_fpcontext(td, &uc.uc_mcontext); /* Restore signal mask. */ diff --git a/sys/arm64/cloudabi64/cloudabi64_sysvec.c b/sys/arm64/cloudabi64/cloudabi64_sysvec.c index f6e75f563668..a98ff0e2c305 100644 --- a/sys/arm64/cloudabi64/cloudabi64_sysvec.c +++ b/sys/arm64/cloudabi64/cloudabi64_sysvec.c @@ -61,7 +61,7 @@ cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp, * tpidr_el0 to the TCB. */ regs = td->td_frame; - regs->tf_x[0] = td->td_retval[0] = + regs->tf_x[0] = stack + roundup(sizeof(cloudabi64_tcb_t), sizeof(register_t)); (void)cpu_set_user_tls(td, (void *)stack); } diff --git a/sys/arm64/include/armreg.h b/sys/arm64/include/armreg.h index a7a15fc87850..cf24fadf1623 100644 --- a/sys/arm64/include/armreg.h +++ b/sys/arm64/include/armreg.h @@ -572,6 +572,7 @@ #define PSR_C 0x20000000 #define PSR_Z 0x40000000 #define PSR_N 0x80000000 +#define PSR_FLAGS 0xf0000000 /* TCR_EL1 - Translation Control Register */ #define TCR_ASID_16 (1 << 36) diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c index 82353cbb235d..9e6bde2eac48 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c +++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c @@ -601,8 +601,8 @@ fasttrap_fork(proc_t *p, proc_t *cp) pid_t ppid = p->p_pid; int i; -#ifdef illumos ASSERT(curproc == p); +#ifdef illumos ASSERT(p->p_proc_flag & P_PR_LOCK); #else PROC_LOCK_ASSERT(p, MA_OWNED); @@ -610,26 +610,15 @@ fasttrap_fork(proc_t *p, proc_t *cp) #ifdef illumos ASSERT(p->p_dtrace_count > 0); #else - if (p->p_dtrace_helpers) { - /* - * dtrace_helpers_duplicate() allocates memory. - */ - _PHOLD(cp); - PROC_UNLOCK(p); - PROC_UNLOCK(cp); - dtrace_helpers_duplicate(p, cp); - PROC_LOCK(cp); - PROC_LOCK(p); - _PRELE(cp); - } /* * This check is purposely here instead of in kern_fork.c because, * for legal resons, we cannot include the dtrace_cddl.h header * inside kern_fork.c and insert if-clause there. */ - if (p->p_dtrace_count == 0) + if (p->p_dtrace_count == 0 && p->p_dtrace_helpers == NULL) return; #endif + ASSERT(cp->p_dtrace_count == 0); /* @@ -658,6 +647,8 @@ fasttrap_fork(proc_t *p, proc_t *cp) _PHOLD(cp); PROC_UNLOCK(cp); PROC_UNLOCK(p); + if (p->p_dtrace_count == 0) + goto dup_helpers; #endif /* @@ -711,6 +702,9 @@ fasttrap_fork(proc_t *p, proc_t *cp) mutex_enter(&cp->p_lock); sprunlock(cp); #else +dup_helpers: + if (p->p_dtrace_helpers != NULL) + dtrace_helpers_duplicate(p, cp); PROC_LOCK(p); PROC_LOCK(cp); _PRELE(cp); diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c index b244eea3b677..8be4fa2df0c9 100644 --- a/sys/compat/linux/linux_emul.c +++ b/sys/compat/linux/linux_emul.c @@ -186,7 +186,7 @@ linux_common_execve(struct thread *td, struct image_args *eargs) error = kern_execve(td, eargs, NULL); post_execve(td, error, oldvmspace); - if (error != 0) + if (error != EJUSTRETURN) return (error); /* @@ -213,7 +213,7 @@ linux_common_execve(struct thread *td, struct image_args *eargs) free(em, M_TEMP); free(pem, M_LINUX); } - return (0); + return (EJUSTRETURN); } void diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c index 7f8f670d7461..4a5f542c1de5 100644 --- a/sys/geom/mirror/g_mirror.c +++ b/sys/geom/mirror/g_mirror.c @@ -54,8 +54,8 @@ static MALLOC_DEFINE(M_MIRROR, "mirror_data", "GEOM_MIRROR Data"); SYSCTL_DECL(_kern_geom); static SYSCTL_NODE(_kern_geom, OID_AUTO, mirror, CTLFLAG_RW, 0, "GEOM_MIRROR stuff"); -u_int g_mirror_debug = 0; -SYSCTL_UINT(_kern_geom_mirror, OID_AUTO, debug, CTLFLAG_RWTUN, &g_mirror_debug, 0, +int g_mirror_debug = 0; +SYSCTL_INT(_kern_geom_mirror, OID_AUTO, debug, CTLFLAG_RWTUN, &g_mirror_debug, 0, "Debug level"); static u_int g_mirror_timeout = 4; SYSCTL_UINT(_kern_geom_mirror, OID_AUTO, timeout, CTLFLAG_RWTUN, &g_mirror_timeout, diff --git a/sys/geom/mirror/g_mirror.h b/sys/geom/mirror/g_mirror.h index f3a4a0070093..3b9664035c98 100644 --- a/sys/geom/mirror/g_mirror.h +++ b/sys/geom/mirror/g_mirror.h @@ -72,7 +72,7 @@ G_MIRROR_DEVICE_FLAG_NOFAILSYNC) #ifdef _KERNEL -extern u_int g_mirror_debug; +extern int g_mirror_debug; #define G_MIRROR_DEBUG(lvl, ...) do { \ if (g_mirror_debug >= (lvl)) { \ diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 68a452208582..dac5fd6967ec 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -1126,6 +1126,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) set_fsbase(td, 0); set_gsbase(td, 0); + /* Make sure edx is 0x0 on entry. Linux binaries depend on it. */ bzero((char *)regs, sizeof(struct trapframe)); regs->tf_eip = imgp->entry_addr; regs->tf_esp = stack; @@ -1168,13 +1169,6 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) * clean FP state if it uses the FPU again. */ fpstate_drop(td); - - /* - * XXX - Linux emulator - * Make sure sure edx is 0x0 on entry. Linux binaries depend - * on it. - */ - td->td_retval[1] = 0; } void diff --git a/sys/i386/include/atomic.h b/sys/i386/include/atomic.h index c167cf5c0fae..7cd5b0d2a7e4 100644 --- a/sys/i386/include/atomic.h +++ b/sys/i386/include/atomic.h @@ -129,6 +129,7 @@ int atomic_cmpset_64(volatile uint64_t *, uint64_t, uint64_t); uint64_t atomic_load_acq_64(volatile uint64_t *); void atomic_store_rel_64(volatile uint64_t *, uint64_t); uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); +uint64_t atomic_fetchadd_64(volatile uint64_t *, uint64_t); #else /* !KLD_MODULE && __GNUCLIKE_ASM */ @@ -565,6 +566,17 @@ atomic_swap_64(volatile uint64_t *p, uint64_t v) return (atomic_swap_64_i586(p, v)); } +static __inline uint64_t +atomic_fetchadd_64(volatile uint64_t *p, uint64_t v) +{ + + for (;;) { + uint64_t t = *p; + if (atomic_cmpset_64(p, t, t + v)) + return (t); + } +} + #endif /* _KERNEL */ #endif /* KLD_MODULE || !__GNUCLIKE_ASM */ diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 645d120d9807..dbd7a4ac07c7 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -797,7 +797,7 @@ start_init(void *dummy) * Otherwise, return via fork_trampoline() all the way * to user mode as init! */ - if ((error = sys_execve(td, &args)) == 0) { + if ((error = sys_execve(td, &args)) == EJUSTRETURN) { mtx_unlock(&Giant); return; } diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index f844a61967c6..284e08a801af 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -318,7 +318,7 @@ post_execve(struct thread *td, int error, struct vmspace *oldvmspace) * If success, we upgrade to SINGLE_EXIT state to * force other threads to suicide. */ - if (error == 0) + if (error == EJUSTRETURN) thread_single(p, SINGLE_EXIT); else thread_single_end(p, SINGLE_BOUNDARY); @@ -962,7 +962,13 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p) ktrprocctor(p); #endif - return (error); + /* + * We don't want cpu_set_syscall_retval() to overwrite any of + * the register values put in place by exec_setregs(). + * Implementations of cpu_set_syscall_retval() will leave + * registers unmodified when returning EJUSTRETURN. + */ + return (error == 0 ? EJUSTRETURN : error); } int diff --git a/sys/netinet/sctp_ss_functions.c b/sys/netinet/sctp_ss_functions.c index 22d3deb58fd9..3099c4893c47 100644 --- a/sys/netinet/sctp_ss_functions.c +++ b/sys/netinet/sctp_ss_functions.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause + * * Copyright (c) 2010-2012, by Michael Tuexen. All rights reserved. * Copyright (c) 2010-2012, by Randall Stewart. All rights reserved. * Copyright (c) 2010-2012, by Robin Seggelmann. All rights reserved. diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index 596ae8079f19..724ae849a069 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -520,22 +520,11 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) * - ps_strings is a NetBSD extention, and will be * ignored by executables which are strictly * compliant with the SVR4 ABI. - * - * XXX We have to set both regs and retval here due to different - * XXX calling convention in trap.c and init_main.c. */ /* Collect argc from the user stack */ argc = fuword((void *)stack); - /* - * XXX PG: these get overwritten in the syscall return code. - * execve() should return EJUSTRETURN, like it does on NetBSD. - * Emulate by setting the syscall return value cells. The - * registers still have to be set for init's fork trampoline. - */ - td->td_retval[0] = argc; - td->td_retval[1] = stack + sizeof(register_t); tf->fixreg[3] = argc; tf->fixreg[4] = stack + sizeof(register_t); tf->fixreg[5] = stack + (2 + argc)*sizeof(register_t); @@ -572,8 +561,6 @@ ppc32_setregs(struct thread *td, struct image_params *imgp, u_long stack) argc = fuword32((void *)stack); - td->td_retval[0] = argc; - td->td_retval[1] = stack + sizeof(uint32_t); tf->fixreg[3] = argc; tf->fixreg[4] = stack + sizeof(uint32_t); tf->fixreg[5] = stack + (2 + argc)*sizeof(uint32_t); diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index d8a968791a05..de1a71e4d2eb 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -279,12 +279,7 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) memset(tf, 0, sizeof(struct trapframe)); - /* - * We need to set a0 for init as it doesn't call - * cpu_set_syscall_retval to copy the value. We also - * need to set td_retval for the cases where we do. - */ - tf->tf_a[0] = td->td_retval[0] = stack; + tf->tf_a[0] = stack; tf->tf_sp = STACKALIGN(stack); tf->tf_ra = imgp->entry_addr; tf->tf_sepc = imgp->entry_addr; diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c index 9d917afafbbd..d450d436379e 100644 --- a/sys/sparc64/sparc64/machdep.c +++ b/sys/sparc64/sparc64/machdep.c @@ -1009,9 +1009,6 @@ exec_setregs(struct thread *td, struct image_params *imgp, u_long stack) * header, it turns out that just always using TSO performs best. */ tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO; - - td->td_retval[0] = tf->tf_out[0]; - td->td_retval[1] = tf->tf_out[1]; } int diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 2c1e61203c2e..ac18efcbb337 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -665,7 +665,7 @@ getcpuinfo(u_long *maskp, int *maxidp) static void -prthuman(const char *name, u_int64_t val, int size) +prthuman(const char *name, uint64_t val, int size) { char buf[10]; int flags; @@ -817,22 +817,22 @@ dovmstat(unsigned int interval, int reps) total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); xo_close_container("processes"); xo_open_container("memory"); -#define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10)) +#define vmstat_pgtok(a) ((uintmax_t)(a) * (sum.v_page_size >> 10)) #define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */ if (hflag) { xo_emit(""); prthuman("available-memory", - total.t_avm * (u_int64_t)sum.v_page_size, 5); + total.t_avm * (uint64_t)sum.v_page_size, 5); xo_emit(" "); prthuman("free-memory", - total.t_free * (u_int64_t)sum.v_page_size, 5); + total.t_free * (uint64_t)sum.v_page_size, 5); xo_emit(" "); } else { xo_emit(" "); - xo_emit("{:available-memory/%7d}", + xo_emit("{:available-memory/%7ju}", vmstat_pgtok(total.t_avm)); xo_emit(" "); - xo_emit("{:free-memory/%7d}", + xo_emit("{:free-memory/%7ju}", vmstat_pgtok(total.t_free)); xo_emit(" "); } @@ -1555,9 +1555,9 @@ display_object(struct kinfo_vmobject *kvo) const char *str; xo_open_instance("object"); - xo_emit("{:resident/%5jd} ", (uintmax_t)kvo->kvo_resident); - xo_emit("{:active/%5jd} ", (uintmax_t)kvo->kvo_active); - xo_emit("{:inactive/%5jd} ", (uintmax_t)kvo->kvo_inactive); + xo_emit("{:resident/%5ju} ", (uintmax_t)kvo->kvo_resident); + xo_emit("{:active/%5ju} ", (uintmax_t)kvo->kvo_active); + xo_emit("{:inactive/%5ju} ", (uintmax_t)kvo->kvo_inactive); xo_emit("{:refcount/%3d} ", kvo->kvo_ref_count); xo_emit("{:shadowcount/%3d} ", kvo->kvo_shadow_count); switch (kvo->kvo_memattr) {