delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/11/30/07:30:07

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=i27NI7lcdb86VUusgMiP6S75zmaLAmeCx4NEvaGRqlNx5FXr+yjSS
lMyz6ElfrO11ZuHMp2JuQExH3mOvQgHDPjztjlZSR3BMIrFl7AyEzRFF2iv8NVVF
sNtFmxS1YA85fL3HjFVDHOQ7nyf81tBTCU81woU8dp3wgugOedgHR8=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=YvMQbB5iH7uSXumrOkp62D4cST0=; b=Q2mSSbhW2z45kyMrS10v16AVKSJl
+QU6RKMhyqO37fIz1WUXW2nbovLsqx/aykIXyq1O8267uzfKQIlOPU9K98e4VXZt
0FTqmtkSD27/jGUoLe+6RSLSSE2V3gcp5cx8ZNDWqOiu/MVuaRvFKFsSPVDQuDzI
FWo/wQS7G7rKK2o=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-101.6 required=5.0 tests=BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=stages, secs, H*MI:sk:RE_GsuH, H*i:CAOTD34b6L
X-HELO: drew.franken.de
Date: Wed, 30 Nov 2016 13:29:39 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Retrieving per-process environment block?
Message-ID: <20161130122939.GC22541@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CAOTD34ZFH5E3r3AuDOXctss46e1hoU2f9pwE1mt4L674J2Ak_A AT mail DOT gmail DOT com> <20161117140012 DOT GA23664 AT calimero DOT vinschen DOT de> <CAOTD34Y9TRq2Qq8Mn2awTf9SCgz0qnbBa-a117pkSEvz9gaHKQ AT mail DOT gmail DOT com> <20161130104334 DOT GB14074 AT calimero DOT vinschen DOT de> <CAOTD34b6L--aGJpzDuJzqEPdhOnPiVOYWW-UzK1kZ+RE_GsuHw AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAOTD34b6L--aGJpzDuJzqEPdhOnPiVOYWW-UzK1kZ+RE_GsuHw@mail.gmail.com>
User-Agent: Mutt/1.7.1 (2016-10-04)

--NKoe5XOeduwbEQHU
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Nov 30 12:35, Erik Bray wrote:
> On Wed, Nov 30, 2016 at 11:43 AM, Corinna Vinschen
> <corinna-cygwin AT cygwin DOT com> wrote:
> > So how do we contact the other process to ask for information?
> >
> > We have a mechanism inside Cygwin to request info from another process.
> > It's part of the signal handling and consists basically of two
> > functions.  The applicant calls _pinfo::commune_request(), this will
> > send a request into the signal pipe of the target process, this in turn
> > will call commune_process(), a callback function, within the target
> > process.
> >
> > Have a look into an example:
> >
> > Start in fhandler_process.cc, function format_process_cmdline()
> > which implements /proc/$PID/cmdline.
> >
> > It fetches the _pinfo pointer of the target process and calls
> > _pinfo::cmdline.
> >
> > _pinfo::cmdline (in pinfo.cc) checks if the target process is a
> > native Windows process a Cygwin process, or if its itself.
> >
> > In the native Windows case, it opens a handle to the target process,
> > fetches its RTL_USER_PROCESS_PARAMETERS block (function
> > open_commune_proc_parms).  and fetches the info from the target process
> > by directly reading from its memory.  If it's itself it just constructs
> > the info as desired and returns.  Boring.
> >
> > In the Cygwin case, it calls _pinfo::commune_request (PICOM_CMDLINE).
> > PICOM_CMDLINE is defined in pinfo.h, together with other values for the
> > commune requests.  It send the request over the signal pipe to the
> > target process.
> >
> > The target process receives the request and calls commune_process().  It
> > checks what info is requested, prepares the info and send it back over
> > over the signal pipe.
> >
> > The (waiting) _pinfo::commune_request fetches the info from the pipe and
> > returns to _pinfo::cmdline, which in turn returns to format_process_cmd=
line().
> >
> > So, ultimately, just copy the functionality of format_process_cmdline,
> > _pinfo::cmdline, as well as the handling of PICOM_CMDLINE in
> > _pinfo::commune_request and commune_process and you're done.
>=20
> Hi Corinna,
>=20
> Thank you for the detailed guidance on that--that all makes sense.  I
> feel silly for missing that--I was actually poking around to see if
> there was already something like that in the source but missed it.
> For some reason I thought the cmdline was just stored directly in the
> pinfo object itself.

There's a catch.  The shared mem regions maintained by Cygwin are
supposed to fit in one allocation page, that is, 64K, at a reproducible
slot in the processes VM (think fork).  Variable size information,
especially information which can have an almost arbitrary size, is quite
tricky to be held in shared mem.

> But I knew, considering how signals are handled, that there had to be
> some communication channel between processes; I just didn't know how
> to use it for general purposes.  I just played around with it a bit
> and I get the gist of how __SIGCOMMUNE works, etc.  Very clever.

Curtesy cgf.  The commune mechanism obviously depends on the reliability
of the signal handling.  It also has a problem in that, since it's a part
of signal handling itself, it can't be interrupted by signals.  In earlier
stages it was pretty bad, but at one point we just changed the pipe calls
to timeout after 1 second each, so either it works or it times out after
a max of 2 secs and the information is just not available on the client
side.  There's worse than that.

> I can see what to do now--thanks.

Cool.


Thanks,
Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--NKoe5XOeduwbEQHU
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJYPsYzAAoJEPU2Bp2uRE+gNzkP+wZWCEKOJXf8WH+iX+uUmCJZ
5IUkbApGvv0oL8KatsWbTv/c1rG+tqTN6k7zKUBlCUKc7NORfAdZJ2I2UM4suyg/
KQTuz5bepOastBq/KizqmLN4dmUZ874eeYSgqBMibpjaYUwrCg9+ZOqh7V6EPB9j
Es/G1ab3bkEnGUwDG3+8ag/HXz3jASbT2TxIMw+vVU6iP+t5EgwEczRsnJeAizX7
T/itTz7L5lUHDy4XGvxwVhnBlnX6ymXuEVThWDPnRWSjOJZmuG20aERzBQAu2rDH
QPDDX5/jDaVViu/v0zhh9iM8H9Rg1/1OvKMIYKc5MyelCbaZrICKsViHc42EBl+f
zVOIxUmRULmlINXWM5xN+aH8qa8iTa2hi2GjlwZdOXT2Az+6kjXMTL3t6dKWdbmY
oJhclEoXd7YBVz+NYTIcnIVi4hwSRKW9HCtVXqNIIYQZxWPjFQ+MpPHkch4Ygh//
fHDVqJMSgsTFfJG+khQQlK0Vzi2vA++0Kg/GpUb/s85zeisF1Qy5GrjG4IrslBfJ
ug6YVcLteQQ/fiPUU7nWSQ4athxdnedNcLD7gVew2FH52YlCc8hhHstz+oRoiG4D
XH05lnd08d8EQ1tZzEmpippBnhkkF71rNtMc3yTFzvytmhogotCuKiFG6rMDjyZ/
GLNgAq7OpXgBACxBhsvC
=z7wu
-----END PGP SIGNATURE-----

--NKoe5XOeduwbEQHU--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019