From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16756 invoked by alias); 6 Dec 2007 03:42:39 -0000 Received: (qmail 16746 invoked by uid 22791); 6 Dec 2007 03:42:38 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.174) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 06 Dec 2007 03:42:34 +0000 Received: by ug-out-1314.google.com with SMTP id h2so1150725ugf for ; Wed, 05 Dec 2007 19:42:31 -0800 (PST) Received: by 10.67.115.15 with SMTP id s15mr958913ugm.1196912550787; Wed, 05 Dec 2007 19:42:30 -0800 (PST) Received: by 10.86.86.9 with HTTP; Wed, 5 Dec 2007 19:42:30 -0800 (PST) Message-ID: <4053daab0712051942q2a421ac7mcc04224d673c0d1d@mail.gmail.com> Date: Thu, 06 Dec 2007 04:25:00 -0000 From: "Pedro Alves" To: gdb-patches@sourceware.org Subject: Re: [RFC] gdb/testsuite/gdb.base/fileio.exp patch for cygwin In-Reply-To: <4053daab0712051706k528ad3d1m9fb692bdaba9560a@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <000101c83593$89c0fcd0$9d42f670$@u-strasbg.fr> <4755E78F.7000301@portugalmail.pt> <20071205101109.GA31968@calimero.vinschen.de> <47572C95.9030804@portugalmail.pt> <20071205230119.GA15204@caradoc.them.org> <4053daab0712051706k528ad3d1m9fb692bdaba9560a@mail.gmail.com> X-Google-Sender-Auth: 2719c13e79225135 X-IsSubscribed: yes 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 X-SW-Source: 2007-12/txt/msg00100.txt.bz2 Pedro Alves wrote: > Daniel Jacobowitz wrote: > > > I might be mistaken, but I don't think there's any way to figure out > > the original identity of the pipe. Handles aren't globally unique, > > are they? > > > > Yeah, I keep thinking CE, where they *are* global. > > There may be other ways to identify the pipes, like using > named pipes for the ttys if possible -- but I don't know if > it's possible to get a pipe name from a pipe handle. If > there's a way to know if two handles point to the same > object it should work too, but I don't think that's possible either... > Just for completeness: Been googling a bit, and, as the Cygwin folks sure know, under NT it is possible to get the internal names of objects, and NT assigns unique names to pipes. This is from the test files pasted at the bottom: >./parent.exe par: Filename from handle (STD_INPUT_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000002 par: Filename from handle (STD_OUTPUT_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000003 par: Filename from handle (STD_ERROR_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000003 par: Filename from handle (hReadPipe) returned : \Device\NamedPipe\Win32Pipes.00000290.00000002 par: Filename from handle (hWritePipe) returned : \Device\NamedPipe\Win32Pipes.00000290.00000002 par: Filename from handle (h) returned : \Device\NamedPipe\testpipe par: Filename from handle (duph) returned : \Device\NamedPipe\Win32Pipes.00000290.00000002 child: Filename from handle (STD_INPUT_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000002 child: Filename from handle (STD_OUTPUT_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000003 child: Filename from handle (STD_ERROR_HANDLE) returned : \Device\NamedPipe\Win32Pipes.00000c70.00000003 Notice that the STD_{INPUT|OUTPUT|ERROR}_HANDLEs are the same pipes. Since the next big Cygwin release will be NT only, perhaps this could be used to map pipes to ttys. Disclosure: I haven't really looked into Cygwin's sources to see what it would take. It may be saying something plain dumb. -- Pedro Alves parent.c: #include #include typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; typedef UNICODE_STRING *PUNICODE_STRING; #define STATUS_SUCCESS 0 typedef ULONG NTSTATUS; typedef enum _OBJECT_INFO_CLASS { ObjectBasicInfo, ObjectNameInfo, ObjectTypeInfo, ObjectAllTypesInfo, ObjectProtectionInfo } OBJECT_INFO_CLASS; typedef NTSTATUS (NTAPI * NTQUERYOBJECT)(HANDLE, OBJECT_INFO_CLASS, PVOID, ULONG, PULONG); typedef struct ObjectNameInfo_t { UNICODE_STRING ObjectName; WCHAR ObjectNameBuffer[1]; } OBJECT_NAME_INFO, *POBJECT_NAME_INFO; static BOOL print_object_name (const char *var, HANDLE h) { HMODULE ntdll = GetModuleHandle ("ntdll.dll"); NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT) GetProcAddress (ntdll, "NtQueryObject"); char buf1[1024]; char buf2[1024]; POBJECT_NAME_INFO pObjectNameInfo = (POBJECT_NAME_INFO) buf1; int rc = NtQueryObject (h, ObjectNameInfo, buf1, sizeof (buf1), NULL); if (rc != STATUS_SUCCESS) { printf ("NtQueryObject failed with rc = 0x%x\n", rc); return FALSE; } wcstombs (buf2, pObjectNameInfo->ObjectName.Buffer, 1024); printf ("par: Filename from handle (%s) returned :\n%s\n", var, buf2); return 0; } int main (int argc, char **argv) { print_object_name ("STD_INPUT_HANDLE", GetStdHandle (STD_INPUT_HANDLE)); print_object_name ("STD_OUTPUT_HANDLE", GetStdHandle (STD_OUTPUT_HANDLE)); print_object_name ("STD_ERROR_HANDLE", GetStdHandle (STD_ERROR_HANDLE)); DWORD bufferSize = 1024; HANDLE h = CreateNamedPipe ("\\\\.\\pipe\\testpipe", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 1, NULL); if (h == INVALID_HANDLE_VALUE) { printf ("CreateNamedPipe failed\n"); return 1; } HANDLE hReadPipe; HANDLE hWritePipe; BOOL good = CreatePipe (&hReadPipe, &hWritePipe, NULL, 100); if (!good) { printf ("CreatePipe failed\n"); return 1; } print_object_name ("hReadPipe", hReadPipe); print_object_name ("hWritePipe", hWritePipe); print_object_name ("h", h); HANDLE duph = INVALID_HANDLE_VALUE; if (!DuplicateHandle (GetCurrentProcess(), hReadPipe, GetCurrentProcess(), &duph, 0, TRUE, DUPLICATE_SAME_ACCESS)) { printf ("DuplicateHandle failed\n"); return 1; } print_object_name ("duph", duph); PROCESS_INFORMATION pi; STARTUPINFO si; memset (&si, 0, sizeof (si)); si.cb = sizeof (si); CreateProcess (0, "child.exe",/* command line */ NULL, /* Security */ NULL, /* thread */ TRUE, /* inherit handles */ 0, /* start flags */ NULL, /* environment */ NULL, /* current directory */ &si, &pi); return 0; } --------- child.c: #include #include typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING; typedef UNICODE_STRING *PUNICODE_STRING; #define STATUS_SUCCESS 0 typedef ULONG NTSTATUS; typedef enum _OBJECT_INFO_CLASS { ObjectBasicInfo, ObjectNameInfo, ObjectTypeInfo, ObjectAllTypesInfo, ObjectProtectionInfo } OBJECT_INFO_CLASS; typedef NTSTATUS (NTAPI * NTQUERYOBJECT)(HANDLE, OBJECT_INFO_CLASS, PVOID, ULONG, PULONG); typedef struct ObjectNameInfo_t { UNICODE_STRING ObjectName; WCHAR ObjectNameBuffer[1]; } OBJECT_NAME_INFO, *POBJECT_NAME_INFO; static BOOL print_object_name (const char *var, HANDLE h) { HMODULE ntdll = GetModuleHandle ("ntdll.dll"); NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT) GetProcAddress (ntdll, "NtQueryObject"); char buf1[1024]; char buf2[1024]; POBJECT_NAME_INFO pObjectNameInfo = (POBJECT_NAME_INFO) buf1; int rc = NtQueryObject (h, ObjectNameInfo, buf1, sizeof (buf1), NULL); if (rc != STATUS_SUCCESS) { printf ("NtQueryObject failed with rc = 0x%x\n", rc); return FALSE; } wcstombs (buf2, pObjectNameInfo->ObjectName.Buffer, 1024); printf ("child: Filename from handle (%s) returned :\n%s\n", var, buf2); return 0; } int main (int argc, char **argv) { print_object_name ("STD_INPUT_HANDLE", GetStdHandle (STD_INPUT_HANDLE)); print_object_name ("STD_OUTPUT_HANDLE", GetStdHandle (STD_OUTPUT_HANDLE)); print_object_name ("STD_ERROR_HANDLE", GetStdHandle (STD_ERROR_HANDLE)); return 0; }