From: Samuel Thibault <samuel.thibault@gnu.org>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org,
"Flávio Cruz" <flaviocruz@gmail.com>
Subject: Re: [RFC PATCH glibc 3/12] mach, hurd: Cast through uintptr_t
Date: Sun, 12 Feb 2023 15:55:18 +0100 [thread overview]
Message-ID: <20230212145518.kr7tora7x5edlcbn@begin> (raw)
In-Reply-To: <20230212111044.610942-4-bugaevc@gmail.com>
Applied, thanks!
Sergey Bugaev, le dim. 12 févr. 2023 14:10:34 +0300, a ecrit:
> When casting between a pointer and an integer of a different size, GCC
> emits a warning (which is escalated to a build failure by -Werror).
> Indeed, if what you start with is a pointer, which you then cast to a
> shorter integer and then back again, you're going to cut off some bits
> of the pointer.
>
> But if you start with an integer (such as mach_port_t), then cast it to
> a longer pointer (void *), and then back to a shorter integer, you are
> fine. To keep GCC happy, cast through an intermediary uintptr_t, which
> is always the same size as a pointer.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> htl/cthreads-compat.c | 5 +++--
> hurd/fopenport.c | 15 ++++++++++-----
> hurd/hurd/port.h | 2 +-
> hurd/port-cleanup.c | 3 ++-
> hurd/vpprintf.c | 6 ++++--
> mach/devstream.c | 9 +++++----
> 6 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/htl/cthreads-compat.c b/htl/cthreads-compat.c
> index 55043a8b..2a0a95b6 100644
> --- a/htl/cthreads-compat.c
> +++ b/htl/cthreads-compat.c
> @@ -25,8 +25,9 @@ void
> __cthread_detach (__cthread_t thread)
> {
> int err;
> + pthread_t pthread = (pthread_t) (uintptr_t) thread;
>
> - err = __pthread_detach ((pthread_t) thread);
> + err = __pthread_detach (pthread);
> assert_perror (err);
> }
> weak_alias (__cthread_detach, cthread_detach)
> @@ -40,7 +41,7 @@ __cthread_fork (__cthread_fn_t func, void *arg)
> err = __pthread_create (&thread, NULL, func, arg);
> assert_perror (err);
>
> - return (__cthread_t) thread;
> + return (__cthread_t) (uintptr_t) thread;
> }
> weak_alias (__cthread_fork, cthread_fork)
>
> diff --git a/hurd/fopenport.c b/hurd/fopenport.c
> index 60afb445..be6aa30c 100644
> --- a/hurd/fopenport.c
> +++ b/hurd/fopenport.c
> @@ -28,9 +28,10 @@ readio (void *cookie, char *buf, size_t n)
> mach_msg_type_number_t nread;
> error_t err;
> char *bufp = buf;
> + io_t io = (io_t) (uintptr_t) cookie;
>
> nread = n;
> - if (err = __io_read ((io_t) cookie, &bufp, &nread, -1, n))
> + if (err = __io_read (io, &bufp, &nread, -1, n))
> return __hurd_fail (err);
>
> if (bufp != buf)
> @@ -50,8 +51,9 @@ writeio (void *cookie, const char *buf, size_t n)
> {
> vm_size_t wrote;
> error_t err;
> + io_t io = (io_t) (uintptr_t) cookie;
>
> - if (err = __io_write ((io_t) cookie, buf, n, -1, &wrote))
> + if (err = __io_write (io, buf, n, -1, &wrote))
> return __hurd_fail (err);
>
> return wrote;
> @@ -65,7 +67,8 @@ seekio (void *cookie,
> off64_t *pos,
> int whence)
> {
> - error_t err = __io_seek ((file_t) cookie, *pos, whence, pos);
> + io_t io = (io_t) (uintptr_t) cookie;
> + error_t err = __io_seek (io, *pos, whence, pos);
> return err ? __hurd_fail (err) : 0;
> }
>
> @@ -74,8 +77,9 @@ seekio (void *cookie,
> static int
> closeio (void *cookie)
> {
> + io_t io = (io_t) (uintptr_t) cookie;
> error_t error = __mach_port_deallocate (__mach_task_self (),
> - (mach_port_t) cookie);
> + io);
> if (error)
> return __hurd_fail (error);
> return 0;
> @@ -127,6 +131,7 @@ __fopenport (mach_port_t port, const char *mode)
> return NULL;
> }
>
> - return fopencookie ((void *) port, mode, funcsio);
> + return fopencookie ((void *) (uintptr_t) port,
> + mode, funcsio);
> }
> weak_alias (__fopenport, fopenport)
> diff --git a/hurd/hurd/port.h b/hurd/hurd/port.h
> index fdba8db5..1e473978 100644
> --- a/hurd/hurd/port.h
> +++ b/hurd/hurd/port.h
> @@ -96,7 +96,7 @@ _hurd_port_locked_get (struct hurd_port *port,
> if (result != MACH_PORT_NULL)
> {
> link->cleanup = &_hurd_port_cleanup;
> - link->cleanup_data = (void *) result;
> + link->cleanup_data = (void *) (uintptr_t) result;
> _hurd_userlink_link (&port->users, link);
> }
> __spin_unlock (&port->lock);
> diff --git a/hurd/port-cleanup.c b/hurd/port-cleanup.c
> index 08ab3d47..ad43b830 100644
> --- a/hurd/port-cleanup.c
> +++ b/hurd/port-cleanup.c
> @@ -26,7 +26,8 @@
> void
> _hurd_port_cleanup (void *cleanup_data, jmp_buf env, int val)
> {
> - __mach_port_deallocate (__mach_task_self (), (mach_port_t) cleanup_data);
> + mach_port_t port = (mach_port_t) (uintptr_t) cleanup_data;
> + __mach_port_deallocate (__mach_task_self (), port);
> }
>
> /* We were cancelled while using a port, and called from the cleanup unwinding.
> diff --git a/hurd/vpprintf.c b/hurd/vpprintf.c
> index fe734946..010f04ca 100644
> --- a/hurd/vpprintf.c
> +++ b/hurd/vpprintf.c
> @@ -25,8 +25,9 @@
> static ssize_t
> do_write (void *cookie, const char *buf, size_t n)
> {
> + io_t io = (io_t) (uintptr_t) cookie;
> vm_size_t amount = n;
> - error_t error = __io_write ((io_t) cookie, buf, n, -1, &amount);
> + error_t error = __io_write (io, buf, n, -1, &amount);
> if (error)
> return __hurd_fail (error);
> return n;
> @@ -51,7 +52,8 @@ vpprintf (io_t port, const char *format, va_list arg)
> #endif
>
> _IO_cookie_init (&temp_f.cfile, _IO_NO_READS,
> - (void *) port, (cookie_io_functions_t) { write: do_write });
> + (void *) (uintptr_t) port,
> + (cookie_io_functions_t) { write: do_write });
>
> done = __vfprintf_internal (&temp_f.cfile.__fp.file, format, arg, 0);
>
> diff --git a/mach/devstream.c b/mach/devstream.c
> index 09272d10..cfa9a4f4 100644
> --- a/mach/devstream.c
> +++ b/mach/devstream.c
> @@ -28,7 +28,7 @@
> static ssize_t
> devstream_write (void *cookie, const char *buffer, size_t n)
> {
> - const device_t dev = (device_t) cookie;
> + const device_t dev = (device_t) (uintptr_t) cookie;
>
> int write_some (const char *p, size_t to_write)
> {
> @@ -83,7 +83,7 @@ devstream_write (void *cookie, const char *buffer, size_t n)
> static ssize_t
> devstream_read (void *cookie, char *buffer, size_t to_read)
> {
> - const device_t dev = (device_t) cookie;
> + const device_t dev = (device_t) (uintptr_t) cookie;
>
> kern_return_t err;
> mach_msg_type_number_t nread = to_read;
> @@ -112,7 +112,8 @@ devstream_read (void *cookie, char *buffer, size_t to_read)
> static int
> dealloc_ref (void *cookie)
> {
> - if (__mach_port_deallocate (mach_task_self (), (mach_port_t) cookie))
> + const device_t dev = (device_t) (uintptr_t) cookie;
> + if (__mach_port_deallocate (mach_task_self (), dev))
> {
> errno = EINVAL;
> return -1;
> @@ -131,7 +132,7 @@ mach_open_devstream (mach_port_t dev, const char *mode)
> return NULL;
> }
>
> - stream = _IO_fopencookie ((void *) dev, mode,
> + stream = _IO_fopencookie ((void *) (uintptr_t) dev, mode,
> (cookie_io_functions_t) { write: devstream_write,
> read: devstream_read,
> close: dealloc_ref });
> --
> 2.39.1
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
next prev parent reply other threads:[~2023-02-12 14:55 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-12 11:10 [RFC PATCH 0/12] Towards glibc on x86_64-gnu Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 1/12] hurd: Refactor readlinkat() Sergey Bugaev
2023-02-12 14:49 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 2/12] hurd: Use mach_msg_type_number_t where appropriate Sergey Bugaev
2023-02-12 14:52 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 3/12] mach, hurd: Cast through uintptr_t Sergey Bugaev
2023-02-12 14:55 ` Samuel Thibault [this message]
2023-02-12 11:10 ` [RFC PATCH glibc 4/12] hurd: Fix xattr error value Sergey Bugaev
2023-02-12 14:56 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 5/12] htl: Fix semaphore reference Sergey Bugaev
2023-02-12 14:57 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH hurd 6/12] hurd: Fix modes_t and speeds_t types on 64-bit Sergey Bugaev
2023-02-12 15:00 ` Samuel Thibault
2023-02-12 15:15 ` Sergey Bugaev
2023-02-12 15:22 ` Samuel Thibault
2023-02-12 16:13 ` Sergey Bugaev
2023-02-12 16:30 ` Samuel Thibault
2023-02-12 19:03 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH mig 7/12] Drop -undef -ansi from cpp flags Sergey Bugaev
2023-02-12 15:01 ` Samuel Thibault
2023-02-12 18:43 ` Flávio Cruz
2023-02-12 18:44 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH mig 8/12] Set max type alignment to sizeof(long) Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 9/12] mach: Look for mach_i386.defs on x86_64 too Sergey Bugaev
2023-02-12 15:07 ` Samuel Thibault
2023-02-12 15:38 ` Sergey Bugaev
2023-02-12 15:46 ` Samuel Thibault
2023-02-12 16:01 ` Sergey Bugaev
2023-02-16 20:22 ` Joseph Myers
2023-02-12 11:10 ` [RFC PATCH glibc 10/12] hurd: Set up the basic tree for x86_64-gnu Sergey Bugaev
2023-02-12 15:15 ` Samuel Thibault
2023-02-12 11:10 ` [RFC PATCH glibc 11/12] hurd, htl: Add some x86_64-specific code Sergey Bugaev
2023-02-12 16:11 ` Samuel Thibault
2023-02-12 16:25 ` Sergey Bugaev
2023-02-12 16:36 ` Samuel Thibault
2023-02-12 16:40 ` Florian Weimer
2023-02-12 16:46 ` Samuel Thibault
2023-02-12 19:29 ` Florian Weimer
2023-02-12 19:37 ` Samuel Thibault
2023-02-12 16:51 ` Sergey Bugaev
2023-02-12 17:02 ` Samuel Thibault
2023-02-12 17:06 ` Sergey Bugaev
2023-02-12 11:10 ` [RFC PATCH glibc 12/12] C11 thrd: Downgrade the default alignment of mtx_t Sergey Bugaev
2023-02-12 15:18 ` Samuel Thibault
2023-02-12 15:52 ` Sergey Bugaev
2023-02-12 16:29 ` Samuel Thibault
2023-02-12 16:12 ` [RFC PATCH 0/12] Towards glibc on x86_64-gnu Samuel Thibault
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=20230212145518.kr7tora7x5edlcbn@begin \
--to=samuel.thibault@gnu.org \
--cc=bug-hurd@gnu.org \
--cc=bugaevc@gmail.com \
--cc=flaviocruz@gmail.com \
--cc=libc-alpha@sourceware.org \
/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).