From owner-svn-src-all@FreeBSD.ORG Wed Apr 28 10:03:55 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D4ED106564A; Wed, 28 Apr 2010 10:03:55 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1A64E8FC20; Wed, 28 Apr 2010 10:03:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o3SA3sbw094587; Wed, 28 Apr 2010 10:03:54 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o3SA3sLQ094583; Wed, 28 Apr 2010 10:03:54 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201004281003.o3SA3sLQ094583@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 28 Apr 2010 10:03:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207317 - in stable/8/sys: compat/freebsd32 kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Apr 2010 10:03:55 -0000 Author: kib Date: Wed Apr 28 10:03:54 2010 New Revision: 207317 URL: http://svn.freebsd.org/changeset/base/207317 Log: MFC r207008: Provide compat32 shims for kinfo_proc sysctl. MFC r207016: Fix typo. Modified: stable/8/sys/compat/freebsd32/freebsd32.h stable/8/sys/kern/kern_proc.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) stable/8/sys/geom/sched/ (props changed) Modified: stable/8/sys/compat/freebsd32/freebsd32.h ============================================================================== --- stable/8/sys/compat/freebsd32/freebsd32.h Wed Apr 28 09:59:28 2010 (r207316) +++ stable/8/sys/compat/freebsd32/freebsd32.h Wed Apr 28 10:03:54 2010 (r207317) @@ -31,6 +31,7 @@ #include #include +#include #define PTRIN(v) (void *)(uintptr_t) (v) #define PTROUT(v) (u_int32_t)(uintptr_t) (v) @@ -229,4 +230,85 @@ struct mq_attr32 { int __reserved[4]; }; +struct kinfo_proc32 { + int ki_structsize; + int ki_layout; + uint32_t ki_args; + uint32_t ki_paddr; + uint32_t ki_addr; + uint32_t ki_tracep; + uint32_t ki_textvp; + uint32_t ki_fd; + uint32_t ki_vmspace; + uint32_t ki_wchan; + pid_t ki_pid; + pid_t ki_ppid; + pid_t ki_pgid; + pid_t ki_tpgid; + pid_t ki_sid; + pid_t ki_tsid; + short ki_jobc; + short ki_spare_short1; + dev_t ki_tdev; + sigset_t ki_siglist; + sigset_t ki_sigmask; + sigset_t ki_sigignore; + sigset_t ki_sigcatch; + uid_t ki_uid; + uid_t ki_ruid; + uid_t ki_svuid; + gid_t ki_rgid; + gid_t ki_svgid; + short ki_ngroups; + short ki_spare_short2; + gid_t ki_groups[KI_NGROUPS]; + uint32_t ki_size; + int32_t ki_rssize; + int32_t ki_swrss; + int32_t ki_tsize; + int32_t ki_dsize; + int32_t ki_ssize; + u_short ki_xstat; + u_short ki_acflag; + fixpt_t ki_pctcpu; + u_int ki_estcpu; + u_int ki_slptime; + u_int ki_swtime; + int ki_spareint1; + u_int64_t ki_runtime; + struct timeval32 ki_start; + struct timeval32 ki_childtime; + int ki_flag; + int ki_kiflag; + int ki_traceflag; + char ki_stat; + signed char ki_nice; + char ki_lock; + char ki_rqindex; + u_char ki_oncpu; + u_char ki_lastcpu; + char ki_ocomm[OCOMMLEN+1]; + char ki_wmesg[WMESGLEN+1]; + char ki_login[LOGNAMELEN+1]; + char ki_lockname[LOCKNAMELEN+1]; + char ki_comm[COMMLEN+1]; + char ki_emul[KI_EMULNAMELEN+1]; + char ki_sparestrings[68]; + int ki_spareints[KI_NSPARE_INT]; + u_int ki_cr_flags; + int ki_jid; + int ki_numthreads; + lwpid_t ki_tid; + struct priority ki_pri; + struct rusage32 ki_rusage; + struct rusage32 ki_rusage_ch; + uint32_t ki_pcb; + uint32_t ki_kstack; + uint32_t ki_udata; + uint32_t ki_spareptrs[KI_NSPARE_PTR]; /* spare room for growth */ + int ki_sparelongs[KI_NSPARE_LONG]; + int ki_sflag; + int ki_tdflags; +}; + #endif /* !_COMPAT_FREEBSD32_FREEBSD32_H_ */ Modified: stable/8/sys/kern/kern_proc.c ============================================================================== --- stable/8/sys/kern/kern_proc.c Wed Apr 28 09:59:28 2010 (r207316) +++ stable/8/sys/kern/kern_proc.c Wed Apr 28 10:03:54 2010 (r207317) @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -79,6 +80,11 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef COMPAT_FREEBSD32 +#include +#include +#endif + SDT_PROVIDER_DEFINE(proc); SDT_PROBE_DEFINE(proc, kernel, ctor, entry); SDT_PROBE_ARGTYPE(proc, kernel, ctor, entry, 0, "struct proc *"); @@ -968,6 +974,128 @@ zpfind(pid_t pid) #define KERN_PROC_ZOMBMASK 0x3 #define KERN_PROC_NOTHREADS 0x4 +#ifdef COMPAT_FREEBSD32 + +/* + * This function is typically used to copy out the kernel address, so + * it can be replaced by assignment of zero. + */ +static inline uint32_t +ptr32_trim(void *ptr) +{ + uintptr_t uptr; + + uptr = (uintptr_t)ptr; + return ((uptr > UINT_MAX) ? 0 : uptr); +} + +#define PTRTRIM_CP(src,dst,fld) \ + do { (dst).fld = ptr32_trim((src).fld); } while (0) + +static void +freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32) +{ + int i; + + bzero(ki32, sizeof(struct kinfo_proc32)); + ki32->ki_structsize = sizeof(struct kinfo_proc32); + CP(*ki, *ki32, ki_layout); + PTRTRIM_CP(*ki, *ki32, ki_args); + PTRTRIM_CP(*ki, *ki32, ki_paddr); + PTRTRIM_CP(*ki, *ki32, ki_addr); + PTRTRIM_CP(*ki, *ki32, ki_tracep); + PTRTRIM_CP(*ki, *ki32, ki_textvp); + PTRTRIM_CP(*ki, *ki32, ki_fd); + PTRTRIM_CP(*ki, *ki32, ki_vmspace); + PTRTRIM_CP(*ki, *ki32, ki_wchan); + CP(*ki, *ki32, ki_pid); + CP(*ki, *ki32, ki_ppid); + CP(*ki, *ki32, ki_pgid); + CP(*ki, *ki32, ki_tpgid); + CP(*ki, *ki32, ki_sid); + CP(*ki, *ki32, ki_tsid); + CP(*ki, *ki32, ki_jobc); + CP(*ki, *ki32, ki_tdev); + CP(*ki, *ki32, ki_siglist); + CP(*ki, *ki32, ki_sigmask); + CP(*ki, *ki32, ki_sigignore); + CP(*ki, *ki32, ki_sigcatch); + CP(*ki, *ki32, ki_uid); + CP(*ki, *ki32, ki_ruid); + CP(*ki, *ki32, ki_svuid); + CP(*ki, *ki32, ki_rgid); + CP(*ki, *ki32, ki_svgid); + CP(*ki, *ki32, ki_ngroups); + for (i = 0; i < KI_NGROUPS; i++) + CP(*ki, *ki32, ki_groups[i]); + CP(*ki, *ki32, ki_size); + CP(*ki, *ki32, ki_rssize); + CP(*ki, *ki32, ki_swrss); + CP(*ki, *ki32, ki_tsize); + CP(*ki, *ki32, ki_dsize); + CP(*ki, *ki32, ki_ssize); + CP(*ki, *ki32, ki_xstat); + CP(*ki, *ki32, ki_acflag); + CP(*ki, *ki32, ki_pctcpu); + CP(*ki, *ki32, ki_estcpu); + CP(*ki, *ki32, ki_slptime); + CP(*ki, *ki32, ki_swtime); + CP(*ki, *ki32, ki_runtime); + TV_CP(*ki, *ki32, ki_start); + TV_CP(*ki, *ki32, ki_childtime); + CP(*ki, *ki32, ki_flag); + CP(*ki, *ki32, ki_kiflag); + CP(*ki, *ki32, ki_traceflag); + CP(*ki, *ki32, ki_stat); + CP(*ki, *ki32, ki_nice); + CP(*ki, *ki32, ki_lock); + CP(*ki, *ki32, ki_rqindex); + CP(*ki, *ki32, ki_oncpu); + CP(*ki, *ki32, ki_lastcpu); + bcopy(ki->ki_ocomm, ki32->ki_ocomm, OCOMMLEN + 1); + bcopy(ki->ki_wmesg, ki32->ki_wmesg, WMESGLEN + 1); + bcopy(ki->ki_login, ki32->ki_login, LOGNAMELEN + 1); + bcopy(ki->ki_lockname, ki32->ki_lockname, LOCKNAMELEN + 1); + bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1); + bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1); + CP(*ki, *ki32, ki_cr_flags); + CP(*ki, *ki32, ki_jid); + CP(*ki, *ki32, ki_numthreads); + CP(*ki, *ki32, ki_tid); + CP(*ki, *ki32, ki_pri); + freebsd32_rusage_out(&ki->ki_rusage, &ki32->ki_rusage); + freebsd32_rusage_out(&ki->ki_rusage_ch, &ki32->ki_rusage_ch); + PTRTRIM_CP(*ki, *ki32, ki_pcb); + PTRTRIM_CP(*ki, *ki32, ki_kstack); + PTRTRIM_CP(*ki, *ki32, ki_udata); + CP(*ki, *ki32, ki_sflag); + CP(*ki, *ki32, ki_tdflags); +} + +static int +sysctl_out_proc_copyout(struct kinfo_proc *ki, struct sysctl_req *req) +{ + struct kinfo_proc32 ki32; + int error; + + if (req->flags & SCTL_MASK32) { + freebsd32_kinfo_proc_out(ki, &ki32); + error = SYSCTL_OUT(req, (caddr_t)&ki32, + sizeof(struct kinfo_proc32)); + } else + error = SYSCTL_OUT(req, (caddr_t)ki, + sizeof(struct kinfo_proc)); + return (error); +} +#else +static int +sysctl_out_proc_copyout(struct kinfo_proc *ki, struct sysctl_req *req) +{ + + return (SYSCTL_OUT(req, (caddr_t)ki, sizeof(struct kinfo_proc))); +} +#endif + /* * Must be called with the process locked and will return with it unlocked. */ @@ -985,13 +1113,11 @@ sysctl_out_proc(struct proc *p, struct s fill_kinfo_proc(p, &kinfo_proc); if (flags & KERN_PROC_NOTHREADS) - error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc, - sizeof(kinfo_proc)); + error = sysctl_out_proc_copyout(&kinfo_proc, req); else { FOREACH_THREAD_IN_PROC(p, td) { fill_kinfo_thread(td, &kinfo_proc, 1); - error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc, - sizeof(kinfo_proc)); + error = sysctl_out_proc_copyout(&kinfo_proc, req); if (error) break; }