From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 31 15:53:07 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id CCE7CF20; Sun, 31 Mar 2013 15:53:07 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-ea0-x234.google.com (mail-ea0-x234.google.com [IPv6:2a00:1450:4013:c01::234]) by mx1.freebsd.org (Postfix) with ESMTP id B5823194; Sun, 31 Mar 2013 15:53:06 +0000 (UTC) Received: by mail-ea0-f180.google.com with SMTP id d10so760577eaj.39 for ; Sun, 31 Mar 2013 08:53:05 -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=j7bLVLKmSZl4rEFkKRnYUi0ulhRmxhfLnYzK1oLwFa4=; b=sWP08neyoODp/wV7Q080wwGKGx0pEUMYNmV5ktLBHZuDDb5ctDqNYNdenyspn0eOcX NLgy0W1rm77/QEA+tIT4re4z4BG6eKK2VND6GyNucDom7lcX9FOVhIuqCCXl5KbuylCu kvt8y+6IyA2rTJqB/fubcnalDkdHbuCRf/IBaAZvZw4dyt4asq4a0z986zY2R1ER7eau ORMOhl77hVlSUM1gzUGPgft2MuIC7Ce2O95HvK32NIm6dY5xCMm71DvU2qX4h1wsx4pH EsQJ7OTg1s5eZ2GljsLDMQ6J2QlW/+ro7IzkWD1RsfijzYcX3GBGzWWl9oI7IOHYw4v9 3EQg== X-Received: by 10.14.182.72 with SMTP id n48mr28997820eem.3.1364745185765; Sun, 31 Mar 2013 08:53:05 -0700 (PDT) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPS id q42sm16154073eem.14.2013.03.31.08.53.03 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 31 Mar 2013 08:53:04 -0700 (PDT) Sender: Mikolaj Golub Date: Sun, 31 Mar 2013 18:53:00 +0300 From: Mikolaj Golub To: Konstantin Belousov Subject: Re: libprocstat(3): retrieve process command line args and environment Message-ID: <20130331155259.GA9867@gmail.com> References: <20130316191605.GJ3794@kib.kiev.ua> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130331134047.GN3794@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) 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 15:53:07 -0000 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. 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? 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