public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: tom@tromey.com, gdb-patches@sourceware.org
Subject: Re: [RFC 00/17] Merge event loop implementations
Date: Fri, 27 Sep 2019 14:53:00 -0000	[thread overview]
Message-ID: <1a09dab3-9dc2-f864-00aa-5e3b3a0e2b13@redhat.com> (raw)
In-Reply-To: <8336ghkegs.fsf@gnu.org>

On 9/27/19 3:20 PM, Eli Zaretskii wrote:
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <palves@redhat.com>
>> Date: Fri, 27 Sep 2019 15:05:27 +0100
>>
>> But, given that gdb (unlike gdbserver), has been using "int"
>> for sockets on Windows for a long while, and 64-bit Windows
>> has been a thing for a long while too, I wonder whether in
>> practice Windows just makes sure that SOCKET handles
>> fit in 32-bit integers, exactly to avoid porting headaches...
> 
> SOCKET is a 64-bit data type on 64-bit Windows.  However, according to
> this:
> 
>   https://stackoverflow.com/questions/1953639/is-it-safe-to-cast-socket-to-int-under-win64
> 
> Microsoft is unlikely to ever populate the high 32 bits with anything
> but zero.
> 
> So I'd generally recommend using DWORDPTR or uintptr_t for SOCKETs,
> but I'm guessing we are good using unsigned ints instead, if changing
> that is too much trouble.

Using unsigned ints would be as much trouble as any other type, because
it'd be in conflict with the type that we want to use for Unix -- int.

The main complication is that the code in question works with int file
descriptors, and accepts / passes around all kinds of file descriptors,
including PTYs, sockets, the console's file descriptor on
Windows (fileno(stdin)), etc., all using a single type.

So if we go the typedef way, it'd have to be a type that could
fit all the different types of handles/descriptors on Windows (i.e.,
a 64-bit-wide unsigned integer in practice), and then all code that
checks for handle validity would have to be tweaked to not do
"fd < 0" or "fd == -1" but instead maybe call some callback to validate
the handle.  That seems a lot of trouble, and unusual.  The gnulib
select route seems more attractive compared to that.

Reading that stackoverflow, I'm convinced that we should
just do what everyone does and cast SOCKET to int like gdb is
already doing, and move on.

Alternatively, if someone feels up to it, we could also borrow
what gnulib's socket replacement does, which is to use these
two macros to convert between a socket and a file descriptor:

 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
 #define SOCKET_TO_FD(fh)   (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY))

_open_osfhandle "Associates a C run-time file descriptor with an existing operating
system file handle.", per:
 https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=vs-2019

But then again, might as well use gnulib's socket/select/etc.
instead of redoing it ourselves.

In conclusion, I suggest sweeping the issue under the rug for now
and cast SOCKET to int for this series, like GDB already does.

Actually, gdbserver also does that too -- gdb_socket_cloexec
returns int, and gdbserver/remote-utils.c uses that to open sockets.

So removing gdb_fildes_t is not really making things worse.

Thanks,
Pedro Alves

  reply	other threads:[~2019-09-27 14:53 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-24 16:51 Tom Tromey
2019-02-24 16:52 ` [RFC 14/17] Remove some dead code from event-loop.c Tom Tromey
2019-02-24 16:52 ` [RFC 12/17] Add the ability to stop the event loop Tom Tromey
2019-02-24 16:52 ` [RFC 07/17] Use warning in event-loop Tom Tromey
2019-09-26 14:02   ` Pedro Alves
2019-02-24 16:52 ` [RFC 15/17] Move gdb_notifier comment Tom Tromey
2019-09-26 14:06   ` Pedro Alves
2019-02-24 16:52 ` [RFC 13/17] Switch gdbserver to common event loop Tom Tromey
2019-02-24 16:52 ` [RFC 11/17] Implement event-loop glue for gdbserver Tom Tromey
2019-02-24 16:52 ` [RFC 02/17] Move gdb-specific code out of start_event_loop Tom Tromey
2019-09-26 14:02   ` Pedro Alves
2019-02-24 16:52 ` [RFC 16/17] Remove gdb_fildes_t Tom Tromey
2019-02-24 16:52 ` [RFC 05/17] Remove gdb_usleep.c Tom Tromey
2019-09-26 14:02   ` Pedro Alves
2019-09-26 14:43     ` Tom Tromey
2019-02-24 16:52 ` [RFC 06/17] Include <chrono> in event-loop.c Tom Tromey
2019-09-26 14:02   ` Pedro Alves
2019-02-24 16:52 ` [RFC 10/17] Move event-loop.[ch] to common/ Tom Tromey
2019-09-26 14:06   ` Pedro Alves
2019-10-04 22:06     ` Tom Tromey
2019-02-24 16:52 ` [RFC 04/17] Move gdb_select.h " Tom Tromey
2019-02-24 16:52 ` [RFC 03/17] Move event-loop configury to common.m4 Tom Tromey
2019-02-24 16:52 ` [RFC 08/17] Introduce and use flush_streams Tom Tromey
2019-02-24 16:52 ` [RFC 17/17] Simplify gdbserver's serial event handling Tom Tromey
2019-09-26 17:36   ` Pedro Alves
2019-10-04 22:08     ` Tom Tromey
2019-02-24 16:52 ` [RFC 09/17] Introduce async-event.[ch] Tom Tromey
2019-09-26 14:06   ` Pedro Alves
2019-10-04 22:17     ` Tom Tromey
2019-02-24 16:52 ` [RFC 01/17] Remove include from event-loop.c Tom Tromey
2019-02-24 17:14 ` [RFC 00/17] Merge event loop implementations Eli Zaretskii
2019-02-24 17:26   ` Tom Tromey
2019-02-24 17:45     ` Eli Zaretskii
2019-02-25 19:57       ` Tom Tromey
2019-02-25 20:30         ` Eli Zaretskii
2019-02-25 20:55           ` Tom Tromey
2019-02-26 16:04             ` Eli Zaretskii
2019-02-26 16:23               ` Tom Tromey
2019-02-26 16:46                 ` Eli Zaretskii
2019-09-26 17:47 ` Pedro Alves
2019-09-26 23:09   ` Tom Tromey
2019-09-27 13:53     ` Pedro Alves
2019-09-27 14:05       ` Pedro Alves
2019-09-27 14:21         ` Eli Zaretskii
2019-09-27 14:53           ` Pedro Alves [this message]
2019-09-27 15:32             ` Eli Zaretskii
2019-09-27 19:10       ` Tom Tromey
2020-02-14  2:22         ` Tom Tromey
2020-02-14 17:58           ` Pedro Alves
2020-02-14 18:36             ` Tom Tromey
2019-10-04 22:25   ` Tom Tromey
2020-02-14 18:20     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a09dab3-9dc2-f864-00aa-5e3b3a0e2b13@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).