diff mbox series

[RFC,2/12] hurd: Use mach_msg_type_number_t where appropriate

Message ID 20230212111044.610942-3-bugaevc@gmail.com
State New
Headers show
Series Towards glibc on x86_64-gnu | expand

Commit Message

Sergey Bugaev Feb. 12, 2023, 11:10 a.m. UTC
It has been decided that on x86_64, mach_msg_type_number_t stays 32-bit.
Therefore, it's not possible to use mach_msg_type_number_t
interchangeably with size_t, in particular this breaks when a pointer to
a variable is passed to a MIG routine.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 hurd/hurdioctl.c               | 2 +-
 hurd/hurdprio.c                | 2 +-
 hurd/lookup-retry.c            | 2 +-
 hurd/xattr.c                   | 4 ++--
 sysdeps/mach/hurd/getcwd.c     | 2 +-
 sysdeps/mach/hurd/readlinkat.c | 6 ++++--
 sysdeps/mach/hurd/sendfile64.c | 2 +-
 7 files changed, 11 insertions(+), 9 deletions(-)

Comments

Samuel Thibault Feb. 12, 2023, 2:52 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev via Libc-alpha, le dim. 12 févr. 2023 14:10:33 +0300, a ecrit:
> It has been decided that on x86_64, mach_msg_type_number_t stays 32-bit.
> Therefore, it's not possible to use mach_msg_type_number_t
> interchangeably with size_t, in particular this breaks when a pointer to
> a variable is passed to a MIG routine.
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
>  hurd/hurdioctl.c               | 2 +-
>  hurd/hurdprio.c                | 2 +-
>  hurd/lookup-retry.c            | 2 +-
>  hurd/xattr.c                   | 4 ++--
>  sysdeps/mach/hurd/getcwd.c     | 2 +-
>  sysdeps/mach/hurd/readlinkat.c | 6 ++++--
>  sysdeps/mach/hurd/sendfile64.c | 2 +-
>  7 files changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/hurd/hurdioctl.c b/hurd/hurdioctl.c
> index e9a6a7ea..59e6a5c1 100644
> --- a/hurd/hurdioctl.c
> +++ b/hurd/hurdioctl.c
> @@ -311,7 +311,7 @@ static int
>  siocgifconf (int fd, int request, struct ifconf *ifc)
>  {
>    error_t err;
> -  size_t data_len = ifc->ifc_len;
> +  mach_msg_type_number_t data_len = ifc->ifc_len;
>    char *data = ifc->ifc_buf;
>  
>    if (data_len <= 0)
> diff --git a/hurd/hurdprio.c b/hurd/hurdprio.c
> index dbeb272b..954d3987 100644
> --- a/hurd/hurdprio.c
> +++ b/hurd/hurdprio.c
> @@ -58,7 +58,7 @@ _hurd_priority_which_map (enum __priority_which which, int who,
>  	  int *oldpi = pi;
>  	  mach_msg_type_number_t oldpisize = pisize;
>  	  char *tw = 0;
> -	  size_t twsz = 0;
> +	  mach_msg_type_number_t twsz = 0;
>  	  err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
>  						     &pi_flags,
>  						     &pi, &pisize,
> diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
> index 0d344026..8850c4fd 100644
> --- a/hurd/lookup-retry.c
> +++ b/hurd/lookup-retry.c
> @@ -162,7 +162,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
>  			    {
>  			      char buf[1024];
>  			      char *trans = buf;
> -			      size_t translen = sizeof buf;
> +			      mach_msg_type_number_t translen = sizeof buf;
>  			      err = __file_get_translator (*result,
>  							   &trans, &translen);
>  			      if (!err
> diff --git a/hurd/xattr.c b/hurd/xattr.c
> index f98e548c..48914bcf 100644
> --- a/hurd/xattr.c
> +++ b/hurd/xattr.c
> @@ -60,7 +60,7 @@ _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
>    if (!strcmp (name, "translator"))
>      {
>        char *buf = value;
> -      size_t bufsz = value ? *size : 0;
> +      mach_msg_type_number_t bufsz = value ? *size : 0;
>        error_t err = __file_get_translator (port, &buf, &bufsz);
>        if (err)
>  	return err;
> @@ -144,7 +144,7 @@ _hurd_xattr_set (io_t port, const char *name, const void *value, size_t size,
>  	{
>  	  /* Must make sure it's already there.  */
>  	  char *buf = NULL;
> -	  size_t bufsz = 0;
> +	  mach_msg_type_number_t bufsz = 0;
>  	  error_t err = __file_get_translator (port, &buf, &bufsz);
>  	  if (err)
>  	    return err;
> diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c
> index fc5e78e7..f24b35b3 100644
> --- a/sysdeps/mach/hurd/getcwd.c
> +++ b/sysdeps/mach/hurd/getcwd.c
> @@ -117,7 +117,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir,
>        int mount_point;
>        file_t newp;
>        char *dirdata;
> -      size_t dirdatasize;
> +      mach_msg_type_number_t dirdatasize;
>        int direntry, nentries;
>  
>  
> diff --git a/sysdeps/mach/hurd/readlinkat.c b/sysdeps/mach/hurd/readlinkat.c
> index dabdbb37..5bb8b753 100644
> --- a/sysdeps/mach/hurd/readlinkat.c
> +++ b/sysdeps/mach/hurd/readlinkat.c
> @@ -35,6 +35,7 @@ __readlinkat (int fd, const char *file_name, char *buf, size_t len)
>    char retryname[1024];
>    file_t file;
>    char *rbuf = buf;
> +  mach_msg_type_number_t nread = len;
>  
>    file_stat = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0);
>    if (file_stat == MACH_PORT_NULL)
> @@ -59,15 +60,16 @@ __readlinkat (int fd, const char *file_name, char *buf, size_t len)
>        goto out;
>      }
>  
> -  err = __io_read (file, &rbuf, &len, 0, len);
> +  err = __io_read (file, &rbuf, &nread, 0, len);
>    __mach_port_deallocate (__mach_task_self (), file);
>    if (err)
>      goto out;
>  
> +  len = nread;
>    if (rbuf != buf)
>      {
>        memcpy (buf, rbuf, len);
> -      __vm_deallocate (__mach_task_self (), (vm_address_t) rbuf, len);
> +      __vm_deallocate (__mach_task_self (), (vm_address_t) rbuf, nread);
>      }
>  
>  
> diff --git a/sysdeps/mach/hurd/sendfile64.c b/sysdeps/mach/hurd/sendfile64.c
> index 658b0282..e36b9790 100644
> --- a/sysdeps/mach/hurd/sendfile64.c
> +++ b/sysdeps/mach/hurd/sendfile64.c
> @@ -35,7 +35,7 @@ __sendfile64 (int out_fd, int in_fd, off64_t *offset, size_t count)
>       which might blow if it's huge or address space is real tight.  */
>  
>    char *data = 0;
> -  size_t datalen = 0;
> +  mach_msg_type_number_t datalen = 0;
>    error_t err = HURD_DPORT_USE (in_fd,
>  				__io_read (port, &data, &datalen,
>  					   offset ? *offset : (off_t) -1,
> -- 
> 2.39.1
>
diff mbox series

Patch

diff --git a/hurd/hurdioctl.c b/hurd/hurdioctl.c
index e9a6a7ea..59e6a5c1 100644
--- a/hurd/hurdioctl.c
+++ b/hurd/hurdioctl.c
@@ -311,7 +311,7 @@  static int
 siocgifconf (int fd, int request, struct ifconf *ifc)
 {
   error_t err;
-  size_t data_len = ifc->ifc_len;
+  mach_msg_type_number_t data_len = ifc->ifc_len;
   char *data = ifc->ifc_buf;
 
   if (data_len <= 0)
diff --git a/hurd/hurdprio.c b/hurd/hurdprio.c
index dbeb272b..954d3987 100644
--- a/hurd/hurdprio.c
+++ b/hurd/hurdprio.c
@@ -58,7 +58,7 @@  _hurd_priority_which_map (enum __priority_which which, int who,
 	  int *oldpi = pi;
 	  mach_msg_type_number_t oldpisize = pisize;
 	  char *tw = 0;
-	  size_t twsz = 0;
+	  mach_msg_type_number_t twsz = 0;
 	  err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
 						     &pi_flags,
 						     &pi, &pisize,
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index 0d344026..8850c4fd 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -162,7 +162,7 @@  __hurd_file_name_lookup_retry (error_t (*use_init_port)
 			    {
 			      char buf[1024];
 			      char *trans = buf;
-			      size_t translen = sizeof buf;
+			      mach_msg_type_number_t translen = sizeof buf;
 			      err = __file_get_translator (*result,
 							   &trans, &translen);
 			      if (!err
diff --git a/hurd/xattr.c b/hurd/xattr.c
index f98e548c..48914bcf 100644
--- a/hurd/xattr.c
+++ b/hurd/xattr.c
@@ -60,7 +60,7 @@  _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
   if (!strcmp (name, "translator"))
     {
       char *buf = value;
-      size_t bufsz = value ? *size : 0;
+      mach_msg_type_number_t bufsz = value ? *size : 0;
       error_t err = __file_get_translator (port, &buf, &bufsz);
       if (err)
 	return err;
@@ -144,7 +144,7 @@  _hurd_xattr_set (io_t port, const char *name, const void *value, size_t size,
 	{
 	  /* Must make sure it's already there.  */
 	  char *buf = NULL;
-	  size_t bufsz = 0;
+	  mach_msg_type_number_t bufsz = 0;
 	  error_t err = __file_get_translator (port, &buf, &bufsz);
 	  if (err)
 	    return err;
diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c
index fc5e78e7..f24b35b3 100644
--- a/sysdeps/mach/hurd/getcwd.c
+++ b/sysdeps/mach/hurd/getcwd.c
@@ -117,7 +117,7 @@  __hurd_canonicalize_directory_name_internal (file_t thisdir,
       int mount_point;
       file_t newp;
       char *dirdata;
-      size_t dirdatasize;
+      mach_msg_type_number_t dirdatasize;
       int direntry, nentries;
 
 
diff --git a/sysdeps/mach/hurd/readlinkat.c b/sysdeps/mach/hurd/readlinkat.c
index dabdbb37..5bb8b753 100644
--- a/sysdeps/mach/hurd/readlinkat.c
+++ b/sysdeps/mach/hurd/readlinkat.c
@@ -35,6 +35,7 @@  __readlinkat (int fd, const char *file_name, char *buf, size_t len)
   char retryname[1024];
   file_t file;
   char *rbuf = buf;
+  mach_msg_type_number_t nread = len;
 
   file_stat = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0);
   if (file_stat == MACH_PORT_NULL)
@@ -59,15 +60,16 @@  __readlinkat (int fd, const char *file_name, char *buf, size_t len)
       goto out;
     }
 
-  err = __io_read (file, &rbuf, &len, 0, len);
+  err = __io_read (file, &rbuf, &nread, 0, len);
   __mach_port_deallocate (__mach_task_self (), file);
   if (err)
     goto out;
 
+  len = nread;
   if (rbuf != buf)
     {
       memcpy (buf, rbuf, len);
-      __vm_deallocate (__mach_task_self (), (vm_address_t) rbuf, len);
+      __vm_deallocate (__mach_task_self (), (vm_address_t) rbuf, nread);
     }
 
 
diff --git a/sysdeps/mach/hurd/sendfile64.c b/sysdeps/mach/hurd/sendfile64.c
index 658b0282..e36b9790 100644
--- a/sysdeps/mach/hurd/sendfile64.c
+++ b/sysdeps/mach/hurd/sendfile64.c
@@ -35,7 +35,7 @@  __sendfile64 (int out_fd, int in_fd, off64_t *offset, size_t count)
      which might blow if it's huge or address space is real tight.  */
 
   char *data = 0;
-  size_t datalen = 0;
+  mach_msg_type_number_t datalen = 0;
   error_t err = HURD_DPORT_USE (in_fd,
 				__io_read (port, &data, &datalen,
 					   offset ? *offset : (off_t) -1,