From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 18 23:23:56 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7E9B733B for ; Sun, 18 Aug 2013 23:23:56 +0000 (UTC) (envelope-from cjpugmed@gmail.com) Received: from mail-vb0-x22b.google.com (mail-vb0-x22b.google.com [IPv6:2607:f8b0:400c:c02::22b]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3D0B22335 for ; Sun, 18 Aug 2013 23:23:56 +0000 (UTC) Received: by mail-vb0-f43.google.com with SMTP id h11so2798027vbh.16 for ; Sun, 18 Aug 2013 16:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rSNVK0QWDX1neW/QrNFpwo17PJY4z5MmLWUc/alXNEE=; b=hHzqFAwE44l1vuk71xjRWsURL1hydYmL7MywsKP+HSLdRO5kouuo5Tvdf+fDcCCWzj dnrg8onkuN5sd+IXWT32S211ZAiCI4h4LtqXHPNkEXhdBNuwUvKm/t+6Frfce8GiHT7O DHBtwnVFu00mAZGt+5HxTcSYTXc7MV079dVL7NmFMP8rK7O1UzxMMZHsRgP7ZbBEgImO VdrnWY2sB4rufyADrIXI1V1AbxbPW6x/mAebuFIWWYv/a4rb30DIWjI6KUMh8hr9SjXX uEYmcYQWfGzzrzgVxstb7vKhbwPx4Moavpd4xrn+MjJ9cxQCcbI/JRYrdr9bzs23e5RL Ks/w== MIME-Version: 1.0 X-Received: by 10.52.164.102 with SMTP id yp6mr9031344vdb.14.1376868235352; Sun, 18 Aug 2013 16:23:55 -0700 (PDT) Received: by 10.220.1.17 with HTTP; Sun, 18 Aug 2013 16:23:55 -0700 (PDT) In-Reply-To: <201308182205.r7IM5BQR062114@elf.torek.net> References: <201308182205.r7IM5BQR062114@elf.torek.net> Date: Mon, 19 Aug 2013 01:23:55 +0200 Message-ID: Subject: Re: ps_strings From: Carlos Jacobo Puga Medina To: superbisquit@gmail.com, fernando.apesteguia@gmail.com, Chris Torek X-Mailman-Approved-At: Tue, 20 Aug 2013 02:04:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: 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, 18 Aug 2013 23:23:56 -0000 First, I want to thank Super Bisquit, Fernando and Chris for their inputs. Second, the ps_strings struct remains in use to report information about the running process back to the user and operating system, and as such enriches the content of the FreeBSD kernel, so it's worth create this man page. However, I'll consult this with a member of the doc team so that everything is in order. Attentively --CJPM 2013/8/19 Chris Torek > >Despite I made a request not long ago[1], I'm looking for > >documentation to create the ps_strings structure man page because > >isn't covered in other man page such e.g. execve(2). So, I'm > >interested to know for what it's currently used. > > Nothing. (Well, backwards compatibility, depending on how far > backwards you go.) > > I invented the "ps_strings" struct a long time ago, about the same > time libkvm was new. > > Some background: There was code in "ps" that would grub around in > the top stack page of each user process and extract the argv > strings. This code knew how execve() worked inside the kernel > (copying the argv and environment strings into the user stack, > just below the signal trampoline code, and then setting up argv > and envp pointers and invoking the libc/csu "start program" code > at the entry point). > > We moved this grub-around-in-process-stack code to libkvm, but it > was still rather horrible code. > > Meanwhile, we had programs like sendmail that would "set their > process title" by saving, in some secret global variable, the > space where the "argv" array itself and its strings lived, and > then -- in setproctitle() -- carefully overwrite it. Of course > there was only as much room there as the kernel provided, based on > the actual strings at execve() time. > > I figured this would all be much cleaner if we created a small > data structure, namely "ps_strings", to hold the information that > libkvm would extract (and hence, ps would show). It would be > simpler than the original code, because the ps_strings structure > lived at a fixed, well known user-space virtual address (the same > VA in every process). Moreover, a user program (like sendmail) > could modify the ps_strings data to point to any other user-space > area: libkvm was smart enough to extract arbitrary data (and > verify the validity of the address too). This removed the limit > on how large a "process title" could be. > > FreeBSD now, however, uses a per-process p_args field in the > "proc" structure, with sysctl()s to set and get p_args. (I had > nothing to do with this new code, but I approve, as if anyone > cares. :-) ) This removes the fixed-virtual-address limitation. > The cost is a bit more kernel code (for the sysctl()s) and this > per-process data, but there is no more messing-about with "where > is ps_strings in this memory-layout / emulation" etc. (Meanwhile > libkvm still retrieves the arguments. It just does it now with > sysctl().) > > Chris >