From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111895 invoked by alias); 31 Mar 2015 15:42:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 111878 invoked by uid 89); 31 Mar 2015 15:42:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 31 Mar 2015 15:42:18 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id B94DBA80A3F; Tue, 31 Mar 2015 17:42:15 +0200 (CEST) Date: Tue, 31 Mar 2015 15:42:00 -0000 From: Corinna Vinschen To: gdb-patches@sourceware.org Subject: Re: [patch/cygwin] Remove dependency on __COPY_CONTEXT_SIZE Message-ID: <20150331154215.GL13285@calimero.vinschen.de> Reply-To: gdb-patches@sourceware.org Mail-Followup-To: gdb-patches@sourceware.org References: <20150330100454.GA8372@calimero.vinschen.de> <551A9443.5010907@redhat.com> <20150331143643.GA10846@calimero.vinschen.de> <551AB630.4010800@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YQEH9CATo+4lan7A" Content-Disposition: inline In-Reply-To: <551AB630.4010800@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg01050.txt.bz2 --YQEH9CATo+4lan7A Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 3442 On Mar 31 15:58, Pedro Alves wrote: > On 03/31/2015 03:36 PM, Corinna Vinschen wrote: > > On Mar 31 13:34, Pedro Alves wrote: > >> On 03/30/2015 11:04 AM, Corinna Vinschen wrote: > >> > >>> @@ -820,7 +819,7 @@ handle_output_debug_string (struct target_waitsta= tus *ourstatus) > >>> #endif > >>> warning (("%s"), s); > >>> } > >>> -#ifdef __COPY_CONTEXT_SIZE > >>> +#ifdef __CYGWIN__ > >>> else > >>> { > >>> /* Got a cygwin signal marker. A cygwin signal is followed by > >>> @@ -847,8 +846,8 @@ handle_output_debug_string (struct target_waitsta= tus *ourstatus) > >>> else if ((x =3D (LPCVOID) (uintptr_t) strtoull (p, NULL, 0)) > >>> && ReadProcessMemory (current_process_handle, x, > >>> &saved_context, > >>> - __COPY_CONTEXT_SIZE, &n) > >>> - && n =3D=3D __COPY_CONTEXT_SIZE) > >>> + sizeof (CONTEXT), &n) > >> > >> Is that really wise? AFAIK, the size of the CONTEXT structure can > >> grow as MSFT adds more registers to support newer machines. > >=20 > > No, that's not possible. The CONTEXT structure matches the platform. > > It doesn't even contain a version number. Consider that the structure > > is available in user space. If Microsoft changes the size on a given > > platform, applications built for this platform might crash due to > > overwritten memory. They wouldn't do that. >=20 > That's not true. GetThreadContext takes a size parameter, > and only writes to the bits that the caller requests with > context.ContextFlags. The ContextFlags member is not a size parameter, it's a bit flag parameter. It tells the OS which values are required, but the flags are responsible for different aspects of the CONTEXT structure and this does not change the size of the CONTEXT datatype. The code in question always copies the exact size of CONTEXT, and that doesn't change per platform. > A size parameter is common in Windows API land > to permit later versions. If the structure grows, evidently the new > fields will need to be requested with a new context.ContextFlags flag. O= ld > applications will never request that extra flag, and will be passing > a smaller SIZE to GetThreadContext, so it won't ever overwrite memory. >=20 > See the description of InitializeContext's parameters: >=20 > https://msdn.microsoft.com/en-us/library/windows/desktop/hh134237%28v=3D= vs.85%29.aspx >=20 > And the remarks section: >=20 > "InitializeContext can be used to initialize a CONTEXT structure within a= buffer > with the required size and alignment characteristics. This routine is req= uired if > the CONTEXT_XSTATE ContextFlag is specified since the required context > size and alignment may change depending on which processor features are > enabled on the system. Right, but this does not change the size of the CONTEXT datatype. The additional AVX values require more space than available in the CONTEXT struct. That's why using CONTEXT_XSTATE and the AVX functions require to use InitializeContext; the size required to get these values is larger than CONTEXT, thus the function returns ERROR_INSUFFICIENT_BUFFER if ContextLength is =3D=3D sizeof (CONTEXT) only. And, we're not using this. The local variable filled with the data is of type CONTEXT and the data transmitted from Cygwin to GDB is of type CONTEXT. It's still the same size, independent of the availablity of CONTEXT_XSTATE. Corinna --=20 Corinna Vinschen Cygwin Maintainer Red Hat --YQEH9CATo+4lan7A Content-Type: application/pgp-signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJVGsBXAAoJEPU2Bp2uRE+gaj0QAKPnzyrsnM8LZOHhjsZfPl3H WZbZMHAyMDZldItCIGeYW/997GTQnknNJXjm7qxx/O0YlxRx7WmMbYb40PBuSgwS vWxXvc83MnYCAog2wARVFVHm4PlVI7jPYCWjwu0Q3qkvblARZpmPC7YcfMmMnruI d2NTFQ3WhBoZ0S0FOU/upK4PNTfuece1Jw5RRDOeLWYXDD0LeODsG+zLOV5OWwxk H1LPC4QqxPKMlWGdjaBzWnV2aD2acuwmtEPfN/KbADiTnt6KpKvE5mEVnJX8tA62 NcrFIF9NGUgq6Mjyf8XowrbnRJ3QajqQpkAlPEvBkTg5ZhJc1VWCeyEq0zFlFR7O HyJFc2Dn+MJdPKUH0RJN4B99lh81bD4wlgvsQM2+U8fwKIABbh572KYVyBsO8j4t uJMIyeCASIbtrLze6cv3XNLQ06JkawYFytcj+5x7MZD3ESqN/EnbUQz/6DS9HGwM bwRTVIxnF1Zxy5c0aI5le2RURwqib6WdS9pbW9jDUWvHC7L75+elfFUKL5OaMp1i F+cN/OFIltR4KpT06cbwBHUpWqAf+HWaA0LDBe2B44q3iJZd+XzamMfN6yr49F27 duoju7Ha3ulvi4LviIpH8CFc07gdqy8N5vnK9gelacQXRyR0FFS5vqgJuKYdRXzn D8MOYLTJPf8LoN32Pr3K =TEDk -----END PGP SIGNATURE----- --YQEH9CATo+4lan7A--