From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 24 15:54:35 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id ABD76365; Sun, 24 Mar 2013 15:54:35 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-ee0-f41.google.com (mail-ee0-f41.google.com [74.125.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 9DAB7178; Sun, 24 Mar 2013 15:54:34 +0000 (UTC) Received: by mail-ee0-f41.google.com with SMTP id c1so517563eek.0 for ; Sun, 24 Mar 2013 08:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=Emtae1618muquy32s6nL0JJctWCBSIJDbLuTjfio9FE=; b=Qx002wwl+f5vgomlrFhu7LITYBSE5e8UEFGES1uxNrNuLzzIgL3ZkBaH08ILqb+VZI J1O3j6OMQsk2zQvLR0U+2yi05XFLrNslnp/NouxbPWiDxU76oXXXBIjRYmMRthHLgviB Gtv3u0uHy1sy7a/dnhkTs2+TZeMkLQkgCEKaGXgapJK6u62fsIJuVqQ3d7FkLYWqigtn wsd/mm2FHT8frBYux6OOTI9UcbnA5us1KLJHPIl98HEk3WlZfj4lvevTTRtLWOLs6Bnw e3loSDFHpmouXhaZTwe8UcSXpR62TCpthBEG0LZNSvXXokCbUEglzqfmidz2hu8ZB/kf x5VQ== X-Received: by 10.14.210.132 with SMTP id u4mr24880208eeo.19.1364140473293; Sun, 24 Mar 2013 08:54:33 -0700 (PDT) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPS id 46sm14065040eea.3.2013.03.24.08.54.30 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 24 Mar 2013 08:54:32 -0700 (PDT) Sender: Mikolaj Golub Date: Sun, 24 Mar 2013 17:54:28 +0200 From: Mikolaj Golub To: Konstantin Belousov Subject: Re: libprocstat(3): retrieve process command line args and environment Message-ID: <20130324155426.GA87022@gmail.com> References: <20130119151253.GB88025@gmail.com> <201301251531.43540.jhb@freebsd.org> <20130212215054.GA9839@gmail.com> <201302200904.15324.jhb@freebsd.org> <20130220195801.GA8679@gmail.com> <20130316180915.GA91146@gmail.com> <20130316191605.GJ3794@kib.kiev.ua> <20130316223339.GA3534@gmail.com> <20130317063033.GL3794@kib.kiev.ua> <20130317091930.GA2833@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130317091930.GA2833@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Stanislav Sedov , Attilio Rao , "Robert N. M. Watson" , freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Mar 2013 15:54:35 -0000 Here is an updated patch set, which I think includes all kib's suggestions. It also introduces procstat groups, umask, rlimit, and osrel notes. http://people.freebsd.org/~trociny/procstat_core.3.patch Sbuf section interface looks like below: /* start a section */ sbuf_start_section(sb, NULL); /* write something to sbuf */ ... /* start a subsection (need to save the current section length) */ sbuf_start_section(sb, &old_len); /* write something to sbuf */ ... /* end a subsection padding to 4 bytes with '\0' bytes (need to provide the previously saved section length) */ sbuf_end_section(sb, old_len, 4, 0); ... /* aling the whole section to page size */ sbuf_end_section(sb, -1, PAGE_SIZE, 0); Open issues/questions: 1) I would also like to make libprocstat(3) extract environment, args, and auxv from the core. It looks like I don't need to store envv and argv in notes, as it is already present in the core. But I think I need to know psstrings to find them. Would it be ok, if I add auxv and psstrings notes, and extract envv and agrv from a program section in the core? 2) I started NT_PROCSTAT constants from the first not used number in elf_common.h, i.e. 8. But in this case they conflict with those available on other systems: contrib/binutils/include/elf/common.h: #define NT_PSTATUS 10 /* Has a struct pstatus */ #define NT_FPREGS 12 /* Has a struct fpregset */ #define NT_PSINFO 13 /* Has a struct psinfo */ #define NT_LWPSTATUS 16 /* Has a struct lwpstatus_t */ #define NT_LWPSINFO 17 /* Has a struct lwpsinfo_t */ #define NT_WIN32PSTATUS 18 /* Has a struct win32_pstatus */ Although note name = "FreeBSD" should have disambiguated this, readelf looks like ignores this and its output for my core on i386 looks confusing: Owner Data size Description FreeBSD 0x0000006c NT_PRPSINFO (prpsinfo structure) FreeBSD 0x00000068 NT_PRSTATUS (prstatus structure) FreeBSD 0x000000b0 NT_FPREGSET (floating point registers) FreeBSD 0x00000018 NT_THRMISC (thrmisc structure) FreeBSD 0x00000304 Unknown note type: (0x00000008) FreeBSD 0x00000a6c Unknown note type: (0x00000009) FreeBSD 0x000008d4 NT_PSTATUS (pstatus structure) FreeBSD 0x0000000c Unknown note type: (0x0000000b) FreeBSD 0x00000006 NT_FPREGS (floating point registers) FreeBSD 0x000000d4 NT_PSINFO (psinfo structure) FreeBSD 0x00000008 Unknown note type: (0x0000000e) Should I use some other range for NT_PROCSTAT notes? 3) Following our current code I align notes to sizeof(Elf_Size), which is 4 on i386 and 8 on amd64. But I have an issue reading the notes by readelf on amd64, which alway uses 4 byte alignment: contrib/binutils/binutils/readelf.c: next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2)); where #define align_power(addr, align) \ (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align))) Should I change alignment to 4 bytes? 4) In libprocstat I added new functions and placed them under already existent FBSD_1.3 version section in Symbol.map. Shouldn't I bump the version? Won't I need any additional care if I want to MFC the code to stable/9 and may be 8? -- Mikolaj Golub