libprocstat(3): retrieve process command line args and environment
Konstantin Belousov
kostikbel at gmail.com
Sun Mar 31 17:23:07 UTC 2013
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:
>
> > 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.
>
> Thanks!
>
> > Does changing the putnote() to align on the 4-byte boundary cause
> > real change in the core file notes layout ?
>
> Currently, we store only 4 types of notes in a core file:
>
> #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. */
>
> I checked the sizes of structures inserted into the notes, and on amd64
> they all are multiple of 8:
>
> (kgdb) p sizeof(prpsinfo_t) % 8
> $1 = 0
> (kgdb) p sizeof(prstatus_t) % 8
> $2 = 0
> (kgdb) p sizeof(prfpregset_t) % 8
> $3 = 0
> (kgdb) p sizeof(thrmisc_t) % 8
> $4 = 0
>
> 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 == 0.
>
> 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.
>
> Are you ok if I commit it before introducing my changes?
Yes, I believe this is the right thing to do.
>
> Index: sys/kern/imgact_elf.c
> ===================================================================
> --- 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 += sizeof note;
> if (dst != NULL)
> bcopy(name, (char *)dst + *off, note.n_namesz);
> - *off += roundup2(note.n_namesz, sizeof(Elf_Size));
> + *off += roundup2(note.n_namesz, sizeof(Elf32_Size));
> if (dst != NULL)
> bcopy(desc, (char *)dst + *off, note.n_descsz);
> - *off += roundup2(note.n_descsz, sizeof(Elf_Size));
> + *off += roundup2(note.n_descsz, sizeof(Elf32_Size));
> }
>
> static boolean_t
>
> Also, shouldn't we update then the following comment in sys/elf_common.h?
>
> /*
> * 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.
> */
>
> --
> Mikolaj Golub
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20130331/6f307c2d/attachment.sig>
More information about the freebsd-hackers
mailing list