From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 31 17:23:07 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 B48604FD; Sun, 31 Mar 2013 17:23:07 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 273D1763; Sun, 31 Mar 2013 17:23:06 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r2VHN1oG003725; Sun, 31 Mar 2013 20:23:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.2 kib.kiev.ua r2VHN1oG003725 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r2VHN14o003724; Sun, 31 Mar 2013 20:23:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 31 Mar 2013 20:23:01 +0300 From: Konstantin Belousov To: Mikolaj Golub Subject: Re: libprocstat(3): retrieve process command line args and environment Message-ID: <20130331172301.GO3794@kib.kiev.ua> References: <20130316223339.GA3534@gmail.com> <20130317063033.GL3794@kib.kiev.ua> <20130317091930.GA2833@gmail.com> <20130324155426.GA87022@gmail.com> <20130328105134.GO3794@kib.kiev.ua> <20130328211820.GA6657@gmail.com> <20130329092245.GU3794@kib.kiev.ua> <20130329123155.GA94024@gmail.com> <20130331134047.GN3794@kib.kiev.ua> <20130331155259.GA9867@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dm/22yvNomxGlc+y" Content-Disposition: inline In-Reply-To: <20130331155259.GA9867@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: Attilio Rao , freebsd-hackers@freebsd.org, Stanislav Sedov , "Robert N. M. Watson" , Mikolaj Golub 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, 31 Mar 2013 17:23:07 -0000 --dm/22yvNomxGlc+y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 31, 2013 at 06:53:00PM +0300, Mikolaj Golub wrote: > On Sun, Mar 31, 2013 at 04:40:47PM +0300, Konstantin Belousov wrote: >=20 > > I inspected imgact_elf.c:parse_note(), imgact_elf.c:putnote() and > > rtld.c:digest_notes(). Only putnote() uses 8-byte alignment. > > Every other OS and our !coredump code assumes 4-byte alignment. >=20 > Thanks! > =20 > > Does changing the putnote() to align on the 4-byte boundary cause > > real change in the core file notes layout ? >=20 > Currently, we store only 4 types of notes in a core file: >=20 > #define NT_PRSTATUS 1 /* Process status. */ > #define NT_FPREGSET 2 /* Floating point registers. */ > #define NT_PRPSINFO 3 /* Process state info. */ > #define NT_THRMISC 7 /* Thread miscellaneous info. */ >=20 > I checked the sizes of structures inserted into the notes, and on amd64 > they all are multiple of 8: >=20 > (kgdb) p sizeof(prpsinfo_t) % 8 > $1 =3D 0 > (kgdb) p sizeof(prstatus_t) % 8 > $2 =3D 0 > (kgdb) p sizeof(prfpregset_t) % 8 > $3 =3D 0 > (kgdb) p sizeof(thrmisc_t) % 8 > $4 =3D 0 >=20 > so both 4-byte and 8-byte aligned. Well, FreeBSD supports some more 64bit architectures, besides amd64. At least on powerpc64, I get prpsinfo 120 0 prstatus_t 344 0 prfpregset_t 264 0 thrmisc_t 24 0 Second column is sizeof(), third is sizeof() % 8. This is in fact not much surprising, since all ABIs define the alignment of the structure as the alignment of the most demanding member. And, because 64bit architectures have 8-byte registers, it is indeed expected that the size % 8 =3D=3D 0. >=20 > I believe that the patch below will not change the current core file > notes layout, will make things consistent in our tree, and will make > adding my procstat notes easier, if I use 4-byte alignment. >=20 > Are you ok if I commit it before introducing my changes? Yes, I believe this is the right thing to do. >=20 > Index: sys/kern/imgact_elf.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- sys/kern/imgact_elf.c (revision 248706) > +++ sys/kern/imgact_elf.c (working copy) > @@ -1538,10 +1538,10 @@ __elfN(putnote)(void *dst, size_t *off, const char > *off +=3D sizeof note; > if (dst !=3D NULL) > bcopy(name, (char *)dst + *off, note.n_namesz); > - *off +=3D roundup2(note.n_namesz, sizeof(Elf_Size)); > + *off +=3D roundup2(note.n_namesz, sizeof(Elf32_Size)); > if (dst !=3D NULL) > bcopy(desc, (char *)dst + *off, note.n_descsz); > - *off +=3D roundup2(note.n_descsz, sizeof(Elf_Size)); > + *off +=3D roundup2(note.n_descsz, sizeof(Elf32_Size)); > } > =20 > static boolean_t >=20 > Also, shouldn't we update then the following comment in sys/elf_common.h? >=20 > /* > * Note header. The ".note" section contains an array of notes. Each > * begins with this header, aligned to a word boundary. Immediately > * following the note header is n_namesz bytes of name, padded to the > * next word boundary. Then comes n_descsz bytes of descriptor, again > * padded to a word boundary. The values of n_namesz and n_descsz do > * not include the padding. > */ >=20 > --=20 > Mikolaj Golub --dm/22yvNomxGlc+y Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRWHD0AAoJEJDCuSvBvK1BOX8P/1mASCWd1ZsLzlCTRXSFHA5T ChXEWGxGEGTn66YdssR6ibISWRiNCXSqSIROyMDLl4WbDTVej9YK2seCl1b7WzDV slzWqU3TdCgP1lX4XJq53n9JbFpKgDRK/nnOLjgy8GX9r5xY3uGcxsH3lLMBI1TE UJqlEi0ebJitd1ps8UxDTTTO65Z85sx4KOcg58RuRpNfe68Dz3nt6FK1uisDnhw4 Q8GNUz0ecahrlg6rKtuuN8qDKciDBimJdPzw3k0x/sT6/sMpnwUmBbDsnZ0XoXuG XJZfYhlCd+5b2YdJ5OJhPCNg81aq38dRAFl6JH88slY4XiE/Oxch/Sxi1l/ESB6c moh8c8Z30tNozdNes+Bc3eyW8wun3ztAOXQwviaG45MINk0L0Mg8oyGTCmwB+ElY rz/x/koremF2vxTtJy3icqX9WTOJr0CRl00zT2xQLq6Vi9fjztIr2h3NV06ger1y RSoinJSVfXuXFMfSKiZeFXYKvnNW9Ew7DqDZMl9zt0C+k04gzTxQFWuZ6+v5IZSw KygvBiF99lY9EnRfuaTQnWO4yp+95SQkg235OJcZQjCWXljg6wn/uCZMhD8JDVor nXYUedeymqL2U1OC+DxpUdzMyzoiBcV84e9x/Ts/dzn1yBWxcgY9cwfUqm6zlNWO HZ6gT3+B7Jf/TDnD4dZo =/Loq -----END PGP SIGNATURE----- --dm/22yvNomxGlc+y--