Define mig_strlen and __mig_strlen to support dynamically sized strings in hurd RPCs

Message ID ZE21+AbyHtzYzU/c@jupiter.tail36e24.ts.net
State Superseded, archived
Headers
Series Define mig_strlen and __mig_strlen to support dynamically sized strings in hurd RPCs |

Checks

Context Check Description
dj/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Flavio Cruz April 30, 2023, 12:27 a.m. UTC
  We make lib{mach,hurd}user.so call __mig_strlen which can be
relocated before libc.so is relocated, similar to what is done with
__mig_memcpy.
---
 mach/Makefile                       |  2 +-
 mach/Versions                       |  4 ++++
 mach/mach/mig_support.h             |  2 ++
 mach/mig_strlen.c                   | 27 +++++++++++++++++++++++++++
 sysdeps/mach/hurd/i386/libc.abilist |  1 +
 5 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 mach/mig_strlen.c
  

Comments

Samuel Thibault April 30, 2023, 10:56 p.m. UTC | #1
Flavio Cruz, le sam. 29 avril 2023 20:27:36 -0400, a ecrit:
> diff --git a/mach/Versions b/mach/Versions
> index b525cfdcf9..2dff5c477e 100644
> --- a/mach/Versions
> +++ b/mach/Versions
> @@ -61,6 +61,9 @@ libc {
>    GLIBC_2.32 {
>      mach_print;
>    }
> +  GLIBC_2.38 {
> +    mig_strlen;
> +  }

Do we really need to expose a public function, and not just a private
function?

The symbol resolution issue is only for the RPCs in libmachuser.

> @@ -71,5 +74,6 @@ libc {
>    GLIBC_PRIVATE {
>      # functions used by RPC stubs
>      __mig_memcpy;
> +    __mig_strlen;
>    }
>  }
  

Patch

diff --git a/mach/Makefile b/mach/Makefile
index 39358fdb83..a5d1252f95 100644
--- a/mach/Makefile
+++ b/mach/Makefile
@@ -25,7 +25,7 @@  headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
 lock = spin-solid spin-lock mutex-init mutex-solid
 lock-headers = lock-intern.h spin-lock.h
 routines = $(mach-syscalls) $(mach-shortcuts) \
-	   mach_init mig_strncpy mig_memcpy msg \
+	   mach_init mig_strncpy mig_strlen mig_memcpy msg \
 	   mig-alloc mig-dealloc mig-reply \
 	   msg-destroy msgserver \
 	   mach_error errstring error_compat errsystems \
diff --git a/mach/Versions b/mach/Versions
index b525cfdcf9..2dff5c477e 100644
--- a/mach/Versions
+++ b/mach/Versions
@@ -61,6 +61,9 @@  libc {
   GLIBC_2.32 {
     mach_print;
   }
+  GLIBC_2.38 {
+    mig_strlen;
+  }
 
   HURD_CTHREADS_0.3 {
     __mutex_init; __mutex_lock; __mutex_lock_solid; __mutex_trylock;
@@ -71,5 +74,6 @@  libc {
   GLIBC_PRIVATE {
     # functions used by RPC stubs
     __mig_memcpy;
+    __mig_strlen;
   }
 }
diff --git a/mach/mach/mig_support.h b/mach/mach/mig_support.h
index 78d4c4f0e3..3108e0af56 100644
--- a/mach/mach/mig_support.h
+++ b/mach/mach/mig_support.h
@@ -53,6 +53,8 @@  extern void mig_reply_setup (const mach_msg_header_t *__request,
 /* Idiocy support function.  */
 extern vm_size_t mig_strncpy (char *__dst, const char *__src, vm_size_t __len);
 extern vm_size_t __mig_strncpy (char *__dst, const char *__src, vm_size_t);
+extern vm_size_t mig_strlen (const char *__src);
+extern vm_size_t __mig_strlen (const char *__src);
 
 extern void *__mig_memcpy (void *__dst, const void *__src, vm_size_t __len);
 
diff --git a/mach/mig_strlen.c b/mach/mig_strlen.c
new file mode 100644
index 0000000000..65e39b9bdf
--- /dev/null
+++ b/mach/mig_strlen.c
@@ -0,0 +1,27 @@ 
+/* strlen stub for mig stubs in libmachuser and libhurduser.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <mach.h>
+#include <string.h>
+
+vm_size_t
+__mig_strlen (const char *src)
+{
+  return strlen (src);
+}
+weak_alias (__mig_strlen, mig_strlen)
diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
index 6925222ff3..ac7d06e385 100644
--- a/sysdeps/mach/hurd/i386/libc.abilist
+++ b/sysdeps/mach/hurd/i386/libc.abilist
@@ -2326,6 +2326,7 @@  GLIBC_2.38 __isoc23_wcstoull F
 GLIBC_2.38 __isoc23_wcstoull_l F
 GLIBC_2.38 __isoc23_wcstoumax F
 GLIBC_2.38 __isoc23_wscanf F
+GLIBC_2.38 mig_strlen F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F