Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet: TODO Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev: cyclic diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtmalloc/dtmalloc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtmalloc/dtmalloc.c --- /tmp/out/external/cddl/osnet/dev/dtmalloc/dtmalloc.c 2013-09-02 04:38:06.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtmalloc/dtmalloc.c 2017-06-10 09:13:27.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtmalloc.c,v 1.2 2010/02/21 01:46:33 darran Exp $ */ + /* * CDDL HEADER START * @@ -20,7 +22,7 @@ * * Portions Copyright 2006-2008 John Birrell jb@freebsd.org * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/dev/dtmalloc/dtmalloc.c 252325 2013-06-28 03:14:40Z markj $ * */ Only in /tmp/out/external/cddl/osnet/dev/dtrace: aarch64 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S --- /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S 2016-04-24 09:59:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S 2017-05-08 15:42:29.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_asm.S,v 1.7 2017/02/27 06:46:59 chs Exp $ */ + /* * CDDL HEADER START * @@ -30,11 +32,12 @@ #define _ASM -#include #include #include +#include +#define MEXITCOUNT -#include "assym.s" +#include "assym.h" #define INTR_POP \ MEXITCOUNT; \ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c --- /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c 2016-04-30 08:22:19.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c 2017-04-20 04:07:10.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_isa.c,v 1.6 2017/02/27 06:46:59 chs Exp $ */ + /* * CDDL HEADER START * @@ -30,17 +32,11 @@ #include #include #include -#include -#include #include -#include #include -#include -#include -#include -#include +#include #include "regset.h" @@ -49,6 +45,17 @@ uint32_t dtrace_fuword32_nocheck(void *); uint64_t dtrace_fuword64_nocheck(void *); +uintptr_t kernelbase = (uintptr_t)KERN_BASE; + +#define INKERNEL(va) ((intptr_t)(va) < 0) + +struct amd64_frame { + struct amd64_frame *f_frame; + uintptr_t f_retaddr; +}; + +typedef unsigned long vm_offset_t; + int dtrace_ustackdepth_max = 2048; void @@ -59,7 +66,7 @@ register_t rbp; struct amd64_frame *frame; vm_offset_t callpc; - pc_t caller = (pc_t) solaris_cpu[curcpu].cpu_dtrace_caller; + pc_t caller = (pc_t) solaris_cpu[cpu_number()].cpu_dtrace_caller; if (intrpc != 0) pcstack[depth++] = (pc_t) intrpc; @@ -89,8 +96,8 @@ } if (frame->f_frame <= frame || - (vm_offset_t)frame->f_frame >= curthread->td_kstack + - curthread->td_kstack_pages * PAGE_SIZE) + (vm_offset_t)frame->f_frame >= + (vm_offset_t)rbp + KSTACK_SIZE) break; frame = frame->f_frame; } @@ -106,7 +113,7 @@ { uintptr_t oldsp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; int ret = 0; ASSERT(pcstack == NULL || pcstack_limit > 0); @@ -119,7 +126,7 @@ */ if (ret++ >= dtrace_ustackdepth_max) { *flags |= CPU_DTRACE_BADSTACK; - cpu_core[curcpu].cpuc_dtrace_illval = sp; + cpu_core[cpu_number()].cpuc_dtrace_illval = sp; break; } @@ -141,7 +148,7 @@ if (sp == oldsp) { *flags |= CPU_DTRACE_BADSTACK; - cpu_core[curcpu].cpuc_dtrace_illval = sp; + cpu_core[cpu_number()].cpuc_dtrace_illval = sp; break; } @@ -166,7 +173,7 @@ struct trapframe *tf; uintptr_t pc, sp, fp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; int n; if (*flags & CPU_DTRACE_FAULT) @@ -178,7 +185,7 @@ /* * If there's no user context we still need to zero the stack. */ - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) goto zero; *pcstack++ = (uint64_t)p->p_pid; @@ -229,7 +236,7 @@ uintptr_t pc, fp, sp; int n = 0; - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) return (0); if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT)) @@ -265,7 +272,7 @@ struct trapframe *tf; uintptr_t pc, sp, fp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; #ifdef notyet /* XXX signal stack */ uintptr_t oldcontext; size_t s1, s2; @@ -280,7 +287,7 @@ /* * If there's no user context we still need to zero the stack. */ - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) goto zero; *pcstack++ = (uint64_t)p->p_pid; @@ -407,6 +414,10 @@ case 5: stack = (uintptr_t *)&tf->tf_r9; break; + default: + KASSERT(0); + stack = NULL; + break; } arg = 0; } else { @@ -447,6 +458,7 @@ DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); return (val); + return (0); } int @@ -467,8 +479,8 @@ break; depth++; if (frame->f_frame <= frame || - (vm_offset_t)frame->f_frame >= curthread->td_kstack + - curthread->td_kstack_pages * PAGE_SIZE) + (vm_offset_t)frame->f_frame >= + (vm_offset_t)rbp + KSTACK_SIZE) break; frame = frame->f_frame; } @@ -481,27 +493,27 @@ ulong_t dtrace_getreg(struct trapframe *rp, uint_t reg) { - /* This table is dependent on reg.d. */ + /* CHUQ skipped */ int regmap[] = { - REG_GS, /* 0 GS */ - REG_FS, /* 1 FS */ - REG_ES, /* 2 ES */ - REG_DS, /* 3 DS */ - REG_RDI, /* 4 EDI */ - REG_RSI, /* 5 ESI */ - REG_RBP, /* 6 EBP, REG_FP */ - REG_RSP, /* 7 ESP */ - REG_RBX, /* 8 EBX, REG_R1 */ - REG_RDX, /* 9 EDX */ - REG_RCX, /* 10 ECX */ - REG_RAX, /* 11 EAX, REG_R0 */ - REG_TRAPNO, /* 12 TRAPNO */ - REG_ERR, /* 13 ERR */ - REG_RIP, /* 14 EIP, REG_PC */ - REG_CS, /* 15 CS */ - REG_RFL, /* 16 EFL, REG_PS */ - REG_RSP, /* 17 UESP, REG_SP */ - REG_SS /* 18 SS */ + REG_GS, /* GS */ + REG_FS, /* FS */ + REG_ES, /* ES */ + REG_DS, /* DS */ + REG_RDI, /* EDI */ + REG_RSI, /* ESI */ + REG_RBP, /* EBP */ + REG_RSP, /* ESP */ + REG_RBX, /* EBX */ + REG_RDX, /* EDX */ + REG_RCX, /* ECX */ + REG_RAX, /* EAX */ + REG_TRAPNO, /* TRAPNO */ + REG_ERR, /* ERR */ + REG_RIP, /* EIP */ + REG_CS, /* CS */ + REG_RFL, /* EFL */ + REG_RSP, /* UESP */ + REG_SS /* SS */ }; if (reg <= SS) { @@ -512,7 +524,6 @@ reg = regmap[reg]; } else { - /* This is dependent on reg.d. */ reg -= SS + 1; } @@ -582,7 +593,7 @@ if (uaddr + size > VM_MAXUSER_ADDRESS || uaddr + size < uaddr) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = uaddr; return (0); } @@ -626,7 +637,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword8_nocheck(uaddr)); @@ -637,7 +648,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword16_nocheck(uaddr)); @@ -648,7 +659,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword32_nocheck(uaddr)); @@ -659,7 +670,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword64_nocheck(uaddr)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c --- /tmp/out/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c 2017-03-02 02:54:25.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c 2017-04-20 04:58:41.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_subr.c,v 1.8 2017/02/27 06:46:59 chs Exp $ */ + /* * CDDL HEADER START * @@ -31,22 +33,23 @@ * Copyright (c) 2011, Joyent, Inc. All rights reserved. */ +#include #include #include #include #include #include #include -#include +#include +#include +#include #include #include -#include -#include #include -#include -#include +#include +#include -extern void dtrace_getnanotime(struct timespec *tsp); +extern uintptr_t kernelbase; int dtrace_invop(uintptr_t, struct trapframe *, uintptr_t); @@ -57,6 +60,9 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; +void dtrace_gethrtime_init(void *); +void dtrace_getnanotime(struct timespec *); + int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax) { @@ -105,28 +111,42 @@ prev->dtih_next = hdlr->dtih_next; } - kmem_free(hdlr, 0); + kmem_free(hdlr, sizeof (dtrace_invop_hdlr_t)); } /*ARGSUSED*/ void dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit)) { - (*func)(0, (uintptr_t) addr_PTmap); + (*func)(0, kernelbase); +} + +static void +xcall_func(void *arg0, void *arg1) +{ + dtrace_xcall_t func = arg0; + + (*func)(arg1); } void dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg) { - cpuset_t cpus; + uint64_t where; - if (cpu == DTRACE_CPUALL) - cpus = all_cpus; - else - CPU_SETOF(cpu, &cpus); + if (cpu == DTRACE_CPUALL) { + where = xc_broadcast(0, xcall_func, func, arg); + } else { + struct cpu_info *cinfo = cpu_lookup(cpu); + + KASSERT(cinfo != NULL); + where = xc_unicast(0, xcall_func, func, arg, cinfo); + } + xc_wait(where); - smp_rendezvous_cpus(cpus, smp_no_rendevous_barrier, func, - smp_no_rendevous_barrier, arg); + /* XXX Q. Do we really need the other cpus to wait also? + * (see solaris:xc_sync()) + */ } static void @@ -240,43 +260,68 @@ } #endif +#ifdef __NetBSD__ +static __inline uint64_t +dtrace_rdtsc(void) +{ + uint32_t hi, lo; + + __asm volatile("rdtsc" : "=d" (hi), "=a" (lo)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} +#define rdtsc dtrace_rdtsc +#endif + +#ifdef notyet static int64_t tgt_cpu_tsc; static int64_t hst_cpu_tsc; -static int64_t tsc_skew[MAXCPU]; +#endif +static int64_t tsc_skew[MAXCPUS]; static uint64_t nsec_scale; /* See below for the explanation of this macro. */ #define SCALE_SHIFT 28 +#ifdef notyet +static void +dtrace_gethrtime_init_sync(void *arg) +{ +#ifdef CHECK_SYNC + /* + * Delay this function from returning on one + * of the CPUs to check that the synchronisation + * works. + */ + uintptr_t cpu = (uintptr_t) arg; + + if (cpu == cpu_number()) { + int i; + for (i = 0; i < 1000000000; i++) + tgt_cpu_tsc = rdtsc(); + tgt_cpu_tsc = 0; + } +#endif +} + static void dtrace_gethrtime_init_cpu(void *arg) { uintptr_t cpu = (uintptr_t) arg; - if (cpu == curcpu) + if (cpu == cpu_number()) tgt_cpu_tsc = rdtsc(); else hst_cpu_tsc = rdtsc(); } +#endif -#ifdef EARLY_AP_STARTUP -static void +void dtrace_gethrtime_init(void *arg) { - struct pcpu *pc; - uint64_t tsc_f; - cpuset_t map; - int i; -#else -/* - * Get the frequency and scale factor as early as possible so that they can be - * used for boot-time tracing. - */ -static void -dtrace_gethrtime_init_early(void *arg) -{ uint64_t tsc_f; -#endif + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo = curcpu(); + cpuid_t cur_cpuid = cpu_number(); /* current cpu id */ /* * Get TSC frequency known at this moment. @@ -284,7 +329,7 @@ * Otherwise tick->time conversion will be inaccurate, but * will preserve monotonic property of TSC. */ - tsc_f = atomic_load_acq_64(&tsc_freq); + tsc_f = cpu_frequency(cinfo); /* * The following line checks that nsec_scale calculated below @@ -292,8 +337,7 @@ * another 32-bit integer without overflowing 64-bit. * Thus minimum supported TSC frequency is 62.5MHz. */ - KASSERT(tsc_f > (NANOSEC >> (32 - SCALE_SHIFT)), - ("TSC frequency is too low")); + KASSERT(tsc_f > (NANOSEC >> (32 - SCALE_SHIFT))); /* * We scale up NANOSEC/tsc_f ratio to preserve as much precision @@ -305,45 +349,15 @@ * (terahertz) values; */ nsec_scale = ((uint64_t)NANOSEC << SCALE_SHIFT) / tsc_f; -#ifndef EARLY_AP_STARTUP -} -SYSINIT(dtrace_gethrtime_init_early, SI_SUB_CPU, SI_ORDER_ANY, - dtrace_gethrtime_init_early, NULL); - -static void -dtrace_gethrtime_init(void *arg) -{ - struct pcpu *pc; - cpuset_t map; - int i; -#endif /* The current CPU is the reference one. */ - sched_pin(); - tsc_skew[curcpu] = 0; - CPU_FOREACH(i) { - if (i == curcpu) - continue; - - pc = pcpu_find(i); - CPU_SETOF(PCPU_GET(cpuid), &map); - CPU_SET(pc->pc_cpuid, &map); - - smp_rendezvous_cpus(map, NULL, - dtrace_gethrtime_init_cpu, - smp_no_rendevous_barrier, (void *)(uintptr_t) i); + tsc_skew[cur_cpuid] = 0; - tsc_skew[i] = tgt_cpu_tsc - hst_cpu_tsc; + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + /* use skew relative to cpu 0 */ + tsc_skew[cpu_index(cinfo)] = cinfo->ci_data.cpu_cc_skew; } - sched_unpin(); } -#ifdef EARLY_AP_STARTUP -SYSINIT(dtrace_gethrtime_init, SI_SUB_DTRACE, SI_ORDER_ANY, - dtrace_gethrtime_init, NULL); -#else -SYSINIT(dtrace_gethrtime_init, SI_SUB_SMP, SI_ORDER_ANY, dtrace_gethrtime_init, - NULL); -#endif /* * DTrace needs a high resolution time function which can @@ -365,7 +379,7 @@ * (see nsec_scale calculations) taking into account 32-bit shift of * the higher half and finally add. */ - tsc = rdtsc() - tsc_skew[curcpu]; + tsc = rdtsc() + tsc_skew[cpu_number()]; lo = tsc; hi = tsc >> 32; return (((lo * nsec_scale) >> SCALE_SHIFT) + @@ -382,26 +396,26 @@ return (current_time.tv_sec * 1000000000ULL + current_time.tv_nsec); } -/* Function to handle DTrace traps during probes. See amd64/amd64/trap.c. */ +/* Function to handle DTrace traps during probes. See amd64/amd64/trap.c */ int dtrace_trap(struct trapframe *frame, u_int type) { - uint16_t nofault; + bool nofault; + cpuid_t cpuid = cpu_number(); /* current cpu id */ /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in its per-cpu flags to indicate that it doesn't - * want to fault. On returning from the probe, the no-fault + * a flag in it's per-cpu flags to indicate that it doesn't + * want to fault. On returning from the the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: + * */ - sched_pin(); - nofault = cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT; - sched_unpin(); + nofault = (cpu_core[cpuid].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0; if (nofault) { - KASSERT((read_rflags() & PSL_I) == 0, ("interrupts enabled")); + KASSERTMSG((read_rflags() & PSL_I) == 0, "interrupts enabled"); /* * There are only a couple of trap types that are expected. @@ -411,7 +425,7 @@ /* General protection fault. */ case T_PROTFLT: /* Flag an illegal operation. */ - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP; + cpu_core[cpuid].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP; /* * Offset the instruction pointer to the instruction @@ -422,8 +436,8 @@ /* Page fault. */ case T_PAGEFLT: /* Flag a bad address. */ - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; - cpu_core[curcpu].cpuc_dtrace_illval = frame->tf_addr; + cpu_core[cpuid].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; + cpu_core[cpuid].cpuc_dtrace_illval = rcr2(); /* * Offset the instruction pointer to the instruction diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_asm.S /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_asm.S --- /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_asm.S 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_asm.S 2017-04-24 19:37:35.000000000 -0700 @@ -33,9 +33,17 @@ #include #include -#include +#include -#include "assym.s" +#define PSR_I I32_bit +#define PSR_F F32_bit + +#ifdef __ARM_BIG_ENDIAN +#define __BIG_ENDIAN 1 +#endif + +#define EENTRY(x) ENTRY_NP(x) +#define EEND(x) /* nothing */ /* void dtrace_membar_producer(void) @@ -66,13 +74,14 @@ void dtrace_interrupt_enable(dtrace_icookie_t cookie) */ ENTRY(dtrace_interrupt_enable) - and r0, r0, #(PSR_I | PSR_F) + and r0, r0, #(PSR_I | PSR_F) mrs r1, cpsr bic r1, r1, #(PSR_I | PSR_F) orr r1, r1, r0 msr cpsr_c, r1 RET END(dtrace_interrupt_enable) + /* uint8_t dtrace_fuword8_nocheck(void *addr) @@ -130,7 +139,7 @@ dtrace_copy(uintptr_t uaddr, uintptr_t kaddr, size_t size) */ ENTRY(dtrace_copy) - stmfd sp!, {r4-r5} /* stack is 8 byte aligned */ + stmfd sp!, {r4-r5} /* stack is 8 byte aligned */ teq r2, #0x00000000 mov r5, #0x00000000 beq 2f @@ -184,8 +193,10 @@ void * dtrace_casptr(volatile void *target, volatile void *cmp, volatile void *new) */ -ENTRY(dtrace_cas32) EENTRY(dtrace_casptr) +ENTRY(dtrace_cas32) +#if __ARM_ARCH >= 6 + 1: ldrex r3, [r0] /* Load target */ cmp r3, r1 /* Check if *target == cmp */ bne 2f /* No, return */ @@ -194,5 +205,33 @@ bne 1b /* No, try again */ 2: mov r0, r3 /* Return the value loaded from target */ RET -EEND(dtrace_casptr) + +#else + + /* + * We don't support MP on CPUs older than v6, so just disable interrupts + * and use non-atomic instructions. + */ + + stmfd sp!, {r4, r5} + + mrs r3, cpsr + mov r4, r3 + orr r4, r4, #(PSR_I | PSR_F) + msr cpsr_c, r4 + + ldr r5, [r0] + cmp r5, r1 + movne r0, r5 + bne 2f + + str r2, [r0] + mov r0, r5 + +2: + msr cpsr_c, r3 + ldmfd sp!, {r4, r5} + RET +#endif END(dtrace_cas32) +EEND(dtrace_casptr) diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_isa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_isa.c --- /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_isa.c 2016-02-24 03:36:22.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_isa.c 2017-07-05 13:28:13.000000000 -0700 @@ -30,24 +30,25 @@ #include #include #include -#include -#include #include -#include #include -#include -#include -#include - -#include #include -#include -#include +#include #include #include -#include + +uintptr_t kernelbase = (uintptr_t)KERNEL_BASE; + +/* TODO: support AAPCS */ +/* XXX: copied from sys/arch/arm/arm/db_trace.c */ +#define INKERNEL(va) (((vaddr_t)(va)) >= VM_MIN_KERNEL_ADDRESS) + +#define FR_SCP (0) +#define FR_RLV (-1) +#define FR_RSP (-2) +#define FR_RFP (-3) #include "regset.h" @@ -68,40 +69,77 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *intrpc) { - struct unwind_state state; - register_t sp; - int scp_offset; - int depth = 0; + uint32_t *frame, *lastframe; +#if 0 + int scp_offset; +#endif + int depth = 0; + pc_t caller = (pc_t) solaris_cpu[cpu_number()].cpu_dtrace_caller; if (intrpc != 0) pcstack[depth++] = (pc_t) intrpc; aframes++; - __asm __volatile("mov %0, sp" : "=&r" (sp)); - - state.registers[FP] = (uint32_t)__builtin_frame_address(0); - state.registers[SP] = sp; - state.registers[LR] = (uint32_t)__builtin_return_address(0); - state.registers[PC] = (uint32_t)dtrace_getpcstack; - - while (depth < pcstack_limit) { - int done; - - done = unwind_stack_one(&state, 1); + frame = (uint32_t *)__builtin_frame_address(0);; + lastframe = NULL; +#if 0 + scp_offset = -(get_pc_str_offset() >> 2); +#endif + + while ((frame != NULL) && (depth < pcstack_limit)) { + db_addr_t scp; +#if 0 + uint32_t savecode; + int r; + uint32_t *rp; +#endif /* - * NB: Unlike some other architectures, we don't need to - * explicitly insert cpu_dtrace_caller as it appears in the - * normal kernel stack trace rather than a special trap frame. + * In theory, the SCP isn't guaranteed to be in the function + * that generated the stack frame. We hope for the best. */ + scp = frame[FR_SCP]; if (aframes > 0) { aframes--; - } else { - pcstack[depth++] = state.registers[PC]; + if ((aframes == 0) && (caller != 0)) { + pcstack[depth++] = caller; + } + } + else { + pcstack[depth++] = scp; } - if (done) +#if 0 + savecode = ((uint32_t *)scp)[scp_offset]; + if ((savecode & 0x0e100000) == 0x08000000) { + /* Looks like an STM */ + rp = frame - 4; + for (r = 10; r >= 0; r--) { + if (savecode & (1 << r)) { + /* register r == *rp-- */ + } + } + } +#endif + + /* + * Switch to next frame up + */ + if (frame[FR_RFP] == 0) + break; /* Top of stack */ + + lastframe = frame; + frame = (uint32_t *)(frame[FR_RFP]); + + if (INKERNEL((int)frame)) { + /* staying in kernel */ + if (frame <= lastframe) { + /* bad frame pointer */ + break; + } + } + else break; } @@ -135,34 +173,53 @@ { /* struct arm_frame *fp = (struct arm_frame *)dtrace_getfp();*/ + printf("IMPLEMENT ME: %s\n", __func__); return (0); } int dtrace_getstackdepth(int aframes) { - struct unwind_state state; - register_t sp; - int scp_offset; - int done = 0; - int depth = 1; - - __asm __volatile("mov %0, sp" : "=&r" (sp)); - - state.registers[FP] = (uint32_t)__builtin_frame_address(0); - state.registers[SP] = sp; - state.registers[LR] = (uint32_t)__builtin_return_address(0); - state.registers[PC] = (uint32_t)dtrace_getstackdepth; + uint32_t *frame, *lastframe; + int depth = 1; + + frame = (uint32_t *)__builtin_frame_address(0);; + lastframe = NULL; + + while (frame != NULL) { +#if 0 + uint32_t savecode; + int r; + uint32_t *rp; +#endif - do { - done = unwind_stack_one(&state, 1); depth++; - } while (!done); + + /* + * Switch to next frame up + */ + if (frame[FR_RFP] == 0) + break; /* Top of stack */ + + lastframe = frame; + frame = (uint32_t *)(frame[FR_RFP]); + + if (INKERNEL((int)frame)) { + /* staying in kernel */ + if (frame <= lastframe) { + /* bad frame pointer */ + break; + } + } + else + break; + } if (depth < aframes) return 0; else return depth - aframes; + } ulong_t @@ -179,7 +236,7 @@ if (uaddr + size > VM_MAXUSER_ADDRESS || uaddr + size < uaddr) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = uaddr; return (0); } @@ -223,7 +280,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword8_nocheck(uaddr)); @@ -234,7 +291,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword16_nocheck(uaddr)); @@ -245,7 +302,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword32_nocheck(uaddr)); @@ -256,7 +313,7 @@ { if ((uintptr_t)uaddr > VM_MAXUSER_ADDRESS) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword64_nocheck(uaddr)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_subr.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_subr.c --- /tmp/out/external/cddl/osnet/dev/dtrace/arm/dtrace_subr.c 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/dtrace_subr.c 2017-05-10 03:10:04.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_subr.c,v 1.3 2017/02/27 06:47:00 chs Exp $ */ + /* * CDDL HEADER START * @@ -27,23 +29,30 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD: head/sys/cddl/dev/dtrace/arm/dtrace_subr.c 308457 2016-11-08 23:59:41Z bdrewery $"); - #include #include #include #include #include #include -#include +#include +#include +#include #include #include -#include -#include +#include #include -#include -#include +#include +#include +#include +#include + +#define FAULT_ALIGN FAULT_ALIGN_0 +extern uintptr_t kernelbase; +extern uintptr_t dtrace_in_probe_addr; +extern int dtrace_in_probe; + +void dtrace_gethrtime_init(void *arg); #define DELAYBRANCH(x) ((int)(x) < 0) @@ -115,29 +124,42 @@ prev->dtih_next = hdlr->dtih_next; } - kmem_free(hdlr, 0); + kmem_free(hdlr, sizeof (dtrace_invop_hdlr_t)); } - /*ARGSUSED*/ void dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit)) { - printf("IMPLEMENT ME: dtrace_toxic_ranges\n"); + (*func)(0, kernelbase); +} + +static void +xcall_func(void *arg0, void *arg1) +{ + dtrace_xcall_t func = arg0; + + (*func)(arg1); } void dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg) { - cpuset_t cpus; + uint64_t where; - if (cpu == DTRACE_CPUALL) - cpus = all_cpus; - else - CPU_SETOF(cpu, &cpus); + if (cpu == DTRACE_CPUALL) { + where = xc_broadcast(0, xcall_func, func, arg); + } else { + struct cpu_info *cinfo = cpu_lookup(cpu); - smp_rendezvous_cpus(cpus, smp_no_rendevous_barrier, func, - smp_no_rendevous_barrier, arg); + KASSERT(cinfo != NULL); + where = xc_unicast(0, xcall_func, func, arg, cinfo); + } + xc_wait(where); + + /* XXX Q. Do we really need the other cpus to wait also? + * (see solaris:xc_sync()) + */ } static void @@ -159,14 +181,13 @@ * Returns nanoseconds since boot. */ uint64_t -dtrace_gethrtime() +dtrace_gethrtime(void) { struct timespec curtime; nanouptime(&curtime); return (curtime.tv_sec * 1000000000UL + curtime.tv_nsec); - } uint64_t @@ -179,10 +200,12 @@ return (current_time.tv_sec * 1000000000UL + current_time.tv_nsec); } -/* Function to handle DTrace traps during probes. See amd64/amd64/trap.c */ +/* Function to handle DTrace traps during probes. Not used on ARM yet */ int dtrace_trap(struct trapframe *frame, u_int type) { + cpuid_t curcpu_id = cpu_number(); /* current cpu id */ + /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets @@ -193,7 +216,8 @@ * Check if DTrace has enabled 'no-fault' mode: * */ - if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { + + if ((cpu_core[curcpu_id].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* * There are only a couple of trap types that are expected. * All the rest will be handled in the usual way. @@ -202,8 +226,8 @@ /* Page fault. */ case FAULT_ALIGN: /* Flag a bad address. */ - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; - cpu_core[curcpu].cpuc_dtrace_illval = 0; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; + cpu_core[curcpu_id].cpuc_dtrace_illval = 0; /* * Offset the instruction pointer to the instruction @@ -231,13 +255,250 @@ (uintptr_t)which, (uintptr_t)fault, (uintptr_t)fltoffs); } +void +dtrace_gethrtime_init(void *arg) +{ + /* FIXME */ +} + +static uint32_t +dtrace_expand_imm(uint32_t imm12) +{ + uint32_t unrot = imm12 & 0xff; + int amount = 2 * (imm12 >> 8); + + if (amount) + return (unrot >> amount) | (unrot << (32 - amount)); + else + return unrot; +} + +static uint32_t +dtrace_add_with_carry(uint32_t x, uint32_t y, int carry_in, + int *carry_out, int *overflow) +{ + uint32_t result; + uint64_t unsigned_sum = x + y + (uint32_t)carry_in; + int64_t signed_sum = (int32_t)x + (int32_t)y + (int32_t)carry_in; + KASSERT(carry_in == 1); + + result = (uint32_t)(unsigned_sum & 0xffffffff); + *carry_out = ((uint64_t)result == unsigned_sum) ? 1 : 0; + *overflow = ((int64_t)result == signed_sum) ? 0 : 1; + + return result; +} + +static void +dtrace_invop_emulate(int invop, struct trapframe *frame) +{ + uint32_t op = invop; +#if 1 + /* nbsd encoding */ + uint32_t code = op >> 28; + uint32_t data = op; +#else + /* fbsd encoding */ + uint32_t code = op & DTRACE_INVOP_MASK; + uint32_t data = DTRACE_INVOP_DATA(invop); +#endif + + switch (code) { + case DTRACE_INVOP_MOV_IP_SP: + /* mov ip, sp */ + frame->tf_ip = frame->tf_svc_sp; + frame->tf_pc += 4; + break; + case DTRACE_INVOP_BX_LR: + /* bx lr */ + frame->tf_pc = frame->tf_svc_lr; + break; + case DTRACE_INVOP_MOV_PC_LR: + /* mov pc, lr */ + frame->tf_pc = frame->tf_svc_lr; + break; + case DTRACE_INVOP_LDM: + /* ldm sp, {..., pc} */ + /* FALLTHRU */ + case DTRACE_INVOP_POPM: { + /* ldmib sp, {..., pc} */ + uint32_t register_list = (op & 0xffff); + uint32_t *sp = (uint32_t *)(intptr_t)frame->tf_svc_sp; + uint32_t *regs = &frame->tf_r0; + int i; + + /* POPM */ + if (code == DTRACE_INVOP_POPM) + sp++; + + for (i = 0; i <= 12; i++) { + if (register_list & (1 << i)) + regs[i] = *sp++; + } + if (register_list & (1 << 13)) + frame->tf_svc_sp = *sp++; + if (register_list & (1 << 14)) + frame->tf_svc_lr = *sp++; + frame->tf_pc = *sp; + break; + } + case DTRACE_INVOP_LDR_IMM: { + /* ldr r?, [{pc,r?}, #?] */ + uint32_t rt = (op >> 12) & 0xf; + uint32_t rn = (op >> 16) & 0xf; + uint32_t imm = op & 0xfff; + uint32_t *regs = &frame->tf_r0; + KDASSERT(rt <= 12); + KDASSERT(rn == 15 || rn <= 12); + if (rn == 15) + regs[rt] = *((uint32_t *)(intptr_t)(frame->tf_pc + 8 + imm)); + else + regs[rt] = *((uint32_t *)(intptr_t)(regs[rn] + imm)); + frame->tf_pc += 4; + break; + } + case DTRACE_INVOP_MOVW: { + /* movw r?, #? */ + uint32_t rd = (op >> 12) & 0xf; + uint32_t imm = (op & 0xfff) | ((op & 0xf0000) >> 4); + uint32_t *regs = &frame->tf_r0; + KDASSERT(rd <= 12); + regs[rd] = imm; + frame->tf_pc += 4; + break; + } + case DTRACE_INVOP_MOV_IMM: { + /* mov r?, #? */ + uint32_t rd = (op >> 12) & 0xf; + uint32_t imm = dtrace_expand_imm(op & 0xfff); + uint32_t *regs = &frame->tf_r0; + KDASSERT(rd <= 12); + regs[rd] = imm; + frame->tf_pc += 4; + break; + } + case DTRACE_INVOP_CMP_IMM: { + /* cmp r?, #? */ + uint32_t rn = (op >> 16) & 0xf; + uint32_t *regs = &frame->tf_r0; + uint32_t imm = dtrace_expand_imm(op & 0xfff); + uint32_t spsr = frame->tf_spsr; + uint32_t result; + int carry; + int overflow; + /* + * (result, carry, overflow) = AddWithCarry(R[n], NOT(imm32), ’1’); + * APSR.N = result<31>; + * APSR.Z = IsZeroBit(result); + * APSR.C = carry; + * APSR.V = overflow; + */ + KDASSERT(rn <= 12); + result = dtrace_add_with_carry(regs[rn], ~imm, 1, &carry, &overflow); + if (result & 0x80000000) + spsr |= PSR_N_bit; + else + spsr &= ~PSR_N_bit; + if (result == 0) + spsr |= PSR_Z_bit; + else + spsr &= ~PSR_Z_bit; + if (carry) + spsr |= PSR_C_bit; + else + spsr &= ~PSR_C_bit; + if (overflow) + spsr |= PSR_V_bit; + else + spsr &= ~PSR_V_bit; + +#if 0 + aprint_normal("pc=%x Rn=%x imm=%x %c%c%c%c\n", frame->tf_pc, regs[rn], imm, + (spsr & PSR_N_bit) ? 'N' : 'n', + (spsr & PSR_Z_bit) ? 'Z' : 'z', + (spsr & PSR_C_bit) ? 'C' : 'c', + (spsr & PSR_V_bit) ? 'V' : 'v'); +#endif + frame->tf_spsr = spsr; + frame->tf_pc += 4; + break; + } + case DTRACE_INVOP_B: { + /* b ??? */ + uint32_t imm = (op & 0x00ffffff) << 2; + int32_t diff; + /* SignExtend(imm26, 32) */ + if (imm & 0x02000000) + imm |= 0xfc000000; + diff = (int32_t)imm; + frame->tf_pc += 8 + diff; + break; + } + case DTRACE_INVOP_PUSHM: { + /* push {...} */ + uint32_t register_list = (op & 0xffff); + uint32_t *sp = (uint32_t *)(intptr_t)frame->tf_svc_sp; + uint32_t *regs = &frame->tf_r0; + int i; + int count = 0; + +#if 0 + if ((op & 0x0fff0fff) == 0x052d0004) { + /* A2: str r4, [sp, #-4]! */ + *(sp - 1) = regs[4]; + frame->tf_pc += 4; + break; + } +#endif + + for (i = 0; i < 16; i++) { + if (register_list & (1 << i)) + count++; + } + sp -= count; + + for (i = 0; i <= 12; i++) { + if (register_list & (1 << i)) + *sp++ = regs[i]; + } + if (register_list & (1 << 13)) + *sp++ = frame->tf_svc_sp; + if (register_list & (1 << 14)) + *sp++ = frame->tf_svc_lr; + if (register_list & (1 << 15)) + *sp = frame->tf_pc + 8; + + /* make sure the caches and memory are in sync */ + cpu_dcache_wbinv_range(frame->tf_svc_sp, count * 4); + + /* In case the current page tables have been modified ... */ + cpu_tlb_flushID(); + cpu_cpwait(); + + frame->tf_svc_sp -= count * 4; + frame->tf_pc += 4; + + break; + } + default: + KDASSERTMSG(0, "invop 0x%08x code %u tf %p", invop, code, frame); + } +} + static int dtrace_invop_start(struct trapframe *frame) { +#if 0 register_t *r0, *sp; int data, invop, reg, update_sp; +#endif + int invop; + + invop = dtrace_invop(frame->tf_pc, frame, frame->tf_r0); - invop = dtrace_invop(frame->tf_pc, frame, frame->tf_pc); + dtrace_invop_emulate(invop, frame); + +#if 0 switch (invop & DTRACE_INVOP_MASK) { case DTRACE_INVOP_PUSHM: sp = (register_t *)frame->tf_svc_sp; @@ -326,10 +587,12 @@ data += 8; frame->tf_pc += data; break; + default: return (-1); break; } +#endif return (0); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/arm/regset.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/regset.h --- /tmp/out/external/cddl/osnet/dev/dtrace/arm/regset.h 2016-05-31 04:20:11.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/arm/regset.h 2017-04-12 02:46:41.000000000 -0700 @@ -19,7 +19,7 @@ * * CDDL HEADER END * - * $FreeBSD: head/sys/cddl/dev/dtrace/riscv/regset.h 300618 2016-05-24 16:41:37Z br $ + * $FreeBSD: head/sys/cddl/dev/dtrace/arm/regset.h 278529 2015-02-10 19:41:30Z gnn $ */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. @@ -42,7 +42,13 @@ extern "C" { #endif -/* Place here */ +#if 0 +#define REG_LINK R14 +#define REG_SP R12 +#define REG_PS R0 +#define REG_R0 R0 +#define REG_R1 R1 +#endif #ifdef __cplusplus } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_anon.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_anon.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_anon.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_anon.c 2017-04-12 08:45:10.000000000 -0700 @@ -1,3 +1,4 @@ +/* $NetBSD: dtrace_anon.c,v 1.2 2010/02/21 01:46:33 darran Exp $ */ /* * CDDL HEADER START * @@ -19,7 +20,7 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_anon.c 179237 2008-05-23 05:59:42Z jb $ */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_cddl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_cddl.h --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_cddl.h 2016-02-04 07:16:28.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_cddl.h 2017-06-16 10:07:29.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_cddl.h,v 1.2 2010/02/21 01:46:33 darran Exp $ */ + /* * CDDL HEADER START * @@ -26,6 +28,11 @@ #define _DTRACE_CDDL_H_ #include +#include + +#define SYSCTL_NODE(...) +#define SYSCTL_DECL(...) +#define SYSCTL_INT(...) #define LOCK_LEVEL 10 @@ -93,6 +100,7 @@ * that the separation on FreeBSD is a licensing constraint designed to * keep the GENERIC kernel BSD licensed. */ +#define td_dtrace l_dtrace #define t_dtrace_vtime td_dtrace->td_dtrace_vtime #define t_dtrace_start td_dtrace->td_dtrace_start #define t_dtrace_stop td_dtrace->td_dtrace_stop @@ -128,16 +136,15 @@ /* * Definitions for fields in struct proc which are named differently in FreeBSD. */ -#define p_cred p_ucred +//#define p_cred p_ucred #define p_parent p_pptr /* - * Definitions for fields in struct thread which are named differently in FreeBSD. + * Definitions for fields in struct thread which are named differently in NetBSD. */ -#define t_procp td_proc -#define t_tid td_tid -#define t_did td_tid -#define t_cred td_ucred +#define t_procp l_proc +#define t_tid l_lid +#define t_did l_lid int priv_policy(const cred_t *, int, boolean_t, int, const char *); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_debug.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_debug.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_debug.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_debug.c 2017-05-10 04:09:52.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_debug.c,v 1.8 2014/03/05 06:06:42 ozaki-r Exp $ */ + /*- * Copyright (C) 2008 John Birrell . * All rights reserved. @@ -29,14 +31,16 @@ * */ -#ifdef DEBUG +static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; +#define hex2ascii(hex) (hex2ascii_data[hex]) +#define MAXCPU MAXCPUS -#include +#ifdef DEBUG #define DTRACE_DEBUG_BUFR_SIZE (32 * 1024) struct dtrace_debug_data { - uintptr_t lock __aligned(CACHE_LINE_SIZE); + u_long lock __aligned(CACHE_LINE_SIZE); char bufr[DTRACE_DEBUG_BUFR_SIZE]; char *first; char *last; @@ -48,29 +52,31 @@ static void dtrace_debug_lock(int cpu) { - uintptr_t tid; + void *tid; - tid = (uintptr_t)curthread; - spinlock_enter(); - while (atomic_cmpset_acq_ptr(&dtrace_debug_data[cpu].lock, 0, tid) == 0) /* Loop until the lock is obtained. */ + tid = curlwp; + while (atomic_cas_ptr(&dtrace_debug_data[cpu].lock, 0, tid) == 0) + /* Loop until the lock is obtained. */ ; } static void dtrace_debug_unlock(int cpu) { - atomic_store_rel_ptr(&dtrace_debug_data[cpu].lock, 0); - spinlock_exit(); + + membar_producer(); + dtrace_debug_data[cpu].lock = 0; } static void dtrace_debug_init(void *dummy) { - int i; struct dtrace_debug_data *d; + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo; - CPU_FOREACH(i) { - d = &dtrace_debug_data[i]; + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + d = &dtrace_debug_data[cpu_index(cinfo)]; if (d->first == NULL) { d->first = d->bufr; @@ -81,8 +87,10 @@ } } +#ifdef __FreeBSD__ SYSINIT(dtrace_debug_init, SI_SUB_KDTRACE, SI_ORDER_ANY, dtrace_debug_init, NULL); SYSINIT(dtrace_debug_smpinit, SI_SUB_SMP, SI_ORDER_ANY, dtrace_debug_init, NULL); +#endif static void dtrace_debug_output(void) @@ -91,8 +99,11 @@ int i; struct dtrace_debug_data *d; uintptr_t count; + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo; - CPU_FOREACH(i) { + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + i = cpu_index(cinfo); dtrace_debug_lock(i); d = &dtrace_debug_data[i]; @@ -176,7 +187,7 @@ { int cpu; - cpu = curcpu; + cpu = cpu_number(); dtrace_debug_lock(cpu); dtrace_debug__putc(cpu, c); @@ -188,8 +199,8 @@ dtrace_debug_puts(const char *s) { int cpu; - - cpu = curcpu; + + cpu = cpu_number(); dtrace_debug_lock(cpu); while (*s != '\0') @@ -539,7 +550,7 @@ va_list ap; int cpu; - cpu = curcpu; + cpu = cpu_number(); dtrace_debug_lock(cpu); va_start(ap, fmt); @@ -557,4 +568,9 @@ #define dtrace_debug_puts(_s) #define dtrace_debug_printf(fmt, ...) +static void +dtrace_debug_init(void *dummy) +{ +} + #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_hacks.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_hacks.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_hacks.c 2015-06-17 09:03:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_hacks.c 2017-05-05 04:52:00.000000000 -0700 @@ -1,10 +1,13 @@ +/* $NetBSD: dtrace_hacks.c,v 1.5 2016/06/23 06:44:52 pgoyette Exp $ */ + /* $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_hacks.c 281916 2015-04-24 03:19:30Z markj $ */ /* XXX Hacks.... */ dtrace_cacheid_t dtrace_predcache_id; boolean_t -priv_policy_only(const cred_t *a, int b, boolean_t c) +priv_policy_only(const cred_t *cr, int b, boolean_t c) { - return 0; + + return kauth_authorize_generic(cr, KAUTH_GENERIC_ISSUSER, NULL) == 0; } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_ioctl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_ioctl.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_ioctl.c 2017-03-02 02:54:26.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_ioctl.c 2017-06-11 04:47:33.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_ioctl.c,v 1.6 2015/09/30 20:59:13 christos Exp $ */ + /* * CDDL HEADER START * @@ -26,11 +28,19 @@ SYSCTL_INT(_debug_dtrace, OID_AUTO, verbose_ioctl, CTLFLAG_RW, &dtrace_verbose_ioctl, 0, "log DTrace ioctls"); +#define pfind(pid) proc_find((pid)) + #define DTRACE_IOCTL_PRINTF(fmt, ...) if (dtrace_verbose_ioctl) printf(fmt, ## __VA_ARGS__ ) +#ifdef __FreeBSD__ static int dtrace_ioctl_helper(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td) +#endif +#ifdef __NetBSD__ +static int +dtrace_ioctl_helper(dev_t dev, u_long cmd, caddr_t addr, int flags) +#endif { struct proc *p; dof_helper_t *dhp; @@ -48,6 +58,7 @@ if (p->p_pid == dhp->dofhp_pid) { dof = dtrace_dof_copyin((uintptr_t)addr, &rval); } else { +#ifdef __FreeBSD__ p = pfind(dhp->dofhp_pid); if (p == NULL) return (EINVAL); @@ -60,11 +71,17 @@ _PHOLD(p); PROC_UNLOCK(p); dof = dtrace_dof_copyin_proc(p, (uintptr_t)addr, &rval); +#endif +#ifdef __NetBSD__ + dof = dtrace_dof_copyin_pid(dhp->dofhp_pid, addr, &rval); +#endif } if (dof == NULL) { +#ifdef __FreeBSD__ if (p != curproc) PRELE(p); +#endif break; } @@ -76,8 +93,10 @@ rval = EINVAL; } mutex_exit(&dtrace_lock); +#ifdef __FreeBSD__ if (p != curproc) PRELE(p); +#endif break; case DTRACEHIOC_REMOVE: mutex_enter(&dtrace_lock); @@ -92,14 +111,19 @@ } /* ARGSUSED */ +#ifdef __FreeBSD__ static int dtrace_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags __unused, struct thread *td) +#endif +#ifdef __NetBSD__ +static int +dtrace_ioctl(struct file *fp, u_long cmd, void *addr) +#endif { - dtrace_state_t *state; - devfs_get_cdevpriv((void **) &state); - + dtrace_state_t *state = (dtrace_state_t *)fp->f_data; int error = 0; + if (state == NULL) return (EINVAL); @@ -229,11 +253,9 @@ __func__,__LINE__, cmd == DTRACEIOC_AGGSNAP ? "DTRACEIOC_AGGSNAP":"DTRACEIOC_BUFSNAP", - curcpu, desc.dtbd_cpu); + cpu_number(), desc.dtbd_cpu); - if (desc.dtbd_cpu >= NCPU) - return (ENOENT); - if (pcpu_find(desc.dtbd_cpu) == NULL) + if (desc.dtbd_cpu >= ncpu) return (ENOENT); mutex_enter(&dtrace_lock); @@ -429,7 +451,7 @@ return (EBUSY); } - if (dtrace_dof_slurp(dof, vstate, td->td_ucred, &enab, 0, 0, + if (dtrace_dof_slurp(dof, vstate, CRED(), &enab, 0, 0, B_TRUE) != 0) { mutex_exit(&dtrace_lock); mutex_exit(&cpu_lock); @@ -682,7 +704,7 @@ pkey.dtpk_id = DTRACE_IDNONE; } - dtrace_cred2priv(td->td_ucred, &priv, &uid, &zoneid); + dtrace_cred2priv(curlwp->l_cred, &priv, &uid, &zoneid); mutex_enter(&dtrace_lock); @@ -724,6 +746,8 @@ DTRACE_IOCTL_PRINTF("%s(%d): DTRACEIOC_PROVIDER\n",__func__,__LINE__); pvd->dtvd_name[DTRACE_PROVNAMELEN - 1] = '\0'; + error = 0; +again: mutex_enter(&dtrace_provider_lock); for (pvp = dtrace_provider; pvp != NULL; pvp = pvp->dtpv_next) { @@ -733,6 +757,23 @@ mutex_exit(&dtrace_provider_lock); + if (pvp == NULL && error == 0) { + char name[NAME_MAX]; + const char *provider; + if (strcmp(pvd->dtvd_name, "proc") == 0) + provider = "sdt"; + else + provider = pvd->dtvd_name; + + if (snprintf(name, sizeof name, "dtrace_%s", + provider) < sizeof name) { + error = module_autoload(name, + MODULE_CLASS_MISC); + if (error == 0) + goto again; + } + } + if (pvp == NULL) return (ESRCH); @@ -770,6 +811,8 @@ dtrace_dstate_t *dstate; int i, j; uint64_t nerrs; + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo; DTRACE_IOCTL_PRINTF("%s(%d): DTRACEIOC_STATUS\n",__func__,__LINE__); @@ -797,11 +840,9 @@ nerrs = state->dts_errors; dstate = &state->dts_vstate.dtvs_dynvars; - for (i = 0; i < NCPU; i++) { -#ifndef illumos - if (pcpu_find(i) == NULL) - continue; -#endif + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + i = cpu_index(cinfo); + dtrace_dstate_percpu_t *dcpu = &dstate->dtds_percpu[i]; stat->dtst_dyndrops += dcpu->dtdsc_drops; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_load.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_load.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_load.c 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_load.c 2017-05-15 16:58:54.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_load.c,v 1.3 2011/08/31 21:57:16 christos Exp $ */ + /* * CDDL HEADER START * @@ -22,6 +24,13 @@ * */ +static void dtrace_debug_init(void *); +static void dtrace_anon_init(void *dummy); +void dtrace_gethrtime_init(void *); + +int dtrace_helptrace_size=0; + +#ifdef __FreeBSD__ #ifndef EARLY_AP_STARTUP static void dtrace_ap_start(void *dummy) @@ -43,16 +52,23 @@ SYSINIT(dtrace_ap_start, SI_SUB_SMP, SI_ORDER_ANY, dtrace_ap_start, NULL); #endif +#endif + +#ifdef __NetBSD__ +void *dtrace_modcb; +#endif static void dtrace_load(void *dummy) { dtrace_provider_id_t id; -#ifdef EARLY_AP_STARTUP - int i; -#endif + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo; -#ifndef illumos + dtrace_debug_init(NULL); + dtrace_gethrtime_init(NULL); + +#ifdef __FreeBSD__ /* * DTrace uses negative logic for the destructive mode switch, so it * is required to translate from the sysctl which uses positive logic. @@ -72,6 +88,7 @@ /* Hang our hook for exceptions. */ dtrace_invop_init(); +#ifdef __FreeBSD__ dtrace_taskq = taskq_create("dtrace_taskq", 1, maxclsyspri, 0, 0, 0); dtrace_arena = new_unrhdr(1, INT_MAX, &dtrace_unr_mtx); @@ -81,6 +98,13 @@ dtrace_kld_load, NULL, EVENTHANDLER_PRI_ANY); dtrace_kld_unload_try_tag = EVENTHANDLER_REGISTER(kld_unload_try, dtrace_kld_unload_try, NULL, EVENTHANDLER_PRI_ANY); +#endif + +#ifdef __NetBSD__ + dtrace_arena = vmem_create("dtrace", 1, INT_MAX, 1, + NULL, NULL, NULL, 0, VM_SLEEP, IPL_NONE); + +#endif /* * Initialise the mutexes without 'witness' because the dtrace @@ -103,7 +127,7 @@ ASSERT(MUTEX_HELD(&cpu_lock)); - dtrace_state_cache = kmem_cache_create("dtrace_state_cache", + dtrace_state_cache = kmem_cache_create(__UNCONST("dtrace_state_cache"), sizeof (dtrace_dstate_percpu_t) * NCPU, DTRACE_STATE_ALIGN, NULL, NULL, NULL, NULL, NULL, 0); @@ -152,27 +176,30 @@ dtrace_provider, NULL, NULL, "ERROR", 1, NULL); mutex_exit(&cpu_lock); - mutex_exit(&dtrace_lock); mutex_exit(&dtrace_provider_lock); mutex_enter(&cpu_lock); -#ifdef EARLY_AP_STARTUP - CPU_FOREACH(i) { - (void) dtrace_cpu_setup(CPU_CONFIG, i); + /* Setup the CPUs */ + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + (void) dtrace_cpu_setup(CPU_CONFIG, cpu_index(cinfo)); } -#else - /* Setup the boot CPU */ - (void) dtrace_cpu_setup(CPU_CONFIG, 0); -#endif mutex_exit(&cpu_lock); +#ifdef __NetBSD__ + dtrace_anon_init(NULL); + + dtrace_modcb = module_register_callbacks(dtrace_module_loaded, + dtrace_module_unloaded); +#endif +#ifdef __FreeBSD__ dtrace_dev = make_dev(&dtrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "dtrace/dtrace"); helper_dev = make_dev(&helper_cdevsw, 0, UID_ROOT, GID_WHEEL, 0660, "dtrace/helper"); +#endif return; } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_modevent.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_modevent.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_modevent.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_modevent.c 2017-04-12 08:44:25.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_modevent.c,v 1.5 2015/11/28 22:41:36 pgoyette Exp $ */ + /* * CDDL HEADER START * @@ -18,30 +20,43 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_load.c 309069 2016-11-23 22:50:20Z gnn $ * */ /* ARGSUSED */ static int -dtrace_modevent(module_t mod __unused, int type, void *data __unused) +dtrace_modcmd(modcmd_t cmd, void *data) { - int error = 0; - - switch (type) { - case MOD_LOAD: - break; + int bmajor = -1, cmajor = -1; + int error; - case MOD_UNLOAD: - break; - - case MOD_SHUTDOWN: - break; + switch (cmd) { + case MODULE_CMD_INIT: + dtrace_load(NULL); + error = devsw_attach("dtrace", NULL, &bmajor, + &dtrace_cdevsw, &cmajor); + if (error != 0) + if (dtrace_unload() != 0) + panic("failed to unload dtrace"); + return error; + + case MODULE_CMD_FINI: + error = devsw_detach(NULL, &dtrace_cdevsw); + if (error != 0) + return error; + + error = dtrace_unload(); + if (error != 0) { + if (devsw_attach("dtrace", NULL, &bmajor, + &dtrace_cdevsw, &cmajor) != 0) + panic("failed to reattach dtrace_devsw"); + } + return error; + case MODULE_CMD_AUTOUNLOAD: + return EBUSY; default: - error = EOPNOTSUPP; - break; - + return ENOTTY; } - return (error); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_sysctl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_sysctl.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_sysctl.c 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_sysctl.c 2017-04-12 08:49:42.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_sysctl.c,v 1.3 2010/04/23 11:39:52 ahoka Exp $ */ + /* * CDDL HEADER START * @@ -22,6 +24,7 @@ * */ +#if 0 /* XXX TBD sysctl */ /* Report registered DTrace providers. */ static int sysctl_dtrace_providers(SYSCTL_HANDLER_ARGS) @@ -67,7 +70,7 @@ if (p_name != NULL) { error = sysctl_handle_string(oidp, p_name, len, req); - kmem_free(p_name, 0); + kmem_free(p_name, len); } return (error); @@ -95,3 +98,5 @@ SYSCTL_INT(_security_bsd, OID_AUTO, allow_destructive_dtrace, CTLFLAG_RDTUN, &dtrace_allow_destructive, 1, "Allow destructive mode DTrace scripts"); + +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_test.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_test.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_test.c 2013-11-28 08:38:39.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_test.c 2017-04-12 08:53:25.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_test.c,v 1.2 2010/02/21 01:46:33 darran Exp $ */ + /*- * Copyright 2008 John Birrell * @@ -22,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_test.c 258622 2013-11-26 08:46:27Z avg $ * */ #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_unload.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_unload.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_unload.c 2015-02-16 15:39:03.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_unload.c 2017-05-15 16:59:03.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_unload.c,v 1.6 2015/02/26 09:10:52 ozaki-r Exp $ */ + /* * CDDL HEADER START * @@ -28,16 +30,20 @@ dtrace_state_t *state; int error = 0; +#ifdef __FreeBSD__ destroy_dev(dtrace_dev); destroy_dev(helper_dev); +#endif + +#ifdef __NetBSD__ + module_unregister_callbacks(dtrace_modcb); +#endif mutex_enter(&dtrace_provider_lock); mutex_enter(&dtrace_lock); mutex_enter(&cpu_lock); - ASSERT(dtrace_opens == 0); - - if (dtrace_helpers > 0) { + if (dtrace_opens > 0 || dtrace_helpers > 0) { mutex_exit(&cpu_lock); mutex_exit(&dtrace_lock); mutex_exit(&dtrace_provider_lock); @@ -52,8 +58,10 @@ } dtrace_provider = NULL; +#ifdef __FreeBSD__ EVENTHANDLER_DEREGISTER(kld_load, dtrace_kld_load_tag); EVENTHANDLER_DEREGISTER(kld_unload_try, dtrace_kld_unload_try_tag); +#endif if ((state = dtrace_anon_grab()) != NULL) { /* @@ -70,7 +78,7 @@ mutex_exit(&cpu_lock); if (dtrace_probes != NULL) { - kmem_free(dtrace_probes, 0); + kmem_free(dtrace_probes, dtrace_nprobes * sizeof (dtrace_probe_t *)); dtrace_probes = NULL; dtrace_nprobes = 0; } @@ -84,10 +92,16 @@ kmem_cache_destroy(dtrace_state_cache); +#ifdef __FreeBSD__ delete_unrhdr(dtrace_arena); +#endif +#ifdef __NetBSD__ + vmem_destroy(dtrace_arena); +#endif if (dtrace_toxrange != NULL) { - kmem_free(dtrace_toxrange, 0); + kmem_free(dtrace_toxrange, + dtrace_toxranges_max * sizeof (dtrace_toxrange_t)); dtrace_toxrange = NULL; dtrace_toxranges = 0; dtrace_toxranges_max = 0; @@ -107,7 +121,9 @@ mutex_destroy(&dtrace_errlock); #endif +#ifdef __FreeBSD__ taskq_destroy(dtrace_taskq); +#endif /* Reset our hook for exceptions. */ dtrace_invop_uninit(); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_vtime.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_vtime.c --- /tmp/out/external/cddl/osnet/dev/dtrace/dtrace_vtime.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/dtrace_vtime.c 2017-04-12 09:01:35.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_vtime.c,v 1.2 2010/02/21 01:46:33 darran Exp $ */ + /* * CDDL HEADER START * @@ -18,7 +20,7 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_vtime.c 179237 2008-05-23 05:59:42Z jb $ */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S --- /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S 2016-04-24 09:59:26.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_asm.S 2017-04-12 09:19:26.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_asm.S,v 1.6 2017/02/27 06:47:00 chs Exp $ */ + /* * CDDL HEADER START * @@ -28,18 +30,45 @@ #define _ASM -#include +#include "assym.h" + #include #include - -#include "assym.s" +#include +#include +#include + +#define INTR_POP \ + addl $16, %esp; \ + popl %edi; \ + popl %esi; \ + popl %ebp; \ + popl %ebx; \ + popl %edx; \ + popl %ecx; \ + popl %eax; \ + addl $8, %esp ENTRY(dtrace_invop_start) + + /* Store a trapframe for dtrace. */ + pushl $0 + pushl $T_PRIVINFLT + pushl %eax + pushl %ecx + pushl %edx + pushl %ebx + pushl %ebp + pushl %esi + pushl %edi + subl $16,%esp /* dummy for segment regs */ + cld + /* Store the args to dtrace_invop(). */ pushl %eax /* push %eax -- may be return value */ pushl %esp /* push stack pointer */ - subl $8, (%esp) /* skip first arg and segment regs */ - pushl 40(%esp) /* push calling EIP */ + addl $4, (%esp) /* skip first arg and segment regs */ + pushl TF_EIP+8(%esp) /* push calling EIP */ /* * Call dtrace_invop to let it check if the exception was @@ -66,7 +95,7 @@ * We must emulate a "pushl %ebp". To do this, we pull the stack * down 4 bytes, and then store the base pointer. */ - popal + INTR_POP subl $4, %esp /* make room for %ebp */ pushl %eax /* push temp */ movl 8(%esp), %eax /* load calling EIP */ @@ -85,7 +114,7 @@ * the above: we remove the %ebp from the stack, and squeeze up the * saved state from the trap. */ - popal + INTR_POP pushl %eax /* push temp */ movl 16(%esp), %ebp /* pop %ebp */ movl 12(%esp), %eax /* load calling EFLAGS */ @@ -105,7 +134,7 @@ * requires two temporaries: one for the new base pointer, and one * for the staging register. */ - popa + INTR_POP pushl %eax /* push temp */ pushl %ebx /* push temp */ movl %ebp, %ebx /* set temp to old %ebp */ @@ -128,7 +157,7 @@ * We must emulate a "nop". This is obviously not hard: we need only * advance the %eip by one. */ - popa + INTR_POP incl (%esp) iret /* return from interrupt */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c --- /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c 2016-04-30 08:21:04.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_isa.c 2017-05-08 01:27:51.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_isa.c,v 1.5 2017/02/27 06:47:00 chs Exp $ */ + /* * CDDL HEADER START * @@ -30,22 +32,24 @@ #include #include #include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include +#include #include "regset.h" -extern uintptr_t kernbase; -uintptr_t kernelbase = (uintptr_t) &kernbase; +uintptr_t kernelbase = (uintptr_t)KERNBASE; + +#define INKERNEL(va) \ + (((vm_offset_t)(va)) >= VM_MIN_KERNEL_ADDRESS && \ + ((vm_offset_t)(va)) < VM_MAX_KERNEL_ADDRESS) + +struct i386_frame { + struct i386_frame *f_frame; + int f_retaddr; +}; + +typedef unsigned long vm_offset_t; uint8_t dtrace_fuword8_nocheck(void *); uint16_t dtrace_fuword16_nocheck(void *); @@ -62,7 +66,7 @@ register_t ebp; struct i386_frame *frame; vm_offset_t callpc; - pc_t caller = (pc_t) solaris_cpu[curcpu].cpu_dtrace_caller; + pc_t caller = (pc_t) solaris_cpu[cpu_number()].cpu_dtrace_caller; if (intrpc != 0) pcstack[depth++] = (pc_t) intrpc; @@ -92,8 +96,8 @@ } if (frame->f_frame <= frame || - (vm_offset_t)frame->f_frame >= curthread->td_kstack + - curthread->td_kstack_pages * PAGE_SIZE) + (vm_offset_t)frame->f_frame >= + (vm_offset_t)ebp + KSTACK_SIZE) break; frame = frame->f_frame; } @@ -114,7 +118,7 @@ #endif uintptr_t oldsp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; int ret = 0; ASSERT(pcstack == NULL || pcstack_limit > 0); @@ -137,7 +141,7 @@ */ if (ret++ >= dtrace_ustackdepth_max) { *flags |= CPU_DTRACE_BADSTACK; - cpu_core[curcpu].cpuc_dtrace_illval = sp; + cpu_core[cpu_number()].cpuc_dtrace_illval = sp; break; } @@ -193,7 +197,7 @@ if (sp == oldsp) { *flags |= CPU_DTRACE_BADSTACK; - cpu_core[curcpu].cpuc_dtrace_illval = sp; + cpu_core[cpu_number()].cpuc_dtrace_illval = sp; break; } @@ -218,7 +222,7 @@ struct trapframe *tf; uintptr_t pc, sp, fp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; int n; if (*flags & CPU_DTRACE_FAULT) @@ -230,7 +234,7 @@ /* * If there's no user context we still need to zero the stack. */ - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) goto zero; *pcstack++ = (uint64_t)p->p_pid; @@ -281,7 +285,7 @@ uintptr_t pc, fp, sp; int n = 0; - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) return (0); if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT)) @@ -317,7 +321,7 @@ struct trapframe *tf; uintptr_t pc, sp, fp; volatile uint16_t *flags = - (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + (volatile uint16_t *)&cpu_core[cpu_number()].cpuc_dtrace_flags; #ifdef notyet /* XXX signal stack */ uintptr_t oldcontext; size_t s1, s2; @@ -332,7 +336,7 @@ /* * If there's no user context we still need to zero the stack. */ - if (p == NULL || (tf = curthread->td_frame) == NULL) + if (p == NULL || (tf = curlwp->l_md.md_regs) == NULL) goto zero; *pcstack++ = (uint64_t)p->p_pid; @@ -431,22 +435,21 @@ for (i = 1; i <= aframes; i++) { fp = fp->f_frame; - if (P2ROUNDUP(fp->f_retaddr, 4) == + if (P2ROUNDUP(fp->f_retaddr, 16) == (long)dtrace_invop_callsite) { /* * If we pass through the invalid op handler, we will * use the trap frame pointer that it pushed on the * stack as the second argument to dtrace_invop() as - * the pointer to the stack. When using this stack, we - * must skip the third argument to dtrace_invop(), - * which is included in the i386_frame. + * the pointer to the stack. */ - frame = (struct trapframe *)(((uintptr_t **)&fp[1])[0]); + frame = (struct trapframe *)(((uintptr_t **)&fp[1])[1]); + /* * Skip the three hardware-saved registers and the * return address. */ - stack = (uintptr_t *)frame->tf_isp + 4; + stack = (uintptr_t *)&frame->tf_esp + 1; goto load; } @@ -490,8 +493,8 @@ break; depth++; if (frame->f_frame <= frame || - (vm_offset_t)frame->f_frame >= curthread->td_kstack + - curthread->td_kstack_pages * PAGE_SIZE) + (vm_offset_t)frame->f_frame >= + (vm_offset_t)ebp + KSTACK_SIZE) break; frame = frame->f_frame; } @@ -541,11 +544,16 @@ switch(reg) { case REG_GS: +#ifdef __FreeBSD__ if ((pcb = curthread->td_pcb) == NULL) { DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP); return (0); } return (pcb->pcb_gs); +#endif +#ifdef __NetBSD__ + return (rp->tf_gs); +#endif case REG_FS: return (rp->tf_fs); case REG_ES: @@ -559,7 +567,12 @@ case REG_RBP: return (rp->tf_ebp); case REG_RSP: +#ifdef __FreeBSD__ return (rp->tf_isp); +#endif +#ifdef __NetBSD__ + return (rp->tf_esp); +#endif case REG_RBX: return (rp->tf_ebx); case REG_RCX: @@ -595,7 +608,7 @@ if (uaddr + size >= kernelbase || uaddr + size < uaddr) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = uaddr; return (0); } @@ -639,7 +652,7 @@ { if ((uintptr_t)uaddr >= kernelbase) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword8_nocheck(uaddr)); @@ -650,7 +663,7 @@ { if ((uintptr_t)uaddr >= kernelbase) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword16_nocheck(uaddr)); @@ -661,7 +674,7 @@ { if ((uintptr_t)uaddr >= kernelbase) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword32_nocheck(uaddr)); @@ -672,7 +685,7 @@ { if ((uintptr_t)uaddr >= kernelbase) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = (uintptr_t)uaddr; + cpu_core[cpu_number()].cpuc_dtrace_illval = (uintptr_t)uaddr; return (0); } return (dtrace_fuword64_nocheck(uaddr)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_subr.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_subr.c --- /tmp/out/external/cddl/osnet/dev/dtrace/i386/dtrace_subr.c 2017-03-02 02:54:25.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/i386/dtrace_subr.c 2017-04-19 10:15:40.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace_subr.c,v 1.8 2017/02/27 06:47:00 chs Exp $ */ + /* * CDDL HEADER START * @@ -34,18 +36,22 @@ #include #include #include -#include #include #include #include -#include +#include +#include +#include #include #include +#include #include -#include #include -#include -#include +#include +#include +#include + +#include extern uintptr_t kernelbase; @@ -60,6 +66,8 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; +void dtrace_gethrtime_init(void *arg); + int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax) { @@ -108,7 +116,7 @@ prev->dtih_next = hdlr->dtih_next; } - kmem_free(hdlr, 0); + kmem_free(hdlr, sizeof (dtrace_invop_hdlr_t)); } void @@ -117,18 +125,32 @@ (*func)(0, kernelbase); } +static void +xcall_func(void *arg0, void *arg1) +{ + dtrace_xcall_t func = arg0; + + (*func)(arg1); +} + void dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg) { - cpuset_t cpus; + uint64_t where; - if (cpu == DTRACE_CPUALL) - cpus = all_cpus; - else - CPU_SETOF(cpu, &cpus); + if (cpu == DTRACE_CPUALL) { + where = xc_broadcast(0, xcall_func, func, arg); + } else { + struct cpu_info *cinfo = cpu_lookup(cpu); - smp_rendezvous_cpus(cpus, smp_no_rendevous_barrier, func, - smp_no_rendevous_barrier, arg); + KASSERT(cinfo != NULL); + where = xc_unicast(0, xcall_func, func, arg, cinfo); + } + xc_wait(where); + + /* XXX Q. Do we really need the other cpus to wait also? + * (see solaris:xc_sync()) + */ } static void @@ -244,41 +266,39 @@ static int64_t tgt_cpu_tsc; static int64_t hst_cpu_tsc; -static int64_t tsc_skew[MAXCPU]; +static int64_t tsc_skew[MAXCPUS]; static uint64_t nsec_scale; /* See below for the explanation of this macro. */ #define SCALE_SHIFT 28 +static __inline uint64_t +dtrace_rdtsc(void) +{ + uint64_t rv; + + __asm __volatile("rdtsc" : "=A" (rv)); + return (rv); +} + static void dtrace_gethrtime_init_cpu(void *arg) { uintptr_t cpu = (uintptr_t) arg; - if (cpu == curcpu) - tgt_cpu_tsc = rdtsc(); + if (cpu == cpu_number()) + tgt_cpu_tsc = dtrace_rdtsc(); else - hst_cpu_tsc = rdtsc(); + hst_cpu_tsc = dtrace_rdtsc(); } -#ifdef EARLY_AP_STARTUP -static void +void dtrace_gethrtime_init(void *arg) { - struct pcpu *pc; uint64_t tsc_f; - cpuset_t map; - int i; -#else -/* - * Get the frequency and scale factor as early as possible so that they can be - * used for boot-time tracing. - */ -static void -dtrace_gethrtime_init_early(void *arg) -{ - uint64_t tsc_f; -#endif + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo = curcpu(); + cpuid_t cur_cpuid = cpu_number(); /* current cpu id */ /* * Get TSC frequency known at this moment. @@ -286,7 +306,7 @@ * Otherwise tick->time conversion will be inaccurate, but * will preserve monotonic property of TSC. */ - tsc_f = atomic_load_acq_64(&tsc_freq); + tsc_f = cpu_frequency(cinfo); /* * The following line checks that nsec_scale calculated below @@ -294,8 +314,8 @@ * another 32-bit integer without overflowing 64-bit. * Thus minimum supported TSC frequency is 62.5MHz. */ - KASSERT(tsc_f > (NANOSEC >> (32 - SCALE_SHIFT)), - ("TSC frequency is too low")); + KASSERTMSG(tsc_f > (NANOSEC >> (32 - SCALE_SHIFT)), + "TSC frequency is too low"); /* * We scale up NANOSEC/tsc_f ratio to preserve as much precision @@ -307,19 +327,17 @@ * (terahertz) values; */ nsec_scale = ((uint64_t)NANOSEC << SCALE_SHIFT) / tsc_f; -#ifndef EARLY_AP_STARTUP -} -SYSINIT(dtrace_gethrtime_init_early, SI_SUB_CPU, SI_ORDER_ANY, - dtrace_gethrtime_init_early, NULL); -static void -dtrace_gethrtime_init(void *arg) -{ - cpuset_t map; - struct pcpu *pc; - int i; -#endif + /* The current CPU is the reference one. */ + tsc_skew[cur_cpuid] = 0; + + for (CPU_INFO_FOREACH(cpuind, cinfo)) { + /* use skew relative to cpu 0 */ + tsc_skew[cpu_index(cinfo)] = cinfo->ci_data.cpu_cc_skew; + } + /* Already handled in x86/tsc.c for ci_data.cpu_cc_skew */ +#if 0 /* The current CPU is the reference one. */ sched_pin(); tsc_skew[curcpu] = 0; @@ -338,7 +356,10 @@ tsc_skew[i] = tgt_cpu_tsc - hst_cpu_tsc; } sched_unpin(); +#endif } + +#ifdef __FreeBSD__ #ifdef EARLY_AP_STARTUP SYSINIT(dtrace_gethrtime_init, SI_SUB_DTRACE, SI_ORDER_ANY, dtrace_gethrtime_init, NULL); @@ -346,6 +367,7 @@ SYSINIT(dtrace_gethrtime_init, SI_SUB_SMP, SI_ORDER_ANY, dtrace_gethrtime_init, NULL); #endif +#endif /* * DTrace needs a high resolution time function which can @@ -367,7 +389,7 @@ * (see nsec_scale calculations) taking into account 32-bit shift of * the higher half and finally add. */ - tsc = rdtsc() - tsc_skew[curcpu]; + tsc = dtrace_rdtsc() + tsc_skew[cpu_number()]; lo = tsc; hi = tsc >> 32; return (((lo * nsec_scale) >> SCALE_SHIFT) + @@ -388,7 +410,8 @@ int dtrace_trap(struct trapframe *frame, u_int type) { - uint16_t nofault; + bool nofault; + cpuid_t cpuid = cpu_number(); /* current cpu id */ /* * A trap can occur while DTrace executes a probe. Before @@ -399,11 +422,9 @@ * * Check if DTrace has enabled 'no-fault' mode: */ - sched_pin(); - nofault = cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT; - sched_unpin(); + nofault = (cpu_core[cpuid].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0; if (nofault) { - KASSERT((read_eflags() & PSL_I) == 0, ("interrupts enabled")); + KASSERTMSG((read_eflags() & PSL_I) == 0, "interrupts enabled"); /* * There are only a couple of trap types that are expected. @@ -413,7 +434,7 @@ /* General protection fault. */ case T_PROTFLT: /* Flag an illegal operation. */ - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP; + cpu_core[cpuid].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP; /* * Offset the instruction pointer to the instruction @@ -424,8 +445,8 @@ /* Page fault. */ case T_PAGEFLT: /* Flag a bad address. */ - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; - cpu_core[curcpu].cpuc_dtrace_illval = rcr2(); + cpu_core[cpuid].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; + cpu_core[cpuid].cpuc_dtrace_illval = rcr2(); /* * Offset the instruction pointer to the instruction Only in /tmp/out/external/cddl/osnet/dev/dtrace: mips Only in /tmp/out/external/cddl/osnet/dev/dtrace: powerpc Only in /tmp/out/external/cddl/osnet/dev/dtrace: riscv diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/x86/dis_tables.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/x86/dis_tables.h --- /tmp/out/external/cddl/osnet/dev/dtrace/x86/dis_tables.h 2017-03-02 02:54:26.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/x86/dis_tables.h 2017-04-20 04:49:47.000000000 -0700 @@ -43,6 +43,7 @@ #endif #include +#include #include /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/dtrace/x86/instr_size.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/x86/instr_size.c --- /tmp/out/external/cddl/osnet/dev/dtrace/x86/instr_size.c 2016-10-10 04:10:02.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/dtrace/x86/instr_size.c 2017-04-20 04:58:22.000000000 -0700 @@ -35,15 +35,16 @@ #endif #include -#include #include +#include #ifdef illumos #include #include #include #include #include -#else +#endif +#ifdef __FreeBSD__ #include #include @@ -52,6 +53,14 @@ int dtrace_instr_size(uchar_t *); int dtrace_instr_size_isa(uchar_t *, model_t, int *); #endif +#ifdef __NetBSD__ +#include + +typedef u_int model_t; +#define DATAMODEL_NATIVE 0 +int dtrace_instr_size(uchar_t *); +int dtrace_instr_size_isa(uchar_t *, model_t, int *); +#endif #include Only in /tmp/out/external/cddl/osnet/dev/fbt: aarch64 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/arm/fbt_isa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c --- /tmp/out/external/cddl/osnet/dev/fbt/arm/fbt_isa.c 2017-04-12 11:57:38.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c 2017-06-20 12:14:24.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * @@ -33,10 +35,16 @@ #include #include +#include +#include #include -#include + #include +#include +#include +#include +#include #include "fbt.h" @@ -51,40 +59,53 @@ int fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t rval) { - solaris_cpu_t *cpu = &solaris_cpu[curcpu]; + solaris_cpu_t *cpu = &solaris_cpu[cpu_number()]; fbt_probe_t *fbt = fbt_probetab[FBT_ADDR2NDX(addr)]; register_t fifthparam; for (; fbt != NULL; fbt = fbt->fbtp_hashnext) { if ((uintptr_t)fbt->fbtp_patchpoint == addr) { - cpu->cpu_dtrace_caller = addr; - - /* Get 5th parameter from stack */ - DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); - fifthparam = *(register_t *)frame->tf_svc_sp; - DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | CPU_DTRACE_BADADDR); - - dtrace_probe(fbt->fbtp_id, frame->tf_r0, - frame->tf_r1, frame->tf_r2, - frame->tf_r3, fifthparam); + if (fbt->fbtp_roffset == 0) { + /* Get 5th parameter from stack */ + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); + fifthparam = *(register_t *)frame->tf_svc_sp; + DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | + CPU_DTRACE_BADADDR); + + cpu->cpu_dtrace_caller = frame->tf_svc_lr; + dtrace_probe(fbt->fbtp_id, frame->tf_r0, + frame->tf_r1, frame->tf_r2, + frame->tf_r3, fifthparam); + } else { + /* XXX set caller */ + cpu->cpu_dtrace_caller = 0; + dtrace_probe(fbt->fbtp_id, fbt->fbtp_roffset, + rval, 0, 0, 0); + } cpu->cpu_dtrace_caller = 0; - - return (fbt->fbtp_rval | (fbt->fbtp_savedval << DTRACE_INVOP_SHIFT)); + return (fbt->fbtp_rval); } } return (0); } + void fbt_patch_tracepoint(fbt_probe_t *fbt, fbt_patchval_t val) { + dtrace_icookie_t c; + + c = dtrace_interrupt_disable(); + + ktext_write(fbt->fbtp_patchpoint, &val, sizeof (val)); - *fbt->fbtp_patchpoint = val; - icache_sync((vm_offset_t)fbt->fbtp_patchpoint, sizeof(val)); + dtrace_interrupt_enable(c); } +#ifdef __FreeBSD__ + int fbt_provide_module_function(linker_file_t lf, int symindx, linker_symval_t *symval, void *opaque) @@ -115,10 +136,10 @@ (*instr & (1 << LR)) == 0) return (0); - fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO); + fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP); fbt->fbtp_name = name; fbt->fbtp_id = dtrace_probe_create(fbt_id, modname, - name, FBT_ENTRY, 2, fbt); + name, FBT_ENTRY, 5, fbt); fbt->fbtp_patchpoint = instr; fbt->fbtp_ctl = lf; fbt->fbtp_loadcnt = lf->loadcnt; @@ -159,11 +180,11 @@ /* * We have a winner! */ - fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO); + fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP); fbt->fbtp_name = name; if (retfbt == NULL) { fbt->fbtp_id = dtrace_probe_create(fbt_id, modname, - name, FBT_RETURN, 2, fbt); + name, FBT_RETURN, 5, fbt); } else { retfbt->fbtp_next = fbt; fbt->fbtp_id = retfbt->fbtp_id; @@ -188,3 +209,195 @@ instr++; goto again; } + +#endif /* __FreeBSD_ */ + +#ifdef __NetBSD__ + +#define FBT_PATCHVAL DTRACE_BREAKPOINT + +/* entry and return */ +#define FBT_BX_LR_P(insn) (((insn) & ~INSN_COND_MASK) == 0x012fff1e) +#define FBT_B_LABEL_P(insn) (((insn) & 0xff000000) == 0xea000000) +/* entry */ +#define FBT_MOV_IP_SP_P(insn) ((insn) == 0xe1a0c00d) +/* index=1, add=1, wback=0 */ +#define FBT_LDR_IMM_P(insn) (((insn) & 0xfff00000) == 0xe5900000) +#define FBT_MOVW_P(insn) (((insn) & 0xfff00000) == 0xe3000000) +#define FBT_MOV_IMM_P(insn) (((insn) & 0xffff0000) == 0xe3a00000) +#define FBT_CMP_IMM_P(insn) (((insn) & 0xfff00000) == 0xe3500000) +#define FBT_PUSH_P(insn) (((insn) & 0xffff0000) == 0xe92d0000) +/* return */ +/* cond=always, writeback=no, rn=sp and register_list includes pc */ +#define FBT_LDM_P(insn) (((insn) & 0x0fff8000) == 0x089d8000) +#define FBT_LDMIB_P(insn) (((insn) & 0x0fff8000) == 0x099d8000) +#define FBT_MOV_PC_LR_P(insn) (((insn) & ~INSN_COND_MASK) == 0x01a0f00e) +/* cond=always, writeback=no, rn=sp and register_list includes lr, but not pc */ +#define FBT_LDM_LR_P(insn) (((insn) & 0xffffc000) == 0xe89d4000) +#define FBT_LDMIB_LR_P(insn) (((insn) & 0xffffc000) == 0xe99d4000) + +/* rval = insn | invop_id (overwriting cond with invop ID) */ +#define BUILD_RVAL(insn, id) (((insn) & ~INSN_COND_MASK) | __SHIFTIN((id), INSN_COND_MASK)) +/* encode cond in the first byte */ +#define PATCHVAL_ENCODE_COND(insn) (FBT_PATCHVAL | __SHIFTOUT((insn), INSN_COND_MASK)) + +int +fbt_provide_module_cb(const char *name, int symindx, void *value, + uint32_t symsize, int type, void *opaque) +{ + fbt_probe_t *fbt, *retfbt; + uint32_t *instr, *limit; + bool was_ldm_lr = false; + int size; + + struct fbt_ksyms_arg *fka = opaque; + modctl_t *mod = fka->fka_mod; + const char *modname = module_name(mod); + + + /* got a function? */ + if (ELF_ST_TYPE(type) != STT_FUNC) + return 0; + + if (fbt_excluded(name)) + return (0); + + /* + * Exclude some more symbols which can be called from probe context. + */ + if (strncmp(name, "_spl", 4) == 0 || + strcmp(name, "binuptime") == 0 || + strcmp(name, "nanouptime") == 0 || + strcmp(name, "dosoftints") == 0 || + strcmp(name, "fbt_emulate") == 0 || + strcmp(name, "undefinedinstruction") == 0 || + strncmp(name, "dmt_", 4) == 0 /* omap */ || + strncmp(name, "mvsoctmr_", 9) == 0 /* marvell */ ) { + return 0; + } + + instr = (uint32_t *) value; + limit = (uint32_t *)((uintptr_t)value + symsize); + + if (!FBT_MOV_IP_SP_P(*instr) + && !FBT_BX_LR_P(*instr) + && !FBT_MOVW_P(*instr) + && !FBT_MOV_IMM_P(*instr) + && !FBT_B_LABEL_P(*instr) + && !FBT_LDR_IMM_P(*instr) + && !FBT_CMP_IMM_P(*instr) + && !FBT_PUSH_P(*instr) + ) { + return 0; + } + + fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP); + fbt->fbtp_name = name; + fbt->fbtp_id = dtrace_probe_create(fbt_id, modname, + name, FBT_ENTRY, 5, fbt); + fbt->fbtp_patchpoint = instr; + fbt->fbtp_ctl = mod; + /* fbt->fbtp_loadcnt = lf->loadcnt; */ + if (FBT_MOV_IP_SP_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_MOV_IP_SP); + else if (FBT_LDR_IMM_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_LDR_IMM); + else if (FBT_MOVW_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_MOVW); + else if (FBT_MOV_IMM_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_MOV_IMM); + else if (FBT_CMP_IMM_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_CMP_IMM); + else if (FBT_BX_LR_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_BX_LR); + else if (FBT_PUSH_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_PUSHM); + else if (FBT_B_LABEL_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_B); + else + KASSERT(0); + + KASSERTMSG((fbt->fbtp_rval >> 28) != 0, + "fbt %p insn 0x%x name %s rval 0x%08x", + fbt, *instr, name, fbt->fbtp_rval); + + fbt->fbtp_patchval = PATCHVAL_ENCODE_COND(*instr); + fbt->fbtp_savedval = *instr; + fbt->fbtp_symindx = symindx; + + fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)]; + fbt_probetab[FBT_ADDR2NDX(instr)] = fbt; + + retfbt = NULL; + + while (instr < limit) { + if (instr >= limit) + return (0); + + size = 1; + + if (!FBT_BX_LR_P(*instr) + && !FBT_MOV_PC_LR_P(*instr) + && !FBT_LDM_P(*instr) + && !FBT_LDMIB_P(*instr) + && !(was_ldm_lr && FBT_B_LABEL_P(*instr)) + ) { + if (FBT_LDM_LR_P(*instr) || FBT_LDMIB_LR_P(*instr)) + was_ldm_lr = true; + else + was_ldm_lr = false; + instr += size; + continue; + } + + /* + * We have a winner! + */ + fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP); + fbt->fbtp_name = name; + + if (retfbt == NULL) { + fbt->fbtp_id = dtrace_probe_create(fbt_id, modname, + name, FBT_RETURN, 5, fbt); + } else { + retfbt->fbtp_next = fbt; + fbt->fbtp_id = retfbt->fbtp_id; + } + + retfbt = fbt; + fbt->fbtp_patchpoint = instr; + fbt->fbtp_ctl = mod; + /* fbt->fbtp_loadcnt = lf->loadcnt; */ + fbt->fbtp_symindx = symindx; + + if (FBT_BX_LR_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_BX_LR); + else if (FBT_MOV_PC_LR_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_MOV_PC_LR); + else if (FBT_LDM_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_LDM); + else if (FBT_LDMIB_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_POPM); + else if (FBT_B_LABEL_P(*instr)) + fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_B); + else + KASSERT(0); + + KASSERTMSG((fbt->fbtp_rval >> 28) != 0, "fbt %p name %s rval 0x%08x", + fbt, name, fbt->fbtp_rval); + + fbt->fbtp_roffset = (uintptr_t)(instr - (uint32_t *) value); + fbt->fbtp_patchval = PATCHVAL_ENCODE_COND(*instr); + + fbt->fbtp_savedval = *instr; + fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)]; + fbt_probetab[FBT_ADDR2NDX(instr)] = fbt; + + instr += size; + was_ldm_lr = false; + } + + return 0; +} + +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/arm/fbt_isa.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/arm/fbt_isa.h --- /tmp/out/external/cddl/osnet/dev/fbt/arm/fbt_isa.h 2017-04-12 11:56:47.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/arm/fbt_isa.h 2017-04-12 11:56:59.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/fbt.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/fbt.c --- /tmp/out/external/cddl/osnet/dev/fbt/fbt.c 2016-12-18 18:06:20.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/fbt.c 2017-11-17 10:54:00.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: fbt.c,v 1.23 2017/11/06 04:43:50 christos Exp $ */ + /* * CDDL HEADER START * @@ -19,6 +21,7 @@ * CDDL HEADER END * * Portions Copyright 2006-2008 John Birrell jb@freebsd.org + * Portions Copyright 2010 Darran Hunt darran@NetBSD.org * * $FreeBSD: head/sys/cddl/dev/fbt/fbt.c 309786 2016-12-10 03:13:11Z markj $ * @@ -30,60 +33,70 @@ */ #include +#include #include #include #include #include #include #include -#include #include #include +#include +#include #include -#include +#include #include #include #include #include #include -#include #include #include #include -#include #include -#include -#include #include #include -#include +#include #include #include +#include +#include #include "fbt.h" -MALLOC_DEFINE(M_FBT, "fbt", "Function Boundary Tracing"); +mod_ctf_t *modptr; dtrace_provider_id_t fbt_id; fbt_probe_t **fbt_probetab; int fbt_probetab_mask; +static int fbt_probetab_size; -static d_open_t fbt_open; +static dev_type_open(fbt_open); static int fbt_unload(void); static void fbt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *); static void fbt_provide_module(void *, modctl_t *); static void fbt_destroy(void *, dtrace_id_t, void *); -static void fbt_enable(void *, dtrace_id_t, void *); +static int fbt_enable(void *, dtrace_id_t, void *); static void fbt_disable(void *, dtrace_id_t, void *); -static void fbt_load(void *); +static void fbt_load(void); static void fbt_suspend(void *, dtrace_id_t, void *); static void fbt_resume(void *, dtrace_id_t, void *); -static struct cdevsw fbt_cdevsw = { - .d_version = D_VERSION, +static const struct cdevsw fbt_cdevsw = { .d_open = fbt_open, - .d_name = "fbt", + .d_close = noclose, + .d_read = noread, + .d_write = nowrite, + .d_ioctl = noioctl, + .d_stop = nostop, + .d_tty = notty, + .d_poll = nopoll, + .d_mmap = nommap, + .d_kqfilter = nokqfilter, + .d_discard = nodiscard, + .d_flag = D_OTHER }; static dtrace_pattr_t fbt_attr = { @@ -107,10 +120,18 @@ fbt_destroy }; -static struct cdev *fbt_cdev; -static int fbt_probetab_size; +#ifdef __FreeBSD__ static int fbt_verbose = 0; +static struct cdev *fbt_cdev; +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +specificdata_key_t fbt_module_key; + +#define version xversion +#endif /* __NetBSD__ */ + int fbt_excluded(const char *name) { @@ -126,6 +147,7 @@ return (1); } +#ifdef __FreeBSD__ /* * Lock owner methods may be called from probe context. */ @@ -143,6 +165,22 @@ if (strncmp(name, "fbt_", 4) == 0) return (1); #endif +#endif + +#ifdef __NetBSD__ + if (name[0] == '_' && name[1] == '_') + return (1); + + if (strcmp(name, "cpu_index") == 0 || + strncmp(name, "db_", 3) == 0 || + strncmp(name, "ddb_", 4) == 0 || + strncmp(name, "kdb_", 4) == 0 || + strncmp(name, "lockdebug_", 10) == 0 || + strncmp(name, "kauth_", 5) == 0 || + strncmp(name, "ktext_write", 11) == 0) { + return (1); + } +#endif return (0); } @@ -161,6 +199,7 @@ } } +#ifdef __FreeBSD__ static void fbt_provide_module(void *arg, modctl_t *lf) { @@ -203,6 +242,76 @@ */ (void) linker_file_function_listall(lf, fbt_provide_module_function, modname); } +#endif +#ifdef __NetBSD__ +static void +fbt_provide_module(void *arg, modctl_t *mod) +{ + struct fbt_ksyms_arg fka; + struct mod_ctf *mc; + char modname[MAXPATHLEN]; + int i; + size_t len; + + if (mod_ctf_get(mod, &mc)) { + printf("fbt: no CTF data for module %s\n", module_name(mod)); + return; + } + + strlcpy(modname, module_name(mod), sizeof(modname)); + len = strlen(modname); + if (len > 5 && strcmp(modname + len - 3, ".kmod") == 0) + modname[len - 4] = '\0'; + + /* + * Employees of dtrace and their families are ineligible. Void + * where prohibited. + */ + if (strcmp(modname, "dtrace") == 0) + return; + + /* + * The cyclic timer subsystem can be built as a module and DTrace + * depends on that, so it is ineligible too. + */ + if (strcmp(modname, "cyclic") == 0) + return; + + /* + * To register with DTrace, a module must list 'dtrace' as a + * dependency in order for the kernel linker to resolve + * symbols like dtrace_register(). All modules with such a + * dependency are ineligible for FBT tracing. + */ + for (i = 0; i < mod->mod_nrequired; i++) { + if (strncmp(module_name(mod->mod_required[i]), + "dtrace", 6) == 0) + return; + } + if (mc->fbt_provided) { + return; + } + + /* + * List the functions in the module and the symbol values. + */ + memset(&fka, 0, sizeof(fka)); + fka.fka_mod = mod; + fka.fka_mc = mc; + ksyms_mod_foreach(modname, fbt_provide_module_cb, &fka); + mc->fbt_provided = true; +} + +static void +fbt_module_dtor(void *arg) +{ + mod_ctf_t *mc = arg; + + if (mc->ctfalloc) + free(mc->ctftab, M_TEMP); + kmem_free(mc, sizeof(*mc)); +} +#endif static void fbt_destroy(void *arg, dtrace_id_t id, void *parg) @@ -214,7 +323,13 @@ do { ctl = fbt->fbtp_ctl; - ctl->fbt_nentries--; +#ifdef __FreeBSD__ + ctl->mod_fbtentries--; +#endif +#ifdef __NetBSD__ + mod_ctf_t *mc = module_getspecific(ctl, fbt_module_key); + mc->fbt_provided = false; +#endif /* * Now we need to remove this probe from the fbt_probetab. @@ -236,18 +351,21 @@ } next = fbt->fbtp_next; - free(fbt, M_FBT); + kmem_free(fbt, sizeof(*fbt)); fbt = next; } while (fbt != NULL); } -static void +static int fbt_enable(void *arg, dtrace_id_t id, void *parg) { fbt_probe_t *fbt = parg; modctl_t *ctl = fbt->fbtp_ctl; +#ifdef __NetBSD__ + module_hold(ctl); +#else ctl->nenabled++; /* @@ -259,14 +377,16 @@ if (fbt_verbose) { printf("fbt is failing for probe %s " "(module %s reloaded)", - fbt->fbtp_name, ctl->filename); + fbt->fbtp_name, module_name(ctl)); } - return; + return 0; } +#endif for (; fbt != NULL; fbt = fbt->fbtp_next) fbt_patch_tracepoint(fbt, fbt->fbtp_patchval); + return 0; } static void @@ -275,26 +395,34 @@ fbt_probe_t *fbt = parg; modctl_t *ctl = fbt->fbtp_ctl; +#ifndef __NetBSD__ ASSERT(ctl->nenabled > 0); ctl->nenabled--; if ((ctl->loadcnt != fbt->fbtp_loadcnt)) return; +#endif for (; fbt != NULL; fbt = fbt->fbtp_next) fbt_patch_tracepoint(fbt, fbt->fbtp_savedval); + +#ifdef __NetBSD__ + module_rele(ctl); +#endif } static void fbt_suspend(void *arg, dtrace_id_t id, void *parg) { fbt_probe_t *fbt = parg; +#ifndef __NetBSD__ modctl_t *ctl = fbt->fbtp_ctl; ASSERT(ctl->nenabled > 0); if ((ctl->loadcnt != fbt->fbtp_loadcnt)) return; +#endif for (; fbt != NULL; fbt = fbt->fbtp_next) fbt_patch_tracepoint(fbt, fbt->fbtp_savedval); @@ -304,45 +432,76 @@ fbt_resume(void *arg, dtrace_id_t id, void *parg) { fbt_probe_t *fbt = parg; +#ifndef __NetBSD__ modctl_t *ctl = fbt->fbtp_ctl; ASSERT(ctl->nenabled > 0); if ((ctl->loadcnt != fbt->fbtp_loadcnt)) return; +#endif for (; fbt != NULL; fbt = fbt->fbtp_next) fbt_patch_tracepoint(fbt, fbt->fbtp_patchval); } static int -fbt_ctfoff_init(modctl_t *lf, linker_ctf_t *lc) +fbt_ctfoff_init(modctl_t *mod, mod_ctf_t *mc) { - const Elf_Sym *symp = lc->symtab;; - const ctf_header_t *hp = (const ctf_header_t *) lc->ctftab; - const uint8_t *ctfdata = lc->ctftab + sizeof(ctf_header_t); + const Elf_Sym *symp = mc->symtab; + const ctf_header_t *hp = (const ctf_header_t *) mc->ctftab; + const uint8_t *ctfdata = mc->ctftab + sizeof(ctf_header_t); int i; uint32_t *ctfoff; uint32_t objtoff = hp->cth_objtoff; uint32_t funcoff = hp->cth_funcoff; ushort_t info; ushort_t vlen; + int nsyms = (mc->nmap != NULL) ? mc->nmapsize : mc->nsym; /* Sanity check. */ if (hp->cth_magic != CTF_MAGIC) { - printf("Bad magic value in CTF data of '%s'\n",lf->pathname); + printf("Bad magic value in CTF data of '%s'\n", + module_name(mod)); return (EINVAL); } - if (lc->symtab == NULL) { - printf("No symbol table in '%s'\n",lf->pathname); + if (mc->symtab == NULL) { + printf("No symbol table in '%s'\n", module_name(mod)); return (EINVAL); } - ctfoff = malloc(sizeof(uint32_t) * lc->nsym, M_LINKER, M_WAITOK); - *lc->ctfoffp = ctfoff; + ctfoff = malloc(sizeof(uint32_t) * nsyms, M_FBT, M_WAITOK); + mc->ctfoffp = ctfoff; + + for (i = 0; i < nsyms; i++, ctfoff++, symp++) { + if (mc->nmap != NULL) { + if (mc->nmap[i] == 0) { + printf("%s.%d: Error! Got zero nmap!\n", + __func__, __LINE__); + continue; + } + + /* + * CTF expects the unsorted symbol ordering, + * so map it from that to the current sorted + * symbol table. + * ctfoff[new-ind] = oldind symbol info. + */ + + /* map old index to new symbol table */ + symp = &mc->symtab[mc->nmap[i] - 1]; + + /* map old index to new ctfoff index */ + ctfoff = &mc->ctfoffp[mc->nmap[i]-1]; + } + + /* + * Note that due to how kern_ksyms.c adjusts st_name + * to be the offset into a virtual combined strtab, + * st_name will never be 0 for loaded modules. + */ - for (i = 0; i < lc->nsym; i++, ctfoff++, symp++) { if (symp->st_name == 0 || symp->st_shndx == SHN_UNDEF) { *ctfoff = 0xffffffff; continue; @@ -415,13 +574,13 @@ } static int -fbt_typoff_init(linker_ctf_t *lc) +fbt_typoff_init(mod_ctf_t *mc) { - const ctf_header_t *hp = (const ctf_header_t *) lc->ctftab; + const ctf_header_t *hp = (const ctf_header_t *) mc->ctftab; const ctf_type_t *tbuf; const ctf_type_t *tend; const ctf_type_t *tp; - const uint8_t *ctfdata = lc->ctftab + sizeof(ctf_header_t); + const uint8_t *ctfdata = mc->ctftab + sizeof(ctf_header_t); int ctf_typemax = 0; uint32_t *xp; ulong_t pop[CTF_K_MAX + 1] = { 0 }; @@ -507,7 +666,8 @@ vbytes = 0; break; default: - printf("%s(%d): detected invalid CTF kind -- %u\n", __func__, __LINE__, kind); + printf("%s(%d): detected invalid CTF kind -- %u\n", + __func__, __LINE__, kind); return (EIO); } tp = (ctf_type_t *)((uintptr_t)tp + increment + vbytes); @@ -516,12 +676,11 @@ /* account for a sentinel value below */ ctf_typemax++; - *lc->typlenp = ctf_typemax; + mc->typlen = ctf_typemax; - xp = malloc(sizeof(uint32_t) * ctf_typemax, M_LINKER, - M_ZERO | M_WAITOK); + xp = malloc(sizeof(uint32_t) * ctf_typemax, M_FBT, M_ZERO | M_WAITOK); - *lc->typoffp = xp; + mc->typoffp = xp; /* type id 0 is used as a sentinel value */ *xp++ = 0; @@ -727,14 +886,14 @@ } static const ctf_type_t * -ctf_lookup_by_id(linker_ctf_t *lc, ctf_id_t type) +ctf_lookup_by_id(mod_ctf_t *mc, ctf_id_t type) { const ctf_type_t *tp; uint32_t offset; - uint32_t *typoff = *lc->typoffp; + uint32_t *typoff = mc->typoffp; - if (type >= *lc->typlenp) { - printf("%s(%d): type %d exceeds max %ld\n",__func__,__LINE__,(int) type,*lc->typlenp); + if (type >= mc->typlen) { + printf("%s(%d): type %d exceeds max %ld\n",__func__,__LINE__,(int) type,mc->typlen); return(NULL); } @@ -744,22 +903,22 @@ return(NULL); } - tp = (const ctf_type_t *)(lc->ctftab + offset + sizeof(ctf_header_t)); + tp = (const ctf_type_t *)(mc->ctftab + offset + sizeof(ctf_header_t)); return (tp); } static void -fbt_array_info(linker_ctf_t *lc, ctf_id_t type, ctf_arinfo_t *arp) +fbt_array_info(mod_ctf_t *mc, ctf_id_t type, ctf_arinfo_t *arp) { - const ctf_header_t *hp = (const ctf_header_t *) lc->ctftab; + const ctf_header_t *hp = (const ctf_header_t *) mc->ctftab; const ctf_type_t *tp; const ctf_array_t *ap; ssize_t increment; bzero(arp, sizeof(*arp)); - if ((tp = ctf_lookup_by_id(lc, type)) == NULL) + if ((tp = ctf_lookup_by_id(mc, type)) == NULL) return; if (CTF_INFO_KIND(tp->ctt_info) != CTF_K_ARRAY) @@ -774,21 +933,21 @@ } static const char * -ctf_strptr(linker_ctf_t *lc, int name) +ctf_strptr(mod_ctf_t *mc, int name) { - const ctf_header_t *hp = (const ctf_header_t *) lc->ctftab;; + const ctf_header_t *hp = (const ctf_header_t *) mc->ctftab;; const char *strp = ""; if (name < 0 || name >= hp->cth_strlen) return(strp); - strp = (const char *)(lc->ctftab + hp->cth_stroff + name + sizeof(ctf_header_t)); + strp = (const char *)(mc->ctftab + hp->cth_stroff + name + sizeof(ctf_header_t)); return (strp); } static void -ctf_decl_push(ctf_decl_t *cd, linker_ctf_t *lc, ctf_id_t type) +ctf_decl_push(ctf_decl_t *cd, mod_ctf_t *mc, ctf_id_t type) { ctf_decl_node_t *cdp; ctf_decl_prec_t prec; @@ -798,41 +957,41 @@ const ctf_type_t *tp; ctf_arinfo_t ar; - if ((tp = ctf_lookup_by_id(lc, type)) == NULL) { + if ((tp = ctf_lookup_by_id(mc, type)) == NULL) { cd->cd_err = ENOENT; return; } switch (kind = CTF_INFO_KIND(tp->ctt_info)) { case CTF_K_ARRAY: - fbt_array_info(lc, type, &ar); - ctf_decl_push(cd, lc, ar.ctr_contents); + fbt_array_info(mc, type, &ar); + ctf_decl_push(cd, mc, ar.ctr_contents); n = ar.ctr_nelems; prec = CTF_PREC_ARRAY; break; case CTF_K_TYPEDEF: - if (ctf_strptr(lc, tp->ctt_name)[0] == '\0') { - ctf_decl_push(cd, lc, tp->ctt_type); + if (ctf_strptr(mc, tp->ctt_name)[0] == '\0') { + ctf_decl_push(cd, mc, tp->ctt_type); return; } prec = CTF_PREC_BASE; break; case CTF_K_FUNCTION: - ctf_decl_push(cd, lc, tp->ctt_type); + ctf_decl_push(cd, mc, tp->ctt_type); prec = CTF_PREC_FUNCTION; break; case CTF_K_POINTER: - ctf_decl_push(cd, lc, tp->ctt_type); + ctf_decl_push(cd, mc, tp->ctt_type); prec = CTF_PREC_POINTER; break; case CTF_K_VOLATILE: case CTF_K_CONST: case CTF_K_RESTRICT: - ctf_decl_push(cd, lc, tp->ctt_type); + ctf_decl_push(cd, mc, tp->ctt_type); prec = cd->cd_qualp; is_qual++; break; @@ -883,7 +1042,7 @@ } static ssize_t -fbt_type_name(linker_ctf_t *lc, ctf_id_t type, char *buf, size_t len) +fbt_type_name(mod_ctf_t *mc, ctf_id_t type, char *buf, size_t len) { ctf_decl_t cd; ctf_decl_node_t *cdp; @@ -891,11 +1050,11 @@ int ptr, arr; uint_t k; - if (lc == NULL && type == CTF_ERR) + if (mc == NULL && type == CTF_ERR) return (-1); /* simplify caller code by permitting CTF_ERR */ ctf_decl_init(&cd, buf, len); - ctf_decl_push(&cd, lc, type); + ctf_decl_push(&cd, mc, type); if (cd.cd_err != 0) { ctf_decl_fini(&cd); @@ -922,8 +1081,8 @@ cdp != NULL; cdp = ctf_list_next(cdp)) { const ctf_type_t *tp = - ctf_lookup_by_id(lc, cdp->cd_type); - const char *name = ctf_strptr(lc, tp->ctt_name); + ctf_lookup_by_id(mc, cdp->cd_type); + const char *name = ctf_strptr(mc, tp->ctt_name); if (k != CTF_K_POINTER && k != CTF_K_ARRAY) ctf_decl_sprintf(&cd, " "); @@ -985,13 +1144,14 @@ { const ushort_t *dp; fbt_probe_t *fbt = parg; - linker_ctf_t lc; + mod_ctf_t *mc; modctl_t *ctl = fbt->fbtp_ctl; int ndx = desc->dtargd_ndx; int symindx = fbt->fbtp_symindx; uint32_t *ctfoff; uint32_t offset; ushort_t info, kind, n; + int nsyms; if (fbt->fbtp_roffset != 0 && desc->dtargd_ndx == 0) { (void) strcpy(desc->dtargd_native, "int"); @@ -1000,51 +1160,63 @@ desc->dtargd_ndx = DTRACE_ARGNONE; - /* Get a pointer to the CTF data and it's length. */ - if (linker_ctf_get(ctl, &lc) != 0) + /* Get a pointer to the CTF data and its length. */ + if (mod_ctf_get(ctl, &mc) != 0) { + static int report = 0; + if (report < 1) { + report++; + printf("FBT: Error no CTF section found in module \"%s\"\n", + module_name(ctl)); + } /* No CTF data? Something wrong? *shrug* */ return; + } + + nsyms = (mc->nmap != NULL) ? mc->nmapsize : mc->nsym; /* Check if this module hasn't been initialised yet. */ - if (*lc.ctfoffp == NULL) { + if (mc->ctfoffp == NULL) { /* * Initialise the CTF object and function symindx to * byte offset array. */ - if (fbt_ctfoff_init(ctl, &lc) != 0) + if (fbt_ctfoff_init(ctl, mc) != 0) return; /* Initialise the CTF type to byte offset array. */ - if (fbt_typoff_init(&lc) != 0) + if (fbt_typoff_init(mc) != 0) return; } - ctfoff = *lc.ctfoffp; + ctfoff = mc->ctfoffp; - if (ctfoff == NULL || *lc.typoffp == NULL) + if (ctfoff == NULL || mc->typoffp == NULL) { return; + } /* Check if the symbol index is out of range. */ - if (symindx >= lc.nsym) + if (symindx >= nsyms) return; /* Check if the symbol isn't cross-referenced. */ if ((offset = ctfoff[symindx]) == 0xffffffff) return; - dp = (const ushort_t *)(lc.ctftab + offset + sizeof(ctf_header_t)); + dp = (const ushort_t *)(mc->ctftab + offset + sizeof(ctf_header_t)); info = *dp++; kind = CTF_INFO_KIND(info); n = CTF_INFO_VLEN(info); if (kind == CTF_K_UNKNOWN && n == 0) { - printf("%s(%d): Unknown function!\n",__func__,__LINE__); + printf("%s(%d): Unknown function %s!\n",__func__,__LINE__, + fbt->fbtp_name); return; } if (kind != CTF_K_FUNCTION) { - printf("%s(%d): Expected a function!\n",__func__,__LINE__); + printf("%s(%d): Expected a function %s!\n",__func__,__LINE__, + fbt->fbtp_name); return; } @@ -1062,12 +1234,13 @@ dp += ndx + 1; } - if (fbt_type_name(&lc, *dp, desc->dtargd_native, sizeof(desc->dtargd_native)) > 0) + if (fbt_type_name(mc, *dp, desc->dtargd_native, sizeof(desc->dtargd_native)) > 0) desc->dtargd_ndx = ndx; return; } +#ifdef __FreeBSD__ static int fbt_linker_file_cb(linker_file_t lf, void *arg) { @@ -1076,13 +1249,20 @@ return (0); } +#endif static void -fbt_load(void *dummy) +fbt_load(void) { + +#ifdef __FreeBSD__ /* Create the /dev/dtrace/fbt entry. */ fbt_cdev = make_dev(&fbt_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "dtrace/fbt"); +#endif +#ifdef __NetBSD__ + (void) module_specific_key_create(&fbt_module_key, fbt_module_dtor); +#endif /* Default the probe table size if not specified. */ if (fbt_probetab_size == 0) @@ -1101,13 +1281,11 @@ if (dtrace_register("fbt", &fbt_attr, DTRACE_PRIV_USER, NULL, &fbt_pops, NULL, &fbt_id) != 0) return; - - /* Create probes for the kernel and already-loaded modules. */ - linker_file_foreach(fbt_linker_file_cb, NULL); } + static int -fbt_unload() +fbt_unload(void) { int error = 0; @@ -1125,41 +1303,46 @@ fbt_probetab = NULL; fbt_probetab_mask = 0; +#ifdef __FreeBSD__ destroy_dev(fbt_cdev); - +#endif +#ifdef __NetBSD__ + (void) module_specific_key_delete(fbt_module_key); +#endif return (error); } + static int -fbt_modevent(module_t mod __unused, int type, void *data __unused) +dtrace_fbt_modcmd(modcmd_t cmd, void *data) { - int error = 0; - - switch (type) { - case MOD_LOAD: - break; - - case MOD_UNLOAD: - break; - - case MOD_SHUTDOWN: - break; + int bmajor = -1, cmajor = -1; + int error; + switch (cmd) { + case MODULE_CMD_INIT: + fbt_load(); + return devsw_attach("fbt", NULL, &bmajor, + &fbt_cdevsw, &cmajor); + case MODULE_CMD_FINI: + error = fbt_unload(); + if (error != 0) + return error; + return devsw_detach(NULL, &fbt_cdevsw); + case MODULE_CMD_AUTOUNLOAD: + return EBUSY; default: - error = EOPNOTSUPP; - break; - + return ENOTTY; } - - return (error); } static int -fbt_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused) +fbt_open(dev_t dev, int flags, int mode, struct lwp *l) { return (0); } +#ifdef __FreeBSD__ SYSINIT(fbt_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, fbt_load, NULL); SYSUNINIT(fbt_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, fbt_unload, NULL); @@ -1167,3 +1350,7 @@ MODULE_VERSION(fbt, 1); MODULE_DEPEND(fbt, dtrace, 1, 1, 1); MODULE_DEPEND(fbt, opensolaris, 1, 1, 1); +#endif +#ifdef __NetBSD__ +MODULE(MODULE_CLASS_MISC, dtrace_fbt, "dtrace,zlib"); +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/fbt.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/fbt.h --- /tmp/out/external/cddl/osnet/dev/fbt/fbt.h 2016-04-24 09:59:20.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/fbt.h 2017-06-20 06:43:33.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * @@ -37,7 +39,7 @@ typedef struct fbt_probe { struct fbt_probe *fbtp_hashnext; fbt_patchval_t *fbtp_patchpoint; - int8_t fbtp_rval; + fbt_patchval_t fbtp_rval; fbt_patchval_t fbtp_patchval; fbt_patchval_t fbtp_savedval; uintptr_t fbtp_roffset; @@ -49,6 +51,11 @@ struct fbt_probe *fbtp_next; } fbt_probe_t; +struct fbt_ksyms_arg { + modctl_t *fka_mod; + void *fka_mc; +}; + struct linker_file; struct linker_symval; struct trapframe; @@ -57,7 +64,9 @@ void fbt_patch_tracepoint(fbt_probe_t *, fbt_patchval_t); int fbt_provide_module_function(struct linker_file *, int, struct linker_symval *, void *); -int fbt_excluded(const char *name); +int fbt_provide_module_cb(const char *, int, void *, + uint32_t, int, void *); +int fbt_excluded(const char *); extern dtrace_provider_id_t fbt_id; extern fbt_probe_t **fbt_probetab; Only in /tmp/out/external/cddl/osnet/dev/fbt: mips Only in /tmp/out/external/cddl/osnet/dev/fbt: powerpc Only in /tmp/out/external/cddl/osnet/dev/fbt: riscv diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/x86/fbt_isa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/x86/fbt_isa.c --- /tmp/out/external/cddl/osnet/dev/fbt/x86/fbt_isa.c 2017-04-12 11:57:51.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/x86/fbt_isa.c 2017-06-15 12:39:26.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * @@ -30,10 +32,23 @@ */ #include +#include #include +#include +#include +#include #include +#if 1 +#include +#include +#if 0 +#include +#endif +#include +#endif + #include "fbt.h" #define FBT_PUSHL_EBP 0x55 @@ -69,10 +84,14 @@ stack = (uintptr_t *)frame->tf_rsp; #else /* Skip hardware-saved registers. */ +#ifdef __NetBSD__ + stack = (uintptr_t *)&frame->tf_esp; +#else stack = (uintptr_t *)frame->tf_isp + 3; #endif +#endif - cpu = &solaris_cpu[curcpu]; + cpu = &solaris_cpu[cpu_number()]; fbt = fbt_probetab[FBT_ADDR2NDX(addr)]; for (; fbt != NULL; fbt = fbt->fbtp_hashnext) { if ((uintptr_t)fbt->fbtp_patchpoint == addr) { @@ -140,26 +159,69 @@ return (0); } + + + +#ifdef __FreeBSD__ void fbt_patch_tracepoint(fbt_probe_t *fbt, fbt_patchval_t val) { *fbt->fbtp_patchpoint = val; } +#endif +#ifdef __NetBSD__ +void +fbt_patch_tracepoint(fbt_probe_t *fbt, fbt_patchval_t val) +{ + u_long psl; + u_long cr0; + + /* Disable interrupts. */ + psl = x86_read_psl(); + x86_disable_intr(); + + /* Disable write protection in supervisor mode. */ + cr0 = rcr0(); + lcr0(cr0 & ~CR0_WP); + + for (; fbt != NULL; fbt = fbt->fbtp_next) { + *fbt->fbtp_patchpoint = val; + } + + /* Write back and invalidate cache, flush pipelines. */ + wbinvd(); + x86_flush(); + x86_write_psl(psl); + + /* Re-enable write protection. */ + lcr0(cr0); +} +#endif + + +#ifdef __FreeBSD__ int fbt_provide_module_function(linker_file_t lf, int symindx, linker_symval_t *symval, void *opaque) +#endif +#ifdef __NetBSD__ +int +fbt_provide_module_cb(const char *name, int symindx, void *value, + uint32_t symsize, int type, void *opaque) +#endif { - char *modname = opaque; - const char *name = symval->name; fbt_probe_t *fbt, *retfbt; + u_int8_t *instr, *limit; int j; int size; - uint8_t *instr, *limit; - if (fbt_excluded(name)) - return (0); +#ifdef __FreeBSD_ + char *modname = opaque; + const char *name = symval->name; + size_t symsize = symval->size; + void *value = symval->value; /* * trap_check() is a wrapper for DTrace's fault handler, so we don't @@ -167,11 +229,30 @@ */ if (strcmp(name, "trap_check") == 0) return (0); +#endif +#ifdef __NetBSD__ + struct fbt_ksyms_arg *fka = opaque; + modctl_t *mod = fka->fka_mod; + const char *modname = module_name(mod); + + /* got a function? */ + if (ELF_ST_TYPE(type) != STT_FUNC) + return 0; - size = symval->size; + /* + * Exclude some more symbols which can be called from probe context. + */ + if (strcmp(name, "x86_curcpu") == 0 || + strcmp(name, "x86_curlwp") == 0) { + return 0; + } +#endif + + if (fbt_excluded(name)) + return (0); - instr = (uint8_t *) symval->value; - limit = (uint8_t *) symval->value + symval->size; + instr = (u_int8_t *) value; + limit = (u_int8_t *) value + symsize; #ifdef __amd64__ while (instr < limit) { @@ -203,13 +284,18 @@ return (0); #endif - fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO); + fbt = kmem_zalloc(sizeof (*fbt), KM_SLEEP); fbt->fbtp_name = name; fbt->fbtp_id = dtrace_probe_create(fbt_id, modname, name, FBT_ENTRY, 3, fbt); fbt->fbtp_patchpoint = instr; +#ifdef __FreeBSD__ fbt->fbtp_ctl = lf; fbt->fbtp_loadcnt = lf->loadcnt; +#endif +#ifdef __NetBSD__ + fbt->fbtp_ctl = mod; +#endif fbt->fbtp_rval = DTRACE_INVOP_PUSHL_EBP; fbt->fbtp_savedval = *instr; fbt->fbtp_patchval = FBT_PATCHVAL; @@ -217,8 +303,9 @@ fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)]; fbt_probetab[FBT_ADDR2NDX(instr)] = fbt; - +#ifdef __FreeBSD__ lf->fbt_nentries++; +#endif retfbt = NULL; again: @@ -268,7 +355,7 @@ caddr_t check = (caddr_t) instr - j; uint8_t *ptr; - if (check < symval->value) + if (check < (caddr_t)value) break; if (check + sizeof (caddr_t) > (caddr_t)limit) @@ -276,7 +363,7 @@ ptr = *(uint8_t **)check; - if (ptr >= (uint8_t *) symval->value && ptr < limit) { + if (ptr >= (uint8_t *) value && ptr < limit) { instr += size; goto again; } @@ -285,7 +372,7 @@ /* * We have a winner! */ - fbt = malloc(sizeof (fbt_probe_t), M_FBT, M_WAITOK | M_ZERO); + fbt = kmem_zalloc(sizeof (*fbt), KM_SLEEP); fbt->fbtp_name = name; if (retfbt == NULL) { @@ -298,8 +385,13 @@ retfbt = fbt; fbt->fbtp_patchpoint = instr; +#ifdef __FreeBSD__ fbt->fbtp_ctl = lf; fbt->fbtp_loadcnt = lf->loadcnt; +#endif +#ifdef __NetBSD__ + fbt->fbtp_ctl = mod; +#endif fbt->fbtp_symindx = symindx; #ifndef __amd64__ @@ -310,13 +402,13 @@ fbt->fbtp_rval = DTRACE_INVOP_LEAVE; } fbt->fbtp_roffset = - (uintptr_t)(instr - (uint8_t *) symval->value) + 1; + (uintptr_t)(instr - (uint8_t *) value) + 1; #else ASSERT(*instr == FBT_RET); fbt->fbtp_rval = DTRACE_INVOP_RET; fbt->fbtp_roffset = - (uintptr_t)(instr - (uint8_t *) symval->value); + (uintptr_t)(instr - (uint8_t *) value); #endif fbt->fbtp_savedval = *instr; @@ -324,7 +416,9 @@ fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)]; fbt_probetab[FBT_ADDR2NDX(instr)] = fbt; +#ifdef __FreeBSD__ lf->fbt_nentries++; +#endif instr += size; goto again; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/fbt/x86/fbt_isa.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/x86/fbt_isa.h --- /tmp/out/external/cddl/osnet/dev/fbt/x86/fbt_isa.h 2017-04-12 11:55:03.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/fbt/x86/fbt_isa.h 2017-04-19 10:15:48.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev: lockstat diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/profile/profile.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/profile/profile.c --- /tmp/out/external/cddl/osnet/dev/profile/profile.c 2016-05-31 04:20:12.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/profile/profile.c 2017-05-06 16:59:31.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: profile.c,v 1.7 2017/01/07 21:39:52 christos Exp $ */ + /* * CDDL HEADER START * @@ -36,11 +38,15 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif #include #include #include +#ifdef __FreeBSD__ #include +#endif #include #include #include @@ -49,12 +55,23 @@ #include #include #include +#ifdef __FreeBSD__ #include #include +#endif #include #include +#ifdef __FreeBSD__ #include #include +#endif + +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif #include #include @@ -97,6 +114,7 @@ * and the static definition doesn't seem to be overly brittle. Still, we * allow for a manual override in case we get it completely wrong. */ +#ifdef __FreeBSD__ #ifdef __amd64 #define PROF_ARTIFICIAL_FRAMES 10 #else @@ -148,14 +166,21 @@ #define PROF_ARTIFICIAL_FRAMES 10 #endif +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +#define PROF_ARTIFICIAL_FRAMES 3 +#endif + typedef struct profile_probe { char prof_name[PROF_NAMELEN]; dtrace_id_t prof_id; int prof_kind; -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) hrtime_t prof_interval; cyclic_id_t prof_cyclic; -#else +#endif +#ifdef __FreeBSD__ sbintime_t prof_interval; struct callout prof_cyclic; sbintime_t prof_expected; @@ -172,11 +197,13 @@ #endif } profile_probe_percpu_t; +#ifdef __FreeBSD__ static d_open_t profile_open; +#endif static int profile_unload(void); static void profile_create(hrtime_t, char *, int); static void profile_destroy(void *, dtrace_id_t, void *); -static void profile_enable(void *, dtrace_id_t, void *); +static int profile_enable(void *, dtrace_id_t, void *); static void profile_disable(void *, dtrace_id_t, void *); static void profile_load(void *); static void profile_provide(void *, dtrace_probedesc_t *); @@ -206,11 +233,13 @@ /* maximum number of profile probes */ static uint32_t profile_total; /* current number of profile probes */ +#ifdef __FreeBSD__ static struct cdevsw profile_cdevsw = { .d_version = D_VERSION, .d_open = profile_open, .d_name = "profile", }; +#endif static dtrace_pattr_t profile_attr = { { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, @@ -233,11 +262,14 @@ profile_destroy }; +#ifdef __FreeBSD__ static struct cdev *profile_cdev; +#endif static dtrace_provider_id_t profile_id; static hrtime_t profile_interval_min = NANOSEC / 5000; /* 5000 hz */ static int profile_aframes = PROF_ARTIFICIAL_FRAMES; +#ifdef __FreeBSD__ SYSCTL_DECL(_kern_dtrace); SYSCTL_NODE(_kern_dtrace, OID_AUTO, profile, CTLFLAG_RD, 0, "DTrace profile parameters"); SYSCTL_INT(_kern_dtrace_profile, OID_AUTO, aframes, CTLFLAG_RW, &profile_aframes, @@ -331,6 +363,36 @@ prof->prof_expected, 0, C_DIRECT_EXEC | C_ABSOLUTE); } +#endif + +#ifdef __NetBSD__ +static void +profile_fire(void *arg) +{ + profile_probe_percpu_t *pcpu = arg; + profile_probe_t *prof = pcpu->profc_probe; + hrtime_t late; + solaris_cpu_t *c = &solaris_cpu[cpu_number()]; + + late = gethrtime() - pcpu->profc_expected; + pcpu->profc_expected += pcpu->profc_interval; + + dtrace_probe(prof->prof_id, c->cpu_profile_pc, + c->cpu_profile_upc, late, 0, 0); +} + +static void +profile_tick(void *arg) +{ + profile_probe_t *prof = arg; + solaris_cpu_t *c = &solaris_cpu[cpu_number()]; + + dtrace_probe(prof->prof_id, c->cpu_profile_pc, + c->cpu_profile_upc, 0, 0, 0); +} + +#endif + static void profile_create(hrtime_t interval, char *name, int kind) { @@ -350,12 +412,12 @@ prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP); (void) strcpy(prof->prof_name, name); -#ifdef illumos - prof->prof_interval = interval; - prof->prof_cyclic = CYCLIC_NONE; -#else +#ifdef __FreeBSD__ prof->prof_interval = nsec_to_sbt(interval); callout_init(&prof->prof_cyclic, 1); +#else + prof->prof_interval = interval; + prof->prof_cyclic = CYCLIC_NONE; #endif prof->prof_kind = kind; prof->prof_id = dtrace_probe_create(profile_id, @@ -399,7 +461,7 @@ { "d", NANOSEC * (hrtime_t)(24 * 60 * 60) }, { "day", NANOSEC * (hrtime_t)(24 * 60 * 60) }, { "hz", 0 }, - { NULL } + { NULL, 0 } }; if (desc == NULL) { @@ -501,10 +563,10 @@ { profile_probe_t *prof = parg; -#ifdef illumos - ASSERT(prof->prof_cyclic == CYCLIC_NONE); -#else +#ifdef __FreeBSD__ ASSERT(!callout_active(&prof->prof_cyclic) && prof->prof_pcpus == NULL); +#else + ASSERT(prof->prof_cyclic == CYCLIC_NONE); #endif kmem_free(prof, sizeof (profile_probe_t)); @@ -512,7 +574,8 @@ atomic_add_32(&profile_total, -1); } -#ifdef illumos +#ifndef __FreeBSD__ + /*ARGSUSED*/ static void profile_online(void *arg, cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *when) @@ -544,7 +607,7 @@ } /* ARGSUSED */ -static void +static int profile_enable(void *arg, dtrace_id_t id, void *parg) { profile_probe_t *prof = parg; @@ -573,6 +636,7 @@ } else { prof->prof_cyclic = cyclic_add_omni(&omni); } + return 0; } /* ARGSUSED */ @@ -666,9 +730,11 @@ static void profile_load(void *dummy) { +#ifdef __FreeBSD__ /* Create the /dev/dtrace/profile entry. */ profile_cdev = make_dev(&profile_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "dtrace/profile"); +#endif if (dtrace_register("profile", &profile_attr, DTRACE_PRIV_USER, NULL, &profile_pops, NULL, &profile_id) != 0) @@ -684,11 +750,15 @@ if ((error = dtrace_unregister(profile_id)) != 0) return (error); +#ifdef __FreeBSD__ destroy_dev(profile_cdev); +#endif return (error); } +#ifdef __FreeBSD__ + /* ARGSUSED */ static int profile_modevent(module_t mod __unused, int type, void *data __unused) @@ -726,4 +796,35 @@ DEV_MODULE(profile, profile_modevent, NULL); MODULE_VERSION(profile, 1); MODULE_DEPEND(profile, dtrace, 1, 1, 1); +MODULE_DEPEND(profile, cyclic, 1, 1, 1); MODULE_DEPEND(profile, opensolaris, 1, 1, 1); + +#endif + +#ifdef __NetBSD__ + +static int +dtrace_profile_modcmd(modcmd_t cmd, void *data) +{ + switch (cmd) { + case MODULE_CMD_INIT: + profile_load(NULL); + return 0; + + case MODULE_CMD_FINI: + profile_unload(); + return 0; + + case MODULE_CMD_AUTOUNLOAD: + if (profile_total) + return EBUSY; + return 0; + + default: + return ENOTTY; + } +} + +MODULE(MODULE_CLASS_MISC, dtrace_profile, "dtrace,cyclic"); + +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/prototype.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/prototype.c --- /tmp/out/external/cddl/osnet/dev/prototype.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/prototype.c 2016-04-20 20:13:04.000000000 -0700 @@ -1,144 +1,180 @@ -/* - * This file is freeware. You are free to use it and add your own - * license. +/* $NetBSD: prototype.c,v 1.4 2016/04/09 15:18:48 riastradh Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. * - * $FreeBSD$ + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #include +__RCSID("$NetBSD: prototype.c,v 1.4 2016/04/09 15:18:48 riastradh Exp $"); + +#include #include -#include #include -#include -#include - #include +#include +#include -static d_open_t prototype_open; -static int prototype_unload(void); -static void prototype_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *); -static void prototype_provide(void *, dtrace_probedesc_t *); -static void prototype_destroy(void *, dtrace_id_t, void *); -static void prototype_enable(void *, dtrace_id_t, void *); -static void prototype_disable(void *, dtrace_id_t, void *); -static void prototype_load(void *); - -static struct cdevsw prototype_cdevsw = { - .d_version = D_VERSION, - .d_open = prototype_open, - .d_name = "prototype", -}; - -static dtrace_pattr_t prototype_attr = { -{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, -{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, -{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, -{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, -{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA }, -}; - -static dtrace_pops_t prototype_pops = { - prototype_provide, - NULL, - prototype_enable, - prototype_disable, - NULL, - NULL, - prototype_getargdesc, - NULL, - NULL, - prototype_destroy -}; - -static struct cdev *prototype_cdev; -static dtrace_provider_id_t prototype_id; +static dtrace_provider_id_t prototype_id; static void -prototype_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc) +prototype_enable(void *arg, dtrace_id_t id, void *parg) { + /* Enable the probe for id. */ } static void -prototype_provide(void *arg, dtrace_probedesc_t *desc) +prototype_disable(void *arg, dtrace_id_t id, void *parg) { + /* Disable the probe for id. */ } static void -prototype_destroy(void *arg, dtrace_id_t id, void *parg) +prototype_getargdesc(void *arg, dtrace_id_t id, void *parg, + dtrace_argdesc_t *desc) { + /* Get the argument descriptions for the probe id. */ } -static void -prototype_enable(void *arg, dtrace_id_t id, void *parg) +static uint64_t +prototype_getargval(void *arg, dtrace_id_t id, void *parg, int argno, + int aframes) { + /* Get the value for the argno'th argument to the probe id. */ } static void -prototype_disable(void *arg, dtrace_id_t id, void *parg) +prototype_provide(void *arg, const dtrace_probedesc_t *desc) { + /* + * Create all probes for this provider. Cookie passed to + * dtrace_probe_create will be passed on to prototype_destroy. + */ } static void -prototype_load(void *dummy) +prototype_destroy(void *arg, dtrace_id_t id, void *parg) { - /* Create the /dev/dtrace/prototype entry. */ - prototype_cdev = make_dev(&prototype_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, - "dtrace/prototype"); - - if (dtrace_register("prototype", &prototype_attr, DTRACE_PRIV_USER, - NULL, &prototype_pops, NULL, &prototype_id) != 0) - return; + /* + * Destroy a probe for this provider. parg is cookie that was + * passed to dtrace_probe_create for this probe. + */ } +static dtrace_pattr_t prototype_attr = { +/* provider attributes */ +{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, +/* module attributes */ +{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, +/* function attributes */ +{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, +/* name attributes */ +{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, +/* arguments attributes */ +{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, +}; + +static dtrace_pops_t prototype_pops = { + prototype_provide, + NULL, /* provide_module (NYI) */ + prototype_enable, + prototype_disable, + NULL, /* suspend (NYI) */ + NULL, /* resume (NYI) */ + prototype_getargdesc, /* optional */ + prototype_getargval, /* optional */ + NULL, /* usermode permissions check */ + prototype_destroy, +}; static int -prototype_unload() +prototype_init(void) { - int error = 0; + int error; + + /* Set up any necessary state, or fail. */ - if ((error = dtrace_unregister(prototype_id)) != 0) - return (error); + /* Register the dtrace provider. */ + KASSERT(prototype_id == 0); + error = dtrace_register("prototype", &prototype_attr, DTRACE_PRIV_USER, + NULL, &prototype_pops, NULL, &prototype_id); + if (error) { + printf("dtrace_prototype: failed to register dtrace provider" + ": %d\n", error); + goto fail0; + } + KASSERT(prototype_id != 0); - destroy_dev(prototype_cdev); + /* Success! */ + return 0; - return (error); +fail0: KASSERT(error); + return error; } static int -prototype_modevent(module_t mod __unused, int type, void *data __unused) +prototype_fini(void) { - int error = 0; - - switch (type) { - case MOD_LOAD: - break; - - case MOD_UNLOAD: - break; - - case MOD_SHUTDOWN: - break; - - default: - error = EOPNOTSUPP; - break; + int error; + /* + * Deregister the dtrace provider, unless we already did but + * something below failed. + */ + if (prototype_id != 0) { + error = dtrace_unregister(prototype_id); + if (error) { + printf("dtrace prototype" + ": failed to unregister dtrace provider: %d\n", + error); + return error; + } + prototype_id = 0; } - return (error); + /* Tear down any necessary state, or fail. */ + + /* Success! */ + return 0; } static int -prototype_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused) +dtrace_prototype_modcmd(modcmd_t cmd, void *data) { - return (0); -} -SYSINIT(prototype_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, prototype_load, NULL); -SYSUNINIT(prototype_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, prototype_unload, NULL); + switch (cmd) { + case MODULE_CMD_INIT: + return prototype_init(); + case MODULE_CMD_FINI: + return prototype_fini(); + case MODULE_CMD_AUTOUNLOAD: + if (prototype_users) + return EBUSY; + return 0; + default: + return ENOTTY; + } +} -DEV_MODULE(prototype, prototype_modevent, NULL); -MODULE_VERSION(prototype, 1); -MODULE_DEPEND(prototype, dtrace, 1, 1, 1); -MODULE_DEPEND(prototype, opensolaris, 1, 1, 1); +MODULE(MODULE_CLASS_MISC, dtrace_prototype, "dtrace"); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/sdt/sdt.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/sdt/sdt.c --- /tmp/out/external/cddl/osnet/dev/sdt/sdt.c 2016-04-16 09:39:04.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/sdt/sdt.c 2017-04-20 06:42:05.000000000 -0700 @@ -38,23 +38,34 @@ * responsible for destroying individual probes when a kernel module is * unloaded; in particular, probes may not span multiple kernel modules. */ +#include +__KERNEL_RCSID(0, "$NetBSD: sdt.c,v 1.18 2017/01/07 21:39:52 christos Exp $"); #include +#include #include #include #include +#ifdef __FreeBSD__ #include +#endif #include -#include +#include +#ifdef __FreeBSD__ #include #include +#endif #include +#ifdef __FreeBSD__ #include +#endif #include +#include #include #include #include +#define KDTRACE_HOOKS #include #include @@ -64,17 +75,21 @@ static void sdt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *); static void sdt_provide_probes(void *, dtrace_probedesc_t *); static void sdt_destroy(void *, dtrace_id_t, void *); -static void sdt_enable(void *, dtrace_id_t, void *); +static int sdt_enable(void *, dtrace_id_t, void *); static void sdt_disable(void *, dtrace_id_t, void *); static void sdt_load(void); static int sdt_unload(void); static void sdt_create_provider(struct sdt_provider *); static void sdt_create_probe(struct sdt_probe *); +#ifdef __FreeBSD__ static void sdt_kld_load(void *, struct linker_file *); static void sdt_kld_unload_try(void *, struct linker_file *, int *); +#endif -static MALLOC_DEFINE(M_SDT, "SDT", "DTrace SDT providers"); +MALLOC_DECLARE(M_SDT); +MALLOC_DEFINE(M_SDT, "SDT", "DTrace SDT providers"); +#define SDT_KASSERT(cond, msg) KASSERT(cond) static dtrace_pattr_t sdt_attr = { { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, @@ -97,10 +112,46 @@ sdt_destroy, }; +#ifdef __NetBSD__ +static int +sdt_open(dev_t dev, int flags, int mode, struct lwp *l) +{ + return 0; +} + +static const struct cdevsw sdt_cdevsw = { + .d_open = sdt_open, + .d_close = noclose, + .d_read = noread, + .d_write = nowrite, + .d_ioctl = noioctl, + .d_stop = nostop, + .d_tty = notty, + .d_poll = nopoll, + .d_mmap = nommap, + .d_kqfilter = nokqfilter, + .d_discard = nodiscard, + .d_flag = D_OTHER +}; +#endif + static TAILQ_HEAD(, sdt_provider) sdt_prov_list; +#ifdef __FreeBSD__ static eventhandler_tag sdt_kld_load_tag; static eventhandler_tag sdt_kld_unload_try_tag; +#endif + +#ifdef __NetBSD__ +static char * +strdup(const char *s, const struct malloc_type *m) +{ + size_t l = strlen(s) + 1; + char *d = malloc(l, m, M_WAITOK); + memcpy(d, s, l); + return d; +} +#endif static void sdt_create_provider(struct sdt_provider *prov) @@ -151,14 +202,16 @@ if (strcmp(prov->name, probe->prov->name) == 0) break; - KASSERT(prov != NULL, ("probe defined without a provider")); + SDT_KASSERT(prov != NULL, ("probe defined without a provider")); +#ifdef __FreeBSD__ /* If no module name was specified, use the module filename. */ if (*probe->mod == 0) { len = strlcpy(mod, probe->sdtp_lf->filename, sizeof(mod)); if (len > 3 && strcmp(mod + len - 3, ".ko") == 0) mod[len - 3] = '\0'; } else +#endif strlcpy(mod, probe->mod, sizeof(mod)); /* @@ -199,15 +252,18 @@ { } -static void +static int sdt_enable(void *arg __unused, dtrace_id_t id, void *parg) { struct sdt_probe *probe = parg; probe->id = id; +#ifdef __FreeBSD__ probe->sdtp_lf->nenabled++; if (strcmp(probe->prov->name, "lockstat") == 0) lockstat_enabled++; +#endif + return 1; } static void @@ -215,12 +271,13 @@ { struct sdt_probe *probe = parg; - KASSERT(probe->sdtp_lf->nenabled > 0, ("no probes enabled")); - +#ifdef __FreeBSD__ + SDT_KASSERT(probe->sdtp_lf->nenabled > 0, ("no probes enabled")); if (strcmp(probe->prov->name, "lockstat") == 0) lockstat_enabled--; - probe->id = 0; probe->sdtp_lf->nenabled--; +#endif + probe->id = 0; } static void @@ -256,6 +313,7 @@ { } +#ifdef __FreeBSD__ /* * Called from the kernel linker when a module is loaded, before * dtrace_module_loaded() is called. This is done so that it's possible to @@ -340,13 +398,85 @@ return (0); } +#endif +#ifdef __NetBSD__ +/* + * weak symbols don't work in kernel modules; link set end symbols are + * weak by default, so we kill that. + */ +#undef __weak +#define __weak +__link_set_decl(sdt_providers_set, struct sdt_provider); +__link_set_decl(sdt_probes_set, struct sdt_probe); +__link_set_decl(sdt_argtypes_set, struct sdt_argtype); + +/* + * Unfortunately we don't have linker set functions and event handlers + * to support loading and unloading probes in modules... Currently if + * modules have probes, if the modules are loaded when sdt is loaded + * they will work, but they will crash unloading. + */ static void -sdt_load() +sdt_link_set_load(void) { + struct sdt_provider * const *provider; + struct sdt_probe * const *probe; + struct sdt_argtype * const *argtype; + + __link_set_foreach(provider, sdt_providers_set) { + sdt_create_provider(*provider); + } + + __link_set_foreach(probe, sdt_probes_set) { + (*probe)->sdtp_lf = NULL; // XXX: we don't support it + sdt_create_probe(*probe); + TAILQ_INIT(&(*probe)->argtype_list); + } + + __link_set_foreach(argtype, sdt_argtypes_set) { + (*argtype)->probe->n_args++; + TAILQ_INSERT_TAIL(&(*argtype)->probe->argtype_list, + *argtype, argtype_entry); + } +} + +static void +sdt_link_set_unload(void) +{ + struct sdt_provider * const *curr, *prov, *tmp; + + /* + * Go through all the providers declared in this linker file and + * unregister any that aren't declared in another loaded file. + */ + __link_set_foreach(curr, sdt_providers_set) { + TAILQ_FOREACH_SAFE(prov, &sdt_prov_list, prov_entry, tmp) { + if (strcmp(prov->name, (*curr)->name) != 0) + continue; + if (prov->sdt_refs == 1) { + if (dtrace_unregister(prov->id) != 0) { + return; + } + TAILQ_REMOVE(&sdt_prov_list, prov, prov_entry); + free(__UNCONST(prov->name), M_SDT); + free(prov, M_SDT); + } else + prov->sdt_refs--; + break; + } + } +} +#endif + + +static void +sdt_load(void) +{ TAILQ_INIT(&sdt_prov_list); +#ifdef __FreeBSD__ sdt_probe_func = dtrace_probe; sdt_kld_load_tag = EVENTHANDLER_REGISTER(kld_load, sdt_kld_load, NULL, @@ -356,31 +486,44 @@ /* Pick up probes from the kernel and already-loaded linker files. */ linker_file_foreach(sdt_linker_file_cb, NULL); +#endif +#ifdef __NetBSD__ + sdt_init(dtrace_probe); + sdt_link_set_load(); +#endif } static int -sdt_unload() +sdt_unload(void) { struct sdt_provider *prov, *tmp; int ret; +#ifdef __FreeBSD__ EVENTHANDLER_DEREGISTER(kld_load, sdt_kld_load_tag); EVENTHANDLER_DEREGISTER(kld_unload_try, sdt_kld_unload_try_tag); sdt_probe_func = sdt_probe_stub; +#endif +#ifdef __NetBSD__ + sdt_exit(); + + sdt_link_set_unload(); +#endif TAILQ_FOREACH_SAFE(prov, &sdt_prov_list, prov_entry, tmp) { ret = dtrace_unregister(prov->id); if (ret != 0) return (ret); TAILQ_REMOVE(&sdt_prov_list, prov, prov_entry); - free(prov->name, M_SDT); + free(__UNCONST(prov->name), M_SDT); free(prov, M_SDT); } return (0); } +#ifdef __FreeBSD__ static int sdt_modevent(module_t mod __unused, int type, void *data __unused) { @@ -401,3 +544,33 @@ DEV_MODULE(sdt, sdt_modevent, NULL); MODULE_VERSION(sdt, 1); MODULE_DEPEND(sdt, dtrace, 1, 1, 1); +#endif + +#ifdef __NetBSD__ +static int +dtrace_sdt_modcmd(modcmd_t cmd, void *data) +{ + int bmajor = -1, cmajor = -1; + int error; + + switch (cmd) { + case MODULE_CMD_INIT: + sdt_load(); + return devsw_attach("sdt", NULL, &bmajor, + &sdt_cdevsw, &cmajor); + case MODULE_CMD_FINI: + error = sdt_unload(); + if (error != 0) + return error; + return devsw_detach(NULL, &sdt_cdevsw); + case MODULE_CMD_AUTOUNLOAD: + return EBUSY; + default: + error = EOPNOTSUPP; + break; + } + return error; +} + +MODULE(MODULE_CLASS_MISC, dtrace_sdt, "dtrace"); +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dev/systrace/systrace.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/systrace/systrace.c --- /tmp/out/external/cddl/osnet/dev/systrace/systrace.c 2016-10-10 04:10:02.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dev/systrace/systrace.c 2017-04-20 07:31:12.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: systrace.c,v 1.9 2017/01/07 21:39:52 christos Exp $ */ + /* * CDDL HEADER START * @@ -19,6 +21,7 @@ * CDDL HEADER END * * Portions Copyright 2006-2008 John Birrell jb@freebsd.org + * */ /* @@ -27,20 +30,19 @@ */ #include -__FBSDID("$FreeBSD: head/sys/cddl/dev/systrace/systrace.c 306220 2016-09-22 23:22:53Z markj $"); +/* __FBSDID("$FreeBSD: head/sys/cddl/dev/systrace/systrace.c 306220 2016-09-22 23:22:53Z markj $"); */ +#include #include #include #include #include -#include #include #include -#include #include #include #include -#include +#include #include #include #include @@ -49,16 +51,19 @@ #include #include #include -#include -#include -#include +#include #include #include -#include +#include +#include "dtrace_cddl.h" + +#include "emultrace.h" -#include +#define CONCAT(x,y) __CONCAT(x,y) +#define STRING(s) __STRING(s) +#ifdef __FreeBSD__ #ifdef LINUX_SYSTRACE #if defined(__amd64__) #include @@ -122,6 +127,39 @@ #define PROVNAME "syscall" #define DEVNAME "dtrace/systrace/" MODNAME +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +#include + +#ifndef NATIVE +extern const char * const CONCAT(emulname,_syscallnames)[]; +extern const char * const CONCAT(alt,CONCAT(emulname,_syscallnames))[]; +extern struct sysent CONCAT(emulname,_sysent)[]; +#define MODNAME CONCAT(dtrace_syscall_,emulname) +#define MODDEP "dtrace_syscall,compat_" STRING(emulname) +#define MAXSYSCALL CONCAT(EMULNAME,_SYS_MAXSYSCALL) +#define SYSCALLNAMES CONCAT(emulname,_syscallnames) +#define ALTSYSCALLNAMES CONCAT(alt,CONCAT(emulname,_syscallnames)) +#define SYSENT CONCAT(emulname,_sysent) +#define PROVNAME STRING(emulname) "_syscall" +#else +extern const char * const syscallnames[]; +extern const char * const altsyscallnames[]; +#define MODNAME dtrace_syscall +#define MODDEP "dtrace" +#define MAXSYSCALL SYS_MAXSYSCALL +#define SYSCALLNAMES syscallnames +#define ALTSYSCALLNAMES altsyscallnames +#define SYSENT sysent +#define PROVNAME "syscall" +#endif + +#define MODCMD CONCAT(MODNAME,_modcmd) +#define EMUL CONCAT(emul_,emulname) +extern struct emul EMUL; +#define curthread curlwp +#endif /* __NetBSD__ */ #define SYSTRACE_ARTIFICIAL_FRAMES 1 @@ -135,21 +173,21 @@ #error 1 << SYSTRACE_SHIFT must exceed number of system calls #endif -static void systrace_load(void *); -static void systrace_unload(void *); - -static void systrace_getargdesc(void *, dtrace_id_t, void *, - dtrace_argdesc_t *); +static int systrace_unload(void); +static void systrace_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *); static uint64_t systrace_getargval(void *, dtrace_id_t, void *, int, int); static void systrace_provide(void *, dtrace_probedesc_t *); static void systrace_destroy(void *, dtrace_id_t, void *); -static void systrace_enable(void *, dtrace_id_t, void *); +static int systrace_enable(void *, dtrace_id_t, void *); static void systrace_disable(void *, dtrace_id_t, void *); +static void systrace_load(void *); +#ifdef __FreeBSD__ static union { const char **p_constnames; char **pp_syscallnames; } uglyhack = { SYSCALLNAMES }; +#endif static dtrace_pattr_t systrace_attr = { { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, @@ -174,7 +212,6 @@ static dtrace_provider_id_t systrace_id; -#ifdef NATIVE_ABI /* * Probe callback function. * @@ -182,6 +219,8 @@ * array the syscall comes from. It could be a standard syscall or a * compat syscall from something like Linux. */ +#ifdef __FreeBSD__ +#ifdef NATIVE_ABI static void systrace_probe(struct syscall_args *sa, enum systrace_probe_t type, int retval) { @@ -227,11 +266,36 @@ /* Process the probe using the converted argments. */ dtrace_probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]); } +#endif /* NATIVE_ABI */ +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +static void +systrace_probe(uint32_t id, register_t sysnum, const struct sysent *se, + const void *params, const register_t *ret, int error) +{ + size_t n_args = 0; + uintptr_t uargs[SYS_MAXSYSARGS + 3]; + + memset(uargs, 0, sizeof(uargs)); + if (ret == NULL) { + /* entry syscall, convert params */ + systrace_args(sysnum, params, uargs, &n_args); + } else { + /* return syscall, set values and params: */ + uargs[0] = ret[0]; + uargs[1] = ret[1]; + uargs[2] = error; + systrace_args(sysnum, params, uargs + 3, &n_args); + } + /* Process the probe using the converted argments. */ + /* XXX: fix for more arguments! */ + dtrace_probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]); +} #endif static void -systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, - dtrace_argdesc_t *desc) +systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc) { int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg); @@ -247,8 +311,7 @@ } static uint64_t -systrace_getargval(void *arg __unused, dtrace_id_t id __unused, - void *parg __unused, int argno, int aframes __unused) +systrace_getargval(void *arg, dtrace_id_t id, void *parg, int argno, int aframes) { uint64_t *uargs; @@ -256,8 +319,15 @@ if (uargs == NULL) /* This is a return probe. */ return (0); +#ifdef __FreeBSD__ if (argno >= nitems(((struct syscall_args *)NULL)->args)) return (0); +#endif +#ifdef __NetBSD__ + if (argno >= SYS_MAXSYSARGS) + return (0); +#endif + return (uargs[argno]); } @@ -270,6 +340,7 @@ return; for (i = 0; i < MAXSYSCALL; i++) { +#ifdef __FreeBSD__ if (dtrace_probe_lookup(systrace_id, MODNAME, uglyhack.pp_syscallnames[i], "entry") != 0) continue; @@ -282,6 +353,19 @@ uglyhack.pp_syscallnames[i], "return", SYSTRACE_ARTIFICIAL_FRAMES, (void *)((uintptr_t)SYSTRACE_RETURN(i))); +#else + const char *name = ALTSYSCALLNAMES[i] ? ALTSYSCALLNAMES[i] : + SYSCALLNAMES[i]; + if (dtrace_probe_lookup(systrace_id, NULL, name, "entry") != 0) + continue; + + (void) dtrace_probe_create(systrace_id, NULL, + name, "entry", SYSTRACE_ARTIFICIAL_FRAMES, + (void *)(intptr_t)SYSTRACE_ENTRY(i)); + (void) dtrace_probe_create(systrace_id, NULL, + name, "return", SYSTRACE_ARTIFICIAL_FRAMES, + (void *)(intptr_t)SYSTRACE_RETURN(i)); +#endif } } @@ -303,18 +387,22 @@ #endif } -static void +static int systrace_enable(void *arg, dtrace_id_t id, void *parg) { int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg); +#ifdef __FreeBSD__ if (SYSENT[sysnum].sy_systrace_args_func == NULL) SYSENT[sysnum].sy_systrace_args_func = systrace_args; +#endif if (SYSTRACE_ISENTRY((uintptr_t)parg)) SYSENT[sysnum].sy_entry = id; else SYSENT[sysnum].sy_return = id; + + return 0; } static void @@ -327,9 +415,8 @@ } static void -systrace_load(void *dummy __unused) +systrace_load(void *dummy) { - if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER, NULL, &systrace_pops, NULL, &systrace_id) != 0) return; @@ -337,20 +424,31 @@ #ifdef NATIVE_ABI systrace_probe_func = systrace_probe; #endif +#ifdef __NetBSD__ + EMUL.e_dtrace_syscall = systrace_probe; +#endif } -static void -systrace_unload(void *dummy __unused) + +static int +systrace_unload() { + int error; #ifdef NATIVE_ABI systrace_probe_func = NULL; #endif +#ifdef __NetBSD__ + EMUL.e_dtrace_syscall = NULL; +#endif - if (dtrace_unregister(systrace_id) != 0) - return; + if ((error = dtrace_unregister(systrace_id)) != 0) + return (error); + + return error; } +#ifdef __FreeBSD__ static int systrace_modevent(module_t mod __unused, int type, void *data __unused) { @@ -407,3 +505,29 @@ MODULE_DEPEND(systrace, dtrace, 1, 1, 1); MODULE_DEPEND(systrace, opensolaris, 1, 1, 1); #endif +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ + +static int +MODCMD(modcmd_t cmd, void *data) +{ + switch (cmd) { + case MODULE_CMD_INIT: + systrace_load(NULL); + return 0; + + case MODULE_CMD_FINI: + return systrace_unload(); + + case MODULE_CMD_AUTOUNLOAD: + return EBUSY; + + default: + return ENOTTY; + } +} + +MODULE(MODULE_CLASS_MISC, MODNAME, MODDEP) + +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/cmd/dtrace/dtrace.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/dtrace/dtrace.c --- /tmp/out/external/cddl/osnet/dist/cmd/dtrace/dtrace.c 2016-10-10 04:14:24.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/dtrace/dtrace.c 2017-06-07 11:38:01.000000000 -0700 @@ -93,7 +93,7 @@ static int g_intr; static int g_impatient; static int g_newline; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) static int g_siginfo; #endif static int g_total; @@ -181,7 +181,7 @@ return (E_USAGE); } -static void +static void __printflike(1, 0) verror(const char *fmt, va_list ap) { int error = errno; @@ -194,7 +194,7 @@ } /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) __dead fatal(const char *fmt, ...) { va_list ap; @@ -214,7 +214,7 @@ } /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) __dead dfatal(const char *fmt, ...) { #if !defined(illumos) && defined(NEED_ERRLOC) @@ -254,7 +254,7 @@ } /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) error(const char *fmt, ...) { va_list ap; @@ -265,7 +265,7 @@ } /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) notice(const char *fmt, ...) { va_list ap; @@ -279,7 +279,7 @@ } /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) oprintf(const char *fmt, ...) { va_list ap; @@ -437,7 +437,8 @@ exit(E_ERROR); } } -#else +#endif +#ifdef illumos static void etcsystem_prune(void) { @@ -548,7 +549,7 @@ error("added forceload directives to %s\n", g_ofile); } -#endif /* !__FreeBSD__ */ +#endif /* illumos__ */ static void print_probe_info(const dtrace_probeinfo_t *p) @@ -694,7 +695,8 @@ oprintf("%02x", *p++); oprintf("\n"); -#else +#endif +#ifdef illumos oprintf("dof-data-%d=0x%x", n, *p++); while (p < q) @@ -897,7 +899,7 @@ static int errhandler(const dtrace_errdata_t *data, void *arg) { - error(data->dteda_msg); + error("%s", data->dteda_msg); return (DTRACE_HANDLE_OK); } @@ -905,7 +907,7 @@ static int drophandler(const dtrace_dropdata_t *data, void *arg) { - error(data->dtdda_msg); + error("%s", data->dtdda_msg); return (DTRACE_HANDLE_OK); } @@ -1776,7 +1778,8 @@ if (g_ofile == NULL) #ifdef illumos g_ofile = "/kernel/drv/dtrace.conf"; -#else +#endif +#ifdef __FreeBSD__ /* * On FreeBSD, anonymous DOF data is written to * the DTrace DOF file. @@ -1821,7 +1824,8 @@ #ifdef __FreeBSD__ bootdof_add(); -#else +#endif +#ifdef illumos etcsystem_add(); error("run update_drv(1M) or reboot to enable changes\n"); #endif @@ -1961,7 +1965,7 @@ if (!g_intr && !done) dtrace_sleep(g_dtp); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if (g_siginfo) { (void)dtrace_aggregate_print(g_dtp, g_ofp, NULL); g_siginfo = 0; Only in /tmp/out/external/cddl/osnet/dist/cmd: pyzfs Only in /tmp/out/external/cddl/osnet/dist/cmd: stat diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/cmd/zfs/zfs_main.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/zfs/zfs_main.c --- /tmp/out/external/cddl/osnet/dist/cmd/zfs/zfs_main.c 2016-10-10 04:14:24.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/zfs/zfs_main.c 2017-04-22 09:42:58.000000000 -0700 @@ -59,7 +59,12 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif +#ifdef __NetBSD__ +#include +#endif #include #include @@ -107,8 +112,10 @@ static int zfs_do_holds(int argc, char **argv); static int zfs_do_release(int argc, char **argv); static int zfs_do_diff(int argc, char **argv); +#ifdef __FreeBSD__ static int zfs_do_jail(int argc, char **argv); static int zfs_do_unjail(int argc, char **argv); +#endif static int zfs_do_bookmark(int argc, char **argv); /* @@ -212,9 +219,11 @@ { "holds", zfs_do_holds, HELP_HOLDS }, { "release", zfs_do_release, HELP_RELEASE }, { "diff", zfs_do_diff, HELP_DIFF }, +#ifdef __FreeBSD__ { NULL }, { "jail", zfs_do_jail, HELP_JAIL }, { "unjail", zfs_do_unjail, HELP_UNJAIL }, +#endif }; #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0])) @@ -6304,7 +6313,8 @@ entry.mnt_minor == minor(statbuf.st_dev)) break; } -#else +#endif +#ifdef __FreeBSD__ { struct statfs sfs; @@ -6316,6 +6326,18 @@ statfs2mnttab(&sfs, &entry); } #endif +#ifdef __NetBSD__ + { + struct statvfs sfs; + + if (statvfs(path, &sfs) != 0) { + (void) fprintf(stderr, "%s: %s\n", path, + strerror(errno)); + ret = -1; + } + statvfs2mnttab(&sfs, &entry); + } +#endif if (ret != 0) { if (op == OP_SHARE) { (void) fprintf(stderr, gettext("cannot %s '%s': not " @@ -6684,6 +6706,7 @@ return (unshare_unmount(OP_SHARE, argc, argv)); } +#ifdef __FreeBSD__ /* * Attach/detach the given dataset to/from the given jail */ @@ -6745,6 +6768,7 @@ return (do_jail(argc, argv, 0)); } +#endif /* __FreeBSD__ */ /* * Called when invoked as /etc/fs/zfs/mount. Do the mount if the mountpoint is Only in /tmp/out/external/cddl/osnet/dist/cmd: zhack Only in /tmp/out/external/cddl/osnet/dist/cmd: zinject Only in /tmp/out/external/cddl/osnet/dist/cmd: zlook diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/cmd/zpool/zpool_vdev.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/zpool/zpool_vdev.c --- /tmp/out/external/cddl/osnet/dist/cmd/zpool/zpool_vdev.c 2016-10-10 04:14:24.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/cmd/zpool/zpool_vdev.c 2017-05-05 09:51:20.000000000 -0700 @@ -75,7 +75,12 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif +#ifdef __NetBSD__ +#include +#endif #include "zpool_util.h" @@ -392,7 +397,8 @@ efi_free(label); (void) close(fd); return (B_TRUE); -#else +#endif +#ifdef __FreeBSD__ int fd; fd = g_open(arg, 0); @@ -402,6 +408,17 @@ } return (B_FALSE); #endif +#ifdef __NetBSD__ + struct disklabel dl; + int fd, rv; + + if ((fd = open(arg, O_RDWR | O_NONBLOCK)) < 0) + return (B_FALSE); + + rv = ioctl(fd, DIOCGDINFO, &dl); + close(fd); + return (rv == 0); +#endif } /* Only in /tmp/out/external/cddl/osnet/dist/cmd: zstreamdump diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_create.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_create.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_create.c 2015-06-17 08:54:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_create.c 2016-04-20 20:13:05.000000000 -0700 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. @@ -52,7 +55,11 @@ ctf_file_t * ctf_create(int *errp) { - static const ctf_header_t hdr = { { CTF_MAGIC, CTF_VERSION, 0 } }; + static const ctf_header_t hdr = { .cth_preamble = { + .ctp_magic = CTF_MAGIC, + .ctp_version = CTF_VERSION, + .ctp_flags = 0 + } }; const ulong_t hashlen = 128; ctf_dtdef_t **hash = ctf_alloc(hashlen * sizeof (ctf_dtdef_t *)); @@ -62,10 +69,10 @@ if (hash == NULL) return (ctf_set_open_errno(errp, EAGAIN)); - cts.cts_name = _CTF_SECTION; + cts.cts_name = __UNCONST(_CTF_SECTION); cts.cts_type = SHT_PROGBITS; cts.cts_flags = 0; - cts.cts_data = (void *)&hdr; + cts.cts_data = __UNCONST(&hdr); cts.cts_size = sizeof (hdr); cts.cts_entsize = 1; cts.cts_offset = 0; @@ -609,8 +616,11 @@ if (!(fp->ctf_flags & LCTF_RDWR)) return (ctf_set_errno(fp, ECTF_RDONLY)); - if (CTF_INDEX_TO_TYPE(fp->ctf_dtnextid, 1) > CTF_MAX_TYPE) + if (CTF_TYPE_ISCHILD(fp->ctf_dtnextid) || + CTF_INDEX_TO_TYPE(fp->ctf_dtnextid, 1) > CTF_MAX_TYPE) { + ctf_dprintf("type id overflow %lu\n", fp->ctf_dtnextid); return (ctf_set_errno(fp, ECTF_FULL)); + } if ((dtd = ctf_alloc(sizeof (ctf_dtdef_t))) == NULL) return (ctf_set_errno(fp, EAGAIN)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_decl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_decl.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_decl.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_decl.c 2016-02-06 09:38:15.000000000 -0800 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_error.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_error.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_error.c 2013-09-02 04:36:32.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_error.c 2016-01-06 05:18:43.000000000 -0800 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_hash.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_hash.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_hash.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_hash.c 2016-01-06 05:18:43.000000000 -0800 @@ -20,6 +20,9 @@ * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -43,7 +46,7 @@ */ if (nelems == 0) { bzero(hp, sizeof (ctf_hash_t)); - hp->h_buckets = (ushort_t *)_CTF_EMPTY; + hp->h_buckets = __UNCONST(_CTF_EMPTY); hp->h_nbuckets = 1; return (0); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_impl.h --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_impl.h 2013-09-02 04:36:32.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_impl.h 2016-02-06 09:38:15.000000000 -0800 @@ -303,7 +303,7 @@ extern void ctf_decl_init(ctf_decl_t *, char *, size_t); extern void ctf_decl_fini(ctf_decl_t *); extern void ctf_decl_push(ctf_decl_t *, ctf_file_t *, ctf_id_t); -extern void ctf_decl_sprintf(ctf_decl_t *, const char *, ...); +extern void ctf_decl_sprintf(ctf_decl_t *, const char *, ...) __printflike(2,3); extern const char *ctf_strraw(ctf_file_t *, uint_t); extern const char *ctf_strptr(ctf_file_t *, uint_t); @@ -323,7 +323,7 @@ extern char *ctf_strdup(const char *); extern const char *ctf_strerror(int); -extern void ctf_dprintf(const char *, ...); +extern void ctf_dprintf(const char *, ...) __printflike(1, 2); extern void *ctf_zopen(int *); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_labels.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_labels.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_labels.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_labels.c 2016-01-06 05:18:43.000000000 -0800 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -54,9 +57,9 @@ const char * ctf_label_topmost(ctf_file_t *fp) { - const ctf_lblent_t *ctlp; + const ctf_lblent_t *ctlp = NULL; // XXX: gcc const char *s; - uint_t num_labels; + uint_t num_labels = 0; // XXX: gcc if (extract_label_info(fp, &ctlp, &num_labels) == CTF_ERR) return (NULL); /* errno is set */ @@ -79,8 +82,8 @@ int ctf_label_iter(ctf_file_t *fp, ctf_label_f *func, void *arg) { - const ctf_lblent_t *ctlp; - uint_t i, num_labels; + const ctf_lblent_t *ctlp = NULL; // XXX: gcc + uint_t i, num_labels = 0; // XXX: gcc ctf_lblinfo_t linfo; const char *lname; int rc; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_lookup.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_lookup.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_lookup.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_lookup.c 2016-01-06 05:18:43.000000000 -0800 @@ -20,6 +20,9 @@ * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -90,7 +93,7 @@ return (ctf_set_errno(fp, EINVAL)); for (p = name, end = name + strlen(name); *p != '\0'; p = q) { - while (isspace(*p)) + while (isspace((unsigned char)*p)) p++; /* skip leading ws */ if (p == end) @@ -132,13 +135,13 @@ for (lp = fp->ctf_lookups; lp->ctl_prefix != NULL; lp++) { if (lp->ctl_prefix[0] == '\0' || strncmp(p, lp->ctl_prefix, (size_t)(q - p)) == 0) { - for (p += lp->ctl_len; isspace(*p); p++) + for (p += lp->ctl_len; isspace((unsigned char)*p); p++) continue; /* skip prefix and next ws */ if ((q = strchr(p, '*')) == NULL) q = end; /* compare until end */ - while (isspace(q[-1])) + while (isspace((unsigned char)q[-1])) q--; /* exclude trailing ws */ if ((hp = ctf_hash_lookup(lp->ctl_hash, fp, p, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_open.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_open.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_open.c 2014-07-17 09:19:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_open.c 2016-01-06 05:18:43.000000000 -0800 @@ -20,6 +20,9 @@ * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -81,7 +84,7 @@ } static const ctf_fileops_t ctf_fileops[] = { - { NULL, NULL }, + { NULL, NULL, NULL }, { get_kind_v1, get_root_v1, get_vlen_v1 }, { get_kind_v2, get_root_v2, get_vlen_v2 }, }; @@ -200,9 +203,9 @@ init_types(ctf_file_t *fp, const ctf_header_t *cth) { /* LINTED - pointer alignment */ - const ctf_type_t *tbuf = (ctf_type_t *)(fp->ctf_buf + cth->cth_typeoff); + const ctf_type_t *tbuf = (const ctf_type_t *)(fp->ctf_buf + cth->cth_typeoff); /* LINTED - pointer alignment */ - const ctf_type_t *tend = (ctf_type_t *)(fp->ctf_buf + cth->cth_stroff); + const ctf_type_t *tend = (const ctf_type_t *)(fp->ctf_buf + cth->cth_stroff); ulong_t pop[CTF_K_MAX + 1] = { 0 }; const ctf_type_t *tp; @@ -695,11 +698,11 @@ fp->ctf_strtab.cts_name = ctf_strdup(fp->ctf_strtab.cts_name); if (fp->ctf_data.cts_name == NULL) - fp->ctf_data.cts_name = _CTF_NULLSTR; + fp->ctf_data.cts_name = __UNCONST(_CTF_NULLSTR); if (fp->ctf_symtab.cts_name == NULL) - fp->ctf_symtab.cts_name = _CTF_NULLSTR; + fp->ctf_symtab.cts_name = __UNCONST(_CTF_NULLSTR); if (fp->ctf_strtab.cts_name == NULL) - fp->ctf_strtab.cts_name = _CTF_NULLSTR; + fp->ctf_strtab.cts_name = __UNCONST(_CTF_NULLSTR); fp->ctf_str[CTF_STRTAB_0].cts_strs = (const char *)buf + hp.cth_stroff; fp->ctf_str[CTF_STRTAB_0].cts_len = hp.cth_strlen; @@ -919,24 +922,24 @@ if (fp->ctf_data.cts_name != _CTF_NULLSTR && fp->ctf_data.cts_name != NULL) { - ctf_free((char *)fp->ctf_data.cts_name, + ctf_free(__UNCONST(fp->ctf_data.cts_name), strlen(fp->ctf_data.cts_name) + 1); } if (fp->ctf_symtab.cts_name != _CTF_NULLSTR && fp->ctf_symtab.cts_name != NULL) { - ctf_free((char *)fp->ctf_symtab.cts_name, + ctf_free(__UNCONST(fp->ctf_symtab.cts_name), strlen(fp->ctf_symtab.cts_name) + 1); } if (fp->ctf_strtab.cts_name != _CTF_NULLSTR && fp->ctf_strtab.cts_name != NULL) { - ctf_free((char *)fp->ctf_strtab.cts_name, + ctf_free(__UNCONST(fp->ctf_strtab.cts_name), strlen(fp->ctf_strtab.cts_name) + 1); } if (fp->ctf_base != fp->ctf_data.cts_data && fp->ctf_base != NULL) - ctf_data_free((void *)fp->ctf_base, fp->ctf_size); + ctf_data_free(__UNCONST(fp->ctf_base), fp->ctf_size); if (fp->ctf_sxlate != NULL) ctf_free(fp->ctf_sxlate, sizeof (uint_t) * fp->ctf_nsyms); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_types.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_types.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_types.c 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_types.c 2017-04-11 02:42:30.000000000 -0700 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. @@ -420,7 +423,7 @@ const void *vmp; (void) ctf_get_ctt_size(fp, tp, &size, &increment); - vmp = (uchar_t *)tp + increment; + vmp = (uchar_t *)__UNCONST(tp) + increment; if (LCTF_INFO_KIND(fp, tp->ctt_info) == CTF_K_STRUCT) n = MIN(n, 1); /* only use first member for structs */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_util.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_util.c --- /tmp/out/external/cddl/osnet/dist/common/ctf/ctf_util.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/ctf/ctf_util.c 2016-01-06 05:18:43.000000000 -0800 @@ -19,6 +19,9 @@ * * CDDL HEADER END */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/nvpair/fnvpair.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/nvpair/fnvpair.c --- /tmp/out/external/cddl/osnet/dist/common/nvpair/fnvpair.c 2015-08-29 19:17:08.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/nvpair/fnvpair.c 2017-12-05 15:07:28.000000000 -0800 @@ -1,4 +1,3 @@ - /* * CDDL HEADER START * @@ -27,6 +26,7 @@ #include #ifndef _KERNEL #include +#include #else #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/nvpair/nvpair.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/nvpair/nvpair.c --- /tmp/out/external/cddl/osnet/dist/common/nvpair/nvpair.c 2016-10-10 04:10:01.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/nvpair/nvpair.c 2017-12-05 15:13:11.000000000 -0800 @@ -44,7 +44,7 @@ #endif #define skip_whitespace(p) while ((*(p) == ' ') || (*(p) == '\t')) p++ -#if defined(__FreeBSD__) && !defined(_KERNEL) +#if !defined(illumos) && !defined(_KERNEL) /* * libnvpair is the lowest commen denominator for ZFS related libraries, * defining aok here makes it usable by all ZFS related libraries @@ -260,12 +260,6 @@ nvl->nvl_pad = 0; } -uint_t -nvlist_nvflag(nvlist_t *nvl) -{ - return (nvl->nvl_nvflag); -} - /* * nvlist_alloc - Allocate nvlist. */ @@ -2261,7 +2255,7 @@ int err = 0; nvstream_t nvs; int nvl_endian; -#if BYTE_ORDER == _LITTLE_ENDIAN +#ifdef _LITTLE_ENDIAN int host_endian = 1; #else int host_endian = 0; @@ -2585,15 +2579,14 @@ { if (nvs->nvs_op == NVS_OP_ENCODE) { nvs_native_t *native = (nvs_native_t *)nvs->nvs_private; - char *packed = (void *) + nvlist_t *packed = (void *) (native->n_curr - nvp->nvp_size + NVP_VALOFF(nvp)); /* * Null out the pointer that is meaningless in the packed * structure. The address may not be aligned, so we have * to use bzero. */ - bzero(packed + offsetof(nvlist_t, nvl_priv), - sizeof(((nvlist_t *)NULL)->nvl_priv)); + bzero(&packed->nvl_priv, sizeof (packed->nvl_priv)); } return (nvs_embedded(nvs, EMBEDDED_NVL(nvp))); @@ -2606,6 +2599,7 @@ nvs_native_t *native = (nvs_native_t *)nvs->nvs_private; char *value = native->n_curr - nvp->nvp_size + NVP_VALOFF(nvp); size_t len = NVP_NELEM(nvp) * sizeof (uint64_t); + nvlist_t *packed = (nvlist_t *)((uintptr_t)value + len); int i; /* * Null out pointers that are meaningless in the packed @@ -2614,17 +2608,13 @@ */ bzero(value, len); - value += len; - for (i = 0; i < NVP_NELEM(nvp); i++) { + for (i = 0; i < NVP_NELEM(nvp); i++, packed++) /* * Null out the pointer that is meaningless in the * packed structure. The address may not be aligned, * so we have to use bzero. */ - bzero(value + offsetof(nvlist_t, nvl_priv), - sizeof(((nvlist_t *)NULL)->nvl_priv)); - value += sizeof(nvlist_t); - } + bzero(&packed->nvl_priv, sizeof (packed->nvl_priv)); } return (nvs_embedded_nvl_array(nvs, nvp, NULL)); @@ -3023,11 +3013,13 @@ */ ret = xdr_longlong_t(xdr, (void *)buf); break; +#ifndef __NetBSD__ #if !defined(_KERNEL) case DATA_TYPE_DOUBLE: ret = xdr_double(xdr, (void *)buf); break; #endif +#endif case DATA_TYPE_STRING: ret = xdr_string(xdr, &buf, buflen - 1); break; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/zfs/zfeature_common.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfeature_common.c --- /tmp/out/external/cddl/osnet/dist/common/zfs/zfeature_common.c 2016-06-27 20:14:26.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfeature_common.c 2017-06-27 16:57:12.000000000 -0700 @@ -232,6 +232,7 @@ "org.open-zfs:large_blocks", "large_blocks", "Support for blocks larger than 128KB.", ZFEATURE_FLAG_PER_DATASET, large_blocks_deps); +#ifndef __NetBSD__ zfeature_register(SPA_FEATURE_SHA512, "org.illumos:sha512", "sha512", "SHA-512/256 hash algorithm.", @@ -240,6 +241,7 @@ "org.illumos:skein", "skein", "Skein hash algorithm.", ZFEATURE_FLAG_PER_DATASET, NULL); +#endif #ifdef illumos zfeature_register(SPA_FEATURE_EDONR, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/zfs/zfeature_common.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfeature_common.h --- /tmp/out/external/cddl/osnet/dist/common/zfs/zfeature_common.h 2016-06-27 20:14:26.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfeature_common.h 2017-06-27 16:57:31.000000000 -0700 @@ -52,8 +52,10 @@ SPA_FEATURE_BOOKMARKS, SPA_FEATURE_FS_SS_LIMIT, SPA_FEATURE_LARGE_BLOCKS, +#ifndef __NetBSD__ SPA_FEATURE_SHA512, SPA_FEATURE_SKEIN, +#endif #ifdef illumos SPA_FEATURE_EDONR, #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/zfs/zfs_ioctl_compat.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfs_ioctl_compat.h --- /tmp/out/external/cddl/osnet/dist/common/zfs/zfs_ioctl_compat.h 2016-10-10 04:10:02.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfs_ioctl_compat.h 2017-04-25 16:40:33.000000000 -0700 @@ -28,6 +28,7 @@ #define _SYS_ZFS_IOCTL_COMPAT_H #include +#include #include #include #include @@ -401,7 +402,7 @@ } zfs_cmd_inlanes_t; #ifdef _KERNEL -unsigned static long zfs_ioctl_v15_to_v28[] = { +static unsigned long zfs_ioctl_v15_to_v28[] = { 0, /* 0 ZFS_IOC_POOL_CREATE */ 1, /* 1 ZFS_IOC_POOL_DESTROY */ 2, /* 2 ZFS_IOC_POOL_IMPORT */ @@ -459,7 +460,7 @@ }; #else /* KERNEL */ -unsigned static long zfs_ioctl_v28_to_v15[] = { +static unsigned long zfs_ioctl_v28_to_v15[] = { 0, /* 0 ZFS_IOC_POOL_CREATE */ 1, /* 1 ZFS_IOC_POOL_DESTROY */ 2, /* 2 ZFS_IOC_POOL_IMPORT */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/zfs/zfs_prop.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfs_prop.c --- /tmp/out/external/cddl/osnet/dist/common/zfs/zfs_prop.c 2016-06-27 20:14:26.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zfs_prop.c 2017-06-27 17:04:06.000000000 -0700 @@ -72,8 +72,10 @@ { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, { "sha256", ZIO_CHECKSUM_SHA256 }, { "noparity", ZIO_CHECKSUM_NOPARITY }, +#ifndef __NetBSD__ { "sha512", ZIO_CHECKSUM_SHA512 }, { "skein", ZIO_CHECKSUM_SKEIN }, +#endif #ifdef illumos { "edonr", ZIO_CHECKSUM_EDONR }, #endif @@ -87,12 +89,14 @@ { "sha256", ZIO_CHECKSUM_SHA256 }, { "sha256,verify", ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, +#ifndef __NetBSD__ { "sha512", ZIO_CHECKSUM_SHA512 }, { "sha512,verify", ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY }, { "skein", ZIO_CHECKSUM_SKEIN }, { "skein,verify", ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY }, +#endif #ifdef illumos { "edonr,verify", ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY }, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/common/zfs/zprop_common.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zprop_common.c --- /tmp/out/external/cddl/osnet/dist/common/zfs/zprop_common.c 2013-03-23 08:29:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/common/zfs/zprop_common.c 2017-06-16 10:20:43.000000000 -0700 @@ -42,8 +42,12 @@ #if defined(_KERNEL) #include +#ifdef __FreeBSD__ #include #else +#include +#endif +#else #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf.5 /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf.5 --- /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf.5 2014-12-11 03:54:49.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf.5 2015-10-04 20:09:34.000000000 -0700 @@ -1,3 +1,4 @@ +.\" $NetBSD: ctf.5,v 1.3 2015/09/29 06:33:01 wiz Exp $ .\" .\" This file and its contents are supplied under the terms of the .\" Common Development and Distribution License ("CDDL"), version 1.0. @@ -11,7 +12,7 @@ .\" .\" Copyright (c) 2014 Joyent, Inc. .\" -.Dd Sep 26, 2014 +.Dd September 26, 2014 .Dt CTF 5 .Os .Sh NAME @@ -39,7 +40,8 @@ sizes of C types, including intrinsic types, enumerations, structures, typedefs, and unions, that are used by the corresponding .Sy ELF -object. The +object. +The .Nm data may also include information about the types of global objects and the return type and arguments of functions in the symbol table. @@ -53,19 +55,22 @@ .Lp On illumos systems, .Nm -data is consumed by multiple programs. It can be used by the modular -debugger, -.Xr mdb 1 , -as well as by -.Xr dtrace 1M . +data is consumed by multiple programs. +It can be used by +.\" the modular +.\" debugger, +.\" .Xr mdb 1 , +.\" as well as by +.Xr dtrace 1 . Programmatic access to .Nm data can be obtained through -.Xr libctf 3LIB . +.Xr libctf 3 . .Lp The .Nm -file format is broken down into seven different sections. The first +file format is broken down into seven different sections. +The first section is the .Sy preamble and @@ -74,18 +79,22 @@ .Nm file, links it has to other .Nm -files, and the sizes of the other sections. The next section is the +files, and the sizes of the other sections. +The next section is the .Sy label section, which provides a way of identifying similar groups of .Nm -data across multiple files. This is followed by the +data across multiple files. +This is followed by the .Sy object information section, which describes the type of global -symbols. The subsequent section is the +symbols. +The subsequent section is the .Sy function information section, which describes the return -types and arguments of functions. The next section is the +types and arguments of functions. +The next section is the .Sy type information section, which describes the format and layout of the C types themselves, and finally the last @@ -106,28 +115,33 @@ file may contain all of the type information that it requires, or it may optionally refer to another .Nm -file which holds the remaining types. When a +file which holds the remaining types. +When a .Nm file refers to another file, it is called the .Sy child and the file it refers to is called the .Sy parent . -A given file may only refer to one parent. This process is called +A given file may only refer to one parent. +This process is called .Em uniquification because it ensures each child only has type information that is -unique to it. A common example of this is that most kernel modules in +unique to it. +A common example of this is that most kernel modules in illumos are uniquified against the kernel module .Sy genunix and the type information that comes from the .Sy IP -module. This means that a module only has types that are unique to +module. +This means that a module only has types that are unique to itself and the most common types in the kernel are not duplicated. .Sh FILE FORMAT This documents version .Em two of the .Nm -file format. All applications and tools currently produce and operate on +file format. +All applications and tools currently produce and operate on this version. .Lp The file format can be summarized with the following image, the @@ -235,25 +249,31 @@ .Sy preamble defines the version of the .Nm -file which defines the format of the rest of the header. While the +file which defines the format of the rest of the header. +While the header may change in subsequent versions, the preamble will not change across versions, though the interpretation of its flags may change from -version to version. The +version to version. +The .Em ctp_magic member defines the magic number for the .Nm -file format. This must always be +file format. +This must always be .Li 0xcff1 . If another value is encountered, then the file should not be treated as a .Nm -file. The +file. +The .Em ctp_version member defines the version of the .Nm -file. The current version is +file. +The current version is .Li 2 . -It is possible to encounter an unsupported version. In that case, +It is possible to encounter an unsupported version. +In that case, software should not try to parse the format, as it may have changed. Finally, the .Em ctp_flags @@ -273,8 +293,10 @@ .Sy zlib library and its .Sy deflate -algorithm. If this flag is not present, then the body has not been -compressed and no special action is needed to interpret it. All offsets +algorithm. +If this flag is not present, then the body has not been +compressed and no special action is needed to interpret it. +All offsets into the data as described by .Sy header , always refer to the @@ -289,7 +311,8 @@ .Nm file is the child of another .Nm -file and also indicates the size of the remaining sections. The +file and also indicates the size of the remaining sections. +The structure for the .Sy header , logically contains a copy of the @@ -315,37 +338,46 @@ .Em cth_parlablel and .Em cth_parname , -are used to identify the parent. The value of both members are offsets +are used to identify the parent. +The value of both members are offsets into the .Sy string -section which point to the start of a null-terminated string. For more +section which point to the start of a null-terminated string. +For more information on the encoding of strings, see the subsection on .Sx String Identifiers . If the value of either is zero, then there is no entry for that -member. If the member +member. +If the member .Em cth_parlabel is set, then the .Em ctf_parname member must be set, otherwise it will not be possible to find the -parent. If +parent. +If .Em ctf_parname is set, it is not necessary to define .Em cth_parlabel , -as the parent may not have a label. For more information on labels +as the parent may not have a label. +For more information on labels and their interpretation, see .Sx The Label Section . .Lp The remaining members (excepting .Em cth_strlen ) -describe the beginning of the corresponding sections. These offsets are +describe the beginning of the corresponding sections. +These offsets are relative to the end of the .Sy header . Therefore, something with an offset of 0 is at an offset of thirty-six bytes relative to the start of the .Nm -file. The difference between members -indicates the size of the section itself. Different offsets have -different alignment requirements. The start of the +file. +The difference between members +indicates the size of the section itself. +Different offsets have +different alignment requirements. +The start of the .Em cth_objotoff and .Em cth_funcoff @@ -353,12 +385,15 @@ .Em cth_lbloff and .Em cth_typeoff -must be four-byte aligned. The section +must be four-byte aligned. +The section .Em cth_stroff -has no alignment requirements. To calculate the size of a given section, +has no alignment requirements. +To calculate the size of a given section, excepting the .Sy string -section, one should subtract the offset of the section from the following one. For +section, one should subtract the offset of the section from the following one. +For example, the size of the .Sy types section can be calculated by subtracting @@ -368,7 +403,8 @@ .Lp Finally, the member .Em cth_strlen -describes the length of the string section itself. From it, you can also +describes the length of the string section itself. +From it, you can also calculate the size of the entire .Nm file by adding together the size of the @@ -380,9 +416,11 @@ .Ss Type Identifiers Through the .Nm ctf -data, types are referred to by identifiers. A given +data, types are referred to by identifiers. +A given .Nm -file supports up to 32767 (0x7fff) types. The first valid type identifier is 0x1. +file supports up to 32767 (0x7fff) types. +The first valid type identifier is 0x1. When a given .Nm file is a child, indicated by a non-zero entry for the @@ -403,16 +441,20 @@ information may use larger or opaque identifiers. .Ss String Identifiers String identifiers are always encoded as four byte unsigned integers -which are an offset into a string table. The +which are an offset into a string table. +The .Nm format supports two different string tables which have an identifier of -zero or one. This identifier is stored in the high-order bit of the -unsigned four byte offset. Therefore, the maximum supported offset into +zero or one. +This identifier is stored in the high-order bit of the +unsigned four byte offset. +Therefore, the maximum supported offset into one of these tables is 0x7ffffffff. .Lp Table identifier zero, always refers to the .Sy string -section in the CTF file itself. String table identifier one refers to an +section in the CTF file itself. +String table identifier one refers to an external string table which is the ELF string table for the ELF symbol table associated with the .Nm @@ -434,7 +476,8 @@ .Lp The 16 bits that make up the encoding are broken down such that you have five bits for the kind, one bit for indicating whether or not it is a -root type, and 10 bits for the variable length. This is laid out as +root type, and 10 bits for the variable length. +This is laid out as follows: .Bd -literal -offset indent +--------------------+ @@ -443,12 +486,14 @@ 15 11 10 9 0 .Ed .Lp -The current version of the file format defines 14 different kinds. The +The current version of the file format defines 14 different kinds. +The interpretation of these different kinds will be discussed in the section .Sx The Type Section . If a kind is encountered that is not listed below, then it is not a valid .Nm -file. The kinds are defined as follows: +file. +The kinds are defined as follows: .Bd -literal -offset indent #define CTF_K_UNKNOWN 0 #define CTF_K_INTEGER 1 @@ -467,14 +512,18 @@ .Ed .Lp Programs directly reference many types; however, other types are referenced -indirectly because they are part of some other structure. These types that are +indirectly because they are part of some other structure. +These types that are referenced directly and used are called .Sy root -types. Other types may be used indirectly, for example, a program may reference -a structure directly, but not one of its members which has a type. That type is +types. +Other types may be used indirectly, for example, a program may reference +a structure directly, but not one of its members which has a type. +That type is not considered a .Sy root -type. If a type is a +type. +If a type is a .Sy root type, then it will have bit 10 set. .Lp @@ -499,14 +548,18 @@ .Nm data, it is often useful to know whether two different .Nm -containers come from the same source base and version. For example, when +containers come from the same source base and version. +For example, when building illumos, there are many kernel modules that are built against a -single collection of source code. A label is encoded into the +single collection of source code. +A label is encoded into the .Nm -files that corresponds with the particular build. This ensures that if +files that corresponds with the particular build. +This ensures that if files on the system were to become mixed up from multiple releases, that they are not used together by tools, particularly when a child needs to -refer to a type in the parent. Because they are linked used the type +refer to a type in the parent. +Because they are linked used the type identifiers, if the wrong parent is used then the wrong type will be encountered. .Lp @@ -530,20 +583,24 @@ The type identifier encoded in the member .Em ctl_typeidx refers to the last type identifier that a label refers to in the current -file. Labels only refer to types in the current file, if the +file. +Labels only refer to types in the current file, if the .Nm file is a child, then it will have the same label as its parent; however, its label will only refer to its types, not its parents. .Lp It is also possible, though rather uncommon, for a .Nm -file to have multiple labels. Labels are placed one after another, every -eight bytes. When multiple labels are present, types may only belong to +file to have multiple labels. +Labels are placed one after another, every +eight bytes. +When multiple labels are present, types may only belong to a single label. .Ss The Object Section The object section provides a mapping from ELF symbols of type .Sy STT_OBJECT -in the symbol table to a type identifier. Every entry in this section is +in the symbol table to a type identifier. +Every entry in this section is a .Sy uint16_t which contains a type identifier as described in the section @@ -555,8 +612,11 @@ .Sy symbol table in the ELF object that contains the .Nm -data. Not every object is included in this section. Specifically, when -walking the symbol table. An entry is skipped if it matches any of the +data. +Not every object is included in this section. +Specifically, when +walking the symbol table. +An entry is skipped if it matches any of the following conditions: .Lp .Bl -bullet -offset indent -compact @@ -628,11 +688,13 @@ The function section of the .Nm file encodes the types of both the function's arguments and the function's -return type. Similar to +return type. +Similar to .Sx The Object Section , the function section encodes information for all symbols of type .Sy STT_FUNCTION , -excepting those that fit specific criteria. Unlike with objects, because +excepting those that fit specific criteria. +Unlike with objects, because functions have a variable number of arguments, they start with a type encoding as defined in .Sx Type Encoding , @@ -640,26 +702,35 @@ .Sy uint16_t . For functions which have no type information available, they are encoded as .Li CTF_TYPE_INFO(CTF_K_UNKNOWN, 0, 0) . -Functions with arguments are encoded differently. Here, the variable length is -turned into the number of arguments in the function. If a function is a +Functions with arguments are encoded differently. +Here, the variable length is +turned into the number of arguments in the function. +If a function is a .Sy varargs -type function, then the number of arguments is increased by one. Functions with +type function, then the number of arguments is increased by one. +Functions with type information are encoded as: .Li CTF_TYPE_INFO(CTF_K_FUNCTION, 0, nargs) . .Lp For functions that have no type information, nothing else is encoded, and the -next function is encoded. For functions with type information, the next +next function is encoded. +For functions with type information, the next .Sy uint16_t -is encoded with the type identifier of the return type of the function. It is +is encoded with the type identifier of the return type of the function. +It is followed by each of the type identifiers of the arguments, if any exist, in the -order that they appear in the function. Therefore, argument 0 is the first type -identifier and so on. When a function has a final varargs argument, that is +order that they appear in the function. +Therefore, argument 0 is the first type +identifier and so on. +When a function has a final varargs argument, that is encoded with the type identifier of zero. .Lp Like .Sx The Object Section , -the function section is encoded in the order of the symbol table. It has -similar, but slightly different considerations from objects. While iterating the +the function section is encoded in the order of the symbol table. +It has +similar, but slightly different considerations from objects. +While iterating the symbol table, if any of the following conditions are true, then the entry is skipped and no corresponding entry is written: .Lp @@ -683,9 +754,12 @@ .Ss The Type Section The type section is the heart of the .Nm -data. It encodes all of the information about the types themselves. The base of +data. +It encodes all of the information about the types themselves. +The base of the type information comes in two forms, a short form and a long form, each of -which may be followed by a variable number of arguments. The following +which may be followed by a variable number of arguments. +The following definitions describe the short and long forms: .Bd -literal #define CTF_MAX_SIZE 0xfffe /* max size of a type in bytes */ @@ -720,14 +794,17 @@ .Sy bytes . The basic small form uses a .Sy ushort_t -to store the number of bytes. If the number of bytes in a structure would exceed +to store the number of bytes. +If the number of bytes in a structure would exceed 0xfffe, then the alternate form, the .Sy ctf_type_t , -is used instead. To indicate that the larger form is being used, the member +is used instead. +To indicate that the larger form is being used, the member .Em ctt_size is set to value of .Sy CTF_LSIZE_SENT -(0xffff). In general, when going through the type section, consumers use the +(0xffff). +In general, when going through the type section, consumers use the .Sy ctf_type_t structure, but pay attention to the value of the member .Em ctt_size @@ -739,14 +816,18 @@ .Sy ctt_size . Those which do not, will always use the .Sy ctf_stype_t -structure. The individual sections for each kind have more information. +structure. +The individual sections for each kind have more information. .Lp -Types are written out in order. Therefore the first entry encountered has a type -id of 0x1, or 0x8000 if a child. The member +Types are written out in order. +Therefore the first entry encountered has a type +id of 0x1, or 0x8000 if a child. +The member .Em ctt_name is encoded as described in the section .Sx String Identifiers . -The string that it points to is the name of the type. If the identifier points +The string that it points to is the name of the type. +If the identifier points to an empty string (one that consists solely of a null terminator) then the type does not have a name, this is common with anonymous structures and unions that only have a typedef to name them, as well as, pointers and qualifiers. @@ -757,17 +838,22 @@ .Sx Type Encoding . The types kind tells us how to interpret the remaining data in the .Sy ctf_type_t -and any variable length data that may exist. The rest of this section will be +and any variable length data that may exist. +The rest of this section will be broken down into the interpretation of the various kinds. .Ss Encoding of Integers Integers, which are of type .Sy CTF_K_INTEGER , -have no variable length arguments. Instead, they are followed by a four byte +have no variable length arguments. +Instead, they are followed by a four byte .Sy uint_t -which describes their encoding. All integers must be encoded with a variable -length of zero. The +which describes their encoding. +All integers must be encoded with a variable +length of zero. +The .Em ctt_size -member describes the length of the integer in bytes. In general, integer sizes +member describes the length of the integer in bytes. +In general, integer sizes will be rounded up to the closest power of two. .Lp The integer encoding contains three different pieces of information: @@ -804,32 +890,39 @@ .Lp By default, an integer is considered to be unsigned, unless it has the .Sy CTF_INT_SIGNED -flag set. If the flag +flag set. +If the flag .Sy CTF_INT_CHAR is set, that indicates that the integer is of a type that stores character data, for example the intrinsic C type .Sy char would have the .Sy CTF_INT_CHAR -flag set. If the flag +flag set. +If the flag .Sy CTF_INT_BOOL -is set, that indicates that the integer represents a boolean type. For example, +is set, that indicates that the integer represents a boolean type. +For example, the intrinsic C type .Sy _Bool would have the .Sy CTF_INT_BOOL -flag set. Finally, the flag +flag set. +Finally, the flag .Sy CTF_INT_VARARGS indicates that the integer is used as part of a variable number of arguments. This encoding is rather uncommon. .Ss Encoding of Floats Floats, which are of type .Sy CTF_K_FLOAT , -are similar to their integer counterparts. They have no variable length +are similar to their integer counterparts. +They have no variable length arguments and are followed by a four byte encoding which describes the kind of -float that exists. The +float that exists. +The .Em ctt_size -member is the size, in bytes, of the float. The float encoding has three +member is the size, in bytes, of the float. +The float encoding has three different pieces of information inside of it: .Lp .Bl -bullet -offset indent -compact @@ -856,9 +949,13 @@ .Ed .Lp Where as the encoding for integers was a series of flags, the encoding for -floats maps to a specific kind of float. It is not a flag-based value. The kinds of floats -correspond to both their size, and the encoding. This covers all of the basic C -intrinsic floating point types. The following are the different kinds of floats +floats maps to a specific kind of float. +It is not a flag-based value. +The kinds of floats +correspond to both their size, and the encoding. +This covers all of the basic C +intrinsic floating point types. +The following are the different kinds of floats represented in the encoding: .Bd -literal -offset indent #define CTF_FP_SINGLE 1 /* IEEE 32-bit float encoding */ @@ -877,12 +974,15 @@ .Ss Encoding of Arrays Arrays, which are of type .Sy CTF_K_ARRAY , -have no variable length arguments. They are followed by a structure which +have no variable length arguments. +They are followed by a structure which describes the number of elements in the array, the type identifier of the -elements in the array, and the type identifier of the index of the array. With +elements in the array, and the type identifier of the index of the array. +With arrays, the .Em ctt_size -member is set to zero. The structure that follows an array is defined as: +member is set to zero. +The structure that follows an array is defined as: .Bd -literal typedef struct ctf_array { ushort_t cta_contents; /* reference to type of array contents */ @@ -901,14 +1001,17 @@ .Sx Type Identifiers . The member .Em cta_nelems -is a simple four byte unsigned count of the number of elements. This count may +is a simple four byte unsigned count of the number of elements. +This count may be zero when encountering C99's flexible array members. .Ss Encoding of Functions Function types, which are of type .Sy CTF_K_FUNCTION , -use the variable length list to be the number of arguments in the function. When +use the variable length list to be the number of arguments in the function. +When the function has a final member which is a varargs, then the argument count is -incremented by one to account for the variable argument. Here, the +incremented by one to account for the variable argument. +Here, the .Em ctt_type member is encoded with the type identifier of the return type of the function. Note that the @@ -916,31 +1019,40 @@ member is not used here. .Lp The variable argument list contains the type identifiers for the arguments of -the function, if any. Each one is represented by a +the function, if any. +Each one is represented by a .Sy uint16_t and encoded according to the .Sx Type Identifiers -section. If the function's last argument is of type varargs, then it is also -written out, but the type identifier is zero. This is included in the count of +section. +If the function's last argument is of type varargs, then it is also +written out, but the type identifier is zero. +This is included in the count of the function's arguments. .Ss Encoding of Structures and Unions Structures and Unions, which are encoded with .Sy CTF_K_STRUCT and .Sy CTF_K_UNION -respectively, are very similar constructs in C. The main difference +respectively, are very similar constructs in C. +The main difference between them is the fact that every member of a structure follows one another, -where as in a union, all members share the same memory. They are also very +where as in a union, all members share the same memory. +They are also very similar in terms of their encoding in .Nm . The variable length argument for structures and unions represents the number of -members that they have. The value of the member +members that they have. +The value of the member .Em ctt_size -is the size of the structure and union. There are two different structures which -are used to encode members in the variable list. When the size of a structure or +is the size of the structure and union. +There are two different structures which +are used to encode members in the variable list. +When the size of a structure or union is greater than or equal to the large member threshold, 8192, then a different structure is used to encode the member, all members are encoded using -the same structure. The structure for members is as follows: +the same structure. +The structure for members is as follows: .Bd -literal typedef struct ctf_member { uint_t ctm_name; /* reference to name in string table */ @@ -961,34 +1073,42 @@ .Em ctm_name and .Em ctlm_name -refer to the name of the member. The name is encoded as an offset into the +refer to the name of the member. +The name is encoded as an offset into the string table as described by the section .Sx String Identifiers . The members .Sy ctm_type and .Sy ctlm_type -both refer to the type of the member. They are encoded as per the section +both refer to the type of the member. +They are encoded as per the section .Sx Type Identifiers . .Lp The last piece of information that is present is the offset which describes the -offset in memory that the member begins at. For unions, this value will always -be zero because the start of unions in memory is always zero. For structures, +offset in memory that the member begins at. +For unions, this value will always +be zero because the start of unions in memory is always zero. +For structures, this is the offset in .Sy bits -that the member begins at. Note that a compiler may lay out a type with padding. +that the member begins at. +Note that a compiler may lay out a type with padding. This means that the difference in offset between two consecutive members may be -larger than the size of the member. When the size of the overall structure is +larger than the size of the member. +When the size of the overall structure is strictly less than 8192 bytes, the normal structure, .Sy ctf_member_t , is used and the offset in bits is stored in the member .Em ctm_offset . However, when the size of the structure is greater than or equal to 8192 bytes, -then the number of bits is split into two 32-bit quantities. One member, +then the number of bits is split into two 32-bit quantities. +One member, .Em ctlm_offsethi , represents the upper 32 bits of the offset, while the other member, .Em ctlm_offsetlo , -represents the lower 32 bits of the offset. These can be joined together to get +represents the lower 32 bits of the offset. +These can be joined together to get a 64-bit sized offset in bits by shifting the member .Em ctlm_offsethi to the left by thirty two and then doing a binary or of @@ -996,8 +1116,10 @@ .Ss Encoding of Enumerations Enumerations, noted by the type .Sy CTF_K_ENUM , -are similar to structures. Enumerations use the variable list to note the number -of values that the enumeration contains, which we'll term enumerators. In C, an +are similar to structures. +Enumerations use the variable list to note the number +of values that the enumeration contains, which we'll term enumerators. +In C, an enumeration is always equivalent to the intrinsic type .Sy int , thus the value of the member @@ -1032,25 +1154,30 @@ .Sy CTF_K_FORWARD , in a .Nm -file refer to types which may not have a definition at all, only a name. If +file refer to types which may not have a definition at all, only a name. +If the .Nm file is a child, then it may be that the forward is resolved to an actual type in the parent, otherwise the definition may be in another .Nm -container or may not be known at all. The only member of the +container or may not be known at all. +The only member of the .Sy ctf_type_t that matters for a forward declaration is the .Em ctt_name which points to the name of the forward reference in the string table as -described earlier. There is no other information recorded for forward +described earlier. +There is no other information recorded for forward references. .Ss Encoding of Pointers, Typedefs, Volatile, Const, and Restrict Pointers, typedefs, volatile, const, and restrict are all similar in .Nm . -They all refer to another type. In the case of typedefs, they provide an +They all refer to another type. +In the case of typedefs, they provide an alternate name, while volatile, const, and restrict change how the type is -interpreted in the C programming language. This covers the +interpreted in the C programming language. +This covers the .Nm kinds .Sy CTF_K_POINTER , @@ -1066,13 +1193,18 @@ .Ss Encoding of Unknown Types Types with the kind .Sy CTF_K_UNKNOWN -are used to indicate gaps in the type identifier space. These entries consume an -identifier, but do not define anything. Nothing should refer to these gap +are used to indicate gaps in the type identifier space. +These entries consume an +identifier, but do not define anything. +Nothing should refer to these gap identifiers. .Ss Dependencies Between Types -C types can be imagined as a directed, cyclic, graph. Structures and unions may -refer to each other in a way that creates a cyclic dependency. In cases such as -these, the entire type section must be read in and processed. Consumers must +C types can be imagined as a directed, cyclic, graph. +Structures and unions may +refer to each other in a way that creates a cyclic dependency. +In cases such as +these, the entire type section must be read in and processed. +Consumers must not assume that every type can be laid out in dependency order; they cannot. .Ss The String Section @@ -1080,27 +1212,37 @@ .Nm file is the .Sy string -section. This section encodes all of the strings that appear throughout -the other sections. It is laid out as a series of characters followed by -a null terminator. Generally, all names are written out in ASCII, as +section. +This section encodes all of the strings that appear throughout +the other sections. +It is laid out as a series of characters followed by +a null terminator. +Generally, all names are written out in ASCII, as most C compilers do not allow and characters to appear in identifiers -outside of a subset of ASCII. However, any extended characters sets +outside of a subset of ASCII. +However, any extended characters sets should be written out as a series of UTF-8 bytes. .Lp The first entry in the section, at offset zero, is a single null -terminator to reference the empty string. Following that, each C string -should be written out, including the null terminator. Offsets that refer +terminator to reference the empty string. +Following that, each C string +should be written out, including the null terminator. +Offsets that refer to something in this section should refer to the first byte which begins -a string. Beyond the first byte in the section being the null +a string. +Beyond the first byte in the section being the null terminator, the order of strings is unimportant. .Ss Data Encoding and ELF Considerations .Nm data is generally included in ELF objects which specify information to -identify the architecture and endianness of the file. A +identify the architecture and endianness of the file. +A .Nm container inside such an object must match the endianness of the ELF -object. Aside from the question of the endian encoding of data, there -should be no other differences between architectures. While many of the +object. +Aside from the question of the endian encoding of data, there +should be no other differences between architectures. +While many of the types in this document refer to non-fixed size C integral types, they are equivalent in the models .Sy ILP32 @@ -1118,14 +1260,17 @@ container inside of an ELF object, there are certain conventions that are expected for the purposes of tooling being able to find the .Nm -data. In particular, a given ELF object should only contain a single +data. +In particular, a given ELF object should only contain a single .Nm -section. Multiple containers should be merged together into a single +section. +Multiple containers should be merged together into a single one. .Lp The .Nm -file should be included in its own ELF section. The section's name +file should be included in its own ELF section. +The section's name must be .Ql .SUNW_ctf . The type of the section must be diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c --- /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c 2017-03-02 02:59:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf_lib.c 2017-04-12 15:50:09.000000000 -0700 @@ -26,6 +26,10 @@ #pragma ident "%Z%%M% %I% %E% SMI" +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf_subr.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf_subr.c --- /tmp/out/external/cddl/osnet/dist/lib/libctf/common/ctf_subr.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libctf/common/ctf_subr.c 2016-02-06 09:38:15.000000000 -0800 @@ -24,6 +24,10 @@ * Use is subject to license terms. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #pragma ident "%Z%%M% %I% %E% SMI" #include Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace: aarch64 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c 2017-05-08 05:44:43.000000000 -0700 @@ -34,11 +34,12 @@ #include #include #include +#include #include #include -#ifdef __FreeBSD__ +#ifndef illumos #include #endif @@ -172,7 +173,7 @@ char name[sizeof (i) * 2 + 1]; for (i = 0; i < symp->st_size; i += 4) { - (void) sprintf(name, "%lx", i); + (void) snprintf(name, sizeof(name), "%lx", i); if (gmatch(name, pattern)) ftp->ftps_offs[ftp->ftps_noffs++] = i; } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/drti.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/drti.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/drti.c 2016-05-31 04:23:09.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/drti.c 2017-04-12 15:52:42.000000000 -0700 @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -64,7 +65,7 @@ extern dof_hdr_t __SUNW_dof; /* DOF defined in the .SUNW_dof section */ static boolean_t dof_init_debug = B_FALSE; /* From DTRACE_DOF_INIT_DEBUG */ -static void +static void __printflike(2,3) dbg_printf(int debug, const char *fmt, ...) { va_list ap; @@ -146,8 +147,8 @@ elf = (void *)lmp->l_addr; dh.dofhp_dof = (uintptr_t)dof; - dh.dofhp_addr = elf->e_type == ET_DYN ? (uintptr_t) lmp->l_addr : 0; -#ifdef __FreeBSD__ + dh.dofhp_addr = elf && elf->e_type == ET_DYN ? (uintptr_t) lmp->l_addr : 0; +#if defined(__FreeBSD__) || defined(__NetBSD__) dh.dofhp_pid = getpid(); #endif @@ -186,7 +187,7 @@ dbg_printf(1, "DTrace ioctl failed for DOF at %p", dof); else { dbg_printf(1, "DTrace ioctl succeeded for DOF at %p\n", dof); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) gen = dh.dofhp_gen; #endif } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_aggregate.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_aggregate.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_aggregate.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_aggregate.c 2017-04-20 07:50:58.000000000 -0700 @@ -186,7 +186,7 @@ { long double lsum = dt_aggregate_lquantizedsum(lhs); long double rsum = dt_aggregate_lquantizedsum(rhs); - int64_t lzero, rzero; + int64_t lzero = 0, rzero = 0; if (lsum < rsum) return (DT_LESSTHAN); @@ -294,7 +294,7 @@ { int nbuckets = DTRACE_QUANTIZE_NBUCKETS; long double ltotal = 0, rtotal = 0; - int64_t lzero, rzero; + int64_t lzero = 0, rzero = 0; uint_t i; for (i = 0; i < nbuckets; i++) { @@ -1248,7 +1248,7 @@ return (0); } -void +static void dt_aggregate_qsort(dtrace_hdl_t *dtp, void *base, size_t nel, size_t width, int (*compar)(const void *, const void *)) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_as.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_as.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_as.c 2014-07-17 09:19:57.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_as.c 2017-04-12 15:55:13.000000000 -0700 @@ -259,6 +259,8 @@ kbits = ubits = -1u; break; default: + kmask = umask = 0; + kbits = ubits = -1u; xyerror(D_UNKNOWN, "internal error -- invalid link mode %u\n", dtp->dt_linkmode); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c 2016-12-03 09:05:32.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cc.c 2017-04-12 16:04:59.000000000 -0700 @@ -622,7 +622,7 @@ } if (str[0] == '\0') - str = DT_FREOPEN_RESTORE; + str = __UNCONST(DT_FREOPEN_RESTORE); } sdp->dtsd_fmtdata = dt_printf_create(dtp, str); @@ -663,7 +663,7 @@ static void dt_action_trace(dtrace_hdl_t *dtp, dt_node_t *dnp, dtrace_stmtdesc_t *sdp) { - int ctflib; + int ctflib = 0; // XXX: gcc dtrace_actdesc_t *ap = dt_stmt_action(dtp, sdp); boolean_t istrace = (dnp->dn_ident->di_id == DT_ACT_TRACE); @@ -1704,7 +1704,7 @@ * On an error, dt_pid_create_probes() will set the error message * and tag -- we just have to longjmp() out of here. */ - if (isdigit(pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) && + if (isdigit((unsigned char)pdp->dtpd_provider[strlen(pdp->dtpd_provider) - 1]) && ((pvp = dt_provider_lookup(dtp, pdp->dtpd_provider)) == NULL || pvp->pv_desc.dtvd_priv.dtpp_flags & DTRACE_PRIV_PROC) && dt_pid_create_probes(pdp, dtp, yypcb) != 0) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_cg.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cg.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_cg.c 2016-12-03 09:05:32.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_cg.c 2017-04-12 16:13:06.000000000 -0700 @@ -2071,7 +2071,7 @@ dt_cg(dt_pcb_t *pcb, dt_node_t *dnp) { dif_instr_t instr; - dt_xlator_t *dxp; + dt_xlator_t *dxp = NULL; // XXX: gcc dt_ident_t *idp; if (pcb->pcb_regs == NULL && (pcb->pcb_regs = diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_consume.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_consume.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_consume.c 2016-12-03 09:05:32.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_consume.c 2017-04-28 20:36:39.000000000 -0700 @@ -40,6 +40,7 @@ #endif #include #include +#include #ifndef illumos #include #endif @@ -498,13 +499,13 @@ } static int -dt_nullprobe() +dt_nullprobe(void) { return (DTRACE_CONSUME_THIS); } static int -dt_nullrec() +dt_nullrec(void) { return (DTRACE_CONSUME_NEXT); } @@ -815,7 +816,7 @@ return (0); } -int +static int dt_print_quantize_packed(dtrace_hdl_t *dtp, FILE *fp, const void *addr, size_t size, const dtrace_aggdata_t *aggdata) { @@ -936,7 +937,7 @@ } /*ARGSUSED*/ -int +static int dt_print_lquantize_packed(dtrace_hdl_t *dtp, FILE *fp, const void *addr, size_t size, const dtrace_aggdata_t *aggdata) { @@ -1160,7 +1161,8 @@ * have meaning for the terminal and for which isprint(3C) and * isspace(3C) return 0. */ - if (isprint(c[i]) || isspace(c[i]) || + if (isprint((unsigned char)c[i]) || + isspace((unsigned char)c[i]) || c[i] == '\b' || c[i] == '\a') continue; @@ -1954,7 +1956,7 @@ return (err); } -int +static int dt_print_aggs(const dtrace_aggdata_t **aggsdata, int naggvars, void *arg) { int i, aggact = 0; @@ -2062,7 +2064,7 @@ return (dt_print_aggs(&aggdata, 1, arg)); } -int +static int dt_setopt(dtrace_hdl_t *dtp, const dtrace_probedata_t *data, const char *option, const char *value) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_dis.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_dis.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_dis.c 2016-12-28 10:21:16.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_dis.c 2017-05-05 09:56:53.000000000 -0700 @@ -499,7 +499,7 @@ if (v->dtdv_flags & DIFV_F_MOD) (void) strcat(flags, "/w"); - (void) fprintf(fp, "%-16s %-4u %-3s %-3s %-4s %s\n", + (void) fprintf(fp, "%-16s %-4x %-3s %-3s %-4s %s\n", &dp->dtdo_strtab[v->dtdv_name], v->dtdv_id, kind, scope, flags + 1, dt_dis_typestr(&v->dtdv_type, type, sizeof (type))); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_handle.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_handle.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_handle.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_handle.c 2017-04-28 20:37:32.000000000 -0700 @@ -337,7 +337,7 @@ (void) snprintf(s, size, "%llu %sdrop%s on CPU %d\n", (u_longlong_t)howmany, what == DTRACEDROP_PRINCIPAL ? "" : "aggregation ", - howmany > 1 ? "s" : "", cpu); + howmany > 1 ? "s" : "", (int)cpu); if (dtp->dt_drophdlr == NULL) return (dt_set_errno(dtp, EDT_DROPABORT)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_ident.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_ident.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_ident.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_ident.c 2017-05-05 09:57:32.000000000 -0700 @@ -204,7 +204,7 @@ } for (p2 = p1; *p2 != '\0'; p2++) { - if (!isspace(*p2)) { + if (!isspace((unsigned char)*p2)) { i++; break; } @@ -265,7 +265,7 @@ * arguments may not follow optional arguments. */ for (i = 0; i < isp->dis_argc; i++, p1 = p2) { - while (isspace(*p1)) + while (isspace((unsigned char)*p1)) p1++; /* skip leading whitespace */ if ((p2 = strchr(p1, ',')) == NULL) diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h 2016-12-03 09:05:32.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h 2017-04-28 20:37:50.000000000 -0700 @@ -156,7 +156,7 @@ #define DT_DM_KERNEL 0x2 /* module is associated with a kernel object */ #define DT_DM_PRIMARY 0x4 /* module is a krtld primary kernel object */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) /* * A representation of a FreeBSD kernel module, used when checking module * dependencies. This differs from dt_module_t, which refers to a KLD in the @@ -250,7 +250,7 @@ dt_idhash_t *dt_tls; /* hash table of thread-local identifiers */ dt_list_t dt_modlist; /* linked list of dt_module_t's */ dt_module_t **dt_mods; /* hash table of dt_module_t's */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dt_kmodule_t **dt_kmods; /* hash table of dt_kmodule_t's */ #endif uint_t dt_modbuckets; /* number of module hash buckets */ @@ -293,7 +293,7 @@ int dt_cpp_argc; /* count of initialized cpp(1) arguments */ int dt_cpp_args; /* size of dt_cpp_argv[] array */ char *dt_ld_path; /* pathname of ld(1) to invoke if needed */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) char *dt_objcopy_path; /* pathname of objcopy(1) to invoke if needed */ #endif dt_list_t dt_lib_path; /* linked-list forming library search path */ @@ -744,11 +744,19 @@ extern const char *_dtrace_libdir; /* default library directory */ extern const char *_dtrace_moddir; /* default kernel module directory */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) extern int gmatch(const char *, const char *); extern int yylex(void); #endif +#ifdef __NetBSD__ +extern const char *dt_bootfile(char *, size_t); + +#define longlong_t long long +#define u_longlong_t unsigned long long +#define __DECONST(a, b) __UNCONST(b) +#endif + #ifdef __cplusplus } #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_lex.l /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_lex.l --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_lex.l 2015-06-17 08:54:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_lex.l 2015-11-19 19:14:15.000000000 -0800 @@ -289,8 +289,9 @@ * If the macro text is not a string an begins with a * digit or a +/- sign, process it as an integer token. */ - if (isdigit(v[0]) || v[0] == '-' || v[0] == '+') { - if (isdigit(v[0])) + if (isdigit((unsigned char)v[0]) || v[0] == '-' || + v[0] == '+') { + if (isdigit((unsigned char)v[0])) yyintprefix = 0; else yyintprefix = *v++; @@ -429,7 +430,10 @@ '{RGX_CHR}$ xyerror(D_CHR_NL, "newline encountered in character constant"); '{RGX_CHR}' { - char *s, *p, *q; + char *s; +#if BYTE_ORDER == _LITTLE_ENDIAN + char *p, *q; +#endif size_t nbytes; /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_link.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_link.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_link.c 2017-03-02 02:59:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_link.c 2017-11-17 10:52:10.000000000 -0800 @@ -27,6 +27,17 @@ #pragma ident "%Z%%M% %I% %E% SMI" #define ELF_TARGET_ALL +#ifdef __NetBSD__ +#ifdef __x86_64__ +#include +#undef ELF32_MACHDEP_ID_CASES +#undef ELF64_MACHDEP_ID_CASES +#undef ELF64_MACHDEP_ENDIANNESS +#undef KERN_ELFSIZE +#undef ARCH_ELFSIZE +#undef R_TYPE +#endif +#endif #include #include @@ -250,6 +261,15 @@ dofr[j].dofr_offset + 4; rel->r_info = ELF32_R_INFO(count + dep->de_global, R_PPC_REL32); +#elif defined(__sparc) + /* + * Add 4 bytes to hit the low half of this 64-bit + * big-endian address. + */ + rel->r_offset = s->dofs_offset + + dofr[j].dofr_offset + 4; + rel->r_info = ELF32_R_INFO(count + dep->de_global, + R_SPARC_32); #elif defined(__riscv__) /* XXX */ printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__); @@ -433,6 +453,9 @@ #elif defined(__riscv__) /* XXX */ #elif defined(__i386) || defined(__amd64) +#ifndef R_X86_64_PC64 +#define R_X86_64_PC64 24 +#endif rel->r_offset = s->dofs_offset + dofr[j].dofr_offset; rel->r_info = ELF64_R_INFO(count + dep->de_global, @@ -500,6 +523,7 @@ int ret = 0; uint_t nshdr; + memset(&de, 0, sizeof(de)); // XXX: gcc if (prepare_elf32(dtp, dof, &de) != 0) return (-1); /* errno is set for us */ @@ -522,7 +546,7 @@ #else elf_file.ehdr.e_ident[EI_DATA] = ELFDATA2LSB; #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) elf_file.ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; #endif elf_file.ehdr.e_type = ET_REL; @@ -646,6 +670,7 @@ int ret = 0; uint_t nshdr; + memset(&de, 0, sizeof(de)); // XXX: gcc if (prepare_elf64(dtp, dof, &de) != 0) return (-1); /* errno is set for us */ @@ -668,7 +693,7 @@ #else elf_file.ehdr.e_ident[EI_DATA] = ELFDATA2LSB; #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) elf_file.ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; #endif elf_file.ehdr.e_type = ET_REL; @@ -1891,7 +1916,7 @@ } (void) close(fd); /* release temporary file */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) /* * Now that we've linked drti.o, reduce the global __SUNW_dof * symbol to a local symbol. This is needed to so that multiple @@ -1926,7 +1951,7 @@ } #endif } else { -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if (rename(tfile, file) != 0) { ret = dt_link_error(dtp, NULL, fd, NULL, "failed to rename %s to %s: %s", tfile, file, @@ -1940,7 +1965,7 @@ done: dtrace_dof_destroy(dtp, dof); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if (!dtp->dt_lazyload) (void) unlink(tfile); #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c 2016-04-16 09:38:37.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c 2017-06-15 16:20:19.000000000 -0700 @@ -37,10 +37,13 @@ #include #else #include -#include +//#include #include #include #endif +#ifdef __NetBSD__ +#include +#endif #include #ifdef illumos @@ -120,6 +123,9 @@ sym->st_value += dmp->dm_sec_offsets[sym->st_shndx]; #endif +#ifdef __NetBSD__ + sym->st_value += (Elf_Addr) dmp->dm_reloc_offset; +#endif } dt_module_symhash_insert(dmp, name, i); @@ -169,6 +175,9 @@ sym->st_value += dmp->dm_sec_offsets[sym->st_shndx]; #endif +#ifdef __NetBSD__ + sym->st_value += (Elf_Addr) dmp->dm_reloc_offset; +#endif } dt_module_symhash_insert(dmp, name, i); @@ -544,7 +553,7 @@ return (ctfp ? ctf_getspecific(ctfp) : NULL); } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dt_kmodule_t * dt_kmodule_lookup(dtrace_hdl_t *dtp, const char *name) { @@ -1129,9 +1138,9 @@ * including the path. */ static void -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) dt_module_update(dtrace_hdl_t *dtp, const char *name) -#else +#elif defined(__FreeBSD__) dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) #endif { @@ -1155,7 +1164,7 @@ #ifdef illumos (void) snprintf(fname, sizeof (fname), "%s/%s/object", OBJFS_ROOT, name); -#else +#elif defined(__FreeBSD__) GElf_Ehdr ehdr; GElf_Phdr ph; char name[MAXPATHLEN]; @@ -1165,6 +1174,42 @@ (void) strlcpy(name, k_stat->name, sizeof(name)); (void) strlcpy(fname, k_stat->pathname, sizeof(fname)); +#elif defined(__NetBSD__) + int mib_osrel[2] = { CTL_KERN, KERN_OSRELEASE }; + int mib_mach[2] = { CTL_HW, HW_MACHINE }; + char osrel[64]; + char machine[64]; + size_t len; + uintptr_t mapbase; + int i; + bool ismod; + + if (strcmp("netbsd", name) == 0) { + /* want the kernel, but it is not absolute */ + dt_bootfile(machine, sizeof(machine)); + snprintf(fname, sizeof(fname), "/%s", machine); + ismod = false; + } else { + + /* build stand module path from system */ + len = sizeof(osrel); + if (sysctl(mib_osrel, 2, osrel, &len, NULL, 0) == -1) { + dt_dprintf("sysctl osrel failed: %s\n", + strerror(errno)); + return; + } + + len = sizeof(machine); + if (sysctl(mib_mach, 2, machine, &len, NULL, 0) == -1) { + dt_dprintf("sysctl machine failed: %s\n", + strerror(errno)); + return; + } + + (void) snprintf(fname, sizeof (fname), + "/stand/%s/%s/modules/%s/%s.kmod", machine, osrel, name, name); + ismod = true; + } #endif if ((fd = open(fname, O_RDONLY)) == -1 || fstat64(fd, &st) == -1 || @@ -1220,6 +1265,34 @@ } } #endif +#ifdef __NetBSD__ + mapbase = 0; + if (ismod) { + int maxmodules = 512; + modstat_t modstat_buf[maxmodules], *ms; + struct iovec iov = { modstat_buf, sizeof(modstat_buf) }; + + if (modctl(MODCTL_STAT, &iov) < 0) { + dt_dprintf("failed to get list of kernel modules: %s\n", + strerror(errno)); + return; + } + + for (i = 0; i < maxmodules; i++) { + ms = &modstat_buf[i]; + if (!strcmp(name, ms->ms_name)) { + mapbase = ms->ms_addr; + break; + } + } + if (i == maxmodules) { + dt_dprintf("module %s not found\n", name); + return; + } + dmp->dm_reloc_offset = (void *)mapbase; + } +#endif + /* * Iterate over the section headers locating various sections of * interest and use their attributes to flesh out the dt_module_t. @@ -1264,7 +1337,8 @@ dmp->dm_flags |= DT_DM_KERNEL; #ifdef illumos dmp->dm_modid = (int)OBJFS_MODID(st.st_ino); -#else +#endif /* illumos */ +#ifdef __FreeBSD__ /* * Include .rodata and special sections into .text. * This depends on default section layout produced by GNU ld @@ -1285,7 +1359,16 @@ } } #endif -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + if (ismod) { + dmp->dm_text_va = mapbase; + dmp->dm_data_va = 0; + dmp->dm_data_size = 0; + dmp->dm_bss_va = 0; + dmp->dm_bss_size = 0; + } +#endif if (dmp->dm_info.objfs_info_primary) dmp->dm_flags |= DT_DM_PRIMARY; @@ -1329,8 +1412,9 @@ dtrace_update(dtrace_hdl_t *dtp) { dt_module_t *dmp; +#ifdef illumos DIR *dirp; -#if defined(__FreeBSD__) +#elif defined(__FreeBSD__) int fileid; #endif @@ -1365,6 +1449,32 @@ if (kldstat(fileid, &k_stat) == 0) dt_module_update(dtp, &k_stat); } +#elif defined(__NetBSD__) + size_t len; + struct iovec iov; + modstat_t *ms; + + dt_module_update(dtp, "netbsd"); + for (len = 8192;;) { + iov.iov_base = malloc(len); + iov.iov_len = len; + if (modctl(MODCTL_STAT, &iov)) { + free(iov.iov_base); + iov.iov_len = 0; + break; + } + if (len >= iov.iov_len) { + break; + } + free(iov.iov_base); + len = iov.iov_len; + } + len = iov.iov_len / sizeof(modstat_t); + for (ms = iov.iov_base; len != 0; ms++, len--) { + if (ms->ms_source != MODULE_SOURCE_FILESYS) + continue; + dt_module_update(dtp, ms->ms_name); + } #endif /* @@ -1541,6 +1651,7 @@ for (dmp = dt_list_next(&dtp->dt_modlist); dmp != NULL; dmp = dt_list_next(dmp)) { + if (addr - dmp->dm_text_va < dmp->dm_text_size || addr - dmp->dm_data_va < dmp->dm_data_size || addr - dmp->dm_bss_va < dmp->dm_bss_size) @@ -1581,10 +1692,10 @@ dtrace_typeinfo_t ti; dt_module_t *dmp; int found = 0; - ctf_id_t id; + ctf_id_t id = CTF_ERR; // XXX: gcc uint_t n, i; int justone; - ctf_file_t *fp; + ctf_file_t *fp = NULL; // XXX: gcc char *buf, *p, *q; uint_t mask = 0; /* mask of dt_module flags to match */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.h --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.h 2015-06-17 08:54:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.h 2015-09-24 09:06:04.000000000 -0700 @@ -44,7 +44,7 @@ extern dt_module_t *dt_module_lookup_by_name(dtrace_hdl_t *, const char *); extern dt_module_t *dt_module_lookup_by_ctf(dtrace_hdl_t *, ctf_file_t *); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) extern dt_kmodule_t *dt_kmodule_lookup(dtrace_hdl_t *, const char *); #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c 2017-03-02 02:59:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c 2017-05-05 09:59:27.000000000 -0700 @@ -279,10 +279,10 @@ DT_VERS_1_2, &dt_idops_func, "_symaddr(uintptr_t)" }, { "getmajor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMAJOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, - &dt_idops_func, "genunix`major_t(genunix`dev_t)" }, + &dt_idops_func, "netbsd`__devmajor_t(netbsd`dev_t)" }, { "getminor", DT_IDENT_FUNC, 0, DIF_SUBR_GETMINOR, DT_ATTR_EVOLCMN, DT_VERS_1_0, - &dt_idops_func, "genunix`minor_t(genunix`dev_t)" }, + &dt_idops_func, "netbsd`__devminor_t(netbsd`dev_t)" }, { "htonl", DT_IDENT_FUNC, 0, DIF_SUBR_HTONL, DT_ATTR_EVOLCMN, DT_VERS_1_3, &dt_idops_func, "uint32_t(uint32_t)" }, { "htonll", DT_IDENT_FUNC, 0, DIF_SUBR_HTONLL, DT_ATTR_EVOLCMN, DT_VERS_1_3, @@ -638,6 +638,10 @@ { "unsigned", "size_t" }, { "long", "id_t" }, { "long", "pid_t" }, +#ifdef __NetBSD__ +{ "unsigned int", "uid_t" }, +{ "unsigned int", "gid_t" }, +#endif { NULL, NULL } }; @@ -666,6 +670,10 @@ { "unsigned long", "size_t" }, { "int", "id_t" }, { "int", "pid_t" }, +#ifdef __NetBSD__ +{ "unsigned int", "uid_t" }, +{ "unsigned int", "gid_t" }, +#endif { NULL, NULL } }; @@ -778,10 +786,10 @@ }; #ifdef illumos -const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ +const char *_dtrace_defcpps[] = { "/usr/ccs/lib/cpp" }; /* default cpp(1) to invoke */ const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ #else -const char *_dtrace_defcpp = "cpp"; /* default cpp(1) to invoke */ +const char *_dtrace_defcpps[] = { "/usr/bin/cpp", "/usr/bin/clang-cpp" }; /* default cpp(1) to invoke */ const char *_dtrace_defld = "ld"; /* default ld(1) to invoke */ const char *_dtrace_defobjcopy = "objcopy"; /* default objcopy(1) to invoke */ #endif @@ -931,8 +939,8 @@ * reallocate it. We normally won't need to do this * because providers aren't being loaded all the time. */ - if ((p = realloc(p_providers,len)) == NULL) { - free(p_providers); + if ((p = realloc(p_providers,len)) == NULL) { + free(p_providers); /* How do we report errors here? */ return; } @@ -1017,6 +1025,36 @@ } #endif +#ifndef illumos +# ifdef __FreeBSD__ +# define DEFKERNEL "kernel" +# define BOOTFILE "kern.bootfile" +# endif +# ifdef __NetBSD__ +# define DEFKERNEL "netbsd" +# define BOOTFILE "machdep.booted_kernel" +# endif + +const char * +dt_bootfile(char *bootfile, size_t len) +{ + char *p; + size_t olen = len; + + if (sysctlbyname(BOOTFILE, bootfile, &len, NULL, 0) != 0) + strlcpy(bootfile, DEFKERNEL, olen); + + if ((p = strrchr(bootfile, '/')) != NULL) + p++; + else + p = bootfile; + return p; +} + +# undef DEFKERNEL +# undef BOOTFILE +#endif + static dtrace_hdl_t * dt_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) @@ -1039,8 +1077,10 @@ dt_fdlist_t df = { NULL, 0, 0 }; +#if defined(__FreeBSD__) char isadef[32], utsdef[32]; char s1[64], s2[64]; +#endif if (version <= 0) return (set_open_errno(dtp, errp, EINVAL)); @@ -1180,19 +1220,28 @@ #endif dtp->dt_modbuckets = _dtrace_strbuckets; dtp->dt_mods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dtp->dt_kmods = calloc(dtp->dt_modbuckets, sizeof (dt_module_t *)); #endif dtp->dt_provbuckets = _dtrace_strbuckets; dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); dt_proc_hash_create(dtp); dtp->dt_vmax = DT_VERS_LATEST; - dtp->dt_cpp_path = strdup(_dtrace_defcpp); + dtp->dt_cpp_path = NULL; + for (i = 0; i < (int)sizeof(_dtrace_defcpps) / sizeof(_dtrace_defcpps[0]); ++i) { + if (access(_dtrace_defcpps[i], X_OK) == 0) { + dtp->dt_cpp_path = strdup(_dtrace_defcpps[i]); + break; + } + } + if (dtp->dt_cpp_path == NULL) + dtp->dt_cpp_path = strdup("cpp"); + dtp->dt_cpp_argv = malloc(sizeof (char *)); dtp->dt_cpp_argc = 1; dtp->dt_cpp_args = 1; dtp->dt_ld_path = strdup(_dtrace_defld); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dtp->dt_objcopy_path = strdup(_dtrace_defobjcopy); #endif dtp->dt_provmod = provmod; @@ -1203,7 +1252,7 @@ if (dtp->dt_mods == NULL || dtp->dt_provs == NULL || dtp->dt_procs == NULL || dtp->dt_ld_path == NULL || -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dtp->dt_kmods == NULL || dtp->dt_objcopy_path == NULL || #endif @@ -1296,30 +1345,35 @@ * used as the kernel. */ #ifndef illumos +# ifdef __FreeBSD__ +# define THREAD "struct thread" +# define MUTEX "struct mtx" +# define RWLOCK "struct rwlock" +# endif +# ifdef __NetBSD__ +# define THREAD "struct lwp" +# define MUTEX "struct kmutex" +# define RWLOCK "struct krwlock" +# endif { - char bootfile[MAXPATHLEN]; - char *p; - int i; - size_t len = sizeof(bootfile); + const char *p; + char kernname[512]; - /* This call shouldn't fail, but use a default just in case. */ - if (sysctlbyname("kern.bootfile", bootfile, &len, NULL, 0) != 0) - strlcpy(bootfile, "kernel", sizeof(bootfile)); - - if ((p = strrchr(bootfile, '/')) != NULL) - p++; - else - p = bootfile; + p = dt_bootfile(kernname, sizeof(kernname)); /* * Format the global variables based on the kernel module name. */ - snprintf(curthread_str, sizeof(curthread_str), "%s`struct thread *",p); - snprintf(intmtx_str, sizeof(intmtx_str), "int(%s`struct mtx *)",p); - snprintf(threadmtx_str, sizeof(threadmtx_str), "struct thread *(%s`struct mtx *)",p); - snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`struct rwlock *)",p); - snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)",p); - } + snprintf(curthread_str, sizeof(curthread_str), "%s`%s *", p, THREAD); + snprintf(intmtx_str, sizeof(intmtx_str), "int(%s`%s *)", p, MUTEX); + snprintf(threadmtx_str, sizeof(threadmtx_str), "%s *(%s`%s *)", + THREAD, p, MUTEX); + snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`%s *)", p, RWLOCK); + snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)", p); + } +# undef THREAD +# undef MUTEX +# undef RWLOCK #endif dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX); @@ -1588,7 +1642,7 @@ * compile, and to provide better error reporting (because the full * reporting of compiler errors requires dtrace_open() to succeed). */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) #ifdef __LP64__ if ((dtp->dt_oflags & DTRACE_O_ILP32) != 0) { if (dtrace_setopt(dtp, "libdir", _dtrace_libdir32) != 0) @@ -1627,7 +1681,7 @@ dtrace_prog_t *pgp; dt_xlator_t *dxp; dt_dirpath_t *dirp; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dt_kmodule_t *dkm; uint_t h; #endif @@ -1658,7 +1712,7 @@ if (dtp->dt_tls != NULL) dt_idhash_destroy(dtp->dt_tls); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) for (h = 0; h < dtp->dt_modbuckets; h++) while ((dkm = dtp->dt_kmods[h]) != NULL) { dtp->dt_kmods[h] = dkm->dkm_next; @@ -1711,12 +1765,12 @@ free(dtp->dt_cpp_argv); free(dtp->dt_cpp_path); free(dtp->dt_ld_path); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) free(dtp->dt_objcopy_path); #endif free(dtp->dt_mods); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) free(dtp->dt_kmods); #endif free(dtp->dt_provs); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_options.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_options.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_options.c 2015-02-19 06:52:00.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_options.c 2017-04-28 20:20:38.000000000 -0700 @@ -280,7 +280,7 @@ return (0); } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) static int dt_opt_objcopy_path(dtrace_hdl_t *dtp, const char *arg, uintptr_t option) { @@ -882,7 +882,7 @@ dt_options_load(dtrace_hdl_t *dtp) { dof_hdr_t hdr, *dof; - dof_sec_t *sec; + dof_sec_t *sec = NULL; // XXX: gcc size_t offs; int i; @@ -982,7 +982,7 @@ { "linkmode", dt_opt_linkmode }, { "linktype", dt_opt_linktype }, { "nolibs", dt_opt_cflags, DTRACE_C_NOLIBS }, -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) { "objcopypath", dt_opt_objcopy_path }, #endif { "pgmax", dt_opt_pgmax }, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.c 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.c 2017-05-05 10:00:23.000000000 -0700 @@ -200,7 +200,7 @@ const char *p, *q, *r, *end, *obj; for (p = s, end = s + strlen(s); *p != '\0'; p = q) { - while (isspace(*p)) + while (isspace((unsigned char)*p)) p++; /* skip leading whitespace prior to token */ if (p == end || (q = strpbrk(p + 1, delimiters)) == NULL) @@ -1053,7 +1053,7 @@ ctf_id_t lref = CTF_ERR, rref = CTF_ERR; int lp_is_void, rp_is_void, lp_is_int, rp_is_int, compat; - uint_t lkind, rkind; + uint_t lkind = 0, rkind = 0; // XXX: gcc ctf_encoding_t e; ctf_arinfo_t r; @@ -2583,7 +2583,7 @@ "characters: %s\n", DTRACE_PROVNAMELEN - 1, name); } - if (isdigit(name[len - 1])) { + if (isdigit((unsigned char)name[len - 1])) { dnerror(dnp, D_PROV_BADNAME, "provider name may not " "end with a digit: %s\n", name); } @@ -3180,7 +3180,7 @@ ctf_membinfo_t m; ctf_file_t *ctfp; ctf_id_t type; - int kind, val, uref; + int kind, val, uref = 0; // XXX: gcc dt_ident_t *idp; char n1[DT_TYPE_NAMELEN]; @@ -5184,8 +5184,10 @@ yypcb->pcb_region = label; } +#ifndef __NetBSD__ int yywrap(void) { return (1); /* indicate that lex should return a zero token for EOF */ } +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.h --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.h 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_parser.h 2017-04-12 18:56:30.000000000 -0700 @@ -276,16 +276,19 @@ YYS_CONTROL /* lex/yacc state for parsing control lines */ } yystate_t; -extern void dnerror(const dt_node_t *, dt_errtag_t, const char *, ...); -extern void dnwarn(const dt_node_t *, dt_errtag_t, const char *, ...); - -extern void xyerror(dt_errtag_t, const char *, ...); -extern void xywarn(dt_errtag_t, const char *, ...); -extern void xyvwarn(dt_errtag_t, const char *, va_list); - -extern void yyerror(const char *, ...); -extern void yywarn(const char *, ...); -extern void yyvwarn(const char *, va_list); +extern void dnerror(const dt_node_t *, dt_errtag_t, const char *, ...) + __printflike(3, 4) __dead; +extern void dnwarn(const dt_node_t *, dt_errtag_t, const char *, ...) + __printflike(3, 4); + +extern void xyerror(dt_errtag_t, const char *, ...) __printflike(2, 3) + __dead; +extern void xywarn(dt_errtag_t, const char *, ...) __printflike(2, 3); +extern void xyvwarn(dt_errtag_t, const char *, va_list) __printflike(2, 0); + +extern void yyerror(const char *, ...) __printflike(1, 2) __dead; +extern void yywarn(const char *, ...) __printflike(1, 2); +extern void yyvwarn(const char *, va_list) __printflike(1, 0); extern void yylabel(const char *); extern void yybegin(yystate_t); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_pid.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_pid.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_pid.c 2016-12-18 18:09:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_pid.c 2017-04-28 20:26:56.000000000 -0700 @@ -48,6 +48,7 @@ #ifndef illumos #include +#include #include #include #include @@ -450,7 +451,7 @@ char *end; if (strncmp(pdp->dtpd_mod, "LM", 2) != 0 || - !isdigit(pdp->dtpd_mod[2])) + !isdigit((unsigned char)pdp->dtpd_mod[2])) return (NULL); lmid = strtoul(&pdp->dtpd_mod[2], &end, 16); @@ -602,11 +603,10 @@ dh.dofhp_dof = sym.st_value; dh.dofhp_addr = (e_type == ET_EXEC) ? 0 : pmp->pr_vaddr; - dt_pid_objname(dh.dofhp_mod, sizeof (dh.dofhp_mod), sip.prs_lmid, mname); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) dh.dofhp_pid = proc_getpid(P); if (fd == -1 && @@ -632,7 +632,7 @@ } if (fd != -1) -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) (void) close(fd); #else (void) pr_close(P, fd); @@ -677,7 +677,7 @@ char *c, *last = NULL, *end; for (c = &pdp->dtpd_provider[0]; *c != '\0'; c++) { - if (!isdigit(*c)) + if (!isdigit((unsigned char)*c)) last = c; } @@ -729,7 +729,7 @@ (void) snprintf(provname, sizeof (provname), "pid%d", (int)pid); if (gmatch(provname, pdp->dtpd_provider) != 0) { -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if ((P = dt_proc_grab(dtp, pid, 0, 1)) == NULL) #else if ((P = dt_proc_grab(dtp, pid, PGRAB_RDONLY | PGRAB_FORCE, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_pragma.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_pragma.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_pragma.c 2015-06-17 08:54:58.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_pragma.c 2015-09-24 09:06:04.000000000 -0700 @@ -82,7 +82,7 @@ dt_pragma_attributes(const char *prname, dt_node_t *dnp) { dtrace_hdl_t *dtp = yypcb->pcb_hdl; - dtrace_attribute_t attr, *a; + dtrace_attribute_t attr, *a = NULL; // XXX: gcc dt_provider_t *pvp; const char *name, *part; dt_ident_t *idp; @@ -239,7 +239,7 @@ { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dt_node_t *nnp = cnp ? cnp->dn_list : NULL; - int found; + int found = 0; // XXX: gcc dt_lib_depend_t *dld; char lib[MAXPATHLEN]; size_t plen; @@ -278,7 +278,7 @@ } else if (strcmp(cnp->dn_string, "module") == 0) { dt_module_t *mp = dt_module_lookup_by_name(dtp, nnp->dn_string); found = mp != NULL && dt_module_getctf(dtp, mp) != NULL; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if (!found) { dt_kmodule_t *dkmp = dt_kmodule_lookup(dtp, nnp->dn_string); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_print.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_print.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_print.c 2014-11-01 03:02:49.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_print.c 2017-04-28 20:27:15.000000000 -0700 @@ -263,7 +263,7 @@ */ if (CTF_IS_CHAR(e)) { char c = *(char *)addr; - if (isprint(c)) + if (isprint((unsigned char)c)) (void) fprintf(fp, "'%c'", c); else if (c == 0) (void) fprintf(fp, "'\\0'"); @@ -395,7 +395,7 @@ char c; for (i = 0; i < car.ctr_nelems; i++) { c = *((char *)addr + eltsize * i); - if (!isprint(c) || c == '\0') + if (!isprint((unsigned char)c) || c == '\0') break; } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_printf.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_printf.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_printf.c 2016-05-31 04:23:09.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_printf.c 2017-04-28 20:28:59.000000000 -0700 @@ -25,11 +25,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. */ -#ifdef illumos #include -#else -#define ABS(a) ((a) < 0 ? -(a) : (a)) -#endif #include #include #include @@ -301,7 +297,10 @@ const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal) { double n = (double)normal; +#if !defined(__arm__) && !defined(__powerpc__) && \ + !defined(__mips__) && !defined(__riscv__) long double ldn = (long double)normal; +#endif switch (size) { case sizeof (float): @@ -517,14 +516,25 @@ { uint16_t port = htons(*((uint16_t *)addr)); char buf[256]; +#if defined(illumos) || defined(__FreeBSD__) struct servent *sv, res; +#endif #ifdef illumos if ((sv = getservbyport_r(port, NULL, &res, buf, sizeof (buf))) != NULL) -#else + return (dt_printf(dtp, fp, format, sv->s_name)); +#elif defined(__FreeBSD__) if (getservbyport_r(port, NULL, &res, buf, sizeof (buf), &sv) > 0) -#endif return (dt_printf(dtp, fp, format, sv->s_name)); +#else + struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = port; + if (getnameinfo((const struct sockaddr *)&sin, sizeof(sin), NULL, 0, + buf, sizeof(buf), 0) > 0) + return (dt_printf(dtp, fp, format, buf)); +#endif (void) snprintf(buf, sizeof (buf), "%d", *((uint16_t *)addr)); return (dt_printf(dtp, fp, format, buf)); @@ -536,10 +546,12 @@ const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal) { char *s = alloca(size + 1); - struct hostent *host, res; char inetaddr[NS_IN6ADDRSZ]; char buf[1024]; +#if defined(illumos) || defined(__FreeBSD__) + struct hostent *host, res; int e; +#endif bcopy(addr, s, size); s[size] = '\0'; @@ -548,15 +560,25 @@ #ifdef illumos if ((host = gethostbyaddr_r(inetaddr, NS_INADDRSZ, AF_INET, &res, buf, sizeof (buf), &e)) != NULL) -#else +#elif defined(__FreeBSD__) if (gethostbyaddr_r(inetaddr, NS_INADDRSZ, AF_INET, &res, buf, sizeof (buf), &host, &e) > 0) -#endif return (dt_printf(dtp, fp, format, host->h_name)); +#else + if (getnameinfo((const struct sockaddr *)inetaddr, NS_INADDRSZ, + buf, sizeof(buf), NULL, 0, 0) > 0) + return (dt_printf(dtp, fp, format, buf)); +#endif } else if (inet_pton(AF_INET6, s, inetaddr) != -1) { +#if defined(__FreeBSD__) if ((host = getipnodebyaddr(inetaddr, NS_IN6ADDRSZ, AF_INET6, &e)) != NULL) return (dt_printf(dtp, fp, format, host->h_name)); +#else + if (getnameinfo((const struct sockaddr *)inetaddr, NS_INADDRSZ, + buf, sizeof(buf), NULL, 0, 0) > 0) + return (dt_printf(dtp, fp, format, buf)); +#endif } return (dt_printf(dtp, fp, format, s)); @@ -889,7 +911,7 @@ goto fmt_switch; } - for (n = 0; isdigit(c); c = *++p) + for (n = 0; isdigit((unsigned char)c); c = *++p) n = n * 10 + c - '0'; if (dot) @@ -1139,6 +1161,7 @@ sizeof (vname)); vnp = &aggnode; } else if (dnp == NULL) { + vnp = NULL; xyerror(D_PRINTF_ARG_PROTO, "%s( ) prototype mismatch: conversion #%d (%%" "%s) is missing a corresponding value argument\n", @@ -1345,12 +1368,12 @@ { dt_pfargd_t *pfd = pfv->pfv_argv; const dtrace_recdesc_t *recp = recs; - const dtrace_aggdata_t *aggdata; + const dtrace_aggdata_t *aggdata = NULL; // XXX: gcc dtrace_aggdesc_t *agg; caddr_t lim = (caddr_t)buf + len, limit; char format[64] = "%"; size_t ret; - int i, aggrec, curagg = -1; + int i, aggrec = 0, curagg = -1; // XXX: gcc uint64_t normal; /* @@ -1388,7 +1411,7 @@ dt_pfprint_f *func; caddr_t addr; size_t size; - uint32_t flags; + uint32_t flags = 0; // XXX: gcc if (pfd->pfd_preflen != 0) { char *tmp = alloca(pfd->pfd_preflen + 1); @@ -1601,7 +1624,7 @@ return ((int)(recp - recs)); } -int +static int dtrace_sprintf(dtrace_hdl_t *dtp, FILE *fp, void *fmtdata, const dtrace_recdesc_t *recp, uint_t nrecs, const void *buf, size_t len) { @@ -1659,7 +1682,9 @@ const dtrace_probedata_t *data, const dtrace_recdesc_t *recp, uint_t nrecs, const void *buf, size_t len) { +#ifdef illumos char selfbuf[40], restorebuf[40], *filename; +#endif FILE *nfp; int rval, errval; dt_pfargv_t *pfv = fmtdata; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.c 2017-04-28 20:29:14.000000000 -0700 @@ -111,7 +111,11 @@ dbp->dbp_data = data; dbp->dbp_addr = addr; +#ifdef __NetBSD__ if (Psetbkpt(P, dbp->dbp_addr, &dbp->dbp_instr) == 0) +#else + if (Psetbkpt(P, dbp->dbp_addr, dbp->dbp_instr) == 0) +#endif dbp->dbp_active = B_TRUE; dt_list_append(&dpr->dpr_bps, dbp); @@ -132,7 +136,7 @@ if (delbkpts && dbp->dbp_active && state != PS_LOST && state != PS_UNDEAD) { (void) Pdelbkpt(dpr->dpr_proc, - dbp->dbp_addr, dbp->dbp_instr); + dbp->dbp_addr, &dbp->dbp_instr); } nbp = dt_list_next(dbp); dt_list_delete(&dpr->dpr_bps, dbp); @@ -182,7 +186,11 @@ (int)dpr->dpr_pid, (ulong_t)dbp->dbp_addr, ++dbp->dbp_hits); dbp->dbp_func(dtp, dpr, dbp->dbp_data); +#ifdef __NetBSD__ + (void) Pxecbkpt(dpr->dpr_proc, &dbp->dbp_instr); +#else (void) Pxecbkpt(dpr->dpr_proc, dbp->dbp_instr); +#endif } static void @@ -212,7 +220,7 @@ for (dbp = dt_list_next(&dpr->dpr_bps); dbp != NULL; dbp = dt_list_next(dbp)) { if (dbp->dbp_active && Pdelbkpt(dpr->dpr_proc, - dbp->dbp_addr, dbp->dbp_instr) == 0) + dbp->dbp_addr, &dbp->dbp_instr) == 0) dbp->dbp_active = B_FALSE; } @@ -302,6 +310,8 @@ (int)dpr->dpr_pid, evname, rdm.type, rdm.u.state); switch (rdm.type) { + case RD_NONE: + break; case RD_DLACTIVITY: if (rdm.u.state != RD_CONSISTENT) break; @@ -810,8 +820,10 @@ dpr->dpr_quit = B_TRUE; #ifdef illumos (void) _lwp_kill(dpr->dpr_tid, SIGCANCEL); -#else +#elif defined(__FreeBSD__) pthread_kill(dpr->dpr_tid, SIGTHR); +#else + pthread_cancel(dpr->dpr_tid); #endif /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.h --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.h 2013-04-20 09:00:30.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_proc.h 2017-04-13 10:05:26.000000000 -0700 @@ -80,7 +80,11 @@ dt_bkpt_f *dbp_func; /* callback function to execute */ void *dbp_data; /* callback function private data */ uintptr_t dbp_addr; /* virtual address of breakpoint */ +#ifdef __NetBSD__ + proc_breakpoint_t dbp_instr; /* saved instruction from breakpoint */ +#else ulong_t dbp_instr; /* saved instruction from breakpoint */ +#endif ulong_t dbp_hits; /* count of breakpoint hits for debug */ int dbp_active; /* flag indicating breakpoint is on */ } dt_bkpt_t; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_program.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_program.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_program.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_program.c 2015-09-24 09:06:04.000000000 -0700 @@ -371,7 +371,7 @@ dt_header_fmt_macro(char *buf, const char *str) { for (;;) { - if (islower(*str)) { + if (islower((unsigned char)*str)) { *buf++ = *str++ + 'A' - 'a'; } else if (*str == '-') { *buf++ = '_'; @@ -559,7 +559,7 @@ info.dthi_pfname = alloca(strlen(pvp->pv_desc.dtvd_name) + 1 + i); dt_header_fmt_func(info.dthi_pfname, pvp->pv_desc.dtvd_name); -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) if (fprintf(out, "#include \n\n") < 0) return (dt_set_errno(dtp, errno)); #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c 2016-12-03 09:05:32.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c 2017-04-28 20:39:45.000000000 -0700 @@ -42,6 +42,7 @@ #include #else #include +#include #include #endif #include @@ -107,7 +108,7 @@ v++; } - if (isdigit(v[1])) { + if (isdigit((unsigned char)v[1])) { long i; errno = 0; @@ -392,7 +393,7 @@ char c; while ((c = *s++) != '\0') { - if (isdigit(c)) + if (isdigit((unsigned char)c)) n[i] = n[i] * 10 + c - '0'; else if (c != '.' || i++ >= sizeof (n) / sizeof (n[0]) - 1) return (-1); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_work.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_work.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/dt_work.c 2015-02-03 23:20:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/dt_work.c 2015-09-24 09:06:04.000000000 -0700 @@ -273,7 +273,7 @@ { int status = dtrace_status(dtp); dtrace_optval_t policy = dtp->dt_options[DTRACEOPT_BUFPOLICY]; - dtrace_workstatus_t rval; + dtrace_workstatus_t rval = 0; // XXX: gcc switch (status) { case DTRACE_STATUS_EXITED: Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common: mkerrno.sh diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/mkerrtags.sh /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/mkerrtags.sh --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/mkerrtags.sh 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/mkerrtags.sh 2015-10-04 20:09:34.000000000 -0700 @@ -26,7 +26,10 @@ # #ident "%Z%%M% %I% %E% SMI" -BSDECHO=-e + +if [ "x$(echo -e)" != "x-e" ]; then + BSDECHO=-e +fi echo ${BSDECHO} "\ /*\n\ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/mknames.sh /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/mknames.sh --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common/mknames.sh 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/common/mknames.sh 2015-10-04 20:09:34.000000000 -0700 @@ -26,7 +26,9 @@ # #ident "%Z%%M% %I% %E% SMI" -BSDECHO=-e +if [ "x$(echo -e)" != "x-e" ]; then + BSDECHO=-e +fi echo ${BSDECHO} "\ /*\n\ Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace/common: mksignal.sh diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libdtrace/i386/dt_isadep.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/i386/dt_isadep.c --- /tmp/out/external/cddl/osnet/dist/lib/libdtrace/i386/dt_isadep.c 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libdtrace/i386/dt_isadep.c 2017-05-06 20:58:22.000000000 -0700 @@ -33,13 +33,14 @@ #include #include #include +#include #include #include #include -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) #include #include #endif Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace/i386: regs.d.in Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace/i386: regs.sed.in Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace: mips Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace: powerpc Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace: riscv Only in /tmp/out/external/cddl/osnet/dist/lib/libdtrace: sparc Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib: libefi diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libgen/common/gmatch.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libgen/common/gmatch.c --- /tmp/out/external/cddl/osnet/dist/lib/libgen/common/gmatch.c 2015-02-03 23:20:38.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libgen/common/gmatch.c 2017-04-13 10:22:08.000000000 -0700 @@ -29,9 +29,13 @@ #pragma ident "%Z%%M% %I% %E% SMI" +/*LINTLIBRARY*/ + #ifdef illumos #pragma weak gmatch = _gmatch +#endif +#ifdef illumos #include "gen_synonyms.h" #endif #include @@ -58,6 +62,7 @@ return (0); \ p += n +int gmatch(const char *, const char *); int gmatch(const char *s, const char *p) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libnvpair/libnvpair.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libnvpair/libnvpair.c --- /tmp/out/external/cddl/osnet/dist/lib/libnvpair/libnvpair.c 2016-10-10 04:14:24.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libnvpair/libnvpair.c 2017-04-20 10:38:21.000000000 -0700 @@ -29,6 +29,7 @@ #include #include #include +#include #include "libnvpair.h" /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libshare/common/libshare.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libshare/common/libshare.h --- /tmp/out/external/cddl/osnet/dist/lib/libshare/common/libshare.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libshare/common/libshare.h 2010-02-27 14:30:14.000000000 -0800 @@ -1,36 +1,279 @@ -/*- - * Copyright (c) 2007 Pawel Jakub Dawidek - * All rights reserved. +/* + * CDDL HEADER START * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. * - * $FreeBSD$ + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * basic API declarations for share management + */ + +#ifndef _LIBSHARE_H +#define _LIBSHARE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * Basic datatypes for most functions + */ +typedef void *sa_group_t; +typedef void *sa_share_t; +typedef void *sa_property_t; +typedef void *sa_optionset_t; +typedef void *sa_security_t; +typedef void *sa_protocol_properties_t; +typedef void *sa_resource_t; + +typedef void *sa_handle_t; /* opaque handle to access core functions */ + +/* + * defined error values + */ + +#define SA_OK 0 +#define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */ +#define SA_NO_MEMORY 2 /* no memory for data structures */ +#define SA_DUPLICATE_NAME 3 /* object name is already in use */ +#define SA_BAD_PATH 4 /* not a full path */ +#define SA_NO_SUCH_GROUP 5 /* group is not defined */ +#define SA_CONFIG_ERR 6 /* system configuration error */ +#define SA_SYSTEM_ERR 7 /* system error, use errno */ +#define SA_SYNTAX_ERR 8 /* syntax error on command line */ +#define SA_NO_PERMISSION 9 /* no permission for operation */ +#define SA_BUSY 10 /* resource is busy */ +#define SA_NO_SUCH_PROP 11 /* property doesn't exist */ +#define SA_INVALID_NAME 12 /* name of object is invalid */ +#define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */ +#define SA_NOT_ALLOWED 14 /* operation not allowed */ +#define SA_BAD_VALUE 15 /* bad value for property */ +#define SA_INVALID_SECURITY 16 /* invalid security type */ +#define SA_NO_SUCH_SECURITY 17 /* security set not found */ +#define SA_VALUE_CONFLICT 18 /* property value conflict */ +#define SA_NOT_IMPLEMENTED 19 /* plugin interface not implemented */ +#define SA_INVALID_PATH 20 /* path is sub-dir of existing share */ +#define SA_NOT_SUPPORTED 21 /* operation not supported for proto */ +#define SA_PROP_SHARE_ONLY 22 /* property valid on share only */ +#define SA_NOT_SHARED 23 /* path is not shared */ +#define SA_NO_SUCH_RESOURCE 24 /* resource not found */ +#define SA_RESOURCE_REQUIRED 25 /* resource name is required */ +#define SA_MULTIPLE_ERROR 26 /* multiple protocols reported error */ +#define SA_PATH_IS_SUBDIR 27 /* check_path found path is subdir */ +#define SA_PATH_IS_PARENTDIR 28 /* check_path found path is parent */ +#define SA_NO_SECTION 29 /* protocol requires section info */ +#define SA_NO_SUCH_SECTION 30 /* no section found */ +#define SA_NO_PROPERTIES 31 /* no properties found */ +#define SA_PASSWORD_ENC 32 /* passwords must be encrypted */ + +/* API Initialization */ +#define SA_INIT_SHARE_API 0x0001 /* init share specific interface */ +#define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */ + +/* not part of API returns */ +#define SA_LEGACY_ERR 32 /* share/unshare error return */ + +/* + * other defined values + */ + +#define SA_MAX_NAME_LEN 100 /* must fit service instance name */ +#define SA_MAX_RESOURCE_NAME 255 /* Maximum length of resource name */ + +/* Used in calls to sa_add_share() and sa_add_resource() */ +#define SA_SHARE_TRANSIENT 0 /* shared but not across reboot */ +#define SA_SHARE_LEGACY 1 /* share is in dfstab only */ +#define SA_SHARE_PERMANENT 2 /* share goes to repository */ + +/* sa_check_path() related */ +#define SA_CHECK_NORMAL 0 /* only check against active shares */ +#define SA_CHECK_STRICT 1 /* check against all shares */ + +/* RBAC related */ +#define SA_RBAC_MANAGE "solaris.smf.manage.shares" +#define SA_RBAC_VALUE "solaris.smf.value.shares" + +/* + * Feature set bit definitions + */ + +#define SA_FEATURE_NONE 0x0000 /* no feature flags set */ +#define SA_FEATURE_RESOURCE 0x0001 /* resource names are required */ +#define SA_FEATURE_DFSTAB 0x0002 /* need to manage in dfstab */ +#define SA_FEATURE_ALLOWSUBDIRS 0x0004 /* allow subdirs to be shared */ +#define SA_FEATURE_ALLOWPARDIRS 0x0008 /* allow parent dirs to be shared */ +#define SA_FEATURE_HAS_SECTIONS 0x0010 /* protocol supports sections */ +#define SA_FEATURE_ADD_PROPERTIES 0x0020 /* can add properties */ +#define SA_FEATURE_SERVER 0x0040 /* protocol supports server mode */ + +/* + * legacy files */ -#ifndef _OPENSOLARIS_LIBSHARE_H_ -#define _OPENSOLARIS_LIBSHARE_H_ +#define SA_LEGACY_DFSTAB "/etc/dfs/dfstab" +#define SA_LEGACY_SHARETAB "/etc/dfs/sharetab" + +/* + * SMF related + */ + +#define SA_SVC_FMRI_BASE "svc:/network/shares/group" + +/* initialization */ +extern sa_handle_t sa_init(int); +extern void sa_fini(sa_handle_t); +extern int sa_update_config(sa_handle_t); +extern char *sa_errorstr(int); + +/* protocol names */ +extern int sa_get_protocols(char ***); +extern int sa_valid_protocol(char *); + +/* group control (create, remove, etc) */ +extern sa_group_t sa_create_group(sa_handle_t, char *, int *); +extern int sa_remove_group(sa_group_t); +extern sa_group_t sa_get_group(sa_handle_t, char *); +extern sa_group_t sa_get_next_group(sa_group_t); +extern char *sa_get_group_attr(sa_group_t, char *); +extern int sa_set_group_attr(sa_group_t, char *, char *); +extern sa_group_t sa_get_sub_group(sa_group_t); +extern int sa_valid_group_name(char *); + +/* share control */ +extern sa_share_t sa_add_share(sa_group_t, char *, int, int *); +extern int sa_check_path(sa_group_t, char *, int); +extern int sa_move_share(sa_group_t, sa_share_t); +extern int sa_remove_share(sa_share_t); +extern sa_share_t sa_get_share(sa_group_t, char *); +extern sa_share_t sa_find_share(sa_handle_t, char *); +extern sa_share_t sa_get_next_share(sa_share_t); +extern char *sa_get_share_attr(sa_share_t, char *); +extern char *sa_get_share_description(sa_share_t); +extern sa_group_t sa_get_parent_group(sa_share_t); +extern int sa_set_share_attr(sa_share_t, char *, char *); +extern int sa_set_share_description(sa_share_t, char *); +extern int sa_enable_share(sa_group_t, char *); +extern int sa_disable_share(sa_share_t, char *); +extern int sa_is_share(void *); + +/* resource name related */ +extern sa_resource_t sa_find_resource(sa_handle_t, char *); +extern sa_resource_t sa_get_resource(sa_group_t, char *); +extern sa_resource_t sa_get_next_resource(sa_resource_t); +extern sa_share_t sa_get_resource_parent(sa_resource_t); +extern sa_resource_t sa_get_share_resource(sa_share_t, char *); +extern sa_resource_t sa_add_resource(sa_share_t, char *, int, int *); +extern int sa_remove_resource(sa_resource_t); +extern char *sa_get_resource_attr(sa_resource_t, char *); +extern int sa_set_resource_attr(sa_resource_t, char *, char *); +extern int sa_set_resource_description(sa_resource_t, char *); +extern char *sa_get_resource_description(sa_resource_t); +extern int sa_enable_resource(sa_resource_t, char *); +extern int sa_disable_resource(sa_resource_t, char *); +extern int sa_rename_resource(sa_resource_t, char *); +extern void sa_fix_resource_name(char *); + +/* data structure free calls */ +extern void sa_free_attr_string(char *); +extern void sa_free_share_description(char *); + +/* optionset control */ +extern sa_optionset_t sa_get_optionset(sa_group_t, char *); +extern sa_optionset_t sa_get_next_optionset(sa_group_t); +extern char *sa_get_optionset_attr(sa_optionset_t, char *); +extern void sa_set_optionset_attr(sa_optionset_t, char *, char *); +extern sa_optionset_t sa_create_optionset(sa_group_t, char *); +extern int sa_destroy_optionset(sa_optionset_t); +extern sa_optionset_t sa_get_derived_optionset(void *, char *, int); +extern void sa_free_derived_optionset(sa_optionset_t); + +/* property functions */ +extern sa_property_t sa_get_property(sa_optionset_t, char *); +extern sa_property_t sa_get_next_property(sa_group_t); +extern char *sa_get_property_attr(sa_property_t, char *); +extern sa_property_t sa_create_section(char *, char *); +extern void sa_set_section_attr(sa_property_t, char *, char *); +extern sa_property_t sa_create_property(char *, char *); +extern int sa_add_property(void *, sa_property_t); +extern int sa_update_property(sa_property_t, char *); +extern int sa_remove_property(sa_property_t); +extern int sa_commit_properties(sa_optionset_t, int); +extern int sa_valid_property(sa_handle_t, void *, char *, sa_property_t); +extern int sa_is_persistent(void *); + +/* security control */ +extern sa_security_t sa_get_security(sa_group_t, char *, char *); +extern sa_security_t sa_get_next_security(sa_security_t); +extern char *sa_get_security_attr(sa_optionset_t, char *); +extern sa_security_t sa_create_security(sa_group_t, char *, char *); +extern int sa_destroy_security(sa_security_t); +extern void sa_set_security_attr(sa_security_t, char *, char *); +extern sa_optionset_t sa_get_all_security_types(void *, char *, int); +extern sa_security_t sa_get_derived_security(void *, char *, char *, int); +extern void sa_free_derived_security(sa_security_t); + +/* protocol specific interfaces */ +extern int sa_parse_legacy_options(sa_group_t, char *, char *); +extern char *sa_proto_legacy_format(char *, sa_group_t, int); +extern int sa_is_security(char *, char *); +extern sa_protocol_properties_t sa_proto_get_properties(char *); +extern uint64_t sa_proto_get_featureset(char *); +extern sa_property_t sa_get_protocol_section(sa_protocol_properties_t, char *); +extern sa_property_t sa_get_next_protocol_section(sa_property_t, char *); +extern sa_property_t sa_get_protocol_property(sa_protocol_properties_t, char *); +extern sa_property_t sa_get_next_protocol_property(sa_property_t, char *); +extern int sa_set_protocol_property(sa_property_t, char *, char *); +extern char *sa_get_protocol_status(char *); +extern void sa_format_free(char *); +extern sa_protocol_properties_t sa_create_protocol_properties(char *); +extern int sa_add_protocol_property(sa_protocol_properties_t, sa_property_t); +extern int sa_proto_valid_prop(sa_handle_t, char *, sa_property_t, + sa_optionset_t); +extern int sa_proto_valid_space(char *, char *); +extern char *sa_proto_space_alias(char *, char *); +extern int sa_proto_get_transients(sa_handle_t, char *); +extern int sa_proto_notify_resource(sa_resource_t, char *); +extern int sa_proto_change_notify(sa_share_t, char *); +extern int sa_proto_delete_section(char *, char *); + +/* handle legacy (dfstab/sharetab) files */ +extern int sa_delete_legacy(sa_share_t, char *); +extern int sa_update_legacy(sa_share_t, char *); +extern int sa_update_sharetab(sa_share_t, char *); +extern int sa_delete_sharetab(sa_handle_t, char *, char *); + +/* ZFS functions */ +extern int sa_zfs_is_shared(sa_handle_t, char *); +extern int sa_group_is_zfs(sa_group_t); +extern int sa_path_is_zfs(char *); -#define SA_OK 0 +/* SA Handle specific functions */ +extern sa_handle_t sa_find_group_handle(sa_group_t); -#define SA_INIT_CONTROL_API 0 +#ifdef __cplusplus +} +#endif -#endif /* !_OPENSOLARIS_LIBSHARE_H_ */ +#endif /* _LIBSHARE_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_avl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_avl.c --- /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_avl.c 2014-04-05 12:02:08.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_avl.c 2009-08-07 11:32:34.000000000 -0700 @@ -128,7 +128,6 @@ pp->uap_next->uap_prev = pp->uap_prev; pp->uap_prev->uap_next = pp->uap_next; (void) pthread_mutex_unlock(&uu_apool_list_lock); - (void) pthread_mutex_destroy(&pp->uap_lock); pp->uap_prev = NULL; pp->uap_next = NULL; uu_free(pp); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_misc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_misc.c --- /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_misc.c 2012-09-13 16:30:40.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_misc.c 2017-05-30 03:49:07.000000000 -0700 @@ -206,7 +206,7 @@ int assfail(const char *astring, const char *file, int line) { - __assert(astring, file, line); + __assert(file, line, astring); /*NOTREACHED*/ return (0); } @@ -243,6 +243,7 @@ } #pragma init(uu_init) +__attribute__((constructor)) static void uu_init(void) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_open.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_open.c --- /tmp/out/external/cddl/osnet/dist/lib/libuutil/common/uu_open.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libuutil/common/uu_open.c 2016-03-03 09:06:44.000000000 -0800 @@ -53,7 +53,8 @@ return (-1); for (;;) { - (void) snprintf(fname, PATH_MAX, "%s/uu%lld", dir, gethrtime()); + (void) snprintf(fname, PATH_MAX, "%s/uu%lld", dir, + (long long)gethrtime()); f = open(fname, O_CREAT | O_EXCL | O_RDWR, 0600); Only in /tmp/out/external/cddl/osnet/dist/lib/libuutil/common: uu_string.c diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs.h --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs.h 2016-12-03 09:05:31.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs.h 2017-04-22 10:17:31.000000000 -0700 @@ -737,10 +737,12 @@ extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, void *, void *, int, zfs_share_op_t); +#ifdef __FreeBSD__ /* * FreeBSD-specific jail support function. */ extern int zfs_jail(zfs_handle_t *, int, int); +#endif /* * When dealing with nvlists, verify() is extremely useful diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_compat.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_compat.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_compat.c 2016-03-26 19:48:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_compat.c 2017-04-25 16:51:09.000000000 -0700 @@ -23,6 +23,8 @@ * Copyright (c) 2013 Martin Matuska . All rights reserved. */ +#include + #include "libzfs_compat.h" int zfs_ioctl_version = ZFS_IOCVER_UNDEF; @@ -38,7 +40,8 @@ int ver = ZFS_IOCVER_NONE; ver_size = sizeof(ver); - sysctlbyname("vfs.zfs.version.ioctl", &ver, &ver_size, NULL, 0); + if (sysctlbyname("vfs.zfs.version.ioctl", &ver, &ver_size, NULL, 0) < 0) + err(1, "sysctl vfs.zfs.version.ioctl failed"); return (ver); } @@ -53,7 +56,8 @@ int ver = 0; ver_size = sizeof(ver); - sysctlbyname("vfs.zfs.version.spa", &ver, &ver_size, NULL, 0); + if (sysctlbyname("vfs.zfs.version.spa", &ver, &ver_size, NULL, 0) < 0) + err(1, "sysctl vfs.zfs.version.spa failed"); return (ver); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_dataset.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_dataset.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_dataset.c 2016-12-03 09:05:31.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_dataset.c 2017-04-22 01:56:07.000000000 -0700 @@ -712,7 +712,7 @@ sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node)); } -void +static void libzfs_mnttab_update(libzfs_handle_t *hdl) { struct mnttab entry; @@ -4853,6 +4853,7 @@ return (volsize); } +#ifdef __FreeBSD__ /* * Attach/detach the given filesystem to/from the given jail. */ @@ -4895,3 +4896,4 @@ return (ret); } +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_impl.h --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_impl.h 2016-10-10 04:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_impl.h 2017-04-19 17:10:55.000000000 -0700 @@ -45,11 +45,6 @@ extern "C" { #endif -#ifdef VERIFY -#undef VERIFY -#endif -#define VERIFY verify - typedef struct libzfs_fru { char *zf_device; char *zf_fru; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_import.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_import.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_import.c 2016-10-10 04:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_import.c 2017-05-05 10:34:14.000000000 -0700 @@ -54,7 +54,13 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif +#ifdef __NetBSD__ +#include +static int native_ioctl(int fd, unsigned long cmd, void *arg); +#endif #include @@ -1081,12 +1087,22 @@ */ check_slices(rn->rn_avl, fd, rn->rn_name); } -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ if (statbuf.st_size < SPA_MINDEVSIZE) { (void) close(fd); return; } -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + off_t size; + + if (native_ioctl(fd, DIOCGMEDIASIZE, &size) < 0 || + size < SPA_MINDEVSIZE) { + (void) close(fd); + return; + } +#endif if ((zpool_read_label(fd, &config)) != 0) { (void) close(fd); @@ -1208,6 +1224,7 @@ avl_create(&slice_cache, slice_cache_compare, sizeof (rdsk_node_t), offsetof(rdsk_node_t, rn_node)); +#ifdef __FreeBSD__ if (strcmp(rdsk, "/dev/") == 0) { struct gmesh mesh; struct gclass *mp; @@ -1239,6 +1256,43 @@ geom_deletetree(&mesh); goto skipdir; } +#endif +#ifdef __NetBSD__ + if (strcmp(rdsk, "/dev/") == 0) { + static const char mib_name[] = "hw.disknames"; + size_t len; + char *disknames, *last, *name; + char part; + + part = getrawpartition(); + if (sysctlbyname(mib_name, NULL, &len, NULL, 0) == -1) { + zfs_error_aux(hdl, strerror(errno)); + (void) zfs_error_fmt(hdl, EZFS_BADPATH, + dgettext(TEXT_DOMAIN, "cannot get hw.disknames list")); + + avl_destroy(&slice_cache); + (void) closedir(dirp); + goto error; + } + disknames = zfs_alloc(hdl, len + 2); + (void)sysctlbyname(mib_name, disknames, &len, NULL, 0); + + + for ((name = strtok_r(disknames, " ", &last)); name; + (name = strtok_r(NULL, " ", &last))) { + slice = zfs_alloc(hdl, sizeof (rdsk_node_t)); + slice->rn_name = zfs_asprintf(hdl, "%s%c", name, 'a' + part); + slice->rn_avl = &slice_cache; + slice->rn_dfd = dfd; + slice->rn_hdl = hdl; + slice->rn_nozpool = B_FALSE; + avl_add(&slice_cache, slice); + } + free(disknames); + + goto skipdir; + } +#endif /* * This is not MT-safe, but we have no MT consumers of libzfs @@ -1746,3 +1800,18 @@ *inuse = ret; return (0); } + +#ifdef __NetBSD__ +/* + * This needs to be at the end of the file so that we can #undef ioctl + * without affecting anything else. + */ +#undef ioctl + +static int +native_ioctl(int fd, unsigned long cmd, void *arg) +{ + + return ioctl(fd, cmd, arg); +} +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_mount.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_mount.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_mount.c 2016-10-10 04:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_mount.c 2017-04-20 15:40:09.000000000 -0700 @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ #include #include #include +#include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_sendrecv.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_sendrecv.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_sendrecv.c 2016-10-10 04:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_sendrecv.c 2017-04-22 10:03:30.000000000 -0700 @@ -60,12 +60,12 @@ #ifdef __FreeBSD__ extern int zfs_ioctl_version; +/* We need to use something for ENODATA. */ +#define ENODATA EIDRM #endif /* in libzfs_dataset.c */ extern void zfs_setprop_error(libzfs_handle_t *, zfs_prop_t, int, char *); -/* We need to use something for ENODATA. */ -#define ENODATA EIDRM static int zfs_receive_impl(libzfs_handle_t *, const char *, const char *, recvflags_t *, int, const char *, nvlist_t *, avl_tree_t *, char **, int, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_util.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_util.c --- /tmp/out/external/cddl/osnet/dist/lib/libzfs/common/libzfs_util.c 2016-10-10 04:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzfs/common/libzfs_util.c 2017-04-25 10:20:07.000000000 -0700 @@ -48,6 +48,11 @@ #include #include #include +#include + +#ifdef __NetBSD__ +#include +#endif #include #include @@ -622,8 +627,7 @@ static int libzfs_load(void) { - int error; - +#ifdef __FreeBSD__ if (modfind("zfs") < 0) { /* Not present in kernel, try loading it. */ if (kldload("zfs") < 0 || modfind("zfs") < 0) { @@ -631,6 +635,18 @@ return (-1); } } +#endif +#ifdef __NetBSD__ + modctl_load_t cmdargs; + + cmdargs.ml_filename = "zfs"; + cmdargs.ml_flags = MODCTL_NO_PROP; + cmdargs.ml_props = NULL; + cmdargs.ml_propslen = 0; + + if (modctl(MODCTL_LOAD, &cmdargs) < 0 && errno != EEXIST) + return (-1); +#endif return (0); } @@ -747,7 +763,8 @@ break; } } -#else +#endif /* illumos */ +#ifdef __FreeBSD__ { struct statfs sfs; @@ -759,7 +776,20 @@ strerror(errno)); } } -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + { + struct statvfs sfs; + + ret = statvfs(path, &sfs); + if (ret == 0) + statvfs2mnttab(&sfs, &entry); + else { + (void) fprintf(stderr, "%s: %s\n", path, + strerror(errno)); + } + } +#endif /* __NetBSD__ */ if (ret != 0) { return (NULL); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/lib/libzpool/common/kernel.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c --- /tmp/out/external/cddl/osnet/dist/lib/libzpool/common/kernel.c 2017-03-26 23:26:21.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/lib/libzpool/common/kernel.c 2017-04-29 21:17:20.000000000 -0700 @@ -923,7 +923,7 @@ return (0); } -#ifdef illumos +#ifndef __FreeBSD__ /* ARGSUSED */ cyclic_id_t cyclic_add(cyc_handler_t *hdlr, cyc_time_t *when) Only in /tmp/out/external/cddl/osnet/dist/lib/libzpool/common: zfs.d Only in /tmp/out/external/cddl/osnet/dist/lib: pyzfs diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/common/list.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/list.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/common/list.c 2012-06-11 22:55:15.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/list.c 2016-02-06 09:38:15.000000000 -0800 @@ -30,6 +30,10 @@ * Routines for manipulating linked lists */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/common/memory.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/memory.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/common/memory.c 2012-06-11 22:55:15.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/memory.c 2016-02-06 09:38:15.000000000 -0800 @@ -30,6 +30,10 @@ * Routines for memory management */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -37,7 +41,7 @@ #include #include "memory.h" -static void +static void __dead memory_bailout(void) { (void) fprintf(stderr, "Out of memory\n"); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/common/symbol.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/symbol.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/common/symbol.c 2012-06-11 22:55:15.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/symbol.c 2010-02-24 13:53:26.000000000 -0800 @@ -26,6 +26,10 @@ #pragma ident "%Z%%M% %I% %E% SMI" +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/common/utils.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/utils.h --- /tmp/out/external/cddl/osnet/dist/tools/ctf/common/utils.h 2012-06-11 22:55:15.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/common/utils.h 2016-02-06 09:38:15.000000000 -0800 @@ -39,10 +39,10 @@ #define E_ERROR 1 /* Exit status for error */ #define E_USAGE 2 /* Exit status for usage error */ -extern void vwarn(const char *, va_list); -extern void warn(const char *, ...); -extern void vdie(const char *, va_list); -extern void die(const char *, ...); +extern void vwarn(const char *, va_list) __printflike(1, 0); +extern void warn(const char *, ...) __printflike(1, 2); +extern void vdie(const char *, va_list) __printflike(1, 0) __dead; +extern void die(const char *, ...) __printflike(1, 2) __dead; extern const char *getpname(void); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/alist.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/alist.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/alist.c 2012-06-11 22:55:16.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/alist.c 2010-02-20 17:46:34.000000000 -0800 @@ -33,6 +33,7 @@ #include #include +#include #include "alist.h" #include "memory.h" diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c 2016-12-18 18:09:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctf.c 2017-04-13 12:16:42.000000000 -0700 @@ -27,6 +27,10 @@ * Create and parse buffers containing CTF data. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include #include #include @@ -75,7 +79,7 @@ static int target_requires_swap; /*PRINTFLIKE1*/ -static void +static void __printflike(1, 2) __dead parseterminate(const char *fmt, ...) { static char msgbuf[1024]; /* sigh */ @@ -355,6 +359,7 @@ break; case POINTER: + case REFERENCE: /* XXX: */ ctt.ctt_info = CTF_TYPE_INFO(CTF_K_POINTER, isroot, 0); ctt.ctt_type = tp->t_tdesc->t_id; write_unsized_type_rec(b, &ctt); @@ -377,12 +382,14 @@ case STRUCT: case UNION: + case CLASS: for (i = 0, mp = tp->t_members; mp != NULL; mp = mp->ml_next) i++; /* count up struct or union members */ if (i > CTF_MAX_VLEN) { - terminate("sou %s has too many members: %d > %d\n", + warning("sou %s has too many members: %d > %d\n", tdesc_name(tp), i, CTF_MAX_VLEN); + i = CTF_MAX_VLEN; } if (tp->t_type == STRUCT) @@ -393,7 +400,8 @@ write_sized_type_rec(b, &ctt, tp->t_size); if (tp->t_size < CTF_LSTRUCT_THRESH) { - for (mp = tp->t_members; mp != NULL; mp = mp->ml_next) { + for (mp = tp->t_members; mp != NULL && i > 0; + mp = mp->ml_next) { offset = strtab_insert(&b->ctb_strtab, mp->ml_name); @@ -407,9 +415,11 @@ SWAP_16(ctm.ctm_offset); } ctf_buf_write(b, &ctm, sizeof (ctm)); + i--; } } else { - for (mp = tp->t_members; mp != NULL; mp = mp->ml_next) { + for (mp = tp->t_members; mp != NULL && i > 0; + mp = mp->ml_next) { offset = strtab_insert(&b->ctb_strtab, mp->ml_name); @@ -429,6 +439,7 @@ } ctf_buf_write(b, &ctlm, sizeof (ctlm)); + i--; } } break; @@ -819,8 +830,9 @@ case CTF_K_UNKNOWN: break; default: - parseterminate("Unknown CTF type %d (#%d) at %#x", - CTF_INFO_KIND(ctt->ctt_info), count, dptr - data); + parseterminate("Unknown CTF type %d (#%d) at %#jx", + CTF_INFO_KIND(ctt->ctt_info), count, + (intmax_t)(dptr - data)); } dptr += increment; @@ -907,8 +919,8 @@ if (!(sym = symit_next(si, STT_OBJECT)) && id != 0) { parseterminate( - "Unexpected end of object symbols at %x of %x", - dptr - buf, bufsz); + "Unexpected end of object symbols at %ju of %zu", + (intmax_t)(dptr - buf), bufsz); } if (id == 0) { @@ -1321,8 +1333,9 @@ return (0); } - debug(3, "reflated %lu bytes to %lu, pointer at %d\n", - zstr.total_in, zstr.total_out, (caddr_t)zstr.next_in - cbuf); + debug(3, "reflated %lu bytes to %lu, pointer at 0x%jx\n", + zstr.total_in, zstr.total_out, + (intmax_t)((caddr_t)zstr.next_in - cbuf)); return (zstr.total_out); } @@ -1366,7 +1379,7 @@ if ((actual = decompress_ctf(buf, bufsz, ctfdata, ctfdatasz)) != ctfdatasz) { parseterminate("Corrupt CTF - short decompression " - "(was %d, expecting %d)", actual, ctfdatasz); + "(was %zu, expecting %zu)", actual, ctfdatasz); } } else { ctfdata = buf; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctfconvert.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctfconvert.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctfconvert.c 2015-02-03 23:20:42.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctfconvert.c 2017-04-13 12:21:22.000000000 -0700 @@ -30,6 +30,10 @@ * CTF data, and replace the stabs sections with a CTF section. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -64,7 +68,7 @@ static void terminate_cleanup(void) { -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) if (!outfile) { fprintf(stderr, "Removing %s\n", infile); unlink(infile); @@ -72,7 +76,7 @@ #endif } -static void +static void __dead handle_sig(int sig) { terminate("Caught signal %d - exiting\n", sig); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c 2015-02-03 23:20:42.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c 2017-04-13 12:25:33.000000000 -0700 @@ -171,9 +171,19 @@ * this comment will not live to see the stock hit five. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE /* XXX TBD fix this */ +#include +#undef _NETBSD_SOURCE +#else #include +#endif #include #include #ifdef illumos @@ -212,10 +222,12 @@ static char *tmpname = NULL; static int dynsym; int debug_level = DEBUG_LEVEL; +#ifdef illumos static size_t maxpgsize = 0x400000; +#endif -void +static void usage(void) { (void) fprintf(stderr, @@ -280,7 +292,7 @@ (void) memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mha, 0, 0); } -#endif /* illumos */ +#endif static void finalize_phase_one(workqueue_t *wq) @@ -386,7 +398,8 @@ slot->wip_td = pow; slot->wip_nmerged = 1; } else { - debug(2, "%d: merging %p into %p\n", pthread_self(), + debug(2, "0x%jx: merging %p into %p\n", + (uintmax_t)(uintptr_t)pthread_self(), (void *)pow, (void *)slot->wip_td); merge_into_master(pow, slot->wip_td, NULL, 0); @@ -456,8 +469,8 @@ pthread_cond_broadcast(&wq->wq_work_avail); pthread_mutex_unlock(&wq->wq_queue_lock); - debug(2, "%d: entering p2 completion barrier\n", - pthread_self()); + debug(2, "0x%jx: entering p2 completion barrier\n", + (uintmax_t)(uintptr_t)pthread_self()); if (barrier_wait(&wq->wq_bar1)) { pthread_mutex_lock(&wq->wq_queue_lock); wq->wq_alldone = 1; @@ -484,7 +497,8 @@ pthread_mutex_unlock(&wq->wq_queue_lock); - debug(2, "%d: merging %p into %p\n", pthread_self(), + debug(2, "0x%jx: merging %p into %p\n", + (uintmax_t)(uintptr_t)pthread_self(), (void *)pow1, (void *)pow2); merge_into_master(pow1, pow2, NULL, 0); tdata_free(pow1); @@ -502,9 +516,9 @@ wq->wq_lastdonebatch = batchid; fifo_add(wq->wq_queue, pow2); - debug(2, "%d: added %p to queue, len now %d, ninqueue %d\n", - pthread_self(), (void *)pow2, fifo_len(wq->wq_queue), - wq->wq_ninqueue); + debug(2, "0x%jx: added %p to queue, len now %d, ninqueue %d\n", + (uintmax_t)(uintptr_t)pthread_self(), (void *)pow2, + fifo_len(wq->wq_queue), wq->wq_ninqueue); pthread_cond_broadcast(&wq->wq_done_cv); pthread_cond_signal(&wq->wq_work_avail); pthread_mutex_unlock(&wq->wq_queue_lock); @@ -519,25 +533,30 @@ { worker_runphase1(wq); - debug(2, "%d: entering first barrier\n", pthread_self()); + debug(2, "0x%jx: entering first barrier\n", + (uintmax_t)(uintptr_t)pthread_self()); if (barrier_wait(&wq->wq_bar1)) { - debug(2, "%d: doing work in first barrier\n", pthread_self()); + debug(2, "0x%jx: doing work in first barrier\n", + (uintmax_t)(uintptr_t)pthread_self()); finalize_phase_one(wq); init_phase_two(wq); - debug(2, "%d: ninqueue is %d, %d on queue\n", pthread_self(), + debug(2, "0x%jx: ninqueue is %d, %d on queue\n", + (uintmax_t)(uintptr_t)pthread_self(), wq->wq_ninqueue, fifo_len(wq->wq_queue)); } - debug(2, "%d: entering second barrier\n", pthread_self()); + debug(2, "0x%jx: entering second barrier\n", + (uintmax_t)(uintptr_t)pthread_self()); (void) barrier_wait(&wq->wq_bar2); - debug(2, "%d: phase 1 complete\n", pthread_self()); + debug(2, "0x%jx: phase 1 complete\n", + (uintmax_t)(uintptr_t)pthread_self()); worker_runphase2(wq); } @@ -561,7 +580,8 @@ } fifo_add(wq->wq_queue, td); - debug(1, "Thread %d announcing %s\n", pthread_self(), name); + debug(1, "Thread 0x%jx announcing %s\n", + (uintmax_t)(uintptr_t)pthread_self(), name); pthread_cond_broadcast(&wq->wq_work_avail); pthread_mutex_unlock(&wq->wq_queue_lock); @@ -586,7 +606,7 @@ * completion. The run time of ctfmerge can, however, be measured in minutes * in some cases, so this is not a valid option. */ -static void +static void __dead handle_sig(int sig) { terminate("Caught signal %d - exiting\n", sig); @@ -603,7 +623,7 @@ if (outfile == NULL) return; -#if !defined(__FreeBSD__) +#if !defined (__FreeBSD__) && !defined(__NetBSD__) if (dounlink) { fprintf(stderr, "Removing %s\n", outfile); unlink(outfile); @@ -649,7 +669,11 @@ wq->wq_wip = xcalloc(sizeof (wip_t) * nslots); wq->wq_nwipslots = nslots; +#ifdef _SC_NPROCESSORS_ONLN wq->wq_nthreads = MIN(sysconf(_SC_NPROCESSORS_ONLN) * 3 / 2, nslots); +#else + wq->wq_nthreads = 2; +#endif wq->wq_thread = xmalloc(sizeof (pthread_t) * wq->wq_nthreads); if (getenv("CTFMERGE_INPUT_THROTTLE")) @@ -665,6 +689,7 @@ for (i = 0; i < nslots; i++) { pthread_mutex_init(&wq->wq_wip[i].wip_lock, NULL); + pthread_cond_init(&wq->wq_wip[i].wip_cv, NULL); wq->wq_wip[i].wip_batchid = wq->wq_next_batchid++; } @@ -732,8 +757,8 @@ static int strcompare(const void *p1, const void *p2) { - char *s1 = *((char **)p1); - char *s2 = *((char **)p2); + const char *s1 = *((const char * const *)p1); + const char *s2 = *((const char * const *)p2); return (strcmp(s1, s2)); } @@ -794,7 +819,7 @@ case 'L': /* Label merged types with getenv(`label`) */ if ((label = getenv(optarg)) == NULL) - label = CTF_DEFAULT_LABEL; + label = __UNCONST(CTF_DEFAULT_LABEL); break; case 'o': /* Place merged types in CTF section in `outfile' */ @@ -885,7 +910,7 @@ for (i = 0; i < nifiles; i++) tifiles[i] = argv[optind + i]; - qsort(tifiles, nifiles, sizeof (char *), (int (*)())strcompare); + qsort(tifiles, nifiles, sizeof (char *), strcompare); ifiles[0] = tifiles[0]; for (idx = 0, tidx = 1; tidx < nifiles; tidx++) { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctftools.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctftools.h --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/ctftools.h 2016-12-18 18:09:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/ctftools.h 2017-04-13 12:26:29.000000000 -0700 @@ -65,8 +65,12 @@ #define MIN(a, b) ((a) > (b) ? (b) : (a)) #endif +#ifndef TRUE #define TRUE 1 +#endif +#ifndef FALSE #define FALSE 0 +#endif #define CTF_ELF_SCN_NAME ".SUNW_ctf" @@ -133,10 +137,12 @@ STABTYPE_FIRST, /* do not use */ INTRINSIC, POINTER, + REFERENCE, ARRAY, FUNCTION, STRUCT, UNION, + CLASS, ENUM, FORWARD, TYPEDEF, @@ -159,7 +165,7 @@ /* Auxiliary structure for structure/union tdesc_t */ typedef struct mlist { int ml_offset; /* Offset from start of structure (in bits) */ - int ml_size; /* Member size (in bits) */ + uint_t ml_size; /* Member size (in bits) */ char *ml_name; /* Member name */ struct tdesc *ml_type; /* Member type */ struct mlist *ml_next; /* Next member */ @@ -435,13 +441,13 @@ int findelfsecidx(Elf *, const char *, const char *); size_t elf_ptrsz(Elf *); char *mktmpname(const char *, const char *); -void terminate(const char *, ...) __NORETURN; -void aborterr(const char *, ...) __NORETURN; +void terminate(const char *, ...) __printflike(1, 2) __dead; +void aborterr(const char *, ...) __printflike(1, 2) __dead; void set_terminate_cleanup(void (*)(void)); -void elfterminate(const char *, const char *, ...); -void warning(const char *, ...); -void vadebug(int, const char *, va_list); -void debug(int, const char *, ...); +void elfterminate(const char *, const char *, ...) __printflike(2, 3) __dead; +void warning(const char *, ...) __printflike(1, 2); +void vadebug(int, const char *, va_list) __printflike(2, 0); +void debug(int, const char *, ...) __printflike(2, 3); void watch_dump(int); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/dwarf.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/dwarf.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/dwarf.c 2016-12-18 18:09:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/dwarf.c 2017-04-22 10:06:56.000000000 -0700 @@ -80,6 +80,10 @@ * traversals. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -177,14 +181,17 @@ switch (tdp->t_type) { case INTRINSIC: case POINTER: + case REFERENCE: case ARRAY: case FUNCTION: case STRUCT: case UNION: + case CLASS: case ENUM: return (tdp->t_size); case FORWARD: + debug(3, "type is forward for %#x\n", tdp->t_id); return (0); case TYPEDEF: @@ -195,10 +202,11 @@ continue; case 0: /* not yet defined */ + debug(3, "type is undefined for %#x\n", tdp->t_id); return (0); default: - terminate("tdp %u: tdesc_size on unknown type %d\n", + terminate("tdp %u: tdesc_size on unknown type %#x\n", tdp->t_id, tdp->t_type); } } @@ -216,11 +224,14 @@ case FUNCTION: case STRUCT: case UNION: + case CLASS: case ENUM: case POINTER: + case REFERENCE: return (tdp->t_size * NBBY); case FORWARD: + debug(3, "bitsize is forward for %d\n", tdp->t_id); return (0); case TYPEDEF: @@ -231,6 +242,7 @@ continue; case 0: /* not yet defined */ + debug(3, "bitsize is undefined for %d\n", tdp->t_id); return (0); default: @@ -285,8 +297,8 @@ else if (rc == DW_DLV_NO_ENTRY) return (NULL); - terminate("die %llu: failed to find type sibling: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to find type sibling: %s\n", + (uintmax_t)die_off(dw, die), dwarf_errmsg(dw->dw_err)); /*NOTREACHED*/ return (NULL); } @@ -302,8 +314,8 @@ else if (rc == DW_DLV_NO_ENTRY) return (NULL); - terminate("die %llu: failed to find type child: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to find type child: %s\n", + (uintmax_t)die_off(dw, die), dwarf_errmsg(dw->dw_err)); /*NOTREACHED*/ return (NULL); } @@ -316,8 +328,8 @@ if (dwarf_tag(die, &tag, &dw->dw_err) == DW_DLV_OK) return (tag); - terminate("die %llu: failed to get tag for type: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get tag for type: %s\n", + (uintmax_t)die_off(dw, die), dwarf_errmsg(dw->dw_err)); /*NOTREACHED*/ return (0); } @@ -332,15 +344,16 @@ return (attr); } else if (rc == DW_DLV_NO_ENTRY) { if (req) { - terminate("die %llu: no attr 0x%x\n", die_off(dw, die), + terminate("die %ju: no attr 0x%x\n", + (uintmax_t)die_off(dw, die), name); } else { return (NULL); } } - terminate("die %llu: failed to get attribute for type: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get attribute for type: %s\n", + (uintmax_t)die_off(dw, die), dwarf_errmsg(dw->dw_err)); /*NOTREACHED*/ return (NULL); } @@ -352,8 +365,9 @@ *valp = 0; if (dwarf_attrval_signed(die, name, valp, &dw->dw_err) != DW_DLV_OK) { if (req) - terminate("die %llu: failed to get signed: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get signed: %s\n", + (uintmax_t)die_off(dw, die), + dwarf_errmsg(dw->dw_err)); return (0); } @@ -367,8 +381,9 @@ *valp = 0; if (dwarf_attrval_unsigned(die, name, valp, &dw->dw_err) != DW_DLV_OK) { if (req) - terminate("die %llu: failed to get unsigned: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get unsigned: %s\n", + (uintmax_t)die_off(dw, die), + dwarf_errmsg(dw->dw_err)); return (0); } @@ -382,8 +397,9 @@ if (dwarf_attrval_flag(die, name, valp, &dw->dw_err) != DW_DLV_OK) { if (req) - terminate("die %llu: failed to get flag: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get flag: %s\n", + (uintmax_t)die_off(dw, die), + dwarf_errmsg(dw->dw_err)); return (0); } @@ -398,8 +414,9 @@ if (dwarf_attrval_string(die, name, &str, &dw->dw_err) != DW_DLV_OK || str == NULL) { if (req) - terminate("die %llu: failed to get string: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get string: %s\n", + (uintmax_t)die_off(dw, die), + dwarf_errmsg(dw->dw_err)); else *strp = NULL; return (0); @@ -415,8 +432,8 @@ Dwarf_Off off; if (dwarf_attrval_unsigned(die, name, &off, &dw->dw_err) != DW_DLV_OK) { - terminate("die %llu: failed to get ref: %s\n", - die_off(dw, die), dwarf_errmsg(dw->dw_err)); + terminate("die %ju: failed to get ref: %s\n", + (uintmax_t)die_off(dw, die), dwarf_errmsg(dw->dw_err)); } return (off); @@ -492,8 +509,9 @@ Dwarf_Half form; if (name != DW_AT_data_member_location) - terminate("die %llu: can only process attribute " - "DW_AT_data_member_location\n", die_off(dw, die)); + terminate("die %ju: can only process attribute " + "DW_AT_data_member_location\n", + (uintmax_t)die_off(dw, die)); if ((at = die_attr(dw, die, name, 0)) == NULL) return (0); @@ -516,9 +534,9 @@ if (dwarf_loclist(at, &loc, &locnum, &dw->dw_err) != DW_DLV_OK) return (0); if (locnum != 1 || loc->ld_s->lr_atom != DW_OP_plus_uconst) { - terminate("die %llu: cannot parse member offset with " + terminate("die %ju: cannot parse member offset with " "operator other than DW_OP_plus_uconst\n", - die_off(dw, die)); + (uintmax_t)die_off(dw, die)); } *valp = loc->ld_s->lr_number; if (loc != NULL) { @@ -552,8 +570,8 @@ break; default: - terminate("die %llu: cannot parse member offset with form " - "%u\n", die_off(dw, die), form); + terminate("die %ju: cannot parse member offset with form " + "%u\n", (uintmax_t)die_off(dw, die), form); } return (1); @@ -657,12 +675,12 @@ } else if (die_tag(dw, dim2) == DW_TAG_subrange_type) { ctdp = xcalloc(sizeof (tdesc_t)); ctdp->t_id = mfgtid_next(dw); - debug(3, "die %llu: creating new type %u for sub-dimension\n", - die_off(dw, dim2), ctdp->t_id); + debug(3, "die %ju: creating new type %#x for sub-dimension\n", + (uintmax_t)die_off(dw, dim2), ctdp->t_id); tdesc_array_create(dw, dim2, arrtdp, ctdp); } else { - terminate("die %llu: unexpected non-subrange node in array\n", - die_off(dw, dim2)); + terminate("die %ju: unexpected non-subrange node in array\n", + (uintmax_t)die_off(dw, dim2)); } dimtdp->t_type = ARRAY; @@ -684,9 +702,9 @@ else if (die_signed(dw, dim, DW_AT_upper_bound, &sval, 0)) ar->ad_nelems = sval + 1; else if (die_unsigned(dw, dim, DW_AT_count, &uval, 0)) - ar->ad_nelems = uval; + ar->ad_nelems = uval + 1; else if (die_signed(dw, dim, DW_AT_count, &sval, 0)) - ar->ad_nelems = sval; + ar->ad_nelems = sval + 1; else ar->ad_nelems = 0; @@ -696,6 +714,8 @@ */ ar->ad_idxtype = tdesc_intr_long(dw); ar->ad_contents = ctdp; + debug(3, "die %ju: hi mom sibling type %#x for dimension\n", + (uintmax_t)die_off(dw, dim), ctdp->t_id); if (ar->ad_contents->t_size != 0) { dimtdp->t_size = ar->ad_contents->t_size * ar->ad_nelems; @@ -715,11 +735,24 @@ Dwarf_Unsigned uval; Dwarf_Die dim; - debug(3, "die %llu <%llx>: creating array\n", off, off); + debug(3, "die %ju <%jx>: creating array\n", + (uintmax_t)off, (uintmax_t)off); if ((dim = die_child(dw, arr)) == NULL || die_tag(dw, dim) != DW_TAG_subrange_type) - terminate("die %llu: failed to retrieve array bounds\n", off); + terminate("die %ju: failed to retrieve array bounds\n", + (uintmax_t)off); + + if (arrtdp->t_type == 0) { + /* + * Add the die that contains the type of the array elements + * to the the ones we process; XXX: no public API for that? + */ + extern Dwarf_Die _dwarf_die_find(Dwarf_Die, Dwarf_Unsigned); + Dwarf_Die elem = _dwarf_die_find(arr, arrtdp->t_id); + if (elem != NULL) + die_create_one(dw, elem); + } tdesc_array_create(dw, dim, arrtdp, tdp); @@ -746,8 +779,8 @@ tdp->t_flags |= flags; } - debug(3, "die %llu <%llx>: array nelems %u size %u\n", off, off, - tdp->t_ardef->ad_nelems, tdp->t_size); + debug(3, "die %ju <%jx>: array nelems %u size %u\n", (uintmax_t)off, + (uintmax_t)off, tdp->t_ardef->ad_nelems, tdp->t_size); } /*ARGSUSED1*/ @@ -760,12 +793,13 @@ if (tdp->t_flags & TDESC_F_RESOLVED) return (1); - debug(3, "trying to resolve array %d (cont %d)\n", tdp->t_id, - tdp->t_ardef->ad_contents->t_id); + debug(3, "trying to resolve array %#x (cont %#x/%d)\n", tdp->t_id, + tdp->t_ardef->ad_contents->t_id, + tdp->t_ardef->ad_contents->t_size); if ((sz = tdesc_size(tdp->t_ardef->ad_contents)) == 0 && (tdp->t_ardef->ad_contents->t_flags & TDESC_F_RESOLVED) == 0) { - debug(3, "unable to resolve array %s (%d) contents %d\n", + debug(3, "unable to resolve array %s (%#x) contents %#x\n", tdesc_name(tdp), tdp->t_id, tdp->t_ardef->ad_contents->t_id); @@ -776,7 +810,7 @@ tdp->t_size = sz * tdp->t_ardef->ad_nelems; tdp->t_flags |= TDESC_F_RESOLVED; - debug(3, "resolved array %d: %u bytes\n", tdp->t_id, tdp->t_size); + debug(3, "resolved array %#x: %u bytes\n", tdp->t_id, tdp->t_size); return (1); } @@ -814,7 +848,7 @@ return; } - debug(3, "die %llu: creating enum\n", off); + debug(3, "die %ju: creating enum\n", (uintmax_t)off); tdp->t_type = ENUM; @@ -842,12 +876,14 @@ &uval, 0)) { el->el_number = uval; } else { - terminate("die %llu: enum %llu: member without " - "value\n", off, die_off(dw, mem)); + terminate("die %ju: enum %ju: member without " + "value\n", (uintmax_t)off, + (uintmax_t)die_off(dw, mem)); } - debug(3, "die %llu: enum %llu: created %s = %d\n", off, - die_off(dw, mem), el->el_name, el->el_number); + debug(3, "die %ju: enum %ju: created %s = %d\n", + (uintmax_t)off, (uintmax_t)die_off(dw, mem), + el->el_name, el->el_number); *elastp = el; elastp = &el->el_next; @@ -933,7 +969,7 @@ int type, const char *typename) { Dwarf_Unsigned sz, bitsz, bitoff; -#if BYTE_ORDER == _LITTLE_ENDIAN +#if BYTE_ORDER == LITTLE_ENDIAN Dwarf_Unsigned bysz; #endif Dwarf_Die mem; @@ -942,9 +978,9 @@ tdp->t_type = (die_isdecl(dw, str) ? FORWARD : type); - debug(3, "die %llu: creating %s %s\n", off, + debug(3, "die %ju: creating %s %s <%d>\n", (uintmax_t)off, (tdp->t_type == FORWARD ? "forward decl" : typename), - tdesc_name(tdp)); + tdesc_name(tdp), tdp->t_id); if (tdp->t_type == FORWARD) { hash_add(dw->dw_fwdhash, tdp); @@ -976,7 +1012,8 @@ continue; } - debug(3, "die %llu: mem %llu: creating member\n", off, memoff); + debug(3, "die %ju: mem %ju: creating member\n", + (uintmax_t)off, (uintmax_t)memoff); ml = xcalloc(sizeof (mlist_t)); @@ -994,8 +1031,8 @@ if (die_mem_offset(dw, mem, DW_AT_data_member_location, &mloff, 0)) { - debug(3, "die %llu: got mloff %llx\n", off, - (u_longlong_t)mloff); + debug(3, "die %ju: got mloff 0x%jx\n", (uintmax_t)off, + (uintmax_t)mloff); ml->ml_offset = mloff * 8; } @@ -1005,7 +1042,7 @@ ml->ml_size = tdesc_bitsize(ml->ml_type); if (die_unsigned(dw, mem, DW_AT_bit_offset, &bitoff, 0)) { -#if BYTE_ORDER == _BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN ml->ml_offset += bitoff; #else /* @@ -1031,8 +1068,9 @@ #endif } - debug(3, "die %llu: mem %llu: created \"%s\" (off %u sz %u)\n", - off, memoff, ml->ml_name, ml->ml_offset, ml->ml_size); + debug(3, "die %ju: mem %ju: created \"%s\" (off %u sz %u)\n", + (uintmax_t)off, (uintmax_t)memoff, ml->ml_name, + ml->ml_offset, ml->ml_size); *mlastp = ml; mlastp = &ml->ml_next; @@ -1064,7 +1102,8 @@ char *new = xmalloc(newsz); (void) snprintf(new, newsz, "orphan %s", old); - debug(3, "die %llu: worked around %s %s\n", off, typename, old); + debug(3, "die %ju: worked around %s %s\n", (uintmax_t)off, + typename, old); if (tdp->t_name != NULL) free(tdp->t_name); @@ -1095,6 +1134,12 @@ die_sou_create(dw, die, off, tdp, UNION, "union"); } +static void +die_class_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp) +{ + die_sou_create(dw, die, off, tdp, CLASS, "class"); +} + /*ARGSUSED1*/ static int die_sou_resolve(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private) @@ -1112,6 +1157,9 @@ if (ml->ml_size == 0) { mt = tdesc_basetype(ml->ml_type); + if (mt == NULL) + continue; + if ((ml->ml_size = tdesc_bitsize(mt)) != 0) continue; @@ -1126,9 +1174,38 @@ if (mt->t_type == ARRAY && mt->t_ardef->ad_nelems == 0) continue; if ((mt->t_flags & TDESC_F_RESOLVED) != 0 && - (mt->t_type == STRUCT || mt->t_type == UNION)) + (mt->t_type == STRUCT || mt->t_type == UNION || + mt->t_type == CLASS)) continue; + if (mt->t_type == STRUCT && + mt->t_members != NULL && + mt->t_members->ml_type->t_type == ARRAY && + mt->t_members->ml_type->t_ardef->ad_nelems == 0) { + /* struct with zero sized array */ + continue; + } + + /* + * anonymous union members are OK. + * XXX: we should consistently use NULL, instead of "" + */ + if (mt->t_type == UNION && + (mt->t_name == NULL || mt->t_name[0] == '\0')) + continue; + + /* + * XXX: Gcc-5.4 DW_TAG_typedef without DW_AT_type; + * assume pointer + */ + if (mt->t_id == TID_VOID) { + ml->ml_size = dw->dw_ptrsz; + continue; + } + + fprintf(stderr, "%s unresolved type=%d (%s) tid=%#x\n", + tdesc_name(tdp), mt->t_type, tdesc_name(mt), + mt->t_id); dw->dw_nunres++; return (1); } @@ -1191,7 +1268,8 @@ fndef_t *fn; int i; - debug(3, "die %llu <%llx>: creating function pointer\n", off, off); + debug(3, "die %ju <0x%jx>: creating function pointer\n", + (uintmax_t)off, (uintmax_t)off); /* * We'll begin by processing any type definition nodes that may be @@ -1239,8 +1317,8 @@ } if (fn->fn_nargs != 0) { - debug(3, "die %llu: adding %d argument%s\n", off, fn->fn_nargs, - (fn->fn_nargs > 1 ? "s" : "")); + debug(3, "die %ju: adding %d argument%s\n", (uintmax_t)off, + fn->fn_nargs, (fn->fn_nargs > 1 ? "s" : "")); fn->fn_args = xcalloc(sizeof (tdesc_t *) * fn->fn_nargs); for (i = 0, arg = die_child(dw, die); @@ -1268,7 +1346,7 @@ static intr_t * die_base_name_parse(const char *name, char **newp) { - char buf[100]; + char buf[1024]; char const *base; char *c; int nlong = 0, nshort = 0, nchar = 0, nint = 0; @@ -1368,7 +1446,7 @@ mult = 2; col = 1; } else if (enc == DW_ATE_imaginary_float -#ifdef illumos +#if defined(sun) || enc == DW_ATE_SUN_imaginary_float #endif ) @@ -1380,7 +1458,8 @@ map++; } - terminate("die %llu: unrecognized real type size %u\n", off, sz); + terminate("die %ju: unrecognized real type size %ju\n", + (uintmax_t)off, (uintmax_t)sz); /*NOTREACHED*/ return (0); } @@ -1419,7 +1498,7 @@ case DW_ATE_float: case DW_ATE_complex_float: case DW_ATE_imaginary_float: -#ifdef illumos +#if defined(sun) case DW_ATE_SUN_imaginary_float: case DW_ATE_SUN_interval_float: #endif @@ -1428,8 +1507,8 @@ intr->intr_fformat = die_base_type2enc(dw, off, enc, sz); break; default: - terminate("die %llu: unknown base type encoding 0x%llx\n", - off, enc); + terminate("die %ju: unknown base type encoding 0x%jx\n", + (uintmax_t)off, (uintmax_t)enc); } return (intr); @@ -1442,7 +1521,7 @@ intr_t *intr; char *new; - debug(3, "die %llu: creating base type\n", off); + debug(3, "die %ju: creating base type\n", (uintmax_t)off); /* * The compilers have their own clever (internally inconsistent) ideas @@ -1456,13 +1535,13 @@ (void) die_unsigned(dw, base, DW_AT_byte_size, &sz, DW_ATTR_REQ); if (tdp->t_name == NULL) - terminate("die %llu: base type without name\n", off); + terminate("die %ju: base type without name\n", (uintmax_t)off); /* XXX make a name parser for float too */ if ((intr = die_base_name_parse(tdp->t_name, &new)) != NULL) { /* Found it. We'll use the parsed version */ - debug(3, "die %llu: name \"%s\" remapped to \"%s\"\n", off, - tdesc_name(tdp), new); + debug(3, "die %ju: name \"%s\" remapped to \"%s\"\n", + (uintmax_t)off, tdesc_name(tdp), new); free(tdp->t_name); tdp->t_name = new; @@ -1471,8 +1550,8 @@ * We didn't recognize the type, so we'll create an intr_t * based on the DWARF data. */ - debug(3, "die %llu: using dwarf data for base \"%s\"\n", off, - tdesc_name(tdp)); + debug(3, "die %ju: using dwarf data for base \"%s\"\n", + (uintmax_t)off, tdesc_name(tdp)); intr = die_base_from_dwarf(dw, base, off, sz); } @@ -1492,7 +1571,8 @@ { Dwarf_Attribute attr; - debug(3, "die %llu <%llx>: creating %s type %d\n", off, off, typename, type); + debug(3, "die %ju <0x%jx>: creating %s type %d\n", (uintmax_t)off, + (uintmax_t)off, typename, type); tdp->t_type = type; @@ -1502,7 +1582,7 @@ tdp->t_tdesc = tdesc_intr_void(dw); } - if (type == POINTER) + if (type == POINTER || type == REFERENCE) tdp->t_size = dw->dw_ptrsz; tdp->t_flags |= TDESC_F_RESOLVED; @@ -1536,6 +1616,12 @@ } static void +die_reference_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp) +{ + die_through_create(dw, die, off, tdp, REFERENCE, "reference"); +} + +static void die_restrict_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp) { die_through_create(dw, die, off, tdp, RESTRICT, "restrict"); @@ -1556,7 +1642,8 @@ iidesc_t *ii; char *name; - debug(3, "die %llu <%llx>: creating function definition\n", off, off); + debug(3, "die %ju <0x%jx>: creating function definition\n", + (uintmax_t)off, (uintmax_t)off); /* * We'll begin by processing any type definition nodes that may be @@ -1585,7 +1672,7 @@ if (ii->ii_type == II_SFUN) ii->ii_owner = xstrdup(dw->dw_cuname); - debug(3, "die %llu: function %s is %s\n", off, ii->ii_name, + debug(3, "die %ju: function %s is %s\n", (uintmax_t)off, ii->ii_name, (ii->ii_type == II_GFUN ? "global" : "static")); if (die_attr(dw, die, DW_AT_type, 0) != NULL) @@ -1597,15 +1684,15 @@ arg = die_sibling(dw, arg)) { char *name1; - debug(3, "die %llu: looking at sub member at %llu\n", - off, die_off(dw, die)); + debug(3, "die %ju: looking at sub member at %ju\n", + (uintmax_t)off, (uintmax_t)die_off(dw, die)); if (die_tag(dw, arg) != DW_TAG_formal_parameter) continue; if ((name1 = die_name(dw, arg)) == NULL) { - terminate("die %llu: func arg %d has no name\n", - off, ii->ii_nargs + 1); + terminate("die %ju: func arg %d has no name\n", + (uintmax_t)off, ii->ii_nargs + 1); } if (strcmp(name1, "...") == 0) { @@ -1620,8 +1707,8 @@ if (ii->ii_nargs > 0) { int i; - debug(3, "die %llu: function has %d argument%s\n", off, - ii->ii_nargs, (ii->ii_nargs == 1 ? "" : "s")); + debug(3, "die %ju: function has %d argument%s\n", + (uintmax_t)off, ii->ii_nargs, ii->ii_nargs == 1 ? "" : "s"); ii->ii_args = xcalloc(sizeof (tdesc_t) * ii->ii_nargs); @@ -1646,7 +1733,7 @@ iidesc_t *ii; char *name; - debug(3, "die %llu: creating object definition\n", off); + debug(3, "die %ju: creating object definition\n", (uintmax_t)off); if (die_isdecl(dw, die) || (name = die_name(dw, die)) == NULL) return; /* skip prototypes and nameless objects */ @@ -1709,10 +1796,12 @@ { DW_TAG_enumeration_type, 0, die_enum_create }, { DW_TAG_lexical_block, DW_F_NOTDP, die_lexblk_descend }, { DW_TAG_pointer_type, 0, die_pointer_create }, + { DW_TAG_reference_type, 0, die_reference_create }, { DW_TAG_structure_type, 0, die_struct_create }, { DW_TAG_subroutine_type, 0, die_funcptr_create }, { DW_TAG_typedef, 0, die_typedef_create }, { DW_TAG_union_type, 0, die_union_create }, + { DW_TAG_class_type, 0, die_class_create }, { DW_TAG_base_type, 0, die_base_create }, { DW_TAG_const_type, 0, die_const_create }, { DW_TAG_subprogram, DW_F_NOTDP, die_function_create }, @@ -1743,17 +1832,19 @@ Dwarf_Half tag; tdesc_t *tdp; - debug(3, "die %llu <%llx>: create_one\n", off, off); + debug(3, "die %ju <0x%jx>: create_one\n", (uintmax_t)off, + (uintmax_t)off); if (off > dw->dw_maxoff) { - terminate("illegal die offset %llu (max %llu)\n", off, + terminate("illegal die offset %ju (max %ju)\n", (uintmax_t)off, dw->dw_maxoff); } tag = die_tag(dw, die); if ((dc = die_tag2ctor(tag)) == NULL) { - debug(2, "die %llu: ignoring tag type %x\n", off, tag); + debug(2, "die %ju: ignoring tag type %x\n", (uintmax_t)off, + tag); return; } @@ -1782,10 +1873,12 @@ NULL, NULL, /* intrinsic */ NULL, /* pointer */ + NULL, /* reference */ die_array_resolve, /* array */ NULL, /* function */ die_sou_resolve, /* struct */ die_sou_resolve, /* union */ + die_sou_resolve, /* class */ die_enum_resolve, /* enum */ die_fwd_resolve, /* forward */ NULL, /* typedef */ @@ -1799,10 +1892,12 @@ NULL, NULL, /* intrinsic */ NULL, /* pointer */ + NULL, /* reference */ die_array_failed, /* array */ NULL, /* function */ die_sou_failed, /* struct */ die_sou_failed, /* union */ + die_sou_failed, /* class */ NULL, /* enum */ NULL, /* forward */ NULL, /* typedef */ @@ -1900,7 +1995,8 @@ int dw_read(tdata_t *td, Elf *elf, char *filename __unused) { - Dwarf_Unsigned abboff, hdrlen, nxthdr; + Dwarf_Unsigned hdrlen, nxthdr; + Dwarf_Off abboff; Dwarf_Half vers, addrsz, offsz; Dwarf_Die cu = 0; Dwarf_Die child = 0; @@ -1920,6 +2016,14 @@ if ((rc = dwarf_elf_init(elf, DW_DLC_READ, NULL, NULL, &dw.dw_dw, &dw.dw_err)) == DW_DLV_NO_ENTRY) { + /* The new library does that */ + if (dwarf_errno(dw.dw_err) == DW_DLE_DEBUG_INFO_NULL) { + /* + * There's no type data in the DWARF section, but + * libdwarf is too clever to handle that properly. + */ + return (0); + } if (should_have_dwarf(elf)) { errno = ENOENT; return (-1); @@ -1940,18 +2044,39 @@ } if ((rc = dwarf_next_cu_header_b(dw.dw_dw, &hdrlen, &vers, &abboff, - &addrsz, &offsz, NULL, &nxthdr, &dw.dw_err)) != DW_DLV_OK) + &addrsz, &offsz, NULL, &nxthdr, &dw.dw_err)) != DW_DLV_OK) { + if (dwarf_errno(dw.dw_err) == DW_DLE_NO_ENTRY) { + /* + * There's no DWARF section... + */ + return (0); + } terminate("rc = %d %s\n", rc, dwarf_errmsg(dw.dw_err)); + } - if ((cu = die_sibling(&dw, NULL)) == NULL || - (((child = die_child(&dw, cu)) == NULL) && - should_have_dwarf(elf))) { - terminate("file does not contain dwarf type data " - "(try compiling with -g)\n"); - } else if (child == NULL) { - return (0); + if ((cu = die_sibling(&dw, NULL)) == NULL) + goto out; + + if ((child = die_child(&dw, cu)) == NULL) { + Dwarf_Unsigned lang; + if (die_unsigned(&dw, cu, DW_AT_language, &lang, 0)) { + debug(1, "DWARF language: %ju\n", (uintmax_t)lang); + /* + * Assembly languages are typically that. + * They have some dwarf info, but not what + * we expect. They have local symbols for + * example, but they are missing the child info. + */ + if (lang >= DW_LANG_lo_user) + return 0; + } + if (should_have_dwarf(elf)) + goto out; } + if (child == NULL) + return (0); + dw.dw_maxoff = nxthdr - 1; if (dw.dw_maxoff > TID_FILEMAX) @@ -1992,4 +2117,8 @@ /* leak the dwarf_t */ return (0); +out: + terminate("file does not contain dwarf type data " + "(try compiling with -g)\n"); + return -1; } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/fixup_tdescs.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/fixup_tdescs.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/fixup_tdescs.c 2012-06-11 22:55:16.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/fixup_tdescs.c 2010-02-24 13:53:26.000000000 -0800 @@ -30,6 +30,10 @@ * fixups. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c 2012-06-11 22:55:16.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/iidesc.c 2010-02-24 13:53:26.000000000 -0800 @@ -29,6 +29,10 @@ * Routines for manipulating iidesc_t structures */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/input.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/input.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/input.c 2013-04-20 09:00:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/input.c 2014-03-09 10:04:00.000000000 -0700 @@ -29,6 +29,10 @@ * Routines for retrieving CTF data from a .SUNW_ctf ELF section */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/merge.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/merge.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/merge.c 2016-10-10 04:14:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/merge.c 2017-04-13 12:51:37.000000000 -0700 @@ -111,6 +111,10 @@ * this comment. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -530,10 +534,12 @@ NULL, map_td_tree_pre, /* intrinsic */ map_td_tree_pre, /* pointer */ + map_td_tree_pre, /* reference */ map_td_tree_pre, /* array */ map_td_tree_pre, /* function */ map_td_tree_pre, /* struct */ map_td_tree_pre, /* union */ + map_td_tree_pre, /* class */ map_td_tree_pre, /* enum */ map_td_tree_pre, /* forward */ map_td_tree_pre, /* typedef */ @@ -547,10 +553,12 @@ NULL, map_td_tree_post, /* intrinsic */ map_td_tree_post, /* pointer */ + map_td_tree_post, /* reference */ map_td_tree_post, /* array */ map_td_tree_post, /* function */ map_td_tree_post, /* struct */ map_td_tree_post, /* union */ + map_td_tree_post, /* class */ map_td_tree_post, /* enum */ map_td_tree_post, /* forward */ map_td_tree_post, /* typedef */ @@ -564,10 +572,12 @@ NULL, map_td_tree_self_post, /* intrinsic */ map_td_tree_self_post, /* pointer */ + map_td_tree_self_post, /* reference */ map_td_tree_self_post, /* array */ map_td_tree_self_post, /* function */ map_td_tree_self_post, /* struct */ map_td_tree_self_post, /* union */ + map_td_tree_self_post, /* class */ map_td_tree_self_post, /* enum */ map_td_tree_self_post, /* forward */ map_td_tree_self_post, /* typedef */ @@ -689,7 +699,8 @@ } if ((template.t_id = get_mapping(mcd->md_ta, oldid)) == 0) - aborterr("failed to get mapping for tid %d <%x>\n", oldid, oldid); + aborterr("failed to get mapping for tid %d (%s) <%x>\n", oldid, + oldtgt->t_name, oldid); if (!hash_find(mcd->md_parent->td_idhash, (void *)&template, (void *)&tgt) && (!(mcd->md_flags & MCD_F_REFMERGE) || @@ -879,10 +890,12 @@ NULL, NULL, /* intrinsic */ NULL, /* pointer */ + NULL, /* reference */ NULL, /* array */ NULL, /* function */ NULL, /* struct */ NULL, /* union */ + NULL, /* class */ NULL, /* enum */ fwd_redir, /* forward */ NULL, /* typedef */ @@ -1120,10 +1133,12 @@ { "ERROR! BAD tdesc TYPE", NULL, NULL }, { "intrinsic", equiv_intrinsic, conjure_intrinsic }, { "pointer", equiv_plain, conjure_plain }, + { "reference", equiv_plain, conjure_plain }, { "array", equiv_array, conjure_array }, { "function", equiv_function, conjure_function }, { "struct", equiv_su, conjure_su }, { "union", equiv_su, conjure_su }, + { "class", equiv_su, conjure_su }, { "enum", equiv_enum, conjure_enum }, { "forward", NULL, conjure_forward }, { "typedef", equiv_plain, conjure_plain }, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/output.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/output.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/output.c 2015-03-18 07:20:40.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/output.c 2017-04-22 13:40:20.000000000 -0700 @@ -28,6 +28,10 @@ * for placing the resulting data into an output file. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -98,10 +102,12 @@ NULL, save_type_by_id, /* intrinsic */ save_type_by_id, /* pointer */ + save_type_by_id, /* reference */ save_type_by_id, /* array */ save_type_by_id, /* function */ save_type_by_id, /* struct */ save_type_by_id, /* union */ + save_type_by_id, /* class */ save_type_by_id, /* enum */ save_type_by_id, /* forward */ save_type_by_id, /* typedef */ @@ -749,7 +755,7 @@ elfterminate(curname, "Cannot write"); if (gelf_getehdr(elf, &ehdr)) { -#if BYTE_ORDER == _BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN byteorder = ELFDATA2MSB; #else byteorder = ELFDATA2LSB; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/st_parse.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/st_parse.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/st_parse.c 2016-12-18 18:09:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/st_parse.c 2017-04-13 12:53:16.000000000 -0700 @@ -26,6 +26,10 @@ * This file is a sewer. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -76,7 +80,7 @@ int debug_parse = DEBUG_PARSE; /*PRINTFLIKE3*/ -static void +static void __printflike(3, 4) parse_debug(int level, char *cp, const char *fmt, ...) { va_list ap; @@ -91,7 +95,7 @@ for (i = 0; i < 30; i++) { if (cp[i] == '\0') break; - if (!iscntrl(cp[i])) + if (!iscntrl((unsigned char)cp[i])) tmp[i] = cp[i]; } tmp[i] = '\0'; @@ -399,7 +403,7 @@ } int -parse_stab(stab_t *stab, char *cp, iidesc_t **iidescp) +parse_stab(stab_t *stab, char * volatile cp, iidesc_t **iidescp) { iidesc_t *ii = NULL; iitype_t (*parse)(char *, iidesc_t *); @@ -478,7 +482,7 @@ { char c; - for (c = *cp++; isspace(c); c = *cp++) + for (c = *cp++; isspace((unsigned char)c); c = *cp++) ; --cp; return (cp); @@ -494,8 +498,8 @@ c = *cp++; if (c == ':') *w = NULL; - else if (isalpha(c) || strchr("_.$#", c)) { - for (c = *cp++; isalnum(c) || strchr(" _.$#", c); c = *cp++) + else if (isalpha((unsigned char)c) || strchr("_.$#", c)) { + for (c = *cp++; isalnum((unsigned char)c) || strchr(" _.$#", c); c = *cp++) ; if (c != ':') reset(); @@ -536,7 +540,7 @@ if (*cp++ != ')') expected("id", ")", cp - 1); *h = MAKETYPEID(n1, n2); - } else if (isdigit(*cp)) { /* gcc style */ + } else if (isdigit((unsigned char)*cp)) { /* gcc style */ cp = number(cp, &n1); *h = n1; } else { @@ -801,7 +805,7 @@ case 'R': intr->intr_type = INTR_REAL; - for (fmt = 0, i = 0; isdigit(*(cp + i)); i++) + for (fmt = 0, i = 0; isdigit((unsigned char)*(cp + i)); i++) fmt = fmt * 10 + (*(cp + i) - '0'); if (fmt < 1 || fmt > CTF_FP_MAX) @@ -1121,7 +1125,7 @@ return (HASH(sum)); } -static void +static void __dead reset(void) { longjmp(resetbuf, 1); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/stabs.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/stabs.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/stabs.c 2012-06-11 22:55:16.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/stabs.c 2017-04-13 12:54:32.000000000 -0700 @@ -30,6 +30,10 @@ * based on the interesting parts of that data. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c 2015-02-03 23:20:42.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c 2017-04-13 12:55:09.000000000 -0700 @@ -27,6 +27,10 @@ * Routines for manipulating tdesc and tdata structures */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -232,19 +236,21 @@ static void (*free_cbs[])(tdesc_t *) = { NULL, - free_intr, - NULL, - free_ardef, - NULL, - free_mlist, - free_mlist, - free_elist, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL + free_intr, /* intrinsic */ + NULL, /* pointer */ + NULL, /* reference */ + free_ardef, /* array */ + NULL, /* function */ + free_mlist, /* struct */ + free_mlist, /* union */ + free_mlist, /* class */ + free_elist, /* enum */ + NULL, /* forward */ + NULL, /* typedef */ + NULL, /* typedef_unres */ + NULL, /* volatile */ + NULL, /* const */ + NULL /* restrict */ }; /*ARGSUSED1*/ @@ -429,10 +435,12 @@ NULL, build_hashes, /* intrinsic */ build_hashes, /* pointer */ + build_hashes, /* reference */ build_hashes, /* array */ build_hashes, /* function */ build_hashes, /* struct */ build_hashes, /* union */ + build_hashes, /* class */ build_hashes, /* enum */ build_hashes, /* forward */ build_hashes, /* typedef */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/traverse.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/traverse.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/traverse.c 2013-04-20 09:00:31.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/traverse.c 2016-03-26 14:06:19.000000000 -0700 @@ -30,6 +30,10 @@ * as the tree is traversed. */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include @@ -115,10 +119,12 @@ NULL, NULL, /* intrinsic */ NULL, /* pointer */ + NULL, /* reference */ NULL, /* array */ NULL, /* function */ NULL, /* struct */ NULL, /* union */ + NULL, /* class */ NULL, /* enum */ NULL, /* forward */ NULL, /* typedef */ @@ -132,10 +138,12 @@ NULL, NULL, /* intrinsic */ tdtrav_plain, /* pointer */ + tdtrav_plain, /* reference */ tdtrav_array, /* array */ tdtrav_func, /* function */ tdtrav_su, /* struct */ tdtrav_su, /* union */ + tdtrav_su, /* class */ NULL, /* enum */ NULL, /* forward */ tdtrav_plain, /* typedef */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/util.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/util.c --- /tmp/out/external/cddl/osnet/dist/tools/ctf/cvt/util.c 2015-02-03 23:20:42.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/tools/ctf/cvt/util.c 2017-04-13 12:55:46.000000000 -0700 @@ -29,6 +29,10 @@ * Utility functions */ +#if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +#endif + #include #include #include @@ -75,14 +79,14 @@ if (gelf_getshdr(scn, &shdr) == NULL) { elfterminate(file, - "Couldn't read header for section %d", + "Couldn't read header for section %zu", elf_ndxscn(scn)); } if ((name = elf_strptr(elf, ehdr.e_shstrndx, (size_t)shdr.sh_name)) == NULL) { elfterminate(file, - "Couldn't get name for section %d", + "Couldn't get name for section %zu", elf_ndxscn(scn)); } Only in /tmp/out/external/cddl/osnet/dist/uts: aarch64 Only in /tmp/out/external/cddl/osnet/dist/uts/arm: dtrace diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c --- /tmp/out/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c 2017-03-02 02:54:24.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c 2017-06-11 04:48:36.000000000 -0700 @@ -66,6 +66,12 @@ * [Group] Functions", allowing one to find each block by searching forward * on capital-f functions. */ +#ifdef __NetBSD__ +#define __MUTEX_PRIVATE +#define __RWLOCK_PRIVATE +#include +#endif + #include #ifndef illumos #include @@ -112,7 +118,7 @@ #include "strtolctype.h" /* FreeBSD includes: */ -#ifndef illumos +#ifdef __FreeBSD__ #include #include #include @@ -128,16 +134,51 @@ #include #include #include +#endif + +#ifdef __NetBSD__ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#ifndef illumos #include +#include "dtrace_xoroshiro128_plus.h" + #include #include "dtrace_cddl.h" #include "dtrace_debug.c" -#endif -#include "dtrace_xoroshiro128_plus.h" +#ifdef __NetBSD__ +struct dtrace_state_worker *dtrace_state_worker_add(void (*fn)(dtrace_state_t *), + dtrace_state_t *state, hrtime_t interval); +void dtrace_state_worker_remove(struct dtrace_state_worker *w); + +modctl_t *mod_nbsd; + +#endif /* __NetBSD__ */ + +#endif /* !illumos */ + /* * DTrace Tunable Variables @@ -222,8 +263,12 @@ static vmem_t *dtrace_minor; /* minor number arena */ #else static taskq_t *dtrace_taskq; /* task queue */ +#ifdef __NetBSD__ +static vmem_t *dtrace_arena; /* probe ID arena */ +#else static struct unrhdr *dtrace_arena; /* Probe ID number. */ #endif +#endif static dtrace_probe_t **dtrace_probes; /* array of all probes */ static int dtrace_nprobes; /* number of probes */ static dtrace_provider_t *dtrace_provider; /* provider list */ @@ -251,7 +296,7 @@ static dtrace_genid_t dtrace_retained_gen; /* current retained enab gen */ static dtrace_dynvar_t dtrace_dynhash_sink; /* end of dynamic hash chains */ static int dtrace_dynvar_failclean; /* dynvars failed to clean */ -#ifndef illumos +#ifdef __FreeBSD__ static struct mtx dtrace_unr_mtx; MTX_SYSINIT(dtrace_unr_mtx, &dtrace_unr_mtx, "Unique resource identifier", MTX_DEF); static eventhandler_tag dtrace_kld_load_tag; @@ -294,12 +339,20 @@ #ifndef illumos /* XXX FreeBSD hacks. */ +#ifdef __FreeBSD__ +static kmutex_t mod_lock; +#endif + #define cr_suid cr_svuid #define cr_sgid cr_svgid #define ipaddr_t in_addr_t #define mod_modname pathname #define vuprintf vprintf +#ifdef __NetBSD__ +#define ttoproc(_a) ((_a)->l_proc) +#else #define ttoproc(_a) ((_a)->td_proc) +#endif #define crgetzoneid(_a) 0 #define SNOCD 0 #define CPU_ON_INTR(_a) 0 @@ -312,12 +365,19 @@ #define PRIV_PROC_ZONE (1 << 5) #define PRIV_ALL ~0 +SYSCTL_NODE(_debug, OID_AUTO, dtrace, CTLFLAG_RD, 0, "DTrace Information"); SYSCTL_DECL(_debug_dtrace); SYSCTL_DECL(_kern_dtrace); #endif #ifdef illumos -#define curcpu CPU->cpu_id +#define curcpu_id CPU->cpu_id +#endif +#ifdef __FreeBSD__ +#define curcpu_id curcpu +#endif +#ifdef __NetBSD__ +#define curcpu_id cpu_number() #endif @@ -341,8 +401,8 @@ static dtrace_pops_t dtrace_provider_ops = { (void (*)(void *, dtrace_probedesc_t *))dtrace_nullop, - (void (*)(void *, modctl_t *))dtrace_nullop, - (void (*)(void *, dtrace_id_t, void *))dtrace_nullop, + (void (*)(void *, modctl_t *))dtrace_nullop, + (int (*)(void *, dtrace_id_t, void *))dtrace_nullop, (void (*)(void *, dtrace_id_t, void *))dtrace_nullop, (void (*)(void *, dtrace_id_t, void *))dtrace_nullop, (void (*)(void *, dtrace_id_t, void *))dtrace_nullop, @@ -441,7 +501,8 @@ (where) = ((curthread->t_did + DIF_VARIABLE_MAX) & \ (((uint64_t)1 << 61) - 1)) | ((uint64_t)intr << 61); \ } -#else +#endif +#ifdef __FreeBSD__ #define DTRACE_TLS_THRKEY(where) { \ solaris_cpu_t *_c = &solaris_cpu[curcpu]; \ uint_t intr = 0; \ @@ -453,6 +514,14 @@ (((uint64_t)1 << 61) - 1)) | ((uint64_t)intr << 61); \ } #endif +#ifdef __NetBSD__ +#define DTRACE_TLS_THRKEY(where) { \ + uint_t intr = 0; \ + (where) = ((curthread->l_lid + (curthread->l_proc->p_pid << 16) + \ + DIF_VARIABLE_MAX) & \ + (((uint64_t)1 << 61) - 1)) | ((uint64_t)intr << 61); \ +} +#endif #define DT_BSWAP_8(x) ((x) & 0xff) #define DT_BSWAP_16(x) ((DT_BSWAP_8(x) << 8) | DT_BSWAP_8((x) >> 8)) @@ -468,7 +537,7 @@ #define DTRACE_ALIGNCHECK(addr, size, flags) \ if (addr & (size - 1)) { \ *flags |= CPU_DTRACE_BADALIGN; \ - cpu_core[curcpu].cpuc_dtrace_illval = addr; \ + cpu_core[curcpu_id].cpuc_dtrace_illval = addr; \ return (0); \ } #else @@ -515,7 +584,7 @@ uint##bits##_t rval; \ int i; \ volatile uint16_t *flags = (volatile uint16_t *) \ - &cpu_core[curcpu].cpuc_dtrace_flags; \ + &cpu_core[curcpu_id].cpuc_dtrace_flags; \ \ DTRACE_ALIGNCHECK(addr, size, flags); \ \ @@ -530,7 +599,7 @@ * This address falls within a toxic region; return 0. \ */ \ *flags |= CPU_DTRACE_BADADDR; \ - cpu_core[curcpu].cpuc_dtrace_illval = addr; \ + cpu_core[curcpu_id].cpuc_dtrace_illval = addr; \ return (0); \ } \ \ @@ -552,6 +621,7 @@ #define DTRACE_DYNHASH_SINK 1 #define DTRACE_DYNHASH_VALID 2 +#define DTRACE_MATCH_FAIL -1 #define DTRACE_MATCH_NEXT 0 #define DTRACE_MATCH_DONE 1 #define DTRACE_ANCHORED(probe) ((probe)->dtpr_func[0] != '\0') @@ -630,7 +700,7 @@ va_list alist; va_start(alist, format); -#ifdef __FreeBSD__ +#ifndef illumos vpanic(format, alist); #else dtrace_vpanic(format, alist); @@ -794,7 +864,7 @@ * up both thread-local variables and any global dynamically-allocated * variables. */ - if (DTRACE_INRANGE(addr, sz, vstate->dtvs_dynvars.dtds_base, + if (DTRACE_INRANGE(addr, sz, (uintptr_t)vstate->dtvs_dynvars.dtds_base, vstate->dtvs_dynvars.dtds_size)) { dtrace_dstate_t *dstate = &vstate->dtvs_dynvars; uintptr_t base = (uintptr_t)dstate->dtds_base + @@ -884,7 +954,7 @@ dtrace_canload_remains(uint64_t addr, size_t sz, size_t *remain, dtrace_mstate_t *mstate, dtrace_vstate_t *vstate) { - volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval; + volatile uintptr_t *illval = &cpu_core[curcpu_id].cpuc_dtrace_illval; file_t *fp; /* @@ -946,12 +1016,14 @@ return (1); } +#ifndef __NetBSD__ if (curthread->t_cred != NULL && DTRACE_INRANGE(addr, sz, curthread->t_cred, sizeof (cred_t))) { DTRACE_RANGE_REMAIN(remain, addr, curthread->t_cred, sizeof (cred_t)); return (1); } +#endif #ifdef illumos if (p != NULL && p->p_pidp != NULL && DTRACE_INRANGE(addr, sz, @@ -1054,6 +1126,7 @@ * If we hold the privilege to read from kernel memory, then * everything is readable. */ + if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) != 0) { DTRACE_RANGE_REMAIN(remain, addr, addr, sz); return (1); @@ -1198,7 +1271,7 @@ if (s1 == s2 || limit == 0) return (0); - flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu_id].cpuc_dtrace_flags; do { if (s1 == NULL) { @@ -1252,13 +1325,13 @@ if (kaddr - taddr < tsize) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = kaddr; + cpu_core[curcpu_id].cpuc_dtrace_illval = kaddr; return (1); } if (taddr - kaddr < size) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = taddr; + cpu_core[curcpu_id].cpuc_dtrace_illval = taddr; return (1); } } @@ -1342,7 +1415,7 @@ { volatile uint16_t *flags; - flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu_id].cpuc_dtrace_flags; if (s1 == s2) return (0); @@ -1478,6 +1551,23 @@ */ ASSERT(s_cr != NULL); +#ifdef __NetBSD__ + if ((cr = CRED()) != NULL) { + uid_t uid; + gid_t gid; + + uid = kauth_cred_getuid(s_cr); + gid = kauth_cred_getgid(s_cr); + + if (uid == kauth_cred_getuid(cr) && + uid == kauth_cred_geteuid(cr) && + uid == kauth_cred_getsvuid(cr) && + gid == kauth_cred_getgid(cr) && + gid == kauth_cred_getegid(cr) && + gid == kauth_cred_getsvgid(cr)) + return 1; + } +#else if ((cr = CRED()) != NULL && s_cr->cr_uid == cr->cr_uid && s_cr->cr_uid == cr->cr_ruid && @@ -1486,6 +1576,7 @@ s_cr->cr_gid == cr->cr_rgid && s_cr->cr_gid == cr->cr_sgid) return (1); +#endif return (0); } @@ -1508,6 +1599,7 @@ ASSERT(s_cr != NULL); if ((cr = CRED()) != NULL && s_cr->cr_zone == cr->cr_zone) + s_cr->cr_zone == cr->cr_zone) return (1); return (0); @@ -1552,7 +1644,7 @@ return (1); bad: - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -1568,7 +1660,7 @@ dtrace_priv_proc_common_nocd()) return (1); - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -1579,7 +1671,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_PROC) return (1); - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV; return (0); } @@ -1590,7 +1682,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL) return (1); - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; return (0); } @@ -1601,7 +1693,7 @@ if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL_DESTRUCTIVE) return (1); - cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; + cpu_core[curcpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV; return (0); } @@ -1670,6 +1762,23 @@ ASSERT(s_cr != NULL); +#ifdef __NetBSD__ + uid_t uid = kauth_cred_getuid(s_cr); + gid_t gid = kauth_cred_getgid(s_cr); + + if ((cr = CRED()) == NULL || + uid != kauth_cred_geteuid(cr) || + uid != kauth_cred_getuid(cr) || + uid != kauth_cred_getsvuid(cr) || + gid != kauth_cred_getegid(cr) || + gid != kauth_cred_getgid(cr) || + gid != kauth_cred_getsvgid(cr) || + (proc = ttoproc(curthread)) == NULL || + (proc->p_flag & SNOCD)) { + if (mode & DTRACE_MODE_NOPRIV_DROP) + return (0); + } +#else /* __NetBSD__ */ if ((cr = CRED()) == NULL || s_cr->cr_uid != cr->cr_uid || s_cr->cr_uid != cr->cr_ruid || @@ -1686,6 +1795,7 @@ mstate->dtms_access &= ~DTRACE_ACCESS_PROC; #endif } +#endif /* __NetBSD__ */ } #ifdef illumos @@ -1731,6 +1841,7 @@ for (i = 0; i < NCPU; i++) { dcpu = &dstate->dtds_percpu[i]; + rinsep = &dcpu->dtdsc_rinsing; /* @@ -1869,7 +1980,7 @@ uint64_t hashval = DTRACE_DYNHASH_VALID; dtrace_dynhash_t *hash = dstate->dtds_hash; dtrace_dynvar_t *free, *new_free, *next, *dvar, *start, *prev = NULL; - processorid_t me = curcpu, cpu = me; + processorid_t me = curcpu_id, cpu = me; dtrace_dstate_percpu_t *dcpu = &dstate->dtds_percpu[me]; size_t bucket, ksize; size_t chunksize = dstate->dtds_chunksize; @@ -2219,7 +2330,7 @@ /* * The clean list appears to be non-empty. We want to - * move the clean list to the free list; we start by + * move the clean list to our free list; we start by * moving the clean pointer aside. */ if (dtrace_casptr(&dcpu->dtdsc_clean, @@ -2242,7 +2353,7 @@ ASSERT(clean->dtdv_hashval == DTRACE_DYNHASH_FREE); /* - * Now we'll move the clean list to our free list. + * Now we'll move the clean list to the free list. * It's impossible for this to fail: the only way * the free list can be updated is through this * code path, and only one CPU can own the clean list. @@ -3052,7 +3163,7 @@ dtrace_speculation_clean_here(dtrace_state_t *state) { dtrace_icookie_t cookie; - processorid_t cpu = curcpu; + processorid_t cpu = curcpu_id; dtrace_buffer_t *dest = &state->dts_buffer[cpu]; dtrace_specid_t i; @@ -3357,14 +3468,15 @@ if ((lwp = curthread->t_lwp) == NULL) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = NULL; + cpu_core[curcpu_id].cpuc_dtrace_illval = NULL; return (0); } return (dtrace_getreg(lwp->lwp_regs, ndx)); return (0); } -#else +#endif +#ifdef __FreeBSD__ case DIF_VAR_UREGS: { struct trapframe *tframe; @@ -3380,6 +3492,22 @@ return (dtrace_getreg(tframe, ndx)); } #endif +#ifdef __NetBSD__ + case DIF_VAR_UREGS: { + struct trapframe *tframe; + + if (!dtrace_priv_proc(state)) + return (0); + + if ((tframe = lwp_trapframe(curlwp)) == NULL) { + DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); + cpu_core[curcpu_id].cpuc_dtrace_illval = 0; + return (0); + } + + return (dtrace_getreg(tframe, ndx)); + } +#endif case DIF_VAR_CURTHREAD: if (!dtrace_priv_proc(state)) @@ -3600,6 +3728,7 @@ return ((uint64_t)curthread->t_tid); case DIF_VAR_EXECARGS: { +#ifdef __FreeBSD__ struct pargs *p_args = curthread->td_proc->p_args; if (p_args == NULL) @@ -3607,6 +3736,9 @@ return (dtrace_dif_varstrz( (uintptr_t) p_args->ar_args, p_args->ar_length, state, mstate)); +#else + return 0; +#endif } case DIF_VAR_EXECNAME: @@ -3631,7 +3763,7 @@ state, mstate)); #else return (dtrace_dif_varstr( - (uintptr_t) curthread->td_proc->p_comm, state, mstate)); + (uintptr_t) curproc->p_comm, state, mstate)); #endif case DIF_VAR_ZONENAME: @@ -3679,9 +3811,13 @@ * credential, since this is never NULL after process birth. */ return ((uint64_t)curthread->t_procp->p_cred->cr_uid); -#else +#endif +#ifdef __FreeBSD__ return ((uint64_t)curthread->td_ucred->cr_uid); #endif +#ifdef __NetBSD__ + return ((uint64_t)kauth_cred_getuid(curthread->t_procp->p_cred)); +#endif case DIF_VAR_GID: if (!dtrace_priv_proc(state)) @@ -3704,9 +3840,13 @@ * credential, since this is never NULL after process birth. */ return ((uint64_t)curthread->t_procp->p_cred->cr_gid); -#else +#endif +#ifdef __FreeBSD__ return ((uint64_t)curthread->td_ucred->cr_gid); #endif +#ifdef __NetBSD__ + return ((uint64_t)kauth_cred_getgid(curthread->t_procp->p_cred)); +#endif case DIF_VAR_ERRNO: { #ifdef illumos @@ -3730,13 +3870,17 @@ return (0); return ((uint64_t)lwp->lwp_errno); -#else +#endif +#ifdef __FreeBSD__ return (curthread->td_errno); #endif +#ifdef __NetBSD__ + return 0; /* XXX TBD errno support at lwp level? */ +#endif } #ifndef illumos case DIF_VAR_CPU: { - return curcpu; + return curcpu_id; } #endif default: @@ -4214,8 +4358,8 @@ dtrace_key_t *tupregs, int nargs, dtrace_mstate_t *mstate, dtrace_state_t *state) { - volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; - volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval; + volatile uint16_t *flags = &cpu_core[curcpu_id].cpuc_dtrace_flags; + volatile uintptr_t *illval = &cpu_core[curcpu_id].cpuc_dtrace_illval; dtrace_vstate_t *vstate = &state->dts_vstate; #ifdef illumos @@ -4228,18 +4372,30 @@ krwlock_t ri; uintptr_t rw; } r; -#else +#endif +#ifdef __FreeBSD__ struct thread *lowner; union { struct lock_object *li; uintptr_t lx; } l; #endif +#ifdef __NetBSD__ + union { + kmutex_t mi; + uint64_t mx; + } m; + + union { + krwlock_t ri; + uintptr_t rw; + } r; +#endif switch (subr) { case DIF_SUBR_RAND: regs[rd] = dtrace_xoroshiro128_plus_next( - state->dts_rstate[curcpu]); + state->dts_rstate[curcpu_id]); break; #ifdef illumos @@ -4330,7 +4486,8 @@ regs[rd] = _RW_ISWRITER(&r.ri); break; -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ case DIF_SUBR_MUTEX_OWNED: if (!dtrace_canload(tupregs[0].dttk_value, sizeof (struct lock_object), mstate, vstate)) { @@ -4421,7 +4578,95 @@ DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); regs[rd] = (lowner == curthread); break; -#endif /* illumos */ + +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + case DIF_SUBR_MUTEX_OWNED: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + m.mx = dtrace_load64(tupregs[0].dttk_value); + if (MUTEX_TYPE_ADAPTIVE(&m.mi)) + regs[rd] = MUTEX_OWNER(&m.mi) != MUTEX_NO_OWNER; + else + regs[rd] = __SIMPLELOCK_LOCKED_P(&m.mi.mtx_lock); + break; + + case DIF_SUBR_MUTEX_OWNER: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + m.mx = dtrace_load64(tupregs[0].dttk_value); + if (MUTEX_TYPE_ADAPTIVE(&m.mi) && + MUTEX_OWNER(&m.mi) != MUTEX_NO_OWNER) + regs[rd] = (uintptr_t)MUTEX_OWNER(&m.mi); + else + regs[rd] = 0; + break; + + case DIF_SUBR_MUTEX_TYPE_ADAPTIVE: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + m.mx = dtrace_load64(tupregs[0].dttk_value); + regs[rd] = MUTEX_TYPE_ADAPTIVE(&m.mi); + break; + + case DIF_SUBR_MUTEX_TYPE_SPIN: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + m.mx = dtrace_load64(tupregs[0].dttk_value); + regs[rd] = MUTEX_TYPE_SPIN(&m.mi); + break; + + case DIF_SUBR_RW_READ_HELD: { + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (krwlock_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + r.rw = dtrace_loadptr(tupregs[0].dttk_value); + regs[rd] = _RW_READ_HELD(&r.ri); + break; + } + + case DIF_SUBR_RW_WRITE_HELD: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (krwlock_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + r.rw = dtrace_loadptr(tupregs[0].dttk_value); + regs[rd] = _RW_WRITE_HELD(&r.ri); + break; + + case DIF_SUBR_RW_ISWRITER: + if (!dtrace_canload(tupregs[0].dttk_value, sizeof (krwlock_t), + mstate, vstate)) { + regs[rd] = 0; + break; + } + + r.rw = dtrace_loadptr(tupregs[0].dttk_value); + regs[rd] = _RW_ISWRITER(&r.ri); + break; + +#endif /* __NetBSD__ */ case DIF_SUBR_BCOPY: { /* @@ -4626,8 +4871,7 @@ if (!dtrace_destructive_disallow && dtrace_priv_proc_control(state) && - !dtrace_istoxic(kaddr, size) && - dtrace_canload(kaddr, size, mstate, vstate)) { + !dtrace_istoxic(kaddr, size)) { DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); dtrace_copyout(kaddr, uaddr, size, flags); DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); @@ -5364,6 +5608,7 @@ regs[rd] = 0; break; } + c = (i >= lim1) ? '\0' : dtrace_load8(s1++); if ((d[i++] = c) == '\0') { i--; @@ -5632,15 +5877,19 @@ regs[rd] = 0; break; } +#ifdef __FreeBSD_ fdp = curproc->p_fd; FILEDESC_SLOCK(fdp); fp = fget_locked(fdp, fd); mstate->dtms_getf = fp; regs[rd] = (uintptr_t)fp; FILEDESC_SUNLOCK(fdp); +#endif +#ifdef __NetBSD__ + regs[rd] = 0; +#endif break; } - case DIF_SUBR_CLEANPATH: { char *dest = (char *)mstate->dtms_scratch_ptr, c; uint64_t size = state->dts_options[DTRACEOPT_STRSIZE]; @@ -6082,8 +6331,8 @@ dtrace_statvar_t *svar; dtrace_dstate_t *dstate = &vstate->dtvs_dynvars; dtrace_difv_t *v; - volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; - volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval; + volatile uint16_t *flags = &cpu_core[curcpu_id].cpuc_dtrace_flags; + volatile uintptr_t *illval = &cpu_core[curcpu_id].cpuc_dtrace_illval; dtrace_key_t tupregs[DIF_DTR_NREGS + 2]; /* +2 for thread and id */ uint64_t regs[DIF_DIR_NREGS]; @@ -6473,7 +6722,7 @@ sz += sizeof (uint64_t); ASSERT(svar->dtsv_size == NCPU * sz); - a += curcpu * sz; + a += curcpu_id * sz; if (*(uint8_t *)a == UINT8_MAX) { /* @@ -6491,7 +6740,7 @@ ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t)); tmp = (uint64_t *)(uintptr_t)svar->dtsv_data; - regs[rd] = tmp[curcpu]; + regs[rd] = tmp[curcpu_id]; break; case DIF_OP_STLS: @@ -6513,7 +6762,7 @@ sz += sizeof (uint64_t); ASSERT(svar->dtsv_size == NCPU * sz); - a += curcpu * sz; + a += curcpu_id * sz; if (regs[rd] == 0) { *(uint8_t *)a = UINT8_MAX; @@ -6535,7 +6784,7 @@ ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t)); tmp = (uint64_t *)(uintptr_t)svar->dtsv_data; - tmp[curcpu] = regs[rd]; + tmp[curcpu_id] = regs[rd]; break; case DIF_OP_LDTS: { @@ -6736,10 +6985,8 @@ if (DIF_INSTR_OP(instr) == DIF_OP_STTAA) { DTRACE_TLS_THRKEY(key[nkeys].dttk_value); key[nkeys++].dttk_size = 0; - VERIFY(id < vstate->dtvs_ntlocals); v = &vstate->dtvs_tlocals[id]; } else { - VERIFY(id < vstate->dtvs_nglobals); v = &vstate->dtvs_globals[id]->dtsv_var; } @@ -6874,8 +7121,8 @@ dtrace_probe_t *probe = ecb->dte_probe; dtrace_provider_t *prov = probe->dtpr_provider; char c[DTRACE_FULLNAMELEN + 80], *str; - char *msg = "dtrace: breakpoint action at probe "; - char *ecbmsg = " (ecb "; + const char *msg = "dtrace: breakpoint action at probe "; + const char *ecbmsg = " (ecb "; uintptr_t mask = (0xf << (sizeof (uintptr_t) * NBBY / 4)); uintptr_t val = (uintptr_t)ecb; int shift = (sizeof (uintptr_t) * NBBY) - 4, i = 0; @@ -6889,7 +7136,7 @@ ASSERT(probe != NULL); /* - * This is a poor man's (destitute man's?) sprintf(): we want to + * This is a poor man's (destitute man's?) snprintf(): we want to * print the provider name, module name, function name and name of * the probe, along with the hex address of the ECB with the breakpoint * action -- all of which we must place in the character buffer by @@ -6929,9 +7176,20 @@ #ifdef illumos debug_enter(c); -#else +#endif + +#ifdef __FreeBSD__ kdb_enter(KDB_WHY_DTRACE, "breakpoint action"); #endif + +#ifdef __NetBSD__ +#ifdef DDB + db_printf("%s\n", c); + Debugger(); +#else + printf("%s ignored\n", c); +#endif /* DDB */ +#endif } static void @@ -6984,12 +7242,20 @@ curthread->t_sig_check = 1; aston(curthread); -#else - struct proc *p = curproc; +#endif + +#ifdef __FreeBSD__ PROC_LOCK(p); kern_psignal(p, sig); PROC_UNLOCK(p); #endif + +#ifdef __NetBSD__ + struct proc *p = curproc; + mutex_enter(proc_lock); + psignal(p, sig); + mutex_exit(proc_lock); +#endif } static void @@ -7004,12 +7270,20 @@ curthread->t_sig_check = 1; aston(curthread); } -#else - struct proc *p = curproc; +#endif + +#ifdef __FreeBSD__ PROC_LOCK(p); kern_psignal(p, SIGSTOP); PROC_UNLOCK(p); #endif + +#ifdef __NetBSD__ + struct proc *p = curproc; + mutex_enter(proc_lock); + psignal(p, SIGSTOP); + mutex_exit(proc_lock); +#endif } static void @@ -7020,13 +7294,13 @@ #ifdef illumos cpu_t *cpu = CPU; #else - cpu_t *cpu = &solaris_cpu[curcpu]; + cpu_t *cpu = &solaris_cpu[curcpu_id]; #endif if (dtrace_destructive_disallow) return; - flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[cpu->cpu_id].cpuc_dtrace_flags; now = dtrace_gethrtime(); @@ -7072,7 +7346,7 @@ int size, offs = 0, i, j; size_t rem; uintptr_t old = mstate->dtms_scratch_ptr, saved; - uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; + uint16_t *flags = &cpu_core[curcpu_id].cpuc_dtrace_flags; char *sym; /* @@ -7189,7 +7463,7 @@ uint64_t val = *valp; size_t valoffs = *valoffsp; - flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags; + flags = (volatile uint16_t *)&cpu_core[curcpu_id].cpuc_dtrace_flags; ASSERT(dtkind == DIF_TF_BYREF || dtkind == DIF_TF_BYUREF); /* @@ -7274,7 +7548,7 @@ cookie = dtrace_interrupt_disable(); probe = dtrace_probes[id - 1]; - cpuid = curcpu; + cpuid = curcpu_id; onintr = CPU_ON_INTR(CPU); if (!onintr && probe->dtpr_predcache != DTRACE_CACHEIDNONE && @@ -8216,6 +8490,8 @@ } #else priv = DTRACE_PRIV_ALL; + *uidp = 0; + *zoneidp = 0; #endif *privp = priv; @@ -8480,7 +8756,7 @@ { dtrace_probe_t template, *probe; dtrace_hash_t *hash = NULL; - int len, best = INT_MAX, nmatched = 0; + int len, rc, best = INT_MAX, nmatched = 0; dtrace_id_t i; ASSERT(MUTEX_HELD(&dtrace_lock)); @@ -8492,7 +8768,8 @@ if (pkp->dtpk_id != DTRACE_IDNONE) { if ((probe = dtrace_probe_lookup_id(pkp->dtpk_id)) != NULL && dtrace_match_probe(probe, pkp, priv, uid, zoneid) > 0) { - (void) (*matched)(probe, arg); + if ((*matched)(probe, arg) == DTRACE_MATCH_FAIL) + return (DTRACE_MATCH_FAIL); nmatched++; } return (nmatched); @@ -8539,8 +8816,12 @@ nmatched++; - if ((*matched)(probe, arg) != DTRACE_MATCH_NEXT) + if ((rc = (*matched)(probe, arg)) != + DTRACE_MATCH_NEXT) { + if (rc == DTRACE_MATCH_FAIL) + return (DTRACE_MATCH_FAIL); break; + } } return (nmatched); @@ -8559,8 +8840,11 @@ nmatched++; - if ((*matched)(probe, arg) != DTRACE_MATCH_NEXT) + if ((rc = (*matched)(probe, arg)) != DTRACE_MATCH_NEXT) { + if (rc == DTRACE_MATCH_FAIL) + return (DTRACE_MATCH_FAIL); break; + } } return (nmatched); @@ -8780,7 +9064,7 @@ dtrace_probe_t *probe, *first = NULL; if (old->dtpv_pops.dtps_enable == - (void (*)(void *, dtrace_id_t, void *))dtrace_nullop) { + (int (*)(void *, dtrace_id_t, void *))dtrace_nullop) { /* * If DTrace itself is the provider, we're called with locks * already held. @@ -8851,6 +9135,9 @@ dtrace_unregister_defunct_reap) noreap = 1; + /* + * We have at least one ECB; we can't remove this provider. + */ if (!self) { mutex_exit(&dtrace_lock); #ifdef illumos @@ -8911,9 +9198,13 @@ kmem_free(probe->dtpr_name, strlen(probe->dtpr_name) + 1); #ifdef illumos vmem_free(dtrace_arena, (void *)(uintptr_t)(probe->dtpr_id), 1); -#else +#endif +#ifdef __FreeBSD__ free_unr(dtrace_arena, probe->dtpr_id); #endif +#ifdef __NetBSD__ + vmem_free(dtrace_arena, (uintptr_t)(probe->dtpr_id), 1); +#endif kmem_free(probe, sizeof (dtrace_probe_t)); } @@ -8959,7 +9250,7 @@ dtrace_provider_t *pvp = (dtrace_provider_t *)id; ASSERT(pvp->dtpv_pops.dtps_enable != - (void (*)(void *, dtrace_id_t, void *))dtrace_nullop); + (int (*)(void *, dtrace_id_t, void *))dtrace_nullop); mutex_enter(&dtrace_provider_lock); mutex_enter(&dtrace_lock); @@ -9000,7 +9291,7 @@ * Make sure this isn't the dtrace provider itself. */ ASSERT(prov->dtpv_pops.dtps_enable != - (void (*)(void *, dtrace_id_t, void *))dtrace_nullop); + (int (*)(void *, dtrace_id_t, void *))dtrace_nullop); mutex_enter(&dtrace_provider_lock); mutex_enter(&dtrace_lock); @@ -9032,9 +9323,13 @@ kmem_free(probe, sizeof (dtrace_probe_t)); #ifdef illumos vmem_free(dtrace_arena, (void *)((uintptr_t)i + 1), 1); -#else +#endif +#ifdef __FreeBSD__ free_unr(dtrace_arena, i + 1); #endif +#ifdef __NetBSD__ + vmem_free(dtrace_arena, ((uintptr_t)i + 1), 1); +#endif } mutex_exit(&dtrace_lock); @@ -9073,9 +9368,16 @@ #ifdef illumos id = (dtrace_id_t)(uintptr_t)vmem_alloc(dtrace_arena, 1, VM_BESTFIT | VM_SLEEP); -#else +#endif +#ifdef __FreeBSD__ id = alloc_unr(dtrace_arena); #endif +#ifdef __NetBSD__ + vmem_addr_t offset; + if (vmem_alloc(dtrace_arena, 1, VM_BESTFIT | VM_SLEEP, &offset) != 0) + ASSERT(0); + id = (dtrace_id_t)(uintptr_t)offset; +#endif probe = kmem_zalloc(sizeof (dtrace_probe_t), KM_SLEEP); probe->dtpr_id = id; @@ -9244,6 +9546,9 @@ #ifdef illumos modctl_t *ctl; #endif +#ifdef __NetBSD__ + module_t *mod; +#endif int all = 0; ASSERT(MUTEX_HELD(&dtrace_provider_lock)); @@ -9279,6 +9584,18 @@ mutex_exit(&mod_lock); #endif +#ifdef __NetBSD__ + kernconfig_lock(); + + /* Fake netbsd module first */ + prv->dtpv_pops.dtps_provide_module(prv->dtpv_arg, module_kernel()); + + TAILQ_FOREACH(mod, &module_list, mod_chain) { + if (module_source(mod) != MODULE_SOURCE_KERNEL) + prv->dtpv_pops.dtps_provide_module(prv->dtpv_arg, mod); + } + kernconfig_unlock(); +#endif } while (all && (prv = prv->dtpv_next) != NULL); } @@ -9937,7 +10254,6 @@ subr == DIF_SUBR_COPYOUTSTR) { dp->dtdo_destructive = 1; } - if (subr == DIF_SUBR_GETF) { /* * If we have a getf() we need to record that @@ -10287,7 +10603,8 @@ subr == DIF_SUBR_NTOHLL || subr == DIF_SUBR_MEMREF) break; -#ifdef __FreeBSD__ + +#if defined(__FreeBSD__) || defined(__NetBSD__) if (subr == DIF_SUBR_MEMSTR) break; #endif @@ -11061,7 +11378,7 @@ return (ecb); } -static void +static int dtrace_ecb_enable(dtrace_ecb_t *ecb) { dtrace_probe_t *probe = ecb->dte_probe; @@ -11074,7 +11391,7 @@ /* * This is the NULL probe -- there's nothing to do. */ - return; + return (0); } if (probe->dtpr_ecb == NULL) { @@ -11088,8 +11405,8 @@ if (ecb->dte_predicate != NULL) probe->dtpr_predcache = ecb->dte_predicate->dtp_cacheid; - prov->dtpv_pops.dtps_enable(prov->dtpv_arg, - probe->dtpr_id, probe->dtpr_arg); + return (prov->dtpv_pops.dtps_enable(prov->dtpv_arg, + probe->dtpr_id, probe->dtpr_arg)); } else { /* * This probe is already active. Swing the last pointer to @@ -11102,6 +11419,7 @@ probe->dtpr_predcache = 0; dtrace_sync(); + return (0); } } @@ -11345,12 +11663,22 @@ /* * We need to allocate an id for this aggregation. */ + #ifdef illumos aggid = (dtrace_aggid_t)(uintptr_t)vmem_alloc(state->dts_aggid_arena, 1, VM_BESTFIT | VM_SLEEP); -#else +#endif +#ifdef __FreeBSD__ aggid = alloc_unr(state->dts_aggid_arena); #endif +#ifdef __NetBSD__ + vmem_addr_t offset; + + if (vmem_alloc(state->dts_aggid_arena, 1, VM_BESTFIT | VM_SLEEP, + &offset) != 0) + ASSERT(0); + aggid = (dtrace_aggid_t)(uintptr_t)offset; +#endif if (aggid - 1 >= state->dts_naggregations) { dtrace_aggregation_t **oaggs = state->dts_aggregations; @@ -11401,9 +11729,13 @@ ASSERT(DTRACEACT_ISAGG(act->dta_kind)); #ifdef illumos vmem_free(state->dts_aggid_arena, (void *)(uintptr_t)aggid, 1); -#else +#endif +#ifdef __FreeBSD__ free_unr(state->dts_aggid_arena, aggid); #endif +#ifdef __NetBSD__ + vmem_free(state->dts_aggid_arena, (uintptr_t)aggid, 1); +#endif ASSERT(state->dts_aggregations[aggid - 1] == agg); state->dts_aggregations[aggid - 1] = NULL; @@ -11908,7 +12240,9 @@ if ((ecb = dtrace_ecb_create(state, probe, enab)) == NULL) return (DTRACE_MATCH_DONE); - dtrace_ecb_enable(ecb); + if (dtrace_ecb_enable(ecb) < 0) + return (DTRACE_MATCH_FAIL); + return (DTRACE_MATCH_NEXT); } @@ -11999,7 +12333,7 @@ dtrace_buffer_t *buf; dtrace_icookie_t cookie = dtrace_interrupt_disable(); - buf = &state->dts_buffer[curcpu]; + buf = &state->dts_buffer[curcpu_id]; if (buf->dtb_tomax != NULL) { /* @@ -12037,6 +12371,10 @@ #ifdef illumos cpu_t *cp; #endif +#ifdef __NetBSD__ + CPU_INFO_ITERATOR cpuind; + struct cpu_info *cinfo; +#endif dtrace_buffer_t *buf; int allocated = 0, desired = 0; @@ -12116,7 +12454,6 @@ buf->dtb_size = 0; } while ((cp = cp->cpu_next) != cpu_list); #else - int i; *factor = 1; #if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \ @@ -12131,7 +12468,15 @@ #endif ASSERT(MUTEX_HELD(&dtrace_lock)); - CPU_FOREACH(i) { +#ifdef __NetBSD__ + for (CPU_INFO_FOREACH(cpuind, cinfo)) +#else + CPU_FOREACH(i) +#endif + { +#ifdef __NetBSD__ + int i = cpu_index(cinfo); +#endif if (cpu != DTRACE_CPUALL && cpu != i) continue; @@ -12173,8 +12518,16 @@ * Error allocating memory, so free the buffers that were * allocated before the failed allocation. */ - CPU_FOREACH(i) { - if (cpu != DTRACE_CPUALL && cpu != i) +#ifdef __NetBSD__ + for (CPU_INFO_FOREACH(cpuind, cinfo)) +#else + CPU_FOREACH(i) +#endif + { +#ifdef __NetBSD__ + int i = cpu_index(cinfo); +#endif + if (cpu != DTRACE_CPUALL && cpu != cpu_index(cinfo)) continue; buf = &bufs[i]; @@ -12855,7 +13208,7 @@ dtrace_enabling_match(dtrace_enabling_t *enab, int *nmatched) { int i = 0; - int matched = 0; + int total_matched = 0, matched = 0; ASSERT(MUTEX_HELD(&cpu_lock)); ASSERT(MUTEX_HELD(&dtrace_lock)); @@ -12866,7 +13219,14 @@ enab->dten_current = ep; enab->dten_error = 0; - matched += dtrace_probe_enable(&ep->dted_probe, enab); + /* + * If a provider failed to enable a probe then get out and + * let the consumer know we failed. + */ + if ((matched = dtrace_probe_enable(&ep->dted_probe, enab)) < 0) + return (EBUSY); + + total_matched += matched; if (enab->dten_error != 0) { /* @@ -12894,7 +13254,7 @@ enab->dten_probegen = dtrace_probegen; if (nmatched != NULL) - *nmatched = matched; + *nmatched = total_matched; return (0); } @@ -13100,7 +13460,6 @@ mutex_exit(&dtrace_lock); mutex_exit(&cpu_lock); } - /* * DTrace DOF Functions */ @@ -13272,7 +13631,54 @@ return (dof); } +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +static dof_hdr_t * +dtrace_dof_copyin_pid(pid_t pid, const void *uarg, int *errp) +{ + dof_hdr_t hdr, *dof; + size_t loadsz; + int err; + + err = copyin_pid(pid, uarg, &hdr, sizeof(hdr)); + if (err != 0) { + *errp = err; + return (NULL); + } + + /* + * Now we'll allocate the entire DOF and copy it in -- provided + * that the length isn't outrageous. + */ + if (hdr.dofh_loadsz >= dtrace_dof_maxsize) { + dtrace_dof_error(&hdr, "load size exceeds maximum"); + *errp = E2BIG; + return (NULL); + } + loadsz = (size_t)hdr.dofh_loadsz; + + if (loadsz < sizeof (hdr)) { + dtrace_dof_error(&hdr, "invalid load size"); + *errp = EINVAL; + return (NULL); + } + + dof = kmem_alloc(loadsz, KM_SLEEP); + + err = copyin_pid(pid, uarg, dof, loadsz); + if (err == 0 && dof->dofh_loadsz != loadsz) + err = EFAULT; + if (err != 0) { + kmem_free(dof, loadsz); + *errp = EFAULT; + return (NULL); + } + + return (dof); +} +#endif +#ifdef __FreeBSD__ static __inline uchar_t dtrace_dof_char(char c) { @@ -13312,6 +13718,48 @@ static dof_hdr_t * dtrace_dof_property(const char *name) { +#ifdef illumos + uchar_t *buf; + uint64_t loadsz; + unsigned int len, i; + dof_hdr_t *dof = NULL; + + /* + * Unfortunately, array of values in .conf files are always (and + * only) interpreted to be integer arrays. We must read our DOF + * as an integer array, and then squeeze it into a byte array. + */ + if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dtrace_devi, 0, + (char *)name, (int **)&buf, &len) != DDI_PROP_SUCCESS) + return (NULL); + + for (i = 0; i < len; i++) + buf[i] = (uchar_t)(((int *)buf)[i]); + + if (len < sizeof (dof_hdr_t)) { + ddi_prop_free(buf); + dtrace_dof_error(NULL, "truncated header"); + return (NULL); + } + + if (len < (loadsz = ((dof_hdr_t *)buf)->dofh_loadsz)) { + ddi_prop_free(buf); + dtrace_dof_error(NULL, "truncated DOF"); + return (NULL); + } + + if (loadsz >= dtrace_dof_maxsize) { + ddi_prop_free(buf); + dtrace_dof_error(NULL, "oversized DOF"); + return (NULL); + } + + dof = kmem_alloc(loadsz, KM_SLEEP); + bcopy(buf, dof, loadsz); + ddi_prop_free(buf); + + return (dof); +#endif /* illumos */ #ifdef __FreeBSD__ uint8_t *dofbuf; u_char *data, *eol; @@ -13387,48 +13835,11 @@ doferr: free(dof, M_SOLARIS); return (NULL); -#else /* __FreeBSD__ */ - uchar_t *buf; - uint64_t loadsz; - unsigned int len, i; - dof_hdr_t *dof; - - /* - * Unfortunately, array of values in .conf files are always (and - * only) interpreted to be integer arrays. We must read our DOF - * as an integer array, and then squeeze it into a byte array. - */ - if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dtrace_devi, 0, - (char *)name, (int **)&buf, &len) != DDI_PROP_SUCCESS) - return (NULL); - - for (i = 0; i < len; i++) - buf[i] = (uchar_t)(((int *)buf)[i]); - - if (len < sizeof (dof_hdr_t)) { - ddi_prop_free(buf); - dtrace_dof_error(NULL, "truncated header"); - return (NULL); - } - - if (len < (loadsz = ((dof_hdr_t *)buf)->dofh_loadsz)) { - ddi_prop_free(buf); - dtrace_dof_error(NULL, "truncated DOF"); - return (NULL); - } - - if (loadsz >= dtrace_dof_maxsize) { - ddi_prop_free(buf); - dtrace_dof_error(NULL, "oversized DOF"); - return (NULL); - } - - dof = kmem_alloc(loadsz, KM_SLEEP); - bcopy(buf, dof, loadsz); - ddi_prop_free(buf); - - return (dof); -#endif /* !__FreeBSD__ */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + printf("dtrace: XXX %s not implemented (name=%s)\n", __func__, name); + return (NULL); +#endif /* __NetBSD__ */ } static void @@ -14319,11 +14730,16 @@ maxper = (limit - (uintptr_t)start) / NCPU; maxper = (maxper / dstate->dtds_chunksize) * dstate->dtds_chunksize; -#ifndef illumos - CPU_FOREACH(i) { -#else - for (i = 0; i < NCPU; i++) { +#ifdef illumos + for (i = 0; i < NCPU; i++) +#endif +#ifdef __FreeBSD__ + CPU_FOREACH(i) #endif +#ifdef __NetBSD__ + for (i = 0; i < NCPU; i++) +#endif + { dstate->dtds_percpu[i].dtdsc_free = dvar = start; /* @@ -14401,24 +14817,33 @@ } } -#ifdef illumos +#ifdef __FreeBSD__ static void -dtrace_state_clean(dtrace_state_t *state) +dtrace_state_clean(void *arg) { + dtrace_state_t *state = arg; + dtrace_optval_t *opt = state->dts_options; + if (state->dts_activity == DTRACE_ACTIVITY_INACTIVE) return; dtrace_dynvar_clean(&state->dts_vstate.dtvs_dynvars); dtrace_speculation_clean(state); + + callout_reset(&state->dts_cleaner, hz * opt[DTRACEOPT_CLEANRATE] / NANOSEC, + dtrace_state_clean, state); } static void -dtrace_state_deadman(dtrace_state_t *state) +dtrace_state_deadman(void *arg) { + dtrace_state_t *state = arg; hrtime_t now; dtrace_sync(); + dtrace_debug_output(); + now = dtrace_gethrtime(); if (state != dtrace_anon.dta_state && @@ -14437,34 +14862,28 @@ state->dts_alive = INT64_MAX; dtrace_membar_producer(); state->dts_alive = now; + + callout_reset(&state->dts_deadman, hz * dtrace_deadman_interval / NANOSEC, + dtrace_state_deadman, state); } -#else /* !illumos */ +#else static void -dtrace_state_clean(void *arg) +dtrace_state_clean(dtrace_state_t *state) { - dtrace_state_t *state = arg; - dtrace_optval_t *opt = state->dts_options; - if (state->dts_activity == DTRACE_ACTIVITY_INACTIVE) return; dtrace_dynvar_clean(&state->dts_vstate.dtvs_dynvars); dtrace_speculation_clean(state); - - callout_reset(&state->dts_cleaner, hz * opt[DTRACEOPT_CLEANRATE] / NANOSEC, - dtrace_state_clean, state); } static void -dtrace_state_deadman(void *arg) +dtrace_state_deadman(dtrace_state_t *state) { - dtrace_state_t *state = arg; hrtime_t now; dtrace_sync(); - dtrace_debug_output(); - now = dtrace_gethrtime(); if (state != dtrace_anon.dta_state && @@ -14483,31 +14902,35 @@ state->dts_alive = INT64_MAX; dtrace_membar_producer(); state->dts_alive = now; - - callout_reset(&state->dts_deadman, hz * dtrace_deadman_interval / NANOSEC, - dtrace_state_deadman, state); } + #endif /* illumos */ static dtrace_state_t * #ifdef illumos dtrace_state_create(dev_t *devp, cred_t *cr) -#else +#endif +#ifdef __FreeBSD__ dtrace_state_create(struct cdev *dev, struct ucred *cred __unused) #endif +#ifdef __NetBSD__ +dtrace_state_create(dev_t *devp, cred_t *cr) +#endif { #ifdef illumos minor_t minor; major_t major; #else - cred_t *cr = NULL; int m = 0; #endif +#ifdef __FreeBSD__ + cred_t *cr = NULL; +#endif + int cpu_it; char c[30]; dtrace_state_t *state; dtrace_optval_t *opt; int bufsize = NCPU * sizeof (dtrace_buffer_t), i; - int cpu_it; ASSERT(MUTEX_HELD(&dtrace_lock)); ASSERT(MUTEX_HELD(&cpu_lock)); @@ -14522,16 +14945,21 @@ } state = ddi_get_soft_state(dtrace_softstate, minor); -#else +#endif +#ifdef __FreeBSD__ if (dev != NULL) { cr = dev->si_cred; m = dev2unit(dev); } +#endif +#ifdef __NetBSD__ + m = minor(*devp) & 0x0F; /* Allocate memory for the state. */ state = kmem_zalloc(sizeof(dtrace_state_t), KM_SLEEP); #endif + state->dts_epid = DTRACE_EPIDNONE + 1; (void) snprintf(c, sizeof (c), "dtrace_aggid_%d", m); @@ -14549,9 +14977,15 @@ if (devp != NULL) *devp = state->dts_dev; -#else +#endif +#ifdef __FreeBSD__ state->dts_aggid_arena = new_unrhdr(1, INT_MAX, &dtrace_unr_mtx); - state->dts_dev = dev; + state->dts_dev = dev; +#endif +#ifdef __NetBSD__ + state->dts_aggid_arena = vmem_create(c, 1, INT_MAX, 1, + NULL, NULL, NULL, 0, VM_SLEEP, IPL_NONE); + state->dts_dev = *devp; #endif /* @@ -14578,13 +15012,19 @@ state->dts_rstate[cpu_it]); } + #ifdef illumos state->dts_cleaner = CYCLIC_NONE; state->dts_deadman = CYCLIC_NONE; -#else +#endif +#ifdef __FreeBSD__ callout_init(&state->dts_cleaner, 1); callout_init(&state->dts_deadman, 1); #endif +#ifdef __NetBSD__ + state->dts_cleaner = NULL; + state->dts_deadman = NULL; +#endif state->dts_vstate.dtvs_state = state; for (i = 0; i < DTRACEOPT_MAX; i++) @@ -15071,12 +15511,19 @@ when.cyt_interval = dtrace_deadman_interval; state->dts_deadman = cyclic_add(&hdlr, &when); -#else +#endif +#ifdef __FreeBSD__ callout_reset(&state->dts_cleaner, hz * opt[DTRACEOPT_CLEANRATE] / NANOSEC, dtrace_state_clean, state); callout_reset(&state->dts_deadman, hz * dtrace_deadman_interval / NANOSEC, dtrace_state_deadman, state); #endif +#ifdef __NetBSD__ + state->dts_cleaner = dtrace_state_worker_add( + dtrace_state_clean, state, opt[DTRACEOPT_CLEANRATE]); + state->dts_deadman = dtrace_state_worker_add( + dtrace_state_deadman, state, dtrace_deadman_interval); +#endif state->dts_activity = DTRACE_ACTIVITY_WARMUP; @@ -15105,7 +15552,7 @@ * level) and to manually activate the buffer for this CPU. */ cookie = dtrace_interrupt_disable(); - *cpu = curcpu; + *cpu = curcpu_id; ASSERT(state->dts_buffer[*cpu].dtb_flags & DTRACEBUF_INACTIVE); state->dts_buffer[*cpu].dtb_flags &= ~DTRACEBUF_INACTIVE; @@ -15134,6 +15581,7 @@ dtrace_xcall(DTRACE_CPUALL, (dtrace_xcall_t)dtrace_buffer_activate, state); #else + /* * Regardless of whether or not now we're in ACTIVE or DRAINING, we * want each CPU to transition its principal buffer out of the @@ -15219,7 +15667,7 @@ state->dts_reserve = 0; cookie = dtrace_interrupt_disable(); - *cpu = curcpu; + *cpu = curcpu_id; dtrace_probe(dtrace_probeid_end, (uint64_t)(uintptr_t)state, 0, 0, 0, 0); dtrace_interrupt_enable(cookie); @@ -15394,12 +15842,20 @@ if (state->dts_deadman != CYCLIC_NONE) cyclic_remove(state->dts_deadman); -#else +#endif +#ifdef __FreeBSD__ callout_stop(&state->dts_cleaner); callout_drain(&state->dts_cleaner); callout_stop(&state->dts_deadman); callout_drain(&state->dts_deadman); #endif +#ifdef __NetBSD__ + if (state->dts_cleaner != NULL) + dtrace_state_worker_remove(state->dts_cleaner); + + if (state->dts_deadman != NULL) + dtrace_state_worker_remove(state->dts_deadman); +#endif dtrace_dstate_fini(&vstate->dtvs_dynvars); dtrace_vstate_fini(vstate); @@ -15428,7 +15884,7 @@ dtrace_format_destroy(state); if (state->dts_aggid_arena != NULL) { -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) vmem_destroy(state->dts_aggid_arena); #else delete_unrhdr(state->dts_aggid_arena); @@ -15439,6 +15895,9 @@ ddi_soft_state_free(dtrace_softstate, minor); vmem_free(dtrace_minor, (void *)(uintptr_t)minor, 1); #endif +#ifdef __NetBSD__ + kmem_free(state, sizeof(dtrace_state_t)); +#endif } /* @@ -15576,7 +16035,7 @@ { uint32_t size, next, nnext, i; dtrace_helptrace_t *ent, *buffer; - uint16_t flags = cpu_core[curcpu].cpuc_dtrace_flags; + uint16_t flags = cpu_core[curcpu_id].cpuc_dtrace_flags; if ((buffer = dtrace_helptrace_buffer) == NULL) return; @@ -15619,7 +16078,7 @@ ent->dtht_fltoffs = (mstate->dtms_present & DTRACE_MSTATE_FLTOFFS) ? mstate->dtms_fltoffs : -1; ent->dtht_fault = DTRACE_FLAGS2FLT(flags); - ent->dtht_illval = cpu_core[curcpu].cpuc_dtrace_illval; + ent->dtht_illval = cpu_core[curcpu_id].cpuc_dtrace_illval; for (i = 0; i < vstate->dtvs_nlocals; i++) { dtrace_statvar_t *svar; @@ -15629,7 +16088,7 @@ ASSERT(svar->dtsv_size >= NCPU * sizeof (uint64_t)); ent->dtht_locals[i] = - ((uint64_t *)(uintptr_t)svar->dtsv_data)[curcpu]; + ((uint64_t *)(uintptr_t)svar->dtsv_data)[curcpu_id]; } } @@ -15637,7 +16096,7 @@ dtrace_helper(int which, dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t arg0, uint64_t arg1) { - uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags; + uint16_t *flags = &cpu_core[curcpu_id].cpuc_dtrace_flags; uint64_t sarg0 = mstate->dtms_arg[0]; uint64_t sarg1 = mstate->dtms_arg[1]; uint64_t rval = 0; @@ -16297,7 +16756,6 @@ help = dtrace_helpers_create(p); vstate = &help->dthps_vstate; - if ((rv = dtrace_dof_slurp(dof, vstate, NULL, &enab, dhp->dofhp_addr, dhp->dofhp_dof, B_FALSE)) != 0) { dtrace_dof_destroy(dof); @@ -16593,6 +17051,19 @@ { dtrace_provider_t *prv; +#ifdef __NetBSD__ + /* + * We have just one symbol table and CTF table for the entire + * base kernel, so ignore any other built-in module entries. + * This means that the module name for a given symbol will change + * depending on whether the module is built-in or loaded separately. + */ + if (module_source(ctl) == MODULE_SOURCE_KERNEL && + strcmp(module_name(ctl), "netbsd")) { + return; + } +#endif + mutex_enter(&dtrace_provider_lock); #ifdef illumos mutex_enter(&mod_lock); @@ -16648,7 +17119,7 @@ } static void -#ifdef illumos +#ifndef __FreeBSD__ dtrace_module_unloaded(modctl_t *ctl) #else dtrace_module_unloaded(modctl_t *ctl, int *error) @@ -16663,7 +17134,8 @@ #ifdef illumos template.dtpr_mod = ctl->mod_modname; -#else +#endif +#ifdef __FreeBSD__ /* Handle the fact that ctl->filename may end in ".ko". */ strlcpy(modname, ctl->filename, sizeof(modname)); len = strlen(ctl->filename); @@ -16671,6 +17143,20 @@ modname[len - 3] = '\0'; template.dtpr_mod = modname; #endif +#ifdef __NetBSD__ + if (module_source(ctl) == MODULE_SOURCE_KERNEL && + strcmp(module_name(ctl), "netbsd")) { + return; + } + + /* Handle the fact that ctl->filename may end in ".kmod". */ + strlcpy(modname, module_name(ctl), sizeof(modname)); + len = strlen(modname); + if (len > 5 && strcmp(modname + len - 5, ".kmod") == 0) + modname[len - 5] = '\0'; + template.dtpr_mod = modname; + +#endif mutex_enter(&dtrace_provider_lock); #ifdef illumos @@ -16678,14 +17164,14 @@ #endif mutex_enter(&dtrace_lock); -#ifndef illumos +#ifdef __FreeBSD__ if (ctl->nenabled > 0) { /* Don't allow unloads if a probe is enabled. */ mutex_exit(&dtrace_provider_lock); mutex_exit(&dtrace_lock); *error = -1; printf( - "kldunload: attempt to unload module that has DTrace probes enabled\n"); + "kldunload: attempt to unload module that has DTrace probes enabled\n"); return; } #endif @@ -16774,9 +17260,13 @@ kmem_free(probe->dtpr_name, strlen(probe->dtpr_name) + 1); #ifdef illumos vmem_free(dtrace_arena, (void *)(uintptr_t)probe->dtpr_id, 1); -#else +#endif +#ifdef __FreeBSD__ free_unr(dtrace_arena, probe->dtpr_id); #endif +#ifdef __NetBSD__ + vmem_free(dtrace_arena, (uintptr_t)probe->dtpr_id, 1); +#endif kmem_free(probe, sizeof (dtrace_probe_t)); } @@ -16787,7 +17277,7 @@ mutex_exit(&dtrace_provider_lock); } -#ifndef illumos +#ifdef __FreeBSD__ static void dtrace_kld_load(void *arg __unused, linker_file_t lf) { @@ -17102,19 +17592,58 @@ return (DDI_SUCCESS); } -#endif /* illumos */ +#endif + +#ifdef __NetBSD__ +static dev_type_open(dtrace_open); + +/* Pseudo Device Entry points */ +/* Just opens, clones to the fileops below */ +const struct cdevsw dtrace_cdevsw = { + .d_open = dtrace_open, + .d_close = noclose, + .d_read = noread, + .d_write = nowrite, + .d_ioctl = noioctl, + .d_stop = nostop, + .d_tty = notty, + .d_poll = nopoll, + .d_mmap = nommap, + .d_kqfilter = nokqfilter, + .d_discard = nodiscard, + .d_flag = D_OTHER | D_MPSAFE +}; + +static int dtrace_ioctl(struct file *fp, u_long cmd, void *data); +static int dtrace_close(struct file *fp); + +static const struct fileops dtrace_fileops = { + .fo_read = fbadop_read, + .fo_write = fbadop_write, + .fo_ioctl = dtrace_ioctl, + .fo_fcntl = fnullop_fcntl, + .fo_poll = fnullop_poll, + .fo_stat = fbadop_stat, + .fo_close = dtrace_close, + .fo_kqfilter = fnullop_kqfilter, +}; +#endif #ifndef illumos static void dtrace_dtr(void *); #endif - + /*ARGSUSED*/ static int #ifdef illumos dtrace_open(dev_t *devp, int flag, int otyp, cred_t *cred_p) -#else +#endif +#ifdef __FreeBSD_ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td) #endif +#ifdef __NetBSD__ +dtrace_open(dev_t dev, int flags, int mode, struct lwp *l) +#endif { dtrace_state_t *state; uint32_t priv; @@ -17131,9 +17660,23 @@ */ if (getminor(*devp) == DTRACEMNRN_DTRACE) return (ENXIO); -#else +#endif +#ifdef __FreeBSD__ + cred_t *cred_p = NULL; + cred_p = dev->si_cred; + + +#endif +#ifdef __NetBSD__ cred_t *cred_p = NULL; - cred_p = dev->si_cred; + struct file *fp; + int fd; + int res; + + if ((res = fd_allocfile(&fp, &fd)) != 0) + return res; + cred_p = l->l_cred; +#endif /* * If no DTRACE_PRIV_* bits are set in the credential, then the @@ -17141,8 +17684,6 @@ */ dtrace_cred2priv(cred_p, &priv, &uid, &zoneid); if (priv == DTRACE_PRIV_NONE) { -#endif - return (EACCES); } @@ -17181,12 +17722,15 @@ dtrace_helptrace_wrapped = 0; dtrace_helptrace_enable = 0; } - state = dtrace_state_create(devp, cred_p); -#else +#endif +#ifdef __FreeBSD__ state = dtrace_state_create(dev, NULL); devfs_set_cdevpriv(state, dtrace_dtr); #endif +#ifdef __NetBSD__ + state = dtrace_state_create(&dev, cred_p); +#endif mutex_exit(&cpu_lock); @@ -17203,37 +17747,50 @@ mutex_exit(&dtrace_lock); +#ifdef __NetBSD__ + return fd_clone(fp, fd, flags, &dtrace_fileops, state); +#else return (0); +#endif } /*ARGSUSED*/ #ifdef illumos static int dtrace_close(dev_t dev, int flag, int otyp, cred_t *cred_p) -#else +#endif +#ifdef __FreeBSD__ static void dtrace_dtr(void *data) #endif +#ifdef __NetBSD__ +static int +dtrace_close(struct file *fp) +#endif { #ifdef illumos minor_t minor = getminor(dev); dtrace_state_t *state; #endif dtrace_helptrace_t *buf = NULL; - + #ifdef illumos if (minor == DTRACEMNRN_HELPER) return (0); state = ddi_get_soft_state(dtrace_softstate, minor); -#else +#endif +#ifdef __FreeBSD__ dtrace_state_t *state = data; #endif +#ifdef __NetBSD__ + dtrace_state_t *state = (dtrace_state_t *)fp->f_data; +#endif mutex_enter(&cpu_lock); mutex_enter(&dtrace_lock); -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) if (state->dts_anon) #else if (state != NULL && state->dts_anon) @@ -17258,7 +17815,7 @@ dtrace_helptrace_buffer = NULL; } -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) dtrace_state_destroy(state); #else if (state != NULL) { @@ -17266,6 +17823,7 @@ kmem_free(state, 0); } #endif + ASSERT(dtrace_opens > 0); #ifdef illumos @@ -17287,7 +17845,7 @@ mutex_exit(&dtrace_lock); mutex_exit(&cpu_lock); -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) return (0); #endif } @@ -18316,8 +18874,9 @@ { return (mod_remove(&modlinkage)); } -#else +#endif +#ifdef __FreeBSD__ static d_ioctl_t dtrace_ioctl; static d_ioctl_t dtrace_ioctl_helper; static void dtrace_load(void *); @@ -18340,6 +18899,83 @@ .d_ioctl = dtrace_ioctl_helper, .d_name = "helper", }; +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +void dtrace_invop_init(void); +void dtrace_invop_uninit(void); + +struct dtrace_state_worker { + kmutex_t lock; + kcondvar_t cv; + void (*fn)(dtrace_state_t *); + dtrace_state_t *state; + int interval; + lwp_t *lwp; + bool exiting; +}; + +static void +dtrace_state_worker_thread(void *vp) +{ + struct dtrace_state_worker *w = vp; + + mutex_enter(&w->lock); + while (!w->exiting) { + int error; + + error = cv_timedwait(&w->cv, &w->lock, w->interval); + if (error == EWOULDBLOCK) { + mutex_exit(&w->lock); + w->fn(w->state); + mutex_enter(&w->lock); + } + } + mutex_exit(&w->lock); + kthread_exit(0); +} + +struct dtrace_state_worker * +dtrace_state_worker_add(void (*fn)(dtrace_state_t *), dtrace_state_t *state, + hrtime_t interval) +{ + struct dtrace_state_worker *w; + int error __diagused; + + w = kmem_alloc(sizeof(*w), KM_SLEEP); + mutex_init(&w->lock, "dtrace", MUTEX_DEFAULT, NULL); + cv_init(&w->cv, "dtrace"); + w->interval = ((uintmax_t)hz * interval) / NANOSEC; + w->fn = fn; + w->state = state; + w->exiting = false; + error = kthread_create(PRI_NONE, KTHREAD_MPSAFE|KTHREAD_MUSTJOIN, NULL, + dtrace_state_worker_thread, w, &w->lwp, "dtrace-state-worker"); + KASSERT(error == 0); /* XXX */ + return w; +} + +void +dtrace_state_worker_remove(struct dtrace_state_worker *w) +{ + int error __diagused; + + KASSERT(!w->exiting); + mutex_enter(&w->lock); + w->exiting = true; + cv_signal(&w->cv); + mutex_exit(&w->lock); + error = kthread_join(w->lwp); + KASSERT(error == 0); + cv_destroy(&w->cv); + mutex_destroy(&w->lock); + kmem_free(w, sizeof(*w)); +} + +#endif /* __NetBSD__ */ + +static void dtrace_load(void *); +static int dtrace_unload(void); #include #include @@ -18351,11 +18987,12 @@ #include #include -SYSINIT(dtrace_load, SI_SUB_DTRACE, SI_ORDER_FIRST, dtrace_load, NULL); -SYSUNINIT(dtrace_unload, SI_SUB_DTRACE, SI_ORDER_FIRST, dtrace_unload, NULL); -SYSINIT(dtrace_anon_init, SI_SUB_DTRACE_ANON, SI_ORDER_FIRST, dtrace_anon_init, NULL); - +#ifdef __FreeBSD__ DEV_MODULE(dtrace, dtrace_modevent, NULL); MODULE_VERSION(dtrace, 1); MODULE_DEPEND(dtrace, opensolaris, 1, 1, 1); -#endif +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +MODULE(MODULE_CLASS_DRIVER, dtrace, "solaris"); +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/vnode.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/vnode.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/vnode.c 2015-08-29 19:17:54.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/vnode.c 2017-05-11 13:07:48.000000000 -0700 @@ -72,6 +72,7 @@ return (xoap); } +#ifdef __FreeBSD__ static void vn_rele_inactive(vnode_t *vp) { @@ -102,3 +103,4 @@ refcount_release(&vp->v_usecount); vdropl(vp); } +#endif /* __FreeBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c 2017-05-15 17:54:12.000000000 -0700 @@ -275,16 +275,44 @@ #endif #endif /* illumos */ +#ifdef __NetBSD__ +#include +#ifndef btop +#define btop(x) ((x) / PAGE_SIZE) +#endif +//#define needfree (uvmexp.free < uvmexp.freetarg ? uvmexp.freetarg : 0) +#define buf_init arc_buf_init +#define freemem uvmexp.free +#define minfree uvmexp.freemin +#define desfree uvmexp.freetarg +#define lotsfree (desfree * 2) +#define availrmem desfree +#define swapfs_minfree 0 +#define swapfs_reserve 0 +#undef curproc +#define curproc curlwp +#define proc_pageout uvm.pagedaemon_lwp + +static void *zio_arena; + +#include +/* Structures used for memory and kva space reclaim. */ +static struct callback_entry arc_kva_reclaim_entry; + +#endif /* __NetBSD__ */ + static kmutex_t arc_reclaim_lock; static kcondvar_t arc_reclaim_thread_cv; static boolean_t arc_reclaim_thread_exit; static kcondvar_t arc_reclaim_waiters_cv; +#ifdef __FreeBSD__ static kmutex_t arc_dnlc_evicts_lock; static kcondvar_t arc_dnlc_evicts_cv; static boolean_t arc_dnlc_evicts_thread_exit; uint_t arc_reduce_dnlc_percent = 3; +#endif /* * The number of headers to evict in arc_evict_state_impl() before @@ -363,12 +391,12 @@ boolean_t zfs_compressed_arc_enabled = B_TRUE; +#if defined(__FreeBSD__) && defined(_KERNEL) static int sysctl_vfs_zfs_arc_free_target(SYSCTL_HANDLER_ARGS); static int sysctl_vfs_zfs_arc_meta_limit(SYSCTL_HANDLER_ARGS); static int sysctl_vfs_zfs_arc_max(SYSCTL_HANDLER_ARGS); static int sysctl_vfs_zfs_arc_min(SYSCTL_HANDLER_ARGS); -#if defined(__FreeBSD__) && defined(_KERNEL) static void arc_free_target_init(void *unused __unused) { @@ -1550,6 +1578,9 @@ { arc_buf_hdr_t *hdr = vbuf; +#ifdef __NetBSD__ + hdr = unused; +#endif bzero(hdr, HDR_FULL_SIZE); cv_init(&hdr->b_l1hdr.b_cv, NULL, CV_DEFAULT, NULL); refcount_create(&hdr->b_l1hdr.b_refcnt); @@ -1566,6 +1597,9 @@ { arc_buf_hdr_t *hdr = vbuf; +#ifdef __NetBSD__ + hdr = unused; +#endif bzero(hdr, HDR_L2ONLY_SIZE); arc_space_consume(HDR_L2ONLY_SIZE, ARC_SPACE_L2HDRS); @@ -1578,6 +1612,9 @@ { arc_buf_t *buf = vbuf; +#ifdef __NetBSD__ + buf = unused; +#endif bzero(buf, sizeof (arc_buf_t)); mutex_init(&buf->b_evict_lock, NULL, MUTEX_DEFAULT, NULL); arc_space_consume(sizeof (arc_buf_t), ARC_SPACE_HDRS); @@ -1595,6 +1632,9 @@ { arc_buf_hdr_t *hdr = vbuf; +#ifdef __NetBSD__ + hdr = unused; +#endif ASSERT(HDR_EMPTY(hdr)); cv_destroy(&hdr->b_l1hdr.b_cv); refcount_destroy(&hdr->b_l1hdr.b_refcnt); @@ -1609,6 +1649,9 @@ { arc_buf_hdr_t *hdr = vbuf; +#ifdef __NetBSD__ + hdr = unused; +#endif ASSERT(HDR_EMPTY(hdr)); arc_space_return(HDR_L2ONLY_SIZE, ARC_SPACE_L2HDRS); } @@ -1619,6 +1662,9 @@ { arc_buf_t *buf = vbuf; +#ifdef __NetBSD__ + buf = unused; +#endif mutex_destroy(&buf->b_evict_lock); arc_space_return(sizeof (arc_buf_t), ARC_SPACE_HDRS); } @@ -3973,6 +4019,7 @@ } } +#if __FreeBSD__ /* * Above limits know nothing about real level of KVA fragmentation. * Start aggressive reclamation if too little sequential KVA left. @@ -3986,6 +4033,7 @@ r = FMR_ZIO_FRAG; } } +#endif #else /* _KERNEL */ /* Every 100 calls, free a small amount */ @@ -4191,6 +4239,8 @@ thread_exit(); } +#ifdef __FreeBSD__ + static u_int arc_dnlc_evicts_arg; extern struct vfsops zfs_vfsops; @@ -4242,6 +4292,8 @@ mutex_exit(&arc_dnlc_evicts_lock); } +#endif + /* * Adapt arc info given the number of bytes we are trying to add and * the state that we are comming from. This function is only called @@ -5063,6 +5115,7 @@ ARCSTAT_CONDSTAT(!HDR_PREFETCH(hdr), demand, prefetch, !HDR_ISTYPE_METADATA(hdr), data, metadata, misses); +#ifdef __FreeBSD__ #ifdef _KERNEL #ifdef RACCT if (racct_enable) { @@ -5074,6 +5127,7 @@ #endif /* RACCT */ curthread->td_ru.ru_inblock++; #endif +#endif if (vd != NULL && l2arc_ndev != 0 && !(l2arc_norw && devw)) { /* @@ -5728,7 +5782,7 @@ * the arc is already going to be evicting, so we just want to * continue to let page writes occur as quickly as possible. */ - if (curproc == pageproc) { + if (curlwp == uvm.pagedaemon_lwp) { if (page_load > MAX(ptob(minfree), available_memory) / 4) return (SET_ERROR(ERESTART)); /* Note: reserve is inflated, so we deflate */ @@ -5885,7 +5939,9 @@ } #ifdef _KERNEL +#ifdef __FreeBSD__ static eventhandler_tag arc_event_lowmem = NULL; +#endif static void arc_lowmem(void *arg __unused, int howto __unused) @@ -5902,7 +5958,7 @@ * here from ARC itself and may hold ARC locks and thus risk a deadlock * with ARC reclaim thread. */ - if (curproc == pageproc) + if (curlwp == uvm.pagedaemon_lwp) (void) cv_wait(&arc_reclaim_waiters_cv, &arc_reclaim_lock); mutex_exit(&arc_reclaim_lock); } @@ -6028,8 +6084,10 @@ cv_init(&arc_reclaim_thread_cv, NULL, CV_DEFAULT, NULL); cv_init(&arc_reclaim_waiters_cv, NULL, CV_DEFAULT, NULL); +#ifdef __FreeBSD__ mutex_init(&arc_dnlc_evicts_lock, NULL, MUTEX_DEFAULT, NULL); cv_init(&arc_dnlc_evicts_cv, NULL, CV_DEFAULT, NULL); +#endif /* Convert seconds to clock ticks */ arc_min_prefetch_lifespan = 1 * hz; @@ -6130,7 +6188,9 @@ buf_init(); arc_reclaim_thread_exit = B_FALSE; +#ifdef __FreeBSD__ arc_dnlc_evicts_thread_exit = FALSE; +#endif arc_ksp = kstat_create("zfs", 0, "arcstats", "misc", KSTAT_TYPE_NAMED, sizeof (arc_stats) / sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL); @@ -6144,6 +6204,7 @@ (void) thread_create(NULL, 0, arc_reclaim_thread, NULL, 0, &p0, TS_RUN, minclsyspri); +#ifdef __FreeBSD__ #ifdef _KERNEL arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL, EVENTHANDLER_PRI_FIRST); @@ -6151,6 +6212,7 @@ (void) thread_create(NULL, 0, arc_dnlc_evicts_thread, NULL, 0, &p0, TS_RUN, minclsyspri); +#endif arc_dead = B_FALSE; arc_warm = B_FALSE; @@ -6225,8 +6287,10 @@ /* Use B_TRUE to ensure *all* buffers are evicted */ arc_flush(NULL, B_TRUE); +#ifdef __FreeBSD__ mutex_enter(&arc_dnlc_evicts_lock); arc_dnlc_evicts_thread_exit = TRUE; + /* * The user evicts thread will set arc_user_evicts_thread_exit * to FALSE when it is finished exiting; we're waiting for that. @@ -6237,6 +6301,10 @@ } mutex_exit(&arc_dnlc_evicts_lock); + mutex_destroy(&arc_dnlc_evicts_lock); + cv_destroy(&arc_dnlc_evicts_cv); +#endif + arc_dead = B_TRUE; if (arc_ksp != NULL) { @@ -6248,18 +6316,17 @@ cv_destroy(&arc_reclaim_thread_cv); cv_destroy(&arc_reclaim_waiters_cv); - mutex_destroy(&arc_dnlc_evicts_lock); - cv_destroy(&arc_dnlc_evicts_cv); - arc_state_fini(); buf_fini(); ASSERT0(arc_loaned_bytes); +#ifdef __FreeBSD__ #ifdef _KERNEL if (arc_event_lowmem != NULL) EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem); #endif +#endif } /* @@ -7182,7 +7249,7 @@ l2arc_dev_t *dev; spa_t *spa; uint64_t size, wrote; - clock_t begin, next = ddi_get_lbolt(); + clock_t begin, next = ddi_get_lbolt() + hz; CALLB_CPR_INIT(&cpr, &l2arc_feed_thr_lock, callb_generic_cpr, FTAG); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dbuf.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dbuf.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dbuf.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dbuf.c 2017-04-25 17:40:35.000000000 -0700 @@ -137,8 +137,11 @@ dbuf_cons(void *vdb, void *unused, int kmflag) { dmu_buf_impl_t *db = vdb; - bzero(db, sizeof (dmu_buf_impl_t)); +#ifdef __NetBSD__ + db = unused; +#endif + bzero(db, sizeof (dmu_buf_impl_t)); mutex_init(&db->db_mtx, NULL, MUTEX_DEFAULT, NULL); cv_init(&db->db_changed, NULL, CV_DEFAULT, NULL); multilist_link_init(&db->db_cache_link); @@ -152,6 +155,10 @@ dbuf_dest(void *vdb, void *unused) { dmu_buf_impl_t *db = vdb; + +#ifdef __NetBSD__ + db = unused; +#endif mutex_destroy(&db->db_mtx); cv_destroy(&db->db_changed); ASSERT(!multilist_link_active(&db->db_cache_link)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu.c 2017-01-24 09:21:52.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu.c 2017-05-02 09:59:07.000000000 -0700 @@ -504,6 +504,7 @@ /* initiate async i/o */ if (read) (void) dbuf_read(db, zio, dbuf_flags); + #ifdef _KERNEL else curthread->td_ru.ru_oublock++; @@ -1185,10 +1186,15 @@ #ifdef illumos err = uiomove((char *)db->db_data + bufoff, tocpy, UIO_READ, uio); -#else +#endif +#ifdef __FreeBSD__ err = vn_io_fault_uiomove((char *)db->db_data + bufoff, tocpy, uio); #endif +#ifdef __NetBSD__ + err = uiomove((char *)db->db_data + bufoff, tocpy, + UIO_READ, uio); +#endif } if (err) break; @@ -1291,10 +1297,15 @@ */ err = uiomove((char *)db->db_data + bufoff, tocpy, UIO_WRITE, uio); -#else +#endif +#ifdef __FreeBSD__ err = vn_io_fault_uiomove((char *)db->db_data + bufoff, tocpy, uio); #endif +#ifdef __NetBSD__ + err = uiomove((char *)db->db_data + bufoff, tocpy, + UIO_WRITE, uio); +#endif if (tocpy == db->db_size) dmu_buf_fill_done(db, tx); @@ -1418,9 +1429,9 @@ dmu_buf_rele_array(dbp, numbufs, FTAG); return (err); } +#endif /* illumos */ -#else /* !illumos */ - +#ifdef __FreeBSD__ int dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, vm_page_t *ma, dmu_tx_t *tx) @@ -1476,7 +1487,64 @@ dmu_buf_rele_array(dbp, numbufs, FTAG); return (err); } -#endif /* illumos */ +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +int +dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, + struct vm_page **pgs, dmu_tx_t *tx) +{ + dmu_buf_t **dbp; + int numbufs, i; + int err; + + if (size == 0) + return (0); + + err = dmu_buf_hold_array(os, object, offset, size, + FALSE, FTAG, &numbufs, &dbp); + if (err) + return (err); + + for (i = 0; i < numbufs; i++) { + int tocpy, copied, thiscpy; + int bufoff; + dmu_buf_t *db = dbp[i]; + caddr_t va; + + ASSERT(size > 0); + ASSERT3U(db->db_size, >=, PAGESIZE); + + bufoff = offset - db->db_offset; + tocpy = (int)MIN(db->db_size - bufoff, size); + + ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size); + + if (tocpy == db->db_size) + dmu_buf_will_fill(db, tx); + else + dmu_buf_will_dirty(db, tx); + + for (copied = 0; copied < tocpy; copied += PAGESIZE) { + ASSERT3U((*pgs)->offset, ==, db->db_offset + bufoff); + thiscpy = MIN(PAGESIZE, tocpy - copied); + va = zfs_map_page(*pgs, S_READ); + bcopy(va, (char *)db->db_data + bufoff, thiscpy); + zfs_unmap_page(*pgs, va); + pgs++; + bufoff += PAGESIZE; + } + + if (tocpy == db->db_size) + dmu_buf_fill_done(db, tx); + + offset += tocpy; + size -= tocpy; + } + dmu_buf_rele_array(dbp, numbufs, FTAG); + return (err); +} +#endif #endif /* _KERNEL */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_diff.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_diff.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_diff.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_diff.c 2017-04-22 00:54:20.000000000 -0700 @@ -41,13 +41,18 @@ #include struct diffarg { +#ifdef __FreeBSD__ + kthread_t *da_td; struct file *da_fp; /* file to which we are reporting */ +#else + struct vnode *da_vp; /* file to which we are reporting */ +#endif offset_t *da_offp; int da_err; /* error that stopped diff search */ dmu_diff_record_t da_ddr; - kthread_t *da_td; }; +#ifdef __FreeBSD__ static int write_bytes(struct diffarg *da) { @@ -59,9 +64,9 @@ auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_resid = aiov.iov_len; - auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_offset = (off_t)-1; + auio.uio_segflg = UIO_SYSSPACE; auio.uio_td = da->da_td; #ifdef _KERNEL if (da->da_fp->f_type == DTYPE_VNODE) @@ -72,17 +77,25 @@ return (EOPNOTSUPP); #endif } +#endif /* __FreeBSD__ */ static int write_record(struct diffarg *da) { + ssize_t resid; /* have to get resid to get detailed errno */ if (da->da_ddr.ddr_type == DDR_NONE) { da->da_err = 0; return (0); } +#ifdef __FreeBSD__ da->da_err = write_bytes(da); +#else + da->da_err = vn_rdwr(UIO_WRITE, da->da_vp, (caddr_t)&da->da_ddr, + sizeof (da->da_ddr), 0, UIO_SYSSPACE, FAPPEND, + RLIM64_INFINITY, CRED(), &resid); +#endif *da->da_offp += sizeof (da->da_ddr); return (da->da_err); } @@ -180,10 +193,10 @@ int dmu_diff(const char *tosnap_name, const char *fromsnap_name, -#ifdef illumos - struct vnode *vp, offset_t *offp) -#else +#ifdef __FreeBSD__ struct file *fp, offset_t *offp) +#else + struct vnode *vp, offset_t *offp) #endif { struct diffarg da; @@ -227,12 +240,16 @@ dsl_dataset_long_hold(tosnap, FTAG); dsl_pool_rele(dp, FTAG); +#ifdef __FreeBSD__ + da.da_td = curthread; da.da_fp = fp; +#else + da.da_vp = vp; +#endif da.da_offp = offp; da.da_ddr.ddr_type = DDR_NONE; da.da_ddr.ddr_first = da.da_ddr.ddr_last = 0; da.da_err = 0; - da.da_td = curthread; error = traverse_dataset(tosnap, fromtxg, TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA, diff_cb, &da); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_send.c 2017-06-16 14:23:39.000000000 -0700 @@ -62,6 +62,28 @@ #define dump_write dmu_dump_write #endif +#ifdef __NetBSD__ +#ifdef _KERNEL +#define FOF_OFFSET FOF_UPDATE_OFFSET +#define td_ucred l_cred +#define bwillwrite() /* nothing */ + +static int +fo_write(struct file *fp, struct uio *uio, cred_t *cred, int flags, kthread_t *thr) +{ + + return (*fp->f_ops->fo_write)(fp, &fp->f_offset, uio, cred, flags); +} + +static int +fo_read(struct file *fp, struct uio *uio, cred_t *cred, int flags, kthread_t *thr) +{ + + return (*fp->f_ops->fo_read)(fp, &fp->f_offset, uio, cred, flags); +} +#endif +#endif + /* Set this tunable to TRUE to replace corrupt data with 0x2f5baddb10c */ int zfs_send_corrupt_data = B_FALSE; int zfs_send_queue_length = 16 * 1024 * 1024; @@ -127,10 +149,18 @@ auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_resid = len; +#ifdef __NetBSD__ +#ifdef _KERNEL + auio.uio_vmspace = vmspace_kernel(); +#endif +#else auio.uio_segflg = UIO_SYSSPACE; +#endif auio.uio_rw = UIO_WRITE; auio.uio_offset = (off_t)-1; +#ifdef __FreeBSD__ auio.uio_td = dsp->dsa_td; +#endif #ifdef _KERNEL if (dsp->dsa_fp->f_type == DTYPE_VNODE) bwillwrite(); @@ -1831,10 +1861,18 @@ auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_resid = len; +#ifdef __NetBSD__ +#ifdef _KERNEL + auio.uio_vmspace = vmspace_kernel(); +#endif +#else auio.uio_segflg = UIO_SYSSPACE; +#endif auio.uio_rw = UIO_READ; auio.uio_offset = off; +#ifdef __FreeBSD__ auio.uio_td = ra->td; +#endif #ifdef _KERNEL error = fo_read(ra->fp, &auio, ra->td->td_ucred, FOF_OFFSET, ra->td); #else diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_tx.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_tx.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_tx.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dmu_tx.c 2017-05-15 18:04:48.000000000 -0700 @@ -1145,10 +1145,14 @@ CALLOUT_FLAG_ABSOLUTE | CALLOUT_FLAG_ROUNDUP) > 0) continue; mutex_exit(&curthread->t_delay_lock); -#else +#endif +#ifdef __FreeBSD__ pause_sbt("dmu_tx_delay", wakeup * SBT_1NS, zfs_delay_resolution_ns * SBT_1NS, C_ABSOLUTE); #endif +#ifdef __NetBSD__ + kpause("dmu_tx_delay", false, (wakeup - now) * hz / 1000000000, NULL); +#endif #else hrtime_t delta = wakeup - gethrtime(); struct timespec ts; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dnode.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dnode.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dnode.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dnode.c 2017-04-25 17:42:13.000000000 -0700 @@ -107,6 +107,9 @@ dnode_t *dn = arg; int i; +#ifdef __NetBSD__ + dn = unused; +#endif rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL); mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL); mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL); @@ -168,6 +171,9 @@ int i; dnode_t *dn = arg; +#ifdef __NetBSD__ + dn = unused; +#endif rw_destroy(&dn->dn_struct_rwlock); mutex_destroy(&dn->dn_mtx); mutex_destroy(&dn->dn_dbufs_mtx); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dataset.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dataset.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dataset.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dataset.c 2017-04-28 17:45:23.000000000 -0700 @@ -997,7 +997,7 @@ return (dsobj); } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) /* FreeBSD ioctl compat begin */ struct destroyarg { nvlist_t *nvl; @@ -1035,7 +1035,7 @@ return (err); } /* FreeBSD ioctl compat end */ -#endif /* __FreeBSD__ */ +#endif /* defined(__FreeBSD__) || defined(__NetBSD__) */ /* * The unique space in the head dataset can be calculated by subtracting diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dir.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dir.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dir.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_dir.c 2017-04-17 16:36:24.000000000 -0700 @@ -707,11 +707,15 @@ prop == ZFS_PROP_SNAPSHOT_LIMIT); #ifdef _KERNEL +#ifdef illumos + if (crgetzoneid(cr) != GLOBAL_ZONEID) +#endif #ifdef __FreeBSD__ if (jailed(cr)) -#else - if (crgetzoneid(cr) != GLOBAL_ZONEID) #endif +#ifdef __NetBSD__ + if (0) +#endif return (ENFORCE_ALWAYS); if (secpolicy_zfs(cr) == 0) diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_pool.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_pool.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_pool.c 2017-01-24 09:21:52.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/dsl_pool.c 2017-04-28 08:42:59.000000000 -0700 @@ -431,6 +431,7 @@ rrw_destroy(&dp->dp_config_rwlock); mutex_destroy(&dp->dp_lock); + cv_destroy(&dp->dp_spaceavail_cv); taskq_destroy(dp->dp_vnrele_taskq); if (dp->dp_blkstats) kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/lz4.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/lz4.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/lz4.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/lz4.c 2017-04-25 09:40:13.000000000 -0700 @@ -44,7 +44,9 @@ static int LZ4_compress64kCtx(void *ctx, const char *source, char *dest, int isize, int osize); +#ifdef __FreeBSD__ static kmem_cache_t *lz4_ctx_cache; +#endif /*ARGSUSED*/ size_t @@ -839,7 +841,11 @@ real_LZ4_compress(const char *source, char *dest, int isize, int osize) { #if HEAPMODE +#ifdef __FreeBSD__ void *ctx = kmem_cache_alloc(lz4_ctx_cache, KM_NOSLEEP); +#else + void *ctx = kmem_zalloc(sizeof (struct refTables), KM_NOSLEEP); +#endif int result; /* @@ -855,7 +861,11 @@ else result = LZ4_compressCtx(ctx, source, dest, isize, osize); +#ifdef __FreeBSD__ kmem_cache_free(lz4_ctx_cache, ctx); +#else + kmem_free(ctx, sizeof (struct refTables)); +#endif return (result); #else if (isize < (int)LZ4_64KLIMIT) @@ -1005,6 +1015,8 @@ return (int)(-(((char *)ip) - source)); } +#ifdef __FreeBSD__ + extern void lz4_init(void) { @@ -1023,3 +1035,5 @@ kmem_cache_destroy(lz4_ctx_cache); #endif } + +#endif /* __FreeBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sa.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sa.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sa.c 2017-05-11 09:36:37.000000000 -0700 @@ -212,6 +212,9 @@ { sa_handle_t *hdl = buf; +#ifdef __NetBSD__ + hdl = unused; +#endif mutex_init(&hdl->sa_lock, NULL, MUTEX_DEFAULT, NULL); return (0); } @@ -221,6 +224,10 @@ sa_cache_destructor(void *buf, void *unused) { sa_handle_t *hdl = buf; + +#ifdef __NetBSD__ + hdl = unused; +#endif mutex_destroy(&hdl->sa_lock); } @@ -413,6 +420,9 @@ ASSERT(MUTEX_HELD(&sa->sa_lock)); tb = kmem_zalloc(sizeof (sa_lot_t), KM_SLEEP); tb->lot_attr_count = attr_count; +#ifdef __NetBSD__ + if (attr_count != 0) +#endif tb->lot_attrs = kmem_alloc(sizeof (sa_attr_type_t) * attr_count, KM_SLEEP); bcopy(attrs, tb->lot_attrs, sizeof (sa_attr_type_t) * attr_count); @@ -1136,6 +1146,9 @@ cookie = NULL; while (layout = avl_destroy_nodes(&sa->sa_layout_num_tree, &cookie)) { +#ifdef __NetBSD__ + if (layout->lot_attr_count != 0) +#endif kmem_free(layout->lot_attrs, sizeof (sa_attr_type_t) * layout->lot_attr_count); kmem_free(layout, sizeof (sa_lot_t)); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sha256.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sha256.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sha256.c 2016-06-27 20:14:25.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sha256.c 2017-06-27 17:06:33.000000000 -0700 @@ -27,6 +27,7 @@ */ #include #include +#ifdef __FreeBSD__ #ifdef _KERNEL #include #include @@ -34,6 +35,9 @@ #include #include #endif +#else +#include +#endif /*ARGSUSED*/ void @@ -60,6 +64,7 @@ zcp->zc_word[3] = BE_64(tmp.zc_word[3]); } +#ifndef __NetBSD__ /*ARGSUSED*/ void zio_checksum_SHA512_native(const void *buf, uint64_t size, @@ -85,3 +90,4 @@ zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]); zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]); } +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c 2017-03-26 23:19:45.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa.c 2017-04-30 07:02:00.000000000 -0700 @@ -978,7 +978,7 @@ if (tqs->stqs_count == 1) { tq = tqs->stqs_taskq[0]; } else { -#ifdef _KERNEL +#if defined(__FreeBSD__) && defined(_KERNEL) tq = tqs->stqs_taskq[cpu_ticks() % tqs->stqs_count]; #else tq = tqs->stqs_taskq[gethrtime() % tqs->stqs_count]; @@ -3924,6 +3924,7 @@ return (0); } +#ifndef __NetBSD__ #ifdef _KERNEL #ifdef illumos /* @@ -4321,6 +4322,7 @@ #endif /* illumos */ #endif /* _KERNEL */ +#endif /* !__NetBSD__ */ /* * Import a non-root pool into the system. @@ -6833,6 +6835,7 @@ * Sync the specified transaction group. New blocks may be dirtied as * part of the process, so we iterate until it converges. */ + void spa_sync(spa_t *spa, uint64_t txg) { @@ -6890,12 +6893,19 @@ #ifdef illumos VERIFY(cyclic_reprogram(spa->spa_deadman_cycid, spa->spa_sync_starttime + spa->spa_deadman_synctime)); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ #ifdef _KERNEL callout_schedule(&spa->spa_deadman_cycid, hz * spa->spa_deadman_synctime / NANOSEC); #endif -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +#ifdef _KERNEL + callout_schedule(&spa->spa_deadman_cycid, + hz * spa->spa_deadman_synctime / NANOSEC); +#endif +#endif /* * If we are upgrading to SPA_VERSION_RAIDZ_DEFLATE this txg, @@ -7081,11 +7091,17 @@ #ifdef illumos VERIFY(cyclic_reprogram(spa->spa_deadman_cycid, CY_INFINITY)); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ #ifdef _KERNEL callout_drain(&spa->spa_deadman_cycid); #endif -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +#ifdef _KERNEL + callout_drain(&spa->spa_deadman_cycid); +#endif +#endif /* __NetBSD__ */ /* * Clear the dirty config list. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_config.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_config.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_config.c 2016-05-31 04:20:10.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_config.c 2017-04-14 13:19:21.000000000 -0700 @@ -99,6 +99,9 @@ if (kobj_get_filesize(file, &fsize) != 0) goto out; + if (fsize == 0) + goto out; + buf = kmem_alloc(fsize, KM_SLEEP); /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_history.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_history.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_history.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_history.c 2017-04-14 13:24:24.000000000 -0700 @@ -183,10 +183,12 @@ spa_history_zone(void) { #ifdef _KERNEL +#ifdef __FreeBSD__ /* XXX: pr_hostname can be changed by default from within a jail! */ if (jailed(curthread->td_ucred)) return (curthread->td_ucred->cr_prison->pr_hostname); #endif +#endif return (NULL); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c 2017-03-26 23:19:45.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/spa_misc.c 2017-05-06 08:16:38.000000000 -0700 @@ -369,10 +369,11 @@ &spa_asize_inflation, 0, "Worst case inflation factor for single sector writes"); #endif -#ifndef illumos + +#ifdef __FreeBSD__ #ifdef _KERNEL static void -zfs_deadman_init() +zfs_deadman_init(void) { /* * If we are not i386 or amd64 or in a virtual machine, @@ -387,7 +388,43 @@ } } #endif /* _KERNEL */ -#endif /* !illumos */ +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +#ifdef _HARDKERNEL +static struct workqueue *spa_workqueue; + +static void spa_deadman(void *arg); + +static void +spa_deadman_wq(struct work *wk, void *arg) +{ + spa_t *spa = container_of(wk, struct spa, spa_deadman_work); + + spa_deadman(spa); +} + +static void +zfs_deadman_init(void) +{ + int error; + + error = workqueue_create(&spa_workqueue, "spa_deadman", + spa_deadman_wq, NULL, PRI_NONE, IPL_NONE, WQ_MPSAFE); + VERIFY0(error); +} + +static void +zfs_deadman_fini(void) +{ + workqueue_destroy(spa_workqueue); + spa_workqueue = NULL; +} +#else /* !_HARDKERNEL */ +#define zfs_deadman_init() /* nothing */ +#define zfs_deadman_fini() /* nothing */ +#endif /* !_HARDKERNEL */ +#endif /* __NetBSD__ */ /* * Normally, we don't allow the last 3.2% (1/(2^spa_slop_shift)) of space in @@ -598,7 +635,7 @@ * looking for potentially hung I/Os. */ static void -spa_deadman(void *arg, int pending) +spa_deadman(void *arg) { spa_t *spa = arg; @@ -619,7 +656,7 @@ ++spa->spa_deadman_calls); if (zfs_deadman_enabled) vdev_deadman(spa->spa_root_vdev); -#ifdef __FreeBSD__ +#ifndef illumos #ifdef _KERNEL callout_schedule(&spa->spa_deadman_cycid, hz * zfs_deadman_checktime_ms / MILLISEC); @@ -627,15 +664,20 @@ #endif } -#if defined(__FreeBSD__) && defined(_KERNEL) +#ifdef _HARDKERNEL static void spa_deadman_timeout(void *arg) { spa_t *spa = arg; +#ifdef __FreeBSD__ taskqueue_enqueue(taskqueue_thread, &spa->spa_deadman_task); -} #endif +#ifdef __NetBSD__ + workqueue_enqueue(spa_workqueue, &spa->spa_deadman_work, NULL); +#endif +} +#endif /* _KERNEL */ /* * Create an uninitialized spa_t with the given name. Requires @@ -647,7 +689,7 @@ { spa_t *spa; spa_config_dirent_t *dp; -#ifdef illumos +#ifndef __FreeBSD__ cyc_handler_t hdlr; cyc_time_t when; #endif @@ -686,7 +728,7 @@ spa->spa_proc = &p0; spa->spa_proc_state = SPA_PROC_NONE; -#ifdef illumos +#ifndef __FreeBSD__ hdlr.cyh_func = spa_deadman; hdlr.cyh_arg = spa; hdlr.cyh_level = CY_LOW_LEVEL; @@ -706,7 +748,8 @@ mutex_enter(&cpu_lock); spa->spa_deadman_cycid = cyclic_add(&hdlr, &when); mutex_exit(&cpu_lock); -#else /* !illumos */ +#endif +#ifdef __FreeBSD__ #ifdef _KERNEL /* * callout(9) does not provide a way to initialize a callout with @@ -727,6 +770,13 @@ spa_deadman_timeout, spa, 0); #endif #endif +#ifdef __NetBSD__ +#ifdef _HARDKERNEL + callout_init(&spa->spa_deadman_cycid, 0); + callout_setfunc(&spa->spa_deadman_cycid, spa_deadman_timeout, spa); +#endif +#endif + refcount_create(&spa->spa_refcount); spa_config_lock_init(spa); @@ -834,12 +884,18 @@ cyclic_remove(spa->spa_deadman_cycid); mutex_exit(&cpu_lock); spa->spa_deadman_cycid = CYCLIC_NONE; -#else /* !illumos */ +#endif /* !illumos */ +#ifdef __FreeBSD__ #ifdef _KERNEL callout_drain(&spa->spa_deadman_cycid); taskqueue_drain(taskqueue_thread, &spa->spa_deadman_task); #endif #endif +#ifdef __NetBSD__ +#ifdef _HARDKERNEL + callout_drain(&spa->spa_deadman_cycid); +#endif +#endif refcount_destroy(&spa->spa_refcount); @@ -1963,9 +2019,11 @@ spa_config_load(); } +#ifdef __FreeBSD__ #ifdef _KERNEL EVENTHANDLER_DEFINE(mountroot, spa_boot_init, NULL, 0); #endif +#endif void spa_init(int mode) @@ -2015,16 +2073,22 @@ zpool_feature_init(); spa_config_load(); l2arc_start(); -#ifndef illumos +#ifdef __FreeBSD__ #ifdef _KERNEL zfs_deadman_init(); #endif -#endif /* !illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + zfs_deadman_init(); +#endif } void spa_fini(void) { +#ifdef __NetBSD__ + zfs_deadman_fini(); +#endif l2arc_stop(); spa_evict_all(); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/dmu.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/dmu.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/dmu.h 2017-03-02 02:54:19.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/dmu.h 2017-04-22 00:57:28.000000000 -0700 @@ -45,6 +45,7 @@ */ #include +#include #include #include #include @@ -955,8 +956,14 @@ uint64_t object, uint64_t offset, int len); void dmu_traverse_objset(objset_t *os, uint64_t txg_start, dmu_traverse_cb_t cb, void *arg); + +#ifdef __FreeBSD__ int dmu_diff(const char *tosnap_name, const char *fromsnap_name, struct file *fp, offset_t *offp); +#else +int dmu_diff(const char *tosnap_name, const char *fromsnap_name, + struct vnode *vp, offset_t *offp); +#endif /* CRC64 table */ #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/refcount.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/refcount.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/refcount.h 2016-10-10 04:09:53.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/refcount.h 2017-04-16 15:01:06.000000000 -0700 @@ -28,7 +28,7 @@ #include #include -#include_next +//#include_next #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/spa_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/spa_impl.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/spa_impl.h 2017-03-02 02:54:19.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/spa_impl.h 2017-04-23 13:41:56.000000000 -0700 @@ -44,6 +44,10 @@ #include #include +#if defined(__NetBSD__) && defined(_HARDKERNEL) +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -264,12 +268,19 @@ uint64_t spa_feat_refcount_cache[SPA_FEATURES]; #ifdef illumos cyclic_id_t spa_deadman_cycid; /* cyclic id */ -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ #ifdef _KERNEL struct callout spa_deadman_cycid; /* callout id */ struct task spa_deadman_task; #endif -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +#ifdef _HARDKERNEL + struct callout spa_deadman_cycid; /* callout id */ + struct work spa_deadman_work; +#endif +#endif /* __NetBSD__ */ uint64_t spa_deadman_calls; /* number of deadman calls */ hrtime_t spa_sync_starttime; /* starting time fo spa_sync */ uint64_t spa_deadman_synctime; /* deadman expiration timer */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_disk.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_disk.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_disk.h 2014-01-12 18:59:34.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_disk.h 2017-06-09 22:31:45.000000000 -0700 @@ -31,7 +31,6 @@ #include #ifdef _KERNEL #include -#include #include #include #endif @@ -42,11 +41,18 @@ #ifdef _KERNEL typedef struct vdev_disk { +#ifdef illumos ddi_devid_t vd_devid; char *vd_minor; ldi_handle_t vd_lh; list_t vd_ldi_cbs; boolean_t vd_ldi_offline; +#endif +#ifdef __NetBSD__ + char *vd_minor; + vnode_t *vd_vp; + struct workqueue *vd_wq; +#endif } vdev_disk_t; #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_impl.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_impl.h 2016-10-10 04:09:53.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/vdev_impl.h 2017-04-17 17:03:28.000000000 -0700 @@ -361,7 +361,7 @@ extern vdev_ops_t vdev_mirror_ops; extern vdev_ops_t vdev_replacing_ops; extern vdev_ops_t vdev_raidz_ops; -#ifdef _KERNEL +#if defined(__FreeBSD__) && defined(_KERNEL) extern vdev_ops_t vdev_geom_ops; #else extern vdev_ops_t vdev_disk_ops; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ioctl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ioctl.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ioctl.h 2016-10-10 04:09:53.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_ioctl.h 2017-04-19 09:43:51.000000000 -0700 @@ -423,6 +423,8 @@ nvlist_t *zct_props; } zfs_creat_t; +extern dev_info_t *zfs_dip; + extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); extern int zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_znode.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_znode.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_znode.h 2016-10-10 04:09:53.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zfs_znode.h 2017-07-09 00:35:23.000000000 -0700 @@ -39,6 +39,10 @@ #include #include +#ifdef __NetBSD__ +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -134,6 +138,16 @@ #define ZFS_SHARES_DIR "SHARES" #define ZFS_SA_ATTRS "SA_ATTRS" +/* Path component length */ +/* + * The generic fs code uses MAXNAMELEN to represent + * what the largest component length is. Unfortunately, + * this length includes the terminating NULL. ZFS needs + * to tell the users via pathconf() and statvfs() what the + * true maximum length of a component is, excluding the NULL. + */ +#define ZFS_MAXNAMELEN (MAXNAMELEN - 1) + /* * Convert mode bits (zp_mode) to BSD-style DT_* values for storing in * the directory entries. @@ -167,6 +181,9 @@ } zfs_dirlock_t; typedef struct znode { +#ifdef __NetBSD__ + struct genfs_node z_gnode; +#endif struct zfsvfs *z_zfsvfs; vnode_t *z_vnode; uint64_t z_id; /* object ID for this znode */ @@ -199,6 +216,9 @@ list_node_t z_link_node; /* all znodes in fs link */ sa_handle_t *z_sa_hdl; /* handle to sa data */ boolean_t z_is_sa; /* are we native sa? */ +#ifdef __NetBSD__ + struct lockf *z_lockf; /* head of byte-level lock list */ +#endif } znode_t; @@ -311,6 +331,11 @@ extern int zfs_freesp(znode_t *, uint64_t, uint64_t, int, boolean_t); extern void zfs_znode_init(void); extern void zfs_znode_fini(void); +#ifdef __NetBSD__ +extern int zfs_loadvnode(struct mount *, struct vnode *, + const void *, size_t, const void **); +extern int zfs_zget_cleaner(zfsvfs_t *, uint64_t, znode_t **); +#endif extern int zfs_zget(zfsvfs_t *, uint64_t, znode_t **); extern int zfs_rezget(znode_t *); extern void zfs_zinactive(znode_t *); @@ -351,6 +376,9 @@ extern void zfs_upgrade(zfsvfs_t *zfsvfs, dmu_tx_t *tx); extern int zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx); +extern caddr_t zfs_map_page(page_t *, enum seg_rw); +extern void zfs_unmap_page(page_t *, caddr_t); + extern zil_get_data_t zfs_get_data; extern zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE]; extern int zfsfstype; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio.h 2017-03-26 23:19:45.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio.h 2017-06-27 17:02:45.000000000 -0700 @@ -83,8 +83,10 @@ ZIO_CHECKSUM_SHA256, ZIO_CHECKSUM_ZILOG2, ZIO_CHECKSUM_NOPARITY, +#ifndef __NetBSD__ ZIO_CHECKSUM_SHA512, ZIO_CHECKSUM_SKEIN, +#endif #ifdef illumos ZIO_CHECKSUM_EDONR, #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_checksum.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_checksum.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_checksum.h 2016-10-10 04:09:53.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_checksum.h 2017-06-27 17:01:51.000000000 -0700 @@ -82,6 +82,7 @@ * Checksum routines. */ extern zio_checksum_t zio_checksum_SHA256; +#ifndef __NetBSD__ extern zio_checksum_t zio_checksum_SHA512_native; extern zio_checksum_t zio_checksum_SHA512_byteswap; @@ -90,6 +91,7 @@ extern zio_checksum_t zio_checksum_skein_byteswap; extern zio_checksum_tmpl_init_t zio_checksum_skein_tmpl_init; extern zio_checksum_tmpl_free_t zio_checksum_skein_tmpl_free; +#endif #ifdef illumos /* Edon-R */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_compress.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_compress.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_compress.h 2014-07-30 21:37:13.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zio_compress.h 2017-04-25 09:39:46.000000000 -0700 @@ -70,8 +70,13 @@ int level); extern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len, int level); +#ifdef __FreeBSD__ extern void lz4_init(void); extern void lz4_fini(void); +#else +#define lz4_init() /* nothing */ +#define lz4_fini() /* nothing */ +#endif extern size_t lz4_compress(void *src, void *dst, size_t s_len, size_t d_len, int level); extern int lz4_decompress(void *src, void *dst, size_t s_len, size_t d_len, diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zvol.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zvol.h --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zvol.h 2015-02-03 23:24:13.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/sys/zvol.h 2017-04-19 08:49:30.000000000 -0700 @@ -45,16 +45,20 @@ extern void zvol_remove_minors(const char *); extern int zvol_set_volsize(const char *, uint64_t); -#ifdef illumos +#ifndef __FreeBSD__ extern int zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr); extern int zvol_dump(dev_t dev, caddr_t addr, daddr_t offset, int nblocks); extern int zvol_close(dev_t dev, int flag, int otyp, cred_t *cr); +#ifdef __NetBSD__ +extern void zvol_strategy(buf_t *bp); +#else extern int zvol_strategy(buf_t *bp); +#endif extern int zvol_read(dev_t dev, uio_t *uiop, cred_t *cr); extern int zvol_write(dev_t dev, uio_t *uiop, cred_t *cr); extern int zvol_aread(dev_t dev, struct aio_req *aio, cred_t *cr); extern int zvol_awrite(dev_t dev, struct aio_req *aio, cred_t *cr); -#endif /* illumos */ +#endif /* !__FreeBSD__ */ extern int zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp); extern int zvol_busy(void); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/trim_map.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/trim_map.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/trim_map.c 2015-02-03 23:24:13.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/trim_map.c 2017-04-22 03:02:25.000000000 -0700 @@ -555,10 +555,31 @@ spa_t *spa = arg; zio_t *zio; +#ifdef __FreeBSD__ #ifdef _KERNEL (void) snprintf(curthread->td_name, sizeof(curthread->td_name), "trim %s", spa_name(spa)); #endif +#endif +#ifdef __NetBSD__ +#ifdef _KERNEL + size_t sz; + char *name, *oname; + struct lwp *l = curlwp; + + name = kmem_alloc(MAXCOMLEN, KM_SLEEP); + snprintf(name, MAXCOMLEN, "trim %s", spa_name(spa)); + name[MAXCOMLEN - 1] = 0; + + lwp_lock(l); + oname = l->l_name; + l->l_name = name; + lwp_unlock(l); + + if (oname != NULL) + kmem_free(oname, MAXCOMLEN); +#endif +#endif for (;;) { mutex_enter(&spa->spa_trim_lock); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev.c 2016-12-03 09:03:49.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev.c 2017-05-04 06:47:07.000000000 -0700 @@ -92,6 +92,7 @@ static uint64_t zfs_max_auto_ashift = SPA_MAXASHIFT; static uint64_t zfs_min_auto_ashift = SPA_MINASHIFT; +#ifdef __FreeBSD__ static int sysctl_vfs_zfs_max_auto_ashift(SYSCTL_HANDLER_ARGS) { @@ -138,6 +139,7 @@ CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_RW, 0, sizeof(uint64_t), sysctl_vfs_zfs_min_auto_ashift, "QU", "Min ashift used when creating new top-level vdevs."); +#endif static vdev_ops_t *vdev_ops_table[] = { &vdev_root_ops, @@ -145,7 +147,7 @@ &vdev_mirror_ops, &vdev_replacing_ops, &vdev_spare_ops, -#ifdef _KERNEL +#if defined(__FreeBSD__) && defined(_KERNEL) &vdev_geom_ops, #else &vdev_disk_ops, @@ -3615,6 +3617,12 @@ "delta %lluns, last io %lluns", fio->io_timestamp, delta, vq->vq_io_complete_ts); + + printf("SLOW IO: zio timestamp %lluns, " + "delta %luns, last io %lluns", + fio->io_timestamp, delta, + vq->vq_io_complete_ts); + fm_panic("I/O to pool '%s' appears to be " "hung on vdev guid %llu at '%s'.", spa_name(spa), diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c 2017-05-11 19:10:16.000000000 -0700 @@ -26,28 +26,32 @@ */ #include -#include +#include #include #include #include #include #include #include -#include #include +#include +#include +#include + +#ifdef __NetBSD__ +static int +geterror(struct buf *bp) +{ + + return (bp->b_error); +} +#endif /* * Virtual device vector for disks. */ -extern ldi_ident_t zfs_li; - -static void vdev_disk_close(vdev_t *); - -typedef struct vdev_disk_ldi_cb { - list_node_t lcb_next; - ldi_callback_id_t lcb_id; -} vdev_disk_ldi_cb_t; +static void vdev_disk_io_intr(buf_t *); static void vdev_disk_alloc(vdev_t *vd) @@ -55,22 +59,29 @@ vdev_disk_t *dvd; dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP); + +#ifdef illumos /* * Create the LDI event callback list. */ list_create(&dvd->vd_ldi_cbs, sizeof (vdev_disk_ldi_cb_t), offsetof(vdev_disk_ldi_cb_t, lcb_next)); +#endif } + static void vdev_disk_free(vdev_t *vd) { vdev_disk_t *dvd = vd->vdev_tsd; +#ifdef illumos vdev_disk_ldi_cb_t *lcb; +#endif if (dvd == NULL) return; +#ifdef illumos /* * We have already closed the LDI handle. Clean up the LDI event * callbacks and free vd->vdev_tsd. @@ -81,196 +92,62 @@ kmem_free(lcb, sizeof (vdev_disk_ldi_cb_t)); } list_destroy(&dvd->vd_ldi_cbs); +#endif kmem_free(dvd, sizeof (vdev_disk_t)); vd->vdev_tsd = NULL; } -/* ARGSUSED */ -static int -vdev_disk_off_notify(ldi_handle_t lh, ldi_ev_cookie_t ecookie, void *arg, - void *ev_data) -{ - vdev_t *vd = (vdev_t *)arg; - vdev_disk_t *dvd = vd->vdev_tsd; - - /* - * Ignore events other than offline. - */ - if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0) - return (LDI_EV_SUCCESS); - /* - * All LDI handles must be closed for the state change to succeed, so - * call on vdev_disk_close() to do this. - * - * We inform vdev_disk_close that it is being called from offline - * notify context so it will defer cleanup of LDI event callbacks and - * freeing of vd->vdev_tsd to the offline finalize or a reopen. - */ - dvd->vd_ldi_offline = B_TRUE; - vdev_disk_close(vd); - - /* - * Now that the device is closed, request that the spa_async_thread - * mark the device as REMOVED and notify FMA of the removal. - */ - zfs_post_remove(vd->vdev_spa, vd); - vd->vdev_remove_wanted = B_TRUE; - spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE); - - return (LDI_EV_SUCCESS); -} - -/* ARGSUSED */ -static void -vdev_disk_off_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie, - int ldi_result, void *arg, void *ev_data) -{ - vdev_t *vd = (vdev_t *)arg; - - /* - * Ignore events other than offline. - */ - if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0) - return; - - /* - * We have already closed the LDI handle in notify. - * Clean up the LDI event callbacks and free vd->vdev_tsd. - */ - vdev_disk_free(vd); - - /* - * Request that the vdev be reopened if the offline state change was - * unsuccessful. - */ - if (ldi_result != LDI_EV_SUCCESS) { - vd->vdev_probe_wanted = B_TRUE; - spa_async_request(vd->vdev_spa, SPA_ASYNC_PROBE); - } -} - -static ldi_ev_callback_t vdev_disk_off_callb = { - .cb_vers = LDI_EV_CB_VERS, - .cb_notify = vdev_disk_off_notify, - .cb_finalize = vdev_disk_off_finalize -}; - -/* ARGSUSED */ +/* + * It's not clear what these hold/rele functions are supposed to do. + */ static void -vdev_disk_dgrd_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie, - int ldi_result, void *arg, void *ev_data) +vdev_disk_hold(vdev_t *vd) { - vdev_t *vd = (vdev_t *)arg; - /* - * Ignore events other than degrade. - */ - if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_DEGRADE) != 0) - return; + ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER)); - /* - * Degrade events always succeed. Mark the vdev as degraded. - * This status is purely informative for the user. - */ - (void) vdev_degrade(vd->vdev_spa, vd->vdev_guid, 0); } -static ldi_ev_callback_t vdev_disk_dgrd_callb = { - .cb_vers = LDI_EV_CB_VERS, - .cb_notify = NULL, - .cb_finalize = vdev_disk_dgrd_finalize -}; - static void -vdev_disk_hold(vdev_t *vd) +vdev_disk_rele(vdev_t *vd) { - ddi_devid_t devid; - char *minor; ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER)); - /* - * We must have a pathname, and it must be absolute. - */ - if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') - return; - - /* - * Only prefetch path and devid info if the device has - * never been opened. - */ - if (vd->vdev_tsd != NULL) - return; - - if (vd->vdev_wholedisk == -1ULL) { - size_t len = strlen(vd->vdev_path) + 3; - char *buf = kmem_alloc(len, KM_SLEEP); - - (void) snprintf(buf, len, "%ss0", vd->vdev_path); - - (void) ldi_vp_from_name(buf, &vd->vdev_name_vp); - kmem_free(buf, len); - } - - if (vd->vdev_name_vp == NULL) - (void) ldi_vp_from_name(vd->vdev_path, &vd->vdev_name_vp); - - if (vd->vdev_devid != NULL && - ddi_devid_str_decode(vd->vdev_devid, &devid, &minor) == 0) { - (void) ldi_vp_from_devid(devid, minor, &vd->vdev_devid_vp); - ddi_devid_str_free(minor); - ddi_devid_free(devid); - } } static void -vdev_disk_rele(vdev_t *vd) +vdev_disk_flush(struct work *work, void *cookie) { - ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER)); + vdev_disk_t *dvd; + int error, cmd; + buf_t *bp; + vnode_t *vp; - if (vd->vdev_name_vp) { - VN_RELE_ASYNC(vd->vdev_name_vp, - dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool)); - vd->vdev_name_vp = NULL; - } - if (vd->vdev_devid_vp) { - VN_RELE_ASYNC(vd->vdev_devid_vp, - dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool)); - vd->vdev_devid_vp = NULL; - } + bp = (struct buf *)work; + vp = bp->b_vp; + dvd = cookie; + + KASSERT(vp == dvd->vd_vp); + + cmd = 1; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = VOP_IOCTL(vp, DIOCCACHESYNC, &cmd, FREAD|FWRITE, kcred); + VOP_UNLOCK(vp, 0); + bp->b_error = error; + vdev_disk_io_intr(bp); } -/* - * We want to be loud in DEBUG kernels when DKIOCGMEDIAINFOEXT fails, or when - * even a fallback to DKIOCGMEDIAINFO fails. - */ -#ifdef DEBUG -#define VDEV_DEBUG(...) cmn_err(CE_NOTE, __VA_ARGS__) -#else -#define VDEV_DEBUG(...) /* Nothing... */ -#endif - static int vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize, - uint64_t *ashift) + uint64_t *ashift, uint64_t *pashift) { spa_t *spa = vd->vdev_spa; - vdev_disk_t *dvd = vd->vdev_tsd; - ldi_ev_cookie_t ecookie; - vdev_disk_ldi_cb_t *lcb; - union { - struct dk_minfo_ext ude; - struct dk_minfo ud; - } dks; - struct dk_minfo_ext *dkmext = &dks.ude; - struct dk_minfo *dkm = &dks.ud; - int error; - dev_t dev; - int otyp; - boolean_t validate_devid = B_FALSE; - ddi_devid_t devid; - uint64_t capacity = 0, blksz = 0, pbsize; + vdev_disk_t *dvd; + vnode_t *vp; + int error, cmd; + struct partinfo pinfo; /* * We must have a pathname, and it must be absolute. @@ -284,18 +161,12 @@ * Reopen the device if it's not currently open. Otherwise, * just update the physical size of the device. */ - if (dvd != NULL) { - if (dvd->vd_ldi_offline && dvd->vd_lh == NULL) { - /* - * If we are opening a device in its offline notify - * context, the LDI handle was just closed. Clean - * up the LDI event callbacks and free vd->vdev_tsd. - */ - vdev_disk_free(vd); - } else { - ASSERT(vd->vdev_reopening); - goto skip_open; - } + if (vd->vdev_tsd != NULL) { + ASSERT(vd->vdev_reopening); + dvd = vd->vdev_tsd; + vp = dvd->vd_vp; + KASSERT(vp != NULL); + goto skip_open; } /* @@ -321,226 +192,62 @@ * by the devid instead. */ if (vd->vdev_devid != NULL) { + /* XXXNETBSD wedges */ +#ifdef illumos if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid, &dvd->vd_minor) != 0) { vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; return (SET_ERROR(EINVAL)); } +#endif } error = EINVAL; /* presume failure */ - if (vd->vdev_path != NULL) { - - if (vd->vdev_wholedisk == -1ULL) { - size_t len = strlen(vd->vdev_path) + 3; - char *buf = kmem_alloc(len, KM_SLEEP); - - (void) snprintf(buf, len, "%ss0", vd->vdev_path); - - error = ldi_open_by_name(buf, spa_mode(spa), kcred, - &dvd->vd_lh, zfs_li); - if (error == 0) { - spa_strfree(vd->vdev_path); - vd->vdev_path = buf; - vd->vdev_wholedisk = 1ULL; - } else { - kmem_free(buf, len); - } - } - - /* - * If we have not yet opened the device, try to open it by the - * specified path. - */ - if (error != 0) { - error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), - kcred, &dvd->vd_lh, zfs_li); - } - - /* - * Compare the devid to the stored value. - */ - if (error == 0 && vd->vdev_devid != NULL && - ldi_get_devid(dvd->vd_lh, &devid) == 0) { - if (ddi_devid_compare(devid, dvd->vd_devid) != 0) { - error = SET_ERROR(EINVAL); - (void) ldi_close(dvd->vd_lh, spa_mode(spa), - kcred); - dvd->vd_lh = NULL; - } - ddi_devid_free(devid); - } - - /* - * If we succeeded in opening the device, but 'vdev_wholedisk' - * is not yet set, then this must be a slice. - */ - if (error == 0 && vd->vdev_wholedisk == -1ULL) - vd->vdev_wholedisk = 0; - } - - /* - * If we were unable to open by path, or the devid check fails, open by - * devid instead. - */ - if (error != 0 && vd->vdev_devid != NULL) { - error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor, - spa_mode(spa), kcred, &dvd->vd_lh, zfs_li); - } - - /* - * If all else fails, then try opening by physical path (if available) - * or the logical path (if we failed due to the devid check). While not - * as reliable as the devid, this will give us something, and the higher - * level vdev validation will prevent us from opening the wrong device. - */ - if (error) { - if (vd->vdev_devid != NULL) - validate_devid = B_TRUE; - - if (vd->vdev_physpath != NULL && - (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV) - error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa), - kcred, &dvd->vd_lh, zfs_li); - - /* - * Note that we don't support the legacy auto-wholedisk support - * as above. This hasn't been used in a very long time and we - * don't need to propagate its oddities to this edge condition. - */ - if (error && vd->vdev_path != NULL) - error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), - kcred, &dvd->vd_lh, zfs_li); + error = vn_open(vd->vdev_path, UIO_SYSSPACE, FREAD|FWRITE, 0, + &vp, CRCREAT, 0); + if (error != 0) { + vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; + return (SET_ERROR(error)); } - - if (error) { + if (vp->v_type != VBLK) { + vrele(vp); vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; - return (error); + return (SET_ERROR(EINVAL)); } /* - * Now that the device has been successfully opened, update the devid - * if necessary. + * XXXNETBSD Compare the devid to the stored value. */ - if (validate_devid && spa_writeable(spa) && - ldi_get_devid(dvd->vd_lh, &devid) == 0) { - if (ddi_devid_compare(devid, dvd->vd_devid) != 0) { - char *vd_devid; - - vd_devid = ddi_devid_str_encode(devid, dvd->vd_minor); - zfs_dbgmsg("vdev %s: update devid from %s, " - "to %s", vd->vdev_path, vd->vdev_devid, vd_devid); - spa_strfree(vd->vdev_devid); - vd->vdev_devid = spa_strdup(vd_devid); - ddi_devid_str_free(vd_devid); - } - ddi_devid_free(devid); - } /* - * Once a device is opened, verify that the physical device path (if - * available) is up to date. + * Create a workqueue to process cache-flushes concurrently. */ - if (ldi_get_dev(dvd->vd_lh, &dev) == 0 && - ldi_get_otyp(dvd->vd_lh, &otyp) == 0) { - char *physpath, *minorname; - - physpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); - minorname = NULL; - if (ddi_dev_pathname(dev, otyp, physpath) == 0 && - ldi_get_minor_name(dvd->vd_lh, &minorname) == 0 && - (vd->vdev_physpath == NULL || - strcmp(vd->vdev_physpath, physpath) != 0)) { - if (vd->vdev_physpath) - spa_strfree(vd->vdev_physpath); - (void) strlcat(physpath, ":", MAXPATHLEN); - (void) strlcat(physpath, minorname, MAXPATHLEN); - vd->vdev_physpath = spa_strdup(physpath); - } - if (minorname) - kmem_free(minorname, strlen(minorname) + 1); - kmem_free(physpath, MAXPATHLEN); + error = workqueue_create(&dvd->vd_wq, "vdevsync", + vdev_disk_flush, dvd, PRI_NONE, IPL_NONE, WQ_MPSAFE); + if (error != 0) { + vrele(vp); + return (SET_ERROR(error)); } - /* - * Register callbacks for the LDI offline event. - */ - if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_OFFLINE, &ecookie) == - LDI_EV_SUCCESS) { - lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP); - list_insert_tail(&dvd->vd_ldi_cbs, lcb); - (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie, - &vdev_disk_off_callb, (void *) vd, &lcb->lcb_id); - } + dvd->vd_vp = vp; - /* - * Register callbacks for the LDI degrade event. - */ - if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_DEGRADE, &ecookie) == - LDI_EV_SUCCESS) { - lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP); - list_insert_tail(&dvd->vd_ldi_cbs, lcb); - (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie, - &vdev_disk_dgrd_callb, (void *) vd, &lcb->lcb_id); - } skip_open: /* * Determine the actual size of the device. + * XXXNETBSD wedges. */ - if (ldi_get_size(dvd->vd_lh, psize) != 0) { + error = VOP_IOCTL(vp, DIOCGPARTINFO, &pinfo, FREAD|FWRITE, kcred); + if (error != 0) { vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; - return (SET_ERROR(EINVAL)); + return (SET_ERROR(error)); } - + *psize = pinfo.pi_size * pinfo.pi_secsize; *max_psize = *psize; - /* - * Determine the device's minimum transfer size. - * If the ioctl isn't supported, assume DEV_BSIZE. - */ - if ((error = ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT, - (intptr_t)dkmext, FKIOCTL, kcred, NULL)) == 0) { - capacity = dkmext->dki_capacity - 1; - blksz = dkmext->dki_lbsize; - pbsize = dkmext->dki_pbsize; - } else if ((error = ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFO, - (intptr_t)dkm, FKIOCTL, kcred, NULL)) == 0) { - VDEV_DEBUG( - "vdev_disk_open(\"%s\"): fallback to DKIOCGMEDIAINFO\n", - vd->vdev_path); - capacity = dkm->dki_capacity - 1; - blksz = dkm->dki_lbsize; - pbsize = blksz; - } else { - VDEV_DEBUG("vdev_disk_open(\"%s\"): " - "both DKIOCGMEDIAINFO{,EXT} calls failed, %d\n", - vd->vdev_path, error); - pbsize = DEV_BSIZE; - } - - *ashift = highbit64(MAX(pbsize, SPA_MINBLOCKSIZE)) - 1; - - if (vd->vdev_wholedisk == 1) { - int wce = 1; - - if (error == 0) { - /* - * If we have the capability to expand, we'd have - * found out via success from DKIOCGMEDIAINFO{,EXT}. - * Adjust max_psize upward accordingly since we know - * we own the whole disk now. - */ - *max_psize = capacity * blksz; - } - - /* - * Since we own the whole disk, try to enable disk write - * caching. We ignore errors because it's OK if we can't do it. - */ - (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce, - FKIOCTL, kcred, NULL); - } + *ashift = highbit(MAX(pinfo.pi_secsize, SPA_MINBLOCKSIZE)) - 1; + *pashift = *ashift; + vd->vdev_wholedisk = (pinfo.pi_offset == 0); /* XXXNETBSD */ /* * Clear the nowritecache bit, so that on a vdev_reopen() we will @@ -559,6 +266,7 @@ if (vd->vdev_reopening || dvd == NULL) return; +#ifdef illumos if (dvd->vd_minor != NULL) { ddi_devid_str_free(dvd->vd_minor); dvd->vd_minor = NULL; @@ -573,8 +281,21 @@ (void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred); dvd->vd_lh = NULL; } +#endif + +#ifdef __NetBSD__ + if (dvd->vd_vp != NULL) { + vn_close(dvd->vd_vp, FREAD|FWRITE, kcred); + dvd->vd_vp = NULL; + } + if (dvd->vd_wq != NULL) { + workqueue_destroy(dvd->vd_wq); + dvd->vd_wq = NULL; + } +#endif vd->vdev_delayed_close = B_FALSE; +#ifdef illumos /* * If we closed the LDI handle due to an offline notify from LDI, * don't free vd->vdev_tsd or unregister the callbacks here; @@ -582,6 +303,7 @@ */ if (dvd->vd_ldi_offline) return; +#endif vdev_disk_free(vd); } @@ -590,6 +312,7 @@ vdev_disk_physio(vdev_t *vd, caddr_t data, size_t size, uint64_t offset, int flags, boolean_t isdump) { +#ifdef illumos vdev_disk_t *dvd = vd->vdev_tsd; /* @@ -612,41 +335,16 @@ } return (vdev_disk_ldi_physio(dvd->vd_lh, data, size, offset, flags)); -} - -int -vdev_disk_ldi_physio(ldi_handle_t vd_lh, caddr_t data, - size_t size, uint64_t offset, int flags) -{ - buf_t *bp; - int error = 0; - - if (vd_lh == NULL) - return (SET_ERROR(EINVAL)); - - ASSERT(flags & B_READ || flags & B_WRITE); - - bp = getrbuf(KM_SLEEP); - bp->b_flags = flags | B_BUSY | B_NOCACHE | B_FAILFAST; - bp->b_bcount = size; - bp->b_un.b_addr = (void *)data; - bp->b_lblkno = lbtodb(offset); - bp->b_bufsize = size; - - error = ldi_strategy(vd_lh, bp); - ASSERT(error == 0); - if ((error = biowait(bp)) == 0 && bp->b_resid != 0) - error = SET_ERROR(EIO); - freerbuf(bp); - - return (error); +#endif +#ifdef __NetBSD__ + return (EIO); +#endif } static void vdev_disk_io_intr(buf_t *bp) { - vdev_buf_t *vb = (vdev_buf_t *)bp; - zio_t *zio = vb->vb_io; + zio_t *zio = bp->b_private; /* * The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO. @@ -658,8 +356,7 @@ if (zio->io_error == 0 && bp->b_resid != 0) zio->io_error = SET_ERROR(EIO); - kmem_free(vb, sizeof (vdev_buf_t)); - + putiobuf(bp); zio_delay_interrupt(zio); } @@ -689,20 +386,29 @@ { vdev_t *vd = zio->io_vd; vdev_disk_t *dvd = vd->vdev_tsd; - vdev_buf_t *vb; - struct dk_callback *dkc; - buf_t *bp; - int error; + vnode_t *vp; + buf_t *bp, *nbp; + int error, size, off, resid; /* * If the vdev is closed, it's likely in the REMOVED or FAULTED state. * Nothing to be done here but return failure. */ +#ifdef illumos if (dvd == NULL || (dvd->vd_ldi_offline && dvd->vd_lh == NULL)) { zio->io_error = SET_ERROR(ENXIO); zio_interrupt(zio); return; } +#endif +#ifdef __NetBSD__ + if (dvd == NULL) { + zio->io_error = SET_ERROR(ENXIO); + zio_interrupt(zio); + return; + } + vp = dvd->vd_vp; +#endif if (zio->io_type == ZIO_TYPE_IOCTL) { /* XXPOLICY */ @@ -713,84 +419,73 @@ } switch (zio->io_cmd) { - case DKIOCFLUSHWRITECACHE: if (zfs_nocacheflush) break; if (vd->vdev_nowritecache) { - zio->io_error = SET_ERROR(ENOTSUP); + zio->io_error = ENOTSUP; break; } - zio->io_vsd = dkc = kmem_alloc(sizeof (*dkc), KM_SLEEP); - zio->io_vsd_ops = &vdev_disk_vsd_ops; - - dkc->dkc_callback = vdev_disk_ioctl_done; - dkc->dkc_flag = FLUSH_VOLATILE; - dkc->dkc_cookie = zio; - - error = ldi_ioctl(dvd->vd_lh, zio->io_cmd, - (uintptr_t)dkc, FKIOCTL, kcred, NULL); - - if (error == 0) { - /* - * The ioctl will be done asychronously, - * and will call vdev_disk_ioctl_done() - * upon completion. - */ - return; - } - - if (error == ENOTSUP || error == ENOTTY) { - /* - * If we get ENOTSUP or ENOTTY, we know that - * no future attempts will ever succeed. - * In this case we set a persistent bit so - * that we don't bother with the ioctl in the - * future. - */ - vd->vdev_nowritecache = B_TRUE; - } - zio->io_error = error; - - break; + bp = getiobuf(vp, true); + bp->b_private = zio; + workqueue_enqueue(dvd->vd_wq, &bp->b_work, NULL); + return; default: zio->io_error = SET_ERROR(ENOTSUP); + break; } zio_execute(zio); return; } - ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE); - zio->io_target_timestamp = zio_handle_io_delay(zio); - - vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP); - - vb->vb_io = zio; - bp = &vb->vb_buf; - - bioinit(bp); - bp->b_flags = B_BUSY | B_NOCACHE | - (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE); - if (!(zio->io_flags & (ZIO_FLAG_IO_RETRY | ZIO_FLAG_TRYHARD))) - bp->b_flags |= B_FAILFAST; + bp = getiobuf(vp, true); + bp->b_flags = (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE); + bp->b_cflags = BC_BUSY | BC_NOCACHE; + bp->b_data = zio->io_data; + bp->b_blkno = btodb(zio->io_offset); bp->b_bcount = zio->io_size; - bp->b_un.b_addr = zio->io_data; - bp->b_lblkno = lbtodb(zio->io_offset); - bp->b_bufsize = zio->io_size; - bp->b_iodone = (int (*)())vdev_disk_io_intr; + bp->b_resid = zio->io_size; + bp->b_iodone = vdev_disk_io_intr; + bp->b_private = zio; + + if (!(bp->b_flags & B_READ)) { + mutex_enter(vp->v_interlock); + vp->v_numoutput++; + mutex_exit(vp->v_interlock); + } - /* ldi_strategy() will return non-zero only on programming errors */ - VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0); + if (bp->b_bcount <= MAXPHYS) { + /* We can do this I/O in one pass. */ + (void)VOP_STRATEGY(vp, bp); + } else { + /* + * The I/O is larger than we can process in one pass. + * Split it into smaller pieces. + */ + resid = zio->io_size; + off = 0; + while (resid != 0) { + size = min(resid, MAXPHYS); + nbp = getiobuf(vp, true); + nbp->b_blkno = btodb(zio->io_offset + off); + /* Below call increments v_numoutput. */ + nestiobuf_setup(bp, nbp, off, size); + (void)VOP_STRATEGY(vp, nbp); + resid -= size; + off += size; + } + } } static void vdev_disk_io_done(zio_t *zio) { +#ifdef illumos vdev_t *vd = zio->io_vd; /* @@ -818,6 +513,7 @@ vd->vdev_delayed_close = B_TRUE; } } +#endif } vdev_ops_t vdev_disk_ops = { @@ -840,6 +536,9 @@ int vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config) { +#ifdef __NetBSD__ + return (ENOTSUP); +#else ldi_handle_t vd_lh; vdev_label_t *label; uint64_t s, size; @@ -910,4 +609,5 @@ error = SET_ERROR(EIDRM); return (error); +#endif } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_file.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_file.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_file.c 2016-03-26 19:52:19.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_file.c 2017-05-05 11:02:28.000000000 -0700 @@ -101,14 +101,10 @@ * Make sure it's a regular file. */ if (vp->v_type != VREG) { -#ifdef __FreeBSD__ (void) VOP_CLOSE(vp, spa_mode(vd->vdev_spa), 1, 0, kcred, NULL); -#endif - vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; -#ifdef __FreeBSD__ kmem_free(vd->vdev_tsd, sizeof (vdev_file_t)); vd->vdev_tsd = NULL; -#endif + vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; return (SET_ERROR(ENODEV)); } #endif /* _KERNEL */ @@ -118,9 +114,14 @@ * Determine the physical size of the file. */ vattr.va_mask = AT_SIZE; +#ifdef __FreeBSD__ vn_lock(vp, LK_SHARED | LK_RETRY); error = VOP_GETATTR(vp, &vattr, kcred); VOP_UNLOCK(vp, 0); +#endif +#ifdef __NetBSD__ + error = VOP_GETATTR(vp, &vattr, 0, kcred, NULL); +#endif if (error) { (void) VOP_CLOSE(vp, spa_mode(vd->vdev_spa), 1, 0, kcred, NULL); vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_mirror.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_mirror.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_mirror.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_mirror.c 2017-04-17 17:26:18.000000000 -0700 @@ -58,11 +58,13 @@ static int vdev_mirror_shift = 21; +#ifdef __FreeBSD__ #ifdef _KERNEL SYSCTL_DECL(_vfs_zfs_vdev); static SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, mirror, CTLFLAG_RD, 0, "ZFS VDEV Mirror"); #endif +#endif /* * The load configuration settings below are tuned by default for diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_raidz.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_raidz.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_raidz.c 2016-03-26 19:52:21.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_raidz.c 2017-05-05 11:03:34.000000000 -0700 @@ -29,7 +29,7 @@ #include #include #include -#ifdef illumos +#ifndef __FreeBSD__ #include #endif #include @@ -38,7 +38,9 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif /* * Virtual device vector for RAID-Z. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zap_micro.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zap_micro.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zap_micro.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zap_micro.c 2017-05-06 16:27:27.000000000 -0700 @@ -861,8 +861,9 @@ } else { *(uint64_t *)buf = MZE_PHYS(zap, mze)->mze_value; - (void) strlcpy(realname, - MZE_PHYS(zap, mze)->mze_name, rn_len); + if (realname != NULL) + (void) strlcpy(realname, + MZE_PHYS(zap, mze)->mze_name, rn_len); if (ncp) { *ncp = mzap_normalization_conflict(zap, zn, mze); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_acl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_acl.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_acl.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_acl.c 2017-05-04 13:15:44.000000000 -0700 @@ -1602,7 +1602,9 @@ boolean_t trim = B_FALSE; boolean_t inherited = B_FALSE; +#ifndef __NetBSD__ ASSERT_VOP_ELOCKED(ZTOV(dzp), __func__); +#endif bzero(acl_ids, sizeof (zfs_acl_ids_t)); acl_ids->z_mode = MAKEIMODE(vap->va_type, vap->va_mode); @@ -2349,7 +2351,7 @@ is_attr = ((zp->z_pflags & ZFS_XATTR) && (ZTOV(zp)->v_type == VDIR)); -#ifdef __FreeBSD_kernel__ +#ifndef illumos /* * In FreeBSD, we don't care about permissions of individual ADS. * Note that not checking them is not just an optimization - without diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c 2017-05-11 16:15:03.000000000 -0700 @@ -65,6 +65,8 @@ * so that it cannot be freed until all snapshots have been unmounted. */ +#ifdef __FreeBSD__ + #include #include #include @@ -1255,3 +1257,17 @@ return (error); } +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ + +#include +#include + +boolean_t +zfsctl_is_node(vnode_t *vp) +{ + + return B_FALSE; +} +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_dir.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_dir.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_dir.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_dir.c 2017-04-28 14:13:09.000000000 -0700 @@ -41,9 +41,11 @@ #include #include #include +#ifdef __FreeBSD__ #include #include #include +#endif #include #include #include @@ -375,7 +377,9 @@ int error; ASSERT(zp->z_links == 0); +#ifndef __NetBSD__ ASSERT_VOP_ELOCKED(ZTOV(zp), __func__); +#endif /* * If this is an attribute directory, purge its contents. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c 2016-12-03 09:03:49.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c 2017-09-13 00:55:04.000000000 -0700 @@ -141,6 +141,7 @@ #include #include #include +#include #include #include #include @@ -175,7 +176,13 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif +#ifdef __NetBSD__ +#include +#include +#endif #include #include #include @@ -198,12 +205,24 @@ #include "zfs_comutil.h" #include "zfs_ioctl_compat.h" +#ifdef __FreeBSD__ CTASSERT(sizeof(zfs_cmd_t) < IOCPARM_MAX); - static struct cdev *zfsdev; +#endif + +#ifdef __NetBSD__ +static int zfs_cmajor = -1; +static int zfs_bmajor = -1; +dev_info_t *zfs_dip; + +#define ddi_driver_major(x) zfs_cmajor -extern void zfs_init(void); -extern void zfs_fini(void); +#define zfs_init() /* nothing */ +#define zfs_fini() /* nothing */ + +#define vfs_busy(x, y) vfs_busy(x) +#define vfs_rel(x) vfs_rele(x) +#endif uint_t zfs_fsyncer_key; extern uint_t rrw_tsd_key; @@ -255,7 +274,9 @@ int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *); static int get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp); +#ifdef __FreeBSD__ static void zfsdev_close(void *data); +#endif static int zfs_prop_activate_feature(spa_t *spa, spa_feature_t feature); @@ -462,8 +483,12 @@ { uint64_t zoned; +#ifdef __NetBSD__ + zoned = 0; +#else if (dsl_prop_get_integer(dataset, "jailed", &zoned, NULL)) return (SET_ERROR(ENOENT)); +#endif return (zfs_dozonecheck_impl(dataset, zoned, cr)); } @@ -473,8 +498,12 @@ { uint64_t zoned; +#ifdef __NetBSD__ + zoned = 0; +#else if (dsl_prop_get_int_ds(ds, "jailed", &zoned)) return (SET_ERROR(ENOENT)); +#endif return (zfs_dozonecheck_impl(dataset, zoned, cr)); } @@ -3038,6 +3067,7 @@ { vfs_t *vfsp; +#ifdef __FreeBSD__ mtx_lock(&mountlist_mtx); TAILQ_FOREACH(vfsp, &mountlist, mnt_list) { if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) { @@ -3048,6 +3078,21 @@ } if (vfsp == NULL) mtx_unlock(&mountlist_mtx); +#endif +#ifdef __NetBSD__ + mount_iterator_t *iter; + + mountlist_iterator_init(&iter); + while ((vfsp = mountlist_iterator_next(iter)) != NULL) { + if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) { + if (vfs_busy(vfsp, 0) != 0) + vfsp = NULL; + break; + } + } + mountlist_iterator_destroy(iter); +#endif + return (vfsp); } @@ -4341,7 +4386,9 @@ char *origin = NULL; char *tosnap; char tofs[ZFS_MAX_DATASET_NAME_LEN]; +#ifdef __FreeBSD__ cap_rights_t rights; +#endif boolean_t first_recvd_props = B_FALSE; if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 || @@ -4359,10 +4406,10 @@ return (error); fd = zc->zc_cookie; -#ifdef illumos - fp = getf(fd); -#else +#ifdef __FreeBSD__ fget_read(curthread, fd, cap_rights_init(&rights, CAP_PREAD), &fp); +#else + fp = getf(fd); #endif if (fp == NULL) { nvlist_free(props); @@ -4638,13 +4685,13 @@ dsl_pool_rele(dp, FTAG); } else { file_t *fp; +#ifdef __FreeBSD__ cap_rights_t rights; -#ifdef illumos - fp = getf(zc->zc_cookie); -#else fget_write(curthread, zc->zc_cookie, cap_rights_init(&rights, CAP_WRITE), &fp); +#else + fp = getf(zc->zc_cookie); #endif if (fp == NULL) return (SET_ERROR(EBADF)); @@ -5244,25 +5291,26 @@ zfs_ioc_diff(zfs_cmd_t *zc) { file_t *fp; - cap_rights_t rights; offset_t off; int error; -#ifdef illumos - fp = getf(zc->zc_cookie); -#else +#ifdef __FreeBSD__ + cap_rights_t rights; + fget_write(curthread, zc->zc_cookie, cap_rights_init(&rights, CAP_WRITE), &fp); +#else + fp = getf(zc->zc_cookie); #endif if (fp == NULL) return (SET_ERROR(EBADF)); off = fp->f_offset; -#ifdef illumos - error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off); -#else +#ifdef __FreeBSD__ error = dmu_diff(zc->zc_name, zc->zc_value, fp, &off); +#else + error = dmu_diff(zc->zc_name, zc->zc_value, fp->f_vnode, &off); #endif if (off >= 0 && off <= MAXOFFSET_T) @@ -5608,6 +5656,8 @@ return (error); } +#ifdef __FreeBSD__ + static int zfs_ioc_jail(zfs_cmd_t *zc) { @@ -5624,6 +5674,8 @@ (int)zc->zc_jailid)); } +#endif + /* * innvl: { * "fd" -> file descriptor to write stream to (int32) @@ -5642,8 +5694,6 @@ static int zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl) { - cap_rights_t rights; - file_t *fp; int error; offset_t off; char *fromname = NULL; @@ -5665,10 +5715,12 @@ (void) nvlist_lookup_uint64(innvl, "resume_object", &resumeobj); (void) nvlist_lookup_uint64(innvl, "resume_offset", &resumeoff); -#ifdef illumos - file_t *fp = getf(fd); -#else +#ifdef __FreeBSD__ + cap_rights_t rights; + fget_write(curthread, fd, cap_rights_init(&rights, CAP_WRITE), &fp); +#else + file_t *fp = getf(fd); #endif if (fp == NULL) return (SET_ERROR(EBADF)); @@ -6131,8 +6183,13 @@ return (0); } +#ifdef __FreeBSD__ static int zfs_ctldev_init(struct cdev *devp) +#else +static int +zfs_ctldev_init(dev_t *devp) +#endif { minor_t minor; zfs_soft_state_t *zs; @@ -6146,7 +6203,9 @@ if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS) return (SET_ERROR(EAGAIN)); +#ifdef __FreeBSD__ devfs_set_cdevpriv((void *)(uintptr_t)minor, zfsdev_close); +#endif zs = ddi_get_soft_state(zfsdev_state, minor); zs->zss_type = ZSST_CTLDEV; @@ -6176,12 +6235,18 @@ return (zp->zss_data); } +#ifdef __FreeBSD__ static int zfsdev_open(struct cdev *devp, int flag, int mode, struct thread *td) +#endif +#ifdef __NetBSD__ +static int +zfsdev_open(dev_t *devp, int flag, int otyp, cred_t *cr) +#endif { int error = 0; -#ifdef illumos +#ifndef __FreeBSD__ if (getminor(*devp) != 0) return (zvol_open(devp, flag, otyp, cr)); #endif @@ -6196,49 +6261,90 @@ return (error); } +#ifdef __FreeBSD__ static void zfsdev_close(void *data) +#endif +#ifdef __NetBSD__ +static int +zfsdev_close(dev_t dev, int flag, int otyp, cred_t *cr) +#endif { zfs_onexit_t *zo; +#ifdef __FreeBSD__ minor_t minor = (minor_t)(uintptr_t)data; +#endif +#ifdef __NetBSD__ + minor_t minor = getminor(dev); +#endif if (minor == 0) +#ifdef __FreeBSD__ return; +#else + return (0); +#endif mutex_enter(&spa_namespace_lock); zo = zfsdev_get_soft_state(minor, ZSST_CTLDEV); if (zo == NULL) { mutex_exit(&spa_namespace_lock); +#ifdef __FreeBSD__ return; +#else + return 0; +#endif } zfs_ctldev_destroy(zo, minor); mutex_exit(&spa_namespace_lock); + +#ifndef __FreeBSD__ + return (0); +#endif } +#ifdef __FreeBSD__ static int zfsdev_ioctl(struct cdev *dev, u_long zcmd, caddr_t arg, int flag, struct thread *td) +#endif +#ifdef __NetBSD__ +static int +zfsdev_ioctl(dev_t dev, int zcmd, intptr_t iarg, int flag, cred_t *cr, int *rvalp) +#endif { zfs_cmd_t *zc; uint_t vecnum; int error, rc, len; -#ifdef illumos - minor_t minor = getminor(dev); -#else zfs_iocparm_t *zc_iocparm; int cflag, cmd, oldvecnum; boolean_t newioc, compat; void *compat_zc = NULL; +#ifdef __FreeBSD__ cred_t *cr = td->td_ucred; #endif const zfs_ioc_vec_t *vec; char *saved_poolname = NULL; nvlist_t *innvl = NULL; +#ifdef __NetBSD__ + caddr_t arg = (caddr_t)iarg; +#endif + +#if defined(illumos) || defined(__NetBSD__) + minor_t minor = getminor(dev); + + if (minor != 0 && + zfsdev_get_soft_state(minor, ZSST_CTLDEV) == NULL) + return (zvol_ioctl(dev, zcmd, iarg, flag, cr, rvalp)); +#endif +#ifdef illumos + vecnum = cmd - ZFS_IOC_FIRST; + ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip)); +#endif cflag = ZFS_CMD_COMPAT_NONE; compat = B_FALSE; newioc = B_TRUE; /* "new" style (zfs_iocparm_t) ioctl */ - len = IOCPARM_LEN(zcmd); vecnum = cmd = zcmd & 0xff; @@ -6280,11 +6386,6 @@ } } -#ifdef illumos - vecnum = cmd - ZFS_IOC_FIRST; - ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip)); -#endif - if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0])) return (SET_ERROR(EINVAL)); vec = &zfs_ioc_vec[vecnum]; @@ -6298,6 +6399,7 @@ goto out; } #else /* !illumos */ + bzero(zc, sizeof(zfs_cmd_t)); if (newioc) { @@ -6542,6 +6644,13 @@ return (error); } +static void +zfs_allow_log_destroy(void *arg) +{ + char *poolname = arg; + strfree(poolname); +} + #ifdef illumos static int zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) @@ -6593,7 +6702,6 @@ return (DDI_FAILURE); } -#endif /* illumos */ /* * OK, so this is a little weird. @@ -6604,7 +6712,6 @@ * /dev/zfs has basically nothing to do except serve up ioctls, * so most of the standard driver entry points are in zvol.c. */ -#ifdef illumos static struct cb_ops zfs_cb_ops = { zfsdev_open, /* open */ zfsdev_close, /* close */ @@ -6653,40 +6760,7 @@ (void *)&zfs_modldrv, NULL }; -#endif /* illumos */ - -static struct cdevsw zfs_cdevsw = { - .d_version = D_VERSION, - .d_open = zfsdev_open, - .d_ioctl = zfsdev_ioctl, - .d_name = ZFS_DEV_NAME -}; - -static void -zfs_allow_log_destroy(void *arg) -{ - char *poolname = arg; - strfree(poolname); -} -static void -zfsdev_init(void) -{ - zfsdev = make_dev(&zfs_cdevsw, 0x0, UID_ROOT, GID_OPERATOR, 0666, - ZFS_DEV_NAME); -} - -static void -zfsdev_fini(void) -{ - if (zfsdev != NULL) - destroy_dev(zfsdev); -} - -static struct root_hold_token *zfs_root_token; -struct proc *zfsproc; - -#ifdef illumos int _init(void) { @@ -6705,6 +6779,7 @@ } tsd_create(&zfs_fsyncer_key, NULL); + tsd_create(&zfs_putpages_key, NULL); tsd_create(&rrw_tsd_key, rrw_tsd_destroy); tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy); @@ -6751,28 +6826,49 @@ } #endif /* illumos */ +#ifdef __FreeBSD__ +static struct cdevsw zfs_cdevsw = { + .d_version = D_VERSION, + .d_open = zfsdev_open, + .d_ioctl = zfsdev_ioctl, + .d_name = ZFS_DEV_NAME +}; + +static void +zfsdev_init(void) +{ + zfsdev = make_dev(&zfs_cdevsw, 0x0, UID_ROOT, GID_OPERATOR, 0666, + ZFS_DEV_NAME); +} + +static void +zfsdev_fini(void) +{ + if (zfsdev != NULL) + destroy_dev(zfsdev); +} + +static struct root_hold_token *zfs_root_token; +struct proc *zfsproc; + static int zfs__init(void); static int zfs__fini(void); static void zfs_shutdown(void *, int); static eventhandler_tag zfs_shutdown_event_tag; -#ifdef __FreeBSD__ #define ZFS_MIN_KSTACK_PAGES 4 -#endif int zfs__init(void) { -#ifdef __FreeBSD__ #if KSTACK_PAGES < ZFS_MIN_KSTACK_PAGES printf("ZFS NOTICE: KSTACK_PAGES is %d which could result in stack " "overflow panic!\nPlease consider adding " "'options KSTACK_PAGES=%d' to your kernel config\n", KSTACK_PAGES, ZFS_MIN_KSTACK_PAGES); #endif -#endif zfs_root_token = root_mount_hold("ZFS"); mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL); @@ -6866,3 +6962,244 @@ MODULE_DEPEND(zfsctrl, opensolaris, 1, 1, 1); MODULE_DEPEND(zfsctrl, krpc, 1, 1, 1); MODULE_DEPEND(zfsctrl, acl_nfs4, 1, 1, 1); + +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ + +#include +#include + +MODULE(MODULE_CLASS_DRIVER, zfs, "solaris"); + +static int +nb_zfsdev_copen(dev_t dev, int flag, int mode, lwp_t *l) +{ + + return zfsdev_open(&dev, flag, OTYPCHR, kauth_cred_get()); +} + +static int +nb_zfsdev_cclose(dev_t dev, int flag, int mode, lwp_t *l) +{ + + return zfsdev_close(dev, flag, OTYPCHR, kauth_cred_get()); +} + +static int +nb_zfsdev_bopen(dev_t dev, int flag, int mode, lwp_t *l) +{ + + return zfsdev_open(&dev, flag, OTYPBLK, kauth_cred_get()); +} + +static int +nb_zfsdev_bclose(dev_t dev, int flag, int mode, lwp_t *l) +{ + + return zfsdev_close(dev, flag, OTYPBLK, kauth_cred_get()); +} + +static int +nb_zvol_read(dev_t dev, struct uio *uio, int flag) +{ + + return zvol_read(dev, uio, kauth_cred_get()); +} + +static int +nb_zvol_write(dev_t dev, struct uio *uio, int flag) +{ + + return zvol_write(dev, uio, kauth_cred_get()); +} + +static int +nb_zfsdev_ioctl(dev_t dev, u_long cmd, void *argp, int flag, lwp_t *l) +{ + int rval; + + return zfsdev_ioctl(dev, cmd, (intptr_t)argp, flag, kauth_cred_get(), + &rval); +} + +static void +nb_zvol_strategy(struct buf *bp) +{ + + (void) zvol_strategy(bp); +} + +const struct bdevsw zfs_bdevsw = { + .d_open = nb_zfsdev_bopen, + .d_close = nb_zfsdev_bclose, + .d_strategy = nb_zvol_strategy, + .d_ioctl = nb_zfsdev_ioctl, + .d_dump = nodump, + .d_psize = nosize, + .d_flag = D_DISK | D_MPSAFE +}; + +const struct cdevsw zfs_cdevsw = { + .d_open = nb_zfsdev_copen, + .d_close = nb_zfsdev_cclose, + .d_read = nb_zvol_read, + .d_write = nb_zvol_write, + .d_ioctl = nb_zfsdev_ioctl, + .d_stop = nostop, + .d_tty = notty, + .d_poll = nopoll, + .d_mmap = nommap, + .d_kqfilter = nokqfilter, + .d_flag = D_DISK | D_MPSAFE +}; + +/* ZFS should only be used on systems with enough memory. */ +#define ZFS_MIN_MEGS 512 + +static int zfs_version_ioctl = ZFS_IOCVER_CURRENT; +static int zfs_version_spa = SPA_VERSION; +static struct sysctllog *zfs_sysctl_log; + +static void +zfs_sysctl_init(void) +{ + const struct sysctlnode *rnode; + + sysctl_createv(&zfs_sysctl_log, 0, NULL, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "zfs", + SYSCTL_DESCR("zfs"), + NULL, 0, NULL, 0, + CTL_VFS, CTL_CREATE, CTL_EOL); + + sysctl_createv(&zfs_sysctl_log, 0, &rnode, &rnode, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "version", + SYSCTL_DESCR("version"), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL); + + sysctl_createv(&zfs_sysctl_log, 0, &rnode, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READONLY, + CTLTYPE_INT, "ioctl", + SYSCTL_DESCR("ZFS ioctl version"), + NULL, 0, &zfs_version_ioctl, 0, + CTL_CREATE, CTL_EOL); + + sysctl_createv(&zfs_sysctl_log, 0, &rnode, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READONLY, + CTLTYPE_INT, "spa", + SYSCTL_DESCR("ZFS SPA version"), + NULL, 0, &zfs_version_spa, 0, + CTL_CREATE, CTL_EOL); +} + +static void +zfs_sysctl_fini(void) +{ + + sysctl_teardown(&zfs_sysctl_log); +} + + +static void +zfs_loadvnode_destroy(void *arg) +{ + + if (arg != NULL) + panic("thread exiting with TSD loadvnode data %p", arg); +} + +static int +zfs_modcmd(modcmd_t cmd, void *arg) +{ + int error; + int active, inactive; + uint64_t availrmem; + + extern struct vfsops zfs_vfsops; + extern uint_t zfs_loadvnode_key; + extern uint_t zfs_putpage_key; + + switch (cmd) { + case MODULE_CMD_INIT: + if (!rootvnode) + return EAGAIN; + + /* XXXNETBSD trim is not supported yet */ + zfs_trim_enabled = B_FALSE; + + printf("WARNING: ZFS on NetBSD is under development\n"); + availrmem = (uint64_t)physmem * PAGE_SIZE / 1048576; + if (availrmem < ZFS_MIN_MEGS * 80 / 100) { + printf("ERROR: at least %dMB of memory required to" + "use ZFS\n", ZFS_MIN_MEGS); + return ENOMEM; + } + mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL); + mutex_init(&zfs_debug_mtx, NULL, MUTEX_DEFAULT, NULL); + + tsd_create(&zfs_fsyncer_key, NULL); + tsd_create(&rrw_tsd_key, rrw_tsd_destroy); + tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy); + tsd_create(&zfs_loadvnode_key, zfs_loadvnode_destroy); + tsd_create(&zfs_putpage_key, NULL); + + spa_init(FREAD | FWRITE); + zfs_init(); + zvol_init(); + zfs_ioctl_init(); + zfs_sysctl_init(); + + error = devsw_attach("zfs", &zfs_bdevsw, &zfs_bmajor, + &zfs_cdevsw, &zfs_cmajor); + if (error != 0) { + goto attacherr; + } + (void) vfs_attach(&zfs_vfsops); + return error; + + case MODULE_CMD_FINI: + if (spa_busy() || zfs_busy() || zvol_busy() || + zio_injection_enabled) + return EBUSY; + + error = vfs_detach(&zfs_vfsops); + if (error) + return error; + + (void) devsw_detach(&zfs_bdevsw, &zfs_cdevsw); + +attacherr: + zfs_sysctl_fini(); + zvol_fini(); + zfs_fini(); + spa_fini(); + + tsd_destroy(&zfs_putpage_key); + tsd_destroy(&zfs_loadvnode_key); + tsd_destroy(&zfs_fsyncer_key); + tsd_destroy(&rrw_tsd_key); + tsd_destroy(&zfs_allow_log_key); + + mutex_destroy(&zfs_debug_mtx); + mutex_destroy(&zfs_share_lock); + + return error; + + case MODULE_CMD_AUTOUNLOAD: + /* + * We don't want to be autounloaded because unlike + * other subsystems, we read our own configuration + * from disk and provide things that might be used + * later (zvols). + */ + return EBUSY; + + default: + return ENOTTY; + } +} + +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c 2015-06-17 09:04:32.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_onexit.c 2017-05-05 15:07:28.000000000 -0700 @@ -120,8 +120,11 @@ int zfs_onexit_fd_hold(int fd, minor_t *minorp) { - file_t *fp, *tmpfp; + file_t *fp; zfs_onexit_t *zo; + +#ifdef __FreeBSD__ + file_t *tmpfp; cap_rights_t rights; void *data; int error; @@ -138,6 +141,14 @@ curthread->td_fpop = tmpfp; if (error != 0) return (SET_ERROR(EBADF)); +#else + fp = getf(fd); + if (fp == NULL) + return (SET_ERROR(EBADF)); + + *minorp = getminor(fp->f_vnode->v_rdev); +#endif + return (zfs_onexit_minor_to_state(*minorp, &zo)); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c 2015-11-22 09:22:33.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_replay.c 2017-05-12 14:45:09.000000000 -0700 @@ -478,8 +478,10 @@ } cn.cn_cred = kcred; +#ifndef __NetBSD__ cn.cn_thread = curthread; cn.cn_flags = SAVENAME; +#endif vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY); switch (txtype) { @@ -535,7 +537,11 @@ out: if (error == 0 && vp != NULL) +#ifdef __NetBSD__ + VN_RELE(vp); +#else VN_URELE(vp); +#endif VN_RELE(ZTOV(dzp)); @@ -567,15 +573,20 @@ cn.cn_namelen = strlen(name); cn.cn_nameiop = DELETE; cn.cn_flags = ISLASTCN | SAVENAME; - cn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; cn.cn_cred = kcred; +#ifndef __NetBSD__ + cn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; cn.cn_thread = curthread; +#endif vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY); error = VOP_LOOKUP(ZTOV(dzp), &vp, &cn); if (error != 0) { VOP_UNLOCK(ZTOV(dzp), 0); goto fail; } +#ifdef __NetBSD__ + VOP_UNLOCK(vp, 0); +#endif switch ((int)lr->lr_common.lrc_txtype) { case TX_REMOVE: @@ -587,7 +598,11 @@ default: error = SET_ERROR(ENOTSUP); } +#ifdef __NetBSD__ + vrele(vp); +#else vput(vp); +#endif VOP_UNLOCK(ZTOV(dzp), 0); fail: @@ -621,13 +636,19 @@ cn.cn_nameptr = name; cn.cn_cred = kcred; +#ifndef __NetBSD__ cn.cn_thread = curthread; cn.cn_flags = SAVENAME; +#endif vn_lock(ZTOV(dzp), LK_EXCLUSIVE | LK_RETRY); +#ifndef __NetBSD__ vn_lock(ZTOV(zp), LK_EXCLUSIVE | LK_RETRY); +#endif error = VOP_LINK(ZTOV(dzp), ZTOV(zp), &cn /*,vflg*/); +#ifndef __NetBSD__ VOP_UNLOCK(ZTOV(zp), 0); +#endif VOP_UNLOCK(ZTOV(dzp), 0); VN_RELE(ZTOV(zp)); @@ -667,9 +688,11 @@ scn.cn_namelen = strlen(sname); scn.cn_nameiop = DELETE; scn.cn_flags = ISLASTCN | SAVENAME; - scn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; scn.cn_cred = kcred; +#ifndef __NetBSD__ + scn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; scn.cn_thread = td; +#endif vn_lock(ZTOV(sdzp), LK_EXCLUSIVE | LK_RETRY); error = VOP_LOOKUP(ZTOV(sdzp), &svp, &scn); VOP_UNLOCK(ZTOV(sdzp), 0); @@ -681,9 +704,11 @@ tcn.cn_namelen = strlen(tname); tcn.cn_nameiop = RENAME; tcn.cn_flags = ISLASTCN | SAVENAME; - tcn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; tcn.cn_cred = kcred; +#ifndef __NetBSD__ + tcn.cn_lkflags = LK_EXCLUSIVE | LK_RETRY; tcn.cn_thread = td; +#endif vn_lock(ZTOV(tdzp), LK_EXCLUSIVE | LK_RETRY); error = VOP_LOOKUP(ZTOV(tdzp), &tvp, &tcn); if (error == EJUSTRETURN) @@ -692,6 +717,9 @@ VOP_UNLOCK(ZTOV(tdzp), 0); goto fail; } +#ifdef __NetBSD__ + vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY); +#endif error = VOP_RENAME(ZTOV(sdzp), svp, &scn, ZTOV(tdzp), tvp, &tcn /*,vflg*/); return (error); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c 2017-06-16 09:35:57.000000000 -0700 @@ -62,9 +62,12 @@ #include #include #include -#include #include "zfs_comutil.h" +#ifdef __FreeBSD_kernel__ + +#include + struct mtx zfs_debug_mtx; MTX_SYSINIT(zfs_debug_mtx, &zfs_debug_mtx, "zfs_debug", MTX_DEF); @@ -114,6 +117,141 @@ VFS_SET(zfs_vfsops, zfs, VFCF_JAIL | VFCF_DELEGADMIN); +#endif /* __FreeBSD_kernel__ */ + +#ifdef __NetBSD__ + +#include +#include + +int zfs_debug_level; +kmutex_t zfs_debug_mtx; + +#define DROP_GIANT() /* nothing */ +#define PICKUP_GIANT() /* nothing */ +#define vfs_stdsync(a, b) 0 + +static int zfs_mount(vfs_t *vfsp, const char *path, void *data, size_t *data_len); +static int zfs_umount(vfs_t *vfsp, int fflag); +static int zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp); +static int zfs_netbsd_root(vfs_t *vfsp, vnode_t **vpp); +static int zfs_statvfs(vfs_t *vfsp, struct statvfs *statp); +static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, vnode_t **vpp); +static int zfs_vget(vfs_t *vfsp, ino_t ino, vnode_t **vpp); +static int zfs_sync(vfs_t *vfsp, int waitfor); +static int zfs_netbsd_sync(vfs_t *vfsp, int waitfor, cred_t *cr); +static void zfs_freevfs(vfs_t *vfsp); + +void zfs_init(void); +void zfs_fini(void); + +extern const struct vnodeopv_desc zfs_vnodeop_opv_desc; + +static const struct vnodeopv_desc * const zfs_vnodeop_descs[] = { + &zfs_vnodeop_opv_desc, + NULL, +}; + +struct vfsops zfs_vfsops = { + .vfs_name = MOUNT_ZFS, + .vfs_min_mount_data = sizeof(struct zfs_args), + .vfs_opv_descs = zfs_vnodeop_descs, + .vfs_mount = zfs_mount, + .vfs_unmount = zfs_umount, + .vfs_root = zfs_netbsd_root, + .vfs_statvfs = zfs_statvfs, + .vfs_sync = zfs_netbsd_sync, + .vfs_vget = zfs_vget, + .vfs_loadvnode = zfs_loadvnode, + .vfs_fhtovp = zfs_fhtovp, + .vfs_init = zfs_init, + .vfs_done = zfs_fini, + .vfs_start = (void *)nullop, + .vfs_renamelock_enter = genfs_renamelock_enter, + .vfs_renamelock_exit = genfs_renamelock_exit, + .vfs_reinit = (void *)nullop, + .vfs_vptofh = (void *)eopnotsupp, + .vfs_fhtovp = (void *)eopnotsupp, + .vfs_quotactl = (void *)eopnotsupp, + .vfs_extattrctl = (void *)eopnotsupp, + .vfs_suspendctl = genfs_suspendctl, + .vfs_snapshot = (void *)eopnotsupp, + .vfs_fsync = (void *)eopnotsupp, +}; + +static bool +zfs_sync_selector(void *cl, struct vnode *vp) +{ + znode_t *zp; + + /* + * Skip the vnode/inode if inaccessible, or if the + * atime is clean. + */ + zp = VTOZ(vp); + return zp != NULL && vp->v_type != VNON && zp->z_atime_dirty != 0 + && !zp->z_unlinked; +} + +static int +zfs_netbsd_sync(vfs_t *vfsp, int waitfor, cred_t *cr) +{ + struct vnode_iterator *marker; + zfsvfs_t *zfsvfs = vfsp->vfs_data; + vnode_t *vp; + + /* + * On NetBSD, we need to push out atime updates. Solaris does + * this during VOP_INACTIVE, but that does not work well with the + * BSD VFS, so we do it in batch here. + */ + vfs_vnode_iterator_init(vfsp, &marker); + while ((vp = vfs_vnode_iterator_next(marker, zfs_sync_selector, NULL))) + { + znode_t *zp; + dmu_buf_t *dbp; + dmu_tx_t *tx; + int error; + + error = vn_lock(vp, LK_EXCLUSIVE); + if (error) { + VN_RELE(vp); + continue; + } + ZFS_ENTER(zfsvfs); + zp = VTOZ(vp); + tx = dmu_tx_create(zfsvfs->z_os); + dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); + zfs_sa_upgrade_txholds(tx, zp); + error = dmu_tx_assign(tx, TXG_WAIT); + if (error) { + dmu_tx_abort(tx); + } else { + (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs), + (void *)&zp->z_atime, sizeof (zp->z_atime), tx); + zp->z_atime_dirty = 0; + dmu_tx_commit(tx); + } + ZFS_EXIT(zfsvfs); + vput(vp); + } + vfs_vnode_iterator_destroy(marker); + + /* + * Then do the regular ZFS stuff. + */ + return zfs_sync(vfsp, waitfor); +} + +static int +zfs_netbsd_root(vfs_t *vfsp, vnode_t **vpp) +{ + + return zfs_root(vfsp, LK_EXCLUSIVE | LK_RETRY, vpp); +} + +#endif /* __NetBSD__ */ + /* * We need to keep a count of active fs's. * This is necessary to prevent our module @@ -125,8 +263,7 @@ static int zfs_sync(vfs_t *vfsp, int waitfor) { - - /* + /* * Data integrity is job one. We don't want a compromised kernel * writing to the storage pool, so we never sync during panic. */ @@ -139,7 +276,7 @@ */ if (waitfor == MNT_LAZY) return (0); - + if (vfsp != NULL) { /* * Sync a specific filesystem. @@ -180,7 +317,7 @@ return (0); } -#ifndef __FreeBSD_kernel__ +#ifdef illumos static int zfs_create_unique_device(dev_t *dev) { @@ -208,6 +345,7 @@ *dev = makedevice(zfs_major, zfs_minor); mutex_exit(&zfs_dev_mtx); } while (vfs_devismounted(*dev) && zfs_minor != start); +#ifdef illumos if (zfs_minor == start) { /* * We are using all ~262,000 minor numbers for the @@ -228,11 +366,13 @@ break; } /* CONSTANTCONDITION */ +#endif } while (1); return (0); } -#endif /* !__FreeBSD_kernel__ */ +#endif /* illumos */ + static void atime_changed_cb(void *arg, uint64_t newval) @@ -1197,11 +1337,17 @@ zfsvfs->z_vfs->mnt_stat.f_iosize = recordsize; vfsp->vfs_data = zfsvfs; +#ifdef __FreeBSD_kernel__ vfsp->mnt_flag |= MNT_LOCAL; vfsp->mnt_kern_flag |= MNTK_LOOKUP_SHARED; vfsp->mnt_kern_flag |= MNTK_SHARED_WRITES; vfsp->mnt_kern_flag |= MNTK_EXTENDED_SHARED; vfsp->mnt_kern_flag |= MNTK_NO_IOPF; /* vn_io_fault can be used */ +#endif +#ifdef __NetBSD__ + vfsp->mnt_flag |= MNT_LOCAL; + vfsp->mnt_iflag |= IMNT_MPSAFE; +#endif /* * The fsid is 64 bits, composed of an 8-bit fs type, which @@ -1213,9 +1359,15 @@ */ fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os); ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0); +#ifdef __FreeBSD_kernel__ vfsp->vfs_fsid.val[0] = fsid_guid; vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) | vfsp->mnt_vfc->vfc_typenum & 0xFF; +#endif +#ifdef __NetBSD__ + vfsp->mnt_stat.f_fsidx.__fsid_val[0] = fsid_guid; + vfsp->mnt_stat.f_fsidx.__fsid_val[1] = fsid_guid >> 32; +#endif /* * Set features for file system. @@ -1249,7 +1401,12 @@ error = zfsvfs_setup(zfsvfs, B_TRUE); } +#ifdef __FreeBSD_kernel__ vfs_mountedfrom(vfsp, osname); +#endif +#ifdef __NetBSD__ + set_statvfs_info("on-name", UIO_SYSSPACE, osname, UIO_SYSSPACE, "zfs", vfsp, curlwp); +#endif if (!zfsvfs->z_issnap) zfsctl_create(zfsvfs); @@ -1586,12 +1743,20 @@ } /*ARGSUSED*/ +#ifdef illumos +static int +zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) +#endif +#ifdef __FreeBSD_kernel__ static int zfs_mount(vfs_t *vfsp) +#endif +#ifdef __NetBSD__ +static int +zfs_mount(vfs_t *vfsp, const char *path, void *data, size_t *data_len) +#endif { - kthread_t *td = curthread; vnode_t *mvp = vfsp->mnt_vnodecovered; - cred_t *cr = td->td_ucred; char *osname; int error = 0; int canwrite; @@ -1616,13 +1781,18 @@ * can be interrogated. */ if ((uap->flags & MS_DATA) && uap->datalen > 0) -#else /* !illumos */ + return (SET_ERROR(EINVAL)); +#endif /* illumos */ + +#ifdef __FreeBSD_kernel__ + kthread_t *td = curthread; + cred_t *cr = td->td_ucred; + if (!prison_allow(td->td_ucred, PR_ALLOW_MOUNT_ZFS)) return (SET_ERROR(EPERM)); if (vfs_getopt(vfsp->mnt_optnew, "from", (void **)&osname, NULL)) return (SET_ERROR(EINVAL)); -#endif /* illumos */ /* * If full-owner-access is enabled and delegated administration is @@ -1633,6 +1803,31 @@ secpolicy_fs_mount_clearopts(cr, vfsp); } +#endif /* __FreeBSD_kernel__ */ + +#ifdef __NetBSD__ + cred_t *cr = CRED(); + struct mounta *uap = data; + + if (uap == NULL) + return (SET_ERROR(EINVAL)); + + if (mvp->v_type != VDIR) + return (SET_ERROR(ENOTDIR)); + + mutex_enter(mvp->v_interlock); + if ((uap->flags & MS_REMOUNT) == 0 && + (uap->flags & MS_OVERLAY) == 0 && + (mvp->v_count != 1 || (mvp->v_flag & VROOT))) { + mutex_exit(mvp->v_interlock); + return (SET_ERROR(EBUSY)); + } + mutex_exit(mvp->v_interlock); + + osname = PNBUF_GET(); + strlcpy(osname, uap->fspec, strlen(uap->fspec) + 1); +#endif /* __NetBSD__ */ + /* * Check for mount privilege? * @@ -1654,6 +1849,7 @@ vattr.va_mask = AT_UID; +#ifdef __FreeBSD_kernel__ vn_lock(mvp, LK_SHARED | LK_RETRY); if (VOP_GETATTR(mvp, &vattr, cr)) { VOP_UNLOCK(mvp, 0); @@ -1666,6 +1862,21 @@ goto out; } VOP_UNLOCK(mvp, 0); +#endif +#ifdef __NetBSD__ + vn_lock(mvp, LK_SHARED | LK_RETRY); + if (VOP_GETATTR(mvp, &vattr, 0, cr, NULL)) { + VOP_UNLOCK(mvp, 0); + goto out; + } + + if (secpolicy_vnode_owner(mvp, cr, vattr.va_uid) != 0 && + VOP_ACCESS(mvp, VWRITE, cr) != 0) { + VOP_UNLOCK(mvp, 0); + goto out; + } + VOP_UNLOCK(mvp, 0); +#endif } secpolicy_fs_mount_clearopts(cr, vfsp); @@ -1687,7 +1898,12 @@ goto out; #endif +#ifdef __FreeBSD_kernel__ vfsp->vfs_flag |= MNT_NFS4ACLS; +#endif +#ifdef __NetBSD__ + vfsp->mnt_iflag |= IMNT_MPSAFE; +#endif /* * When doing a remount, we simply refresh our temporary properties @@ -1710,6 +1926,7 @@ goto out; } +#ifdef __FreeBSD_kernel__ /* Initial root mount: try hard to import the requested root pool. */ if ((vfsp->vfs_flag & MNT_ROOTFS) != 0 && (vfsp->vfs_flag & MNT_UPDATE) == 0) { @@ -1721,6 +1938,8 @@ if (error) goto out; } +#endif + DROP_GIANT(); error = zfs_domount(vfsp, osname); PICKUP_GIANT(); @@ -1734,17 +1953,35 @@ VFS_HOLD(mvp->v_vfsp); #endif +#ifdef __NetBSD__ + vfs_getnewfsid(vfsp); + + /* setup zfs mount info */ + strlcpy(vfsp->mnt_stat.f_mntfromname, osname, + sizeof(vfsp->mnt_stat.f_mntfromname)); + set_statvfs_info(path, UIO_USERSPACE, vfsp->mnt_stat.f_mntfromname, + UIO_SYSSPACE, vfsp->mnt_op->vfs_name, vfsp, curlwp); +#endif + out: return (error); } +#ifdef __FreeBSD_kernel__ static int zfs_statfs(vfs_t *vfsp, struct statfs *statp) +#endif +#ifdef __NetBSD__ +static int +zfs_statvfs(vfs_t *vfsp, struct statvfs *statp) +#endif { zfsvfs_t *zfsvfs = vfsp->vfs_data; uint64_t refdbytes, availbytes, usedobjs, availobjs; +#ifdef __FreeBSD_kernel__ statp->f_version = STATFS_VERSION; +#endif ZFS_ENTER(zfsvfs); @@ -1757,6 +1994,9 @@ * and we report our blocksize as the filesystem's maximum blocksize. */ statp->f_bsize = SPA_MINBLOCKSIZE; +#ifdef __NetBSD__ + statp->f_frsize = SPA_MINBLOCKSIZE; +#endif statp->f_iosize = zfsvfs->z_vfs->mnt_stat.f_iosize; /* @@ -1778,8 +2018,19 @@ * and the number of blocks (each object will take at least a block). */ statp->f_ffree = MIN(availobjs, statp->f_bfree); +#ifndef __FreeBSD__ + statp->f_favail = statp->f_ffree; /* no "root reservation" */ +#endif statp->f_files = statp->f_ffree + usedobjs; +#ifdef __FreeBSD__ + (void) cmpldev(&d32, vfsp->vfs_dev); + statp->f_fsid = d32; +#endif +#ifdef __NetBSD__ + statp->f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0]; +#endif + /* * We're a zfs filesystem. */ @@ -1790,7 +2041,12 @@ strlcpy(statp->f_mntonname, vfsp->mnt_stat.f_mntonname, sizeof(statp->f_mntonname)); +#ifdef __FreeBSD_kernel__ statp->f_namemax = MAXNAMELEN - 1; +#endif +#ifdef __NetBSD__ + statp->f_namemax = ZFS_MAXNAMELEN; +#endif ZFS_EXIT(zfsvfs); return (0); @@ -1924,11 +2180,16 @@ static int zfs_umount(vfs_t *vfsp, int fflag) { - kthread_t *td = curthread; zfsvfs_t *zfsvfs = vfsp->vfs_data; objset_t *os; - cred_t *cr = td->td_ucred; int ret; +#ifdef __FreeBSD_kernel__ + kthread_t *td = curthread; + cred_t *cr = td->td_ucred; +#endif +#ifdef __NetBSD__ + cred_t *cr = CRED(); +#endif ret = secpolicy_fs_unmount(cr, vfsp); if (ret) { @@ -1968,7 +2229,12 @@ /* * Flush all the files. */ +#ifdef __FreeBSD_kernel__ ret = vflush(vfsp, 0, (fflag & MS_FORCE) ? FORCECLOSE : 0, td); +#endif +#ifdef __NetBSD__ + ret = vflush(vfsp, NULL, (fflag & MS_FORCE) ? FORCECLOSE : 0); +#endif if (ret != 0) return (ret); @@ -2026,12 +2292,21 @@ return (0); } +#ifdef __FreeBSD_kernel__ static int zfs_vget(vfs_t *vfsp, ino_t ino, int flags, vnode_t **vpp) +#endif +#ifdef __NetBSD__ +static int +zfs_vget(vfs_t *vfsp, ino_t ino, vnode_t **vpp) +#endif { zfsvfs_t *zfsvfs = vfsp->vfs_data; znode_t *zp; int err; +#ifdef __NetBSD__ + int flags = LK_EXCLUSIVE; +#endif /* * zfs_zget() can't operate on virtual entries like .zfs/ or @@ -2045,7 +2320,7 @@ ZFS_ENTER(zfsvfs); err = zfs_zget(zfsvfs, ino, &zp); if (err == 0 && zp->z_unlinked) { - vrele(ZTOV(zp)); + VN_RELE(ZTOV(zp)); err = EINVAL; } if (err == 0) @@ -2055,9 +2330,11 @@ err = vn_lock(*vpp, flags); if (err != 0) *vpp = NULL; + return (err); } +#ifdef __FreeBSD_kernel__ static int zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp, struct ucred **credanonp, int *numsecflavors, int **secflavors) @@ -2077,9 +2354,16 @@ CTASSERT(SHORT_FID_LEN <= sizeof(struct fid)); CTASSERT(LONG_FID_LEN <= sizeof(struct fid)); +#endif +#ifdef __FreeBSD_kernel__ static int zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp) +#endif +#ifdef __NetBSD__ +static int +zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, vnode_t **vpp) +#endif { struct componentname cn; zfsvfs_t *zfsvfs = vfsp->vfs_data; @@ -2093,8 +2377,13 @@ *vpp = NULL; +#ifdef __NetBSD__ + return (SET_ERROR(ENOTSUP)); +#endif + ZFS_ENTER(zfsvfs); +#ifdef __FreeBSD_kernel__ /* * On FreeBSD we can get snapshot's mount point or its parent file * system mount point depending if snapshot is already mounted or not. @@ -2167,7 +2456,7 @@ } return (err); } - +#endif gen_mask = -1ULL >> (64 - 8 * i); dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask); @@ -2182,18 +2471,20 @@ zp_gen = 1; if (zp->z_unlinked || zp_gen != fid_gen) { dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen); - vrele(ZTOV(zp)); + VN_RELE(ZTOV(zp)); ZFS_EXIT(zfsvfs); return (SET_ERROR(EINVAL)); } *vpp = ZTOV(zp); ZFS_EXIT(zfsvfs); +#ifdef __FreeBSD_kernel__ err = vn_lock(*vpp, flags); if (err == 0) vnode_create_vobject(*vpp, zp->z_size, curthread); else *vpp = NULL; +#endif return (err); } @@ -2301,6 +2592,7 @@ atomic_dec_32(&zfs_active_fs_count); } +#ifdef __FreeBSD_kernel__ #ifdef __i386__ static int desiredvnodes_backup; #endif @@ -2334,6 +2626,19 @@ desiredvnodes = desiredvnodes_backup; #endif } +#endif /* __FreeBSD_kernel__ */ + +#ifdef __NetBSD__ +static void +zfs_vnodes_adjust(void) +{ +} + +static void +zfs_vnodes_adjust_back(void) +{ +} +#endif void zfs_init(void) @@ -2483,6 +2788,7 @@ return (error); } +#ifdef __FreeBSD_kernel__ #ifdef _KERNEL void zfsvfs_update_fromname(const char *oldname, const char *newname) @@ -2514,3 +2820,4 @@ mtx_unlock(&mountlist_mtx); } #endif +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vnops.c 2017-09-13 00:55:33.000000000 -0700 @@ -66,14 +66,26 @@ #include #include #include +#include #include -#include -#include -#include #include #include #include +#include + +#ifdef __FreeBSD__ +#include +#include #include +#endif + +#ifdef __NetBSD__ +#include +#include +#include + +uint_t zfs_putpage_key; +#endif /* * Programming rules. @@ -386,6 +398,7 @@ return (SET_ERROR(ENOTTY)); } +#ifdef __FreeBSD__ static vm_page_t page_busy(vnode_t *vp, int64_t start, int64_t off, int64_t nbytes) { @@ -672,6 +685,127 @@ zfs_vmobject_wunlock(obj); return (error); } +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ + +caddr_t +zfs_map_page(page_t *pp, enum seg_rw rw) +{ + vaddr_t va; + int flags; + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS + if (mm_md_direct_mapped_phys(VM_PAGE_TO_PHYS(pp), &va)) + return (caddr_t)va; +#endif + + flags = UVMPAGER_MAPIN_WAITOK | + (rw == S_READ ? UVMPAGER_MAPIN_WRITE : UVMPAGER_MAPIN_READ); + va = uvm_pagermapin(&pp, 1, flags); + return (caddr_t)va; +} + +void +zfs_unmap_page(page_t *pp, caddr_t addr) +{ + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS + vaddr_t va; + + if (mm_md_direct_mapped_phys(VM_PAGE_TO_PHYS(pp), &va)) + return; +#endif + uvm_pagermapout((vaddr_t)addr, 1); +} + +static int +mappedread(vnode_t *vp, int nbytes, uio_t *uio) +{ + znode_t *zp = VTOZ(vp); + struct uvm_object *uobj = &vp->v_uobj; + kmutex_t *mtx = uobj->vmobjlock; + int64_t start; + caddr_t va; + size_t len = nbytes; + int off; + int error = 0; + int npages, found; + + start = uio->uio_loffset; + off = start & PAGEOFFSET; + + for (start &= PAGEMASK; len > 0; start += PAGESIZE) { + page_t *pp; + uint64_t bytes = MIN(PAGESIZE - off, len); + + pp = NULL; + npages = 1; + mutex_enter(mtx); + found = uvn_findpages(uobj, start, &npages, &pp, UFP_NOALLOC); + mutex_exit(mtx); + + /* XXXNETBSD shouldn't access userspace with the page busy */ + if (found) { + va = zfs_map_page(pp, S_READ); + error = uiomove(va + off, bytes, UIO_READ, uio); + zfs_unmap_page(pp, va); + } else { + error = dmu_read_uio_dbuf(sa_get_db(zp->z_sa_hdl), + uio, bytes); + } + + mutex_enter(mtx); + uvm_page_unbusy(&pp, 1); + mutex_exit(mtx); + + len -= bytes; + off = 0; + if (error) + break; + } + return (error); +} + +static void +update_pages(vnode_t *vp, int64_t start, int len, objset_t *os, uint64_t oid, + int segflg, dmu_tx_t *tx) +{ + struct uvm_object *uobj = &vp->v_uobj; + kmutex_t *mtx = uobj->vmobjlock; + caddr_t va; + int off; + + ASSERT(vp->v_mount != NULL); + + mutex_enter(mtx); + + off = start & PAGEOFFSET; + for (start &= PAGEMASK; len > 0; start += PAGESIZE) { + page_t *pp; + int nbytes = MIN(PAGESIZE - off, len); + int npages, found; + + pp = NULL; + npages = 1; + found = uvn_findpages(uobj, start, &npages, &pp, UFP_NOALLOC); + if (found) { + mutex_exit(mtx); + + va = zfs_map_page(pp, S_WRITE); + (void) dmu_read(os, oid, start + off, nbytes, + va + off, DMU_READ_PREFETCH); + zfs_unmap_page(pp, va); + + mutex_enter(mtx); + uvm_page_unbusy(&pp, 1); + } + len -= nbytes; + off = 0; + } + mutex_exit(mtx); +} +#endif /* __NetBSD__ */ offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */ @@ -871,6 +1005,14 @@ int count = 0; sa_bulk_attr_t bulk[4]; uint64_t mtime[2], ctime[2]; + int segflg; + +#ifdef __NetBSD__ + segflg = VMSPACE_IS_KERNEL_P(uio->uio_vmspace) ? + UIO_SYSSPACE : UIO_USERSPACE; +#else + segflg = uio->uio_segflg; +#endif /* * Fasttrack empty write @@ -974,17 +1116,24 @@ rl = zfs_range_lock(zp, woff, n, RL_WRITER); } - if (vn_rlimit_fsize(vp, uio, uio->uio_td)) { +#ifdef illumos + if (woff >= limit) { zfs_range_unlock(rl); ZFS_EXIT(zfsvfs); - return (EFBIG); + return (SET_ERROR(EFBIG)); } - if (woff >= limit) { +#endif +#ifdef __FreeBSD__ + if (vn_rlimit_fsize(vp, uio, uio->uio_td)) { zfs_range_unlock(rl); ZFS_EXIT(zfsvfs); return (SET_ERROR(EFBIG)); } +#endif +#ifdef __NetBSD__ + /* XXXNETBSD we might need vn_rlimit_fsize() too here eventually */ +#endif if ((woff + n) > limit || woff > (limit - n)) n = limit - woff; @@ -1047,8 +1196,10 @@ break; } ASSERT(cbytes == max_blksz); -#else +#endif +#ifdef __FreeBSD__ ssize_t resid = uio->uio_resid; + error = vn_io_fault_uiomove(abuf->b_data, max_blksz, uio); if (error != 0) { uio->uio_offset -= resid - uio->uio_resid; @@ -1057,6 +1208,17 @@ break; } #endif +#ifdef __NetBSD__ + ssize_t resid = uio->uio_resid; + + error = uiomove(abuf->b_data, max_blksz, UIO_WRITE, uio); + if (error != 0) { + uio->uio_offset -= resid - uio->uio_resid; + uio->uio_resid = resid; + dmu_return_arcbuf(abuf); + break; + } +#endif } /* @@ -1141,7 +1303,7 @@ } if (tx_bytes && vn_has_cached_data(vp)) { update_pages(vp, woff, tx_bytes, zfsvfs->z_os, - zp->z_id, uio->uio_segflg, tx); + zp->z_id, segflg, tx); } /* @@ -1269,7 +1431,7 @@ * Release the vnode asynchronously as we currently have the * txg stopped from syncing. */ - VN_RELE_ASYNC(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os))); + VN_RELE_CLEANER(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os))); if (error == 0 && zgd->zgd_bp) zil_add_block(zgd->zgd_zilog, zgd->zgd_bp); @@ -1304,14 +1466,14 @@ /* * Nothing to do if the file has been removed */ - if (zfs_zget(zfsvfs, object, &zp) != 0) + if (zfs_zget_cleaner(zfsvfs, object, &zp) != 0) return (SET_ERROR(ENOENT)); if (zp->z_unlinked) { /* * Release the vnode asynchronously as we currently have the * txg stopped from syncing. */ - VN_RELE_ASYNC(ZTOV(zp), + VN_RELE_CLEANER(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os))); return (SET_ERROR(ENOENT)); } @@ -1428,6 +1590,7 @@ return (error); } +#ifdef __FreeBSD__ static int zfs_dd_callback(struct mount *mp, void *arg, int lkflags, struct vnode **vpp) { @@ -1728,6 +1891,172 @@ return (error); } +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +/* + * If vnode is for a device return a specfs vnode instead. + */ +static int +specvp_check(vnode_t **vpp, cred_t *cr) +{ + int error = 0; + + if (IS_DEVVP(*vpp)) { + struct vnode *svp; + + svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); + VN_RELE(*vpp); + if (svp == NULL) + error = ENOSYS; + *vpp = svp; + } + return (error); +} + +/* + * Lookup an entry in a directory, or an extended attribute directory. + * If it exists, return a held vnode reference for it. + * + * IN: dvp - vnode of directory to search. + * nm - name of entry to lookup. + * pnp - full pathname to lookup [UNUSED]. + * flags - LOOKUP_XATTR set if looking for an attribute. + * rdir - root directory vnode [UNUSED]. + * cr - credentials of caller. + * ct - caller context + * direntflags - directory lookup flags + * realpnp - returned pathname. + * + * OUT: vpp - vnode of located entry, NULL if not found. + * + * RETURN: 0 if success + * error code if failure + * + * Timestamps: + * NA + */ +/* ARGSUSED */ +static int +zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp, + int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, + int *direntflags, pathname_t *realpnp) +{ + znode_t *zdp = VTOZ(dvp); + znode_t *zp; + zfsvfs_t *zfsvfs = zdp->z_zfsvfs; + int error = 0; + + /* fast path */ + if (!(flags & LOOKUP_XATTR)) { + if (dvp->v_type != VDIR) { + return (ENOTDIR); + } else if (zdp->z_sa_hdl == NULL) { + return (SET_ERROR(EIO)); + } + + if (nm[0] == 0 || (nm[0] == '.' && nm[1] == '\0')) { + error = zfs_fastaccesschk_execute(zdp, cr); + if (!error) { + *vpp = dvp; + VN_HOLD(*vpp); + return (0); + } + return (error); + } else { + vnode_t *tvp = dnlc_lookup(dvp, nm); + + if (tvp) { + error = zfs_fastaccesschk_execute(zdp, cr); + if (error) { + VN_RELE(tvp); + return (error); + } + if (tvp == DNLC_NO_VNODE) { + VN_RELE(tvp); + return (ENOENT); + } else { + *vpp = tvp; + return (specvp_check(vpp, cr)); + } + } + } + } + + DTRACE_PROBE2(zfs__fastpath__lookup__miss, vnode_t *, dvp, char *, nm); + + ZFS_ENTER(zfsvfs); + ZFS_VERIFY_ZP(zdp); + + *vpp = NULL; + + if (flags & LOOKUP_XATTR) { +#ifdef TODO + /* + * If the xattr property is off, refuse the lookup request. + */ + if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) { + ZFS_EXIT(zfsvfs); + return (EINVAL); + } +#endif + + /* + * We don't allow recursive attributes.. + * Maybe someday we will. + */ + if (zdp->z_pflags & ZFS_XATTR) { + ZFS_EXIT(zfsvfs); + return (EINVAL); + } + + if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) { + ZFS_EXIT(zfsvfs); + return (error); + } + + /* + * Do we have permission to get into attribute directory? + */ + if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0, + B_FALSE, cr)) { + VN_RELE(*vpp); + *vpp = NULL; + } + + ZFS_EXIT(zfsvfs); + return (error); + } + + if (dvp->v_type != VDIR) { + ZFS_EXIT(zfsvfs); + return (ENOTDIR); + } + + /* + * Check accessibility of directory. + */ + if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) { + ZFS_EXIT(zfsvfs); + return (error); + } + + if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm), + NULL, U8_VALIDATE_ENTIRE, &error) < 0) { + ZFS_EXIT(zfsvfs); + return (EILSEQ); + } + + error = zfs_dirlook(zdp, nm, &zp); + if (error == 0) { + *vpp = ZTOV(zp); + error = specvp_check(vpp, cr); + } + + ZFS_EXIT(zfsvfs); + return (error); +} +#endif /* * Attempt to create a new entry in a directory. If the entry @@ -2303,7 +2632,7 @@ */ /* ARGSUSED */ static int -zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, int *ncookies, u_long **cookies) +zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, int *ncookies, off_t **cookies) { znode_t *zp = VTOZ(vp); iovec_t *iovp; @@ -2324,9 +2653,15 @@ uint8_t prefetch; boolean_t check_sysattrs; uint8_t type; - int ncooks; - u_long *cooks = NULL; + int ncooks = 0; + off_t *cooks = NULL; int flags = 0; +#ifdef __FreeBSD__ + boolean_t user = uio->uio_segflg != UIO_SYSSPACE; +#endif +#ifdef __NetBSD__ + boolean_t user = !VMSPACE_IS_KERNEL_P(uio->uio_vmspace); +#endif ZFS_ENTER(zfsvfs); ZFS_VERIFY_ZP(zp); @@ -2385,7 +2720,7 @@ */ iovp = uio->uio_iov; bytes_wanted = iovp->iov_len; - if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) { + if (user || uio->uio_iovcnt != 1) { bufsize = bytes_wanted; outbuf = kmem_alloc(bufsize, KM_SLEEP); odp = (struct dirent64 *)outbuf; @@ -2400,11 +2735,18 @@ /* * Minimum entry size is dirent size and 1 byte for a file name. */ +#ifdef __FreeBSD__ ncooks = uio->uio_resid / (sizeof(struct dirent) - sizeof(((struct dirent *)NULL)->d_name) + 1); cooks = malloc(ncooks * sizeof(u_long), M_TEMP, M_WAITOK); +#endif +#ifdef __NetBSD__ + ncooks = uio->uio_resid / _DIRENT_MINSIZE(odp); + cooks = kmem_alloc(ncooks * sizeof(off_t), KM_SLEEP); +#endif *cookies = cooks; *ncookies = ncooks; } + /* * If this VFS supports the system attribute view interface; and * we're looking at an extended attribute directory; and we care @@ -2564,7 +2906,12 @@ if (cooks != NULL) { *cooks++ = offset; ncooks--; +#ifdef __FreeBSD__ KASSERT(ncooks >= 0, ("ncookies=%d", ncooks)); +#endif +#ifdef __NetBSD__ + KASSERTMSG(ncooks >= 0, "ncooks=%d", ncooks); +#endif } } zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */ @@ -2573,11 +2920,11 @@ if (ncookies != NULL) *ncookies -= ncooks; - if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) { + if (!user && uio->uio_iovcnt == 1) { iovp->iov_base += outcount; iovp->iov_len -= outcount; uio->uio_resid -= outcount; - } else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) { + } else if (error = uiomove(outbuf, (size_t)outcount, UIO_READ, uio)) { /* * Reset the pointer. */ @@ -2586,7 +2933,7 @@ update: zap_cursor_fini(&zc); - if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) + if (user || uio->uio_iovcnt != 1) kmem_free(outbuf, bufsize); if (error == ENOENT) @@ -2597,7 +2944,12 @@ uio->uio_loffset = offset; ZFS_EXIT(zfsvfs); if (error != 0 && cookies != NULL) { +#ifdef __FreeBSD__ free(*cookies, M_TEMP); +#endif +#ifdef __NetBSD__ + kmem_free(*cookies, ncooks * sizeof(off_t)); +#endif *cookies = NULL; *ncookies = 0; } @@ -2617,6 +2969,10 @@ if (zfsvfs->z_os->os_sync != ZFS_SYNC_DISABLED) { ZFS_ENTER(zfsvfs); ZFS_VERIFY_ZP(zp); + +#ifdef __NetBSD__ + if (!zp->z_unlinked) +#endif zil_commit(zfsvfs->z_log, zp->z_id); ZFS_EXIT(zfsvfs); } @@ -2697,9 +3053,13 @@ vap->va_mode = zp->z_mode & ~S_IFMT; #ifdef illumos vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev; -#else +#endif +#ifdef __FreeBSD__ vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0]; #endif +#ifdef __NetBSD__ + vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0]; +#endif vap->va_nodeid = zp->z_id; if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp)) links = zp->z_links + 1; @@ -3501,9 +3861,11 @@ const char *tnm = tcnp->cn_nameptr; int error; +#ifdef __FreeBSD__ VOP_UNLOCK(tdvp, 0); if (*tvpp != NULL && *tvpp != tdvp) VOP_UNLOCK(*tvpp, 0); +#endif relock: error = vn_lock(sdvp, LK_EXCLUSIVE); @@ -3511,6 +3873,10 @@ goto out; sdzp = VTOZ(sdvp); +#ifdef __NetBSD__ + if (tdvp == sdvp) { + } else { +#endif error = vn_lock(tdvp, LK_EXCLUSIVE | LK_NOWAIT); if (error != 0) { VOP_UNLOCK(sdvp, 0); @@ -3522,6 +3888,10 @@ VOP_UNLOCK(tdvp, 0); goto relock; } +#ifdef __NetBSD__ + } /* end if (tdvp == sdvp) */ +#endif + tdzp = VTOZ(tdvp); /* @@ -3546,6 +3916,9 @@ if (tdzp->z_sa_hdl == NULL || sdzp->z_sa_hdl == NULL) { ZFS_EXIT(zfsvfs); VOP_UNLOCK(sdvp, 0); +#ifdef __NetBSD__ + if (tdvp != sdvp) +#endif VOP_UNLOCK(tdvp, 0); error = SET_ERROR(EIO); goto out; @@ -3560,6 +3933,9 @@ /* Source entry invalid or not there. */ ZFS_EXIT(zfsvfs); VOP_UNLOCK(sdvp, 0); +#ifdef __NetBSD__ + if (tdvp != sdvp) +#endif VOP_UNLOCK(tdvp, 0); if ((scnp->cn_flags & ISDOTDOT) != 0 || (scnp->cn_namelen == 1 && scnp->cn_nameptr[0] == '.')) @@ -3575,6 +3951,9 @@ if (error != 0) { ZFS_EXIT(zfsvfs); VOP_UNLOCK(sdvp, 0); +#ifdef __NetBSD__ + if (tdvp != sdvp) +#endif VOP_UNLOCK(tdvp, 0); vrele(svp); if ((tcnp->cn_flags & ISDOTDOT) != 0) @@ -3599,6 +3978,9 @@ error = vn_lock(nvp, LK_EXCLUSIVE | LK_NOWAIT); if (error != 0) { VOP_UNLOCK(sdvp, 0); +#ifdef __NetBSD__ + if (tdvp != sdvp) +#endif VOP_UNLOCK(tdvp, 0); if (tvp != NULL) vrele(tvp); @@ -3621,10 +4003,16 @@ error = SET_ERROR(EINVAL); goto out; } +#ifdef __NetBSD__ + if (*svpp != NULL) +#endif vrele(*svpp); *svpp = nvp; goto relock; } +#ifdef __NetBSD__ + if (*svpp != NULL) +#endif vrele(*svpp); *svpp = nvp; @@ -3633,10 +4021,21 @@ *tvpp = NULL; if (tvp != NULL) { nvp = tvp; + +#ifdef __NetBSD__ + if (tvp == svp || tvp == sdvp) { + } else { +#endif error = vn_lock(nvp, LK_EXCLUSIVE | LK_NOWAIT); if (error != 0) { VOP_UNLOCK(sdvp, 0); +#ifdef __NetBSD__ + if (tdvp != sdvp) +#endif VOP_UNLOCK(tdvp, 0); +#ifdef __NetBSD__ + if (*svpp != tdvp) +#endif VOP_UNLOCK(*svpp, 0); if (error != EBUSY) { vrele(nvp); @@ -3650,9 +4049,18 @@ vput(nvp); goto relock; } +#ifdef __NetBSD__ + } /* end if (tvp == svp || tvp == sdvp) */ +#endif + *tvpp = nvp; } + KASSERT(VOP_ISLOCKED(sdvp) == LK_EXCLUSIVE); + KASSERT(VOP_ISLOCKED(*svpp) == LK_EXCLUSIVE); + KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE); + KASSERT(*tvpp == NULL || VOP_ISLOCKED(*tvpp) == LK_EXCLUSIVE); + return (0); out: @@ -3740,12 +4148,12 @@ znode_t *sdzp, *tdzp, *szp, *tzp; zilog_t *zilog = NULL; dmu_tx_t *tx; - char *snm = scnp->cn_nameptr; - char *tnm = tcnp->cn_nameptr; + char *snm = __UNCONST(scnp->cn_nameptr); + char *tnm = __UNCONST(tcnp->cn_nameptr); int error = 0; /* Reject renames across filesystems. */ - if ((*svpp)->v_mount != tdvp->v_mount || + if (((*svpp) != NULL && (*svpp)->v_mount != tdvp->v_mount) || ((*tvpp) != NULL && (*svpp)->v_mount != (*tvpp)->v_mount)) { error = SET_ERROR(EXDEV); goto out; @@ -3837,7 +4245,7 @@ if ((scnp->cn_namelen == 1 && scnp->cn_nameptr[0] == '.') || sdzp == szp || (scnp->cn_flags | tcnp->cn_flags) & ISDOTDOT) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto unlockout; } @@ -3871,6 +4279,26 @@ goto unlockout; } } + + /* + * POSIX dictates that when the source and target + * entries refer to the same file object, rename + * must do nothing and exit without error. + */ +#ifndef __NetBSD__ + /* + * But on NetBSD we have a different system call to do + * this, posix_rename, which sorta kinda handles this + * case (modulo races), and our tests expect BSD + * semantics for rename, so we'll do that until we can + * push the choice between BSD and POSIX semantics into + * the VOP_RENAME protocol as a flag. + */ + if (szp->z_id == tzp->z_id) { + error = 0; + goto unlockout; + } +#endif } vnevent_rename_src(*svpp, sdvp, scnp->cn_nameptr, ct); @@ -3908,11 +4336,13 @@ } - if (tzp) /* Attempt to remove the existing target */ + if (tzp && (tzp->z_id != szp->z_id)) + /* Attempt to remove the existing target */ error = zfs_link_destroy(tdzp, tnm, tzp, tx, 0, NULL); if (error == 0) { - error = zfs_link_create(tdzp, tnm, szp, tx, ZRENAMING); + if (!tzp || (tzp->z_id != szp->z_id)) + error = zfs_link_create(tdzp, tnm, szp, tx, ZRENAMING); if (error == 0) { szp->z_pflags |= ZFS_AV_MODIFIED; @@ -3920,8 +4350,9 @@ (void *)&szp->z_pflags, sizeof (uint64_t), tx); ASSERT0(error); - error = zfs_link_destroy(sdzp, snm, szp, tx, ZRENAMING, - NULL); + error = zfs_link_destroy(sdzp, snm, szp, tx, + /* Kludge for BSD rename semantics. */ + tzp && tzp->z_id == szp->z_id ? 0: ZRENAMING, NULL); if (error == 0) { zfs_log_rename(zilog, tx, TX_RENAME, sdzp, snm, tdzp, tnm, szp); @@ -3957,19 +4388,23 @@ dmu_tx_commit(tx); + if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS) + zil_commit(zilog, 0); + unlockout: /* all 4 vnodes are locked, ZFS_ENTER called */ ZFS_EXIT(zfsvfs); + VOP_UNLOCK(*svpp, 0); VOP_UNLOCK(sdvp, 0); -out: /* original two vnodes are locked */ - if (error == 0 && zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS) - zil_commit(zilog, 0); - + if (*tvpp != sdvp && *tvpp != *svpp) if (*tvpp != NULL) VOP_UNLOCK(*tvpp, 0); + if (tdvp != sdvp && tdvp != *svpp) if (tdvp != *tvpp) VOP_UNLOCK(tdvp, 0); + +out: return (error); } @@ -4332,8 +4767,10 @@ } +#ifdef __FreeBSD__ CTASSERT(sizeof(struct zfid_short) <= sizeof(struct fid)); CTASSERT(sizeof(struct zfid_long) <= sizeof(struct fid)); +#endif /*ARGSUSED*/ static int @@ -4468,6 +4905,7 @@ *valp = 0; return (0); +#ifndef __NetBSD__ case _PC_ACL_NFS4: *valp = 1; return (0); @@ -4475,6 +4913,7 @@ case _PC_ACL_PATH_MAX: *valp = ACL_MAX_ENTRIES; return (0); +#endif default: return (EOPNOTSUPP); @@ -4537,548 +4976,314 @@ return (flags); } -static int -zfs_getpages(struct vnode *vp, vm_page_t *m, int count, int *rbehind, - int *rahead) -{ - znode_t *zp = VTOZ(vp); - zfsvfs_t *zfsvfs = zp->z_zfsvfs; - objset_t *os = zp->z_zfsvfs->z_os; - vm_page_t mlast; - vm_object_t object; - caddr_t va; - struct sf_buf *sf; - off_t startoff, endoff; - int i, error; - vm_pindex_t reqstart, reqend; - int lsize, size; - - object = m[0]->object; - error = 0; - - ZFS_ENTER(zfsvfs); - ZFS_VERIFY_ZP(zp); - - zfs_vmobject_wlock(object); - if (m[count - 1]->valid != 0 && --count == 0) { - zfs_vmobject_wunlock(object); - goto out; - } - - mlast = m[count - 1]; - - if (IDX_TO_OFF(mlast->pindex) >= - object->un_pager.vnp.vnp_size) { - zfs_vmobject_wunlock(object); - ZFS_EXIT(zfsvfs); - return (zfs_vm_pagerret_bad); - } - - PCPU_INC(cnt.v_vnodein); - PCPU_ADD(cnt.v_vnodepgsin, count); - - lsize = PAGE_SIZE; - if (IDX_TO_OFF(mlast->pindex) + lsize > object->un_pager.vnp.vnp_size) - lsize = object->un_pager.vnp.vnp_size - - IDX_TO_OFF(mlast->pindex); - zfs_vmobject_wunlock(object); - - for (i = 0; i < count; i++) { - size = PAGE_SIZE; - if (i == count - 1) - size = lsize; - va = zfs_map_page(m[i], &sf); - error = dmu_read(os, zp->z_id, IDX_TO_OFF(m[i]->pindex), - size, va, DMU_READ_PREFETCH); - if (size != PAGE_SIZE) - bzero(va + size, PAGE_SIZE - size); - zfs_unmap_page(sf); - if (error != 0) - goto out; - } - - zfs_vmobject_wlock(object); - for (i = 0; i < count; i++) - m[i]->valid = VM_PAGE_BITS_ALL; - zfs_vmobject_wunlock(object); - -out: - ZFS_ACCESSTIME_STAMP(zfsvfs, zp); - ZFS_EXIT(zfsvfs); - if (error == 0) { - if (rbehind) - *rbehind = 0; - if (rahead) - *rahead = 0; - return (zfs_vm_pagerret_ok); - } else - return (zfs_vm_pagerret_error); -} +#ifdef __NetBSD__ static int -zfs_freebsd_getpages(ap) - struct vop_getpages_args /* { - struct vnode *a_vp; - vm_page_t *a_m; - int a_count; - int *a_rbehind; - int *a_rahead; - } */ *ap; +zfs_netbsd_open(void *v) { + struct vop_open_args *ap = v; - return (zfs_getpages(ap->a_vp, ap->a_m, ap->a_count, ap->a_rbehind, - ap->a_rahead)); + return (zfs_open(&ap->a_vp, ap->a_mode, ap->a_cred, NULL)); } static int -zfs_putpages(struct vnode *vp, vm_page_t *ma, size_t len, int flags, - int *rtvals) +zfs_netbsd_close(void *v) { - znode_t *zp = VTOZ(vp); - zfsvfs_t *zfsvfs = zp->z_zfsvfs; - rl_t *rl; - dmu_tx_t *tx; - struct sf_buf *sf; - vm_object_t object; - vm_page_t m; - caddr_t va; - size_t tocopy; - size_t lo_len; - vm_ooffset_t lo_off; - vm_ooffset_t off; - uint_t blksz; - int ncount; - int pcount; - int err; - int i; - - ZFS_ENTER(zfsvfs); - ZFS_VERIFY_ZP(zp); - - object = vp->v_object; - pcount = btoc(len); - ncount = pcount; - - KASSERT(ma[0]->object == object, ("mismatching object")); - KASSERT(len > 0 && (len & PAGE_MASK) == 0, ("unexpected length")); - - for (i = 0; i < pcount; i++) - rtvals[i] = zfs_vm_pagerret_error; - - off = IDX_TO_OFF(ma[0]->pindex); - blksz = zp->z_blksz; - lo_off = rounddown(off, blksz); - lo_len = roundup(len + (off - lo_off), blksz); - rl = zfs_range_lock(zp, lo_off, lo_len, RL_WRITER); - - zfs_vmobject_wlock(object); - if (len + off > object->un_pager.vnp.vnp_size) { - if (object->un_pager.vnp.vnp_size > off) { - int pgoff; - - len = object->un_pager.vnp.vnp_size - off; - ncount = btoc(len); - if ((pgoff = (int)len & PAGE_MASK) != 0) { - /* - * If the object is locked and the following - * conditions hold, then the page's dirty - * field cannot be concurrently changed by a - * pmap operation. - */ - m = ma[ncount - 1]; - vm_page_assert_sbusied(m); - KASSERT(!pmap_page_is_write_mapped(m), - ("zfs_putpages: page %p is not read-only", m)); - vm_page_clear_dirty(m, pgoff, PAGE_SIZE - - pgoff); - } - } else { - len = 0; - ncount = 0; - } - if (ncount < pcount) { - for (i = ncount; i < pcount; i++) { - rtvals[i] = zfs_vm_pagerret_bad; - } - } - } - zfs_vmobject_wunlock(object); - - if (ncount == 0) - goto out; - - if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) || - zfs_owner_overquota(zfsvfs, zp, B_TRUE)) { - goto out; - } - - tx = dmu_tx_create(zfsvfs->z_os); - dmu_tx_hold_write(tx, zp->z_id, off, len); - - dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); - zfs_sa_upgrade_txholds(tx, zp); - err = dmu_tx_assign(tx, TXG_WAIT); - if (err != 0) { - dmu_tx_abort(tx); - goto out; - } - - if (zp->z_blksz < PAGE_SIZE) { - i = 0; - for (i = 0; len > 0; off += tocopy, len -= tocopy, i++) { - tocopy = len > PAGE_SIZE ? PAGE_SIZE : len; - va = zfs_map_page(ma[i], &sf); - dmu_write(zfsvfs->z_os, zp->z_id, off, tocopy, va, tx); - zfs_unmap_page(sf); - } - } else { - err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, ma, tx); - } - - if (err == 0) { - uint64_t mtime[2], ctime[2]; - sa_bulk_attr_t bulk[3]; - int count = 0; - - SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, - &mtime, 16); - SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, - &ctime, 16); - SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, - &zp->z_pflags, 8); - zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, - B_TRUE); - (void)sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); - zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0); - - zfs_vmobject_wlock(object); - for (i = 0; i < ncount; i++) { - rtvals[i] = zfs_vm_pagerret_ok; - vm_page_undirty(ma[i]); - } - zfs_vmobject_wunlock(object); - PCPU_INC(cnt.v_vnodeout); - PCPU_ADD(cnt.v_vnodepgsout, ncount); - } - dmu_tx_commit(tx); + struct vop_close_args *ap = v; -out: - zfs_range_unlock(rl); - if ((flags & (zfs_vm_pagerput_sync | zfs_vm_pagerput_inval)) != 0 || - zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS) - zil_commit(zfsvfs->z_log, zp->z_id); - ZFS_EXIT(zfsvfs); - return (rtvals[0]); + return (zfs_close(ap->a_vp, ap->a_fflag, 0, 0, ap->a_cred, NULL)); } -int -zfs_freebsd_putpages(ap) - struct vop_putpages_args /* { - struct vnode *a_vp; - vm_page_t *a_m; - int a_count; - int a_sync; - int *a_rtvals; - } */ *ap; +static int +zfs_netbsd_ioctl(void *v) { + struct vop_ioctl_args *ap = v; - return (zfs_putpages(ap->a_vp, ap->a_m, ap->a_count, ap->a_sync, - ap->a_rtvals)); + return (zfs_ioctl(ap->a_vp, ap->a_command, (intptr_t)ap->a_data, + ap->a_fflag, ap->a_cred, NULL, NULL)); } -static int -zfs_freebsd_bmap(ap) - struct vop_bmap_args /* { - struct vnode *a_vp; - daddr_t a_bn; - struct bufobj **a_bop; - daddr_t *a_bnp; - int *a_runp; - int *a_runb; - } */ *ap; -{ - - if (ap->a_bop != NULL) - *ap->a_bop = &ap->a_vp->v_bufobj; - if (ap->a_bnp != NULL) - *ap->a_bnp = ap->a_bn; - if (ap->a_runp != NULL) - *ap->a_runp = 0; - if (ap->a_runb != NULL) - *ap->a_runb = 0; - - return (0); -} static int -zfs_freebsd_open(ap) - struct vop_open_args /* { - struct vnode *a_vp; - int a_mode; - struct ucred *a_cred; - struct thread *a_td; - } */ *ap; +zfs_netbsd_read(void *v) { - vnode_t *vp = ap->a_vp; - znode_t *zp = VTOZ(vp); - int error; + struct vop_read_args *ap = v; - error = zfs_open(&vp, ap->a_mode, ap->a_cred, NULL); - if (error == 0) - vnode_create_vobject(vp, zp->z_size, ap->a_td); - return (error); + return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL)); } static int -zfs_freebsd_close(ap) - struct vop_close_args /* { - struct vnode *a_vp; - int a_fflag; - struct ucred *a_cred; - struct thread *a_td; - } */ *ap; +zfs_netbsd_write(void *v) { + struct vop_write_args *ap = v; - return (zfs_close(ap->a_vp, ap->a_fflag, 1, 0, ap->a_cred, NULL)); + return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), ap->a_cred, NULL)); } static int -zfs_freebsd_ioctl(ap) - struct vop_ioctl_args /* { - struct vnode *a_vp; - u_long a_command; - caddr_t a_data; - int a_fflag; - struct ucred *cred; - struct thread *td; - } */ *ap; +zfs_netbsd_access(void *v) { + struct vop_access_args /* { + struct vnode *a_vp; + int a_mode; + kauth_cred_t a_cred; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + int mode = ap->a_mode; + mode_t zfs_mode = 0; + kauth_cred_t cred = ap->a_cred; + int error; - return (zfs_ioctl(ap->a_vp, ap->a_command, (intptr_t)ap->a_data, - ap->a_fflag, ap->a_cred, NULL, NULL)); -} + /* + * XXX This is really random, especially the left shift by six, + * and it exists only because of randomness in zfs_unix_to_v4 + * and zfs_zaccess_rwx in zfs_acl.c. + */ + if (mode & VREAD) + zfs_mode |= S_IROTH; + if (mode & VWRITE) + zfs_mode |= S_IWOTH; + if (mode & VEXEC) + zfs_mode |= S_IXOTH; + zfs_mode <<= 6; -static int -zfs_freebsd_read(ap) - struct vop_read_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - } */ *ap; -{ + KASSERT(VOP_ISLOCKED(vp)); + error = zfs_access(vp, zfs_mode, 0, cred, NULL); - return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), - ap->a_cred, NULL)); + return (error); } static int -zfs_freebsd_write(ap) - struct vop_write_args /* { - struct vnode *a_vp; - struct uio *a_uio; - int a_ioflag; - struct ucred *a_cred; - } */ *ap; +zfs_netbsd_lookup(void *v) { + struct vop_lookup_v2_args /* { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode **vpp = ap->a_vpp; + struct componentname *cnp = ap->a_cnp; + char nm[NAME_MAX + 1]; + int error; + int iswhiteout; - return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag), - ap->a_cred, NULL)); -} + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + KASSERT(cnp->cn_namelen < sizeof nm); -static int -zfs_freebsd_access(ap) - struct vop_access_args /* { - struct vnode *a_vp; - accmode_t a_accmode; - struct ucred *a_cred; - struct thread *a_td; - } */ *ap; -{ - vnode_t *vp = ap->a_vp; - znode_t *zp = VTOZ(vp); - accmode_t accmode; - int error = 0; + *vpp = NULL; /* - * ZFS itself only knowns about VREAD, VWRITE, VEXEC and VAPPEND, + * Do an access check before the cache lookup. zfs_lookup does + * an access check too, but it's too scary to contemplate + * injecting our namecache stuff into zfs internals. + * + * XXX Is this the correct access check? */ - accmode = ap->a_accmode & (VREAD|VWRITE|VEXEC|VAPPEND); - if (accmode != 0) - error = zfs_access(ap->a_vp, accmode, 0, ap->a_cred, NULL); + if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred)) != 0) + goto out; /* - * VADMIN has to be handled by vaccess(). + * Check the namecache before entering zfs_lookup. + * cache_lookup does the locking dance for us. */ - if (error == 0) { - accmode = ap->a_accmode & ~(VREAD|VWRITE|VEXEC|VAPPEND); - if (accmode != 0) { - error = vaccess(vp->v_type, zp->z_mode, zp->z_uid, - zp->z_gid, accmode, ap->a_cred, NULL); + if (cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen, + cnp->cn_nameiop, cnp->cn_flags, &iswhiteout, vpp)) { + if (iswhiteout) { + cnp->cn_flags |= ISWHITEOUT; } + return *vpp == NULL ? ENOENT : 0; } /* - * For VEXEC, ensure that at least one execute bit is set for - * non-directories. + * zfs_lookup wants a null-terminated component name, but namei + * gives us a pointer into the full pathname. + */ + (void)strlcpy(nm, cnp->cn_nameptr, cnp->cn_namelen + 1); + + error = zfs_lookup(dvp, nm, vpp, NULL, 0, NULL, cnp->cn_cred, NULL, + NULL, NULL); + + /* + * Translate errors to match our namei insanity. Also, if the + * caller wants to create an entry here, it's apparently our + * responsibility as lookup to make sure that's permissible. + * Go figure. */ - if (error == 0 && (ap->a_accmode & VEXEC) != 0 && vp->v_type != VDIR && - (zp->z_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) { - error = EACCES; + if (cnp->cn_flags & ISLASTCN) { + switch (cnp->cn_nameiop) { + case CREATE: + case RENAME: + if (error == ENOENT) { + error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred); + if (error) + break; + error = EJUSTRETURN; + break; + } + /* FALLTHROUGH */ + case DELETE: + break; + } } - return (error); -} + if (error) { + KASSERT(*vpp == NULL); + goto out; + } + KASSERT(*vpp != NULL); -static int -zfs_freebsd_lookup(ap) - struct vop_lookup_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - } */ *ap; -{ - struct componentname *cnp = ap->a_cnp; - char nm[NAME_MAX + 1]; + if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) { + KASSERT(!(cnp->cn_flags & ISDOTDOT)); + KASSERT(dvp == *vpp); + } else if ((cnp->cn_namelen == 2) && + (cnp->cn_nameptr[0] == '.') && + (cnp->cn_nameptr[1] == '.')) { + KASSERT(cnp->cn_flags & ISDOTDOT); + } else { + KASSERT(!(cnp->cn_flags & ISDOTDOT)); + } - ASSERT(cnp->cn_namelen < sizeof(nm)); - strlcpy(nm, cnp->cn_nameptr, MIN(cnp->cn_namelen + 1, sizeof(nm))); +out: + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); - return (zfs_lookup(ap->a_dvp, nm, ap->a_vpp, cnp, cnp->cn_nameiop, - cnp->cn_cred, cnp->cn_thread, 0)); -} + /* + * Insert name into cache if appropriate. + */ -static int -zfs_cache_lookup(ap) - struct vop_lookup_args /* { - struct vnode *a_dvp; - struct vnode **a_vpp; - struct componentname *a_cnp; - } */ *ap; -{ - zfsvfs_t *zfsvfs; + if (error == 0 || (error == ENOENT && cnp->cn_nameiop != CREATE)) + cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen, + cnp->cn_flags); - zfsvfs = ap->a_dvp->v_mount->mnt_data; - if (zfsvfs->z_use_namecache) - return (vfs_cache_lookup(ap)); - else - return (zfs_freebsd_lookup(ap)); + return (error); } static int -zfs_freebsd_create(ap) - struct vop_create_args /* { +zfs_netbsd_create(void *v) +{ + struct vop_create_v3_args /* { struct vnode *a_dvp; struct vnode **a_vpp; struct componentname *a_cnp; struct vattr *a_vap; - } */ *ap; -{ - zfsvfs_t *zfsvfs; + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode **vpp = ap->a_vpp; struct componentname *cnp = ap->a_cnp; - vattr_t *vap = ap->a_vap; - int error, mode; + struct vattr *vap = ap->a_vap; + int mode; + int error; - ASSERT(cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); vattr_init_mask(vap); mode = vap->va_mode & ALLPERMS; - zfsvfs = ap->a_dvp->v_mount->mnt_data; - error = zfs_create(ap->a_dvp, cnp->cn_nameptr, vap, !EXCL, mode, - ap->a_vpp, cnp->cn_cred, cnp->cn_thread); - if (zfsvfs->z_use_namecache && - error == 0 && (cnp->cn_flags & MAKEENTRY) != 0) - cache_enter(ap->a_dvp, *ap->a_vpp, cnp); + /* XXX !EXCL is wrong here... */ + error = zfs_create(dvp, __UNCONST(cnp->cn_nameptr), vap, !EXCL, mode, + vpp, cnp->cn_cred, NULL); + + KASSERT((error == 0) == (*vpp != NULL)); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + VOP_UNLOCK(*vpp, 0); + return (error); } static int -zfs_freebsd_remove(ap) - struct vop_remove_args /* { +zfs_netbsd_remove(void *v) +{ + struct vop_remove_v2_args /* { struct vnode *a_dvp; struct vnode *a_vp; struct componentname *a_cnp; - } */ *ap; -{ + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode *vp = ap->a_vp; + struct componentname *cnp = ap->a_cnp; + int error; - ASSERT(ap->a_cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE); - return (zfs_remove(ap->a_dvp, ap->a_vp, ap->a_cnp->cn_nameptr, - ap->a_cnp->cn_cred)); + error = zfs_remove(dvp, vp, __UNCONST(cnp->cn_nameptr), cnp->cn_cred); + vput(vp); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + return (error); } static int -zfs_freebsd_mkdir(ap) - struct vop_mkdir_args /* { +zfs_netbsd_mkdir(void *v) +{ + struct vop_mkdir_v3_args /* { struct vnode *a_dvp; struct vnode **a_vpp; struct componentname *a_cnp; struct vattr *a_vap; - } */ *ap; -{ - vattr_t *vap = ap->a_vap; + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode **vpp = ap->a_vpp; + struct componentname *cnp = ap->a_cnp; + struct vattr *vap = ap->a_vap; + int error; - ASSERT(ap->a_cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); vattr_init_mask(vap); - return (zfs_mkdir(ap->a_dvp, ap->a_cnp->cn_nameptr, vap, ap->a_vpp, - ap->a_cnp->cn_cred)); + error = zfs_mkdir(dvp, __UNCONST(cnp->cn_nameptr), vap, vpp, + cnp->cn_cred); + + KASSERT((error == 0) == (*vpp != NULL)); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + VOP_UNLOCK(*vpp, 0); + + return (error); } static int -zfs_freebsd_rmdir(ap) - struct vop_rmdir_args /* { +zfs_netbsd_rmdir(void *v) +{ + struct vop_rmdir_v2_args /* { struct vnode *a_dvp; struct vnode *a_vp; struct componentname *a_cnp; - } */ *ap; -{ + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode *vp = ap->a_vp; struct componentname *cnp = ap->a_cnp; + int error; - ASSERT(cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE); - return (zfs_rmdir(ap->a_dvp, ap->a_vp, cnp->cn_nameptr, cnp->cn_cred)); + error = zfs_rmdir(dvp, vp, __UNCONST(cnp->cn_nameptr), cnp->cn_cred); + vput(vp); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + return error; } static int -zfs_freebsd_readdir(ap) - struct vop_readdir_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - int *a_eofflag; - int *a_ncookies; - u_long **a_cookies; - } */ *ap; +zfs_netbsd_readdir(void *v) { + struct vop_readdir_args *ap = v; return (zfs_readdir(ap->a_vp, ap->a_uio, ap->a_cred, ap->a_eofflag, - ap->a_ncookies, ap->a_cookies)); + ap->a_ncookies, ap->a_cookies)); } static int -zfs_freebsd_fsync(ap) - struct vop_fsync_args /* { - struct vnode *a_vp; - int a_waitfor; - struct thread *a_td; - } */ *ap; +zfs_netbsd_fsync(void *v) { + struct vop_fsync_args *ap = v; - vop_stdfsync(ap); - return (zfs_fsync(ap->a_vp, 0, ap->a_td->td_ucred, NULL)); + return (zfs_fsync(ap->a_vp, ap->a_flags, ap->a_cred, NULL)); } static int -zfs_freebsd_getattr(ap) - struct vop_getattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - } */ *ap; +zfs_netbsd_getattr(void *v) { + struct vop_getattr_args *ap = v; vattr_t *vap = ap->a_vap; xvattr_t xvap; u_long fflags = 0; @@ -5094,14 +5299,6 @@ XVA_SET_REQ(&xvap, XAT_APPENDONLY); XVA_SET_REQ(&xvap, XAT_NOUNLINK); XVA_SET_REQ(&xvap, XAT_NODUMP); - XVA_SET_REQ(&xvap, XAT_READONLY); - XVA_SET_REQ(&xvap, XAT_ARCHIVE); - XVA_SET_REQ(&xvap, XAT_SYSTEM); - XVA_SET_REQ(&xvap, XAT_HIDDEN); - XVA_SET_REQ(&xvap, XAT_REPARSE); - XVA_SET_REQ(&xvap, XAT_OFFLINE); - XVA_SET_REQ(&xvap, XAT_SPARSE); - error = zfs_getattr(ap->a_vp, (vattr_t *)&xvap, 0, ap->a_cred, NULL); if (error != 0) return (error); @@ -5117,23 +5314,8 @@ xvap.xva_xoptattrs.xoa_appendonly); FLAG_CHECK(SF_NOUNLINK, XAT_NOUNLINK, xvap.xva_xoptattrs.xoa_nounlink); - FLAG_CHECK(UF_ARCHIVE, XAT_ARCHIVE, - xvap.xva_xoptattrs.xoa_archive); FLAG_CHECK(UF_NODUMP, XAT_NODUMP, xvap.xva_xoptattrs.xoa_nodump); - FLAG_CHECK(UF_READONLY, XAT_READONLY, - xvap.xva_xoptattrs.xoa_readonly); - FLAG_CHECK(UF_SYSTEM, XAT_SYSTEM, - xvap.xva_xoptattrs.xoa_system); - FLAG_CHECK(UF_HIDDEN, XAT_HIDDEN, - xvap.xva_xoptattrs.xoa_hidden); - FLAG_CHECK(UF_REPARSE, XAT_REPARSE, - xvap.xva_xoptattrs.xoa_reparse); - FLAG_CHECK(UF_OFFLINE, XAT_OFFLINE, - xvap.xva_xoptattrs.xoa_offline); - FLAG_CHECK(UF_SPARSE, XAT_SPARSE, - xvap.xva_xoptattrs.xoa_sparse); - #undef FLAG_CHECK *vap = xvap.xva_vattr; vap->va_flags = fflags; @@ -5141,22 +5323,21 @@ } static int -zfs_freebsd_setattr(ap) - struct vop_setattr_args /* { - struct vnode *a_vp; - struct vattr *a_vap; - struct ucred *a_cred; - } */ *ap; +zfs_netbsd_setattr(void *v) { + struct vop_setattr_args *ap = v; vnode_t *vp = ap->a_vp; vattr_t *vap = ap->a_vap; cred_t *cred = ap->a_cred; xvattr_t xvap; u_long fflags; uint64_t zflags; + int flags = 0; vattr_init_mask(vap); vap->va_mask &= ~AT_NOSET; + if (ISSET(vap->va_vaflags, VA_UTIMES_NULL)) + flags |= ATTR_UTIME; xva_init(&xvap); xvap.xva_vattr = *vap; @@ -5164,25 +5345,18 @@ zflags = VTOZ(vp)->z_pflags; if (vap->va_flags != VNOVAL) { - zfsvfs_t *zfsvfs = VTOZ(vp)->z_zfsvfs; int error; - if (zfsvfs->z_use_fuids == B_FALSE) - return (EOPNOTSUPP); - fflags = vap->va_flags; - /* - * XXX KDM - * We need to figure out whether it makes sense to allow - * UF_REPARSE through, since we don't really have other - * facilities to handle reparse points and zfs_setattr() - * doesn't currently allow setting that attribute anyway. - */ - if ((fflags & ~(SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK|UF_ARCHIVE| - UF_NODUMP|UF_SYSTEM|UF_HIDDEN|UF_READONLY|UF_REPARSE| - UF_OFFLINE|UF_SPARSE)) != 0) + if ((fflags & ~(SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK|UF_NODUMP)) != 0) return (EOPNOTSUPP); /* + * Callers may only modify the file flags on objects they + * have VADMIN rights for. + */ + if ((error = VOP_ACCESS(vp, VWRITE, cred)) != 0) + return (error); + /* * Unprivileged processes are not permitted to unset system * flags, or modify flags if any system flags are set. * Privileged non-jail processes may not modify system flags @@ -5192,24 +5366,12 @@ * is non-zero; otherwise, they behave like unprivileged * processes. */ - if (secpolicy_fs_owner(vp->v_mount, cred) == 0 || - priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0) == 0) { + if (kauth_authorize_system(cred, KAUTH_SYSTEM_CHSYSFLAGS, 0, + NULL, NULL, NULL) != 0) { + if (zflags & (ZFS_IMMUTABLE | ZFS_APPENDONLY | ZFS_NOUNLINK)) { - error = securelevel_gt(cred, 0); - if (error != 0) - return (error); - } - } else { - /* - * Callers may only modify the file flags on objects they - * have VADMIN rights for. - */ - if ((error = VOP_ACCESS(vp, VADMIN, cred, curthread)) != 0) - return (error); - if (zflags & - (ZFS_IMMUTABLE | ZFS_APPENDONLY | ZFS_NOUNLINK)) { - return (EPERM); + return (EPERM); } if (fflags & (SF_IMMUTABLE | SF_APPEND | SF_NOUNLINK)) { @@ -5232,33 +5394,16 @@ xvap.xva_xoptattrs.xoa_appendonly); FLAG_CHANGE(SF_NOUNLINK, ZFS_NOUNLINK, XAT_NOUNLINK, xvap.xva_xoptattrs.xoa_nounlink); - FLAG_CHANGE(UF_ARCHIVE, ZFS_ARCHIVE, XAT_ARCHIVE, - xvap.xva_xoptattrs.xoa_archive); FLAG_CHANGE(UF_NODUMP, ZFS_NODUMP, XAT_NODUMP, xvap.xva_xoptattrs.xoa_nodump); - FLAG_CHANGE(UF_READONLY, ZFS_READONLY, XAT_READONLY, - xvap.xva_xoptattrs.xoa_readonly); - FLAG_CHANGE(UF_SYSTEM, ZFS_SYSTEM, XAT_SYSTEM, - xvap.xva_xoptattrs.xoa_system); - FLAG_CHANGE(UF_HIDDEN, ZFS_HIDDEN, XAT_HIDDEN, - xvap.xva_xoptattrs.xoa_hidden); - FLAG_CHANGE(UF_REPARSE, ZFS_REPARSE, XAT_REPARSE, - xvap.xva_xoptattrs.xoa_hidden); - FLAG_CHANGE(UF_OFFLINE, ZFS_OFFLINE, XAT_OFFLINE, - xvap.xva_xoptattrs.xoa_offline); - FLAG_CHANGE(UF_SPARSE, ZFS_SPARSE, XAT_SPARSE, - xvap.xva_xoptattrs.xoa_sparse); #undef FLAG_CHANGE } - if (vap->va_birthtime.tv_sec != VNOVAL) { - xvap.xva_vattr.va_mask |= AT_XVATTR; - XVA_SET_REQ(&xvap, XAT_CREATETIME); - } - return (zfs_setattr(vp, (vattr_t *)&xvap, 0, cred, NULL)); + return (zfs_setattr(vp, (vattr_t *)&xvap, flags, cred, NULL)); } static int -zfs_freebsd_rename(ap) +zfs_netbsd_rename(void *v) +{ struct vop_rename_args /* { struct vnode *a_fdvp; struct vnode *a_fvp; @@ -5266,810 +5411,622 @@ struct vnode *a_tdvp; struct vnode *a_tvp; struct componentname *a_tcnp; - } */ *ap; -{ + } */ *ap = v; vnode_t *fdvp = ap->a_fdvp; vnode_t *fvp = ap->a_fvp; + struct componentname *fcnp = ap->a_fcnp; vnode_t *tdvp = ap->a_tdvp; vnode_t *tvp = ap->a_tvp; + struct componentname *tcnp = ap->a_tcnp; + kauth_cred_t cred; int error; - ASSERT(ap->a_fcnp->cn_flags & (SAVENAME|SAVESTART)); - ASSERT(ap->a_tcnp->cn_flags & (SAVENAME|SAVESTART)); + KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE); + KASSERT(tvp == NULL || VOP_ISLOCKED(tvp) == LK_EXCLUSIVE); + KASSERT(fdvp->v_type == VDIR); + KASSERT(tdvp->v_type == VDIR); - error = zfs_rename(fdvp, &fvp, ap->a_fcnp, tdvp, &tvp, - ap->a_tcnp, ap->a_fcnp->cn_cred); + cred = fcnp->cn_cred; - vrele(fdvp); - vrele(fvp); - vrele(tdvp); + /* + * XXX Want a better equality test. `tcnp->cn_cred == cred' + * hoses p2k because puffs transmits the creds separately and + * allocates distinct but equivalent structures for them. + */ + KASSERT(kauth_cred_uidmatch(cred, tcnp->cn_cred)); + + /* + * Drop the insane locks. + */ + VOP_UNLOCK(tdvp, 0); + if (tvp != NULL && tvp != tdvp) + VOP_UNLOCK(tvp, 0); + + /* + * Release the source and target nodes; zfs_rename will look + * them up again once the locking situation is sane. + */ + VN_RELE(fvp); if (tvp != NULL) - vrele(tvp); + VN_RELE(tvp); + fvp = NULL; + tvp = NULL; + + /* + * Do the rename ZFSly. + */ + error = zfs_rename(fdvp, &fvp, fcnp, tdvp, &tvp, tcnp, cred); + + /* + * Release the directories now too, because the VOP_RENAME + * protocol is insane. + */ + + VN_RELE(fdvp); + VN_RELE(tdvp); + VN_RELE(fvp); + if (tvp != NULL) + VN_RELE(tvp); return (error); } static int -zfs_freebsd_symlink(ap) - struct vop_symlink_args /* { +zfs_netbsd_symlink(void *v) +{ + struct vop_symlink_v3_args /* { struct vnode *a_dvp; struct vnode **a_vpp; struct componentname *a_cnp; struct vattr *a_vap; char *a_target; - } */ *ap; -{ + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode **vpp = ap->a_vpp; struct componentname *cnp = ap->a_cnp; - vattr_t *vap = ap->a_vap; + struct vattr *vap = ap->a_vap; + char *target = ap->a_target; + int error; - ASSERT(cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); - vap->va_type = VLNK; /* FreeBSD: Syscall only sets va_mode. */ + vap->va_type = VLNK; /* Netbsd: Syscall only sets va_mode. */ vattr_init_mask(vap); - return (zfs_symlink(ap->a_dvp, ap->a_vpp, cnp->cn_nameptr, vap, - ap->a_target, cnp->cn_cred, cnp->cn_thread)); + error = zfs_symlink(dvp, vpp, __UNCONST(cnp->cn_nameptr), vap, target, + cnp->cn_cred, 0); + + KASSERT((error == 0) == (*vpp != NULL)); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); + VOP_UNLOCK(*vpp, 0); + + return (error); } static int -zfs_freebsd_readlink(ap) - struct vop_readlink_args /* { - struct vnode *a_vp; - struct uio *a_uio; - struct ucred *a_cred; - } */ *ap; +zfs_netbsd_readlink(void *v) { + struct vop_readlink_args *ap = v; return (zfs_readlink(ap->a_vp, ap->a_uio, ap->a_cred, NULL)); } static int -zfs_freebsd_link(ap) - struct vop_link_args /* { - struct vnode *a_tdvp; +zfs_netbsd_link(void *v) +{ + struct vop_link_v2_args /* { + struct vnode *a_dvp; struct vnode *a_vp; struct componentname *a_cnp; - } */ *ap; -{ + } */ *ap = v; + struct vnode *dvp = ap->a_dvp; + struct vnode *vp = ap->a_vp; struct componentname *cnp = ap->a_cnp; - vnode_t *vp = ap->a_vp; - vnode_t *tdvp = ap->a_tdvp; - - if (tdvp->v_mount != vp->v_mount) - return (EXDEV); + int error; - ASSERT(cnp->cn_flags & SAVENAME); + KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE); - return (zfs_link(tdvp, vp, cnp->cn_nameptr, cnp->cn_cred, NULL, 0)); + vn_lock(vp, LK_EXCLUSIVE); + error = zfs_link(dvp, vp, __UNCONST(cnp->cn_nameptr), cnp->cn_cred, + NULL, 0); + VOP_UNLOCK(vp, 0); + return error; } static int -zfs_freebsd_inactive(ap) - struct vop_inactive_args /* { - struct vnode *a_vp; - struct thread *a_td; - } */ *ap; +zfs_netbsd_inactive(void *v) { + struct vop_inactive_v2_args *ap = v; vnode_t *vp = ap->a_vp; + znode_t *zp = VTOZ(vp); + + /* + * NetBSD: nothing to do here, other than indicate if the + * vnode should be reclaimed. No need to lock, if we race + * vrele() will call us again. + */ + *ap->a_recycle = (zp->z_unlinked != 0); - zfs_inactive(vp, ap->a_td->td_ucred, NULL); return (0); } static int -zfs_freebsd_reclaim(ap) - struct vop_reclaim_args /* { - struct vnode *a_vp; - struct thread *a_td; - } */ *ap; +zfs_netbsd_reclaim(void *v) { - vnode_t *vp = ap->a_vp; - znode_t *zp = VTOZ(vp); - zfsvfs_t *zfsvfs = zp->z_zfsvfs; + struct vop_reclaim_v2_args /* { + struct vnode *a_vp; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + znode_t *zp; + zfsvfs_t *zfsvfs; + int error; + + VOP_UNLOCK(vp, 0); + zp = VTOZ(vp); + zfsvfs = zp->z_zfsvfs; - ASSERT(zp != NULL); + KASSERTMSG(!vn_has_cached_data(vp), "vp %p", vp); - /* Destroy the vm object and flush associated pages. */ - vnode_destroy_vobject(vp); + rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER); /* - * z_teardown_inactive_lock protects from a race with - * zfs_znode_dmu_fini in zfsvfs_teardown during - * force unmount. + * Process a deferred atime update. */ - rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER); + /* + * XXXNETBSD I don't think this actually works. + * We are dirtying the znode again after the vcache layer cleaned it, + * so we would need to zil_commit() again here. + */ + if (zp->z_atime_dirty && zp->z_unlinked == 0) { + dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os); + + dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); + zfs_sa_upgrade_txholds(tx, zp); + error = dmu_tx_assign(tx, TXG_WAIT); + if (error) { + dmu_tx_abort(tx); + } else { + (void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs), + (void *)&zp->z_atime, sizeof (zp->z_atime), tx); + zp->z_atime_dirty = 0; + dmu_tx_commit(tx); + } + } + if (zp->z_sa_hdl == NULL) zfs_znode_free(zp); else zfs_zinactive(zp); rw_exit(&zfsvfs->z_teardown_inactive_lock); - - vp->v_data = NULL; - return (0); + return 0; } static int -zfs_freebsd_fid(ap) - struct vop_fid_args /* { - struct vnode *a_vp; - struct fid *a_fid; - } */ *ap; +zfs_netbsd_fid(void *v) { + struct vop_fid_args *ap = v; return (zfs_fid(ap->a_vp, (void *)ap->a_fid, NULL)); } static int -zfs_freebsd_pathconf(ap) - struct vop_pathconf_args /* { - struct vnode *a_vp; - int a_name; - register_t *a_retval; - } */ *ap; +zfs_netbsd_pathconf(void *v) { + struct vop_pathconf_args *ap = v; ulong_t val; int error; - error = zfs_pathconf(ap->a_vp, ap->a_name, &val, curthread->td_ucred, NULL); + error = zfs_pathconf(ap->a_vp, ap->a_name, &val, curthread->l_cred, NULL); if (error == 0) *ap->a_retval = val; - else if (error == EOPNOTSUPP) - error = vop_stdpathconf(ap); + else if (error == EOPNOTSUPP) { + switch (ap->a_name) { + case _PC_NAME_MAX: + *ap->a_retval = NAME_MAX; + return (0); + case _PC_PATH_MAX: + *ap->a_retval = PATH_MAX; + return (0); + case _PC_LINK_MAX: + *ap->a_retval = LINK_MAX; + return (0); + case _PC_MAX_CANON: + *ap->a_retval = MAX_CANON; + return (0); + case _PC_MAX_INPUT: + *ap->a_retval = MAX_INPUT; + return (0); + case _PC_PIPE_BUF: + *ap->a_retval = PIPE_BUF; + return (0); + case _PC_CHOWN_RESTRICTED: + *ap->a_retval = 1; + return (0); + case _PC_NO_TRUNC: + *ap->a_retval = 1; + return (0); + case _PC_VDISABLE: + *ap->a_retval = _POSIX_VDISABLE; + return (0); + default: + return (EINVAL); + } + /* NOTREACHED */ + } return (error); } static int -zfs_freebsd_fifo_pathconf(ap) - struct vop_pathconf_args /* { - struct vnode *a_vp; - int a_name; - register_t *a_retval; - } */ *ap; +zfs_netbsd_advlock(void *v) { + struct vop_advlock_args /* { + struct vnode *a_vp; + void *a_id; + int a_op; + struct flock *a_fl; + int a_flags; + } */ *ap = v; + struct vnode *vp; + struct znode *zp; + struct zfsvfs *zfsvfs; + int error; - switch (ap->a_name) { - case _PC_ACL_EXTENDED: - case _PC_ACL_NFS4: - case _PC_ACL_PATH_MAX: - case _PC_MAC_PRESENT: - return (zfs_freebsd_pathconf(ap)); - default: - return (fifo_specops.vop_pathconf(ap)); - } -} + vp = ap->a_vp; + zp = VTOZ(vp); + zfsvfs = zp->z_zfsvfs; -/* - * FreeBSD's extended attributes namespace defines file name prefix for ZFS' - * extended attribute name: - * - * NAMESPACE PREFIX - * system freebsd:system: - * user (none, can be used to access ZFS fsattr(5) attributes - * created on Solaris) - */ -static int -zfs_create_attrname(int attrnamespace, const char *name, char *attrname, - size_t size) -{ - const char *namespace, *prefix, *suffix; + ZFS_ENTER(zfsvfs); + ZFS_VERIFY_ZP(zp); + error = lf_advlock(ap, &zp->z_lockf, zp->z_size); + ZFS_EXIT(zfsvfs); - /* We don't allow '/' character in attribute name. */ - if (strchr(name, '/') != NULL) - return (EINVAL); - /* We don't allow attribute names that start with "freebsd:" string. */ - if (strncmp(name, "freebsd:", 8) == 0) - return (EINVAL); - - bzero(attrname, size); - - switch (attrnamespace) { - case EXTATTR_NAMESPACE_USER: -#if 0 - prefix = "freebsd:"; - namespace = EXTATTR_NAMESPACE_USER_STRING; - suffix = ":"; -#else - /* - * This is the default namespace by which we can access all - * attributes created on Solaris. - */ - prefix = namespace = suffix = ""; -#endif - break; - case EXTATTR_NAMESPACE_SYSTEM: - prefix = "freebsd:"; - namespace = EXTATTR_NAMESPACE_SYSTEM_STRING; - suffix = ":"; - break; - case EXTATTR_NAMESPACE_EMPTY: - default: - return (EINVAL); - } - if (snprintf(attrname, size, "%s%s%s%s", prefix, namespace, suffix, - name) >= size) { - return (ENAMETOOLONG); - } - return (0); + return error; } -/* - * Vnode operating to retrieve a named extended attribute. - */ static int -zfs_getextattr(struct vop_getextattr_args *ap) -/* -vop_getextattr { - IN struct vnode *a_vp; - IN int a_attrnamespace; - IN const char *a_name; - INOUT struct uio *a_uio; - OUT size_t *a_size; - IN struct ucred *a_cred; - IN struct thread *a_td; -}; -*/ +zfs_netbsd_getpages(void *v) { - zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs; - struct thread *td = ap->a_td; - struct nameidata nd; - char attrname[255]; - struct vattr va; - vnode_t *xvp = NULL, *vp; - int error, flags; - - error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace, - ap->a_cred, ap->a_td, VREAD); - if (error != 0) - return (error); + struct vop_getpages_args /* { + struct vnode *a_vp; + voff_t a_offset; + struct vm_page **a_m; + int *a_count; + int a_centeridx; + vm_prot_t a_access_type; + int a_advice; + int a_flags; + } */ * const ap = v; - error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname, - sizeof(attrname)); - if (error != 0) - return (error); + vnode_t *const vp = ap->a_vp; + off_t offset = ap->a_offset + (ap->a_centeridx << PAGE_SHIFT); + const int flags = ap->a_flags; + const bool async = (flags & PGO_SYNCIO) == 0; + const bool memwrite = (ap->a_access_type & VM_PROT_WRITE) != 0; - ZFS_ENTER(zfsvfs); + struct uvm_object * const uobj = &vp->v_uobj; + kmutex_t * const mtx = uobj->vmobjlock; + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + struct vm_page *pg; + caddr_t va; + int npages, found, err = 0; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, - LOOKUP_XATTR); - if (error != 0) { - ZFS_EXIT(zfsvfs); - return (error); + if (flags & PGO_LOCKED) { + *ap->a_count = 0; + ap->a_m[ap->a_centeridx] = NULL; + return EBUSY; } + mutex_exit(mtx); - flags = FREAD; - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname, - xvp, td); - error = vn_open_cred(&nd, &flags, 0, 0, ap->a_cred, NULL); - vp = nd.ni_vp; - NDFREE(&nd, NDF_ONLY_PNBUF); - if (error != 0) { - ZFS_EXIT(zfsvfs); - if (error == ENOENT) - error = ENOATTR; - return (error); + if (async) { + return 0; } - if (ap->a_size != NULL) { - error = VOP_GETATTR(vp, &va, ap->a_cred); - if (error == 0) - *ap->a_size = (size_t)va.va_size; - } else if (ap->a_uio != NULL) - error = VOP_READ(vp, ap->a_uio, IO_UNIT, ap->a_cred); - - VOP_UNLOCK(vp, 0); - vn_close(vp, flags, ap->a_cred, td); - ZFS_EXIT(zfsvfs); - - return (error); -} - -/* - * Vnode operation to remove a named attribute. - */ -int -zfs_deleteextattr(struct vop_deleteextattr_args *ap) -/* -vop_deleteextattr { - IN struct vnode *a_vp; - IN int a_attrnamespace; - IN const char *a_name; - IN struct ucred *a_cred; - IN struct thread *a_td; -}; -*/ -{ - zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs; - struct thread *td = ap->a_td; - struct nameidata nd; - char attrname[255]; - struct vattr va; - vnode_t *xvp = NULL, *vp; - int error, flags; + ZFS_ENTER(zfsvfs); + ZFS_VERIFY_ZP(zp); - error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace, - ap->a_cred, ap->a_td, VWRITE); - if (error != 0) - return (error); + mutex_enter(mtx); + npages = 1; + pg = NULL; + uvn_findpages(uobj, offset, &npages, &pg, UFP_ALL); - error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname, - sizeof(attrname)); - if (error != 0) - return (error); + if (pg->flags & PG_FAKE) { + mutex_exit(mtx); - ZFS_ENTER(zfsvfs); + va = zfs_map_page(pg, S_WRITE); + err = dmu_read(zfsvfs->z_os, zp->z_id, offset, PAGE_SIZE, + va, DMU_READ_PREFETCH); + zfs_unmap_page(pg, va); - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, - LOOKUP_XATTR); - if (error != 0) { - ZFS_EXIT(zfsvfs); - return (error); + mutex_enter(mtx); + pg->flags &= ~(PG_FAKE); + pmap_clear_modify(pg); } - NDINIT_ATVP(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF, - UIO_SYSSPACE, attrname, xvp, td); - error = namei(&nd); - vp = nd.ni_vp; - if (error != 0) { - ZFS_EXIT(zfsvfs); - NDFREE(&nd, NDF_ONLY_PNBUF); - if (error == ENOENT) - error = ENOATTR; - return (error); + if (memwrite) { + if ((vp->v_iflag & VI_ONWORKLST) == 0) { + vn_syncer_add_to_worklist(vp, filedelay); + } + if ((vp->v_iflag & (VI_WRMAP|VI_WRMAPDIRTY)) == VI_WRMAP) { + vp->v_iflag |= VI_WRMAPDIRTY; + } } + mutex_exit(mtx); + ap->a_m[ap->a_centeridx] = pg; - error = VOP_REMOVE(nd.ni_dvp, vp, &nd.ni_cnd); - NDFREE(&nd, NDF_ONLY_PNBUF); - - vput(nd.ni_dvp); - if (vp == nd.ni_dvp) - vrele(vp); - else - vput(vp); ZFS_EXIT(zfsvfs); - return (error); + return (err); } -/* - * Vnode operation to set a named attribute. - */ static int -zfs_setextattr(struct vop_setextattr_args *ap) -/* -vop_setextattr { - IN struct vnode *a_vp; - IN int a_attrnamespace; - IN const char *a_name; - INOUT struct uio *a_uio; - IN struct ucred *a_cred; - IN struct thread *a_td; -}; -*/ +zfs_putapage(vnode_t *vp, page_t **pp, int count, int flags) { - zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs; - struct thread *td = ap->a_td; - struct nameidata nd; - char attrname[255]; - struct vattr va; - vnode_t *xvp = NULL, *vp; - int error, flags; - - error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace, - ap->a_cred, ap->a_td, VWRITE); - if (error != 0) - return (error); - - error = zfs_create_attrname(ap->a_attrnamespace, ap->a_name, attrname, - sizeof(attrname)); - if (error != 0) - return (error); + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + dmu_tx_t *tx; + voff_t off, koff; + voff_t len, klen; + int err; - ZFS_ENTER(zfsvfs); + bool async = (flags & PGO_SYNCIO) == 0; + bool *cleanedp; + struct uvm_object *uobj = &vp->v_uobj; + kmutex_t *mtx = uobj->vmobjlock; + + off = pp[0]->offset; + len = count * PAGESIZE; + KASSERT(off + len <= round_page(zp->z_size)); - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, - LOOKUP_XATTR | CREATE_XATTR_DIR); - if (error != 0) { - ZFS_EXIT(zfsvfs); - return (error); + if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) || + zfs_owner_overquota(zfsvfs, zp, B_TRUE)) { + err = SET_ERROR(EDQUOT); + goto out; } + tx = dmu_tx_create(zfsvfs->z_os); + dmu_tx_hold_write(tx, zp->z_id, off, len); - flags = FFLAGS(O_WRONLY | O_CREAT); - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname, - xvp, td); - error = vn_open_cred(&nd, &flags, 0600, 0, ap->a_cred, NULL); - vp = nd.ni_vp; - NDFREE(&nd, NDF_ONLY_PNBUF); - if (error != 0) { - ZFS_EXIT(zfsvfs); - return (error); + dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); + zfs_sa_upgrade_txholds(tx, zp); + err = dmu_tx_assign(tx, TXG_WAIT); + if (err != 0) { + dmu_tx_abort(tx); + goto out; } - VATTR_NULL(&va); - va.va_size = 0; - error = VOP_SETATTR(vp, &va, ap->a_cred); - if (error == 0) - VOP_WRITE(vp, ap->a_uio, IO_UNIT, ap->a_cred); - - VOP_UNLOCK(vp, 0); - vn_close(vp, flags, ap->a_cred, td); - ZFS_EXIT(zfsvfs); - - return (error); -} - -/* - * Vnode operation to retrieve extended attributes on a vnode. - */ -static int -zfs_listextattr(struct vop_listextattr_args *ap) -/* -vop_listextattr { - IN struct vnode *a_vp; - IN int a_attrnamespace; - INOUT struct uio *a_uio; - OUT size_t *a_size; - IN struct ucred *a_cred; - IN struct thread *a_td; -}; -*/ -{ - zfsvfs_t *zfsvfs = VTOZ(ap->a_vp)->z_zfsvfs; - struct thread *td = ap->a_td; - struct nameidata nd; - char attrprefix[16]; - u_char dirbuf[sizeof(struct dirent)]; - struct dirent *dp; - struct iovec aiov; - struct uio auio, *uio = ap->a_uio; - size_t *sizep = ap->a_size; - size_t plen; - vnode_t *xvp = NULL, *vp; - int done, error, eof, pos; - - error = extattr_check_cred(ap->a_vp, ap->a_attrnamespace, - ap->a_cred, ap->a_td, VREAD); - if (error != 0) - return (error); - - error = zfs_create_attrname(ap->a_attrnamespace, "", attrprefix, - sizeof(attrprefix)); - if (error != 0) - return (error); - plen = strlen(attrprefix); - - ZFS_ENTER(zfsvfs); + if (zp->z_blksz <= PAGESIZE) { + KASSERTMSG(count == 1, "vp %p pp %p count %d", vp, pp, count); + caddr_t va = zfs_map_page(*pp, S_READ); + ASSERT3U(len, <=, PAGESIZE); + dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx); + zfs_unmap_page(*pp, va); + } else { + err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx); + } + cleanedp = tsd_get(zfs_putpage_key); + *cleanedp = true; - if (sizep != NULL) - *sizep = 0; + if (err == 0) { + uint64_t mtime[2], ctime[2]; + sa_bulk_attr_t bulk[3]; + int count = 0; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, - LOOKUP_XATTR); - if (error != 0) { - ZFS_EXIT(zfsvfs); - /* - * ENOATTR means that the EA directory does not yet exist, - * i.e. there are no extended attributes there. - */ - if (error == ENOATTR) - error = 0; - return (error); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, + &mtime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, + &ctime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, + &zp->z_pflags, 8); + zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, + B_TRUE); + err = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); + ASSERT0(err); + zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0); } + dmu_tx_commit(tx); - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKSHARED, - UIO_SYSSPACE, ".", xvp, td); - error = namei(&nd); - vp = nd.ni_vp; - NDFREE(&nd, NDF_ONLY_PNBUF); - if (error != 0) { - ZFS_EXIT(zfsvfs); - return (error); + if (async) { + mutex_enter(mtx); + mutex_enter(&uvm_pageqlock); + uvm_page_unbusy(pp, count); + mutex_exit(&uvm_pageqlock); + mutex_exit(mtx); } - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_td = td; - auio.uio_rw = UIO_READ; - auio.uio_offset = 0; - - do { - u_char nlen; - - aiov.iov_base = (void *)dirbuf; - aiov.iov_len = sizeof(dirbuf); - auio.uio_resid = sizeof(dirbuf); - error = VOP_READDIR(vp, &auio, ap->a_cred, &eof, NULL, NULL); - done = sizeof(dirbuf) - auio.uio_resid; - if (error != 0) - break; - for (pos = 0; pos < done;) { - dp = (struct dirent *)(dirbuf + pos); - pos += dp->d_reclen; - /* - * XXX: Temporarily we also accept DT_UNKNOWN, as this - * is what we get when attribute was created on Solaris. - */ - if (dp->d_type != DT_REG && dp->d_type != DT_UNKNOWN) - continue; - if (plen == 0 && strncmp(dp->d_name, "freebsd:", 8) == 0) - continue; - else if (strncmp(dp->d_name, attrprefix, plen) != 0) - continue; - nlen = dp->d_namlen - plen; - if (sizep != NULL) - *sizep += 1 + nlen; - else if (uio != NULL) { - /* - * Format of extattr name entry is one byte for - * length and the rest for name. - */ - error = uiomove(&nlen, 1, uio->uio_rw, uio); - if (error == 0) { - error = uiomove(dp->d_name + plen, nlen, - uio->uio_rw, uio); - } - if (error != 0) - break; - } - } - } while (!eof && error == 0); - - vput(vp); - ZFS_EXIT(zfsvfs); - - return (error); +out: + return (err); } -int -zfs_freebsd_getacl(ap) - struct vop_getacl_args /* { - struct vnode *vp; - acl_type_t type; - struct acl *aclp; - struct ucred *cred; - struct thread *td; - } */ *ap; +static void +zfs_netbsd_gop_markupdate(vnode_t *vp, int flags) { - int error; - vsecattr_t vsecattr; - - if (ap->a_type != ACL_TYPE_NFS4) - return (EINVAL); - - vsecattr.vsa_mask = VSA_ACE | VSA_ACECNT; - if (error = zfs_getsecattr(ap->a_vp, &vsecattr, 0, ap->a_cred, NULL)) - return (error); + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + dmu_tx_t *tx; + sa_bulk_attr_t bulk[2]; + uint64_t mtime[2], ctime[2]; + int count = 0, err; - error = acl_from_aces(ap->a_aclp, vsecattr.vsa_aclentp, vsecattr.vsa_aclcnt); - if (vsecattr.vsa_aclentp != NULL) - kmem_free(vsecattr.vsa_aclentp, vsecattr.vsa_aclentsz); + KASSERT(flags == GOP_UPDATE_MODIFIED); - return (error); + tx = dmu_tx_create(zfsvfs->z_os); + err = dmu_tx_assign(tx, TXG_WAIT); + if (err != 0) { + dmu_tx_abort(tx); + return; + } + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16); + zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, B_TRUE); + dmu_tx_commit(tx); } -int -zfs_freebsd_setacl(ap) - struct vop_setacl_args /* { - struct vnode *vp; - acl_type_t type; - struct acl *aclp; - struct ucred *cred; - struct thread *td; - } */ *ap; +static int +zfs_netbsd_putpages(void *v) { - int error; - vsecattr_t vsecattr; - int aclbsize; /* size of acl list in bytes */ - aclent_t *aaclp; + struct vop_putpages_args /* { + struct vnode *a_vp; + voff_t a_offlo; + voff_t a_offhi; + int a_flags; + } */ * const ap = v; - if (ap->a_type != ACL_TYPE_NFS4) - return (EINVAL); + struct vnode *vp = ap->a_vp; + voff_t offlo = ap->a_offlo; + voff_t offhi = ap->a_offhi; + int flags = ap->a_flags; - if (ap->a_aclp == NULL) - return (EINVAL); + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + rl_t *rl = NULL; + int error; + bool cleaned = false; - if (ap->a_aclp->acl_cnt < 1 || ap->a_aclp->acl_cnt > MAX_ACL_ENTRIES) - return (EINVAL); + bool async = (flags & PGO_SYNCIO) == 0; + bool cleaning = (flags & PGO_CLEANIT) != 0; - /* - * With NFSv4 ACLs, chmod(2) may need to add additional entries, - * splitting every entry into two and appending "canonical six" - * entries at the end. Don't allow for setting an ACL that would - * cause chmod(2) to run out of ACL entries. - */ - if (ap->a_aclp->acl_cnt * 2 + 6 > ACL_MAX_ENTRIES) - return (ENOSPC); + ZFS_ENTER(zfsvfs); + ZFS_VERIFY_ZP(zp); - error = acl_nfs4_check(ap->a_aclp, ap->a_vp->v_type == VDIR); - if (error != 0) - return (error); + if (cleaning) { + rl = zfs_range_lock(zp, offlo, offhi, RL_WRITER); + tsd_set(zfs_putpage_key, &cleaned); + } + error = genfs_putpages(v); + if (rl) { + tsd_set(zfs_putpage_key, NULL); + zfs_range_unlock(rl); + } - vsecattr.vsa_mask = VSA_ACE; - aclbsize = ap->a_aclp->acl_cnt * sizeof(ace_t); - vsecattr.vsa_aclentp = kmem_alloc(aclbsize, KM_SLEEP); - aaclp = vsecattr.vsa_aclentp; - vsecattr.vsa_aclentsz = aclbsize; - - aces_from_acl(vsecattr.vsa_aclentp, &vsecattr.vsa_aclcnt, ap->a_aclp); - error = zfs_setsecattr(ap->a_vp, &vsecattr, 0, ap->a_cred, NULL); - kmem_free(aaclp, aclbsize); + /* + * Only zil_commit() if we cleaned something. + * This avoids deadlock if we're called from zfs_netbsd_setsize(). + */ - return (error); + if (cleaned) + if (!async || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS) + zil_commit(zfsvfs->z_log, zp->z_id); + ZFS_EXIT(zfsvfs); + return error; } -int -zfs_freebsd_aclcheck(ap) - struct vop_aclcheck_args /* { - struct vnode *vp; - acl_type_t type; - struct acl *aclp; - struct ucred *cred; - struct thread *td; - } */ *ap; +/* + * Restrict the putpages range to the ZFS block containing the offset. + */ +static void +zfs_netbsd_gop_putrange(struct vnode *vp, off_t off, off_t *lop, off_t *hip) { + znode_t *zp = VTOZ(vp); - return (EOPNOTSUPP); + *lop = trunc_page(rounddown2(off, zp->z_blksz)); + *hip = round_page(*lop + zp->z_blksz); } -static int -zfs_vptocnp(struct vop_vptocnp_args *ap) +void +zfs_netbsd_setsize(vnode_t *vp, off_t size) { - vnode_t *covered_vp; - vnode_t *vp = ap->a_vp;; - zfsvfs_t *zfsvfs = vp->v_vfsp->vfs_data; - znode_t *zp = VTOZ(vp); - uint64_t parent; - int ltype; - int error; + struct uvm_object *uobj = &vp->v_uobj; + kmutex_t *mtx = uobj->vmobjlock; + page_t *pg; + int count, pgoff; + caddr_t va; + off_t tsize; - ZFS_ENTER(zfsvfs); - ZFS_VERIFY_ZP(zp); + uvm_vnp_setsize(vp, size); + if (!vn_has_cached_data(vp)) + return; + + tsize = trunc_page(size); + if (tsize == size) + return; /* - * If we are a snapshot mounted under .zfs, run the operation - * on the covered vnode. + * If there's a partial page, we need to zero the tail. */ - if ((error = sa_lookup(zp->z_sa_hdl, - SA_ZPL_PARENT(zfsvfs), &parent, sizeof (parent))) != 0) { - ZFS_EXIT(zfsvfs); - return (error); - } - - if (zp->z_id != parent || zfsvfs->z_parent == zfsvfs) { - char name[MAXNAMLEN + 1]; - znode_t *dzp; - size_t len; - error = zfs_znode_parent_and_name(zp, &dzp, name); - if (error == 0) { - len = strlen(name); - if (*ap->a_buflen < len) - error = SET_ERROR(ENOMEM); - } - if (error == 0) { - *ap->a_buflen -= len; - bcopy(name, ap->a_buf + *ap->a_buflen, len); - *ap->a_vpp = ZTOV(dzp); - } - ZFS_EXIT(zfsvfs); - return (error); + mutex_enter(mtx); + count = 1; + pg = NULL; + if (uvn_findpages(uobj, tsize, &count, &pg, UFP_NOALLOC)) { + va = zfs_map_page(pg, S_WRITE); + pgoff = size - tsize; + memset(va + pgoff, 0, PAGESIZE - pgoff); + zfs_unmap_page(pg, va); + uvm_page_unbusy(&pg, 1); } - ZFS_EXIT(zfsvfs); - covered_vp = vp->v_mount->mnt_vnodecovered; - vhold(covered_vp); - ltype = VOP_ISLOCKED(vp); - VOP_UNLOCK(vp, 0); - error = vget(covered_vp, LK_SHARED | LK_VNHELD, curthread); - if (error == 0) { - error = VOP_VPTOCNP(covered_vp, ap->a_vpp, ap->a_cred, - ap->a_buf, ap->a_buflen); - vput(covered_vp); - } - vn_lock(vp, ltype | LK_RETRY); - if ((vp->v_iflag & VI_DOOMED) != 0) - error = SET_ERROR(ENOENT); - return (error); + mutex_exit(mtx); } -#ifdef DIAGNOSTIC static int -zfs_lock(ap) - struct vop_lock1_args /* { - struct vnode *a_vp; - int a_flags; - char *file; - int line; - } */ *ap; +zfs_netbsd_print(void *v) { - vnode_t *vp; - znode_t *zp; - int err; + struct vop_print_args /* { + struct vnode *a_vp; + } */ *ap = v; + vnode_t *vp; + znode_t *zp; - err = vop_stdlock(ap); - if (err == 0 && (ap->a_flags & LK_NOWAIT) == 0) { - vp = ap->a_vp; - zp = vp->v_data; - if (vp->v_mount != NULL && (vp->v_iflag & VI_DOOMED) == 0 && - zp != NULL && (zp->z_pflags & ZFS_XATTR) == 0) - VERIFY(!RRM_LOCK_HELD(&zp->z_zfsvfs->z_teardown_lock)); - } - return (err); + vp = ap->a_vp; + zp = VTOZ(vp); + + printf("\tino %" PRIu64 " size %" PRIu64 "\n", + zp->z_id, zp->z_size); + return 0; } -#endif -struct vop_vector zfs_vnodeops; -struct vop_vector zfs_fifoops; -struct vop_vector zfs_shareops; - -struct vop_vector zfs_vnodeops = { - .vop_default = &default_vnodeops, - .vop_inactive = zfs_freebsd_inactive, - .vop_reclaim = zfs_freebsd_reclaim, - .vop_access = zfs_freebsd_access, - .vop_lookup = zfs_cache_lookup, - .vop_cachedlookup = zfs_freebsd_lookup, - .vop_getattr = zfs_freebsd_getattr, - .vop_setattr = zfs_freebsd_setattr, - .vop_create = zfs_freebsd_create, - .vop_mknod = zfs_freebsd_create, - .vop_mkdir = zfs_freebsd_mkdir, - .vop_readdir = zfs_freebsd_readdir, - .vop_fsync = zfs_freebsd_fsync, - .vop_open = zfs_freebsd_open, - .vop_close = zfs_freebsd_close, - .vop_rmdir = zfs_freebsd_rmdir, - .vop_ioctl = zfs_freebsd_ioctl, - .vop_link = zfs_freebsd_link, - .vop_symlink = zfs_freebsd_symlink, - .vop_readlink = zfs_freebsd_readlink, - .vop_read = zfs_freebsd_read, - .vop_write = zfs_freebsd_write, - .vop_remove = zfs_freebsd_remove, - .vop_rename = zfs_freebsd_rename, - .vop_pathconf = zfs_freebsd_pathconf, - .vop_bmap = zfs_freebsd_bmap, - .vop_fid = zfs_freebsd_fid, - .vop_getextattr = zfs_getextattr, - .vop_deleteextattr = zfs_deleteextattr, - .vop_setextattr = zfs_setextattr, - .vop_listextattr = zfs_listextattr, - .vop_getacl = zfs_freebsd_getacl, - .vop_setacl = zfs_freebsd_setacl, - .vop_aclcheck = zfs_freebsd_aclcheck, - .vop_getpages = zfs_freebsd_getpages, - .vop_putpages = zfs_freebsd_putpages, - .vop_vptocnp = zfs_vptocnp, -#ifdef DIAGNOSTIC - .vop_lock1 = zfs_lock, -#endif +const struct genfs_ops zfs_genfsops = { + .gop_write = zfs_putapage, + .gop_markupdate = zfs_netbsd_gop_markupdate, + .gop_putrange = zfs_netbsd_gop_putrange, }; -struct vop_vector zfs_fifoops = { - .vop_default = &fifo_specops, - .vop_fsync = zfs_freebsd_fsync, - .vop_access = zfs_freebsd_access, - .vop_getattr = zfs_freebsd_getattr, - .vop_inactive = zfs_freebsd_inactive, - .vop_read = VOP_PANIC, - .vop_reclaim = zfs_freebsd_reclaim, - .vop_setattr = zfs_freebsd_setattr, - .vop_write = VOP_PANIC, - .vop_pathconf = zfs_freebsd_fifo_pathconf, - .vop_fid = zfs_freebsd_fid, - .vop_getacl = zfs_freebsd_getacl, - .vop_setacl = zfs_freebsd_setacl, - .vop_aclcheck = zfs_freebsd_aclcheck, +#define zfs_netbsd_lock genfs_lock +#define zfs_netbsd_unlock genfs_unlock +#define zfs_netbsd_islocked genfs_islocked +#define zfs_netbsd_seek genfs_seek +#define zfs_netbsd_mmap genfs_mmap +#define zfs_netbsd_fcntl genfs_fcntl + +int (**zfs_vnodeop_p)(void *); +const struct vnodeopv_entry_desc zfs_vnodeop_entries[] = { + { &vop_default_desc, vn_default_error }, + { &vop_lookup_desc, zfs_netbsd_lookup }, + { &vop_create_desc, zfs_netbsd_create }, + { &vop_open_desc, zfs_netbsd_open }, + { &vop_close_desc, zfs_netbsd_close }, + { &vop_access_desc, zfs_netbsd_access }, + { &vop_getattr_desc, zfs_netbsd_getattr }, + { &vop_setattr_desc, zfs_netbsd_setattr }, + { &vop_read_desc, zfs_netbsd_read }, + { &vop_write_desc, zfs_netbsd_write }, + { &vop_ioctl_desc, zfs_netbsd_ioctl }, + { &vop_fsync_desc, zfs_netbsd_fsync }, + { &vop_remove_desc, zfs_netbsd_remove }, + { &vop_link_desc, zfs_netbsd_link }, + { &vop_lock_desc, zfs_netbsd_lock }, + { &vop_unlock_desc, zfs_netbsd_unlock }, + { &vop_rename_desc, zfs_netbsd_rename }, + { &vop_mkdir_desc, zfs_netbsd_mkdir }, + { &vop_rmdir_desc, zfs_netbsd_rmdir }, + { &vop_symlink_desc, zfs_netbsd_symlink }, + { &vop_readdir_desc, zfs_netbsd_readdir }, + { &vop_readlink_desc, zfs_netbsd_readlink }, + { &vop_inactive_desc, zfs_netbsd_inactive }, + { &vop_reclaim_desc, zfs_netbsd_reclaim }, + { &vop_pathconf_desc, zfs_netbsd_pathconf }, + { &vop_seek_desc, zfs_netbsd_seek }, + { &vop_getpages_desc, zfs_netbsd_getpages }, + { &vop_putpages_desc, zfs_netbsd_putpages }, + { &vop_mmap_desc, zfs_netbsd_mmap }, + { &vop_islocked_desc, zfs_netbsd_islocked }, + { &vop_advlock_desc, zfs_netbsd_advlock }, + { &vop_print_desc, zfs_netbsd_print }, + { &vop_fcntl_desc, zfs_netbsd_fcntl }, + { NULL, NULL } }; -/* - * special share hidden files vnode operations template - */ -struct vop_vector zfs_shareops = { - .vop_default = &default_vnodeops, - .vop_access = zfs_freebsd_access, - .vop_inactive = zfs_freebsd_inactive, - .vop_reclaim = zfs_freebsd_reclaim, - .vop_fid = zfs_freebsd_fid, - .vop_pathconf = zfs_freebsd_pathconf, -}; +const struct vnodeopv_desc zfs_vnodeop_opv_desc = + { &zfs_vnodeop_p, zfs_vnodeop_entries }; + +#endif /* __NetBSD__ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c 2016-12-03 09:03:49.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c 2017-07-10 13:29:31.000000000 -0700 @@ -52,6 +52,24 @@ #include #include #include + +#ifdef __NetBSD__ +#include + +extern int (**zfs_vnodeop_p)(void *); +extern int (**zfs_fifoop_p)(void *); +extern int (**zfs_specop_p)(void *); + +struct zfs_loadvnode_args { + dmu_buf_t *db; + int blksz; + dmu_object_type_t obj_type; + void *sa_hdl; +}; + +uint_t zfs_loadvnode_key; + +#endif #endif /* _KERNEL */ #include @@ -120,6 +138,9 @@ { znode_t *zp = buf; +#ifdef __NetBSD__ + zp = arg; +#endif POINTER_INVALIDATE(&zp->z_zfsvfs); list_link_init(&zp->z_link_node); @@ -142,9 +163,14 @@ { znode_t *zp = buf; +#ifdef __NetBSD__ + zp = arg; +#endif ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs)); ASSERT(ZTOV(zp) == NULL); +#ifndef __NetBSD__ vn_free(ZTOV(zp)); +#endif ASSERT(!list_link_active(&zp->z_link_node)); mutex_destroy(&zp->z_acl_lock); avl_destroy(&zp->z_range_avl); @@ -584,6 +610,7 @@ zp->z_sa_hdl = NULL; } +#ifdef __FreeBSD__ static void zfs_vnode_forget(vnode_t *vp) { @@ -737,6 +764,7 @@ #endif return (zp); } +#endif /* __FreeBSD__ */ static uint64_t empty_xattr; static uint64_t pad[4]; @@ -978,7 +1006,20 @@ VERIFY(sa_replace_all_by_template(sa_hdl, sa_attrs, cnt, tx) == 0); if (!(flag & IS_ROOT_NODE)) { +#ifdef __NetBSD__ + vnode_t *vp; + struct zfs_loadvnode_args args = { db, 0, obj_type, sa_hdl }; + + tsd_set(zfs_loadvnode_key, &args); + err = vcache_get(zfsvfs->z_vfs, &obj, sizeof(obj), &vp); + tsd_set(zfs_loadvnode_key, NULL); + + ASSERT3U(err, ==, 0); + *zpp = VTOZ(vp); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); +#else *zpp = zfs_znode_alloc(zfsvfs, db, 0, obj_type, sa_hdl); +#endif ASSERT(*zpp != NULL); } else { /* @@ -1000,6 +1041,7 @@ acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) { VERIFY0(zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx)); } +#ifndef __NetBSD__ if (!(flag & IS_ROOT_NODE)) { vnode_t *vp; @@ -1009,6 +1051,7 @@ vp->v_vflag &= ~VV_FORCEINSMQ; KASSERT(err == 0, ("insmntque() failed: error %d", err)); } +#endif ZFS_OBJ_HOLD_EXIT(zfsvfs, obj); } @@ -1107,6 +1150,235 @@ } } +#ifdef __NetBSD__ + +static inline int +zfs_do_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp, + int (*get)(struct mount *, const void *, size_t, struct vnode **)) +{ + struct vnode *vp; + int err; + + ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num); + + err = (*get)(zfsvfs->z_vfs, &obj_num, sizeof(obj_num), &vp); + if (err) + *zpp = NULL; + else + *zpp = VTOZ(vp); + + ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num); + + return (err); +} + +int +zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp) +{ + + return zfs_do_zget(zfsvfs, obj_num, zpp, vcache_get); +} + +int +zfs_zget_cleaner(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp) +{ + dmu_buf_t *db; + sa_handle_t *hdl; + dmu_object_info_t doi; + znode_t *zp; + int err; + + err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db); + if (err) { + return (SET_ERROR(err)); + } + + dmu_object_info_from_db(db, &doi); + if (doi.doi_bonus_type != DMU_OT_SA && + (doi.doi_bonus_type != DMU_OT_ZNODE || + (doi.doi_bonus_type == DMU_OT_ZNODE && + doi.doi_bonus_size < sizeof (znode_phys_t)))) { + sa_buf_rele(db, NULL); + return (SET_ERROR(EINVAL)); + } + hdl = dmu_buf_get_user(db); + KASSERT(hdl != NULL); + zp = sa_get_userdata(hdl); + *zpp = zp; + return (0); +} + +/* + * Callback from vcache to set up the znode. + * This is largely copied from zfs_znode_alloc(). + */ + +int +zfs_loadvnode(struct mount *mp, struct vnode *vp, + const void *key, size_t key_len, const void **new_key) +{ + znode_t *zp; + uint64_t mode; + uint64_t parent; + sa_bulk_attr_t bulk[9]; + int count = 0; + int err; + + uint64_t obj_num, rdev; + zfsvfs_t *zfsvfs; + dmu_object_info_t doi; + + /* args to zfs_zvnode_alloc() */ + struct zfs_loadvnode_args *args; + dmu_buf_t *db; + int blksz; + dmu_object_type_t obj_type; + sa_handle_t *hdl; + + KASSERT(key_len == sizeof(obj_num)); + memcpy(&obj_num, key, key_len); + + zfsvfs = mp->mnt_data; + + args = tsd_get(zfs_loadvnode_key); + if (args) { + db = args->db; + blksz = args->blksz; + obj_type = args->obj_type; + hdl = args->sa_hdl; + goto skip_lookup; + } + + err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db); + if (err) { + return (SET_ERROR(err)); + } + + dmu_object_info_from_db(db, &doi); + if (doi.doi_bonus_type != DMU_OT_SA && + (doi.doi_bonus_type != DMU_OT_ZNODE || + (doi.doi_bonus_type == DMU_OT_ZNODE && + doi.doi_bonus_size < sizeof (znode_phys_t)))) { + sa_buf_rele(db, NULL); + return (SET_ERROR(EINVAL)); + } + blksz = doi.doi_data_block_size; + obj_type = doi.doi_bonus_type; + hdl = dmu_buf_get_user(db); + + if (hdl != NULL) { + zp = sa_get_userdata(hdl); + + /* + * Since "SA" does immediate eviction we + * should never find a sa handle that doesn't + * know about the znode. + */ + ASSERT3P(zp, !=, NULL); + ASSERT3U(zp->z_id, ==, obj_num); + + sa_buf_rele(db, NULL); + VFS_HOLD(zfsvfs->z_vfs); + *new_key = &zp->z_id; + return (0); + } + +skip_lookup: + vp->v_op = zfs_vnodeop_p; + vp->v_tag = VT_ZFS; + + zp = kmem_cache_alloc(znode_cache, KM_SLEEP); + zp->z_vnode = vp; + vp->v_data = zp; + + extern const struct genfs_ops zfs_genfsops; + genfs_node_init(vp, &zfs_genfsops); + + ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs)); + zp->z_moved = 0; + + /* + * Defer setting z_zfsvfs until the znode is ready to be a candidate for + * the zfs_znode_move() callback. + */ + zp->z_sa_hdl = NULL; + zp->z_unlinked = 0; + zp->z_atime_dirty = 0; + zp->z_mapcnt = 0; + zp->z_id = db->db_object; + zp->z_blksz = blksz; + zp->z_seq = 0x7A4653; + zp->z_sync_cnt = 0; + + zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl); + + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL, &zp->z_gen, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL, + &zp->z_size, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, + &zp->z_links, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, + &zp->z_pflags, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL, &parent, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL, + &zp->z_atime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL, + &zp->z_uid, 8); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL, + &zp->z_gid, 8); + + if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || zp->z_gen == 0) { + if (hdl == NULL) + sa_handle_destroy(zp->z_sa_hdl); + zp->z_vnode = NULL; + kmem_cache_free(znode_cache, zp); + sa_buf_rele(db, NULL); + return (SET_ERROR(ENOENT)); + } + + zp->z_mode = mode; + + vp->v_type = IFTOVT((mode_t)zp->z_mode); + + switch (vp->v_type) { + case VDIR: + zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */ + break; + case VBLK: + case VCHR: + /* XXX NetBSD vp->v_op = zfs_specop_p; */ + (void) sa_lookup(hdl, SA_ZPL_RDEV(zfsvfs), &rdev, + sizeof (rdev)); + spec_node_init(vp, zfs_cmpldev(rdev)); + break; + case VFIFO: + /* XXX NetBSD vp->v_op = zfs_fifoop_p; */ + break; + } + + uvm_vnp_setsize(vp, zp->z_size); + dprintf("zfs_loadvnode znode %p -- vnode %p\n", zp, vp); + dprintf("zfs_loadvnode z_id %ld\n", zp->z_id); + + mutex_enter(&zfsvfs->z_znodes_lock); + list_insert_tail(&zfsvfs->z_all_znodes, zp); + membar_producer(); + + /* + * Everything else must be valid before assigning z_zfsvfs makes the + * znode eligible for zfs_znode_move(). + */ + zp->z_zfsvfs = zfsvfs; + mutex_exit(&zfsvfs->z_znodes_lock); + + VFS_HOLD(zfsvfs->z_vfs); + *new_key = &zp->z_id; + return (0); +} + +#else /* __NetBSD__ */ + int zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp) { @@ -1237,6 +1509,8 @@ return (err); } +#endif /* __NetBSD__ */ + int zfs_rezget(znode_t *zp) { @@ -1400,6 +1674,19 @@ { zfsvfs_t *zfsvfs = zp->z_zfsvfs; +#ifdef __NetBSD__ + struct vnode *vp = ZTOV(zp); + + genfs_node_destroy(vp); + + /* + * Interlock with zfs_sync(). + */ + mutex_enter(vp->v_interlock); + vp->v_data = NULL; + mutex_exit(vp->v_interlock); +#endif + ASSERT(zp->z_sa_hdl == NULL); zp->z_vnode = NULL; mutex_enter(&zfsvfs->z_znodes_lock); @@ -1927,6 +2214,7 @@ for (i = 0; i != ZFS_OBJ_MTX_SZ; i++) mutex_destroy(&zfsvfs->z_hold_mtx[i]); + mutex_destroy(&zfsvfs->z_znodes_lock); kmem_free(zfsvfs, sizeof (zfsvfs_t)); } #endif /* _KERNEL */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zio.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zio.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zio.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zio.c 2017-05-07 07:10:06.000000000 -0700 @@ -45,11 +45,15 @@ SYSCTL_DECL(_vfs_zfs); SYSCTL_NODE(_vfs_zfs, OID_AUTO, zio, CTLFLAG_RW, 0, "ZFS ZIO"); +#ifdef __NetBSD__ +const int zio_use_uma = 0; +#else #if defined(__amd64__) static int zio_use_uma = 1; #else static int zio_use_uma = 0; #endif +#endif SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, use_uma, CTLFLAG_RDTUN, &zio_use_uma, 0, "Use uma(9) for ZIO allocations"); static int zio_exclude_metadata = 0; @@ -151,6 +155,8 @@ sizeof (zio_t), 0, NULL, NULL, NULL, NULL, NULL, 0); zio_link_cache = kmem_cache_create("zio_link_cache", sizeof (zio_link_t), 0, NULL, NULL, NULL, NULL, NULL, 0); + +#ifndef __NetBSD__ if (!zio_use_uma) goto out; @@ -214,6 +220,7 @@ zio_data_buf_cache[c - 1] = zio_data_buf_cache[c]; } out: +#endif /* __NetBSD__ */ zio_inject_init(); @@ -235,6 +242,7 @@ kmem_cache_t *last_cache = NULL; kmem_cache_t *last_data_cache = NULL; +#ifndef __NetBSD__ for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) { if (zio_buf_cache[c] != last_cache) { last_cache = zio_buf_cache[c]; @@ -248,6 +256,7 @@ } zio_data_buf_cache[c] = NULL; } +#endif /* __NetBSD__ */ kmem_cache_destroy(zio_link_cache); kmem_cache_destroy(zio_cache); @@ -1528,7 +1537,7 @@ * to a single taskq at a time. It would be a grievous error * to dispatch the zio to another taskq at the same time. */ -#if defined(illumos) || !defined(_KERNEL) +#if defined(illumos) || defined(__NetBSD__) || !defined(_KERNEL) ASSERT(zio->io_tqent.tqent_next == NULL); #else ASSERT(zio->io_tqent.tqent_task.ta_pending == 0); @@ -1578,7 +1587,8 @@ * functionality has been disabled for userspace builds. */ -#ifdef _KERNEL +#ifndef __NetBSD__ + /* XXXNETBSD implement timeout_generic() with a callout_t in zio_t */ /* * If io_target_timestamp is zero, then no delay has been registered * for this IO, thus jump to the end of this function and "skip" the @@ -3832,7 +3842,7 @@ * Reexecution is potentially a huge amount of work. * Hand it off to the otherwise-unused claim taskq. */ -#if defined(illumos) || !defined(_KERNEL) +#if defined(illumos) || defined(__NetBSD__) || !defined(_KERNEL) ASSERT(zio->io_tqent.tqent_next == NULL); #else ASSERT(zio->io_tqent.tqent_task.ta_pending == 0); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zio_checksum.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zio_checksum.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zio_checksum.c 2016-10-10 04:09:56.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zio_checksum.c 2017-06-27 17:04:54.000000000 -0700 @@ -123,6 +123,7 @@ NULL, NULL, ZCHECKSUM_FLAG_EMBEDDED, "zilog2"}, {{zio_checksum_off, zio_checksum_off}, NULL, NULL, 0, "noparity"}, +#ifndef __NetBSD__ {{zio_checksum_SHA512_native, zio_checksum_SHA512_byteswap}, NULL, NULL, ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_DEDUP | ZCHECKSUM_FLAG_NOPWRITE, "sha512"}, @@ -130,6 +131,7 @@ zio_checksum_skein_tmpl_init, zio_checksum_skein_tmpl_free, ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_DEDUP | ZCHECKSUM_FLAG_SALTED | ZCHECKSUM_FLAG_NOPWRITE, "skein"}, +#endif #ifdef illumos {{zio_checksum_edonr_native, zio_checksum_edonr_byteswap}, zio_checksum_edonr_tmpl_init, zio_checksum_edonr_tmpl_free, @@ -148,10 +150,12 @@ VERIFY((cksum & ~ZIO_CHECKSUM_MASK) == 0); switch (cksum) { +#ifndef __NetBSD__ case ZIO_CHECKSUM_SHA512: return (SPA_FEATURE_SHA512); case ZIO_CHECKSUM_SKEIN: return (SPA_FEATURE_SKEIN); +#endif #ifdef illumos case ZIO_CHECKSUM_EDONR: return (SPA_FEATURE_EDONR); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zvol.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zvol.c --- /tmp/out/external/cddl/osnet/dist/uts/common/fs/zfs/zvol.c 2017-03-26 23:19:46.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/fs/zfs/zvol.c 2017-06-27 17:31:17.000000000 -0700 @@ -57,8 +57,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -94,38 +94,53 @@ #include #include -#include - #include "zfs_namecheck.h" -#ifndef illumos +#ifdef __FreeBSD__ +#include +#include + struct g_class zfs_zvol_class = { .name = "ZFS::ZVOL", .version = G_VERSION, }; DECLARE_GEOM_CLASS(zfs_zvol_class, zfs_zvol); +#endif + +#ifdef __NetBSD__ +#include +#include + +#define DROP_GIANT() /* nothing */ +#define PICKUP_GIANT() /* nothing */ + +void zvol_minphys(struct buf *); +static struct dkdriver zvol_dkdriver = { zvol_strategy, zvol_minphys }; +#define bioerror(bp, er) ((bp)->b_error = (er)) +#define b_edev b_dev #endif + void *zfsdev_state; static char *zvol_tag = "zvol_tag"; #define ZVOL_DUMPSIZE "dumpsize" +#ifdef __FreeBSD__ +/* + * In FreeBSD we've replaced the upstream zfsdev_state_lock with the + * spa_namespace_lock in the ZVOL code. + */ +#define zfsdev_state_lock spa_namespace_lock +#else /* * This lock protects the zfsdev_state structure from being modified * while it's being used, e.g. an open that comes in before a create * finishes. It also protects temporary opens of the dataset so that, * e.g., an open doesn't get a spurious EBUSY. */ -#ifdef illumos kmutex_t zfsdev_state_lock; -#else -/* - * In FreeBSD we've replaced the upstream zfsdev_state_lock with the - * spa_namespace_lock in the ZVOL code. - */ -#define zfsdev_state_lock spa_namespace_lock #endif static uint32_t zvol_minors; @@ -156,16 +171,16 @@ char zv_name[MAXPATHLEN]; /* pool/dd name */ uint64_t zv_volsize; /* amount of space we advertise */ uint64_t zv_volblocksize; /* volume block size */ -#ifdef illumos - minor_t zv_minor; /* minor number */ -#else +#ifdef __FreeBSD__ struct cdev *zv_dev; /* non-GEOM device */ struct g_provider *zv_provider; /* GEOM provider */ +#else + minor_t zv_minor; /* minor number */ #endif uint8_t zv_min_bs; /* minimum addressable block shift */ uint8_t zv_flags; /* readonly, dumpified, etc. */ objset_t *zv_objset; /* objset handle */ -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) uint32_t zv_open_count[OTYPCNT]; /* open counts */ #endif uint32_t zv_total_opens; /* total open count */ @@ -174,12 +189,16 @@ list_t zv_extents; /* List of extents for dump */ znode_t zv_znode; /* for range locking */ dmu_buf_t *zv_dbuf; /* bonus handle */ -#ifndef illumos +#ifdef __FreeBSD__ int zv_state; int zv_volmode; /* Provide GEOM or cdev */ struct bio_queue_head zv_queue; struct mtx zv_queue_mtx; /* zv_queue mutex */ #endif +#ifdef __NetBSD__ + struct disk zv_dk; /* disk statistics */ + kmutex_t zv_dklock; /* disk statistics */ +#endif } zvol_state_t; #ifndef illumos @@ -209,7 +228,7 @@ */ boolean_t zvol_unmap_sync_enabled = B_FALSE; -#ifndef illumos +#ifdef __FreeBSD__ SYSCTL_INT(_vfs_zfs_vol, OID_AUTO, unmap_enabled, CTLFLAG_RWTUN, &zvol_unmap_enabled, 0, "Enable UNMAP functionality"); @@ -244,7 +263,10 @@ static void zvol_geom_worker(void *arg); static void zvol_log_truncate(zvol_state_t *zv, dmu_tx_t *tx, uint64_t off, uint64_t len, boolean_t sync); -#endif /* !illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +/* XXXNETBSD need devsw, etc */ +#endif extern int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *); @@ -269,7 +291,8 @@ /* Notify specfs to invalidate the cached size */ spec_size_invalidate(dev, VBLK); spec_size_invalidate(dev, VCHR); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ zv->zv_volsize = volsize; if (zv->zv_volmode == ZFS_VOLMODE_GEOM) { struct g_provider *pp; @@ -290,9 +313,35 @@ g_resize_provider(pp, zv->zv_volsize); g_topology_unlock(); } -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + prop_dictionary_t disk_info, odisk_info, geom; + struct disk *disk; + + disk = &zv->zv_dk; + + disk_info = prop_dictionary_create(); + geom = prop_dictionary_create(); + + prop_dictionary_set_cstring_nocopy(disk_info, "type", "ESDI"); + prop_dictionary_set_uint64(geom, "sectors-per-unit", zv->zv_volsize); + prop_dictionary_set_uint32(geom, "sector-size", + DEV_BSIZE /* XXX 512? */); + prop_dictionary_set_uint32(geom, "sectors-per-track", 32); + prop_dictionary_set_uint32(geom, "tracks-per-cylinder", 64); + prop_dictionary_set_uint32(geom, "cylinders-per-unit", zv->zv_volsize / 2048); + prop_dictionary_set(disk_info, "geometry", geom); + prop_object_release(geom); + + odisk_info = disk->dk_info; + disk->dk_info = disk_info; + + if (odisk_info != NULL) + prop_object_release(odisk_info); +#endif } + int zvol_check_volsize(uint64_t volsize, uint64_t blocksize) { @@ -354,13 +403,17 @@ ASSERT(MUTEX_HELD(&zfsdev_state_lock)); #ifdef illumos - for (minor = 1; minor <= ZFSDEV_MAX_MINOR; minor++) { + for (minor = 1; minor <= ZFSDEV_MAX_MINOR; minor++) +#else + LIST_FOREACH(zv, &all_zvols, zv_links) +#endif + { +#ifdef illumos zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); if (zv == NULL) continue; -#else - LIST_FOREACH(zv, &all_zvols, zv_links) { #endif + if (strcmp(zv->zv_name, name) == 0) return (zv); } @@ -605,20 +658,26 @@ zfs_soft_state_t *zs; zvol_state_t *zv; objset_t *os; + int error; #ifdef illumos dmu_object_info_t doi; minor_t minor = 0; char chrbuf[30], blkbuf[30]; -#else +#endif +#ifdef __FreeBSD__ struct g_provider *pp; struct g_geom *gp; uint64_t mode; -#endif - int error; -#ifndef illumos ZFS_LOG(1, "Creating ZVOL %s...", name); #endif +#ifdef __NetBSD__ + dmu_object_info_t doi; + minor_t minor = 0; + vnode_t *vp = NULL; + char *devpath; + size_t devpathlen = strlen(ZVOL_FULL_DEV_DIR) + strlen(name) + 1; +#endif mutex_enter(&zfsdev_state_lock); @@ -674,8 +733,9 @@ zs = ddi_get_soft_state(zfsdev_state, minor); zs->zss_type = ZSST_ZVOL; zv = zs->zss_data = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ zv = kmem_zalloc(sizeof(*zv), KM_SLEEP); zv->zv_state = 0; error = dsl_prop_get_integer(name, @@ -721,7 +781,92 @@ zv->zv_dev->si_iosize_max = MAXPHYS; } LIST_INSERT_HEAD(&all_zvols, zv, zv_links); -#endif /* illumos */ +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ + + /* + * If there's an existing /dev/zvol symlink, try to use the + * same minor number we used last time. + */ + devpath = kmem_alloc(devpathlen, KM_SLEEP); + + /* Get full path to ZFS volume disk device */ + (void) snprintf(devpath, devpathlen, "%s/%s", ZVOL_FULL_DEV_DIR, name); + + error = lookupname(devpath, UIO_SYSSPACE, NO_FOLLOW, NULL, &vp); + + if (error == 0 && vp->v_type != VBLK) { + error = EINVAL; + } + + if (error == 0) { + struct stat sb; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = vn_stat(vp, &sb); + VOP_UNLOCK(vp, 0); + if (error == 0) { + minor = getminor(sb.st_rdev); + } + } + + if (vp != NULL) + VN_RELE(vp); + + /* + * If we found a minor but it's already in use, we must pick a new one. + */ + + if (minor != 0 && zfsdev_get_soft_state(minor, ZSST_ZVOL) != NULL) + minor = 0; + + if (minor == 0) + minor = zfsdev_minor_alloc(); + + if (minor == 0) { + dmu_objset_disown(os, zvol_tag); + mutex_exit(&zfsdev_state_lock); + kmem_free(devpath, devpathlen); + return (ENXIO); + } + + if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS) { + dmu_objset_disown(os, zvol_tag); + mutex_exit(&zfsdev_state_lock); + kmem_free(devpath, devpathlen); + return (EAGAIN); + } + (void) ddi_prop_update_string(minor, zfs_dip, ZVOL_PROP_NAME, + (char *)name); + + if (ddi_create_minor_node(zfs_dip, (char *)name, S_IFCHR, + minor, DDI_PSEUDO, 0) == DDI_FAILURE) { + ddi_soft_state_free(zfsdev_state, minor); + dmu_objset_disown(os, zvol_tag); + mutex_exit(&zfsdev_state_lock); + kmem_free(devpath, devpathlen); + return (EAGAIN); + } + + if (ddi_create_minor_node(zfs_dip, (char *)name, S_IFBLK, + minor, DDI_PSEUDO, 0) == DDI_FAILURE) { + ddi_remove_minor_node(zfs_dip, (char *)name); + ddi_soft_state_free(zfsdev_state, minor); + dmu_objset_disown(os, zvol_tag); + mutex_exit(&zfsdev_state_lock); + kmem_free(devpath, devpathlen); + return (EAGAIN); + } + zs = ddi_get_soft_state(zfsdev_state, minor); + zs->zss_type = ZSST_ZVOL; + zv = zs->zss_data = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP); + + disk_init(&zv->zv_dk, name, &zvol_dkdriver); + disk_attach(&zv->zv_dk); + mutex_init(&zv->zv_dklock, NULL, MUTEX_DEFAULT, NULL); + + LIST_INSERT_HEAD(&all_zvols, zv, zv_links); +#endif /* __NetBSD__ */ (void) strlcpy(zv->zv_name, name, MAXPATHLEN); zv->zv_min_bs = DEV_BSHIFT; @@ -736,7 +881,7 @@ sizeof (rl_t), offsetof(rl_t, r_node)); list_create(&zv->zv_extents, sizeof (zvol_extent_t), offsetof(zvol_extent_t, ze_node)); -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) /* get and cache the blocksize */ error = dmu_object_info(os, ZVOL_OBJ, &doi); ASSERT(error == 0); @@ -755,7 +900,7 @@ zvol_minors++; mutex_exit(&zfsdev_state_lock); -#ifndef illumos +#ifdef __FreeBSD__ if (zv->zv_volmode == ZFS_VOLMODE_GEOM) { zvol_geom_run(zv); g_topology_unlock(); @@ -764,7 +909,6 @@ ZFS_LOG(1, "ZVOL %s created.", name); #endif - return (0); } @@ -774,22 +918,22 @@ static int zvol_remove_zv(zvol_state_t *zv) { -#ifdef illumos - char nmbuf[20]; - minor_t minor = zv->zv_minor; -#endif ASSERT(MUTEX_HELD(&zfsdev_state_lock)); if (zv->zv_total_opens != 0) return (SET_ERROR(EBUSY)); #ifdef illumos + char nmbuf[20]; + minor_t minor = zv->zv_minor; + (void) snprintf(nmbuf, sizeof (nmbuf), "%u,raw", minor); ddi_remove_minor_node(zfs_dip, nmbuf); (void) snprintf(nmbuf, sizeof (nmbuf), "%u", minor); ddi_remove_minor_node(zfs_dip, nmbuf); -#else +#endif +#ifdef __FreeBSD__ ZFS_LOG(1, "ZVOL %s destroyed.", zv->zv_name); LIST_REMOVE(zv, zv_links); @@ -802,6 +946,17 @@ destroy_dev(zv->zv_dev); } #endif +#ifdef __NetBSD__ + char nmbuf[20]; + minor_t minor = zv->zv_minor; + + /* XXXNETBSD needs changes here */ + (void) snprintf(nmbuf, sizeof (nmbuf), "%u,raw", zv->zv_minor); + ddi_remove_minor_node(zfs_dip, nmbuf); + + (void) snprintf(nmbuf, sizeof (nmbuf), "%u", zv->zv_minor); + ddi_remove_minor_node(zfs_dip, nmbuf); +#endif avl_destroy(&zv->zv_znode.z_range_avl); mutex_destroy(&zv->zv_znode.z_range_lock); @@ -810,6 +965,9 @@ #ifdef illumos ddi_soft_state_free(zfsdev_state, minor); #endif +#ifdef __NetBSD__ + ddi_soft_state_free(zfsdev_state, minor); +#endif zvol_minors--; return (0); } @@ -900,6 +1058,12 @@ dmu_objset_disown(zv->zv_objset, zvol_tag); zv->zv_objset = NULL; +#ifdef __NetBSD__xxx + /* the old code has this here, but it's in the wrong place. */ + disk_detach(&zv->zv_dk); + disk_destroy(&zv->zv_dk); + mutex_destroy(&zv->zv_dklock); +#endif } #ifdef illumos @@ -1128,15 +1292,20 @@ #ifdef illumos int zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr) -#else +#endif +#ifdef __FreeBSD__ static int zvol_open(struct g_provider *pp, int flag, int count) #endif +#ifdef __NetBSD__ +int +zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr) +#endif { zvol_state_t *zv; int err = 0; -#ifdef illumos +#ifdef illumos mutex_enter(&zfsdev_state_lock); zv = zfsdev_get_soft_state(getminor(*devp), ZSST_ZVOL); @@ -1151,7 +1320,8 @@ mutex_exit(&zfsdev_state_lock); return (err); } -#else /* !illumos */ +#endif /* !illumos */ +#ifdef __FreeBSD__ boolean_t locked = B_FALSE; if (!zpool_on_zvol && tsd_get(zfs_geom_probe_vdev_key) != NULL) { @@ -1199,7 +1369,24 @@ pp->stripeoffset = 0; pp->stripesize = zv->zv_volblocksize; } -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + mutex_enter(&zfsdev_state_lock); + + zv = zfsdev_get_soft_state(getminor(*devp), ZSST_ZVOL); + if (zv == NULL) { + mutex_exit(&zfsdev_state_lock); + return (SET_ERROR(ENXIO)); + } + + if (zv->zv_total_opens == 0) + err = zvol_first_open(zv); + if (err) { + mutex_exit(&zfsdev_state_lock); + return (err); + } +#endif + if ((flag & FWRITE) && (zv->zv_flags & ZVOL_RDONLY)) { err = SET_ERROR(EROFS); goto out; @@ -1224,30 +1411,43 @@ zv->zv_total_opens++; } mutex_exit(&zfsdev_state_lock); -#else +#endif +#ifdef __FreeBSD__ zv->zv_total_opens += count; if (locked) mutex_exit(&zfsdev_state_lock); #endif +#ifdef __NetBSD__ + if (zv->zv_open_count[otyp] == 0 || otyp == OTYP_LYR) { + zv->zv_open_count[otyp]++; + zv->zv_total_opens++; + } + mutex_exit(&zfsdev_state_lock); +#endif return (err); out: if (zv->zv_total_opens == 0) zvol_last_close(zv); -#ifdef illumos - mutex_exit(&zfsdev_state_lock); -#else +#ifdef __FreeBSD__ if (locked) - mutex_exit(&zfsdev_state_lock); #endif + mutex_exit(&zfsdev_state_lock); + return (err); } /*ARGSUSED*/ -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) int zvol_close(dev_t dev, int flag, int otyp, cred_t *cr) +#endif +#ifdef __FreeBSD__ +static int +zvol_close(struct g_provider *pp, int flag, int count) +#endif { +#if defined(illumos) || defined(__NetBSD__) minor_t minor = getminor(dev); zvol_state_t *zv; int error = 0; @@ -1257,10 +1457,10 @@ zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); if (zv == NULL) { mutex_exit(&zfsdev_state_lock); -#else /* !illumos */ -static int -zvol_close(struct g_provider *pp, int flag, int count) -{ + return (SET_ERROR(ENXIO)); + } +#endif /* illumos */ +#ifdef __FreeBSD__ zvol_state_t *zv; int error = 0; boolean_t locked = B_FALSE; @@ -1275,9 +1475,9 @@ if (zv == NULL) { if (locked) mutex_exit(&zfsdev_state_lock); -#endif /* illumos */ return (SET_ERROR(ENXIO)); } +#endif /* __FreeBSD__ */ if (zv->zv_flags & ZVOL_EXCL) { ASSERT(zv->zv_total_opens == 1); @@ -1288,7 +1488,7 @@ * If the open count is zero, this is a spurious close. * That indicates a bug in the kernel / DDI framework. */ -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) ASSERT(zv->zv_open_count[otyp] != 0); #endif ASSERT(zv->zv_total_opens != 0); @@ -1296,7 +1496,7 @@ /* * You may get multiple opens, but only one close. */ -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) zv->zv_open_count[otyp]--; zv->zv_total_opens--; #else @@ -1306,7 +1506,7 @@ if (zv->zv_total_opens == 0) zvol_last_close(zv); -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) mutex_exit(&zfsdev_state_lock); #else if (locked) @@ -1560,16 +1760,28 @@ return (error); } +#else /* !illumos */ +static inline int +zvol_dumpio(zvol_state_t *zv, void *addr, uint64_t offset, uint64_t size, + boolean_t doread, boolean_t isdump) +{ + return 0; +} +#endif /* illumos */ +#ifdef illumos int zvol_strategy(buf_t *bp) -{ - zfs_soft_state_t *zs = NULL; -#else /* !illumos */ +#endif +#ifdef __FreeBSD__ void zvol_strategy(struct bio *bp) +#endif +#ifdef __NetBSD__ +void +zvol_strategy(buf_t *bp) +#endif { -#endif /* illumos */ zvol_state_t *zv; uint64_t off, volsize; size_t resid; @@ -1586,6 +1798,8 @@ boolean_t sync; #ifdef illumos + zfs_soft_state_t *zs = NULL; + if (getminor(bp->b_edev) == 0) { error = SET_ERROR(EINVAL); } else { @@ -1611,7 +1825,8 @@ } off = ldbtob(bp->b_blkno); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ if (bp->bio_to) zv = bp->bio_to->private; else @@ -1641,7 +1856,36 @@ } off = bp->bio_offset; -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + zfs_soft_state_t *zs = NULL; + + if (getminor(bp->b_edev) == 0) { + error = SET_ERROR(EINVAL); + } else { + zs = ddi_get_soft_state(zfsdev_state, getminor(bp->b_edev)); + if (zs == NULL) + error = SET_ERROR(ENXIO); + else if (zs->zss_type != ZSST_ZVOL) + error = SET_ERROR(EINVAL); + } + + if (error) { + bioerror(bp, error); + biodone(bp); + return; + } + + zv = zs->zss_data; + + if (!(bp->b_flags & B_READ) && (zv->zv_flags & ZVOL_RDONLY)) { + bioerror(bp, EROFS); + biodone(bp); + return; + } + off = (uint64_t)bp->b_blkno * DEV_BSIZE; +#endif + volsize = zv->zv_volsize; os = zv->zv_objset; @@ -1663,7 +1907,8 @@ !(zv->zv_flags & ZVOL_WCE)) || (zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS)) && !doread && !is_dumpified; -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ addr = bp->bio_data; resid = bp->bio_length; @@ -1675,7 +1920,27 @@ is_dumpified = B_FALSE; sync = !doread && !is_dumpified && zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS; -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + addr = bp->b_data; + resid = bp->b_bcount; + + if (resid > 0 && off >= volsize) { + bioerror(bp, EIO); + biodone(bp); + return; + } + + is_dumpified = B_FALSE; + sync = ((!(bp->b_flags & B_ASYNC) && + !(zv->zv_flags & ZVOL_WCE)) || + (zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS)) && + !doread && !is_dumpified; + + mutex_enter(&zv->zv_dklock); + disk_busy(&zv->zv_dk); + mutex_exit(&zv->zv_dklock); +#endif /* * There must be no buffer changes when doing a dmu_sync() because @@ -1684,7 +1949,7 @@ rl = zfs_range_lock(&zv->zv_znode, off, resid, doread ? RL_READER : RL_WRITER); -#ifndef illumos +#ifdef __FreeBSD__ if (bp->bio_cmd == BIO_DELETE) { dmu_tx_t *tx = dmu_tx_create(zv->zv_objset); error = dmu_tx_assign(tx, TXG_WAIT); @@ -1702,15 +1967,11 @@ #endif while (resid != 0 && off < volsize) { size_t size = MIN(resid, zvol_maxphys); -#ifdef illumos if (is_dumpified) { size = MIN(size, P2END(off, zv->zv_volblocksize) - off); error = zvol_dumpio(zv, addr, off, size, doread, B_FALSE); } else if (doread) { -#else - if (doread) { -#endif error = dmu_read(os, ZVOL_OBJ, off, size, addr, DMU_READ_PREFETCH); } else { @@ -1735,7 +1996,7 @@ addr += size; resid -= size; } -#ifndef illumos +#ifdef __FreeBSD__ unlock: #endif zfs_range_unlock(rl); @@ -1749,7 +2010,8 @@ biodone(bp); return (0); -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ bp->bio_completed = bp->bio_length - resid; if (bp->bio_completed < bp->bio_length && off > volsize) error = EINVAL; @@ -1763,10 +2025,21 @@ g_io_deliver(bp, error); else biofinish(bp, NULL, error); -#endif /* illumos */ +#endif /* __FreeBSD__ */ +#ifdef __NetBSD__ + if ((bp->b_resid = resid) == bp->b_bcount) + bioerror(bp, off > volsize ? EINVAL : error); + + if (sync) + zil_commit(zv->zv_zilog, ZVOL_OBJ); + mutex_enter(&zv->zv_dklock); + disk_unbusy(&zv->zv_dk, bp->b_bcount - bp->b_resid, doread); + mutex_exit(&zv->zv_dklock); + biodone(bp); +#endif /* __NetBSD__ */ } -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) /* * Set the buffer count to the zvol maximum transfer. * Using our own routine instead of the default minphys() @@ -1781,7 +2054,9 @@ if (bp->b_bcount > zvol_maxphys) bp->b_bcount = zvol_maxphys; } +#endif +#ifdef illumos int zvol_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblocks) { @@ -1816,23 +2091,26 @@ return (error); } +#endif /*ARGSUSED*/ +#if defined(illumos) || defined(__NetBSD__) int zvol_read(dev_t dev, uio_t *uio, cred_t *cr) -{ - minor_t minor = getminor(dev); -#else /* !illumos */ +#endif +#ifdef __FreeBSD__ int zvol_read(struct cdev *dev, struct uio *uio, int ioflag) +#endif { -#endif /* illumos */ zvol_state_t *zv; uint64_t volsize; rl_t *rl; int error = 0; -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) + minor_t minor = getminor(dev); + zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); if (zv == NULL) return (SET_ERROR(ENXIO)); @@ -1875,24 +2153,24 @@ return (error); } -#ifdef illumos /*ARGSUSED*/ +#if defined(illumos) || defined(__NetBSD__) int zvol_write(dev_t dev, uio_t *uio, cred_t *cr) -{ - minor_t minor = getminor(dev); -#else /* !illumos */ +#else int zvol_write(struct cdev *dev, struct uio *uio, int ioflag) +#endif { -#endif /* illumos */ zvol_state_t *zv; uint64_t volsize; rl_t *rl; int error = 0; boolean_t sync; -#ifdef illumos +#if defined(illumos) || defined(__NetBSD__) + minor_t minor = getminor(dev); + zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); if (zv == NULL) return (SET_ERROR(ENXIO)); @@ -1914,9 +2192,13 @@ } sync = !(zv->zv_flags & ZVOL_WCE) || -#else +#endif +#ifdef __FreeBSD__ sync = (ioflag & IO_SYNC) || #endif +#ifdef __NetBSD__ + sync = 1 || +#endif (zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS); rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid, @@ -2327,17 +2609,16 @@ { VERIFY(ddi_soft_state_init(&zfsdev_state, sizeof (zfs_soft_state_t), 1) == 0); -#ifdef illumos +#ifndef __FreeBSD__ mutex_init(&zfsdev_state_lock, NULL, MUTEX_DEFAULT, NULL); -#else - ZFS_LOG(1, "ZVOL Initialized."); #endif + ZFS_LOG(1, "ZVOL Initialized."); } void zvol_fini(void) { -#ifdef illumos +#ifndef __FreeBSD__ mutex_destroy(&zfsdev_state_lock); #endif ddi_soft_state_fini(&zfsdev_state); @@ -2648,8 +2929,9 @@ return (0); } -#else /* !illumos */ +#endif /* illumos */ +#ifdef __FreeBSD__ static void zvol_geom_run(zvol_state_t *zv) { @@ -3240,4 +3522,66 @@ return (error); } -#endif /* illumos */ +#endif /* __FreeBSD__ */ + +#ifdef __NetBSD__ +/*ARGSUSED*/ +int +zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) +{ + zvol_state_t *zv; + int error = 0; + + mutex_enter(&zfsdev_state_lock); + + zv = zfsdev_get_soft_state(getminor(dev), ZSST_ZVOL); + + if (zv == NULL) { + mutex_exit(&zfsdev_state_lock); + return (ENXIO); + } + + switch(cmd) { + case DIOCGWEDGEINFO: + { + struct dkwedge_info *dkw = (void *) arg; + + strlcpy(dkw->dkw_devname, zv->zv_name, 16); + strlcpy(dkw->dkw_wname, zv->zv_name, MAXPATHLEN); + strlcpy(dkw->dkw_parent, zv->zv_name, 16); + + dkw->dkw_offset = 0; + /* XXX NetBSD supports only DEV_BSIZE device block + size zv_volblocksize >> DEV_BSIZE*/ + dkw->dkw_size = (zv->zv_volsize / DEV_BSIZE); + dprintf("dkw %"PRIu64" volsize %"PRIu64" volblock %"PRIu64" \n", + dkw->dkw_size, zv->zv_volsize, zv->zv_volblocksize); + strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS); + + break; + } + + case DIOCGDISKINFO: + { + struct plistref *pref = (struct plistref *) arg; + + if (zv->zv_dk.dk_info == NULL) { + mutex_exit(&zfsdev_state_lock); + return ENOTSUP; + } else + prop_dictionary_copyout_ioctl(pref, cmd, + zv->zv_dk.dk_info); + + break; + } + + default: + aprint_debug("unknown disk_ioctl called\n"); + error = ENOTTY; + break; + } + + mutex_exit(&zfsdev_state_lock); + return (error); +} +#endif /* __NetBSD__ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc: types.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc: xdr.c diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/rpc/xdr.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc/xdr.h --- /tmp/out/external/cddl/osnet/dist/uts/common/rpc/xdr.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc/xdr.h 2017-12-05 17:36:17.000000000 -0800 @@ -1,70 +1,648 @@ /* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ +/* + * Portions of this source code were derived from Berkeley + * 4.3 BSD under license from the Regents of the University of + * California. */ -#ifndef _OPENSOLARIS_RPC_XDR_H_ -#define _OPENSOLARIS_RPC_XDR_H_ +/* + * xdr.h, External Data Representation Serialization Routines. + * + */ -#include_next +#ifndef _RPC_XDR_H +#define _RPC_XDR_H +#include /* For all ntoh* and hton*() kind of macros */ +#include /* For all ntoh* and hton*() kind of macros */ #ifndef _KERNEL +#include /* defines FILE *, used in ANSI C function prototypes */ +#endif + +#ifdef __NetBSD__ /* Avoid conflicts with libc xdr. */ +/* xdr.c */ +#define xdr_bool _solaris_xdr_bool +#define xdr_bytes _solaris_xdr_bytes +#define xdr_char _solaris_xdr_char +#define xdr_enum _solaris_xdr_enum +#define xdr_free _solaris_xdr_free +#define xdr_int _solaris_xdr_int +#define xdr_int32_t _solaris_xdr_int32_t +#define xdr_int64_t _solaris_xdr_int64_t +#define xdr_longlong_t _solaris_xdr_longlong_t +#define xdr_netobj _solaris_xdr_netobj +#define xdr_opaque _solaris_xdr_opaque +#define xdr_short _solaris_xdr_short +#define xdr_string _solaris_xdr_string +#define xdr_u_char _solaris_xdr_u_char +#define xdr_u_int _solaris_xdr_u_int +#define xdr_u_longlong_t _solaris_xdr_u_longlong_t +#define xdr_u_short _solaris_xdr_u_short +#define xdr_uint32_t _solaris_xdr_uint32_t +#define xdr_uint64_t _solaris_xdr_uint64_t +#define xdr_union _solaris_xdr_union +#define xdr_vector _solaris_xdr_vector +#define xdr_void _solaris_xdr_void +#define xdr_wrapstring _solaris_xdr_wrapstring + +/* xdr_array.c */ +#define xdr_array _solaris_xdr_array + +/* xdr_mem.c */ +#define xdrmem_create _solaris_xdrmem_create + +typedef void *mblk_t; + +#else /* !__NetBSD__ */ -#include +#ifdef _KERNEL +#include +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* - * Taken from sys/xdr/xdr_mem.c. + * XDR provides a conventional way for converting between C data + * types and an external bit-string representation. Library supplied + * routines provide for the conversion on built-in C data types. These + * routines and utility routines defined here are used to help implement + * a type encode/decode routine for each user-defined type. + * + * Each data type provides a single procedure which takes two arguments: + * + * bool_t + * xdrproc(xdrs, argresp) + * XDR *xdrs; + * *argresp; + * + * xdrs is an instance of a XDR handle, to which or from which the data + * type is to be converted. argresp is a pointer to the structure to be + * converted. The XDR handle contains an operation field which indicates + * which of the operations (ENCODE, DECODE * or FREE) is to be performed. * - * FreeBSD's userland XDR doesn't implement control method (only the kernel), - * but OpenSolaris nvpair still depend on it, so we have to implement it here. + * XDR_DECODE may allocate space if the pointer argresp is null. This + * data can be freed with the XDR_FREE operation. + * + * We write only one procedure per data type to make it easy + * to keep the encode and decode procedures for a data type consistent. + * In many cases the same code performs all operations on a user defined type, + * because all the hard work is done in the component type routines. + * decode as a series of calls on the nested data types. */ -static __inline bool_t -xdrmem_control(XDR *xdrs, int request, void *info) -{ - xdr_bytesrec *xptr; - - switch (request) { - case XDR_GET_BYTES_AVAIL: - xptr = (xdr_bytesrec *)info; - xptr->xc_is_last_record = TRUE; - xptr->xc_num_avail = xdrs->x_handy; - return (TRUE); - default: - assert(!"unexpected request"); - } - return (FALSE); -} -#undef XDR_CONTROL -#define XDR_CONTROL(xdrs, req, op) \ - (((xdrs)->x_ops->x_control == NULL) ? \ - xdrmem_control((xdrs), (req), (op)) : \ - (*(xdrs)->x_ops->x_control)(xdrs, req, op)) +/* + * Xdr operations. XDR_ENCODE causes the type to be encoded into the + * stream. XDR_DECODE causes the type to be extracted from the stream. + * XDR_FREE can be used to release the space allocated by an XDR_DECODE + * request. + */ +enum xdr_op { + XDR_ENCODE = 0, + XDR_DECODE = 1, + XDR_FREE = 2 +}; + +/* + * This is the number of bytes per unit of external data. + */ +#define BYTES_PER_XDR_UNIT (4) +#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ + * BYTES_PER_XDR_UNIT) + +/* + * The XDR handle. + * Contains operation which is being applied to the stream, + * an operations vector for the paticular implementation (e.g. see xdr_mem.c), + * and two private fields for the use of the particular impelementation. + * + * PSARC 2003/523 Contract Private Interface + * XDR + * Changes must be reviewed by Solaris File Sharing + * Changes must be communicated to contract-2003-523@sun.com + */ +typedef struct XDR { + enum xdr_op x_op; /* operation; fast additional param */ + struct xdr_ops *x_ops; + caddr_t x_public; /* users' data */ + caddr_t x_private; /* pointer to private data */ + caddr_t x_base; /* private used for position info */ + int x_handy; /* extra private word */ +} XDR; + +/* + * PSARC 2003/523 Contract Private Interface + * xdr_ops + * Changes must be reviewed by Solaris File Sharing + * Changes must be communicated to contract-2003-523@sun.com + * + * XXX We are not Solaris, we are NetBSD. So no need for silly ABI + * compatibility with Solaris ILP32 gunk. + */ +struct xdr_ops { +#ifdef __STDC__ +#if !defined(_KERNEL) && !defined(__NetBSD__) + bool_t (*x_getlong)(struct XDR *, long *); + /* get a long from underlying stream */ + bool_t (*x_putlong)(struct XDR *, long *); + /* put a long to " */ +#endif /* KERNEL */ + bool_t (*x_getbytes)(struct XDR *, caddr_t, int); + /* get some bytes from " */ + bool_t (*x_putbytes)(struct XDR *, caddr_t, int); + /* put some bytes to " */ + uint_t (*x_getpostn)(struct XDR *); + /* returns bytes off from beginning */ + bool_t (*x_setpostn)(struct XDR *, uint_t); + /* lets you reposition the stream */ + rpc_inline_t *(*x_inline)(struct XDR *, int); + /* buf quick ptr to buffered data */ + void (*x_destroy)(struct XDR *); + /* free privates of this xdr_stream */ + bool_t (*x_control)(struct XDR *, int, void *); +#if defined(_LP64) || defined(_KERNEL) || defined(__NetBSD__) + bool_t (*x_getint32)(struct XDR *, int32_t *); + /* get a int from underlying stream */ + bool_t (*x_putint32)(struct XDR *, int32_t *); + /* put an int to " */ +#endif /* _LP64 || _KERNEL */ +#else +#if !defined(_KERNEL) && !defined(__NetBSD__) + bool_t (*x_getlong)(); /* get a long from underlying stream */ + bool_t (*x_putlong)(); /* put a long to " */ +#endif /* KERNEL */ + bool_t (*x_getbytes)(); /* get some bytes from " */ + bool_t (*x_putbytes)(); /* put some bytes to " */ + uint_t (*x_getpostn)(); /* returns bytes off from beginning */ + bool_t (*x_setpostn)(); /* lets you reposition the stream */ + rpc_inline_t *(*x_inline)(); + /* buf quick ptr to buffered data */ + void (*x_destroy)(); /* free privates of this xdr_stream */ + bool_t (*x_control)(); +#if defined(_LP64) || defined(_KERNEL) || defined(__NetBSD__) + bool_t (*x_getint32)(); + bool_t (*x_putint32)(); +#endif /* _LP64 || defined(_KERNEL) */ +#endif +}; + +/* + * Operations defined on a XDR handle + * + * XDR *xdrs; + * long *longp; + * caddr_t addr; + * uint_t len; + * uint_t pos; + */ +#if !defined(_KERNEL) && !defined(__NetBSD__) +#define XDR_GETLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) +#define xdr_getlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) + +#define XDR_PUTLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +#define xdr_putlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +#endif /* KERNEL */ + + +#if !defined(_LP64) && !defined(_KERNEL) && !defined(__NetBSD__) + +/* + * For binary compatability on ILP32 we do not change the shape + * of the XDR structure and the GET/PUTINT32 functions just use + * the get/putlong vectors which operate on identically-sized + * units of data. + */ + +#define XDR_GETINT32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p) +#define xdr_getint32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p) + +#define XDR_PUTINT32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p) +#define xdr_putint32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p) + +#else /* !_LP64 && !_KERNEL */ + +#define XDR_GETINT32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) +#define xdr_getint32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) + +#define XDR_PUTINT32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) +#define xdr_putint32(xdrs, int32p) \ + (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) + +#endif /* !_LP64 && !_KERNEL */ + +#define XDR_GETBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) +#define xdr_getbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) + +#define XDR_PUTBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) +#define xdr_putbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) + +#define XDR_GETPOS(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) +#define xdr_getpos(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) + +#define XDR_SETPOS(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) +#define xdr_setpos(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) + +#define XDR_INLINE(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) +#define xdr_inline(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) + +#define XDR_DESTROY(xdrs) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) +#define xdr_destroy(xdrs) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) + +#define XDR_CONTROL(xdrs, req, op) \ + (*(xdrs)->x_ops->x_control)(xdrs, req, op) +#define xdr_control(xdrs, req, op) \ + (*(xdrs)->x_ops->x_control)(xdrs, req, op) + +/* + * Support struct for discriminated unions. + * You create an array of xdrdiscrim structures, terminated with + * a entry with a null procedure pointer. The xdr_union routine gets + * the discriminant value and then searches the array of structures + * for a matching value. If a match is found the associated xdr routine + * is called to handle that part of the union. If there is + * no match, then a default routine may be called. + * If there is no match and no default routine it is an error. + */ + + +/* + * A xdrproc_t exists for each data type which is to be encoded or decoded. + * + * The second argument to the xdrproc_t is a pointer to an opaque pointer. + * The opaque pointer generally points to a structure of the data type + * to be decoded. If this pointer is 0, then the type routines should + * allocate dynamic storage of the appropriate size and return it. + * bool_t (*xdrproc_t)(XDR *, void *); + */ +#ifdef __cplusplus +typedef bool_t (*xdrproc_t)(XDR *, void *); +#else +#ifdef __STDC__ +typedef bool_t (*xdrproc_t)(); /* For Backward compatibility */ +#else +typedef bool_t (*xdrproc_t)(); +#endif +#endif + +#define NULL_xdrproc_t ((xdrproc_t)0) + +#if defined(_LP64) || defined(_I32LPx) +#define xdr_rpcvers(xdrs, versp) xdr_u_int(xdrs, versp) +#define xdr_rpcprog(xdrs, progp) xdr_u_int(xdrs, progp) +#define xdr_rpcproc(xdrs, procp) xdr_u_int(xdrs, procp) +#define xdr_rpcprot(xdrs, protp) xdr_u_int(xdrs, protp) +#define xdr_rpcport(xdrs, portp) xdr_u_int(xdrs, portp) +#else +#define xdr_rpcvers(xdrs, versp) xdr_u_long(xdrs, versp) +#define xdr_rpcprog(xdrs, progp) xdr_u_long(xdrs, progp) +#define xdr_rpcproc(xdrs, procp) xdr_u_long(xdrs, procp) +#define xdr_rpcprot(xdrs, protp) xdr_u_long(xdrs, protp) +#define xdr_rpcport(xdrs, portp) xdr_u_long(xdrs, portp) +#endif + +struct xdr_discrim { + int value; + xdrproc_t proc; +}; + +/* + * In-line routines for fast encode/decode of primitve data types. + * Caveat emptor: these use single memory cycles to get the + * data from the underlying buffer, and will fail to operate + * properly if the data is not aligned. The standard way to use these + * is to say: + * if ((buf = XDR_INLINE(xdrs, count)) == NULL) + * return (FALSE); + * <<< macro calls >>> + * where ``count'' is the number of bytes of data occupied + * by the primitive data types. + * + * N.B. and frozen for all time: each data type here uses 4 bytes + * of external representation. + */ + +#define IXDR_GET_INT32(buf) ((int32_t)ntohl((uint32_t)*(buf)++)) +#define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((uint32_t)v)) +#define IXDR_GET_U_INT32(buf) ((uint32_t)IXDR_GET_INT32(buf)) +#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) + +#if !defined(_KERNEL) && !defined(_LP64) && !defined(__NetBSD__) + +#define IXDR_GET_LONG(buf) ((long)ntohl((ulong_t)*(buf)++)) +#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((ulong_t)v)) +#define IXDR_GET_U_LONG(buf) ((ulong_t)IXDR_GET_LONG(buf)) +#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) + +#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) +#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) +#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) +#define IXDR_GET_U_SHORT(buf) ((ushort_t)IXDR_GET_LONG(buf)) + +#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) + +#else + +#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_INT32(buf)) +#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_INT32(buf)) +#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_INT32(buf)) +#define IXDR_GET_U_SHORT(buf) ((ushort_t)IXDR_GET_INT32(buf)) + +#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_INT32((buf), ((int)(v))) +#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_INT32((buf), ((int)(v))) +#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_INT32((buf), ((int)(v))) +#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_INT32((buf), ((int)(v))) + +#endif + +#ifndef _LITTLE_ENDIAN +#define IXDR_GET_HYPER(buf, v) { \ + *((int32_t *)(&v)) = ntohl(*(uint32_t *)buf++); \ + *((int32_t *)(((char *)&v) + BYTES_PER_XDR_UNIT)) \ + = ntohl(*(uint32_t *)buf++); \ + } +#define IXDR_PUT_HYPER(buf, v) { \ + *(buf)++ = (int32_t)htonl(*(uint32_t *) \ + ((char *)&v)); \ + *(buf)++ = \ + (int32_t)htonl(*(uint32_t *)(((char *)&v) \ + + BYTES_PER_XDR_UNIT)); \ + } +#else + +#define IXDR_GET_HYPER(buf, v) { \ + *((int32_t *)(((char *)&v) + \ + BYTES_PER_XDR_UNIT)) \ + = ntohl(*(uint32_t *)buf++); \ + *((int32_t *)(&v)) = \ + ntohl(*(uint32_t *)buf++); \ + } + +#define IXDR_PUT_HYPER(buf, v) { \ + *(buf)++ = \ + (int32_t)htonl(*(uint32_t *)(((char *)&v) + \ + BYTES_PER_XDR_UNIT)); \ + *(buf)++ = \ + (int32_t)htonl(*(uint32_t *)((char *)&v)); \ + } +#endif +#define IXDR_GET_U_HYPER(buf, v) IXDR_GET_HYPER(buf, v) +#define IXDR_PUT_U_HYPER(buf, v) IXDR_PUT_HYPER(buf, v) + + +/* + * These are the "generic" xdr routines. + */ +#ifdef __STDC__ +extern bool_t xdr_void(void); +extern bool_t xdr_int(XDR *, int *); +extern bool_t xdr_u_int(XDR *, uint_t *); +extern bool_t xdr_long(XDR *, long *); +extern bool_t xdr_u_long(XDR *, ulong_t *); +extern bool_t xdr_short(XDR *, short *); +extern bool_t xdr_u_short(XDR *, ushort_t *); +extern bool_t xdr_bool(XDR *, bool_t *); +extern bool_t xdr_enum(XDR *, enum_t *); +extern bool_t xdr_array(XDR *, caddr_t *, uint_t *, const uint_t, + const uint_t, const xdrproc_t); +extern bool_t xdr_bytes(XDR *, char **, uint_t *, const uint_t); +extern bool_t xdr_opaque(XDR *, caddr_t, const uint_t); +extern bool_t xdr_string(XDR *, char **, const uint_t); +extern bool_t xdr_union(XDR *, enum_t *, char *, + const struct xdr_discrim *, const xdrproc_t); +extern bool_t xdr_vector(XDR *, char *, const uint_t, const uint_t, + const xdrproc_t); +extern unsigned int xdr_sizeof(xdrproc_t, void *); + +extern bool_t xdr_hyper(XDR *, longlong_t *); +extern bool_t xdr_longlong_t(XDR *, longlong_t *); +extern bool_t xdr_u_hyper(XDR *, u_longlong_t *); +extern bool_t xdr_u_longlong_t(XDR *, u_longlong_t *); + +extern bool_t xdr_char(XDR *, char *); +extern bool_t xdr_u_char(XDR *, uchar_t *); +extern bool_t xdr_wrapstring(XDR *, char **); +extern bool_t xdr_reference(XDR *, caddr_t *, uint_t, const xdrproc_t); +extern bool_t xdr_pointer(XDR *, char **, uint_t, const xdrproc_t); +extern void xdr_free(xdrproc_t, char *); +extern bool_t xdr_time_t(XDR *, time_t *); -#endif /* !_KERNEL */ +extern bool_t xdr_int8_t(XDR *, int8_t *); +extern bool_t xdr_uint8_t(XDR *, uint8_t *); +extern bool_t xdr_int16_t(XDR *, int16_t *); +extern bool_t xdr_uint16_t(XDR *, uint16_t *); +extern bool_t xdr_int32_t(XDR *, int32_t *); +extern bool_t xdr_uint32_t(XDR *, uint32_t *); +#if defined(_INT64_TYPE) +extern bool_t xdr_int64_t(XDR *, int64_t *); +extern bool_t xdr_uint64_t(XDR *, uint64_t *); +#endif + +#ifndef _KERNEL +extern bool_t xdr_float(XDR *, float *); +extern bool_t xdr_double(XDR *, double *); +extern bool_t xdr_quadruple(XDR *, long double *); +#endif /* !_KERNEL */ +#else +extern bool_t xdr_void(); +extern bool_t xdr_int(); +extern bool_t xdr_u_int(); +extern bool_t xdr_long(); +extern bool_t xdr_u_long(); +extern bool_t xdr_short(); +extern bool_t xdr_u_short(); +extern bool_t xdr_bool(); +extern bool_t xdr_enum(); +extern bool_t xdr_array(); +extern bool_t xdr_bytes(); +extern bool_t xdr_opaque(); +extern bool_t xdr_string(); +extern bool_t xdr_union(); +extern bool_t xdr_vector(); + +extern bool_t xdr_hyper(); +extern bool_t xdr_longlong_t(); +extern bool_t xdr_u_hyper(); +extern bool_t xdr_u_longlong_t(); +extern bool_t xdr_char(); +extern bool_t xdr_u_char(); +extern bool_t xdr_reference(); +extern bool_t xdr_pointer(); +extern void xdr_free(); +extern bool_t xdr_wrapstring(); +extern bool_t xdr_time_t(); + +extern bool_t xdr_int8_t(); +extern bool_t xdr_uint8_t(); +extern bool_t xdr_int16_t(); +extern bool_t xdr_uint16_t(); +extern bool_t xdr_int32_t(); +extern bool_t xdr_uint32_t(); +#if defined(_INT64_TYPE) +extern bool_t xdr_int64_t(); +extern bool_t xdr_uint64_t(); +#endif + +#ifndef _KERNEL +extern bool_t xdr_float(); +extern bool_t xdr_double(); +extern bool_t xdr_quadruple(); +#endif /* !_KERNEL */ +#endif + +/* + * Common opaque bytes objects used by many rpc protocols; + * declared here due to commonality. + */ +#define MAX_NETOBJ_SZ 1024 +struct netobj { + uint_t n_len; + char *n_bytes; +}; +typedef struct netobj netobj; + +#ifdef __STDC__ +extern bool_t xdr_netobj(XDR *, netobj *); +#else +extern bool_t xdr_netobj(); +#endif + +/* + * These are XDR control operators + */ + +#define XDR_GET_BYTES_AVAIL 1 + +struct xdr_bytesrec { + bool_t xc_is_last_record; + size_t xc_num_avail; +}; + +typedef struct xdr_bytesrec xdr_bytesrec; + +/* + * These are the request arguments to XDR_CONTROL. + * + * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream. + * XDR_SKIPBYTES - skips the next N bytes in the XDR stream. + * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from + * the XDR stream being moved over RDMA + * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in + * the XDR stream moving over RDMA. + */ +#define XDR_PEEK 2 +#define XDR_SKIPBYTES 3 +#define XDR_RDMA_GET_FLAGS 4 +#define XDR_RDMA_SET_FLAGS 5 +#define XDR_RDMA_ADD_CHUNK 6 +#define XDR_RDMA_GET_CHUNK_LEN 7 +#define XDR_RDMA_SET_WLIST 8 +#define XDR_RDMA_GET_WLIST 9 +#define XDR_RDMA_GET_WCINFO 10 +#define XDR_RDMA_GET_RLIST 11 + +/* + * These are the public routines for the various implementations of + * xdr streams. + */ +#ifndef _KERNEL +#ifdef __STDC__ +extern void xdrmem_create(XDR *, const caddr_t, const uint_t, const enum +xdr_op); + /* XDR using memory buffers */ +extern void xdrstdio_create(XDR *, FILE *, const enum xdr_op); +/* XDR using stdio library */ +extern void xdrrec_create(XDR *, const uint_t, const uint_t, const caddr_t, +int (*) (void *, caddr_t, int), int (*) (void *, caddr_t, int)); +/* XDR pseudo records for tcp */ +extern bool_t xdrrec_endofrecord(XDR *, bool_t); +/* make end of xdr record */ +extern bool_t xdrrec_skiprecord(XDR *); +/* move to beginning of next record */ +extern bool_t xdrrec_eof(XDR *); +extern uint_t xdrrec_readbytes(XDR *, caddr_t, uint_t); +/* true if no more input */ +#else +extern void xdrmem_create(); +extern void xdrstdio_create(); +extern void xdrrec_create(); +extern bool_t xdrrec_endofrecord(); +extern bool_t xdrrec_skiprecord(); +extern bool_t xdrrec_eof(); +extern uint_t xdrrec_readbytes(); +#endif +#else + +#define DLEN(mp) (mp->b_cont ? msgdsize(mp) : (mp->b_wptr - mp->b_rptr)) + +extern void xdrmem_create(XDR *, caddr_t, uint_t, enum xdr_op); +extern void xdrmblk_init(XDR *, mblk_t *, enum xdr_op, int); +extern bool_t xdrmblk_getmblk(XDR *, mblk_t **, uint_t *); +extern bool_t xdrmblk_putmblk(XDR *, mblk_t *, uint_t); +extern struct xdr_ops xdrmblk_ops; +extern struct xdr_ops xdrrdmablk_ops; +extern struct xdr_ops xdrrdma_ops; + +struct rpc_msg; +extern bool_t xdr_callmsg(XDR *, struct rpc_msg *); +extern bool_t xdr_replymsg_body(XDR *, struct rpc_msg *); +extern bool_t xdr_replymsg_hdr(XDR *, struct rpc_msg *); + +#endif /* !_KERNEL */ + +#ifdef __cplusplus +} +#endif -#endif /* !_OPENSOLARIS_RPC_XDR_H_ */ +#endif /* !_RPC_XDR_H */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc: xdr_array.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/rpc: xdr_mem.c diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/acl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/acl.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/acl.h 2016-07-13 18:26:26.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/acl.h 2017-04-25 06:46:24.000000000 -0700 @@ -31,16 +31,6 @@ #include #include -#if defined(_KERNEL) -/* - * When compiling OpenSolaris kernel code, this file is included instead of the - * FreeBSD one. Include the original sys/acl.h as well. - */ -#undef _SYS_ACL_H -#include_next -#define _SYS_ACL_H -#endif /* _KERNEL */ - #ifdef __cplusplus extern "C" { #endif Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: byteorder.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/ccompile.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/ccompile.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/ccompile.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/ccompile.h 2017-04-20 07:16:09.000000000 -0700 @@ -27,8 +27,6 @@ #ifndef _SYS_CCOMPILE_H #define _SYS_CCOMPILE_H -#pragma ident "%Z%%M% %I% %E% SMI" - /* * This file contains definitions designed to enable different compilers * to be used harmoniously on Solaris systems. Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: crc32.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/debug.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/debug.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/debug.h 2015-11-22 09:22:33.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/debug.h 2017-04-20 10:00:43.000000000 -0700 @@ -129,7 +129,11 @@ */ #ifndef CTASSERT #define CTASSERT(x) _CTASSERT(x, __LINE__) +#endif +#ifndef _CTASSERT #define _CTASSERT(x, y) __CTASSERT(x, y) +#endif +#ifndef __CTASSERT #define __CTASSERT(x, y) \ typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1] #endif Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: dklabel.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/dtrace.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/dtrace.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/dtrace.h 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/dtrace.h 2017-05-09 08:20:41.000000000 -0700 @@ -1419,7 +1419,7 @@ char dofhp_mod[DTRACE_MODNAMELEN]; /* executable or library name */ uint64_t dofhp_addr; /* base address of object */ uint64_t dofhp_dof; /* address of helper DOF */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) pid_t dofhp_pid; /* target process ID */ int dofhp_gen; #endif @@ -2123,7 +2123,7 @@ typedef struct dtrace_pops { void (*dtps_provide)(void *arg, dtrace_probedesc_t *spec); void (*dtps_provide_module)(void *arg, modctl_t *mp); - void (*dtps_enable)(void *arg, dtrace_id_t id, void *parg); + int (*dtps_enable)(void *arg, dtrace_id_t id, void *parg); void (*dtps_disable)(void *arg, dtrace_id_t id, void *parg); void (*dtps_suspend)(void *arg, dtrace_id_t id, void *parg); void (*dtps_resume)(void *arg, dtrace_id_t id, void *parg); @@ -2409,13 +2409,13 @@ #endif #define DTRACE_CPUFLAG_ISSET(flag) \ - (cpu_core[curcpu].cpuc_dtrace_flags & (flag)) + (cpu_core[cpu_number()].cpuc_dtrace_flags & (flag)) #define DTRACE_CPUFLAG_SET(flag) \ - (cpu_core[curcpu].cpuc_dtrace_flags |= (flag)) + (cpu_core[cpu_number()].cpuc_dtrace_flags |= (flag)) #define DTRACE_CPUFLAG_CLEAR(flag) \ - (cpu_core[curcpu].cpuc_dtrace_flags &= ~(flag)) + (cpu_core[cpu_number()].cpuc_dtrace_flags &= ~(flag)) #endif /* _KERNEL */ @@ -2450,6 +2450,15 @@ #define DTRACE_INVOP_POPM 2 #define DTRACE_INVOP_B 3 +#define DTRACE_INVOP_MOV_IP_SP 4 +#define DTRACE_INVOP_BX_LR 5 +#define DTRACE_INVOP_MOV_PC_LR 6 +#define DTRACE_INVOP_LDM 7 +#define DTRACE_INVOP_LDR_IMM 8 +#define DTRACE_INVOP_MOVW 9 +#define DTRACE_INVOP_MOV_IMM 10 +#define DTRACE_INVOP_CMP_IMM 11 + #elif defined(__aarch64__) #define INSN_SIZE 4 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/dtrace_impl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/dtrace_impl.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/dtrace_impl.h 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/dtrace_impl.h 2017-05-16 14:08:58.000000000 -0700 @@ -69,6 +69,9 @@ #ifdef __FreeBSD__ #define NCPU MAXCPU #endif /* __FreeBSD__ */ +#ifdef __NetBSD__ +#define NCPU MAXCPUS +#endif /* __NetBSD__ */ struct dtrace_probe; struct dtrace_ecb; @@ -1128,10 +1131,10 @@ * dtrace_state structure. */ struct dtrace_state { -#ifdef illumos - dev_t dts_dev; /* device */ -#else +#ifdef __FreeBSD__ struct cdev *dts_dev; /* device */ +#else + dev_t dts_dev; /* device */ #endif int dts_necbs; /* total number of ECBs */ dtrace_ecb_t **dts_ecbs; /* array of ECBs */ @@ -1146,10 +1149,10 @@ int dts_nspeculations; /* number of speculations */ int dts_naggregations; /* number of aggregations */ dtrace_aggregation_t **dts_aggregations; /* aggregation array */ -#ifdef illumos - vmem_t *dts_aggid_arena; /* arena for aggregation IDs */ -#else +#ifdef __FreeBSD__ struct unrhdr *dts_aggid_arena; /* arena for aggregation IDs */ +#else + vmem_t *dts_aggid_arena; /* arena for aggregation IDs */ #endif uint64_t dts_errors; /* total number of errors */ uint32_t dts_speculations_busy; /* number of spec. busy */ @@ -1161,10 +1164,15 @@ #ifdef illumos cyclic_id_t dts_cleaner; /* cleaning cyclic */ cyclic_id_t dts_deadman; /* deadman cyclic */ -#else +#endif +#ifdef __FreeBSD__ struct callout dts_cleaner; /* Cleaning callout. */ struct callout dts_deadman; /* Deadman callout. */ #endif +#ifdef __NetBSD__ + struct dtrace_state_worker *dts_cleaner;/* cleaning cyclic */ + struct dtrace_state_worker *dts_deadman;/* deadman cyclic */ +#endif hrtime_t dts_alive; /* time last alive */ char dts_speculates; /* boolean: has speculations */ char dts_destructive; /* boolean: has dest. actions */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: efi_partition.h Only in /tmp/out/external/cddl/osnet/dist/uts/common/sys: fasttrap_impl.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/fm/util.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/fm/util.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/fm/util.h 2012-06-11 22:57:28.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/fm/util.h 2017-04-25 09:09:40.000000000 -0700 @@ -85,7 +85,7 @@ extern void fm_init(void); extern void fm_nvprint(nvlist_t *); -#define fm_panic panic +extern void fm_panic(const char *, ...); extern void fm_banner(void); extern void fm_ereport_dump(void); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/fs/zfs.h 2017-04-29 20:34:54.000000000 -0700 @@ -626,7 +626,12 @@ * The location of the pool configuration repository, shared between kernel and * userland. */ +#ifdef __FreeBSD__ #define ZPOOL_CACHE "/boot/zfs/zpool.cache" +#endif +#ifdef __NetBSD__ +#define ZPOOL_CACHE "/var/db/zfs/zpool.cache" +#endif /* * vdev states are ordered from least to most healthy. Only in /tmp/out/external/cddl/osnet/dist/uts/common/sys/fs: zut.h Only in /tmp/out/external/cddl/osnet/dist/uts/common/sys/sysevent: dev.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/systeminfo.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/systeminfo.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/systeminfo.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/systeminfo.h 2010-02-27 14:32:39.000000000 -0800 @@ -1,6 +1,112 @@ -#ifndef _SYS_SYSTEMINFO_H_ -#define _SYS_SYSTEMINFO_H_ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ -#define HW_HOSTID_LEN 11 +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ -#endif /* !_SYS_SYSTEMINFO_H_ */ + +#ifndef _SYS_SYSTEMINFO_H +#define _SYS_SYSTEMINFO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _KERNEL +extern char architecture[]; +extern char architecture_32[]; +extern char hw_serial[]; /* machine's 32-bit hostid; a decimal string */ +extern char hw_provider[]; +extern char srpc_domain[]; +extern char platform[]; +#endif /* _KERNEL */ + +/* + * Commands to sysinfo(2) + * + * Values for sysinfo(2) commands are to be assigned by the following + * algorithm: + * + * 1 - 256 Unix International assigned numbers for `get' style commands. + * 257 - 512 Unix International assigned numbers for `set' style commands + * where the value is selected to be the value for the + * corresponding `get' command plus 256. + * 513 - 768 Solaris specific `get' style commands. + * 769 - 1024 Solaris specific `set' style commands where the value is + * selected to be the value for the corresponding `get' command + * plus 256. + * + * These values have be registered + * with Unix International can't be corrected now. The status of a command + * as published or unpublished does not alter the algorithm. + */ + +/* UI defined `get' commands (1-256) */ +#define SI_SYSNAME 1 /* return name of operating system */ +#define SI_HOSTNAME 2 /* return name of node */ +#define SI_RELEASE 3 /* return release of operating system */ +#define SI_VERSION 4 /* return version field of utsname */ +#define SI_MACHINE 5 /* return kind of machine */ +#define SI_ARCHITECTURE 6 /* return instruction set arch */ +#define SI_HW_SERIAL 7 /* return hardware serial number */ +#define SI_HW_PROVIDER 8 /* return hardware manufacturer */ +#define SI_SRPC_DOMAIN 9 /* return secure RPC domain */ + +/* UI defined `set' commands (257-512) */ +#define SI_SET_HOSTNAME 258 /* set name of node */ +#define SI_SET_SRPC_DOMAIN 265 /* set secure RPC domain */ + +/* Solaris defined `get' commands (513-768) */ +#define SI_PLATFORM 513 /* return platform identifier */ +#define SI_ISALIST 514 /* return supported isa list */ +#define SI_DHCP_CACHE 515 /* return kernel-cached DHCPACK */ +#define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */ +#define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */ +#define SI_ARCHITECTURE_K 518 /* kernel SI_ARCHITECTURE equivalent */ +#define SI_ARCHITECTURE_NATIVE 519 /* SI_ARCHITECTURE of the caller */ + +/* Solaris defined `set' commands (769-1024) (none currently assigned) */ + + +#define HW_INVALID_HOSTID 0xFFFFFFFF /* an invalid hostid */ +#define HW_HOSTID_LEN 11 /* minimum buffer size needed */ + /* to hold a decimal or hex */ + /* hostid string */ +#define DOM_NM_LN 64 /* maximum length of domain */ + /* name */ + +#if !defined(_KERNEL) +#if defined(__STDC__) +int sysinfo(int, char *, long); +#else +int sysinfo(); +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_SYSTEMINFO_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/sys/taskq.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/taskq.h --- /tmp/out/external/cddl/osnet/dist/uts/common/sys/taskq.h 2013-11-28 08:38:45.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys/taskq.h 2017-04-17 16:07:59.000000000 -0700 @@ -28,7 +28,9 @@ #include #include +#ifdef __FreeBSD__ #include +#endif #ifdef __cplusplus extern "C" { @@ -36,20 +38,21 @@ #define TASKQ_NAMELEN 31 +#ifdef __FreeBSD__ struct taskqueue; struct taskq { struct taskqueue *tq_queue; }; - -typedef struct taskq taskq_t; -typedef uintptr_t taskqid_t; -typedef void (task_func_t)(void *); - typedef struct taskq_ent { struct task tqent_task; task_func_t *tqent_func; void *tqent_arg; } taskq_ent_t; +#endif + +typedef struct taskq taskq_t; +typedef uintptr_t taskqid_t; +typedef void (task_func_t)(void *); struct proc; @@ -86,8 +89,10 @@ taskq_t *taskq_create_sysdc(const char *, int, int, int, struct proc *, uint_t, uint_t); taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); +#ifdef __FreeBSD__ void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, taskq_ent_t *); +#endif void nulltask(void *); void taskq_destroy(taskq_t *); void taskq_wait(taskq_t *); Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: taskq_impl.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: tsol Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: vnode.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/sys: vtoc.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/zmod/zconf.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/zmod/zconf.h --- /tmp/out/external/cddl/osnet/dist/uts/common/zmod/zconf.h 2012-06-11 22:57:28.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/zmod/zconf.h 2017-04-25 09:06:12.000000000 -0700 @@ -94,6 +94,13 @@ #define crc32 z_crc32 #define get_crc_table z_get_crc_table #define zError z_zError +#define _tr_flush_block z__tr_flush_block +#define _length_code z__length_code +#define inflate_fast z_inflate_fast +#define _tr_stored_block z__tr_stored_block +#define _dist_code z__dist_code +#define _tr_init z__tr_init +#define _tr_align z__tr_align #define MAX_MEM_LEVEL 9 #define MAX_WBITS 15 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/dist/uts/common/zmod/zutil.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/zmod/zutil.h --- /tmp/out/external/cddl/osnet/dist/uts/common/zmod/zutil.h 2012-06-11 22:57:28.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts/common/zmod/zutil.h 2017-04-25 09:04:21.000000000 -0700 @@ -55,6 +55,8 @@ typedef ush FAR ushf; typedef unsigned long ulg; +#define z_errmsg opensolaris_z_errmsg + extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ Only in /tmp/out/external/cddl/osnet/dist/uts/intel: dtrace Only in /tmp/out/external/cddl/osnet/dist/uts: mips Only in /tmp/out/external/cddl/osnet/dist/uts: powerpc Only in /tmp/out/external/cddl/osnet/dist/uts: riscv Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/dist/uts: sparc diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/alloca.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/alloca.h --- /tmp/out/external/cddl/osnet/include/alloca.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/alloca.h 2017-06-09 12:08:57.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: alloca.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/alloca.h 177698 2008-03-28 22:16:18Z jb $ * */ Only in /tmp/out/external/cddl/osnet/include: assert.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/devid.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/devid.h --- /tmp/out/external/cddl/osnet/include/devid.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/devid.h 2017-04-22 09:03:55.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: devid.h,v 1.4 2017/01/10 19:20:35 christos Exp $ */ + /* * CDDL HEADER START * @@ -18,8 +20,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. @@ -33,6 +33,8 @@ #include #include +#define DISK_IDENT_SIZE 128 + typedef struct ddi_devid { char devid[DISK_IDENT_SIZE]; } ddi_devid_t; @@ -44,8 +46,8 @@ int devid_str_decode(char *devidstr, ddi_devid_t *retdevid, char **retminor_name); -int devid_deviceid_to_nmlist(char *search_path, ddi_devid_t devid, - char *minor_name, devid_nmlist_t **retlist); +int devid_deviceid_to_nmlist(const char *search_path, ddi_devid_t devid, + const char *minor_name, devid_nmlist_t **retlist); void devid_str_free(char *str); void devid_free(ddi_devid_t devid); void devid_free_nmlist(devid_nmlist_t *list); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/dtrace.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/dtrace.h --- /tmp/out/external/cddl/osnet/include/dtrace.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/dtrace.h 2017-06-09 12:09:20.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dtrace.h,v 1.2 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2008 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/dtrace.h 179163 2008-05-21 00:26:38Z jb $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/fcntl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/fcntl.h --- /tmp/out/external/cddl/osnet/include/fcntl.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/fcntl.h 2017-06-09 14:29:17.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: fcntl.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/fcntl.h 219089 2011-02-27 19:41:40Z pjd $ * */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include: fm diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/fsshare.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/fsshare.h --- /tmp/out/external/cddl/osnet/include/fsshare.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/fsshare.h 2017-06-09 14:32:13.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: fsshare.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/fsshare.h 177698 2008-03-28 22:16:18Z jb $ */ #ifndef _OPENSOLARIS_FSSHARE_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/libintl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/libintl.h --- /tmp/out/external/cddl/osnet/include/libintl.h 2014-11-01 03:02:51.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/libintl.h 2010-02-20 17:46:34.000000000 -0800 @@ -1,97 +1,42 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2014 Garrett D'Amore - * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - - -#ifndef _LIBINTL_H -#define _LIBINTL_H +/* $NetBSD: libintl.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * wchar_t is a built-in type in standard C++ and as such is not - * defined here when using standard C++. However, the GNU compiler - * fixincludes utility nonetheless creates its own version of this - * header for use by gcc and g++. In that version it adds a redundant - * guard for __cplusplus. To avoid the creation of a gcc/g++ specific - * header we need to include the following magic comment: - * - * we must use the C++ compiler's type - * - * The above comment should not be removed or changed until GNU - * gcc/fixinc/inclhack.def is updated to bypass this header. +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__)) -#ifndef _WCHAR_T -#define _WCHAR_T -#if defined(_LP64) -typedef int wchar_t; -#else -typedef long wchar_t; -#endif -#endif /* !_WCHAR_T */ -#endif /* !defined(__cplusplus) ... */ -#define TEXTDOMAINMAX 256 - -#define __GNU_GETTEXT_SUPPORTED_REVISION(m) \ - ((((m) == 0) || ((m) == 1)) ? 1 : -1) - -extern char *dcgettext(const char *, const char *, const int); -extern char *dgettext(const char *, const char *); -extern char *gettext(const char *); -extern char *textdomain(const char *); -extern char *bindtextdomain(const char *, const char *); - -/* - * LI18NUX 2000 Globalization Specification Version 1.0 - * with Amendment 2 - */ -extern char *dcngettext(const char *, const char *, - const char *, unsigned long int, int); -extern char *dngettext(const char *, const char *, - const char *, unsigned long int); -extern char *ngettext(const char *, const char *, unsigned long int); -extern char *bind_textdomain_codeset(const char *, const char *); +#ifndef _LIBINTL_H_ +#define _LIBINTL_H_ -/* Word handling functions --- requires dynamic linking */ -/* Warning: these are experimental and subject to change. */ -extern int wdinit(void); -extern int wdchkind(wchar_t); -extern int wdbindf(wchar_t, wchar_t, int); -extern wchar_t *wddelim(wchar_t, wchar_t, int); -extern wchar_t mcfiller(void); -extern int mcwrap(void); +#include +#include -#ifdef __cplusplus -} -#endif +#define textdomain(domain) 0 +#define gettext(...) (__VA_ARGS__) +#define dgettext(domain, ...) (__VA_ARGS__) -#endif /* _LIBINTL_H */ +#endif /* !_SOLARIS_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/libproc.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/libproc.h --- /tmp/out/external/cddl/osnet/include/libproc.h 2016-12-18 18:09:18.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/libproc.h 2017-06-27 08:43:35.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: libproc.h,v 1.3 2015/09/24 14:17:20 christos Exp $ */ + /* * Copyright (C) 2008 John Birrell * All rights reserved. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/mnttab.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/mnttab.h --- /tmp/out/external/cddl/osnet/include/mnttab.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/mnttab.h 2017-04-22 09:01:47.000000000 -0700 @@ -1,4 +1,33 @@ -/* $FreeBSD$ */ +/* $NetBSD: mnttab.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _OPENSOLARIS_MNTTAB_H_ #define _OPENSOLARIS_MNTTAB_H_ @@ -9,14 +38,16 @@ #include #include -#define MNTTAB _PATH_DEVZERO +#define MNTTAB _PATH_DEVNULL #define MNT_LINE_MAX 1024 +#if 0 #define MS_OVERLAY 0x0 #define MS_NOMNTTAB 0x0 #define MS_RDONLY 0x1 #define umount2(p, f) unmount(p, f) +#endif struct mnttab { char *mnt_special; @@ -30,6 +61,7 @@ int getmntent(FILE *fp, struct mnttab *mp); char *hasmntopt(struct mnttab *mnt, char *opt); -void statfs2mnttab(struct statfs *sfs, struct mnttab *mp); +struct statvfs; +void statvfs2mnttab(struct statvfs *sfs, struct mnttab *mp); #endif /* !_OPENSOLARIS_MNTTAB_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/priv.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/priv.h --- /tmp/out/external/cddl/osnet/include/priv.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/priv.h 2010-02-20 17:46:34.000000000 -0800 @@ -1,19 +1,46 @@ -/* $FreeBSD$ */ +/* $NetBSD: priv.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _OPENSOLARIS_PRIV_H_ #define _OPENSOLARIS_PRIV_H_ #include +#include #include #include -#define PRIV_SYS_CONFIG 0 - static __inline int -priv_ineffect(int priv) +priv_ineffect(const char *name) { - assert(priv == PRIV_SYS_CONFIG); return (geteuid() == 0); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/sha2.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/sha2.h --- /tmp/out/external/cddl/osnet/include/sha2.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/sha2.h 2010-02-28 07:13:27.000000000 -0800 @@ -1,38 +1,21 @@ -/*- - * Copyright (c) 2010 Pawel Jakub Dawidek - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _OPENSOLARIS_SHA2_H_ -#define _OPENSOLARIS_SHA2_H_ - -#include_next - -#define SHA256Init(c) SHA256_Init(c) -#define SHA256Update(c, d, s) SHA256_Update((c), (d), (s)) -#define SHA256Final(b, c) SHA256_Final((unsigned char *)(b), (c)) +#ifndef _SHA256_H_ +#define _SHA256_H_ -#endif /* !_OPENSOLARIS_SHA2_H_ */ +#include + +#include_next + +#define SHA256Init(b) SHA256_Init(b) +#define SHA256Update SHA256_Update + +static void +SHA256Final(void *digest, SHA256_CTX *ctx) +{ + uint8_t tmp[SHA256_DIGEST_LENGTH]; + + SHA256_Final(tmp, ctx); + memcpy(digest, &tmp, sizeof(tmp)); +} + + +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/solaris.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/solaris.h --- /tmp/out/external/cddl/osnet/include/solaris.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/solaris.h 2017-06-09 18:02:14.000000000 -0700 @@ -1,4 +1,35 @@ -/* $FreeBSD$ */ +/* $NetBSD: solaris.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* $FreeBSD: head/cddl/compat/opensolaris/include/solaris.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _SOLARIS_H_ #define _SOLARIS_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/statcommon.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/statcommon.h --- /tmp/out/external/cddl/osnet/include/statcommon.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/statcommon.h 2010-03-01 13:13:09.000000000 -0800 @@ -1,50 +1,8 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. - * - * Common routines for acquiring snapshots of kstats for - * iostat, mpstat, and vmstat. - */ +#ifndef _STATCOMMON_H_ +#define _STATCOMMON_H_ -#ifndef _STATCOMMON_H -#define _STATCOMMON_H +#define NODATE 0 /* Default: No time stamp */ +#define DDATE 1 /* Standard date format */ +#define UDATE 2 /* Internal representation of Unix time */ -#ifdef __cplusplus -extern "C" { #endif - -#include -#include -#include - -#define NODATE 0 /* Default: No time stamp */ -#define DDATE 1 /* Standard date format */ -#define UDATE 2 /* Internal representation of Unix time */ - -/* Print a timestamp in either Unix or standard format. */ -void print_timestamp(uint_t); - -#ifdef __cplusplus -} -#endif - -#endif /* _STATCOMMON_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/stdio.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdio.h --- /tmp/out/external/cddl/osnet/include/stdio.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdio.h 2017-06-09 14:45:31.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: stdio.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/stdio.h 177698 2008-03-28 22:16:18Z jb $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/stdio_ext.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdio_ext.h --- /tmp/out/external/cddl/osnet/include/stdio_ext.h 2012-06-11 22:55:16.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdio_ext.h 2009-08-07 13:57:55.000000000 -0700 @@ -1,32 +1,32 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. +/* $NetBSD: stdio_ext.h,v 1.1 2009/08/07 20:57:55 haad Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * CDDL HEADER END - */ -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _STDIO_EXT_H -#define _STDIO_EXT_H - -#define enable_extended_FILE_stdio(x,y) (0) - -#endif +#define enable_extended_FILE_stdio(a, b) (0) diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/stdlib.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdlib.h --- /tmp/out/external/cddl/osnet/include/stdlib.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/stdlib.h 2017-06-09 14:45:57.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: stdlib.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/stdlib.h 234856 2012-04-30 23:12:16Z rmh $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/strings.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/strings.h --- /tmp/out/external/cddl/osnet/include/strings.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/strings.h 2017-06-09 15:04:28.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: strings.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/strings.h 177698 2008-03-28 22:16:18Z jb $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/thread.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/thread.h --- /tmp/out/external/cddl/osnet/include/thread.h 2014-11-01 03:02:51.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/thread.h 2017-04-22 08:53:29.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: thread.h,v 1.3 2010/05/10 06:26:11 haad Exp $ */ + /* * CDDL HEADER START * @@ -20,8 +22,6 @@ */ /* - * Copyright 2014 Garrett D'Amore - * * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -29,8 +29,9 @@ #ifndef _THREAD_H #define _THREAD_H +#pragma ident "%Z%%M% %I% %E% SMI" + #include -#include #include /* @@ -48,8 +49,12 @@ #define thr_equal(a,b) pthread_equal(a,b) #define thr_join(t,d,s) pthread_join(t,s) #define thr_exit(r) pthread_exit(r) +#define thr_main() (1) #define _mutex_init(l,f,a) pthread_mutex_init(l,NULL) #define _mutex_destroy(l) pthread_mutex_destroy(l) +#if 0 +#define _mutex_held(l) pthread_mutex_held_np(l) +#endif #define mutex_lock(l) pthread_mutex_lock(l) #define mutex_trylock(l) pthread_mutex_trylock(l) #define mutex_unlock(l) pthread_mutex_unlock(l) @@ -76,7 +81,6 @@ thr_create(void *stack_base, size_t stack_size, void *(*start_func) (void*), void *arg, long flags, thread_t *new_thread_ID) { - pthread_t dummy; int ret; assert(stack_base == NULL); @@ -86,15 +90,19 @@ pthread_attr_t attr; pthread_attr_init(&attr); - if (flags & THR_DETACHED) + if(flags & THR_DETACHED) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (new_thread_ID == NULL) - new_thread_ID = &dummy; + thread_t th_id; + thread_t *t_id; + if(new_thread_ID != NULL) + t_id = new_thread_ID; + else + t_id = &th_id; /* This function ignores the THR_BOUND flag, since NPTL doesn't seem to support PTHREAD_SCOPE_PROCESS */ - ret = pthread_create(new_thread_ID, &attr, start_func, arg); + ret = pthread_create(t_id, &attr, start_func, arg); pthread_attr_destroy(&attr); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/umem.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/umem.h --- /tmp/out/external/cddl/osnet/include/umem.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/umem.h 2009-08-07 13:57:55.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: umem.h,v 1.1 2009/08/07 20:57:55 haad Exp $ */ + /* * CDDL HEADER START * @@ -18,8 +20,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/unistd.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/unistd.h --- /tmp/out/external/cddl/osnet/include/unistd.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/unistd.h 2017-06-09 14:46:28.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: unistd.h,v 1.5 2012/11/04 19:12:41 christos Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/include/unistd.h 177698 2008-03-28 22:16:18Z jb $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/include/zone.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/zone.h --- /tmp/out/external/cddl/osnet/include/zone.h 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/include/zone.h 2010-02-20 17:46:34.000000000 -0800 @@ -1,4 +1,33 @@ -/* $FreeBSD$ */ +/* $NetBSD: zone.h,v 1.3 2010/02/21 01:46:34 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef _ZONE_H_ #define _ZONE_H_ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: drti Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libavl Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libctf diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/errno.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/errno.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/errno.d 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/errno.d 2017-06-09 14:51:21.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: errno.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -21,7 +23,7 @@ * * Portions Copyright 2006-2008 John Birrell jb@freebsd.org * - * $FreeBSD$ + * $FreeBSD: head/cddl/lib/libdtrace/errno.d 179189 2008-05-22 04:26:42Z jb $ */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/libproc_compat.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/libproc_compat.h --- /tmp/out/external/cddl/osnet/lib/libdtrace/libproc_compat.h 2016-12-18 18:09:18.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/libproc_compat.h 2017-06-09 14:35:35.000000000 -0700 @@ -47,7 +47,7 @@ #define Pdelbkpt proc_bkptdel #define Pgrab_error strerror #define Plmid(p, a, l) (-1) -#define Plmid_to_map(p, l, o) proc_name2map(p, o) +#define Plmid_to_map(p, l, o) proc_obj2map((p), (o)) #define Plookup_by_addr proc_addr2sym #define Pname_to_ctf(p, obj) (ctf_file_t *)proc_name2ctf(p, obj) #define Pname_to_map proc_name2map diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/net.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/net.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/net.d 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/net.d 2017-06-09 14:56:22.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: net.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -20,7 +22,7 @@ * * Portions Copyright 2006-2008 John Birrell jb@freebsd.org * - * $FreeBSD$ + * $FreeBSD: head/cddl/lib/libdtrace/net.d 179189 2008-05-22 04:26:42Z jb $ */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/nfs.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/nfs.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/nfs.d 2015-08-29 19:29:09.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/nfs.d 2017-06-09 14:55:58.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: nfs.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -30,8 +32,7 @@ #pragma D depends_on library ip.d #pragma D depends_on library net.d -#pragma D depends_on module kernel -#pragma D depends_on module nfs +#pragma D depends_on module genunix typedef struct nfsv4opinfo { uint64_t noi_xid; /* unique transation ID */ @@ -46,48 +47,52 @@ #pragma D binding "1.5" translator translator conninfo_t < struct svc_req *P > { ci_protocol = P->rq_xprt->xp_master->xp_netid == "tcp" ? "ipv4" : - P->rq_xprt->xp_master->xp_netid == "udp" ? "ipv4" : P->rq_xprt->xp_master->xp_netid == "tcp6" ? "ipv6" : - P->rq_xprt->xp_master->xp_netid == "udp6" ? "ipv6" : ""; - ci_local = (P->rq_xprt->xp_master->xp_netid == "tcp" || - P->rq_xprt->xp_master->xp_netid == "udp") ? - inet_ntoa(&((struct sockaddr_in *) - P->rq_xprt->xp_xpc.xpc_lcladdr.buf)->sin_addr.S_un.S_addr) : - (P->rq_xprt->xp_master->xp_netid == "tcp6" || - P->rq_xprt->xp_master->xp_netid == "udp6") ? - inet_ntoa6(&((struct sockaddr_in6 *) - P->rq_xprt->xp_xpc.xpc_lcladdr.buf)->sin6_addr) : - "unknown"; - - ci_remote = (P->rq_xprt->xp_master->xp_netid == "tcp" || - P->rq_xprt->xp_master->xp_netid == "udp") ? - inet_ntoa(&((struct sockaddr_in *) - P->rq_xprt->xp_xpc.xpc_rtaddr.buf)->sin_addr.S_un.S_addr) : - (P->rq_xprt->xp_master->xp_netid == "tcp6" || - P->rq_xprt->xp_master->xp_netid == "udp6") ? - inet_ntoa6(&((struct sockaddr_in6 *) - P->rq_xprt->xp_xpc.xpc_rtaddr.buf)->sin6_addr) : - "unknown"; + ci_local = inet_ntoa6(&((conn_t *)P->rq_xprt->xp_xpc. + xpc_wq->q_next->q_ptr)->connua_v6addr.connua_laddr); + + ci_remote = inet_ntoa6(&((conn_t *)P->rq_xprt->xp_xpc. + xpc_wq->q_next->q_ptr)->connua_v6addr.connua_faddr); +}; + +#pragma D binding "1.5" translator +translator conninfo_t < struct compound_state *P > { + ci_protocol = P->req->rq_xprt->xp_master->xp_netid == "tcp" ? "ipv4" : + P->req->rq_xprt->xp_master->xp_netid == "tcp6" ? "ipv6" : + ""; + + ci_local = inet_ntoa6(&((conn_t *)P->req->rq_xprt->xp_xpc. + xpc_wq->q_next->q_ptr)->connua_v6addr.connua_laddr); + + ci_remote = inet_ntoa6(&((conn_t *)P->req->rq_xprt->xp_xpc. + xpc_wq->q_next->q_ptr)->connua_v6addr.connua_faddr); +}; + +#pragma D binding "1.5" translator +translator nfsv4opinfo_t < struct compound_state *P > { + noi_xid = P->req->rq_xprt->xp_xid; + noi_cred = P->basecr; + noi_curpath = (P->vp == NULL) ? "" : P->vp->v_path; }; #pragma D binding "1.5" translator translator conninfo_t < rfs4_client_t *P > { - ci_protocol = (P->rc_addr.ss_family == AF_INET) ? "ipv4" : "ipv6"; + ci_protocol = (P->cl_addr.ss_family == AF_INET) ? "ipv4" : "ipv6"; ci_local = ""; - ci_remote = (P->rc_addr.ss_family == AF_INET) ? + ci_remote = (P->cl_addr.ss_family == AF_INET) ? inet_ntoa((ipaddr_t *) - &((struct sockaddr_in *)&P->rc_addr)->sin_addr) : - inet_ntoa6(&((struct sockaddr_in6 *)&P->rc_addr)->sin6_addr); + &((struct sockaddr_in *)&P->cl_addr)->sin_addr) : + inet_ntoa6(&((struct sockaddr_in6 *)&P->cl_addr)->sin6_addr); }; #pragma D binding "1.5" translator translator nfsv4cbinfo_t < rfs4_deleg_state_t *P > { - nci_curpath = (P->rds_finfo->rf_vp == NULL) ? "" : - P->rds_finfo->rf_vp->v_path; + nci_curpath = (P->finfo->vp == NULL) ? "" : + P->finfo->vp->v_path; }; typedef struct nfsv3opinfo { diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/psinfo.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/psinfo.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/psinfo.d 2016-10-10 04:14:32.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/psinfo.d 2017-06-09 14:51:46.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: psinfo.d,v 1.5 2015/10/07 00:35:23 christos Exp $ */ + /* * CDDL HEADER START * @@ -28,8 +30,6 @@ * Use is subject to license terms. */ -#pragma D depends_on module kernel - typedef struct psinfo { int pr_nlwp; /* number of threads */ pid_t pr_pid; /* unique process id */ @@ -44,25 +44,22 @@ pr_addr; /* address of process */ string pr_psargs; /* process arguments */ u_int pr_arglen; /* process argument length */ - u_int pr_jailid; /* jail id */ } psinfo_t; #pragma D binding "1.0" translator translator psinfo_t < struct proc *T > { - pr_nlwp = T->p_numthreads; + pr_nlwp = T->p_nlwps; pr_pid = T->p_pid; pr_ppid = (T->p_pptr == 0) ? 0 : T->p_pptr->p_pid; - pr_pgid = (T->p_leader == 0) ? 0 : T->p_leader->p_pid; + pr_pgid = (T->p_pgrp->pg_session->s_leader == 0) ? 0 : T->p_pgrp->pg_session->s_leader->p_pid; pr_sid = (T->p_pgrp == 0) ? 0 : ((T->p_pgrp->pg_session == 0) ? 0 : T->p_pgrp->pg_session->s_sid); - pr_uid = T->p_ucred->cr_ruid; - pr_euid = T->p_ucred->cr_uid; - pr_gid = T->p_ucred->cr_rgid; - pr_egid = T->p_ucred->cr_groups[0]; + pr_uid = T->p_cred->cr_uid; + pr_euid = T->p_cred->cr_euid; + pr_gid = T->p_cred->cr_gid; + pr_egid = T->p_cred->cr_egid; pr_addr = 0; - pr_psargs = (T->p_args == 0) ? "" : - memstr(T->p_args->ar_args, ' ', T->p_args->ar_length); - pr_arglen = T->p_args->ar_length; - pr_jailid = T->p_ucred->cr_prison->pr_id; + pr_psargs = stringof(T->p_comm); + pr_arglen = strlen(T->p_comm); }; typedef struct lwpsinfo { @@ -79,22 +76,21 @@ } lwpsinfo_t; #pragma D binding "1.0" translator -translator lwpsinfo_t < struct thread *T > { - pr_lwpid = T->td_tid; - pr_pri = T->td_priority; - pr_flag = T->td_flags; - pr_state = 0; /* XXX */ - pr_sname = '?'; /* XXX */ +translator lwpsinfo_t < struct lwp *T > { + pr_lwpid = T->l_lid; + pr_pri = T->l_priority; + pr_flag = T->l_flag; + pr_state = T->l_stat; + pr_sname = '?'; /* XXX */ pr_syscall = 0; /* XXX */ pr_addr = (uintptr_t)T; - pr_wchan = (uintptr_t)T->td_wchan; + pr_wchan = (uintptr_t)T->l_wchan; }; -inline psinfo_t *curpsinfo = xlate (curthread->td_proc); +inline psinfo_t *curpsinfo = xlate (curthread->l_proc); #pragma D attributes Stable/Stable/Common curpsinfo #pragma D binding "1.0" curpsinfo inline lwpsinfo_t *curlwpsinfo = xlate (curthread); #pragma D attributes Stable/Stable/Common curlwpsinfo #pragma D binding "1.0" curlwpsinfo - diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/sched.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/sched.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/sched.d 2015-08-29 19:29:09.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/sched.d 2017-06-09 14:55:49.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sched.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -27,7 +29,7 @@ * Use is subject to license terms. */ -#pragma D depends_on module kernel +#pragma D depends_on module unix #pragma D depends_on provider sched struct cpuinfo { Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace: shlib_version diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/signal.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/signal.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/signal.d 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/signal.d 2017-06-09 14:57:22.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: signal.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -21,7 +23,7 @@ * * Portions Copyright 2008 John Birrell jb@freebsd.org * - * $FreeBSD$ + * $FreeBSD: head/cddl/lib/libdtrace/signal.d 179189 2008-05-22 04:26:42Z jb $ */ inline int SIGHUP = 1; diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libdtrace/unistd.d /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/unistd.d --- /tmp/out/external/cddl/osnet/lib/libdtrace/unistd.d 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libdtrace/unistd.d 2017-06-09 14:57:47.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: unistd.d,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -18,7 +20,7 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/cddl/lib/libdtrace/unistd.d 179189 2008-05-22 04:26:42Z jb $ */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libnvpair Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libumem: shlib_version diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libumem/umem.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libumem/umem.c --- /tmp/out/external/cddl/osnet/lib/libumem/umem.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libumem/umem.c 2010-05-02 16:59:54.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: umem.c,v 1.2 2010/05/02 23:59:54 haad Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* * Copyright 2006 Ricardo Correia. All rights reserved. @@ -135,7 +135,8 @@ } if(cache->constructor != NULL) { - if(cache->constructor(buf, cache->callback_data, flags) != 0) { + /* XXX NetBSD pool cache costructor has switched arguments. */ + if(cache->constructor(cache->callback_data, buf, flags) != 0) { free(buf); if(!(flags & UMEM_NOFAIL)) return NULL; @@ -155,7 +156,8 @@ void umem_cache_free(umem_cache_t *cache, void *buffer) { if(cache->destructor != NULL) - cache->destructor(buffer, cache->callback_data); + /* XXX NetBSD pool cache costructor has switched arguments. */ + cache->destructor(cache->callback_data, buffer); free(buffer); } Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libuutil diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/deviceid.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/deviceid.c --- /tmp/out/external/cddl/osnet/lib/libzfs/deviceid.c 2012-07-17 20:08:47.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/deviceid.c 2017-06-09 15:01:14.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: deviceid.c,v 1.3 2017/01/10 19:20:35 christos Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -25,7 +56,8 @@ */ #include -__FBSDID("$FreeBSD$"); +/* __FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/deviceid.c 238112 2012-07-04 17:36:26Z pjd $"); */ +__RCSID("$NetBSD: deviceid.c,v 1.3 2017/01/10 19:20:35 christos Exp $"); #include #include @@ -33,8 +65,8 @@ #include #include #include -#include #include +#include int devid_str_decode(char *devidstr, ddi_devid_t *retdevid, char **retminor_name) @@ -51,23 +83,11 @@ } int -devid_deviceid_to_nmlist(char *search_path, ddi_devid_t devid, char *minor_name, - devid_nmlist_t **retlist) +devid_deviceid_to_nmlist(const char *search_path, ddi_devid_t devid, + const char *minor_name, devid_nmlist_t **retlist) { - char path[MAXPATHLEN]; - char *dst; - if (g_get_name(devid.devid, path, sizeof(path)) == -1) - return (errno); - *retlist = malloc(sizeof(**retlist)); - if (*retlist == NULL) - return (ENOMEM); - if (strlcpy((*retlist)[0].devname, path, - sizeof((*retlist)[0].devname)) >= sizeof((*retlist)[0].devname)) { - free(*retlist); - return (ENAMETOOLONG); - } - return (0); + errx(1, "XXXNETBSD devid_deviceid_to_nmlist"); } void @@ -93,7 +113,6 @@ int devid_get(int fd, ddi_devid_t *retdevid) { - return (ENOENT); } Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs: efi.c diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/fsshare.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/fsshare.c --- /tmp/out/external/cddl/osnet/lib/libzfs/fsshare.c 2016-05-31 04:23:09.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/fsshare.c 2017-06-09 15:02:37.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: fsshare.c,v 1.2 2009/08/10 22:44:41 haad Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -25,7 +27,9 @@ */ #include -__FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/fsshare.c 299342 2016-05-10 07:50:57Z bapt $"); +/* __FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/fsshare.c 299342 2016-05-10 07:50:57Z bapt $"); */ + +__RCSID("$NetBSD: fsshare.c,v 1.2 2009/08/10 22:44:41 haad Exp $"); #include @@ -33,12 +37,12 @@ #include #include #include -#include #include /* _PATH_MOUNTDPID */ #include #include #include #include +#include #define FILE_HEADER "# !!! DO NOT EDIT THIS FILE MANUALLY !!!\n\n" #define OPTSSIZE 1024 @@ -47,21 +51,15 @@ static void restart_mountd(void) { - struct pidfh *pfh; - pid_t mountdpid; + int pid; + FILE *pfh; - pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid); - if (pfh != NULL) { - /* Mountd is not running. */ - pidfile_remove(pfh); + pfh = fopen(_PATH_MOUNTDPID, "r"); + if (pfh == NULL) return; - } - if (errno != EEXIST) { - /* Cannot open pidfile for some reason. */ - return; - } - /* We have mountd(8) PID in mountdpid varible. */ - kill(mountdpid, SIGHUP); + fscanf(pfh, "%d", &pid); + fclose(pfh); + kill((pid_t)pid, SIGHUP); } /* @@ -112,11 +110,11 @@ * * Recognized keywords: * - * ro, maproot, mapall, mask, network, sec, alldirs, public, webnfs, index, quiet + * ro, maproot, mapall, mask, network, alldirs, public, webnfs, index, quiet * */ static const char *known_opts[] = { "ro", "maproot", "mapall", "mask", - "network", "sec", "alldirs", "public", "webnfs", "index", "quiet", NULL }; + "network", "alldirs", "public", "webnfs", "index", "quiet", NULL }; static char * translate_opts(const char *shareopts) { @@ -223,7 +221,6 @@ error = errno; unlink(tmpfile); } else { - fflush(newfd); /* * Send SIGHUP to mountd, but unlock exports file later. */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/mkdirp.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/mkdirp.c --- /tmp/out/external/cddl/osnet/lib/libzfs/mkdirp.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/mkdirp.c 2009-08-07 13:57:56.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: mkdirp.c,v 1.1 2009/08/07 20:57:56 haad Exp $ */ + /* * CDDL HEADER START * @@ -18,8 +20,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* Copyright (c) 1988 AT&T */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/mnttab.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/mnttab.c --- /tmp/out/external/cddl/osnet/lib/libzfs/mnttab.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/mnttab.c 2017-04-29 14:29:33.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: mnttab.c,v 1.2 2010/02/28 17:36:51 haad Exp $ */ + /*- * Copyright (c) 2006 Pawel Jakub Dawidek * All rights reserved. @@ -30,20 +32,22 @@ */ #include -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/mnttab.c 209962 2010-07-12 23:49:04Z mm $"); +__RCSID("$NetBSD: mnttab.c,v 1.2 2010/02/28 17:36:51 haad Exp $"); #include -#include +#include #include #include -#include +#include #include #include #include #include +#include -static char * +char * mntopt(char **p) { char *cp = *p; @@ -92,14 +96,14 @@ } void -statfs2mnttab(struct statfs *sfs, struct mnttab *mp) +statvfs2mnttab(struct statvfs *sfs, struct mnttab *mp) { static char mntopts[MNTMAXSTR]; long flags; mntopts[0] = '\0'; - flags = sfs->f_flags; + flags = sfs->f_flag; #define OPTADD(opt) optadd(mntopts, sizeof(mntopts), (opt)) if (flags & MNT_RDONLY) OPTADD(MNTOPT_RO); @@ -127,27 +131,26 @@ mp->mnt_mntopts = mntopts; } -static struct statfs *gsfs = NULL; -static int allfs = 0; +static struct statvfs *gsfs; +static int allfs; static int -statfs_init(void) +statvfs_init(void) { - struct statfs *sfs; + struct statvfs *sfs; int error; if (gsfs != NULL) { free(gsfs); gsfs = NULL; } - allfs = getfsstat(NULL, 0, MNT_WAIT); + allfs = getvfsstat(NULL, 0, ST_WAIT); if (allfs == -1) goto fail; gsfs = malloc(sizeof(gsfs[0]) * allfs * 2); if (gsfs == NULL) goto fail; - allfs = getfsstat(gsfs, (long)(sizeof(gsfs[0]) * allfs * 2), - MNT_WAIT); + allfs = getvfsstat(gsfs, sizeof(gsfs[0]) * allfs * 2, ST_WAIT); if (allfs == -1) goto fail; sfs = realloc(gsfs, allfs * sizeof(gsfs[0])); @@ -164,12 +167,11 @@ } int -getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp) +getmntany(FILE *fd, struct mnttab *mgetp, struct mnttab *mrefp) { - struct statfs *sfs; int i, error; - error = statfs_init(); + error = statvfs_init(); if (error != 0) return (error); @@ -186,7 +188,7 @@ strcmp(mrefp->mnt_fstype, gsfs[i].f_fstypename) != 0) { continue; } - statfs2mnttab(&gsfs[i], mgetp); + statvfs2mnttab(&gsfs[i], mgetp); return (0); } return (-1); @@ -195,21 +197,21 @@ int getmntent(FILE *fp, struct mnttab *mp) { - struct statfs *sfs; + struct statvfs *sfs; int error, nfs; nfs = (int)lseek(fileno(fp), 0, SEEK_CUR); if (nfs == -1) return (errno); - /* If nfs is 0, we want to refresh out cache. */ + /* If nfs is 0, we want to refresh our cache. */ if (nfs == 0 || gsfs == NULL) { - error = statfs_init(); + error = statvfs_init(); if (error != 0) return (error); } if (nfs >= allfs) return (-1); - statfs2mnttab(&gsfs[nfs], mp); + statvfs2mnttab(&gsfs[nfs], mp); if (lseek(fileno(fp), 1, SEEK_CUR) == -1) return (errno); return (0); Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs: shlib_version diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/thread_pool.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/thread_pool.c --- /tmp/out/external/cddl/osnet/lib/libzfs/thread_pool.c 2014-12-11 03:54:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/thread_pool.c 2017-04-20 15:48:27.000000000 -0700 @@ -25,9 +25,7 @@ */ #include -__FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/thread_pool.c 275595 2014-12-08 06:10:47Z delphij $"); - -#pragma ident "%Z%%M% %I% %E% SMI" +/* __FBSDID("$FreeBSD: head/cddl/compat/opensolaris/misc/thread_pool.c 275595 2014-12-08 06:10:47Z delphij $"); */ #include #include diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/zmount.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/zmount.c --- /tmp/out/external/cddl/osnet/lib/libzfs/zmount.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/zmount.c 2009-08-07 13:57:56.000000000 -0700 @@ -1,7 +1,12 @@ +/* $NetBSD: zmount.c,v 1.1 2009/08/07 20:57:56 haad Exp $ */ + /*- - * Copyright (c) 2006 Pawel Jakub Dawidek + * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,98 +16,58 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * This file implements Solaris compatible zmount() function. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #include -__FBSDID("$FreeBSD$"); - #include #include #include #include -#include + #include #include #include -#include - -static void -build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, - size_t len) -{ - int i; +#include - if (*iovlen < 0) - return; - i = *iovlen; - *iov = realloc(*iov, sizeof(**iov) * (i + 2)); - if (*iov == NULL) { - *iovlen = -1; - return; - } - (*iov)[i].iov_base = strdup(name); - (*iov)[i].iov_len = strlen(name) + 1; - i++; - (*iov)[i].iov_base = val; - if (len == (size_t)-1) { - if (val != NULL) - len = strlen(val) + 1; - else - len = 0; - } - (*iov)[i].iov_len = (int)len; - *iovlen = ++i; -} +#undef mount int zmount(const char *spec, const char *dir, int mflag, char *fstype, char *dataptr, int datalen, char *optptr, int optlen) { - struct iovec *iov; - char *optstr, *os, *p; - int iovlen, rv; - - assert(spec != NULL); - assert(dir != NULL); - assert(mflag == 0 || mflag == MS_RDONLY); - assert(fstype != NULL); - assert(strcmp(fstype, MNTTYPE_ZFS) == 0); - assert(dataptr == NULL); - assert(datalen == 0); - assert(optptr != NULL); - assert(optlen > 0); - - optstr = strdup(optptr); - assert(optstr != NULL); - - iov = NULL; - iovlen = 0; - if (mflag & MS_RDONLY) - build_iovec(&iov, &iovlen, "ro", NULL, 0); - build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); - build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, dir), - (size_t)-1); - build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1); - for (p = optstr; p != NULL; strsep(&p, ",/ ")) { - if (*p != '\0') - build_iovec(&iov, &iovlen, p, NULL, (size_t)-1); - } - rv = nmount(iov, iovlen, 0); - free(optstr); - return (rv); + zfs_args_t za; + + memset(&za, 0, sizeof(zfs_args_t)); + + strlcpy(za.fspec, spec, sizeof(za.fspec) - 1); + if (dataptr != NULL) + strlcpy(za.dataptr, dataptr, MAXPATHLEN); + strlcpy(za.optptr, optptr, sizeof(za.optptr) - 1); + za.mflag = mflag; + za.datalen = datalen; + za.optlen = optlen; + + /* Null unused variables */ + za.flags = 0; + za.fstype = NULL; + + return mount(fstype, dir, 0, &za, sizeof(za)); +} + +int +umount2(const char *spec, int mflag) +{ + + return unmount(spec, 0); } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/lib/libzfs/zone.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/zone.c --- /tmp/out/external/cddl/osnet/lib/libzfs/zone.c 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib/libzfs/zone.c 2017-06-09 15:04:10.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: zone.c,v 1.1 2009/08/07 20:57:56 haad Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/cddl/compat/opensolaris/misc/zone.c 185029 2008-11-17 20:49:29Z pjd $ */ #include @@ -32,15 +34,10 @@ #include #include -zoneid_t +int getzoneid(void) { - size_t size; - int jailid; /* Information that we are in jail or not is enough for our needs. */ - size = sizeof(jailid); - if (sysctlbyname("security.jail.jailed", &jailid, &size, NULL, 0) == -1) - assert(!"No security.jail.jailed sysctl!"); - return ((zoneid_t)jailid); + return 0; } Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libzfs_core Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/lib: libzpool Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys: elf.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/kern/callb.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/callb.c --- /tmp/out/external/cddl/osnet/sys/kern/callb.c 2015-02-03 23:24:18.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/callb.c 2009-08-07 13:57:57.000000000 -0700 @@ -1,9 +1,12 @@ +/* $NetBSD: callb.c,v 1.1 2009/08/07 20:57:57 haad Exp $ */ + /* * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,10 +22,12 @@ * CDDL HEADER END */ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +#pragma ident "%Z%%M% %I% %E% SMI" + #include #include #include @@ -106,24 +111,14 @@ callb_fini(void *dummy __unused) { callb_t *cp; - int i; mutex_enter(&ct->ct_lock); - for (i = 0; i < 16; i++) { - while ((cp = ct->ct_freelist) != NULL) { - ct->ct_freelist = cp->c_next; - ct->ct_ncallb--; - kmem_free(cp, sizeof (callb_t)); - } - if (ct->ct_ncallb == 0) - break; - /* Not all callbacks finished, waiting for the rest. */ - mutex_exit(&ct->ct_lock); - tsleep(ct, 0, "callb", hz / 4); - mutex_enter(&ct->ct_lock); + while ((cp = ct->ct_freelist) != NULL) { + ct->ct_freelist = cp->c_next; + ct->ct_ncallb--; + kmem_free(cp, sizeof (callb_t)); } - if (ct->ct_ncallb > 0) - printf("%s: Leaked %d callbacks!\n", __func__, ct->ct_ncallb); + ASSERT(ct->ct_ncallb == 0); mutex_exit(&ct->ct_lock); mutex_destroy(&callb_safe_mutex); mutex_destroy(&callb_table.ct_lock); @@ -275,7 +270,7 @@ #ifdef CALLB_DEBUG printf("callb_execute: name=%s func=%p arg=%p\n", - cp->c_name, (void *)cp->c_func, (void *)cp->c_arg); + cp->c_name, (void *)cp->c_func, (void *)cp->c_arg); #endif /* CALLB_DEBUG */ mutex_exit(&ct->ct_lock); @@ -314,14 +309,12 @@ switch (code) { case CB_CODE_CPR_CHKPT: cp->cc_events |= CALLB_CPR_START; -#ifdef CPR_NOT_THREAD_SAFE while (!(cp->cc_events & CALLB_CPR_SAFE)) /* cv_timedwait() returns -1 if it times out. */ - if ((ret = cv_reltimedwait(&cp->cc_callb_cv, - cp->cc_lockp, (callb_timeout_sec * hz), - TR_CLOCK_TICK)) == -1) + if ((ret = cv_timedwait(&cp->cc_callb_cv, + cp->cc_lockp, + callb_timeout_sec * hz)) == -1) break; -#endif break; case CB_CODE_CPR_RESUME: @@ -367,72 +360,3 @@ cv_broadcast(&ct->ct_busy_cv); mutex_exit(&ct->ct_lock); } - -#ifdef illumos -/* - * Return a boolean value indicating whether a particular kernel thread is - * stopped in accordance with the cpr callback protocol. If returning - * false, also return a pointer to the thread name via the 2nd argument. - */ -boolean_t -callb_is_stopped(kthread_id_t tp, caddr_t *thread_name) -{ - callb_t *cp; - boolean_t ret_val; - - mutex_enter(&ct->ct_lock); - - for (cp = ct->ct_first_cb[CB_CL_CPR_DAEMON]; - cp != NULL && tp != cp->c_thread; cp = cp->c_next) - ; - - ret_val = (cp != NULL); - if (ret_val) { - /* - * We found the thread in the callback table and have - * provisionally set the return value to true. Now - * see if it is marked "safe" and is sleeping or stopped. - */ - callb_cpr_t *ccp = (callb_cpr_t *)cp->c_arg; - - *thread_name = cp->c_name; /* in case not stopped */ - mutex_enter(ccp->cc_lockp); - - if (ccp->cc_events & CALLB_CPR_SAFE) { - int retry; - - mutex_exit(ccp->cc_lockp); - for (retry = 0; retry < CALLB_MAX_RETRY; retry++) { - thread_lock(tp); - if (tp->t_state & (TS_SLEEP | TS_STOPPED)) { - thread_unlock(tp); - break; - } - thread_unlock(tp); - delay(CALLB_THREAD_DELAY); - } - ret_val = retry < CALLB_MAX_RETRY; - } else { - ret_val = - (ccp->cc_events & CALLB_CPR_ALWAYS_SAFE) != 0; - mutex_exit(ccp->cc_lockp); - } - } else { - /* - * Thread not found in callback table. Make the best - * attempt to identify the thread in the error message. - */ - ulong_t offset; - char *sym = kobj_getsymname((uintptr_t)tp->t_startpc, - &offset); - - *thread_name = sym ? sym : "*unknown*"; - } - - mutex_exit(&ct->ct_lock); - return (ret_val); -} -#endif /* illumos */ - -SYSINIT(sol_callb, SI_SUB_DRIVERS, SI_ORDER_FIRST, callb_init, NULL); -SYSUNINIT(sol_callb, SI_SUB_DRIVERS, SI_ORDER_FIRST, callb_fini, NULL); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/kern/ddi.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/ddi.c --- /tmp/out/external/cddl/osnet/sys/kern/ddi.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/ddi.c 2017-06-09 22:28:56.000000000 -0700 @@ -1,3 +1,33 @@ + +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + /*- * Copyright (c) 2010 Pawel Jakub Dawidek * All rights reserved. @@ -24,52 +54,168 @@ * SUCH DAMAGE. */ -#include -__FBSDID("$FreeBSD$"); - +#include +#include +#include +#include #include -#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -int -ddi_strtol(const char *str, char **nptr, int base, long *result) +__strong_alias(ddi_strtol,ddi_strtoul) + +/* + * String to integer conversion routines. + * + * This file is derived from usr/src/common/util/strtol.c + * + * We cannot use the user land versions as there is no errno to report + * error in kernel. So the return value is used to return an error, + * and the result is stored in an extra parameter passed by reference. + * Otherwise, the following functions are identical to the user land + * versions. + */ + +/* + * We should have a kernel version of ctype.h. + */ +#define isalnum(ch) (isalpha(ch) || isdigit(ch)) +#define isalpha(ch) (isupper(ch) || islower(ch)) +#define isdigit(ch) ((ch) >= '0' && (ch) <= '9') +#define islower(ch) ((ch) >= 'a' && (ch) <= 'z') +#define isspace(ch) (((ch) == ' ') || ((ch) == '\r') || ((ch) == '\n') || \ + ((ch) == '\t') || ((ch) == '\f')) +#define isupper(ch) ((ch) >= 'A' && (ch) <= 'Z') +#define isxdigit(ch) (isdigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || \ + ((ch) >= 'A' && (ch) <= 'F')) + +#define DIGIT(x) \ + (isdigit(x) ? (x) - '0' : islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A') + +#define MBASE ('z' - 'a' + 1 + 10) + +/* + * The following macro is a local version of isalnum() which limits + * alphabetic characters to the ranges a-z and A-Z; locale dependent + * characters will not return 1. The members of a-z and A-Z are + * assumed to be in ascending order and contiguous + */ +#define lisalnum(x) \ + (isdigit(x) || ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z')) + +static int +do_mkdirp(const char *path) { + struct lwp *l = curlwp; + int mode; + int error; + register_t ret; + + const char *s, *e; + char *here; + + error = 0; + mode = 493; + + if (*path != '/') + panic("Not an absolute path"); + + here = PNBUF_GET(); + for (s = path;; s = e) { + e = strchr(s + 1, '/'); + if (e == NULL) + break; + + strlcpy(here, path, e - path + 1); + error = do_sys_mkdir((const char *)here, mode, UIO_SYSSPACE); + } + PNBUF_PUT(here); - *result = strtol(str, nptr, base); - if (*result == 0) - return (EINVAL); - else if (*result == LONG_MIN || *result == LONG_MAX) - return (ERANGE); - return (0); + if (error == EEXIST) + error = 0; + + return error; } int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result) { - - if (str == hw_serial) { - *result = prison0.pr_hostid; - return (0); - } - - *result = strtoul(str, nptr, base); - if (*result == 0) + unsigned long val; + int c; + int xx; + unsigned long multmax; + int neg = 0; + const char **ptr = (const char **)nptr; + const unsigned char *ustr = (const unsigned char *)str; + + if (ptr != (const char **)0) + *ptr = (char *)ustr; /* in case no number is formed */ + if (base < 0 || base > MBASE || base == 1) { + /* base is invalid -- should be a fatal error */ return (EINVAL); - else if (*result == ULONG_MAX) - return (ERANGE); + } + if (!isalnum(c = *ustr)) { + while (isspace(c)) + c = *++ustr; + switch (c) { + case '-': + neg++; + /* FALLTHROUGH */ + case '+': + c = *++ustr; + } + } + if (base == 0) + if (c != '0') + base = 10; + else if (ustr[1] == 'x' || ustr[1] == 'X') + base = 16; + else + base = 8; + /* + * for any base > 10, the digits incrementally following + * 9 are assumed to be "abc...z" or "ABC...Z" + */ + if (!lisalnum(c) || (xx = DIGIT(c)) >= base) + return (EINVAL); /* no number formed */ + if (base == 16 && c == '0' && (ustr[1] == 'x' || ustr[1] == 'X') && + isxdigit(ustr[2])) + c = *(ustr += 2); /* skip over leading "0x" or "0X" */ + + multmax = ULONG_MAX / (unsigned long)base; + val = DIGIT(c); + for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; ) { + if (val > multmax) + goto overflow; + val *= base; + if (ULONG_MAX - val < xx) + goto overflow; + val += xx; + c = *++ustr; + } + if (ptr != (const char **)0) + *ptr = (char *)ustr; + *result = neg ? -val : val; return (0); + +overflow: + for (c = *++ustr; lisalnum(c) && (xx = DIGIT(c)) < base; (c = *++ustr)) + ; + if (ptr != (const char **)0) + *ptr = (char *)ustr; + return (ERANGE); } int ddi_strtoull(const char *str, char **nptr, int base, unsigned long long *result) { - *result = (unsigned long long)strtouq(str, nptr, base); + *result = (unsigned long long)strtoull(str, nptr, base); if (*result == 0) return (EINVAL); else if (*result == ULLONG_MAX) @@ -77,122 +223,401 @@ return (0); } -struct ddi_soft_state_item { - int ssi_item; - void *ssi_data; - LIST_ENTRY(ddi_soft_state_item) ssi_next; -}; - -struct ddi_soft_state { - size_t ss_size; - kmutex_t ss_lock; - LIST_HEAD(, ddi_soft_state_item) ss_list; -}; +/* + * Find first bit set in a mask (returned counting from 1 up) + */ -static void * -ddi_get_soft_state_locked(struct ddi_soft_state *ss, int item) +int +ddi_ffs(long mask) { - struct ddi_soft_state_item *itemp; + return (ffs(mask)); +} - ASSERT(MUTEX_HELD(&ss->ss_lock)); +/* + * Find last bit set. Take mask and clear + * all but the most significant bit, and + * then let ffs do the rest of the work. + * + * Algorithm courtesy of Steve Chessin. + */ + +int +ddi_fls(long mask) +{ + while (mask) { + long nx; - LIST_FOREACH(itemp, &ss->ss_list, ssi_next) { - if (itemp->ssi_item == item) - return (itemp->ssi_data); + if ((nx = (mask & (mask - 1))) == 0) + break; + mask = nx; } - return (NULL); + return (ffs(mask)); } -void * -ddi_get_soft_state(void *state, int item) +/* + * The next five routines comprise generic storage management utilities + * for driver soft state structures (in "the old days," this was done + * with a statically sized array - big systems and dynamic loading + * and unloading make heap allocation more attractive) + */ + +/* + * Allocate a set of pointers to 'n_items' objects of size 'size' + * bytes. Each pointer is initialized to nil. + * + * The 'size' and 'n_items' values are stashed in the opaque + * handle returned to the caller. + * + * This implementation interprets 'set of pointers' to mean 'array + * of pointers' but note that nothing in the interface definition + * precludes an implementation that uses, for example, a linked list. + * However there should be a small efficiency gain from using an array + * at lookup time. + * + * NOTE As an optimization, we make our growable array allocations in + * powers of two (bytes), since that's how much kmem_alloc (currently) + * gives us anyway. It should save us some free/realloc's .. + * + * As a further optimization, we make the growable array start out + * with MIN_N_ITEMS in it. + */ + +/* + * This data structure is entirely private to the soft state allocator. + */ +struct i_ddi_soft_state { + void **array; /* the array of pointers */ + kmutex_t lock; /* serialize access to this struct */ + size_t size; /* how many bytes per state struct */ + size_t n_items; /* how many structs herein */ + struct i_ddi_soft_state *next; /* 'dirty' elements */ +}; + +#define MIN_N_ITEMS 8 /* 8 void *'s == 32 bytes */ + +int +ddi_soft_state_init(void **state_p, size_t size, size_t n_items) { - struct ddi_soft_state *ss = state; - void *data; + struct i_ddi_soft_state *ss; + + if (state_p == NULL || *state_p != NULL || size == 0) + return (EINVAL); + + ss = kmem_zalloc(sizeof (*ss), KM_SLEEP); + mutex_init(&ss->lock, NULL, MUTEX_DRIVER, NULL); + ss->size = size; + + if (n_items < MIN_N_ITEMS) + ss->n_items = MIN_N_ITEMS; + else { + int bitlog; + + if ((bitlog = ddi_fls(n_items)) == ddi_ffs(n_items)) + bitlog--; + ss->n_items = 1 << bitlog; + } + + ASSERT(ss->n_items >= n_items); + + ss->array = kmem_zalloc(ss->n_items * sizeof (void *), KM_SLEEP); - mutex_enter(&ss->ss_lock); - data = ddi_get_soft_state_locked(ss, item); - mutex_exit(&ss->ss_lock); - return (data); + *state_p = ss; + + return (0); } + +/* + * Allocate a state structure of size 'size' to be associated + * with item 'item'. + * + * In this implementation, the array is extended to + * allow the requested offset, if needed. + */ int ddi_soft_state_zalloc(void *state, int item) { - struct ddi_soft_state *ss = state; - struct ddi_soft_state_item *itemp; + struct i_ddi_soft_state *ss; + void **array; + void *new_element; - itemp = kmem_alloc(sizeof(*itemp), KM_SLEEP); - itemp->ssi_item = item; - itemp->ssi_data = kmem_zalloc(ss->ss_size, KM_SLEEP); - - mutex_enter(&ss->ss_lock); - if (ddi_get_soft_state_locked(ss, item) != NULL) { - mutex_exit(&ss->ss_lock); - kmem_free(itemp->ssi_data, ss->ss_size); - kmem_free(itemp, sizeof(*itemp)); + if ((ss = state) == NULL || item < 0) return (DDI_FAILURE); + + mutex_enter(&ss->lock); + if (ss->size == 0) { + mutex_exit(&ss->lock); + cmn_err(CE_WARN, "ddi_soft_state_zalloc: bad handle"); + return (DDI_FAILURE); + } + + array = ss->array; /* NULL if ss->n_items == 0 */ + ASSERT(ss->n_items != 0 && array != NULL); + + /* + * refuse to tread on an existing element + */ + if (item < ss->n_items && array[item] != NULL) { + mutex_exit(&ss->lock); + return (DDI_FAILURE); + } + + /* + * Allocate a new element to plug in + */ + new_element = kmem_zalloc(ss->size, KM_SLEEP); + + /* + * Check if the array is big enough, if not, grow it. + */ + if (item >= ss->n_items) { + void **new_array; + size_t new_n_items; + struct i_ddi_soft_state *dirty; + + /* + * Allocate a new array of the right length, copy + * all the old pointers to the new array, then + * if it exists at all, put the old array on the + * dirty list. + * + * Note that we can't kmem_free() the old array. + * + * Why -- well the 'get' operation is 'mutex-free', so we + * can't easily catch a suspended thread that is just about + * to dereference the array we just grew out of. So we + * cons up a header and put it on a list of 'dirty' + * pointer arrays. (Dirty in the sense that there may + * be suspended threads somewhere that are in the middle + * of referencing them). Fortunately, we -can- garbage + * collect it all at ddi_soft_state_fini time. + */ + new_n_items = ss->n_items; + while (new_n_items < (1 + item)) + new_n_items <<= 1; /* double array size .. */ + + ASSERT(new_n_items >= (1 + item)); /* sanity check! */ + + new_array = kmem_zalloc(new_n_items * sizeof (void *), + KM_SLEEP); + /* + * Copy the pointers into the new array + */ + bcopy(array, new_array, ss->n_items * sizeof (void *)); + + /* + * Save the old array on the dirty list + */ + dirty = kmem_zalloc(sizeof (*dirty), KM_SLEEP); + dirty->array = ss->array; + dirty->n_items = ss->n_items; + dirty->next = ss->next; + ss->next = dirty; + + ss->array = (array = new_array); + ss->n_items = new_n_items; } - LIST_INSERT_HEAD(&ss->ss_list, itemp, ssi_next); - mutex_exit(&ss->ss_lock); + + ASSERT(array != NULL && item < ss->n_items && array[item] == NULL); + + array[item] = new_element; + + mutex_exit(&ss->lock); return (DDI_SUCCESS); } -static void -ddi_soft_state_free_locked(struct ddi_soft_state *ss, int item) + +/* + * Fetch a pointer to the allocated soft state structure. + * + * This is designed to be cheap. + * + * There's an argument that there should be more checking for + * nil pointers and out of bounds on the array.. but we do a lot + * of that in the alloc/free routines. + * + * An array has the convenience that we don't need to lock read-access + * to it c.f. a linked list. However our "expanding array" strategy + * means that we should hold a readers lock on the i_ddi_soft_state + * structure. + * + * However, from a performance viewpoint, we need to do it without + * any locks at all -- this also makes it a leaf routine. The algorithm + * is 'lock-free' because we only discard the pointer arrays at + * ddi_soft_state_fini() time. + */ +void * +ddi_get_soft_state(void *state, int item) { - struct ddi_soft_state_item *itemp; + struct i_ddi_soft_state *ss = state; - ASSERT(MUTEX_HELD(&ss->ss_lock)); + ASSERT(ss != NULL && item >= 0); - LIST_FOREACH(itemp, &ss->ss_list, ssi_next) { - if (itemp->ssi_item == item) - break; + if (item < ss->n_items && ss->array != NULL) + return (ss->array[item]); + return (NULL); +} + +/* + * Free the state structure corresponding to 'item.' Freeing an + * element that has either gone or was never allocated is not + * considered an error. Note that we free the state structure, but + * we don't shrink our pointer array, or discard 'dirty' arrays, + * since even a few pointers don't really waste too much memory. + * + * Passing an item number that is out of bounds, or a null pointer will + * provoke an error message. + */ +void +ddi_soft_state_free(void *state, int item) +{ + struct i_ddi_soft_state *ss; + void **array; + void *element; + static char msg[] = "ddi_soft_state_free:"; + + if ((ss = state) == NULL) { + cmn_err(CE_WARN, "%s null handle", + msg); + return; } - if (itemp != NULL) { - LIST_REMOVE(itemp, ssi_next); - kmem_free(itemp->ssi_data, ss->ss_size); - kmem_free(itemp, sizeof(*itemp)); + + element = NULL; + + mutex_enter(&ss->lock); + + if ((array = ss->array) == NULL || ss->size == 0) { + cmn_err(CE_WARN, "%s bad handle", + msg); + } else if (item < 0 || item >= ss->n_items) { + cmn_err(CE_WARN, "%s item %d not in range [0..%lu]", + msg, item, ss->n_items - 1); + } else if (array[item] != NULL) { + element = array[item]; + array[item] = NULL; } + + mutex_exit(&ss->lock); + + if (element) + kmem_free(element, ss->size); } + +/* + * Free the entire set of pointers, and any + * soft state structures contained therein. + * + * Note that we don't grab the ss->lock mutex, even though + * we're inspecting the various fields of the data structure. + * + * There is an implicit assumption that this routine will + * never run concurrently with any of the above on this + * particular state structure i.e. by the time the driver + * calls this routine, there should be no other threads + * running in the driver. + */ void -ddi_soft_state_free(void *state, int item) +ddi_soft_state_fini(void **state_p) { - struct ddi_soft_state *ss = state; + struct i_ddi_soft_state *ss, *dirty; + int item; + static char msg[] = "ddi_soft_state_fini:"; + + if (state_p == NULL || (ss = *state_p) == NULL) { + cmn_err(CE_WARN, "%s null handle", + msg); + return; + } - mutex_enter(&ss->ss_lock); - ddi_soft_state_free_locked(ss, item); - mutex_exit(&ss->ss_lock); + if (ss->size == 0) { + cmn_err(CE_WARN, "%s bad handle", + msg); + return; + } + + if (ss->n_items > 0) { + for (item = 0; item < ss->n_items; item++) + ddi_soft_state_free(ss, item); + kmem_free(ss->array, ss->n_items * sizeof (void *)); + } + + /* + * Now delete any dirty arrays from previous 'grow' operations + */ + for (dirty = ss->next; dirty; dirty = ss->next) { + ss->next = dirty->next; + kmem_free(dirty->array, dirty->n_items * sizeof (void *)); + kmem_free(dirty, sizeof (*dirty)); + } + + mutex_destroy(&ss->lock); + kmem_free(ss, sizeof (*ss)); + + *state_p = NULL; } int -ddi_soft_state_init(void **statep, size_t size, size_t nitems __unused) +ddi_create_minor_node(dev_info_t *dip, char *name, int spec_type, + minor_t minor_num, char *node_type, int flag) { - struct ddi_soft_state *ss; - - ss = kmem_alloc(sizeof(*ss), KM_SLEEP); - mutex_init(&ss->ss_lock, NULL, MUTEX_DEFAULT, NULL); - ss->ss_size = size; - LIST_INIT(&ss->ss_list); - *statep = ss; - return (0); + struct lwp *l = curlwp; + char *pn; + dev_t dev; + int error; + register_t ret; + + printf("ddi_create_minor_node: name %s\n", name); + + dev = makedev(flag, minor_num); + + pn = PNBUF_GET(); + if (spec_type == S_IFCHR) + snprintf(pn, MAXPATHLEN, "/dev/zvol/rdsk/%s", name); + else + snprintf(pn, MAXPATHLEN, "/dev/zvol/dsk/%s", name); + + if ((error = do_mkdirp(pn)) != 0) + goto exit; + + error = do_sys_mknod(l, (const char *)pn, spec_type, dev, &ret, UIO_SYSSPACE); + +exit: + PNBUF_PUT(pn); + + return error; } void -ddi_soft_state_fini(void **statep) +ddi_remove_minor_node(dev_info_t *dip, char *name) { - struct ddi_soft_state *ss = *statep; - struct ddi_soft_state_item *itemp; - int item; + char *pn; + int error; + + pn = PNBUF_GET(); + snprintf(pn, MAXPATHLEN, "/dev/zvol/dsk/%s", name); + (void)do_sys_unlink(pn, UIO_SYSSPACE); + PNBUF_PUT(pn); + + /* We need to remove raw and block device nodes */ + pn = PNBUF_GET(); + snprintf(pn, MAXPATHLEN, "/dev/zvol/rdsk/%s", name); + (void)do_sys_unlink(pn, UIO_SYSSPACE); + PNBUF_PUT(pn); +} + +#if 0 +clock_t +ddi_get_lbolt() +{ + + return hardclock_ticks; +} - mutex_enter(&ss->ss_lock); - while ((itemp = LIST_FIRST(&ss->ss_list)) != NULL) { - item = itemp->ssi_item; - ddi_soft_state_free_locked(ss, item); - } - mutex_exit(&ss->ss_lock); - mutex_destroy(&ss->ss_lock); - kmem_free(ss, sizeof(*ss)); +int64_t +ddi_get_lbolt64() +{ - *statep = NULL; + return hardclock_ticks; } +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/kern/fm.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/fm.c --- /tmp/out/external/cddl/osnet/sys/kern/fm.c 2015-02-03 23:24:18.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/fm.c 2017-05-06 17:34:49.000000000 -0700 @@ -19,7 +19,8 @@ * CDDL HEADER END */ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ /* @@ -52,20 +53,18 @@ */ #include +#include #include +#include +#include #include #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include @@ -79,11 +78,7 @@ static const char *fm_msgid = "SUNOS-8000-0G"; static char *volatile fm_panicstr = NULL; -#ifdef illumos errorq_t *ereport_errorq; -#endif -void *ereport_dumpbuf; -size_t ereport_dumplen; static uint_t ereport_chanlen = ERPT_EVCH_MAX; static evchan_t *ereport_chan = NULL; @@ -91,86 +86,6 @@ static size_t ereport_size = 0; static int ereport_cols = 80; -extern void fastreboot_disable_highpil(void); - -/* - * Common fault management kstats to record ereport generation - * failures - */ - -struct erpt_kstat { - kstat_named_t erpt_dropped; /* num erpts dropped on post */ - kstat_named_t erpt_set_failed; /* num erpt set failures */ - kstat_named_t fmri_set_failed; /* num fmri set failures */ - kstat_named_t payload_set_failed; /* num payload set failures */ -}; - -static struct erpt_kstat erpt_kstat_data = { - { "erpt-dropped", KSTAT_DATA_UINT64 }, - { "erpt-set-failed", KSTAT_DATA_UINT64 }, - { "fmri-set-failed", KSTAT_DATA_UINT64 }, - { "payload-set-failed", KSTAT_DATA_UINT64 } -}; - -#ifdef illumos -/*ARGSUSED*/ -static void -fm_drain(void *private, void *data, errorq_elem_t *eep) -{ - nvlist_t *nvl = errorq_elem_nvl(ereport_errorq, eep); - - if (!panicstr) - (void) fm_ereport_post(nvl, EVCH_TRYHARD); - else - fm_nvprint(nvl); -} -#endif - -void -fm_init(void) -{ - kstat_t *ksp; - -#ifdef illumos - (void) sysevent_evc_bind(FM_ERROR_CHAN, - &ereport_chan, EVCH_CREAT | EVCH_HOLD_PEND); - - (void) sysevent_evc_control(ereport_chan, - EVCH_SET_CHAN_LEN, &ereport_chanlen); -#endif - - if (ereport_qlen == 0) - ereport_qlen = ERPT_MAX_ERRS * MAX(max_ncpus, 4); - - if (ereport_size == 0) - ereport_size = ERPT_DATA_SZ; - -#ifdef illumos - ereport_errorq = errorq_nvcreate("fm_ereport_queue", - (errorq_func_t)fm_drain, NULL, ereport_qlen, ereport_size, - FM_ERR_PIL, ERRORQ_VITAL); - if (ereport_errorq == NULL) - panic("failed to create required ereport error queue"); -#endif - - ereport_dumpbuf = kmem_alloc(ereport_size, KM_SLEEP); - ereport_dumplen = ereport_size; - - /* Initialize ereport allocation and generation kstats */ - ksp = kstat_create("unix", 0, "fm", "misc", KSTAT_TYPE_NAMED, - sizeof (struct erpt_kstat) / sizeof (kstat_named_t), - KSTAT_FLAG_VIRTUAL); - - if (ksp != NULL) { - ksp->ks_data = &erpt_kstat_data; - kstat_install(ksp); - } else { - cmn_err(CE_NOTE, "failed to create fm/misc kstat\n"); - - } -} - -#ifdef illumos /* * Formatting utility function for fm_nvprintr. We attempt to wrap chunks of * output so they aren't split across console lines, and return the end column. @@ -182,22 +97,22 @@ va_list ap; int width; char c1; - + return 0; va_start(ap, format); width = vsnprintf(&c1, sizeof (c1), format, ap); va_end(ap); if (c + width >= cols) { - console_printf("\n\r"); + printf("\n\r"); c = 0; if (format[0] != ' ' && depth > 0) { - console_printf(" "); + printf(" "); c++; } } va_start(ap, format); - console_vprintf(format, ap); + vprintf(format, ap); va_end(ap); return ((c + width) % cols); @@ -355,15 +270,15 @@ char *class; int c = 0; - console_printf("\r"); + printf("\r"); if (nvlist_lookup_string(nvl, FM_CLASS, &class) == 0) c = fm_printf(0, c, ereport_cols, "%s", class); if (fm_nvprintr(nvl, 0, c, ereport_cols) != 0) - console_printf("\n"); + printf("\n"); - console_printf("\n"); + printf("\n"); } /* @@ -380,135 +295,58 @@ va_list ap; (void) atomic_cas_ptr((void *)&fm_panicstr, NULL, (void *)format); -#if defined(__i386) || defined(__amd64) - fastreboot_disable_highpil(); -#endif /* __i386 || __amd64 */ va_start(ap, format); - vpanic(format, ap); + vcmn_err(CE_PANIC, format, ap); va_end(ap); } /* - * Simply tell the caller if fm_panicstr is set, ie. an fma event has - * caused the panic. If so, something other than the default panic - * diagnosis method will diagnose the cause of the panic. - */ -int -is_fm_panic() -{ - if (fm_panicstr) - return (1); - else - return (0); -} - -/* * Print any appropriate FMA banner message before the panic message. This * function is called by panicsys() and prints the message for fm_panic(). * We print the message here so that it comes after the system is quiesced. * A one-line summary is recorded in the log only (cmn_err(9F) with "!" prefix). * The rest of the message is for the console only and not needed in the log, - * so it is printed using console_printf(). We break it up into multiple + * so it is printed using printf(). We break it up into multiple * chunks so as to avoid overflowing any small legacy prom_printf() buffers. */ void fm_banner(void) { - timespec_t tod; + struct timespec tod; hrtime_t now; if (!fm_panicstr) return; /* panic was not initiated by fm_panic(); do nothing */ - if (panicstr) { - tod = panic_hrestime; - now = panic_hrtime; - } else { - gethrestime(&tod); - now = gethrtime_waitfree(); - } + getnanotime(&tod); + now = hardclock_ticks; cmn_err(CE_NOTE, "!SUNW-MSG-ID: %s, " "TYPE: Error, VER: 1, SEVERITY: Major\n", fm_msgid); - console_printf( + printf( "\n\rSUNW-MSG-ID: %s, TYPE: Error, VER: 1, SEVERITY: Major\n" "EVENT-TIME: 0x%lx.0x%lx (0x%llx)\n", fm_msgid, tod.tv_sec, tod.tv_nsec, (u_longlong_t)now); - console_printf( + printf( "PLATFORM: %s, CSN: -, HOSTNAME: %s\n" -"SOURCE: %s, REV: %s %s\n", - platform, utsname.nodename, utsname.sysname, - utsname.release, utsname.version); +"SOURCE: %s, REV: %s\n", + machine, hostname, "NetBSD", + osrelease); - console_printf( + printf( "DESC: Errors have been detected that require a reboot to ensure system\n" "integrity. See %s/%s for more information.\n", fm_url, fm_msgid); - console_printf( -"AUTO-RESPONSE: Solaris will attempt to save and diagnose the error telemetry\n" + printf( +"AUTO-RESPONSE: NetBSD will not attempt to save and diagnose the error telemetry\n" "IMPACT: The system will sync files, save a crash dump if needed, and reboot\n" -"REC-ACTION: Save the error summary below in case telemetry cannot be saved\n"); - - console_printf("\n"); -} - -/* - * Utility function to write all of the pending ereports to the dump device. - * This function is called at either normal reboot or panic time, and simply - * iterates over the in-transit messages in the ereport sysevent channel. - */ -void -fm_ereport_dump(void) -{ - evchanq_t *chq; - sysevent_t *sep; - erpt_dump_t ed; - - timespec_t tod; - hrtime_t now; - char *buf; - size_t len; - - if (panicstr) { - tod = panic_hrestime; - now = panic_hrtime; - } else { - if (ereport_errorq != NULL) - errorq_drain(ereport_errorq); - gethrestime(&tod); - now = gethrtime_waitfree(); - } - - /* - * In the panic case, sysevent_evc_walk_init() will return NULL. - */ - if ((chq = sysevent_evc_walk_init(ereport_chan, NULL)) == NULL && - !panicstr) - return; /* event channel isn't initialized yet */ - - while ((sep = sysevent_evc_walk_step(chq)) != NULL) { - if ((buf = sysevent_evc_event_attr(sep, &len)) == NULL) - break; - - ed.ed_magic = ERPT_MAGIC; - ed.ed_chksum = checksum32(buf, len); - ed.ed_size = (uint32_t)len; - ed.ed_pad = 0; - ed.ed_hrt_nsec = SE_TIME(sep); - ed.ed_hrt_base = now; - ed.ed_tod_base.sec = tod.tv_sec; - ed.ed_tod_base.nsec = tod.tv_nsec; - - dumpvp_write(&ed, sizeof (ed)); - dumpvp_write(buf, len); - } +"REC-ACTION: Save the error summary below\n"); - sysevent_evc_walk_fini(chq); + printf("\n"); } -#endif /* * Post an error report (ereport) to the sysevent error channel. The error @@ -520,31 +358,16 @@ { size_t nvl_size = 0; evchan_t *error_chan; - sysevent_id_t eid; +#if 0 (void) nvlist_size(ereport, &nvl_size, NV_ENCODE_NATIVE); if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) { - atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64); - return; - } - -#ifdef illumos - if (sysevent_evc_bind(FM_ERROR_CHAN, &error_chan, - EVCH_CREAT|EVCH_HOLD_PEND) != 0) { - atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64); + printf("fm_ereport_post: dropped report\n"); return; } - if (sysevent_evc_publish(error_chan, EC_FM, ESC_FM_ERROR, - SUNW_VENDOR, FM_PUB, ereport, evc_flag) != 0) { - atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64); - (void) sysevent_evc_unbind(error_chan); - return; - } - (void) sysevent_evc_unbind(error_chan); -#else - (void) ddi_log_sysevent(NULL, SUNW_VENDOR, EC_DEV_STATUS, - ESC_DEV_DLE, ereport, &eid, DDI_SLEEP); + fm_banner(); + fm_nvprint(ereport); #endif } @@ -636,8 +459,8 @@ if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) { if (hdl_alloced) { - nv_alloc_fini(nvhdl); kmem_free(nvhdl, sizeof (nv_alloc_t)); + nv_alloc_fini(nvhdl); } return (NULL); } @@ -803,7 +626,7 @@ va_end(ap); if (ret) - atomic_inc_64(&erpt_kstat_data.payload_set_failed.value.ui64); + printf("fm_payload_set: failed\n"); } /* @@ -817,14 +640,6 @@ * detector nvlist_t * ereport-payload nvlist_t * - * We don't actually add a 'version' member to the payload. Really, - * the version quoted to us by our caller is that of the category 1 - * "ereport" event class (and we require FM_EREPORT_VERS0) but - * the payload version of the actual leaf class event under construction - * may be something else. Callers should supply a version in the varargs, - * or (better) we could take two version arguments - one for the - * ereport category 1 classification (expect FM_EREPORT_VERS0) and one - * for the leaf class. */ void fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class, @@ -836,24 +651,24 @@ int ret; if (version != FM_EREPORT_VERS0) { - atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64); + printf("fm_payload_set: bad version\n"); return; } (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s", FM_EREPORT_CLASS, erpt_class); if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) { - atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64); + printf("fm_payload_set: can't add\n"); return; } if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) { - atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64); + printf("fm_payload_set: can't add\n"); } if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR, (nvlist_t *)detector) != 0) { - atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64); + printf("fm_payload_set: can't add\n"); } va_start(ap, detector); @@ -862,251 +677,7 @@ va_end(ap); if (ret) - atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64); -} - -/* - * Set-up and validate the members of an hc fmri according to; - * - * Member name Type Value - * =================================================== - * version uint8_t 0 - * auth nvlist_t - * hc-name string - * hc-id string - * - * Note that auth and hc-id are optional members. - */ - -#define HC_MAXPAIRS 20 -#define HC_MAXNAMELEN 50 - -static int -fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth) -{ - if (version != FM_HC_SCHEME_VERSION) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return (0); - } - - if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 || - nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return (0); - } - - if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, - (nvlist_t *)auth) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return (0); - } - - return (1); -} - -void -fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth, - nvlist_t *snvl, int npairs, ...) -{ - nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); - nvlist_t *pairs[HC_MAXPAIRS]; - va_list ap; - int i; - - if (!fm_fmri_hc_set_common(fmri, version, auth)) - return; - - npairs = MIN(npairs, HC_MAXPAIRS); - - va_start(ap, npairs); - for (i = 0; i < npairs; i++) { - const char *name = va_arg(ap, const char *); - uint32_t id = va_arg(ap, uint32_t); - char idstr[11]; - - (void) snprintf(idstr, sizeof (idstr), "%u", id); - - pairs[i] = fm_nvlist_create(nva); - if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || - nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - } - } - va_end(ap); - - if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0) - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - - for (i = 0; i < npairs; i++) - fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); - - if (snvl != NULL) { - if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - } - } -} - -/* - * Set-up and validate the members of an dev fmri according to: - * - * Member name Type Value - * ==================================================== - * version uint8_t 0 - * auth nvlist_t - * devpath string - * [devid] string - * [target-port-l0id] string - * - * Note that auth and devid are optional members. - */ -void -fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth, - const char *devpath, const char *devid, const char *tpl0) -{ - int err = 0; - - if (version != DEV_SCHEME_VERSION0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - err |= nvlist_add_uint8(fmri_dev, FM_VERSION, version); - err |= nvlist_add_string(fmri_dev, FM_FMRI_SCHEME, FM_FMRI_SCHEME_DEV); - - if (auth != NULL) { - err |= nvlist_add_nvlist(fmri_dev, FM_FMRI_AUTHORITY, - (nvlist_t *)auth); - } - - err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_PATH, devpath); - - if (devid != NULL) - err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_ID, devid); - - if (tpl0 != NULL) - err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_TGTPTLUN0, tpl0); - - if (err) - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - -} - -/* - * Set-up and validate the members of an cpu fmri according to: - * - * Member name Type Value - * ==================================================== - * version uint8_t 0 - * auth nvlist_t - * cpuid uint32_t - * cpumask uint8_t - * serial uint64_t - * - * Note that auth, cpumask, serial are optional members. - * - */ -void -fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth, - uint32_t cpu_id, uint8_t *cpu_maskp, const char *serial_idp) -{ - uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64; - - if (version < CPU_SCHEME_VERSION1) { - atomic_inc_64(failedp); - return; - } - - if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) { - atomic_inc_64(failedp); - return; - } - - if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME, - FM_FMRI_SCHEME_CPU) != 0) { - atomic_inc_64(failedp); - return; - } - - if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY, - (nvlist_t *)auth) != 0) - atomic_inc_64(failedp); - - if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0) - atomic_inc_64(failedp); - - if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK, - *cpu_maskp) != 0) - atomic_inc_64(failedp); - - if (serial_idp == NULL || nvlist_add_string(fmri_cpu, - FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0) - atomic_inc_64(failedp); -} - -/* - * Set-up and validate the members of a mem according to: - * - * Member name Type Value - * ==================================================== - * version uint8_t 0 - * auth nvlist_t [optional] - * unum string - * serial string [optional*] - * offset uint64_t [optional] - * - * * serial is required if offset is present - */ -void -fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth, - const char *unum, const char *serial, uint64_t offset) -{ - if (version != MEM_SCHEME_VERSION0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - if (!serial && (offset != (uint64_t)-1)) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - if (auth != NULL) { - if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, - (nvlist_t *)auth) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - } - } - - if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - } - - if (serial != NULL) { - if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID, - (char **)&serial, 1) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - } - if (offset != (uint64_t)-1 && nvlist_add_uint64(fmri, - FM_FMRI_MEM_OFFSET, offset) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - } - } + printf("fm_payload_set: can't add\n"); } void @@ -1114,28 +685,27 @@ uint64_t vdev_guid) { if (version != ZFS_SCHEME_VERSION0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); + printf("fm_fmri_zfs_set: bad version\n"); return; } if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); + printf("fm_fmri_zfs_set: can't set\n"); return; } if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_ZFS) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); + printf("fm_fmri_zfs_set: can't set\n"); return; } if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_POOL, pool_guid) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); + printf("fm_fmri_zfs_set: can't set\n"); } if (vdev_guid != 0) { if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_VDEV, vdev_guid) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); + printf("fm_fmri_zfs_set: can't set\n"); } } } @@ -1176,7 +746,7 @@ ena = (uint64_t)((format & ENA_FORMAT_MASK) | ((cpuid << ENA_FMT1_CPUID_SHFT) & ENA_FMT1_CPUID_MASK) | - ((gethrtime_waitfree() << ENA_FMT1_TIME_SHFT) & + ((hardclock_ticks << ENA_FMT1_TIME_SHFT) & ENA_FMT1_TIME_MASK)); } break; @@ -1194,7 +764,7 @@ uint64_t fm_ena_generate(uint64_t timestamp, uchar_t format) { - return (fm_ena_generate_cpu(timestamp, PCPU_GET(cpuid), format)); + return (fm_ena_generate_cpu(timestamp, cpu_index(curcpu()), format)); } uint64_t @@ -1261,139 +831,3 @@ return (time); } - -#ifdef illumos -/* - * Convert a getpcstack() trace to symbolic name+offset, and add the resulting - * string array to a Fault Management ereport as FM_EREPORT_PAYLOAD_NAME_STACK. - */ -void -fm_payload_stack_add(nvlist_t *payload, const pc_t *stack, int depth) -{ - int i; - char *sym; - ulong_t off; - char *stkpp[FM_STK_DEPTH]; - char buf[FM_STK_DEPTH * FM_SYM_SZ]; - char *stkp = buf; - - for (i = 0; i < depth && i != FM_STK_DEPTH; i++, stkp += FM_SYM_SZ) { - if ((sym = kobj_getsymname(stack[i], &off)) != NULL) - (void) snprintf(stkp, FM_SYM_SZ, "%s+%lx", sym, off); - else - (void) snprintf(stkp, FM_SYM_SZ, "%lx", (long)stack[i]); - stkpp[i] = stkp; - } - - fm_payload_set(payload, FM_EREPORT_PAYLOAD_NAME_STACK, - DATA_TYPE_STRING_ARRAY, depth, stkpp, NULL); -} -#endif - -#ifdef illumos -void -print_msg_hwerr(ctid_t ct_id, proc_t *p) -{ - uprintf("Killed process %d (%s) in contract id %d " - "due to hardware error\n", p->p_pid, p->p_user.u_comm, ct_id); -} -#endif - -void -fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth, - nvlist_t *snvl, nvlist_t *bboard, int npairs, ...) -{ - nv_alloc_t *nva = nvlist_lookup_nv_alloc(fmri); - nvlist_t *pairs[HC_MAXPAIRS]; - nvlist_t **hcl; - uint_t n; - int i, j; - va_list ap; - char *hcname, *hcid; - - if (!fm_fmri_hc_set_common(fmri, version, auth)) - return; - - /* - * copy the bboard nvpairs to the pairs array - */ - if (nvlist_lookup_nvlist_array(bboard, FM_FMRI_HC_LIST, &hcl, &n) - != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - for (i = 0; i < n; i++) { - if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, - &hcname) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &hcid) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - pairs[i] = fm_nvlist_create(nva); - if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, hcname) != 0 || - nvlist_add_string(pairs[i], FM_FMRI_HC_ID, hcid) != 0) { - for (j = 0; j <= i; j++) { - if (pairs[j] != NULL) - fm_nvlist_destroy(pairs[j], - FM_NVA_RETAIN); - } - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - } - - /* - * create the pairs from passed in pairs - */ - npairs = MIN(npairs, HC_MAXPAIRS); - - va_start(ap, npairs); - for (i = n; i < npairs + n; i++) { - const char *name = va_arg(ap, const char *); - uint32_t id = va_arg(ap, uint32_t); - char idstr[11]; - (void) snprintf(idstr, sizeof (idstr), "%u", id); - pairs[i] = fm_nvlist_create(nva); - if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 || - nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) { - for (j = 0; j <= i; j++) { - if (pairs[j] != NULL) - fm_nvlist_destroy(pairs[j], - FM_NVA_RETAIN); - } - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - } - va_end(ap); - - /* - * Create the fmri hc list - */ - if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, - npairs + n) != 0) { - atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - - for (i = 0; i < npairs + n; i++) { - fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN); - } - - if (snvl != NULL) { - if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) { - atomic_inc_64( - &erpt_kstat_data.fmri_set_failed.value.ui64); - return; - } - } -} Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: kmem.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: kobj.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: kstat.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: misc.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: mod.c diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/kern/opensolaris.c /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/opensolaris.c --- /tmp/out/external/cddl/osnet/sys/kern/opensolaris.c 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern/opensolaris.c 2017-06-09 15:06:31.000000000 -0700 @@ -1,3 +1,4 @@ +/* $NetBSD: opensolaris.c,v 1.1 2010/03/12 21:37:37 darran Exp $ */ /*- * Copyright 2007 John Birrell * @@ -22,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris.c 222670 2011-06-04 07:02:06Z avg $ * */ @@ -31,22 +32,20 @@ #include #include #include -#include +#include #include #include #include #include -cpu_core_t cpu_core[MAXCPU]; -kmutex_t cpu_lock; -solaris_cpu_t solaris_cpu[MAXCPU]; -int nsec_per_tick; +cpu_core_t cpu_core[MAXCPUS]; +solaris_cpu_t solaris_cpu[MAXCPUS]; /* * OpenSolaris subsystem initialisation. */ -static void -opensolaris_load(void *dummy) +void +opensolaris_init(void *dummy) { int i; @@ -55,49 +54,14 @@ * that the asserts work. On FreeBSD, if a CPU exists, it is * enabled. */ - for (i = 0; i < MAXCPU; i++) { + for (i = 0; i < MAXCPUS; i++) { solaris_cpu[i].cpuid = i; solaris_cpu[i].cpu_flags &= CPU_ENABLE; } - mutex_init(&cpu_lock, "OpenSolaris CPU lock", MUTEX_DEFAULT, NULL); - - nsec_per_tick = NANOSEC / hz; -} - -SYSINIT(opensolaris_register, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_load, NULL); - -static void -opensolaris_unload(void) -{ - mutex_destroy(&cpu_lock); } -SYSUNINIT(opensolaris_unregister, SI_SUB_OPENSOLARIS, SI_ORDER_FIRST, opensolaris_unload, NULL); - -static int -opensolaris_modevent(module_t mod __unused, int type, void *data __unused) +void +opensolaris_fini(void *dummy) { - int error = 0; - - switch (type) { - case MOD_LOAD: - utsname.nodename = prison0.pr_hostname; - break; - - case MOD_UNLOAD: - break; - - case MOD_SHUTDOWN: - break; - - default: - error = EOPNOTSUPP; - break; - - } - return (error); } - -DEV_MODULE(opensolaris, opensolaris_modevent, NULL); -MODULE_VERSION(opensolaris, 1); Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: policy.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: printf.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: string.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: sysevent.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: taskq.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: vfs.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: zfs_stub.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/kern: zone.c Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys: machine Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys: sharefs Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: acl diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/acl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/acl.h --- /tmp/out/external/cddl/osnet/sys/sys/acl.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/acl.h 2017-04-26 08:10:34.000000000 -0700 @@ -1,7 +1,10 @@ /*- - * Copyright (c) 2008, 2009 Edward Tomasz Napierała + * Copyright (c) 1999-2001 Robert N. M. Watson + * Copyright (c) 2008 Edward Tomasz Napierała * All rights reserved. * + * This software was developed by Robert Watson for the TrustedBSD Project. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -23,17 +26,406 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/sys/acl.h 287445 2015-09-04 00:14:20Z delphij $ + */ +/* + * Developed by the TrustedBSD Project. + * Support for POSIX.1e and NFSv4 access control lists. */ -#ifndef OPENSOLARIS_SYS_ACL_H -#define OPENSOLARIS_SYS_ACL_H +#ifndef _FREEBSD_SYS_ACL_H_ +#define _FREEBSD_SYS_ACL_H_ +/* + * This file contains the FreeBSD native . + * In FreeBSD, this file is a wrapper which pulls in osnet one + * and that one pulls in the FreeBSD native one for the kernel. + * But since NetBSD has no native ACLs yet, the contents are + * swapped around for now. + */ #include_next -struct acl; +#ifdef _KERNEL + +#include +#include + +/* + * POSIX.1e and NFSv4 ACL types and related constants. + */ + +typedef uint32_t acl_tag_t; +typedef uint32_t acl_perm_t; +typedef uint16_t acl_entry_type_t; +typedef uint16_t acl_flag_t; +typedef int acl_type_t; +typedef int *acl_permset_t; +typedef uint16_t *acl_flagset_t; + +/* + * With 254 entries, "struct acl_t_struct" is exactly one 4kB page big. + * Note that with NFSv4 ACLs, the maximum number of ACL entries one + * may set on file or directory is about half of ACL_MAX_ENTRIES. + * + * If you increase this, you might also need to increase + * _ACL_T_ALIGNMENT_BITS in lib/libc/posix1e/acl_support.h. + * + * The maximum number of POSIX.1e ACLs is controlled + * by OLDACL_MAX_ENTRIES. Changing that one will break binary + * compatibility with pre-8.0 userland and change on-disk ACL layout. + */ +#define ACL_MAX_ENTRIES 254 + +#if defined(_KERNEL) || defined(_ACL_PRIVATE) + +#define POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_ACCESS_EXTATTR_NAME "posix1e.acl_access" +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAME "posix1e.acl_default" +#define NFS4_ACL_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define NFS4_ACL_EXTATTR_NAME "nfs4.acl" +#define OLDACL_MAX_ENTRIES 32 + +/* + * "struct oldacl" is used in compatibility ACL syscalls and for on-disk + * storage of POSIX.1e ACLs. + */ +typedef int oldacl_tag_t; +typedef mode_t oldacl_perm_t; + +struct oldacl_entry { + oldacl_tag_t ae_tag; + uid_t ae_id; + oldacl_perm_t ae_perm; +}; +typedef struct oldacl_entry *oldacl_entry_t; + +struct oldacl { + int acl_cnt; + struct oldacl_entry acl_entry[OLDACL_MAX_ENTRIES]; +}; + +/* + * Current "struct acl". + */ +struct acl_entry { + acl_tag_t ae_tag; + uid_t ae_id; + acl_perm_t ae_perm; + /* NFSv4 entry type, "allow" or "deny". Unused in POSIX.1e ACLs. */ + acl_entry_type_t ae_entry_type; + /* NFSv4 ACL inheritance. Unused in POSIX.1e ACLs. */ + acl_flag_t ae_flags; +}; +typedef struct acl_entry *acl_entry_t; + +/* + * Internal ACL structure, used in libc, kernel APIs and for on-disk + * storage of NFSv4 ACLs. POSIX.1e ACLs use "struct oldacl" for on-disk + * storage. + */ +struct acl { + unsigned int acl_maxcnt; + unsigned int acl_cnt; + /* Will be required e.g. to implement NFSv4.1 ACL inheritance. */ + int acl_spare[4]; + struct acl_entry acl_entry[ACL_MAX_ENTRIES]; +}; + +/* + * ACL structure internal to libc. + */ +struct acl_t_struct { + struct acl ats_acl; + int ats_cur_entry; + /* + * ats_brand is for libc internal bookkeeping only. + * Applications should use acl_get_brand_np(3). + * Kernel code should use the "type" argument passed + * to VOP_SETACL, VOP_GETACL or VOP_ACLCHECK calls; + * ACL_TYPE_ACCESS or ACL_TYPE_DEFAULT mean POSIX.1e + * ACL, ACL_TYPE_NFS4 means NFSv4 ACL. + */ + int ats_brand; +}; +typedef struct acl_t_struct *acl_t; + +#else /* _KERNEL || _ACL_PRIVATE */ + +typedef void *acl_entry_t; +typedef void *acl_t; + +#endif /* !_KERNEL && !_ACL_PRIVATE */ + +/* + * Possible valid values for ats_brand field. + */ +#define ACL_BRAND_UNKNOWN 0 +#define ACL_BRAND_POSIX 1 +#define ACL_BRAND_NFS4 2 + +/* + * Possible valid values for ae_tag field. For explanation, see acl(9). + */ +#define ACL_UNDEFINED_TAG 0x00000000 +#define ACL_USER_OBJ 0x00000001 +#define ACL_USER 0x00000002 +#define ACL_GROUP_OBJ 0x00000004 +#define ACL_GROUP 0x00000008 +#define ACL_MASK 0x00000010 +#define ACL_OTHER 0x00000020 +#define ACL_OTHER_OBJ ACL_OTHER +#define ACL_EVERYONE 0x00000040 + +/* + * Possible valid values for ae_entry_type field, valid only for NFSv4 ACLs. + */ +#define ACL_ENTRY_TYPE_ALLOW 0x0100 +#define ACL_ENTRY_TYPE_DENY 0x0200 +#define ACL_ENTRY_TYPE_AUDIT 0x0400 +#define ACL_ENTRY_TYPE_ALARM 0x0800 + +/* + * Possible valid values for acl_type_t arguments. First two + * are provided only for backwards binary compatibility. + */ +#define ACL_TYPE_ACCESS_OLD 0x00000000 +#define ACL_TYPE_DEFAULT_OLD 0x00000001 +#define ACL_TYPE_ACCESS 0x00000002 +#define ACL_TYPE_DEFAULT 0x00000003 +#define ACL_TYPE_NFS4 0x00000004 + +/* + * Possible bits in ae_perm field for POSIX.1e ACLs. Note + * that ACL_EXECUTE may be used in both NFSv4 and POSIX.1e ACLs. + */ +#define ACL_EXECUTE 0x0001 +#define ACL_WRITE 0x0002 +#define ACL_READ 0x0004 +#define ACL_PERM_NONE 0x0000 +#define ACL_PERM_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) +#define ACL_POSIX1E_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) + +/* + * Possible bits in ae_perm field for NFSv4 ACLs. + */ +#define ACL_READ_DATA 0x00000008 +#define ACL_LIST_DIRECTORY 0x00000008 +#define ACL_WRITE_DATA 0x00000010 +#define ACL_ADD_FILE 0x00000010 +#define ACL_APPEND_DATA 0x00000020 +#define ACL_ADD_SUBDIRECTORY 0x00000020 +#define ACL_READ_NAMED_ATTRS 0x00000040 +#define ACL_WRITE_NAMED_ATTRS 0x00000080 +/* ACL_EXECUTE is defined above. */ +#define ACL_DELETE_CHILD 0x00000100 +#define ACL_READ_ATTRIBUTES 0x00000200 +#define ACL_WRITE_ATTRIBUTES 0x00000400 +#define ACL_DELETE 0x00000800 +#define ACL_READ_ACL 0x00001000 +#define ACL_WRITE_ACL 0x00002000 +#define ACL_WRITE_OWNER 0x00004000 +#define ACL_SYNCHRONIZE 0x00008000 + +#define ACL_FULL_SET (ACL_READ_DATA | ACL_WRITE_DATA | \ + ACL_APPEND_DATA | ACL_READ_NAMED_ATTRS | ACL_WRITE_NAMED_ATTRS | \ + ACL_EXECUTE | ACL_DELETE_CHILD | ACL_READ_ATTRIBUTES | \ + ACL_WRITE_ATTRIBUTES | ACL_DELETE | ACL_READ_ACL | ACL_WRITE_ACL | \ + ACL_WRITE_OWNER | ACL_SYNCHRONIZE) + +#define ACL_MODIFY_SET (ACL_FULL_SET & \ + ~(ACL_WRITE_ACL | ACL_WRITE_OWNER)) + +#define ACL_READ_SET (ACL_READ_DATA | ACL_READ_NAMED_ATTRS | \ + ACL_READ_ATTRIBUTES | ACL_READ_ACL) + +#define ACL_WRITE_SET (ACL_WRITE_DATA | ACL_APPEND_DATA | \ + ACL_WRITE_NAMED_ATTRS | ACL_WRITE_ATTRIBUTES) + +#define ACL_NFS4_PERM_BITS ACL_FULL_SET + +/* + * Possible entry_id values for acl_get_entry(3). + */ +#define ACL_FIRST_ENTRY 0 +#define ACL_NEXT_ENTRY 1 + +/* + * Possible values in ae_flags field; valid only for NFSv4 ACLs. + */ +#define ACL_ENTRY_FILE_INHERIT 0x0001 +#define ACL_ENTRY_DIRECTORY_INHERIT 0x0002 +#define ACL_ENTRY_NO_PROPAGATE_INHERIT 0x0004 +#define ACL_ENTRY_INHERIT_ONLY 0x0008 +#define ACL_ENTRY_SUCCESSFUL_ACCESS 0x0010 +#define ACL_ENTRY_FAILED_ACCESS 0x0020 +#define ACL_ENTRY_INHERITED 0x0080 + +#define ACL_FLAGS_BITS (ACL_ENTRY_FILE_INHERIT | \ + ACL_ENTRY_DIRECTORY_INHERIT | ACL_ENTRY_NO_PROPAGATE_INHERIT | \ + ACL_ENTRY_INHERIT_ONLY | ACL_ENTRY_SUCCESSFUL_ACCESS | \ + ACL_ENTRY_FAILED_ACCESS | ACL_ENTRY_INHERITED) + +/* + * Undefined value in ae_id field. ae_id should be set to this value + * iff ae_tag is ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER or ACL_EVERYONE. + */ +#define ACL_UNDEFINED_ID ((uid_t)-1) + +/* + * Possible values for _flags parameter in acl_to_text_np(3). + */ +#define ACL_TEXT_VERBOSE 0x01 +#define ACL_TEXT_NUMERIC_IDS 0x02 +#define ACL_TEXT_APPEND_ID 0x04 + +/* + * POSIX.1e ACLs are capable of expressing the read, write, and execute bits + * of the POSIX mode field. We provide two masks: one that defines the bits + * the ACL will replace in the mode, and the other that defines the bits that + * must be preseved when an ACL is updating a mode. + */ +#define ACL_OVERRIDE_MASK (S_IRWXU | S_IRWXG | S_IRWXO) +#define ACL_PRESERVE_MASK (~ACL_OVERRIDE_MASK) + +#ifdef _KERNEL + +/* + * Filesystem-independent code to move back and forth between POSIX mode and + * POSIX.1e ACL representations. + */ +acl_perm_t acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode); +struct acl_entry acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, + gid_t gid, mode_t mode); +mode_t acl_posix1e_perms_to_mode( + struct acl_entry *acl_user_obj_entry, + struct acl_entry *acl_group_obj_entry, + struct acl_entry *acl_other_entry); +mode_t acl_posix1e_acl_to_mode(struct acl *acl); +mode_t acl_posix1e_newfilemode(mode_t cmode, + struct acl *dacl); +struct acl *acl_alloc(int flags); +void acl_free(struct acl *aclp); + +void acl_nfs4_sync_acl_from_mode(struct acl *aclp, + mode_t mode, int file_owner_id); +void acl_nfs4_sync_mode_from_acl(mode_t *mode, + const struct acl *aclp); +int acl_nfs4_is_trivial(const struct acl *aclp, + int file_owner_id); +void acl_nfs4_compute_inherited_acl( + const struct acl *parent_aclp, + struct acl *child_aclp, mode_t mode, + int file_owner_id, int is_directory); +int acl_copy_oldacl_into_acl(const struct oldacl *source, + struct acl *dest); +int acl_copy_acl_into_oldacl(const struct acl *source, + struct oldacl *dest); + +#if 0 +/* + * To allocate 'struct acl', use acl_alloc()/acl_free() instead of this. + */ +MALLOC_DECLARE(M_ACL); +#endif +/* + * Filesystem-independent syntax check for a POSIX.1e ACL. + */ +int acl_posix1e_check(struct acl *acl); +int acl_nfs4_check(const struct acl *aclp, int is_directory); + +#else /* !_KERNEL */ + +#if defined(_ACL_PRIVATE) + +/* + * Syscall interface -- use the library calls instead as the syscalls have + * strict ACL entry ordering requirements. + */ +__BEGIN_DECLS +int __acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_aclcheck_file(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_aclcheck_link(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_delete_fd(int _filedes, acl_type_t _type); +int __acl_delete_file(const char *_path_p, acl_type_t _type); +int __acl_delete_link(const char *_path_p, acl_type_t _type); +int __acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_get_link(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_link(const char *_path, acl_type_t _type, struct acl *_aclp); +__END_DECLS + +#endif /* _ACL_PRIVATE */ + +/* + * Supported POSIX.1e ACL manipulation and assignment/retrieval API _np calls + * are local extensions that reflect an environment capable of opening file + * descriptors of directories, and allowing additional ACL type for different + * filesystems (i.e., AFS). + */ +__BEGIN_DECLS +int acl_add_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_calc_mask(acl_t *_acl_p); +int acl_clear_flags_np(acl_flagset_t _flagset_d); +int acl_clear_perms(acl_permset_t _permset_d); +int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d); +ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size); +acl_t acl_copy_int(const void *_buf_p); +int acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p); +int acl_create_entry_np(acl_t *_acl_p, acl_entry_t *_entry_p, int _index); +int acl_delete_entry(acl_t _acl, acl_entry_t _entry_d); +int acl_delete_entry_np(acl_t _acl, int _index); +int acl_delete_fd_np(int _filedes, acl_type_t _type); +int acl_delete_file_np(const char *_path_p, acl_type_t _type); +int acl_delete_link_np(const char *_path_p, acl_type_t _type); +int acl_delete_def_file(const char *_path_p); +int acl_delete_def_link_np(const char *_path_p); +int acl_delete_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm); +acl_t acl_dup(acl_t _acl); +int acl_free(void *_obj_p); +acl_t acl_from_text(const char *_buf_p); +int acl_get_brand_np(acl_t _acl, int *_brand_p); +int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p); +acl_t acl_get_fd(int _fd); +acl_t acl_get_fd_np(int fd, acl_type_t _type); +acl_t acl_get_file(const char *_path_p, acl_type_t _type); +int acl_get_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t *_entry_type_p); +acl_t acl_get_link_np(const char *_path_p, acl_type_t _type); +void *acl_get_qualifier(acl_entry_t _entry_d); +int acl_get_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); +int acl_get_perm_np(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_get_flagset_np(acl_entry_t _entry_d, acl_flagset_t *_flagset_p); +int acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p); +int acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p); +acl_t acl_init(int _count); +int acl_set_fd(int _fd, acl_t _acl); +int acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type); +int acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t _entry_type); +int acl_set_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_flagset_np(acl_entry_t _entry_d, acl_flagset_t _flagset_d); +int acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d); +int acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p); +int acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type); +ssize_t acl_size(acl_t _acl); +char *acl_to_text(acl_t _acl, ssize_t *_len_p); +char *acl_to_text_np(acl_t _acl, ssize_t *_len_p, int _flags); +int acl_valid(acl_t _acl); +int acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl); +int acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_valid_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_is_trivial_np(const acl_t _acl, int *_trivialp); +acl_t acl_strip_np(const acl_t _acl, int recalculate_mask); +__END_DECLS + +#endif /* !_KERNEL */ -void aces_from_acl(ace_t *aces, int *nentries, const struct acl *aclp); -int acl_from_aces(struct acl *aclp, const ace_t *aces, int nentries); +#endif /* _KERNEL */ -#endif /* OPENSOLARIS_SYS_ACL_H */ +#endif /* !_FREEBSD_SYS_ACL_H_ */ Only in /tmp/out/external/cddl/osnet/sys/sys: assfail.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/atomic.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/atomic.h --- /tmp/out/external/cddl/osnet/sys/sys/atomic.h 2017-01-20 03:40:18.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/atomic.h 2010-02-20 17:46:35.000000000 -0800 @@ -1,7 +1,12 @@ +/* $NetBSD: atomic.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /*- - * Copyright (c) 2007 Pawel Jakub Dawidek + * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,132 +16,69 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/atomic.h 311170 2017-01-03 21:02:30Z mjg $ + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _OPENSOLARIS_SYS_ATOMIC_H_ -#define _OPENSOLARIS_SYS_ATOMIC_H_ +#ifndef _CDDL_SYS_ATOMIC_H_ +#define _CDDL_SYS_ATOMIC_H_ -#include -#include +#include_next -#define casptr(_a, _b, _c) \ - atomic_cmpset_ptr((volatile uintptr_t *)(_a), (uintptr_t)(_b), (uintptr_t) (_c)) -#define cas32 atomic_cmpset_32 - -#if !defined(__LP64__) && !defined(__mips_n32) && !defined(ARM_HAVE_ATOMIC64) -extern void atomic_add_64(volatile uint64_t *target, int64_t delta); -extern void atomic_dec_64(volatile uint64_t *target); -#endif -#ifndef __sparc64__ -extern uint32_t atomic_cas_32(volatile uint32_t *target, uint32_t cmp, - uint32_t newval); -extern uint64_t atomic_cas_64(volatile uint64_t *target, uint64_t cmp, - uint64_t newval); -#endif -extern uint64_t atomic_add_64_nv(volatile uint64_t *target, int64_t delta); -extern uint8_t atomic_or_8_nv(volatile uint8_t *target, uint8_t value); -extern void membar_producer(void); - -#if defined(__sparc64__) || defined(__powerpc__) || defined(__arm__) || \ - defined(__mips__) || defined(__aarch64__) || defined(__riscv__) -extern void atomic_or_8(volatile uint8_t *target, uint8_t value); -#else -static __inline void -atomic_or_8(volatile uint8_t *target, uint8_t value) -{ - atomic_set_8(target, value); -} -#endif +#define casptr(_a, _b, _c) \ + atomic_cas_ptr((volatile uint64_t *) _a, _b, _c); -static __inline uint32_t -atomic_add_32_nv(volatile uint32_t *target, int32_t delta) -{ - return (atomic_fetchadd_32(target, delta) + delta); -} -static __inline u_int -atomic_add_int_nv(volatile u_int *target, int delta) -{ - return (atomic_add_32_nv(target, delta)); -} static __inline void -atomic_dec_32(volatile uint32_t *target) +atomic_or_8(volatile uint8_t *ptr, uint8_t val) { - atomic_subtract_32(target, 1); -} + uint32_t mask; -static __inline uint32_t -atomic_dec_32_nv(volatile uint32_t *target) -{ - return (atomic_fetchadd_32(target, -1) - 1); -} - -#if defined(__LP64__) || defined(__mips_n32) || defined(ARM_HAVE_ATOMIC64) -static __inline void -atomic_dec_64(volatile uint64_t *target) -{ - atomic_subtract_64(target, 1); -} +#if _BYTE_ORDER == _LITTLE_ENDIAN + switch ((uintptr_t)ptr & 3) { + case 0: + mask = (uint32_t)val; + break; + case 1: + mask = (uint32_t)val << 8; + break; + case 2: + mask = (uint32_t)val << 16; + break; + case 3: + mask = (uint32_t)val << 24; + break; + } +#elif _BYTE_ORDER == _BIG_ENDIAN + switch ((uintptr_t)ptr & 3) { + case 3: + mask = (uint32_t)val; + break; + case 2: + mask = (uint32_t)val << 8; + break; + case 1: + mask = (uint32_t)val << 16; + break; + case 0: + mask = (uint32_t)val << 24; + break; + } +#else +#error What byte order? #endif -static __inline void -atomic_inc_32(volatile uint32_t *target) -{ - atomic_add_32(target, 1); -} - -static __inline uint32_t -atomic_inc_32_nv(volatile uint32_t *target) -{ - return (atomic_add_32_nv(target, 1)); -} - -static __inline void -atomic_inc_64(volatile uint64_t *target) -{ - atomic_add_64(target, 1); -} - -static __inline uint64_t -atomic_inc_64_nv(volatile uint64_t *target) -{ - return (atomic_add_64_nv(target, 1)); -} - -static __inline uint64_t -atomic_dec_64_nv(volatile uint64_t *target) -{ - return (atomic_add_64_nv(target, -1)); -} - -#if !defined(COMPAT_32BIT) && defined(__LP64__) -static __inline void * -atomic_cas_ptr(volatile void *target, void *cmp, void *newval) -{ - return ((void *)atomic_cas_64((volatile uint64_t *)target, - (uint64_t)cmp, (uint64_t)newval)); -} -#else -static __inline void * -atomic_cas_ptr(volatile void *target, void *cmp, void *newval) -{ - return ((void *)atomic_cas_32((volatile uint32_t *)target, - (uint32_t)cmp, (uint32_t)newval)); + atomic_or_32((uint32_t *)((uintptr_t)ptr & (uintptr_t)~3ULL), mask); } -#endif /* !defined(COMPAT_32BIT) && defined(__LP64__) */ -#endif /* !_OPENSOLARIS_SYS_ATOMIC_H_ */ +#endif /* _CDDL_SYS_ATOMIC_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/bitmap.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/bitmap.h --- /tmp/out/external/cddl/osnet/sys/sys/bitmap.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/bitmap.h 2010-02-20 17:46:35.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: bitmap.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/byteorder.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/byteorder.h --- /tmp/out/external/cddl/osnet/sys/sys/byteorder.h 2013-02-16 08:40:58.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/byteorder.h 2017-04-22 02:36:25.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: byteorder.h,v 1.4 2010/02/28 14:45:47 haad Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* @@ -42,11 +42,6 @@ #ifndef _OPENSOLARIS_SYS_BYTEORDER_H_ #define _OPENSOLARIS_SYS_BYTEORDER_H_ -/* for htonl() */ -#ifndef _KERNEL -#include -#endif - /* * Macros to reverse byte order */ @@ -64,6 +59,15 @@ * Macros to convert from a specific byte order to/from native byte order */ #if _BYTE_ORDER == _BIG_ENDIAN +#define LE_64(x) BSWAP_64(x) +#else +#define LE_64(x) BMASK_64(x) +#endif + +/* + * Macros to convert from a specific byte order to/from native byte order + */ +#ifdef _BIG_ENDIAN #define BE_8(x) BMASK_8(x) #define BE_16(x) BMASK_16(x) #define BE_32(x) BMASK_32(x) @@ -83,14 +87,6 @@ #define BE_64(x) BSWAP_64(x) #endif -#if _BYTE_ORDER == _BIG_ENDIAN -#define htonll(x) BMASK_64(x) -#define ntohll(x) BMASK_64(x) -#else -#define htonll(x) BSWAP_64(x) -#define ntohll(x) BSWAP_64(x) -#endif - #define BE_IN32(xa) htonl(*((uint32_t *)(void *)(xa))) #endif /* _OPENSOLARIS_SYS_BYTEORDER_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: callb.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: cdefs.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/cmn_err.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cmn_err.h --- /tmp/out/external/cddl/osnet/sys/sys/cmn_err.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cmn_err.h 2017-06-09 17:13:40.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: cmn_err.h,v 1.4 2011/07/17 20:54:33 joerg Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,14 +25,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/cmn_err.h 179202 2008-05-22 08:33:24Z jb $ */ #ifndef _OPENSOLARIS_SYS_CMN_ERR_H_ #define _OPENSOLARIS_SYS_CMN_ERR_H_ #include -#include #ifdef __cplusplus extern "C" { @@ -44,8 +45,8 @@ #define CE_PANIC 3 /* panic */ #define CE_IGNORE 4 /* print nothing */ -void cmn_err(int, const char *, ...); -void vcmn_err(int, const char *, va_list); +void vcmn_err(int, const char *, va_list); +void cmn_err(int, const char *, ...); #ifdef __cplusplus } diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/cpupart.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpupart.h --- /tmp/out/external/cddl/osnet/sys/sys/cpupart.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpupart.h 2010-02-20 17:46:35.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: cpupart.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ /* diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/cpuvar.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpuvar.h --- /tmp/out/external/cddl/osnet/sys/sys/cpuvar.h 2014-12-11 03:55:13.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpuvar.h 2017-04-19 15:39:40.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: cpuvar.h,v 1.7 2010/03/13 22:31:15 christos Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/cpuvar.h 275576 2014-12-07 11:21:41Z avg $ */ /* @@ -29,17 +29,19 @@ #ifndef _COMPAT_OPENSOLARIS_SYS_CPUVAR_H #define _COMPAT_OPENSOLARIS_SYS_CPUVAR_H +#include #include #include #ifdef _KERNEL -struct cyc_cpu; - typedef struct { int cpuid; + struct cyc_cpu *cpu_cyclic; uint32_t cpu_flags; uint_t cpu_intr_actv; + uintptr_t cpu_profile_pc; + uintptr_t cpu_profile_upc; uintptr_t cpu_dtrace_caller; /* DTrace: caller, if any */ hrtime_t cpu_dtrace_chillmark; /* DTrace: chill mark time */ hrtime_t cpu_dtrace_chilled; /* DTrace: total chill time */ @@ -62,8 +64,7 @@ */ #define CPUC_SIZE (sizeof (uint16_t) + sizeof (uintptr_t) + \ sizeof (kmutex_t)) -#define CPUC_SIZE1 roundup(CPUC_SIZE, CPU_CACHE_COHERENCE_SIZE) -#define CPUC_PADSIZE CPUC_SIZE1 - CPUC_SIZE +#define CPUC_PADSIZE CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE typedef struct cpu_core { uint16_t cpuc_dtrace_flags; /* DTrace flags */ @@ -73,11 +74,35 @@ } cpu_core_t; extern cpu_core_t cpu_core[]; - -extern kmutex_t cpu_lock; #endif /* _KERNEL */ /* + * DTrace flags. + */ +#define CPU_DTRACE_NOFAULT 0x0001 /* Don't fault */ +#define CPU_DTRACE_DROP 0x0002 /* Drop this ECB */ +#define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */ +#define CPU_DTRACE_BADALIGN 0x0008 /* DTrace fault: bad alignment */ +#define CPU_DTRACE_DIVZERO 0x0010 /* DTrace fault: divide by zero */ +#define CPU_DTRACE_ILLOP 0x0020 /* DTrace fault: illegal operation */ +#define CPU_DTRACE_NOSCRATCH 0x0040 /* DTrace fault: out of scratch */ +#define CPU_DTRACE_KPRIV 0x0080 /* DTrace fault: bad kernel access */ +#define CPU_DTRACE_UPRIV 0x0100 /* DTrace fault: bad user access */ +#define CPU_DTRACE_TUPOFLOW 0x0200 /* DTrace fault: tuple stack overflow */ +#if defined(__sparc) +#define CPU_DTRACE_FAKERESTORE 0x0400 /* pid provider hint to getreg */ +#endif +#define CPU_DTRACE_ENTRY 0x0800 /* pid provider hint to ustack() */ +#define CPU_DTRACE_BADSTACK 0x1000 /* DTrace fault: bad stack */ + +#define CPU_DTRACE_FAULT (CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \ + CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \ + CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \ + CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \ + CPU_DTRACE_BADSTACK) +#define CPU_DTRACE_ERROR (CPU_DTRACE_FAULT | CPU_DTRACE_DROP) + +/* * Flags in the CPU structure. * * These are protected by cpu_lock (except during creation). @@ -129,6 +154,7 @@ } cpu_setup_t; typedef int cpu_setup_func_t(cpu_setup_t, int, void *); +#define mp_maxid ncpu #endif /* _COMPAT_OPENSOLARIS_SYS_CPUVAR_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/cpuvar_defs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpuvar_defs.h --- /tmp/out/external/cddl/osnet/sys/sys/cpuvar_defs.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cpuvar_defs.h 2010-02-20 17:46:35.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: cpuvar_defs.h,v 1.2 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/cred.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cred.h --- /tmp/out/external/cddl/osnet/sys/sys/cred.h 2013-03-23 08:29:27.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/cred.h 2017-06-09 17:22:00.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: cred.h,v 1.4 2010/03/13 22:31:15 christos Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,37 +25,63 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/cred.h 248571 2013-03-21 08:38:03Z mm $ */ #ifndef _OPENSOLARIS_SYS_CRED_H_ #define _OPENSOLARIS_SYS_CRED_H_ #include -#define _WANT_UCRED -#include -#undef _WANT_UCRED - -typedef struct ucred cred_t; -typedef struct ucred ucred_t; +#include #ifdef _KERNEL -#define CRED() (curthread->td_ucred) +#include -/* - * kcred is used when you need all privileges. - */ -#define kcred (thread0.td_ucred) +#define CRED() (kauth_cred_get()) +#define kcred cred0 + +extern kauth_cred_t cred0; + +#define crgetuid(cr) kauth_cred_geteuid(cr) +#define crgetruid(cr) kauth_cred_getuid(cr) +#define crgetgid(cr) kauth_cred_getegid(cr) +#define crgetrgid(cr) kauth_cred_getgid(cr) +#define crgetngroups(cr) kauth_cred_ngroups(cr) +#define cralloc() kauth_cred_alloc() +#define crhold(cr) kauth_cred_hold(cr) +#define crfree(cr) kauth_cred_free(cr) +#define crsetugid(cr, u, g) ( \ + kauth_cred_setuid(cr, u), \ + kauth_cred_setgid(cr, g), \ + kauth_cred_seteuid(cr, u), \ + kauth_cred_setegid(cr, g), \ + kauth_cred_setsvuid(cr, u), \ + kauth_cred_setsvgid(cr, g), 0) +#define crsetgroups(cr, gc, ga) \ + kauth_cred_setgroups(cr, ga, gc, 0, UIO_SYSSPACE) +#define crgetsid(cr, i) (NULL) + +static __inline gid_t * +crgetgroups(cred_t *cr) +{ + static gid_t gids[NGROUPS_MAX]; + + memset(gids, 0, NGROUPS_MAX); + if (kauth_cred_getgroups(cr, gids, NGROUPS_MAX, UIO_SYSSPACE) != 0) + return NULL; + + return gids; +} + +static __inline int +groupmember(gid_t gid, cred_t *cr) +{ + int result; + + kauth_cred_ismember_gid(cr, gid, &result); + return result; +} -#define crgetuid(cred) ((cred)->cr_uid) -#define crgetruid(cred) ((cred)->cr_ruid) -#define crgetgid(cred) ((cred)->cr_gid) -#define crgetgroups(cred) ((cred)->cr_groups) -#define crgetngroups(cred) ((cred)->cr_ngroups) -#define crgetsid(cred, i) (NULL) -#else /* !_KERNEL */ -#define kcred NULL -#define CRED() NULL -#endif /* !_KERNEL */ +#endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_CRED_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: ctype.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: cyclic.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: cyclic_impl.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/debug.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/debug.h --- /tmp/out/external/cddl/osnet/sys/sys/debug.h 2012-09-13 16:31:02.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/debug.h 2017-06-11 05:21:15.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: debug.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,20 +25,63 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/debug.h 240415 2012-09-12 18:05:43Z mm $ */ #ifndef _OPENSOLARIS_SYS_DEBUG_H_ #define _OPENSOLARIS_SYS_DEBUG_H_ #ifdef _KERNEL +#include #include #include_next + +#define assfail(a, f, l) \ + (panic("solaris assert: %s, file: %s, line: %d", (a), (f), (l)), 0) + +#define assfail3(a, lv, op, rv, f, l) \ + panic("solaris assert: %s (0x%jx %s 0x%jx), file: %s, line: %d", \ + (a), (uintmax_t)(lv), (op), (uintmax_t)(rv), (f), (l)) #else /* !_KERNEL */ +#include +#include + #include_next -#include -#endif /* _KERNEL */ + +#ifndef HAVE_ASSFAIL +extern int aok; + +static __inline int +__assfail(const char *expr, const char *file, int line) +{ + + (void)fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n", + expr, file, line); + if (!aok) + abort(); + return (0); +} +#define assfail __assfail +#endif + +#ifndef HAVE_ASSFAIL3 +extern int aok; + +static inline void +__assfail3(const char *expr, uintmax_t lv, const char *op, uintmax_t rv, + const char *file, int line) { + + (void)fprintf(stderr, + "Assertion failed: %s (0x%jx %s 0x%jx), file %s, line %d.\n", + expr, lv, op, rv, file, line); + if (!aok) + abort(); +} +#define assfail3 __assfail3 +#endif + +#endif /* !_KERNEL */ #endif /* _OPENSOLARIS_SYS_DEBUG_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/dirent.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dirent.h --- /tmp/out/external/cddl/osnet/sys/sys/dirent.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dirent.h 2017-06-09 17:30:43.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dirent.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/dirent.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_DIRENT_H_ @@ -40,8 +42,8 @@ #define d_ino d_fileno -#define DIRENT64_RECLEN(len) ((sizeof(struct dirent) - \ - sizeof(((struct dirent *)NULL)->d_name) + \ - (len) + 1 + 3) & ~3) +#define __DIRENT64_NAMEOFF __builtin_offsetof(struct dirent, d_name) +#define DIRENT64_RECLEN(len) \ + roundup2(__DIRENT64_NAMEOFF + (len) + 1, sizeof(ino_t)) #endif /* !_OPENSOLARIS_SYS_DIRENT_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/dkio.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dkio.h --- /tmp/out/external/cddl/osnet/sys/sys/dkio.h 2014-05-04 04:56:43.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dkio.h 2010-02-20 17:46:35.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: dkio.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/dkio.h 265152 2014-04-30 17:46:29Z smh $ */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. @@ -28,6 +28,7 @@ #ifndef _OPENSOLARIS_SYS_DKIO_H_ #define _OPENSOLARIS_SYS_DKIO_H_ + #ifdef __cplusplus extern "C" { #endif @@ -84,4 +85,6 @@ } #endif +#include_next + #endif /* _OPENSOLARIS_SYS_DKIO_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/dnlc.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dnlc.h --- /tmp/out/external/cddl/osnet/sys/sys/dnlc.h 2016-06-27 20:14:32.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/dnlc.h 2017-06-09 17:14:01.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: dnlc.h,v 1.3 2010/02/21 01:46:35 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -35,6 +37,6 @@ #define dnlc_update(dvp, name, vp) do { } while (0) #define dnlc_remove(dvp, name) do { } while (0) #define dnlc_purge_vfsp(vfsp, count) (0) -void dnlc_reduce_cache(void *arg); +#define dnlc_reduce_cache(percent) do { } while (0) #endif /* !_OPENSOLARIS_SYS_DNLC_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/elf.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/elf.h --- /tmp/out/external/cddl/osnet/sys/sys/elf.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/elf.h 2017-06-09 17:31:30.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: elf.h,v 1.5 2010/03/01 11:19:40 darran Exp $ */ + /* * CDDL HEADER START * @@ -18,7 +20,7 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/elf.h 177698 2008-03-28 22:16:18Z jb $ * * ELF compatibility definitions for OpenSolaris source. * @@ -27,90 +29,15 @@ #ifndef _SYS__ELF_SOLARIS_H_ #define _SYS__ELF_SOLARIS_H_ -#include_next - -#define __sElfN(x) typedef __CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x) x - -__sElfN(Addr); -__sElfN(Cap); -__sElfN(Dyn); -__sElfN(Ehdr); -__sElfN(Move); -__sElfN(Off); -__sElfN(Phdr); -__sElfN(Rel); -__sElfN(Rela); -__sElfN(Shdr); -__sElfN(Sym); -__sElfN(Syminfo); -__sElfN(Verdaux); -__sElfN(Verdef); -__sElfN(Vernaux); -__sElfN(Verneed); -__sElfN(Versym); - -__sElfN(Half); -__sElfN(Sword); -__sElfN(Word); - -#if __ELF_WORD_SIZE == 32 -typedef Elf32_Word Xword; /* Xword/Sxword are 32-bits in Elf32 */ -typedef Elf32_Sword Sxword; +#if HAVE_NBTOOL_CONFIG_H +#include #else -typedef Elf64_Xword Xword; -typedef Elf64_Sxword Sxword; +#include #endif -#define ELF_M_INFO __ELFN(M_INFO) -#define ELF_M_SIZE __ELFN(M_SIZE) -#define ELF_M_SYM __ELFN(M_SYM) +#define SHT_SUNW_dof 0x6ffffff4 +#define EM_AMD64 EM_X86_64 -/* - * Elf `printf' type-cast macros. These force arguments to be a fixed size - * so that Elf32 and Elf64 can share common format strings. - */ -#define EC_ADDR(a) ((Elf64_Addr)(a)) /* "ull" */ -#define EC_OFF(a) ((Elf64_Off)(a)) /* "ull" */ -#define EC_HALF(a) ((Elf64_Half)(a)) /* "d" */ -#define EC_WORD(a) ((Elf64_Word)(a)) /* "u" */ -#define EC_SWORD(a) ((Elf64_Sword)(a)) /* "d" */ -#define EC_XWORD(a) ((Elf64_Xword)(a)) /* "ull" */ -#define EC_SXWORD(a) ((Elf64_Sxword)(a)) /* "ll" */ -#define EC_LWORD(a) ((Elf64_Lword)(a)) /* "ull" */ - -#define elf_checksum __elfN(checksum) -#define elf_fsize __elfN(fsize) -#define elf_getehdr __elfN(getehdr) -#define elf_getphdr __elfN(getphdr) -#define elf_newehdr __elfN(newehdr) -#define elf_newphdr __elfN(newphdr) -#define elf_getshdr __elfN(getshdr) -#define elf_xlatetof __elfN(xlatetof) -#define elf_xlatetom __elfN(xlatetom) - -#define Elf_cap_entry __ElfN(cap_entry) -#define Elf_cap_title __ElfN(cap_title) -#define Elf_demangle_name __ElfN(demangle_name) -#define Elf_dyn_entry __ElfN(dyn_entry) -#define Elf_dyn_title __ElfN(dyn_title) -#define Elf_ehdr __ElfN(ehdr) -#define Elf_got_entry __ElfN(got_entry) -#define Elf_got_title __ElfN(got_title) -#define Elf_reloc_apply_reg __ElfN(reloc_apply_reg) -#define Elf_reloc_apply_val __ElfN(reloc_apply_val) -#define Elf_reloc_entry_1 __ElfN(reloc_entry_1) -#define Elf_reloc_entry_2 __ElfN(reloc_entry_2) -#define Elf_reloc_title __ElfN(reloc_title) -#define Elf_phdr __ElfN(phdr) -#define Elf_shdr __ElfN(shdr) -#define Elf_syms_table_entry __ElfN(syms_table_entry) -#define Elf_syms_table_title __ElfN(syms_table_title) -#define Elf_ver_def_title __ElfN(ver_def_title) -#define Elf_ver_line_1 __ElfN(ver_line_1) -#define Elf_ver_line_2 __ElfN(ver_line_2) -#define Elf_ver_line_3 __ElfN(ver_line_3) -#define Elf_ver_line_4 __ElfN(ver_line_4) -#define Elf_ver_line_5 __ElfN(ver_line_5) -#define Elf_ver_need_title __ElfN(ver_need_title) +#define __ELF_WORD_SIZE ELFSIZE #endif /* !_SYS__ELF_SOLARIS_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: errno.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/extdirent.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/extdirent.h --- /tmp/out/external/cddl/osnet/sys/sys/extdirent.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/extdirent.h 2009-08-07 13:57:57.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: extdirent.h,v 1.1 2009/08/07 20:57:57 haad Exp $ */ + /* * CDDL HEADER START * diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/feature_tests.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/feature_tests.h --- /tmp/out/external/cddl/osnet/sys/sys/feature_tests.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/feature_tests.h 2017-06-09 17:31:58.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: feature_tests.h,v 1.2 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/feature_tests.h 179204 2008-05-22 09:08:41Z jb $ * */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: fs Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: int_limits.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: int_types.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/isa_defs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/isa_defs.h --- /tmp/out/external/cddl/osnet/sys/sys/isa_defs.h 2016-02-04 07:16:29.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/isa_defs.h 2015-02-21 21:21:32.000000000 -0800 @@ -1,695 +1,51 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ +/* $NetBSD: isa_defs.h,v 1.2 2015/02/21 15:00:30 ozaki-r Exp $ */ -/* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SYS_ISA_DEFS_H -#define _SYS_ISA_DEFS_H +#include -/* - * This header file serves to group a set of well known defines and to - * set these for each instruction set architecture. These defines may - * be divided into two groups; characteristics of the processor and - * implementation choices for Solaris on a processor. - * - * Processor Characteristics: - * - * _LITTLE_ENDIAN / _BIG_ENDIAN: - * The natural byte order of the processor. A pointer to an int points - * to the least/most significant byte of that int. - * - * _STACK_GROWS_UPWARD / _STACK_GROWS_DOWNWARD: - * The processor specific direction of stack growth. A push onto the - * stack increases/decreases the stack pointer, so it stores data at - * successively higher/lower addresses. (Stackless machines ignored - * without regrets). - * - * _LONG_LONG_HTOL / _LONG_LONG_LTOH: - * A pointer to a long long points to the most/least significant long - * within that long long. - * - * _BIT_FIELDS_HTOL / _BIT_FIELDS_LTOH: - * The C compiler assigns bit fields from the high/low to the low/high end - * of an int (most to least significant vs. least to most significant). - * - * _IEEE_754: - * The processor (or supported implementations of the processor) - * supports the ieee-754 floating point standard. No other floating - * point standards are supported (or significant). Any other supported - * floating point formats are expected to be cased on the ISA processor - * symbol. - * - * _CHAR_IS_UNSIGNED / _CHAR_IS_SIGNED: - * The C Compiler implements objects of type `char' as `unsigned' or - * `signed' respectively. This is really an implementation choice of - * the compiler writer, but it is specified in the ABI and tends to - * be uniform across compilers for an instruction set architecture. - * Hence, it has the properties of a processor characteristic. - * - * _CHAR_ALIGNMENT / _SHORT_ALIGNMENT / _INT_ALIGNMENT / _LONG_ALIGNMENT / - * _LONG_LONG_ALIGNMENT / _DOUBLE_ALIGNMENT / _LONG_DOUBLE_ALIGNMENT / - * _POINTER_ALIGNMENT / _FLOAT_ALIGNMENT: - * The ABI defines alignment requirements of each of the primitive - * object types. Some, if not all, may be hardware requirements as - * well. The values are expressed in "byte-alignment" units. - * - * _MAX_ALIGNMENT: - * The most stringent alignment requirement as specified by the ABI. - * Equal to the maximum of all the above _XXX_ALIGNMENT values. - * - * _ALIGNMENT_REQUIRED: - * True or false (1 or 0) whether or not the hardware requires the ABI - * alignment. - * - * _LONG_LONG_ALIGNMENT_32 - * The 32-bit ABI supported by a 64-bit kernel may have different - * alignment requirements for primitive object types. The value of this - * identifier is expressed in "byte-alignment" units. - * - * _HAVE_CPUID_INSN - * This indicates that the architecture supports the 'cpuid' - * instruction as defined by Intel. (Intel allows other vendors - * to extend the instruction for their own purposes.) - * - * - * Implementation Choices: - * - * _ILP32 / _LP64: - * This specifies the compiler data type implementation as specified in - * the relevant ABI. The choice between these is strongly influenced - * by the underlying hardware, but is not absolutely tied to it. - * Currently only two data type models are supported: - * - * _ILP32: - * Int/Long/Pointer are 32 bits. This is the historical UNIX - * and Solaris implementation. Due to its historical standing, - * this is the default case. - * - * _LP64: - * Long/Pointer are 64 bits, Int is 32 bits. This is the chosen - * implementation for 64-bit ABIs such as SPARC V9. - * - * _I32LPx: - * A compilation environment where 'int' is 32-bit, and - * longs and pointers are simply the same size. - * - * In all cases, Char is 8 bits and Short is 16 bits. - * - * _SUNOS_VTOC_8 / _SUNOS_VTOC_16 / _SVR4_VTOC_16: - * This specifies the form of the disk VTOC (or label): - * - * _SUNOS_VTOC_8: - * This is a VTOC form which is upwardly compatible with the - * SunOS 4.x disk label and allows 8 partitions per disk. - * - * _SUNOS_VTOC_16: - * In this format the incore vtoc image matches the ondisk - * version. It allows 16 slices per disk, and is not - * compatible with the SunOS 4.x disk label. - * - * Note that these are not the only two VTOC forms possible and - * additional forms may be added. One possible form would be the - * SVr4 VTOC form. The symbol for that is reserved now, although - * it is not implemented. - * - * _SVR4_VTOC_16: - * This VTOC form is compatible with the System V Release 4 - * VTOC (as implemented on the SVr4 Intel and 3b ports) with - * 16 partitions per disk. - * - * - * _DMA_USES_PHYSADDR / _DMA_USES_VIRTADDR - * This describes the type of addresses used by system DMA: - * - * _DMA_USES_PHYSADDR: - * This type of DMA, used in the x86 implementation, - * requires physical addresses for DMA buffers. The 24-bit - * addresses used by some legacy boards is the source of the - * "low-memory" (<16MB) requirement for some devices using DMA. - * - * _DMA_USES_VIRTADDR: - * This method of DMA allows the use of virtual addresses for - * DMA transfers. - * - * _FIRMWARE_NEEDS_FDISK / _NO_FDISK_PRESENT - * This indicates the presence/absence of an fdisk table. - * - * _FIRMWARE_NEEDS_FDISK - * The fdisk table is required by system firmware. If present, - * it allows a disk to be subdivided into multiple fdisk - * partitions, each of which is equivalent to a separate, - * virtual disk. This enables the co-existence of multiple - * operating systems on a shared hard disk. - * - * _NO_FDISK_PRESENT - * If the fdisk table is absent, it is assumed that the entire - * media is allocated for a single operating system. - * - * _HAVE_TEM_FIRMWARE - * Defined if this architecture has the (fallback) option of - * using prom_* calls for doing I/O if a suitable kernel driver - * is not available to do it. - * - * _DONT_USE_1275_GENERIC_NAMES - * Controls whether or not device tree node names should - * comply with the IEEE 1275 "Generic Names" Recommended - * Practice. With _DONT_USE_GENERIC_NAMES, device-specific - * names identifying the particular device will be used. - * - * __i386_COMPAT - * This indicates whether the i386 ABI is supported as a *non-native* - * mode for the platform. When this symbol is defined: - * - 32-bit xstat-style system calls are enabled - * - 32-bit xmknod-style system calls are enabled - * - 32-bit system calls use i386 sizes -and- alignments - * - * Note that this is NOT defined for the i386 native environment! - * - * __x86 - * This is ONLY a synonym for defined(__i386) || defined(__amd64) - * which is useful only insofar as these two architectures share - * common attributes. Analogous to __sparc. - * - * _PSM_MODULES - * This indicates whether or not the implementation uses PSM - * modules for processor support, reading /etc/mach from inside - * the kernel to extract a list. - * - * _RTC_CONFIG - * This indicates whether or not the implementation uses /etc/rtc_config - * to configure the real-time clock in the kernel. - * - * _UNIX_KRTLD - * This indicates that the implementation uses a dynamically - * linked unix + krtld to form the core kernel image at boot - * time, or (in the absence of this symbol) a prelinked kernel image. - * - * _OBP - * This indicates the firmware interface is OBP. - * - * _SOFT_HOSTID - * This indicates that the implementation obtains the hostid - * from the file /etc/hostid, rather than from hardware. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * The following set of definitions characterize Solaris on AMD's - * 64-bit systems. - */ -#if defined(__x86_64) || defined(__amd64) - -#if !defined(__amd64) -#define __amd64 /* preferred guard */ -#endif - -#if !defined(__x86) -#define __x86 -#endif - -/* - * Define the appropriate "processor characteristics" - */ -#ifdef illumos -#define _LITTLE_ENDIAN -#endif -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_SIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_ALIGNMENT 8 -#define _LONG_LONG_ALIGNMENT 8 -#define _DOUBLE_ALIGNMENT 8 -#define _DOUBLE_COMPLEX_ALIGNMENT 8 -#define _LONG_DOUBLE_ALIGNMENT 16 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 16 -#define _POINTER_ALIGNMENT 8 -#define _MAX_ALIGNMENT 16 -#define _ALIGNMENT_REQUIRED 1 - -/* - * Different alignment constraints for the i386 ABI in compatibility mode - */ -#define _LONG_LONG_ALIGNMENT_32 4 - -/* - * Define the appropriate "implementation choices". - */ -#if !defined(_LP64) -#define _LP64 -#endif -#if !defined(_I32LPx) && defined(_KERNEL) -#define _I32LPx -#endif -#define _MULTI_DATAMODEL -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define __i386_COMPAT -#define _PSM_MODULES -#define _RTC_CONFIG -#define _SOFT_HOSTID -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN - -/* - * The feature test macro __i386 is generic for all processors implementing - * the Intel 386 instruction set or a superset of it. Specifically, this - * includes all members of the 386, 486, and Pentium family of processors. - */ -#elif defined(__i386) || defined(__i386__) - -#if !defined(__i386) -#define __i386 -#endif - -#if !defined(__x86) -#define __x86 -#endif - -/* - * Define the appropriate "processor characteristics" - */ -#ifdef illumos -#define _LITTLE_ENDIAN -#endif -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_SIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_ALIGNMENT 4 -#define _LONG_LONG_ALIGNMENT 4 -#define _DOUBLE_ALIGNMENT 4 -#define _DOUBLE_COMPLEX_ALIGNMENT 4 -#define _LONG_DOUBLE_ALIGNMENT 4 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 4 -#define _POINTER_ALIGNMENT 4 -#define _MAX_ALIGNMENT 4 -#define _ALIGNMENT_REQUIRED 0 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices". - */ +#if defined(__i386__) #if !defined(_ILP32) -#define _ILP32 -#endif -#if !defined(_I32LPx) && defined(_KERNEL) -#define _I32LPx +#define _ILP32 #endif -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define _PSM_MODULES -#define _RTC_CONFIG -#define _SOFT_HOSTID -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN -#elif defined(__aarch64__) - -/* - * Define the appropriate "processor characteristics" - */ -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_UNSIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_ALIGNMENT 8 -#define _LONG_LONG_ALIGNMENT 8 -#define _DOUBLE_ALIGNMENT 8 -#define _DOUBLE_COMPLEX_ALIGNMENT 8 -#define _LONG_DOUBLE_ALIGNMENT 16 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 16 -#define _POINTER_ALIGNMENT 8 -#define _MAX_ALIGNMENT 16 -#define _ALIGNMENT_REQUIRED 1 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices" - */ -#if !defined(_LP64) -#define _LP64 -#endif -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define _PSM_MODULES -#define _RTC_CONFIG -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN - -#elif defined(__riscv__) - -/* - * Define the appropriate "processor characteristics" - */ -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_UNSIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_ALIGNMENT 8 -#define _LONG_LONG_ALIGNMENT 8 -#define _DOUBLE_ALIGNMENT 8 -#define _DOUBLE_COMPLEX_ALIGNMENT 8 -#define _LONG_DOUBLE_ALIGNMENT 16 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 16 -#define _POINTER_ALIGNMENT 8 -#define _MAX_ALIGNMENT 16 -#define _ALIGNMENT_REQUIRED 1 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices" - */ +#elif defined(__amd64__) #if !defined(_LP64) -#define _LP64 +#define _LP64 #endif -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define _PSM_MODULES -#define _RTC_CONFIG -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN #elif defined(__arm__) - -/* - * Define the appropriate "processor characteristics" - */ -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_SIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_ALIGNMENT 4 -#define _LONG_LONG_ALIGNMENT 4 -#define _DOUBLE_ALIGNMENT 4 -#define _DOUBLE_COMPLEX_ALIGNMENT 4 -#define _LONG_DOUBLE_ALIGNMENT 4 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 4 -#define _POINTER_ALIGNMENT 4 -#define _MAX_ALIGNMENT 4 -#define _ALIGNMENT_REQUIRED 0 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices". - */ #if !defined(_ILP32) -#define _ILP32 -#endif -#if !defined(_I32LPx) && defined(_KERNEL) -#define _I32LPx -#endif -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define _PSM_MODULES -#define _RTC_CONFIG -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN - -#elif defined(__mips__) - -/* - * Define the appropriate "processor characteristics" - */ -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_LTOH -#define _BIT_FIELDS_LTOH -#define _IEEE_754 -#define _CHAR_IS_SIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#if defined(__mips_n64) -#define _LONG_ALIGNMENT 8 -#define _LONG_LONG_ALIGNMENT 8 -#define _DOUBLE_ALIGNMENT 8 -#define _DOUBLE_COMPLEX_ALIGNMENT 8 -#define _LONG_DOUBLE_ALIGNMENT 8 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 8 -#define _POINTER_ALIGNMENT 8 -#define _MAX_ALIGNMENT 8 -#define _ALIGNMENT_REQUIRED 0 - -#define _LONG_LONG_ALIGNMENT_32 _INT_ALIGNMENT -/* - * Define the appropriate "implementation choices". - */ -#if !defined(_LP64) -#define _LP64 -#endif -#else -#define _LONG_ALIGNMENT 4 -#define _LONG_LONG_ALIGNMENT 4 -#define _DOUBLE_ALIGNMENT 4 -#define _DOUBLE_COMPLEX_ALIGNMENT 4 -#define _LONG_DOUBLE_ALIGNMENT 4 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 4 -#define _POINTER_ALIGNMENT 4 -#define _MAX_ALIGNMENT 4 -#define _ALIGNMENT_REQUIRED 0 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices". - */ -#define _ILP32 -#if !defined(_I32LPx) && defined(_KERNEL) -#define _I32LPx -#endif -#endif -#define _SUNOS_VTOC_16 -#define _DMA_USES_PHYSADDR -#define _FIRMWARE_NEEDS_FDISK -#define _PSM_MODULES -#define _RTC_CONFIG -#define _DONT_USE_1275_GENERIC_NAMES -#define _HAVE_CPUID_INSN - -#elif defined(__powerpc__) - -#if defined(__BIG_ENDIAN__) -#define _BIT_FIELDS_HTOL -#else -#define _BIT_FIELDS_LTOH -#endif - -/* - * The following set of definitions characterize the Solaris on SPARC systems. - * - * The symbol __sparc indicates any of the SPARC family of processor - * architectures. This includes SPARC V7, SPARC V8 and SPARC V9. - * - * The symbol __sparcv8 indicates the 32-bit SPARC V8 architecture as defined - * by Version 8 of the SPARC Architecture Manual. (SPARC V7 is close enough - * to SPARC V8 for the former to be subsumed into the latter definition.) - * - * The symbol __sparcv9 indicates the 64-bit SPARC V9 architecture as defined - * by Version 9 of the SPARC Architecture Manual. - * - * The symbols __sparcv8 and __sparcv9 are mutually exclusive, and are only - * relevant when the symbol __sparc is defined. - */ -/* - * XXX Due to the existence of 5110166, "defined(__sparcv9)" needs to be added - * to support backwards builds. This workaround should be removed in s10_71. - */ -#elif defined(__sparc) || defined(__sparcv9) || defined(__sparc__) -#if !defined(__sparc) -#define __sparc -#endif - -/* - * You can be 32-bit or 64-bit, but not both at the same time. - */ -#if defined(__sparcv8) && defined(__sparcv9) -#error "SPARC Versions 8 and 9 are mutually exclusive choices" -#endif - -/* - * Existing compilers do not set __sparcv8. Years will transpire before - * the compilers can be depended on to set the feature test macro. In - * the interim, we'll set it here on the basis of historical behaviour; - * if you haven't asked for SPARC V9, then you must've meant SPARC V8. - */ -#if !defined(__sparcv9) && !defined(__sparcv8) -#define __sparcv8 -#endif - -/* - * Define the appropriate "processor characteristics" shared between - * all Solaris on SPARC systems. - */ -#ifdef illumos -#define _BIG_ENDIAN -#endif -#define _STACK_GROWS_DOWNWARD -#define _LONG_LONG_HTOL -#define _BIT_FIELDS_HTOL -#define _IEEE_754 -#define _CHAR_IS_SIGNED -#define _BOOL_ALIGNMENT 1 -#define _CHAR_ALIGNMENT 1 -#define _SHORT_ALIGNMENT 2 -#define _INT_ALIGNMENT 4 -#define _FLOAT_ALIGNMENT 4 -#define _FLOAT_COMPLEX_ALIGNMENT 4 -#define _LONG_LONG_ALIGNMENT 8 -#define _DOUBLE_ALIGNMENT 8 -#define _DOUBLE_COMPLEX_ALIGNMENT 8 -#define _ALIGNMENT_REQUIRED 1 - -/* - * Define the appropriate "implementation choices" shared between versions. - */ -#define _SUNOS_VTOC_8 -#define _DMA_USES_VIRTADDR -#define _NO_FDISK_PRESENT -#define _HAVE_TEM_FIRMWARE -#define _OBP - -/* - * The following set of definitions characterize the implementation of - * 32-bit Solaris on SPARC V8 systems. - */ -#if defined(__sparcv8) - -/* - * Define the appropriate "processor characteristics" - */ -#define _LONG_ALIGNMENT 4 -#define _LONG_DOUBLE_ALIGNMENT 8 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 8 -#define _POINTER_ALIGNMENT 4 -#define _MAX_ALIGNMENT 8 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices" - */ -#define _ILP32 -#if !defined(_I32LPx) && defined(_KERNEL) -#define _I32LPx -#endif - -/* - * The following set of definitions characterize the implementation of - * 64-bit Solaris on SPARC V9 systems. - */ -#elif defined(__sparcv9) - -/* - * Define the appropriate "processor characteristics" - */ -#define _LONG_ALIGNMENT 8 -#define _LONG_DOUBLE_ALIGNMENT 16 -#define _LONG_DOUBLE_COMPLEX_ALIGNMENT 16 -#define _POINTER_ALIGNMENT 8 -#define _MAX_ALIGNMENT 16 - -#define _LONG_LONG_ALIGNMENT_32 _LONG_LONG_ALIGNMENT - -/* - * Define the appropriate "implementation choices" - */ -#if !defined(_LP64) -#define _LP64 +#define _ILP32 #endif -#if !defined(_I32LPx) -#define _I32LPx -#endif -#define _MULTI_DATAMODEL #else -#error "unknown SPARC version" -#endif - -/* - * #error is strictly ansi-C, but works as well as anything for K&R systems. - */ -#else -#error "ISA not supported" +#error "architecture not supported" #endif - -#if defined(_ILP32) && defined(_LP64) -#error "Both _ILP32 and _LP64 are defined" -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_ISA_DEFS_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/kcondvar.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kcondvar.h --- /tmp/out/external/cddl/osnet/sys/sys/kcondvar.h 2013-10-05 05:53:08.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kcondvar.h 2017-04-28 10:21:59.000000000 -0700 @@ -1,8 +1,12 @@ +/* $NetBSD: kcondvar.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- - * Copyright (c) 2007 Pawel Jakub Dawidek - * Copyright (c) 2013 iXsystems, Inc. + * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -12,66 +16,60 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _OPENSOLARIS_SYS_CONDVAR_H_ -#define _OPENSOLARIS_SYS_CONDVAR_H_ +#ifndef _OPENSOLARIS_SYS_KCONDVAR_H_ +#define _OPENSOLARIS_SYS_KCONDVAR_H_ -#include -#include +#include_next #ifdef _KERNEL -#include -#include -#include - -typedef struct cv kcondvar_t; - typedef enum { CV_DEFAULT, CV_DRIVER } kcv_type_t; -#define zfs_cv_init(cv, name, type, arg) do { \ - const char *_name; \ - ASSERT((type) == CV_DEFAULT); \ - for (_name = #cv; *_name != '\0'; _name++) { \ - if (*_name >= 'a' && *_name <= 'z') \ - break; \ - } \ - if (*_name == '\0') \ - _name = #cv; \ - cv_init((cv), _name); \ -} while (0) -#define cv_init(cv, name, type, arg) zfs_cv_init(cv, name, type, arg) +typedef enum { + TR_CLOCK_TICK, +} time_res_t; + +#define cv_init(a, b, c, d) cv_init(a, "zfscv") -static clock_t +static inline clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, hrtime_t res, int flag) { - sbintime_t sbt; - sbintime_t pr; + extern int hz; + int ticks = ((uint64_t)tim * hz) / 1000000000; + + return cv_timedwait(cvp, mp, ticks); +} - sbt = tim * SBT_1NS; - pr = res * SBT_1NS; +static inline clock_t +cv_reltimedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t delta, time_res_t res) +{ - return (cv_timedwait_sbt(cvp, mp, sbt, pr, 0)); + cv_wait(cvp, mp); + return 0; } +#else + +extern clock_t cv_timedwait_hires(kcondvar_t *, kmutex_t *, hrtime_t, hrtime_t, + int); + #endif /* _KERNEL */ -#endif /* _OPENSOLARIS_SYS_CONDVAR_H_ */ +#endif /* _OPENSOLARIS_SYS_KCONDVAR_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: kernel.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/kidmap.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kidmap.h --- /tmp/out/external/cddl/osnet/sys/sys/kidmap.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kidmap.h 2017-06-10 09:09:35.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: kidmap.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/kidmap.h 185029 2008-11-17 20:49:29Z pjd $ */ #ifndef _OPENSOLARIS_SYS_KIDMAP_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/kmem.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kmem.h --- /tmp/out/external/cddl/osnet/sys/sys/kmem.h 2016-12-03 09:03:50.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kmem.h 2017-11-30 00:06:44.000000000 -0800 @@ -1,7 +1,13 @@ + +/* $NetBSD: kmem.h,v 1.9 2017/11/18 18:52:59 kre Exp $ */ + /*- - * Copyright (c) 2007 Pawel Jakub Dawidek + * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,79 +17,79 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/kmem.h 309017 2016-11-22 18:13:46Z alc $ + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _OPENSOLARIS_SYS_KMEM_H_ #define _OPENSOLARIS_SYS_KMEM_H_ -#include -#include -#include +#include_next +#include #include -#include -#include -#include +#define KM_PUSHPAGE KM_SLEEP +#define KM_NORMALPRI 0 +#define KM_NODEBUG 0 -MALLOC_DECLARE(M_SOLARIS); +#define KMC_NODEBUG 0 +#define KMC_NOTOUCH 0 + +typedef void kmem_cache_t; #define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3)) #define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1)) -#define KM_SLEEP M_WAITOK -#define KM_PUSHPAGE M_WAITOK -#define KM_NOSLEEP M_NOWAIT -#define KM_NODEBUG M_NODUMP -#define KM_NORMALPRI 0 -#define KMC_NODEBUG UMA_ZONE_NODUMP -#define KMC_NOTOUCH 0 - -typedef struct kmem_cache { - char kc_name[32]; -#if defined(_KERNEL) && !defined(KMEM_DEBUG) - uma_zone_t kc_zone; -#else - size_t kc_size; -#endif - int (*kc_constructor)(void *, void *, int); - void (*kc_destructor)(void *, void *); - void *kc_private; -} kmem_cache_t; - -void *zfs_kmem_alloc(size_t size, int kmflags); -void zfs_kmem_free(void *buf, size_t size); -uint64_t kmem_size(void); -kmem_cache_t *kmem_cache_create(char *name, size_t bufsize, size_t align, +void kmem_reap(void); + +static inline kmem_cache_t * +kmem_cache_create(char *name, size_t bufsize, size_t align, int (*constructor)(void *, void *, int), void (*destructor)(void *, void *), - void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags); -void kmem_cache_destroy(kmem_cache_t *cache); -void *kmem_cache_alloc(kmem_cache_t *cache, int flags); -void kmem_cache_free(kmem_cache_t *cache, void *buf); -void kmem_cache_reap_now(kmem_cache_t *cache); -void kmem_reap(void); -int kmem_debugging(void); -void *calloc(size_t n, size_t s); + void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags) +{ + pool_cache_t pc; + int flags = bufsize > PAGESIZE ? PR_NOALIGN : 0; + + KASSERT(vmp == NULL); + + pc = pool_cache_init(bufsize, align, 0, flags, name, NULL, IPL_NONE, + constructor, destructor, private); + if (pc != NULL && reclaim != NULL) { + pool_cache_set_drain_hook(pc, (void *)reclaim, private); + } + return pc; +} + +static inline void * +kmem_cache_alloc(kmem_cache_t *cache, int flags) +{ + return pool_cache_get(cache, flags); +} + +#define kmem_cache_destroy(cache) pool_cache_destroy(cache) +#define kmem_cache_free(cache, buf) pool_cache_put(cache, buf) +#define kmem_cache_reap_now(cache) pool_cache_invalidate(cache) -#define freemem vm_cnt.v_free_count -#define minfree vm_cnt.v_free_min #define heap_arena kmem_arena -#define kmem_alloc(size, kmflags) zfs_kmem_alloc((size), (kmflags)) -#define kmem_zalloc(size, kmflags) zfs_kmem_alloc((size), (kmflags) | M_ZERO) -#define kmem_free(buf, size) zfs_kmem_free((buf), (size)) #define kmem_cache_set_move(cache, movefunc) do { } while (0) +#define kmem_alloc solaris_kmem_alloc +#define kmem_zalloc solaris_kmem_zalloc +#define kmem_free solaris_kmem_free +#define kmem_size() ((uint64_t)physmem * PAGE_SIZE) + +void *solaris_kmem_alloc(size_t, int); +void *solaris_kmem_zalloc(size_t, int); +void solaris_kmem_free(void *, size_t); + #endif /* _OPENSOLARIS_SYS_KMEM_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/kobj.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kobj.h --- /tmp/out/external/cddl/osnet/sys/sys/kobj.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kobj.h 2017-06-09 17:32:32.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: kobj.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/kobj.h 177698 2008-03-28 22:16:18Z jb $ */ #ifndef _OPENSOLARIS_SYS_KOBJ_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/kstat.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kstat.h --- /tmp/out/external/cddl/osnet/sys/sys/kstat.h 2017-03-26 23:19:45.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/kstat.h 2017-04-23 11:02:16.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: kstat.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -42,8 +73,8 @@ void *ks_data; u_int ks_ndata; #ifdef _KERNEL - struct sysctl_ctx_list ks_sysctl_ctx; - struct sysctl_oid *ks_sysctl_root; + struct sysctllog *ks_clog; + const struct sysctlnode *ks_node; #endif int (*ks_update)(struct kstat *, int); /* dynamic update */ void *ks_private; /* arbitrary provider-private data */ @@ -65,7 +96,7 @@ } value; } kstat_named_t; -kstat_t *kstat_create(char *module, int instance, char *name, char *cls, +kstat_t *kstat_create(char *module, int instance, char *name, char *class, uchar_t type, ulong_t ndata, uchar_t flags); void kstat_install(kstat_t *ksp); void kstat_delete(kstat_t *ksp); Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: linker.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/misc.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/misc.h --- /tmp/out/external/cddl/osnet/sys/sys/misc.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/misc.h 2017-06-09 17:43:44.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: misc.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,20 +25,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/misc.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_MISC_H_ #define _OPENSOLARIS_SYS_MISC_H_ -#include +#include #define MAXUID UID_MAX -#define SPEC_MAXOFFSET_T OFF_MAX +#define SPEC_MAXOFFSET_T LLONG_MAX -#define _ACL_ACLENT_ENABLED 0x1 -#define _ACL_ACE_ENABLED 0x2 +#define _ACL_ACLENT_ENABLED 0x1 +#define _ACL_ACE_ENABLED 0x2 #define _FIOFFS (INT_MIN) #define _FIOGDIO (INT_MIN+1) @@ -45,17 +47,6 @@ #define _FIO_SEEK_DATA FIOSEEKDATA #define _FIO_SEEK_HOLE FIOSEEKHOLE -#ifdef _KERNEL -struct opensolaris_utsname { - char *sysname; - char *nodename; - char *release; - char version[32]; - char *machine; -}; - extern char hw_serial[11]; -extern struct opensolaris_utsname utsname; -#endif #endif /* _OPENSOLARIS_SYS_MISC_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: mkdev.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/mman.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mman.h --- /tmp/out/external/cddl/osnet/sys/sys/mman.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mman.h 2017-06-09 18:07:18.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: mman.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/mman.h 177698 2008-03-28 22:16:18Z jb $ * */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/mntent.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mntent.h --- /tmp/out/external/cddl/osnet/sys/sys/mntent.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mntent.h 2017-06-09 18:07:34.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: mntent.h,v 1.2 2010/02/21 01:46:36 darran Exp $ */ + /* * CDDL HEADER START * @@ -19,7 +21,7 @@ * * CDDL HEADER END * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/mntent.h 185029 2008-11-17 20:49:29Z pjd $ */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/mnttab.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mnttab.h --- /tmp/out/external/cddl/osnet/sys/sys/mnttab.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mnttab.h 2017-04-20 15:35:54.000000000 -0700 @@ -1,36 +1,113 @@ -/*- - * Copyright (c) 2007 Pawel Jakub Dawidek - * All rights reserved. +/* $NetBSD: mnttab.h,v 1.4 2010/12/14 01:00:26 haad Exp $ */ + +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] * - * $FreeBSD$ + * CDDL HEADER END + */ +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ -#ifndef _OPENSOLARIS_SYS_MNTTAB_H_ -#define _OPENSOLARIS_SYS_MNTTAB_H_ +#ifndef _SYS_MNTTAB_H +#define _SYS_MNTTAB_H #ifndef _KERNEL #include #endif -#endif /* !_OPENSOLARIS_MNTTAB_H_ */ +#if 0 + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MNTTAB "/dev/null" +#define MNT_LINE_MAX 1024 + +#define MNT_TOOLONG 1 /* entry exceeds MNT_LINE_MAX */ +#define MNT_TOOMANY 2 /* too many fields in line */ +#define MNT_TOOFEW 3 /* too few fields in line */ + +#define mntnull(mp)\ + ((mp)->mnt_special = (mp)->mnt_mountp = \ + (mp)->mnt_fstype = (mp)->mnt_mntopts = \ + (mp)->mnt_time = NULL) + +#define putmntent(fd, mp) (-1) + +struct mnttab { + char *mnt_special; + char *mnt_mountp; + char *mnt_fstype; + char *mnt_mntopts; + char *mnt_time; +}; + +/* + * NOTE: fields in extmnttab should match struct mnttab till new fields + * are encountered, this allows hasmntopt to work properly when its arg is + * a pointer to an extmnttab struct cast to a mnttab struct pointer. + */ +struct extmnttab { + char *mnt_special; + char *mnt_mountp; + char *mnt_fstype; + char *mnt_mntopts; + char *mnt_time; + uint_t mnt_major; + uint_t mnt_minor; +}; + +#if !defined(_KERNEL) +#ifdef __STDC__ +extern void resetmnttab(FILE *); +extern int getmntent(FILE *, struct mnttab *); +extern int getextmntent(FILE *, struct extmnttab *, size_t); +extern int getmntany(FILE *, struct mnttab *, struct mnttab *); +extern int getstatfs(struct statvfs *, const char *); +extern char *hasmntopt(struct mnttab *, char *); +extern char *mntopt(char **); +#else +extern void resetmnttab(); +extern int getmntent(); +extern int getextmntent(); +extern int getmntany(); +extern char *hasmntopt(); +extern char *mntopt(); +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#endif /* _SYS_MNTTAB_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/modctl.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/modctl.h --- /tmp/out/external/cddl/osnet/sys/sys/modctl.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/modctl.h 2017-06-09 18:07:55.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: modctl.h,v 1.5 2010/03/01 11:19:40 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/modctl.h 177698 2008-03-28 22:16:18Z jb $ * */ @@ -33,6 +35,6 @@ #include #include -typedef struct linker_file modctl_t; +typedef struct module modctl_t; #endif /* _COMPAT_OPENSOLARIS_SYS_MODCTL_H */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/mount.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mount.h --- /tmp/out/external/cddl/osnet/sys/sys/mount.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mount.h 2017-06-09 18:08:47.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: mount.h,v 1.7 2014/03/04 09:24:42 ozaki-r Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,19 +25,45 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/mount.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_MOUNT_H_ #define _OPENSOLARIS_SYS_MOUNT_H_ -#include - #include_next +#define MS_OVERLAY 0 +#define MS_RDONLY MNT_RDONLY #define MS_FORCE MNT_FORCE #define MS_REMOUNT MNT_UPDATE +#define MS_OPTIONSTR __MNT_UNUSED1 +#define MS_NOMNTTAB 0 /* We don't have any mnttab anyway. */ typedef struct fid fid_t; +#define mount(a,b,c,d,e,f,g,h) zmount(a,b,c,d,e,f,g,h) + +struct zfs_args { + char fspec[MAXNAMELEN - 1]; + char dataptr[MAXPATHLEN]; + char optptr[MAXPATHLEN]; + char *fstype; + int mflag; + int datalen; + int optlen; + int flags; +}; + +typedef struct zfs_args zfs_args_t; + +int +zmount(const char *spec, const char *dir, int mflag, char *fstype, + char *dataptr, int datalen, char *optptr, int optlen); + +int +umount2(const char *spec, int mflag); + +#define vfs_fstype mnt_op->vfs_name + #endif /* !_OPENSOLARIS_SYS_MOUNT_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/mutex.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mutex.h --- /tmp/out/external/cddl/osnet/sys/sys/mutex.h 2013-09-02 04:38:23.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/mutex.h 2017-05-01 17:32:27.000000000 -0700 @@ -1,7 +1,12 @@ +/* $NetBSD: mutex.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- - * Copyright (c) 2007 Pawel Jakub Dawidek + * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -11,19 +16,17 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _OPENSOLARIS_SYS_MUTEX_H_ @@ -31,47 +34,11 @@ #ifdef _KERNEL -#include -#include #include_next -#include -#include - -typedef enum { - MUTEX_DEFAULT = 6 /* kernel default mutex */ -} kmutex_type_t; #define MUTEX_HELD(x) (mutex_owned(x)) -#define MUTEX_NOT_HELD(x) (!mutex_owned(x) || panicstr) - -typedef struct sx kmutex_t; - -#ifndef OPENSOLARIS_WITNESS -#define MUTEX_FLAGS (SX_DUPOK | SX_NOWITNESS) -#else -#define MUTEX_FLAGS (SX_DUPOK) -#endif - -#define mutex_init(lock, desc, type, arg) do { \ - const char *_name; \ - ASSERT((type) == 0 || (type) == MUTEX_DEFAULT); \ - KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) != \ - LO_EXPECTED, ("lock %s already initialized", #lock)); \ - bzero((lock), sizeof(struct sx)); \ - for (_name = #lock; *_name != '\0'; _name++) { \ - if (*_name >= 'a' && *_name <= 'z') \ - break; \ - } \ - if (*_name == '\0') \ - _name = #lock; \ - sx_init_flags((lock), _name, MUTEX_FLAGS); \ -} while (0) -#define mutex_destroy(lock) sx_destroy(lock) -#define mutex_enter(lock) sx_xlock(lock) -#define mutex_tryenter(lock) sx_try_xlock(lock) -#define mutex_exit(lock) sx_xunlock(lock) -#define mutex_owned(lock) sx_xlocked(lock) -#define mutex_owner(lock) sx_xholder(lock) +#define MUTEX_NOT_HELD(x) (!mutex_owned(x) || panicstr != NULL) +#define mutex_init(a, b, c, d) mutex_init(a, MUTEX_DEFAULT, IPL_NONE) #endif /* _KERNEL */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: mutex_impl.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/objfs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/objfs.h --- /tmp/out/external/cddl/osnet/sys/sys/objfs.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/objfs.h 2010-02-20 17:46:36.000000000 -0800 @@ -1,3 +1,5 @@ +/* $NetBSD: objfs.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /* * CDDL HEADER START * @@ -17,8 +19,6 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END - * - * $FreeBSD$ */ #ifndef _COMPAT_OPENSOLARIS_SYS_OBJFS_H Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: open.h Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: opentypes.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/param.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/param.h --- /tmp/out/external/cddl/osnet/sys/sys/param.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/param.h 2017-06-09 18:09:40.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: param.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,19 +25,22 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/param.h 185029 2008-11-17 20:49:29Z pjd $ * */ +#include + #ifndef _COMPAT_OPENSOLARIS_SYS_PARAM_H_ #define _COMPAT_OPENSOLARIS_SYS_PARAM_H_ +#define __HIDE_DELAY #include_next -#define PAGESIZE PAGE_SIZE - #ifdef _KERNEL -#define ptob(x) ((uint64_t)(x) << PAGE_SHIFT) +#define PAGESIZE PAGE_SIZE +#else +#define PAGESIZE getpagesize() #endif #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/pathname.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/pathname.h --- /tmp/out/external/cddl/osnet/sys/sys/pathname.h 2017-03-02 02:54:25.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/pathname.h 2017-06-09 18:09:55.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: pathname.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -34,6 +36,15 @@ #include #include +typedef struct pathname { + char *pn_buf; /* underlying storage */ + char *pn_path; /* remaining pathname */ + size_t pn_pathlen; /* remaining length */ + size_t pn_bufsize; /* total size of pn_buf */ +} pathname_t; + +#define NO_FOLLOW NOFOLLOW + int lookupname(char *, enum uio_seg, enum symfollow, vnode_t **, vnode_t **); int lookupnameat(char *, enum uio_seg, enum symfollow, vnode_t **, vnode_t **, vnode_t *); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/pcpu.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/pcpu.h --- /tmp/out/external/cddl/osnet/sys/sys/pcpu.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/pcpu.h 2017-06-09 18:10:24.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: pcpu.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/pcpu.h 179202 2008-05-22 08:33:24Z jb $ * */ @@ -32,6 +34,8 @@ #include_next -typedef struct pcpu pcpu_t; +typedef struct pcpu cpu_t; + +#define cpu_id pc_cpuid #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/policy.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/policy.h --- /tmp/out/external/cddl/osnet/sys/sys/policy.h 2017-04-17 17:45:48.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/policy.h 2017-06-10 09:09:58.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: policy.h,v 1.7 2012/10/19 19:58:33 riastradh Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -38,6 +40,8 @@ struct mount; struct vattr; +typedef int accmode_t; + int secpolicy_nfs(cred_t *cr); int secpolicy_zfs(cred_t *crd); int secpolicy_sys_config(cred_t *cr, int checkonly); @@ -71,6 +75,8 @@ vtype_t vtype); int secpolicy_smb(cred_t *cr); +int secpolicy_vnode_utime_modify(cred_t *cr); + #endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_POLICY_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: priv_names.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/proc.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/proc.h --- /tmp/out/external/cddl/osnet/sys/sys/proc.h 2016-10-10 04:10:03.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/proc.h 2017-06-10 21:07:26.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: proc.h,v 1.5 2010/03/13 22:31:15 christos Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -30,70 +61,43 @@ #define _OPENSOLARIS_SYS_PROC_H_ #include -#include #include_next #include -#include -#include -#include -#include -#include -#include #ifdef _KERNEL -#define CPU curcpu -#define minclsyspri PRIBIO -#define maxclsyspri PVM -#define max_ncpus (mp_maxid + 1) -#define boot_max_ncpus (mp_maxid + 1) +#include + +#define CPU curcpu() +#define minclsyspri PRI_KTHREAD +#define maxclsyspri MAXPRI_KTHREAD +#define max_ncpus ncpu +#define boot_max_ncpus ncpu +#define curthread curlwp +#define syscid PRI_NONE +#define sysccid PRI_NONE #define TS_RUN 0 #define p0 proc0 -#define t_tid td_tid - -typedef short pri_t; -typedef struct thread _kthread; -typedef struct thread kthread_t; -typedef struct thread *kthread_id_t; -typedef struct proc proc_t; - -extern struct proc *zfsproc; - -static __inline kthread_t * -do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg, - size_t len, proc_t *pp, int state, pri_t pri) -{ - kthread_t *td = NULL; - int error; - - /* - * Be sure there are no surprises. - */ - ASSERT(stk == NULL); - ASSERT(len == 0); - ASSERT(state == TS_RUN); - ASSERT(pp == &p0); - - error = kproc_kthread_add(proc, arg, &zfsproc, &td, RFSTOPPED, - stksize / PAGE_SIZE, "zfskern", "solthread %p", proc); - if (error == 0) { - thread_lock(td); - sched_prio(td, pri); - sched_add(td, SRQ_BORING); - thread_unlock(td); - } - return (td); -} - -#define thread_create(stk, stksize, proc, arg, len, pp, state, pri) \ - do_thread_create(stk, stksize, proc, arg, len, pp, state, pri) -#define thread_exit() kthread_exit() - -int uread(proc_t *, void *, size_t, uintptr_t); -int uwrite(proc_t *, void *, size_t, uintptr_t); +typedef struct lwp _kthread; +typedef struct lwp kthread_t; +typedef struct lwp *kthread_id_t; + +#if (KSTACK_PAGES * PAGE_SIZE) < 16384 +#define ZFS_KSTACK_PAGES (16384 / PAGE_SIZE) +#else +#define ZFS_KSTACK_PAGES 0 +#endif + +struct contract { +}; + +kthread_t *thread_create(void *, size_t, void (*)(void *), void *, size_t, + proc_t *, int, pri_t); +void thread_exit(void); +void thread_join(uint64_t); #endif /* _KERNEL */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/procset.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/procset.h --- /tmp/out/external/cddl/osnet/sys/sys/procset.h 2015-02-03 23:24:17.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/procset.h 2017-04-20 07:59:37.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD$ */ + /* * CDDL HEADER START * @@ -31,8 +33,6 @@ #ifndef _SYS_PROCSET_H #define _SYS_PROCSET_H -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ - #ifdef __cplusplus extern "C" { #endif @@ -51,40 +51,7 @@ #define P_INITUID 0 #define P_INITPGID 0 -#ifndef _IDTYPE_T_DECLARED - -/* - * The following defines the values for an identifier type. It - * specifies the interpretation of an id value. An idtype and - * id together define a simple set of processes. - */ -typedef enum -#if !defined(_XPG4_2) || defined(__EXTENSIONS__) - idtype /* pollutes XPG4.2 namespace */ -#endif - { - P_PID, /* A process identifier. */ - P_PPID, /* A parent process identifier. */ - P_PGID, /* A process group (job control group) */ - /* identifier. */ - P_SID, /* A session identifier. */ - P_CID, /* A scheduling class identifier. */ - P_UID, /* A user identifier. */ - P_GID, /* A group identifier. */ - P_ALL, /* All processes. */ - P_LWPID, /* An LWP identifier. */ - P_TASKID, /* A task identifier. */ - P_PROJID, /* A project identifier. */ - P_POOLID, /* A pool identifier. */ - P_ZONEID, /* A zone identifier. */ - P_CTID, /* A (process) contract identifier. */ - P_CPUID, /* CPU identifier. */ - P_PSETID /* Processor set identifier */ -} idtype_t; - -#define _IDTYPE_T_DECLARED - -#endif +#include /* * The following defines the operations which can be performed to Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: racct.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/random.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/random.h --- /tmp/out/external/cddl/osnet/sys/sys/random.h 2016-10-10 04:10:03.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/random.h 2017-06-09 18:11:42.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: random.h,v 1.5 2013/01/03 17:12:05 dsl Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -29,9 +31,10 @@ #ifndef _OPENSOLARIS_SYS_RANDOM_H_ #define _OPENSOLARIS_SYS_RANDOM_H_ -#include_next +#include -#define random_get_bytes(p, s) read_random((p), (int)(s)) -#define random_get_pseudo_bytes(p, s) arc4rand((p), (int)(s), 0) +#define random_get_bytes(p, s) cprng_fast((p), (s)) +#define random_get_pseudo_bytes(p, s) cprng_fast((p), (s)) +#define read_random(p, s) cprng_fast((p), (s)) #endif /* !_OPENSOLARIS_SYS_RANDOM_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/refstr.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/refstr.h --- /tmp/out/external/cddl/osnet/sys/sys/refstr.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/refstr.h 2017-06-09 18:12:47.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: refstr.h,v 1.2 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - $ $FreeBSD$ + $ $FreeBSD: head/sys/cddl/compat/opensolaris/sys/refstr.h 185029 2008-11-17 20:49:29Z pjd $ */ #ifndef _OPENSOLARIS_SYS_REFSTR_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/rwlock.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/rwlock.h --- /tmp/out/external/cddl/osnet/sys/sys/rwlock.h 2013-09-02 04:38:23.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/rwlock.h 2017-06-09 18:13:59.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: rwlock.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,72 +54,26 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/rwlock.h 253996 2013-08-06 15:51:56Z avg $ */ #ifndef _OPENSOLARIS_SYS_RWLOCK_H_ #define _OPENSOLARIS_SYS_RWLOCK_H_ -#include -#include -#include -#include +#include_next #ifdef _KERNEL typedef enum { + RW_DRIVER = 2, /* driver (DDI) rwlock */ RW_DEFAULT = 4 /* kernel default rwlock */ } krw_type_t; -typedef enum { - RW_WRITER, - RW_READER -} krw_t; - -typedef struct sx krwlock_t; - -#ifndef OPENSOLARIS_WITNESS -#define RW_FLAGS (SX_DUPOK | SX_NOWITNESS) -#else -#define RW_FLAGS (SX_DUPOK) -#endif - #define RW_READ_HELD(x) (rw_read_held((x))) #define RW_WRITE_HELD(x) (rw_write_held((x))) #define RW_LOCK_HELD(x) (rw_lock_held((x))) #define RW_ISWRITER(x) (rw_iswriter(x)) - -#define rw_init(lock, desc, type, arg) do { \ - const char *_name; \ - ASSERT((type) == 0 || (type) == RW_DEFAULT); \ - KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) != \ - LO_EXPECTED, ("lock %s already initialized", #lock)); \ - bzero((lock), sizeof(struct sx)); \ - for (_name = #lock; *_name != '\0'; _name++) { \ - if (*_name >= 'a' && *_name <= 'z') \ - break; \ - } \ - if (*_name == '\0') \ - _name = #lock; \ - sx_init_flags((lock), _name, RW_FLAGS); \ -} while (0) -#define rw_destroy(lock) sx_destroy(lock) -#define rw_enter(lock, how) do { \ - if ((how) == RW_READER) \ - sx_slock(lock); \ - else /* if ((how) == RW_WRITER) */ \ - sx_xlock(lock); \ -} while (0) -#define rw_tryenter(lock, how) ((how) == RW_READER ? sx_try_slock(lock) : sx_try_xlock(lock)) -#define rw_exit(lock) sx_unlock(lock) -#define rw_downgrade(lock) sx_downgrade(lock) -#define rw_tryupgrade(lock) sx_try_upgrade(lock) -#define rw_read_held(lock) ((lock)->sx_lock != SX_LOCK_UNLOCKED && ((lock)->sx_lock & SX_LOCK_SHARED)) -#define rw_write_held(lock) sx_xlocked(lock) -#define rw_lock_held(lock) (rw_read_held(lock) || rw_write_held(lock)) -#define rw_iswriter(lock) sx_xlocked(lock) -/* TODO: Change to sx_xholder() once it is moved from kern_sx.c to sx.h. */ -#define rw_owner(lock) ((lock)->sx_lock & SX_LOCK_SHARED ? NULL : (struct thread *)SX_OWNER((lock)->sx_lock)) +#define rw_init(a, b, c, d) rw_init(a) #endif /* defined(_KERNEL) */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: rwlock_impl.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sdt.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sdt.h --- /tmp/out/external/cddl/osnet/sys/sys/sdt.h 2014-11-01 03:04:55.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sdt.h 2017-04-17 13:52:10.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sdt.h,v 1.7 2015/10/02 17:28:57 christos Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -30,6 +32,28 @@ #define _OPENSOLARIS_SYS_SDT_H_ #include_next +#include + +#undef DTRACE_PROBE +#undef DTRACE_PROBE1 +#undef DTRACE_PROBE2 +#undef DTRACE_PROBE3 +#undef DTRACE_PROBE4 +#undef DTRACE_PROBE5 +#undef DTRACE_PROBE6 +#undef DTRACE_PROBE7 + +#define DTRACE_PROBE(name) +#define DTRACE_PROBE1(name, type1, arg1) +#define DTRACE_PROBE2(name, type1, arg1, type2, arg2) +#define DTRACE_PROBE3(name, type1, arg1, type2, arg2, type3, arg3) +#define DTRACE_PROBE4(name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) +#define DTRACE_PROBE5(name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5) +#define DTRACE_PROBE6(name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5, type6, arg6) +#define DTRACE_PROBE7(name, type1, arg1, type2, arg2, type3, arg3, \ + type4, arg4, type5, arg5, type6, arg6, type7, arg7) #ifdef KDTRACE_HOOKS SDT_PROBE_DECLARE(sdt, , , set__error); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sema.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sema.h --- /tmp/out/external/cddl/osnet/sys/sys/sema.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sema.h 2017-06-09 18:14:27.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sema.h,v 1.2 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/sema.h 179203 2008-05-22 08:35:03Z jb $ * */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: sha2.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sid.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sid.h --- /tmp/out/external/cddl/osnet/sys/sys/sid.h 2012-09-13 16:31:02.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sid.h 2017-06-10 09:10:55.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sid.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/sid.h 240162 2012-09-06 13:43:48Z mm $ */ #ifndef _OPENSOLARIS_SYS_SID_H_ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sig.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sig.h --- /tmp/out/external/cddl/osnet/sys/sys/sig.h 2013-03-23 08:29:27.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sig.h 2017-06-09 18:14:57.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sig.h,v 1.2 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2008 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/sig.h 248470 2013-03-18 17:23:58Z jhb $ */ #ifndef _OPENSOLARIS_SYS_SIG_H_ @@ -55,7 +57,7 @@ p = td->td_proc; PROC_LOCK(p); mtx_lock(&p->p_sigacts->ps_mtx); - sig = cursig(td); + sig = cursig(td, SIG_STOP_ALLOWED); mtx_unlock(&p->p_sigacts->ps_mtx); PROC_UNLOCK(p); if (sig != 0) diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/stat.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/stat.h --- /tmp/out/external/cddl/osnet/sys/sys/stat.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/stat.h 2017-06-09 18:16:21.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: stat.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /* * Copyright (C) 2007 John Birrell * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/stat.h 219089 2011-02-27 19:41:40Z pjd $ * */ @@ -33,24 +35,8 @@ #include_next #define stat64 stat +#define fstat64 fstat -#define MAXOFFSET_T OFF_MAX - -#ifndef _KERNEL -#include +#define SF_NOUNLINK 0x00100000 -static __inline int -fstat64(int fd, struct stat *sb) -{ - int ret; - - ret = fstat(fd, sb); - if (ret == 0) { - if (S_ISCHR(sb->st_mode)) - (void)ioctl(fd, DIOCGMEDIASIZE, &sb->st_size); - } - return (ret); -} #endif - -#endif /* !_COMPAT_OPENSOLARIS_SYS_STAT_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/string.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/string.h --- /tmp/out/external/cddl/osnet/sys/sys/string.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/string.h 2017-06-09 18:16:54.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: string.h,v 1.4 2010/12/14 01:01:41 haad Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,17 +25,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/string.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_STRING_H_ #define _OPENSOLARIS_SYS_STRING_H_ -#include - char *strpbrk(const char *, const char *); -void strident_canon(char *, size_t); -char *kmem_asprintf(const char *, ...); -void strfree(char *); +void strident_canon(char *s, size_t n); +void numtos(unsigned long num, char *s); #endif /* _OPENSOLARIS_SYS_STRING_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sunddi.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sunddi.h --- /tmp/out/external/cddl/osnet/sys/sys/sunddi.h 2015-02-03 23:24:06.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sunddi.h 2017-06-09 22:41:17.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sunddi.h,v 1.4 2010/05/19 18:01:26 haad Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -32,14 +34,16 @@ #ifdef _KERNEL #include -#include +#include #include -#define ddi_driver_major(zfs_dip) (0) -#define ddi_copyin(from, to, size, flag) \ - (copyin((from), (to), (size)), 0) -#define ddi_copyout(from, to, size, flag) \ - (copyout((from), (to), (size)), 0) +#ifndef _KERNEL +#define ddi_copyin(from, to, size, flag) (bcopy((from), (to), (size)), 0) +#define ddi_copyout(from, to, size, flag) (bcopy((from), (to), (size)), 0) +#else +#define ddi_copyin(from, to, size, flag) (ioctl_copyin((flag), (from), (to), (size))) +#define ddi_copyout(from, to, size, flag) (ioctl_copyout((flag), (from), (to), (size))) +#endif int ddi_strtol(const char *str, char **nptr, int base, long *result); int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result); int ddi_strtoull(const char *str, char **nptr, int base, @@ -63,6 +67,17 @@ _ddi_log_sysevent((vendor), (class_name), (subclass_name), \ (attr_list), (eidp), (flag)) + +#define DDI_PSEUDO "" + +typedef void *dev_info_t; +int ddi_create_minor_node(dev_info_t *, char *, int, + minor_t, char *, int); +void ddi_remove_minor_node(dev_info_t *, char *); + +#define ddi_name_to_major(name) devsw_name2blk(name, NULL, 0) +#define ddi_prop_update_string(a, b, c, d) DDI_SUCCESS + #endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_SUNDDI_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: sunldi.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/sysmacros.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sysmacros.h --- /tmp/out/external/cddl/osnet/sys/sys/sysmacros.h 2015-07-06 08:44:48.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/sysmacros.h 2017-04-22 10:55:06.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: sysmacros.h,v 1.7 2016/02/01 02:12:55 christos Exp $ */ + /* * CDDL HEADER START * @@ -31,10 +33,7 @@ #define _SYS_SYSMACROS_H #include -#include -#if defined(__FreeBSD__) && defined(_KERNEL) -#include -#endif +#include #ifdef __cplusplus extern "C" { @@ -46,7 +45,9 @@ /* * Disk blocks (sectors) and bytes. */ +#ifndef dtob #define dtob(DD) ((DD) << DEV_BSHIFT) +#endif #define btod(BB) (((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT) #define btodt(BB) ((BB) >> DEV_BSHIFT) #define lbtod(BB) (((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT) @@ -78,6 +79,8 @@ #endif /* _KERNEL */ +#ifndef __NetBSD__ + /* * WARNING: The device number macros defined here should not be used by device * drivers or user software. Device drivers should use the device functions @@ -115,7 +118,6 @@ #define L_MAXMIN L_MAXMIN32 #endif -#ifdef illumos #ifdef _KERNEL /* major part of a device internal to the kernel */ @@ -139,16 +141,18 @@ /* major part of a device external from the kernel (same as emajor below) */ +#undef major #define major(x) (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ) /* minor part of a device external from the kernel (same as eminor below) */ - +#undef minor #define minor(x) (minor_t)((x) & O_MAXMIN) #endif /* _KERNEL */ /* create old device number */ +#undef makedev #define makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN)) /* make an new device number */ @@ -175,7 +179,6 @@ #define getemajor(x) (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \ NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ)) #define geteminor(x) (minor_t)((x) & L_MAXMIN) -#endif /* illumos */ /* * These are versions of the kernel routines for compressing and @@ -212,17 +215,25 @@ (dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \ ((x) & O_MAXMIN)) +#endif /* !__NetBSD__ */ + /* * Macro for checking power of 2 address alignment. */ #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) +#ifndef __NetBSD__ + /* * Macros for counting and rounding. */ +#undef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) +#undef roundup #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#endif /* !__NetBSD__ */ + /* * Macro to determine if value is a power of 2 */ @@ -336,6 +347,7 @@ * because if a field crosses a byte boundary it's not likely to be meaningful * without reassembly in its nonnative endianness. */ +#ifdef notdef #if defined(_BIT_FIELDS_LTOH) #define DECL_BITFIELD2(_a, _b) \ uint8_t _a, _b @@ -369,6 +381,7 @@ #else #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined #endif /* _BIT_FIELDS_LTOH */ +#endif #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) @@ -397,19 +410,19 @@ h += 32; i >>= 32; } #endif - if (i & 0xffff0000) { + if (i & 0xffff0000ul) { h += 16; i >>= 16; } - if (i & 0xff00) { + if (i & 0xff00ul) { h += 8; i >>= 8; } - if (i & 0xf0) { + if (i & 0xf0ul) { h += 4; i >>= 4; } - if (i & 0xc) { + if (i & 0xcul) { h += 2; i >>= 2; } - if (i & 0x2) { + if (i & 0x2ul) { h += 1; } return (h); diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/systm.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/systm.h --- /tmp/out/external/cddl/osnet/sys/sys/systm.h 2016-03-26 19:52:21.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/systm.h 2017-06-09 22:48:07.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: systm.h,v 1.4 2013/06/21 16:22:46 christos Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -26,24 +57,29 @@ * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/systm.h 296510 2016-03-08 17:27:13Z mav $ */ +#include + #ifndef _OPENSOLARIS_SYS_SYSTM_H_ #define _OPENSOLARIS_SYS_SYSTM_H_ #ifdef _KERNEL +#define __HIDE_DELAY +#include_next +#endif #include -#include_next +#ifdef _KERNEL #include #define PAGESIZE PAGE_SIZE #define PAGEOFFSET (PAGESIZE - 1) #define PAGEMASK (~PAGEOFFSET) -#define delay(x) pause("soldelay", (x)) +#define delay(x) kpause("soldelay", false, (x), NULL) -#define timeout_generic(type, fn, arg, t, r, f) \ - timeout(fn, arg, t / (NANOSEC/hz) + 1) +#define timeout_generic(type, fn, arg, t, r, f) \ + panic("timeout_generic() not implemented") #endif /* _KERNEL */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: thread.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/time.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/time.h --- /tmp/out/external/cddl/osnet/sys/sys/time.h 2016-03-26 19:52:21.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/time.h 2017-06-09 22:50:50.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: time.h,v 1.7 2016/04/28 11:45:02 christos Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -57,6 +59,8 @@ #define NSEC_TO_TICK(nsec) ((nsec) / (NANOSEC / hz)) #ifdef _KERNEL +#include + static __inline hrtime_t gethrtime(void) { @@ -72,20 +76,32 @@ #define gethrestime(ts) getnanotime(ts) #define gethrtime_waitfree() gethrtime() -extern int nsec_per_tick; /* nanoseconds per clock tick */ +static inline int64_t +ddi_get_lbolt64(void) +{ + struct timespec ts; + const int hz = 100; + + getnanouptime(&ts); + return (int64_t)(SEC_TO_TICK(ts.tv_sec) + NSEC_TO_TICK(ts.tv_nsec)); +} -#define ddi_get_lbolt64() \ - (int64_t)(((getsbinuptime() >> 16) * hz) >> 16) #define ddi_get_lbolt() (clock_t)ddi_get_lbolt64() #else +int clock_gettime(clockid_t, struct timespec *) + __RENAME(__clock_gettime50); + static __inline hrtime_t gethrtime(void) { struct timespec ts; - clock_gettime(CLOCK_UPTIME,&ts); + clock_gettime(CLOCK_REALTIME,&ts); return (((u_int64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } +#define ddi_get_lbolt() (gethrtime() >> 23) +#define ddi_get_lbolt64() (gethrtime() >> 23) + #endif /* _KERNEL */ #endif /* !_OPENSOLARIS_SYS_TIME_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/types.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/types.h --- /tmp/out/external/cddl/osnet/sys/sys/types.h 2016-05-31 04:20:12.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/types.h 2017-06-09 22:54:11.000000000 -0700 @@ -1,3 +1,34 @@ +/* $NetBSD: types.h,v 1.17 2016/02/01 02:12:55 christos Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -32,67 +63,35 @@ /* * This is a bag of dirty hacks to keep things compiling. */ - +#define longlong_t __hide_longlong_t +#define u_longlong_t __hide_u_longlong_t +#ifndef _KERNEL +#include +#else #include - -#ifdef _KERNEL -typedef int64_t clock_t; -#define _CLOCK_T_DECLARED #endif - +#ifndef HAVE_NBTOOLS_CONFIG_H +#ifdef _NETBSD_SOURCE #include_next - -#define MAXNAMELEN 256 - -typedef struct timespec timestruc_t; -typedef struct timespec timespec_t; -typedef u_int uint_t; -typedef u_char uchar_t; -typedef u_short ushort_t; -typedef u_long ulong_t; -typedef long long longlong_t; -typedef unsigned long long u_longlong_t; -#ifndef _OFF64_T_DECLARED -#define _OFF64_T_DECLARED -typedef off_t off64_t; +#include_next +#else +#define _NETBSD_SOURCE +#include_next +#include_next +#undef _NETBSD_SOURCE +#endif #endif -typedef id_t taskid_t; -typedef id_t projid_t; -typedef id_t poolid_t; -typedef id_t zoneid_t; -typedef id_t ctid_t; -typedef mode_t o_mode_t; -typedef uint64_t pgcnt_t; -typedef u_int minor_t; - -#ifdef _KERNEL - -#define B_FALSE 0 -#define B_TRUE 1 - -typedef short index_t; -typedef off_t offset_t; -typedef long ptrdiff_t; /* pointer difference */ -typedef int64_t rlim64_t; -typedef int major_t; +#undef longlong_t +#undef u_longlong_t +typedef long long longlong_t; +typedef unsigned long long u_longlong_t; +#ifndef _KERNEL +#include #else -#ifdef NEED_SOLARIS_BOOLEAN -#if defined(__XOPEN_OR_POSIX) -typedef enum { _B_FALSE, _B_TRUE } boolean_t; -#else -typedef enum { B_FALSE, B_TRUE } boolean_t; -#endif /* defined(__XOPEN_OR_POSIX) */ +#include #endif -typedef longlong_t offset_t; -typedef u_longlong_t u_offset_t; -typedef uint64_t upad64_t; -typedef short pri_t; -typedef int32_t daddr32_t; -typedef int32_t time32_t; -typedef u_longlong_t diskaddr_t; - -#endif /* !_KERNEL */ +#include #endif /* !_OPENSOLARIS_SYS_TYPES_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: types32.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/uio.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/uio.h --- /tmp/out/external/cddl/osnet/sys/sys/uio.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/uio.h 2017-06-09 22:54:27.000000000 -0700 @@ -1,5 +1,36 @@ +/* $NetBSD: uio.h,v 1.9 2015/09/26 03:32:17 christos Exp $ */ + /*- - * Copyright (c) 2010 Pawel Jakub Dawidek + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +54,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/uio.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_UIO_H_ @@ -33,6 +64,9 @@ #include #ifndef _KERNEL +#include +#include + #define FOF_OFFSET 1 /* Use the offset in uio argument */ struct uio { @@ -46,44 +80,74 @@ }; #endif -#define uio_loffset uio_offset +struct xuio { + struct uio xu_uio; + int xuio_rw; + void *xuio_priv; +}; + +#define XUIO_XUZC_PRIV(xuio) ((xuio)->xuio_priv) +#define XUIO_XUZC_RW(xuio) ((xuio)->xuio_rw) typedef struct uio uio_t; +typedef struct xuio xuio_t; typedef struct iovec iovec_t; -typedef enum xuio_type { - UIOTYPE_ASYNCIO, - UIOTYPE_ZEROCOPY -} xuio_type_t; - -typedef struct xuio { - uio_t xu_uio; - - /* Extended uio fields */ - enum xuio_type xu_type; /* What kind of uio structure? */ - union { - struct { - int xu_zc_rw; - void *xu_zc_priv; - } xu_zc; - } xu_ext; -} xuio_t; +typedef enum uio_seg uio_seg_t; + +#define uio_loffset uio_offset -#define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv -#define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw +int uiomove(void *, size_t, struct uio *); -#ifdef BUILDING_ZFS static __inline int zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio) { - ASSERT(uio->uio_rw == dir); - return (uiomove(cp, (int)n, uio)); + assert(uio->uio_rw == dir); + return (uiomove(cp, n, uio)); +} + +static __inline int +zfs_uiocopy(void *cp, size_t n, enum uio_rw dir, uio_t *uio, size_t *cbytes) +{ + uio_t uio2; + int err; + + memcpy(&uio2, uio, sizeof(*uio)); + assert(uio->uio_rw == dir); + if ((err = uiomove(cp, n, &uio2)) != 0) + return err; + + *cbytes = uio->uio_resid - uio2.uio_resid; + + return (0); } -#define uiomove(cp, n, dir, uio) zfs_uiomove((cp), (n), (dir), (uio)) -int uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes); -void uioskip(uio_t *uiop, size_t n); -#endif /* BUILDING_ZFS */ +static __inline void +zfs_uioskip(uio_t *uiop, size_t n) +{ + if (n > (size_t)uiop->uio_resid) + return; + while (n != 0) { + iovec_t *iovp = uiop->uio_iov; + size_t niovb = MIN(iovp->iov_len, n); + + if (niovb == 0) { + uiop->uio_iov++; + uiop->uio_iovcnt--; + continue; + } + iovp->iov_base = (char *)iovp->iov_base + niovb; + uiop->uio_offset += niovb; + iovp->iov_len -= niovb; + uiop->uio_resid -= niovb; + n -= niovb; + } + +} + +#define uiomove(cp, n, dir, uio) zfs_uiomove((cp), (n), (dir), (uio)) +#define uiocopy(cp, n, dir, uio, cbytes) zfs_uiocopy((cp), (n), (dir), (uio), (cbytes)) +#define uioskip(uio, size) zfs_uioskip((uio), (size)) #endif /* !_OPENSOLARIS_SYS_UIO_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: va_list.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/varargs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/varargs.h --- /tmp/out/external/cddl/osnet/sys/sys/varargs.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/varargs.h 2017-06-09 22:56:56.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: varargs.h,v 1.4 2011/07/17 20:54:33 joerg Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,14 +25,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/varargs.h 177698 2008-03-28 22:16:18Z jb $ */ #ifndef _OPENSOLARIS_SYS_VARARGS_H_ #define _OPENSOLARIS_SYS_VARARGS_H_ #ifdef _KERNEL -#include +#include #else #include #endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/vfs.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vfs.h --- /tmp/out/external/cddl/osnet/sys/sys/vfs.h 2016-04-16 09:39:03.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vfs.h 2017-04-26 06:07:48.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: vfs.h,v 1.4 2010/02/28 14:45:47 haad Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -42,8 +44,7 @@ #define vfs_flag mnt_flag #define vfs_data mnt_data -#define vfs_count mnt_ref -#define vfs_fsid mnt_stat.f_fsid +#define vfs_count mnt_refcnt #define vfs_bsize mnt_stat.f_bsize #define vfs_resource mnt_stat.f_mntfromname @@ -54,7 +55,7 @@ #define VFS_NOSETUID MNT_NOSUID #define VFS_NOEXEC MNT_NOEXEC -#define fs_vscan(vp, cr, async) (0) +#define fs_vscan(vp, cr, async) (0) #define VROOT VV_ROOT @@ -86,6 +87,7 @@ #define VFS_DISPLAY 0x02 /* Turn off MO_NODISPLAY bit for opt */ #define VFS_NODISPLAY 0x04 /* Turn on MO_NODISPLAY bit for opt */ #define VFS_CREATEOPT 0x08 /* Create the opt if it's not there */ +#define VFS_UNMOUNTED 0x100 /* file system has been unmounted */ /* * Structure holding mount option strings for the mounted file system. @@ -95,6 +97,28 @@ mntopt_t *mo_list; /* list of mount options */ } mntopts_t; + /* + * Argument structure for mount(2). + * + * Flags are defined in . + * + * Note that if the MS_SYSSPACE bit is set in flags, the pointer fields in + * this structure are to be interpreted as kernel addresses. File systems + * should be prepared for this possibility. + */ +struct mounta { + char fspec[MAXNAMELEN - 1]; + char dataptr[MAXPATHLEN]; + char optptr[MAXPATHLEN]; + char *fstype; /* Unused */ + int mflag; + int datalen; + int optlen; + int flags; /* Unused */ +}; + +#define vfs_devismounted(dev) 0 + void vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg, int flags __unused); void vfs_clearmntopt(vfs_t *vfsp, const char *name); @@ -120,6 +144,13 @@ #define vfs_clear_feature(vfsp, feature) do { } while (0) #define vfs_has_feature(vfsp, feature) (0) +#define VFS_HOLD(vfsp) do { \ + /* XXXNETBSD nothing */ \ +} while (0) +#define VFS_RELE(vfsp) do { \ + /* XXXNETBSD nothing */ \ +} while (0) + #endif /* _KERNEL */ #endif /* _OPENSOLARIS_SYS_VFS_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: vm diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/vm.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vm.h --- /tmp/out/external/cddl/osnet/sys/sys/vm.h 2013-12-10 20:45:57.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vm.h 2017-05-02 09:57:33.000000000 -0700 @@ -1,61 +1,6 @@ -/*- - * Copyright (c) 2013 EMC Corp. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ +#ifndef _SYS_VFS_VM_H +#define _SYS_VFS_VM_H -#ifndef _OPENSOLARIS_SYS_VM_H_ -#define _OPENSOLARIS_SYS_VM_H_ +#include -#ifdef _KERNEL - -#include - -extern const int zfs_vm_pagerret_bad; -extern const int zfs_vm_pagerret_error; -extern const int zfs_vm_pagerret_ok; -extern const int zfs_vm_pagerput_sync; -extern const int zfs_vm_pagerput_inval; - -void zfs_vmobject_assert_wlocked(vm_object_t object); -void zfs_vmobject_wlock(vm_object_t object); -void zfs_vmobject_wunlock(vm_object_t object); - -static inline caddr_t -zfs_map_page(vm_page_t pp, struct sf_buf **sfp) -{ - *sfp = sf_buf_alloc(pp, 0); - return ((caddr_t)sf_buf_kva(*sfp)); -} - -static inline void -zfs_unmap_page(struct sf_buf *sf) -{ - sf_buf_free(sf); -} - -#endif /* _KERNEL */ - -#endif /* _OPENSOLARIS_SYS_VM_H_ */ +#endif diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/vnode.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vnode.h --- /tmp/out/external/cddl/osnet/sys/sys/vnode.h 2017-03-02 02:54:23.000000000 -0800 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/vnode.h 2017-06-27 17:41:28.000000000 -0700 @@ -1,3 +1,6 @@ + +/* $NetBSD: vnode.h,v 1.13 2015/04/09 05:32:53 riastradh Exp $ */ + /* * CDDL HEADER START * @@ -18,7 +21,6 @@ * * CDDL HEADER END */ - /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -36,391 +38,371 @@ * contributors. */ -#ifndef _SYS_VNODE_H -#define _SYS_VNODE_H - -#include_next - -#define IS_DEVVP(vp) \ - ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO) - -#define V_XATTRDIR 0x0000 /* attribute unnamed directory */ - -#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 2007 Pawel Jakub Dawidek + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/vnode.h 308691 2016-11-15 18:22:50Z alc $ + */ + +#ifndef _OPENSOLARIS_SYS_VNODE_H_ +#define _OPENSOLARIS_SYS_VNODE_H_ + +#ifdef _KERNEL + +struct vnode; +struct vattr; + +typedef struct vnode vnode_t; +typedef struct vattr vattr_t; +typedef enum vtype vtype_t; -/* - * Structure of all optional attributes. - */ -typedef struct xoptattr { - timestruc_t xoa_createtime; /* Create time of file */ - uint8_t xoa_archive; - uint8_t xoa_system; - uint8_t xoa_readonly; - uint8_t xoa_hidden; - uint8_t xoa_nounlink; - uint8_t xoa_immutable; - uint8_t xoa_appendonly; - uint8_t xoa_nodump; - uint8_t xoa_opaque; - uint8_t xoa_av_quarantined; - uint8_t xoa_av_modified; - uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; - uint8_t xoa_reparse; - uint64_t xoa_generation; - uint8_t xoa_offline; - uint8_t xoa_sparse; -} xoptattr_t; +#include +enum symfollow { NO_FOLLOW = NOFOLLOW }; /* - * The xvattr structure is really a variable length structure that - * is made up of: - * - The classic vattr_t (xva_vattr) - * - a 32 bit quantity (xva_mapsize) that specifies the size of the - * attribute bitmaps in 32 bit words. - * - A pointer to the returned attribute bitmap (needed because the - * previous element, the requested attribute bitmap) is variable lenth. - * - The requested attribute bitmap, which is an array of 32 bit words. - * Callers use the XVA_SET_REQ() macro to set the bits corresponding to - * the attributes that are being requested. - * - The returned attribute bitmap, which is an array of 32 bit words. - * File systems that support optional attributes use the XVA_SET_RTN() - * macro to set the bits corresponding to the attributes that are being - * returned. - * - The xoptattr_t structure which contains the attribute values - * - * xva_mapsize determines how many words in the attribute bitmaps. - * Immediately following the attribute bitmaps is the xoptattr_t. - * xva_getxoptattr() is used to get the pointer to the xoptattr_t - * section. - */ - -#define XVA_MAPSIZE 3 /* Size of attr bitmaps */ -#define XVA_MAGIC 0x78766174 /* Magic # for verification */ - -/* - * The xvattr structure is an extensible structure which permits optional - * attributes to be requested/returned. File systems may or may not support - * optional attributes. They do so at their own discretion but if they do - * support optional attributes, they must register the VFSFT_XVATTR feature - * so that the optional attributes can be set/retrived. - * - * The fields of the xvattr structure are: - * - * xva_vattr - The first element of an xvattr is a legacy vattr structure - * which includes the common attributes. If AT_XVATTR is set in the va_mask - * then the entire structure is treated as an xvattr. If AT_XVATTR is not - * set, then only the xva_vattr structure can be used. - * - * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification. - * - * xva_mapsize - Size of requested and returned attribute bitmaps. - * - * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the - * size of the array before it, xva_reqattrmap[], could change which means - * the location of xva_rtnattrmap[] could change. This will allow unbundled - * file systems to find the location of xva_rtnattrmap[] when the sizes change. - * - * xva_reqattrmap[] - Array of requested attributes. Attributes are - * represented by a specific bit in a specific element of the attribute - * map array. Callers set the bits corresponding to the attributes - * that the caller wants to get/set. - * - * xva_rtnattrmap[] - Array of attributes that the file system was able to - * process. Not all file systems support all optional attributes. This map - * informs the caller which attributes the underlying file system was able - * to set/get. (Same structure as the requested attributes array in terms - * of each attribute corresponding to specific bits and array elements.) - * - * xva_xoptattrs - Structure containing values of optional attributes. - * These values are only valid if the corresponding bits in xva_reqattrmap - * are set and the underlying file system supports those attributes. - */ -typedef struct xvattr { - vattr_t xva_vattr; /* Embedded vattr structure */ - uint32_t xva_magic; /* Magic Number */ - uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ - uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ - uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ - uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ - xoptattr_t xva_xoptattrs; /* Optional attributes */ -} xvattr_t; - -/* - * Attributes of interest to the caller of setattr or getattr. - */ -#define AT_TYPE 0x00001 -#define AT_MODE 0x00002 -#define AT_UID 0x00004 -#define AT_GID 0x00008 -#define AT_FSID 0x00010 -#define AT_NODEID 0x00020 -#define AT_NLINK 0x00040 -#define AT_SIZE 0x00080 -#define AT_ATIME 0x00100 -#define AT_MTIME 0x00200 -#define AT_CTIME 0x00400 -#define AT_RDEV 0x00800 -#define AT_BLKSIZE 0x01000 -#define AT_NBLOCKS 0x02000 -/* 0x04000 */ /* unused */ -#define AT_SEQ 0x08000 -/* - * If AT_XVATTR is set then there are additional bits to process in - * the xvattr_t's attribute bitmap. If this is not set then the bitmap - * MUST be ignored. Note that this bit must be set/cleared explicitly. - * That is, setting AT_ALL will NOT set AT_XVATTR. + * We'll use the two-parameter FreeBSD VOP_UNLOCK() in ZFS code. */ -#define AT_XVATTR 0x10000 -#define AT_ALL (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\ - AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\ - AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) - -#define AT_STAT (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\ - AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE) +#define VOP_UNLOCK __hide_VOP_UNLOCK +#include_next +/* verify that the real definition is what we expect */ +int __hide_VOP_UNLOCK(struct vnode *); +#undef VOP_UNLOCK + +int VOP_UNLOCK(struct vnode *, int); + +#include +#include +#include +#include +#include + +#include + +typedef int (**vnodeops_t)(void *); + +#define vop_fid vop_vptofh +#define vop_fid_args vop_vptofh_args +#define a_fid a_fhp + +#define v_count v_usecount +#define v_object v_uobj + +struct vop_vptofh_args { + struct vnode *a_vp; + struct fid *a_fid; +}; + +#define IS_XATTRDIR(vp) (0) + +#define v_lock v_interlock + +#define SAVENAME 0 + +int vn_is_readonly(vnode_t *); + +#define vn_vfswlock(vp) (0) +#define vn_vfsunlock(vp) do { } while (0) +#define vn_ismntpt(vp) ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL) +#define vn_mountedvfs(vp) ((vp)->v_mountedhere) +#define vn_has_cached_data(vp) ((vp)->v_uobj.uo_npages != 0) +#define vn_exists(vp) do { } while (0) +#define vn_invalid(vp) do { } while (0) +#define vn_free(vp) do { } while (0) +#define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0) +#define vn_matchops(vp, vops) ((vp)->v_op == &(vops)) + +#define VN_HOLD(v) vref(v) +#define VN_RELE(v) \ +do { \ + if ((v)->v_usecount == 0) { \ + printf("VN_RELE(%s,%d): %p unused\n", __FILE__, __LINE__, v); \ + vprint("VN_RELE", (v)); \ + panic("VN_RELE"); \ + } else { \ + vrele(v); \ + } \ +} while (/*CONSTCOND*/0) +#define VN_URELE(v) vput(v) +#undef VN_RELE_ASYNC +#define VN_RELE_ASYNC(vp, taskq) vrele_async((vp)) +#define VN_RELE_CLEANER(vp, taskq) /* nothing */ + +#define vnevent_create(vp, ct) do { } while (0) +#define vnevent_link(vp, ct) do { } while (0) +#define vnevent_remove(vp, dvp, name, ct) do { } while (0) +#define vnevent_rmdir(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_src(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_dest(vp, dvp, name, ct) do { } while (0) +#define vnevent_rename_dest_dir(vp, ct) do { } while (0) + +#define specvp(vp, rdev, type, cr) (VN_HOLD(vp), (vp)) +#define MANDMODE(mode) (0) +#define MANDLOCK(vp, mode) (0) +#define chklock(vp, op, offset, size, mode, ct) (0) +#define cleanlocks(vp, pid, foo) do { } while (0) +#define cleanshares(vp, pid) do { } while (0) + +/* + * We will use va_spare is place of Solaris' va_mask. + * This field is initialized in zfs_setattr(). + */ +#define va_mask va_spare +/* TODO: va_fileid is shorter than va_nodeid !!! */ +#define va_nodeid va_fileid +/* TODO: This field needs conversion! */ +#define va_nblocks va_bytes +#define va_blksize va_blocksize +#define va_seq va_gen + +#define EXCL 0 + +#define ACCESSED (AT_ATIME) +#define STATE_CHANGED (AT_CTIME) +#define CONTENT_MODIFIED (AT_MTIME | AT_CTIME) + +static inline void +vattr_init_mask(vattr_t *vap) +{ + + vap->va_mask = 0; + + if (vap->va_type != VNON) + vap->va_mask |= AT_TYPE; + if (vap->va_uid != (uid_t)VNOVAL) + vap->va_mask |= AT_UID; + if (vap->va_gid != (gid_t)VNOVAL) + vap->va_mask |= AT_GID; + if (vap->va_size != (u_quad_t)VNOVAL) + vap->va_mask |= AT_SIZE; + if (vap->va_atime.tv_sec != VNOVAL) + vap->va_mask |= AT_ATIME; + if (vap->va_mtime.tv_sec != VNOVAL) + vap->va_mask |= AT_MTIME; + if (vap->va_mode != (mode_t)VNOVAL) + vap->va_mask |= AT_MODE; +} -#define AT_TIMES (AT_ATIME|AT_MTIME|AT_CTIME) +#define FCREAT O_CREAT +#define FTRUNC O_TRUNC +#define FSYNC FFSYNC +#define FOFFMAX 0x00 + +static inline int +zfs_vn_open(const char *pnamep, enum uio_seg seg, int filemode, int createmode, + vnode_t **vpp, enum create crwhy, mode_t umask) +{ + struct pathbuf *pb; + struct nameidata nd; + int error; + + ASSERT(seg == UIO_SYSSPACE); + ASSERT((filemode & (FWRITE | FCREAT | FTRUNC | FOFFMAX)) != 0); + ASSERT(crwhy == CRCREAT); + ASSERT(umask == 0); + + pb = pathbuf_create(pnamep); + NDINIT(&nd, LOOKUP, NOFOLLOW, pb); + error = vn_open(&nd, filemode, createmode); + if (error == 0) { + VOP_UNLOCK(nd.ni_vp, 0); + *vpp = nd.ni_vp; + } + pathbuf_destroy(pb); + return (error); +} +#define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask) \ + zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask)) -#define AT_NOSET (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\ - AT_BLKSIZE|AT_NBLOCKS|AT_SEQ) +#define vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy, umask, rootvn, unk) \ + zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask)) -/* - * Attribute bits used in the extensible attribute's (xva's) attribute - * bitmaps. Note that the bitmaps are made up of a variable length number - * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n" - * is the element in the bitmap (starting at 1). This convention is for - * the convenience of the maintainer to keep track of which element each - * attribute belongs to. - * - * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS - * MUST USE THE XAT_* DEFINES. - */ -#define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */ -#define XAT0_CREATETIME 0x00000001 /* Create time of file */ -#define XAT0_ARCHIVE 0x00000002 /* Archive */ -#define XAT0_SYSTEM 0x00000004 /* System */ -#define XAT0_READONLY 0x00000008 /* Readonly */ -#define XAT0_HIDDEN 0x00000010 /* Hidden */ -#define XAT0_NOUNLINK 0x00000020 /* Nounlink */ -#define XAT0_IMMUTABLE 0x00000040 /* immutable */ -#define XAT0_APPENDONLY 0x00000080 /* appendonly */ -#define XAT0_NODUMP 0x00000100 /* nodump */ -#define XAT0_OPAQUE 0x00000200 /* opaque */ -#define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */ -#define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */ -#define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */ -#define XAT0_REPARSE 0x00002000 /* FS reparse point */ -#define XAT0_GEN 0x00004000 /* object generation number */ -#define XAT0_OFFLINE 0x00008000 /* offline */ -#define XAT0_SPARSE 0x00010000 /* sparse */ - -#define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \ - XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \ - XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \ - XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE) - -/* Support for XAT_* optional attributes */ -#define XVA_MASK 0xffffffff /* Used to mask off 32 bits */ -#define XVA_SHFT 32 /* Used to shift index */ +#define RLIM64_INFINITY 0 +static inline int +zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len, + offset_t offset, enum uio_seg seg, int ioflag, uint64_t ulimit, cred_t *cr, + ssize_t *residp) +{ + int error; + size_t resid; + + ASSERT(rw == UIO_WRITE); + ASSERT(ioflag == 0); + ASSERT(ulimit == RLIM64_INFINITY); + + ioflag = IO_UNIT; + + error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, + &resid, curlwp); + if (residp != NULL) + *residp = (ssize_t)resid; + return (error); +} +#define vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \ + zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp)) -/* - * Used to pry out the index and attribute bits from the XAT_* attributes - * defined below. Note that we're masking things down to 32 bits then - * casting to uint32_t. - */ -#define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK)) -#define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK)) +static inline int +zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr) +{ + int error; + + ASSERT(flag == FSYNC); + + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = VOP_FSYNC(vp, cr, FSYNC_WAIT, 0, 0); + VOP_UNLOCK(vp, 0); + return (error); +} +#define VOP_FSYNC(vp, flag, cr, unk) zfs_vop_fsync((vp), (flag), (cr)) -/* - * The following defines present a "flat namespace" so that consumers don't - * need to keep track of which element belongs to which bitmap entry. - * - * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER - */ -#define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME) -#define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE) -#define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM) -#define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY) -#define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN) -#define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK) -#define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE) -#define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY) -#define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP) -#define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE) -#define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED) -#define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED) -#define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP) -#define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE) -#define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN) -#define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE) -#define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE) +static inline int +zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr) +{ -/* - * The returned attribute map array (xva_rtnattrmap[]) is located past the - * requested attribute map array (xva_reqattrmap[]). Its location changes - * when the array sizes change. We use a separate pointer in a known location - * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is - * set in xva_init() - */ -#define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp) + ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX)); + ASSERT(count == 1); + ASSERT(offset == 0); -/* - * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap - * of requested attributes (xva_reqattrmap[]). - */ -#define XVA_SET_REQ(xvap, attr) { \ - ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ - ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ + return (vn_close(vp, flag, cr)); } -/* - * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap - * of requested attributes (xva_reqattrmap[]). - */ -#define XVA_CLR_REQ(xvap, attr) { \ - ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ - ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr); \ +#define VOP_CLOSE(vp, oflags, count, offset, cr, unk) \ + zfs_vop_close((vp), (oflags), (count), (offset), (cr)) + +static inline int +zfs_vop_getattr(vnode_t *vp, vattr_t *ap, int flag, cred_t *cr) +{ + int error; + + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = VOP_GETATTR(vp, ap, cr); + VOP_UNLOCK(vp, 0); + return (error); } +#define VOP_GETATTR(vp, ap, flag, cr, unk) zfs_vop_getattr((vp), (ap), (flag), (cr)) -/* - * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap - * of returned attributes (xva_rtnattrmap[]). - */ -#define XVA_SET_RTN(xvap, attr) { \ - ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \ - ASSERT((xvap)->xva_magic == XVA_MAGIC); \ - (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr); \ +static inline int +zfs_vop_seek(vnode_t *vp, off_t off, off_t *offp) +{ + int error; + + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + error = VOP_SEEK(vp, off, *offp, CRED()); + VOP_UNLOCK(vp, 0); + return (error); } +#define VOP_SEEK(vp, off, offp, unk) zfs_vop_seek(vp, off, offp) -/* - * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[]) - * to see of the corresponding attribute bit is set. If so, returns non-zero. - */ -#define XVA_ISSET_REQ(xvap, attr) \ - ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ - ((xvap)->xva_magic == XVA_MAGIC) && \ - ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ - ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) +#define B_INVAL BC_INVAL -/* - * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[]) - * to see of the corresponding attribute bit is set. If so, returns non-zero. - */ -#define XVA_ISSET_RTN(xvap, attr) \ - ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \ - ((xvap)->xva_magic == XVA_MAGIC) && \ - ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \ - ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0) +static inline int +zfs_vop_putpage(vnode_t *vp, off_t off, size_t len, int flag) +{ + int nbflag; + + nbflag = 0; + if (len == 0) { + nbflag |= PGO_ALLPAGES; + } + if ((flag & B_ASYNC) == 0) { + nbflag |= PGO_SYNCIO; + } + if ((flag & B_INVAL) != 0) { + nbflag |= PGO_FREE; + } else { + nbflag |= PGO_CLEANIT; + } -#define MODEMASK 07777 /* mode bits plus permission bits */ -#define PERMMASK 00777 /* permission bits */ + mutex_enter(vp->v_interlock); + return VOP_PUTPAGES(vp, off, len, nbflag); +} +#define VOP_PUTPAGE(vp, off, len, flag, cr, ct) zfs_vop_putpage((vp), (off), (len), (flag)) -/* - * VOP_ACCESS flags - */ -#define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */ +static inline int +vn_rename(char *from, char *to, enum uio_seg seg) +{ -/* - * Flags for vnode operations. - */ -enum rm { RMFILE, RMDIRECTORY }; /* rm or rmdir (remove) */ -enum create { CRCREAT, CRMKNOD, CRMKDIR }; /* reason for create */ + ASSERT(seg == UIO_SYSSPACE); -/* - * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations - */ + return (do_sys_rename(from, to, seg, 0)); +} -typedef struct vsecattr { - uint_t vsa_mask; /* See below */ - int vsa_aclcnt; /* ACL entry count */ - void *vsa_aclentp; /* pointer to ACL entries */ - int vsa_dfaclcnt; /* default ACL entry count */ - void *vsa_dfaclentp; /* pointer to default ACL entries */ - size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ - uint_t vsa_aclflags; /* ACE ACL flags */ -} vsecattr_t; - -/* vsa_mask values */ -#define VSA_ACL 0x0001 -#define VSA_ACLCNT 0x0002 -#define VSA_DFACL 0x0004 -#define VSA_DFACLCNT 0x0008 -#define VSA_ACE 0x0010 -#define VSA_ACECNT 0x0020 -#define VSA_ACE_ALLTYPES 0x0040 -#define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */ +static inline int +vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag) +{ -/* - * Structure used by various vnode operations to determine - * the context (pid, host, identity) of a caller. - * - * The cc_caller_id is used to identify one or more callers who invoke - * operations, possibly on behalf of others. For example, the NFS - * server could have it's own cc_caller_id which can be detected by - * vnode/vfs operations or (FEM) monitors on those operations. New - * caller IDs are generated by fs_new_caller_id(). - */ -typedef struct caller_context { - pid_t cc_pid; /* Process ID of the caller */ - int cc_sysid; /* System ID, used for remote calls */ - u_longlong_t cc_caller_id; /* Identifier for (set of) caller(s) */ - ulong_t cc_flags; -} caller_context_t; - -struct taskq; + ASSERT(seg == UIO_SYSSPACE); + ASSERT(dirflag == RMFILE); -/* - * Flags for VOP_LOOKUP - * - * Defined in file.h, but also possible, FIGNORECASE and FSEARCH - * - */ -#define LOOKUP_DIR 0x01 /* want parent dir vp */ -#define LOOKUP_XATTR 0x02 /* lookup up extended attr dir */ -#define CREATE_XATTR_DIR 0x04 /* Create extended attr dir */ -#define LOOKUP_HAVE_SYSATTR_DIR 0x08 /* Already created virtual GFS dir */ + return (do_sys_unlink(fnamep, seg)); +} /* - * Flags for VOP_READDIR + * VOP_ACCESS flags */ -#define V_RDDIR_ENTFLAGS 0x01 /* request dirent flags */ -#define V_RDDIR_ACCFILTER 0x02 /* filter out inaccessible dirents */ +#define V_APPEND 0x2 /* want to do append only check */ -/* - * Public vnode manipulation functions. - */ -#ifdef _KERNEL +#define VV_NOSYNC 0 -void vn_rele_async(struct vnode *vp, struct taskq *taskq); +#define VI_LOCK(vp) mutex_enter((vp)->v_interlock) +#define VI_UNLOCK(vp) mutex_exit((vp)->v_interlock) -/* - * Extensible vnode attribute (xva) routines: - * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR) - * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t - */ -void xva_init(xvattr_t *); -xoptattr_t *xva_getxoptattr(xvattr_t *); /* Get ptr to xoptattr_t */ +#define VATTR_NULL(x) vattr_null(x) -#define VN_RELE_ASYNC(vp, taskq) { \ - vn_rele_async(vp, taskq); \ -} +#define getnewvnode_reserve(x) +#define getnewvnode_drop_reserve() +#define cache_purge_negative(vp) cache_purge(vp) #endif /* _KERNEL */ -/* - * Flags to VOP_SETATTR/VOP_GETATTR. - */ -#define ATTR_UTIME 0x01 /* non-default utime(2) request */ -#define ATTR_EXEC 0x02 /* invocation from exec(2) */ -#define ATTR_COMM 0x04 /* yield common vp attributes */ -#define ATTR_HINT 0x08 /* information returned will be `hint' */ -#define ATTR_REAL 0x10 /* yield attributes of the real vp */ -#define ATTR_NOACLCHECK 0x20 /* Don't check ACL when checking permissions */ -#define ATTR_TRIGGER 0x40 /* Mount first if vnode is a trigger mount */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_VNODE_H */ +#endif /* _OPENSOLARIS_SYS_VNODE_H_ */ diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/zfs_context.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/zfs_context.h --- /tmp/out/external/cddl/osnet/sys/sys/zfs_context.h 2016-04-16 09:38:37.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/zfs_context.h 2017-06-16 09:42:28.000000000 -0700 @@ -1,9 +1,12 @@ +/* $NetBSD: zfs_context.h,v 1.18 2017/01/10 19:20:35 christos Exp $ */ + /* * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,31 +22,36 @@ * CDDL HEADER END */ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2015 by Delphix. All rights reserved. - * Copyright (c) 2012, Joyent, Inc. All rights reserved. - */ -/* - * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ #ifndef _SYS_ZFS_CONTEXT_H #define _SYS_ZFS_CONTEXT_H +#pragma ident "%Z%%M% %I% %E% SMI" + #ifdef __cplusplus extern "C" { #endif -#define _SYS_MUTEX_H -#define _SYS_RWLOCK_H -#define _SYS_CONDVAR_H +#include + +#ifndef _KERNEL + +#define _SYS_MUTEX_H +#define _SYS_MUTEX_H_ +#define _SYS_RWLOCK_H +#define _SYS_RWLOCK_H_ +#define _SYS_CONDVAR_H +#define _SYS_CONDVAR_H_ #define _SYS_SYSTM_H +#define _SYS_SYSTM_H_ #define _SYS_T_LOCK_H #define _SYS_VNODE_H #define _SYS_VFS_H #define _SYS_SUNDDI_H #define _SYS_CALLB_H -#define _SYS_SCHED_H_ #include #include @@ -57,7 +65,6 @@ #include #include #include -#include #include #include #include @@ -65,37 +72,42 @@ #include #include #include -#include +#include + #include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include #include +#include +#include + +extern void panic(const char *, ...); + +#include + #include -#include -#include -#include -#ifdef illumos -#include "zfs.h" + +#ifndef ABS +#define ABS(a) ((a) < 0 ? -(a) : (a)) #endif -#define ZFS_EXPORTS_PATH "/etc/zfs/exports" +extern int aok; /* * Debugging @@ -124,98 +136,44 @@ extern void dprintf_setup(int *argc, char **argv); #endif /* ZFS_DEBUG */ -extern void cmn_err(int, const char *, ...); -extern void vcmn_err(int, const char *, __va_list); -extern void panic(const char *, ...); -extern void vpanic(const char *, __va_list); +/* extern void cmn_err(int, const char *, ...); +extern void vcmn_err(int, const char *, va_list); */ +/* extern void vpanic(const char *, va_list); */ #define fm_panic panic -extern int aok; - /* - * DTrace SDT probes have different signatures in userland than they do in - * the kernel. If they're being used in kernel code, re-define them out of + * Dtrace SDT probes have different signatures in userland than they do in + * kernel. If they're being used in kernel code, re-define them out of * existence for their counterparts in libzpool. - * - * Here's an example of how to use the set-error probes in userland: - * zfs$target:::set-error /arg0 == EBUSY/ {stack();} - * - * Here's an example of how to use DTRACE_PROBE probes in userland: - * If there is a probe declared as follows: - * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn); - * Then you can use it as follows: - * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/ - * {printf("%u %p\n", arg1, arg2);} */ -#ifdef DTRACE_PROBE -#undef DTRACE_PROBE -#endif /* DTRACE_PROBE */ -#ifdef illumos -#define DTRACE_PROBE(a) \ - ZFS_PROBE0(#a) -#endif - #ifdef DTRACE_PROBE1 #undef DTRACE_PROBE1 +#define DTRACE_PROBE1(a, b, c) ((void)0) #endif /* DTRACE_PROBE1 */ -#ifdef illumos -#define DTRACE_PROBE1(a, b, c) \ - ZFS_PROBE1(#a, (unsigned long)c) -#endif #ifdef DTRACE_PROBE2 #undef DTRACE_PROBE2 +#define DTRACE_PROBE2(a, b, c, d, e) ((void)0) #endif /* DTRACE_PROBE2 */ -#ifdef illumos -#define DTRACE_PROBE2(a, b, c, d, e) \ - ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e) -#endif #ifdef DTRACE_PROBE3 #undef DTRACE_PROBE3 +#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) #endif /* DTRACE_PROBE3 */ -#ifdef illumos -#define DTRACE_PROBE3(a, b, c, d, e, f, g) \ - ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g) -#endif #ifdef DTRACE_PROBE4 #undef DTRACE_PROBE4 -#endif /* DTRACE_PROBE4 */ -#ifdef illumos -#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \ - ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \ - (unsigned long)i) -#endif - -#ifdef illumos -/* - * We use the comma operator so that this macro can be used without much - * additional code. For example, "return (EINVAL);" becomes - * "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated - * twice, so it should not have side effects (e.g. something like: - * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice). - */ -#define SET_ERROR(err) (ZFS_SET_ERROR(err), err) -#else /* !illumos */ - -#define DTRACE_PROBE(a) ((void)0) -#define DTRACE_PROBE1(a, b, c) ((void)0) -#define DTRACE_PROBE2(a, b, c, d, e) ((void)0) -#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) - -#define SET_ERROR(err) (err) -#endif /* !illumos */ +#endif /* DTRACE_PROBE4 */ /* * Threads */ #define curthread ((void *)(uintptr_t)thr_self()) -#define kpreempt(x) sched_yield() +#define kpreempt(x) yield() typedef struct kthread kthread_t; @@ -244,6 +202,7 @@ /* * Mutexes */ + typedef struct kmutex { void *m_owner; boolean_t initialized; @@ -267,13 +226,14 @@ #define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp)) #define mutex_destroy(mp) zmutex_destroy((kmutex_t *)(mp)) +#define mutex_enter(mp) zmutex_enter(mp) +#define mutex_exit(mp) zmutex_exit(mp) #define mutex_owned(mp) zmutex_owned((kmutex_t *)(mp)) extern void zmutex_init(kmutex_t *mp); extern void zmutex_destroy(kmutex_t *mp); -extern int zmutex_owned(kmutex_t *mp); -extern void mutex_enter(kmutex_t *mp); -extern void mutex_exit(kmutex_t *mp); +extern void zmutex_enter(kmutex_t *mp); +extern void zmutex_exit(kmutex_t *mp); extern int mutex_tryenter(kmutex_t *mp); extern void *mutex_owner(kmutex_t *mp); @@ -281,7 +241,7 @@ * RW locks */ typedef struct krwlock { - int rw_count; + int rw_count; void *rw_owner; boolean_t initialized; rwlock_t rw_lock; @@ -293,12 +253,15 @@ #define RW_WRITER 1 #define RW_DEFAULT USYNC_THREAD +#define RW_LOCK_HELD(x) rw_lock_held(x) +#define RW_WRITE_HELD(x) rw_write_held(x) +#define RW_READ_HELD(x) rw_read_held(x) + #undef RW_READ_HELD #define RW_READ_HELD(x) ((x)->rw_owner == NULL && (x)->rw_count > 0) #undef RW_WRITE_HELD #define RW_WRITE_HELD(x) ((x)->rw_owner == curthread) -#define RW_LOCK_HELD(x) rw_lock_held(x) #undef RW_LOCK_HELD #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x)) @@ -310,14 +273,15 @@ extern int rw_tryupgrade(krwlock_t *rwlp); extern void rw_exit(krwlock_t *rwlp); extern int rw_lock_held(krwlock_t *rwlp); +extern int rw_write_held(krwlock_t *rwlp); +extern int rw_read_held(krwlock_t *rwlp); #define rw_downgrade(rwlp) do { } while (0) extern uid_t crgetuid(cred_t *cr); -extern uid_t crgetruid(cred_t *cr); extern gid_t crgetgid(cred_t *cr); extern int crgetngroups(cred_t *cr); extern gid_t *crgetgroups(cred_t *cr); - + /* * Condition variables */ @@ -355,7 +319,7 @@ #define kmem_alloc(_s, _f) umem_alloc(_s, _f) #define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) #define kmem_free(_b, _s) umem_free(_b, _s) -#define kmem_size() (physmem * PAGESIZE) +#define kmem_size() ((uint64_t)physmem * PAGESIZE) #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) #define kmem_cache_destroy(_c) umem_cache_destroy(_c) @@ -364,18 +328,12 @@ #define kmem_debugging() 0 #define kmem_cache_reap_now(_c) /* nothing */ #define kmem_cache_set_move(_c, _cb) /* nothing */ +#define vmem_qcache_reap(_v) /* nothing */ #define POINTER_INVALIDATE(_pp) /* nothing */ #define POINTER_IS_VALID(_p) 0 typedef umem_cache_t kmem_cache_t; - -typedef enum kmem_cbrc { - KMEM_CBRC_YES, - KMEM_CBRC_NO, - KMEM_CBRC_LATER, - KMEM_CBRC_DONT_NEED, - KMEM_CBRC_DONT_KNOW -} kmem_cbrc_t; +typedef struct vmem vmem_t; /* * Task queues @@ -394,11 +352,11 @@ #define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */ -#define TASKQ_PREPOPULATE 0x0001 -#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ -#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ -#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ -#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ +#define TASKQ_PREPOPULATE 0x0001 +#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ +#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ +#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ +#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ #define TQ_SLEEP KM_SLEEP /* Can block for memory */ #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ @@ -408,22 +366,17 @@ extern taskq_t *system_taskq; -extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); -#define taskq_create_proc(a, b, c, d, e, p, f) \ - (taskq_create(a, b, c, d, e, f)) -#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ - (taskq_create(a, b, maxclsyspri, d, e, f)) +extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); +#define taskq_create_proc(a, b, c, d, e, p, f) \ + (taskq_create(a, b, c, d, e, f)) +#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ + (taskq_create(a, b, maxclsyspri, d, e, f)) extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); -extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, - taskq_ent_t *); -extern void taskq_destroy(taskq_t *); -extern void taskq_wait(taskq_t *); -extern int taskq_member(taskq_t *, void *); -extern void system_taskq_init(void); -extern void system_taskq_fini(void); - -#define taskq_dispatch_safe(tq, func, arg, flags, task) \ - taskq_dispatch((tq), (func), (arg), (flags)) +extern void taskq_destroy(taskq_t *); +extern void taskq_wait(taskq_t *); +extern int taskq_member(taskq_t *, void *); +extern void system_taskq_init(void); +extern void system_taskq_fini(void); #define XVA_MAPSIZE 3 #define XVA_MAGIC 0x78766174 @@ -441,91 +394,48 @@ extern char *vn_dumpdir; #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ -typedef struct xoptattr { - timestruc_t xoa_createtime; /* Create time of file */ - uint8_t xoa_archive; - uint8_t xoa_system; - uint8_t xoa_readonly; - uint8_t xoa_hidden; - uint8_t xoa_nounlink; - uint8_t xoa_immutable; - uint8_t xoa_appendonly; - uint8_t xoa_nodump; - uint8_t xoa_settable; - uint8_t xoa_opaque; - uint8_t xoa_av_quarantined; - uint8_t xoa_av_modified; - uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; - uint8_t xoa_reparse; - uint8_t xoa_offline; - uint8_t xoa_sparse; -} xoptattr_t; - typedef struct vattr { uint_t va_mask; /* bit-mask of attributes */ u_offset_t va_size; /* file size in bytes */ } vattr_t; - -typedef struct xvattr { - vattr_t xva_vattr; /* Embedded vattr structure */ - uint32_t xva_magic; /* Magic Number */ - uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ - uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ - uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ - uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ - xoptattr_t xva_xoptattrs; /* Optional attributes */ -} xvattr_t; - -typedef struct vsecattr { - uint_t vsa_mask; /* See below */ - int vsa_aclcnt; /* ACL entry count */ - void *vsa_aclentp; /* pointer to ACL entries */ - int vsa_dfaclcnt; /* default ACL entry count */ - void *vsa_dfaclentp; /* pointer to default ACL entries */ - size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ -} vsecattr_t; - -#define AT_TYPE 0x00001 -#define AT_MODE 0x00002 -#define AT_UID 0x00004 -#define AT_GID 0x00008 -#define AT_FSID 0x00010 -#define AT_NODEID 0x00020 -#define AT_NLINK 0x00040 -#define AT_SIZE 0x00080 -#define AT_ATIME 0x00100 -#define AT_MTIME 0x00200 -#define AT_CTIME 0x00400 -#define AT_RDEV 0x00800 -#define AT_BLKSIZE 0x01000 -#define AT_NBLOCKS 0x02000 -#define AT_SEQ 0x08000 -#define AT_XVATTR 0x10000 +#define AT_TYPE 0x0001 +#define AT_MODE 0x0002 +#define AT_UID 0x0004 +#define AT_GID 0x0008 +#define AT_FSID 0x0010 +#define AT_NODEID 0x0020 +#define AT_NLINK 0x0040 +#define AT_SIZE 0x0080 +#define AT_ATIME 0x0100 +#define AT_MTIME 0x0200 +#define AT_CTIME 0x0400 +#define AT_RDEV 0x0800 +#define AT_BLKSIZE 0x1000 +#define AT_NBLOCKS 0x2000 +#define AT_SEQ 0x8000 #define CRCREAT 0 -extern int fop_getattr(vnode_t *vp, vattr_t *vap); - -#define VOP_CLOSE(vp, f, c, o, cr, ct) 0 -#define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 -#define VOP_GETATTR(vp, vap, cr) fop_getattr((vp), (vap)); - -#define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) +#define VOP_CLOSE(vp, f, c, o, cr, unk) 0 +#define VOP_PUTPAGE(vp, of, sz, fl, cr, unk) 0 +#define VOP_GETATTR(vp, vap, fl, cr, unk) fop_getattr(vp, vap) +#define VOP_FSYNC(vp, f, cr, unk) fsync((vp)->v_fd) -#define VN_RELE(vp) vn_close(vp, 0, NULL, NULL) -#define VN_RELE_ASYNC(vp, taskq) vn_close(vp, 0, NULL, NULL) +#define VN_RELE(vp) vn_close(vp) +#define VN_RELE_ASYNC(vp) vn_close(vp) -#define vn_lock(vp, type) -#define VOP_UNLOCK(vp, type) +#define vn_lock(vp, type) +#define VOP_UNLOCK(vp, type) extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, int x2, int x3); extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, - int x2, int x3, vnode_t *vp, int fd); + int x2, int x3, vnode_t *vp, int unk); extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); -extern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td); +extern void vn_close(vnode_t *vp, int, cred_t *, kthread_t *); +extern int vn_getattr(vnode_t *vp, vattr_t *va); #define vn_remove(path, x1, x2) remove(path) #define vn_rename(from, to, seg) rename((from), (to)) @@ -539,20 +449,17 @@ /* * Random stuff */ -#define ddi_get_lbolt() (gethrtime() >> 23) -#define ddi_get_lbolt64() (gethrtime() >> 23) +#define lbolt (gethrtime() >> 23) +#define lbolt64 (gethrtime() >> 23) #define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ extern void delay(clock_t ticks); -#define SEC_TO_TICK(sec) ((sec) * hz) -#define NSEC_TO_TICK(nsec) ((nsec) / (NANOSEC / hz)) - #define gethrestime_sec() time(NULL) -#define gethrestime(t) \ +#define gethrestime(t) \ do {\ - (t)->tv_sec = gethrestime_sec();\ - (t)->tv_nsec = 0;\ + (t)->tv_sec = gethrestime_sec();\ + (t)->tv_nsec = 0;\ } while (0); #define max_ncpus 64 @@ -565,13 +472,13 @@ #define kcred NULL #define CRED() NULL -#ifndef ptob -#define ptob(x) ((x) * PAGESIZE) +#ifdef ptob +#undef ptob #endif +#define ptob(x) ((x) * PAGESIZE) extern uint64_t physmem; -extern int highbit64(uint64_t i); extern int random_get_bytes(uint8_t *ptr, size_t len); extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); @@ -579,7 +486,7 @@ extern void kernel_fini(void); struct spa; -extern void nicenum(uint64_t num, char *buf); +extern void nicenum(uint64_t, char *); extern void show_pool_stats(struct spa *); typedef struct callb_cpr { @@ -606,19 +513,15 @@ #define zone_dataset_visible(x, y) (1) #define INGLOBALZONE(z) (1) -extern char *kmem_asprintf(const char *fmt, ...); -#define strfree(str) kmem_free((str), strlen(str) + 1) - /* * Hostname information */ extern struct utsname utsname; -extern char hw_serial[]; /* for userland-emulated hostid access */ +extern char hw_serial[]; extern int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result); - -extern int ddi_strtoull(const char *str, char **nptr, int base, - u_longlong_t *result); +#define ddi_get_lbolt() (gethrtime() >> 23) +#define ddi_get_lbolt64() (gethrtime() >> 23) /* ZFS Boot Related stuff. */ @@ -630,35 +533,28 @@ uint64_t st_size; }; -typedef struct ace_object { - uid_t a_who; - uint32_t a_access_mask; - uint16_t a_flags; - uint16_t a_type; - uint8_t a_obj_type[16]; - uint8_t a_inherit_obj_type[16]; -} ace_object_t; - - -#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 -#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 -#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 -#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 +extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); +extern int zfs_secpolicy_rename_perms(const char *from, const char *to, + cred_t *cr); +extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); extern struct _buf *kobj_open_file(char *name); extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off); extern void kobj_close_file(struct _buf *file); extern int kobj_get_filesize(struct _buf *file, uint64_t *size); -extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); -extern int zfs_secpolicy_rename_perms(const char *from, const char *to, - cred_t *cr); -extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); -extern zoneid_t getzoneid(void); + /* Random compatibility stuff. */ +#define lbolt (gethrtime() >> 23) +#define lbolt64 (gethrtime() >> 23) + +extern uint64_t physmem; + +#define gethrestime_sec() time(NULL) + #define pwrite64(d, p, n, o) pwrite(d, p, n, o) #define readdir64(d) readdir(d) -#define SIGPENDING(td) (0) +#define sigispending(td, sig) (0) #define root_mount_wait() do { } while (0) #define root_mounted() (1) @@ -669,7 +565,14 @@ #define FCREAT O_CREAT #define FOFFMAX 0x0 +/* Errors */ + +#ifndef ERESTART +#define ERESTART (-1) +#endif + /* SID stuff */ + typedef struct ksiddomain { uint_t kd_ref; uint_t kd_len; @@ -679,145 +582,238 @@ ksiddomain_t *ksid_lookupdomain(const char *); void ksiddomain_rele(ksiddomain_t *); -typedef uint32_t idmap_rid_t; - #define DDI_SLEEP KM_SLEEP #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) (0) -#define SX_SYSINIT(name, lock, desc) +typedef struct ace_object { + uid_t a_who; + uint32_t a_access_mask; + uint16_t a_flags; + uint16_t a_type; + uint8_t a_obj_type[16]; + uint8_t a_inherit_obj_type[16]; +} ace_object_t; + +#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 +#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 +#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 +#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 -#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \ - intptr_t arg2, struct sysctl_req *req +/* libzfs_dataset.c */ +#define priv_allocset() (NULL) +#define getppriv(a, b) (0) +#define priv_isfullset(a) (B_FALSE) +#define priv_freeset(a) (0) + +#define di_devlink_init(a, b) (NULL) +#define di_devlink_fini(a) (0) +typedef void *di_devlink_handle_t; -/* - * This describes the access space for a sysctl request. This is needed - * so that we can use the interface from the kernel or from user-space. - */ -struct sysctl_req { - struct thread *td; /* used for access checking */ - int lock; /* wiring state */ - void *oldptr; - size_t oldlen; - size_t oldidx; - int (*oldfunc)(struct sysctl_req *, const void *, size_t); - void *newptr; - size_t newlen; - size_t newidx; - int (*newfunc)(struct sysctl_req *, void *, size_t); - size_t validlen; - int flags; -}; +extern char *kmem_asprintf(const char *fmt, ...); +#define strfree(str) kmem_free((str), strlen(str)+1) + +#define DEV_PHYS_PATH "phys_path" + +typedef uint32_t idmap_rid_t; + +#define ZFS_EXPORTS_PATH "/etc/zfs/exports" + +#else /* _KERNEL */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define CPU_SEQID (curcpu()->ci_data.cpu_index) +#define lbolt hardclock_ticks +#define lbolt64 lbolt + +#ifdef __cplusplus +} +#endif + +extern int zfs_debug_level; +extern kmutex_t zfs_debug_mtx; +#define ZFS_LOG(lvl, ...) do { \ + if (((lvl) & 0xff) <= zfs_debug_level) { \ + mutex_enter(&zfs_debug_mtx); \ + printf("%s:%u[%d]: ", __func__, __LINE__, (lvl)); \ + printf(__VA_ARGS__); \ + printf("\n"); \ + if ((lvl) & 0x100) \ + /* XXXNETBSD backtrace */ \ + mutex_exit(&zfs_debug_mtx); \ + } \ +} while (0) + +extern struct utsname utsname; + +#define makedevice(a, b) makedev(a, b) +#define getmajor(a) major(a) +#define getminor(a) minor(a) +#define issig(x) (sigispending(curlwp, 0)) +#define ISSIG(thr, why) (sigispending(thr, 0)) +#define fm_panic panic -SLIST_HEAD(sysctl_oid_list, sysctl_oid); +#ifdef ptob +#undef ptob +#endif +#define ptob(x) ((x) * PAGE_SIZE) + +#define strncat(a, b, c) strlcat(a, b, c) +#define kmem_debugging() 0 + +#define zone_get_hostid(a) 0 + +extern char *kmem_asprintf(const char *fmt, ...); +#define strfree(str) kmem_free((str), strlen(str)+1) + +static inline void +tsd_create(uint_t *keyp, void (*func)(void *)) +{ + int error __unused; + + error = lwp_specific_key_create(keyp, func); + KASSERT(error == 0); +} + +static inline void +tsd_destroy(uint_t *keyp) +{ + + lwp_specific_key_delete(*keyp); +} + +static inline void * +tsd_get(uint_t key) +{ + + return lwp_getspecific(key); +} + +static inline int +tsd_set(uint_t key, void *value) +{ + + lwp_setspecific(key, value); + return 0; +} + +#define td_ru l_ru + +/* NetBSD doesn't need this routines in zfs code, yet */ +#define taskq_create_proc(a, b, c, d, e, p, f) \ + (taskq_create(a, b, c, d, e, f)) +#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ + (taskq_create(a, b, maxclsyspri, d, e, f)) + +#define FIGNORECASE 0 + +#define DEV_PHYS_PATH "phys_path" + +#define sys_shutdown 0 + +static inline int +sprintf(char * __restrict buf, const char * __restrict fmt, ...) +{ + va_list ap; + int rv; + + va_start(ap, fmt); + rv = vsnprintf(buf, 1024, fmt, ap); + va_end(ap); + return rv; +} + +static inline int +vsprintf(char * __restrict buf, const char * __restrict fmt, va_list ap) +{ + + return vsnprintf(buf, 1024, fmt, ap); +} /* - * This describes one "oid" in the MIB tree. Potentially more nodes can - * be hidden behind it, expanded by the handler. + * FreeBSD interfaces */ -struct sysctl_oid { - struct sysctl_oid_list *oid_parent; - SLIST_ENTRY(sysctl_oid) oid_link; - int oid_number; - u_int oid_kind; - void *oid_arg1; - intptr_t oid_arg2; - const char *oid_name; - int (*oid_handler)(SYSCTL_HANDLER_ARGS); - const char *oid_fmt; - int oid_refcnt; - u_int oid_running; - const char *oid_descr; -}; + +void zfs_netbsd_setsize(vnode_t *, off_t); +#define vnode_pager_setsize(vp, size) zfs_netbsd_setsize(vp, size) +#define vn_pages_remove(a, b, c) + +#define getf fd_getfile +#define releasef fd_putfile + +#define callout_drain(x) callout_stop(x) + +#endif /* _KERNEL */ #define SYSCTL_DECL(...) #define SYSCTL_NODE(...) #define SYSCTL_INT(...) #define SYSCTL_UINT(...) +#define SYSCTL_LONG(...) #define SYSCTL_ULONG(...) -#define SYSCTL_PROC(...) #define SYSCTL_QUAD(...) #define SYSCTL_UQUAD(...) #ifdef TUNABLE_INT #undef TUNABLE_INT #undef TUNABLE_ULONG -#undef TUNABLE_QUAD +#undef TUNABLE_INT_FETCH #endif #define TUNABLE_INT(...) #define TUNABLE_ULONG(...) -#define TUNABLE_QUAD(...) - -int sysctl_handle_64(SYSCTL_HANDLER_ARGS); +#define TUNABLE_INT_FETCH(...) 0 -/* Errors */ +#define ASSERT_VOP_LOCKED(vp, name) KASSERT(VOP_ISLOCKED(vp) != 0) +#define ASSERT_VOP_ELOCKED(vp, name) KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE) -#ifndef ERESTART -#define ERESTART (-1) -#endif - -#ifdef illumos -/* - * Cyclic information - */ -extern kmutex_t cpu_lock; - -typedef uintptr_t cyclic_id_t; -typedef uint16_t cyc_level_t; -typedef void (*cyc_func_t)(void *); - -#define CY_LOW_LEVEL 0 -#define CY_INFINITY INT64_MAX -#define CYCLIC_NONE ((cyclic_id_t)0) - -typedef struct cyc_time { - hrtime_t cyt_when; - hrtime_t cyt_interval; -} cyc_time_t; - -typedef struct cyc_handler { - cyc_func_t cyh_func; - void *cyh_arg; - cyc_level_t cyh_level; -} cyc_handler_t; - -extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *); -extern void cyclic_remove(cyclic_id_t); -extern int cyclic_reprogram(cyclic_id_t, hrtime_t); -#endif /* illumos */ - -#ifdef illumos -/* - * Buf structure - */ -#define B_BUSY 0x0001 -#define B_DONE 0x0002 -#define B_ERROR 0x0004 -#define B_READ 0x0040 /* read when I/O occurs */ -#define B_WRITE 0x0100 /* non-read pseudo-flag */ - -typedef struct buf { - int b_flags; - size_t b_bcount; - union { - caddr_t b_addr; - } b_un; - - lldaddr_t _b_blkno; -#define b_lblkno _b_blkno._f - size_t b_resid; - size_t b_bufsize; - int (*b_iodone)(struct buf *); - int b_error; - void *b_private; -} buf_t; - -extern void bioinit(buf_t *); -extern void biodone(buf_t *); -extern void bioerror(buf_t *, int); -extern int geterror(buf_t *); -#endif - -#ifdef __cplusplus -} -#endif +#define UID_NOBODY (-2) +#define GID_NOBODY (-2) #endif /* _SYS_ZFS_CONTEXT_H */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys: zfs_prop.h diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/sys/sys/zone.h /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/zone.h --- /tmp/out/external/cddl/osnet/sys/sys/zone.h 2012-06-11 22:57:29.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys/sys/zone.h 2017-06-09 22:57:06.000000000 -0700 @@ -1,3 +1,5 @@ +/* $NetBSD: zone.h,v 1.3 2010/02/21 01:46:36 darran Exp $ */ + /*- * Copyright (c) 2007 Pawel Jakub Dawidek * All rights reserved. @@ -23,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/zone.h 219089 2011-02-27 19:41:40Z pjd $ */ #ifndef _OPENSOLARIS_SYS_ZONE_H_ @@ -31,43 +33,38 @@ #ifdef _KERNEL -#include +struct ucred; /* * Macros to help with zone visibility restrictions. */ /* - * Is thread in the global zone? + * Is process in the global zone? */ -#define INGLOBALZONE(thread) (!jailed((thread)->td_ucred)) +#define INGLOBALZONE(p) (1) /* * Attach the given dataset to the given jail. */ -extern int zone_dataset_attach(struct ucred *, const char *, int); +extern int zone_dataset_attach(cred_t *, const char *, int); /* * Detach the given dataset to the given jail. */ -extern int zone_dataset_detach(struct ucred *, const char *, int); +extern int zone_dataset_detach(cred_t *, const char *, int); /* * Returns true if the named pool/dataset is visible in the current zone. */ extern int zone_dataset_visible(const char *, int *); -/* - * Safely get the hostid of the specified zone (defaults to machine's hostid - * if the specified zone doesn't emulate a hostid). Passing NULL retrieves - * the global zone's (i.e., physical system's) hostid. - */ -extern uint32_t zone_get_hostid(void *); - #else /* !_KERNEL */ #define GLOBAL_ZONEID 0 +extern int getzoneid(void); + #endif /* _KERNEL */ #endif /* !_OPENSOLARIS_SYS_ZONE_H_ */ Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys: util Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/sys: vm diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/usr.bin/ctfdump/ctfdump.1 /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.bin/ctfdump/ctfdump.1 --- /tmp/out/external/cddl/osnet/usr.bin/ctfdump/ctfdump.1 2012-06-11 22:55:36.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.bin/ctfdump/ctfdump.1 2017-10-24 00:40:56.000000000 -0700 @@ -26,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/cddl/usr.bin/ctfdump/ctfdump.1 211187 2010-08-11 18:00:45Z rpaulo $ .\" .Dd July 7, 2010 .Dt CTFDUMP 1 diff -ur -x CVS -x 'Makefile*' /tmp/out/external/cddl/osnet/usr.bin/ctfmerge/ctfmerge.1 /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.bin/ctfmerge/ctfmerge.1 --- /tmp/out/external/cddl/osnet/usr.bin/ctfmerge/ctfmerge.1 2012-09-02 15:26:52.000000000 -0700 +++ /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.bin/ctfmerge/ctfmerge.1 2017-10-24 00:40:57.000000000 -0700 @@ -26,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/cddl/usr.bin/ctfmerge/ctfmerge.1 239969 2012-09-01 06:23:13Z joel $ .\" .Dd July 7, 2010 .Dt CTFMERGE 1 Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.bin: ztest Only in /home/chs/netbsd/trees/dtrace/src/external/cddl/osnet/usr.sbin: dtrace