8a8cfb
commit 09e1b0e3f6facc1af2dbcfef204f0aaa8718772b
8a8cfb
Author: Florian Weimer <fweimer@redhat.com>
8a8cfb
Date:   Mon May 20 21:54:57 2019 +0200
8a8cfb
8a8cfb
    libio: Remove codecvt vtable [BZ #24588]
8a8cfb
    
8a8cfb
    The codecvt vtable is not a real vtable because it also contains the
8a8cfb
    conversion state data.  Furthermore, wide stream support was added to
8a8cfb
    GCC 3.0, after a C++ ABI bump, so there is no compatibility
8a8cfb
    requirement with libstdc++.
8a8cfb
    
8a8cfb
    This change removes several unmangled function pointers which could
8a8cfb
    be used with a corrupted FILE object to redirect execution.  (libio
8a8cfb
    vtable verification did not cover the codecvt vtable.)
8a8cfb
    
8a8cfb
    Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>
8a8cfb
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
8a8cfb
8a8cfb
diff --git a/libio/fileops.c b/libio/fileops.c
8a8cfb
index d2070a856e..daa5a05877 100644
8a8cfb
--- a/libio/fileops.c
8a8cfb
+++ b/libio/fileops.c
8a8cfb
@@ -331,9 +331,6 @@ _IO_new_file_fopen (FILE *fp, const char *filename, const char *mode,
8a8cfb
 
8a8cfb
 	  cc = fp->_codecvt = &fp->_wide_data->_codecvt;
8a8cfb
 
8a8cfb
-	  /* The functions are always the same.  */
8a8cfb
-	  *cc = __libio_codecvt;
8a8cfb
-
8a8cfb
 	  cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
8a8cfb
 	  cc->__cd_in.__cd.__steps = fcts.towc;
8a8cfb
 
8a8cfb
diff --git a/libio/iofgetpos.c b/libio/iofgetpos.c
8a8cfb
index 8032192440..388c4a0708 100644
8a8cfb
--- a/libio/iofgetpos.c
8a8cfb
+++ b/libio/iofgetpos.c
8a8cfb
@@ -70,8 +70,7 @@ _IO_new_fgetpos (FILE *fp, __fpos_t *posp)
8a8cfb
   else
8a8cfb
     {
8a8cfb
       posp->__pos = pos;
8a8cfb
-      if (fp->_mode > 0
8a8cfb
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
8a8cfb
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
8a8cfb
 	/* This is a stateful encoding, safe the state.  */
8a8cfb
 	posp->__state = fp->_wide_data->_IO_state;
8a8cfb
     }
8a8cfb
diff --git a/libio/iofgetpos64.c b/libio/iofgetpos64.c
8a8cfb
index 54de6a8205..6a0ba50d29 100644
8a8cfb
--- a/libio/iofgetpos64.c
8a8cfb
+++ b/libio/iofgetpos64.c
8a8cfb
@@ -54,8 +54,7 @@ _IO_new_fgetpos64 (FILE *fp, __fpos64_t *posp)
8a8cfb
   else
8a8cfb
     {
8a8cfb
       posp->__pos = pos;
8a8cfb
-      if (fp->_mode > 0
8a8cfb
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
8a8cfb
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
8a8cfb
 	/* This is a stateful encoding, safe the state.  */
8a8cfb
 	posp->__state = fp->_wide_data->_IO_state;
8a8cfb
     }
8a8cfb
diff --git a/libio/iofsetpos.c b/libio/iofsetpos.c
8a8cfb
index d7b1abbc61..4df1aae082 100644
8a8cfb
--- a/libio/iofsetpos.c
8a8cfb
+++ b/libio/iofsetpos.c
8a8cfb
@@ -58,8 +58,7 @@ _IO_new_fsetpos (FILE *fp, const __fpos_t *posp)
8a8cfb
   else
8a8cfb
     {
8a8cfb
       result = 0;
8a8cfb
-      if (fp->_mode > 0
8a8cfb
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
8a8cfb
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
8a8cfb
 	/* This is a stateful encoding, restore the state.  */
8a8cfb
 	fp->_wide_data->_IO_state = posp->__state;
8a8cfb
     }
8a8cfb
diff --git a/libio/iofsetpos64.c b/libio/iofsetpos64.c
8a8cfb
index d1865b728e..f382ba0dc1 100644
8a8cfb
--- a/libio/iofsetpos64.c
8a8cfb
+++ b/libio/iofsetpos64.c
8a8cfb
@@ -48,8 +48,7 @@ _IO_new_fsetpos64 (FILE *fp, const fpos64_t *posp)
8a8cfb
   else
8a8cfb
     {
8a8cfb
       result = 0;
8a8cfb
-      if (fp->_mode > 0
8a8cfb
-	  && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
8a8cfb
+      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
8a8cfb
 	/* This is a stateful encoding, safe the state.  */
8a8cfb
 	fp->_wide_data->_IO_state = posp->__state;
8a8cfb
     }
8a8cfb
diff --git a/libio/iofwide.c b/libio/iofwide.c
8a8cfb
index 247cfde3d0..80cb2d5074 100644
8a8cfb
--- a/libio/iofwide.c
8a8cfb
+++ b/libio/iofwide.c
8a8cfb
@@ -39,44 +39,6 @@
8a8cfb
 #include <sysdep.h>
8a8cfb
 
8a8cfb
 
8a8cfb
-/* Prototypes of libio's codecvt functions.  */
8a8cfb
-static enum __codecvt_result do_out (struct _IO_codecvt *codecvt,
8a8cfb
-				     __mbstate_t *statep,
8a8cfb
-				     const wchar_t *from_start,
8a8cfb
-				     const wchar_t *from_end,
8a8cfb
-				     const wchar_t **from_stop, char *to_start,
8a8cfb
-				     char *to_end, char **to_stop);
8a8cfb
-static enum __codecvt_result do_unshift (struct _IO_codecvt *codecvt,
8a8cfb
-					 __mbstate_t *statep, char *to_start,
8a8cfb
-					 char *to_end, char **to_stop);
8a8cfb
-static enum __codecvt_result do_in (struct _IO_codecvt *codecvt,
8a8cfb
-				    __mbstate_t *statep,
8a8cfb
-				    const char *from_start,
8a8cfb
-				    const char *from_end,
8a8cfb
-				    const char **from_stop, wchar_t *to_start,
8a8cfb
-				    wchar_t *to_end, wchar_t **to_stop);
8a8cfb
-static int do_encoding (struct _IO_codecvt *codecvt);
8a8cfb
-static int do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
-		      const char *from_start,
8a8cfb
-		      const char *from_end, size_t max);
8a8cfb
-static int do_max_length (struct _IO_codecvt *codecvt);
8a8cfb
-static int do_always_noconv (struct _IO_codecvt *codecvt);
8a8cfb
-
8a8cfb
-
8a8cfb
-/* The functions used in `codecvt' for libio are always the same.  */
8a8cfb
-const struct _IO_codecvt __libio_codecvt =
8a8cfb
-{
8a8cfb
-  .__codecvt_destr = NULL,		/* Destructor, never used.  */
8a8cfb
-  .__codecvt_do_out = do_out,
8a8cfb
-  .__codecvt_do_unshift = do_unshift,
8a8cfb
-  .__codecvt_do_in = do_in,
8a8cfb
-  .__codecvt_do_encoding = do_encoding,
8a8cfb
-  .__codecvt_do_always_noconv = do_always_noconv,
8a8cfb
-  .__codecvt_do_length = do_length,
8a8cfb
-  .__codecvt_do_max_length = do_max_length
8a8cfb
-};
8a8cfb
-
8a8cfb
-
8a8cfb
 /* Return orientation of stream.  If mode is nonzero try to change
8a8cfb
    the orientation first.  */
8a8cfb
 #undef _IO_fwide
8a8cfb
@@ -118,9 +80,6 @@ _IO_fwide (FILE *fp, int mode)
8a8cfb
 	assert (fcts.towc_nsteps == 1);
8a8cfb
 	assert (fcts.tomb_nsteps == 1);
8a8cfb
 
8a8cfb
-	/* The functions are always the same.  */
8a8cfb
-	*cc = __libio_codecvt;
8a8cfb
-
8a8cfb
 	cc->__cd_in.__cd.__nsteps = fcts.towc_nsteps;
8a8cfb
 	cc->__cd_in.__cd.__steps = fcts.towc;
8a8cfb
 
8a8cfb
@@ -150,11 +109,11 @@ _IO_fwide (FILE *fp, int mode)
8a8cfb
 }
8a8cfb
 
8a8cfb
 
8a8cfb
-static enum __codecvt_result
8a8cfb
-do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
-	const wchar_t *from_start, const wchar_t *from_end,
8a8cfb
-	const wchar_t **from_stop, char *to_start, char *to_end,
8a8cfb
-	char **to_stop)
8a8cfb
+enum __codecvt_result
8a8cfb
+__libio_codecvt_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
+		     const wchar_t *from_start, const wchar_t *from_end,
8a8cfb
+		     const wchar_t **from_stop, char *to_start, char *to_end,
8a8cfb
+		     char **to_stop)
8a8cfb
 {
8a8cfb
   enum __codecvt_result result;
8a8cfb
 
8a8cfb
@@ -202,57 +161,11 @@ do_out (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
 }
8a8cfb
 
8a8cfb
 
8a8cfb
-static enum __codecvt_result
8a8cfb
-do_unshift (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
-	    char *to_start, char *to_end, char **to_stop)
8a8cfb
-{
8a8cfb
-  enum __codecvt_result result;
8a8cfb
-
8a8cfb
-  struct __gconv_step *gs = codecvt->__cd_out.__cd.__steps;
8a8cfb
-  int status;
8a8cfb
-  size_t dummy;
8a8cfb
-
8a8cfb
-  codecvt->__cd_out.__cd.__data[0].__outbuf = (unsigned char *) to_start;
8a8cfb
-  codecvt->__cd_out.__cd.__data[0].__outbufend = (unsigned char *) to_end;
8a8cfb
-  codecvt->__cd_out.__cd.__data[0].__statep = statep;
8a8cfb
-
8a8cfb
-  __gconv_fct fct = gs->__fct;
8a8cfb
-#ifdef PTR_DEMANGLE
8a8cfb
-  if (gs->__shlib_handle != NULL)
8a8cfb
-    PTR_DEMANGLE (fct);
8a8cfb
-#endif
8a8cfb
-
8a8cfb
-  status = DL_CALL_FCT (fct,
8a8cfb
-			(gs, codecvt->__cd_out.__cd.__data, NULL, NULL,
8a8cfb
-			 NULL, &dummy, 1, 0));
8a8cfb
-
8a8cfb
-  *to_stop = (char *) codecvt->__cd_out.__cd.__data[0].__outbuf;
8a8cfb
-
8a8cfb
-  switch (status)
8a8cfb
-    {
8a8cfb
-    case __GCONV_OK:
8a8cfb
-    case __GCONV_EMPTY_INPUT:
8a8cfb
-      result = __codecvt_ok;
8a8cfb
-      break;
8a8cfb
-
8a8cfb
-    case __GCONV_FULL_OUTPUT:
8a8cfb
-    case __GCONV_INCOMPLETE_INPUT:
8a8cfb
-      result = __codecvt_partial;
8a8cfb
-      break;
8a8cfb
-
8a8cfb
-    default:
8a8cfb
-      result = __codecvt_error;
8a8cfb
-      break;
8a8cfb
-    }
8a8cfb
-
8a8cfb
-  return result;
8a8cfb
-}
8a8cfb
-
8a8cfb
-
8a8cfb
-static enum __codecvt_result
8a8cfb
-do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
-       const char *from_start, const char *from_end, const char **from_stop,
8a8cfb
-       wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
8a8cfb
+enum __codecvt_result
8a8cfb
+__libio_codecvt_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
+		    const char *from_start, const char *from_end,
8a8cfb
+		    const char **from_stop,
8a8cfb
+		    wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
8a8cfb
 {
8a8cfb
   enum __codecvt_result result;
8a8cfb
 
8a8cfb
@@ -300,8 +213,8 @@ do_in (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
 }
8a8cfb
 
8a8cfb
 
8a8cfb
-static int
8a8cfb
-do_encoding (struct _IO_codecvt *codecvt)
8a8cfb
+int
8a8cfb
+__libio_codecvt_encoding (struct _IO_codecvt *codecvt)
8a8cfb
 {
8a8cfb
   /* See whether the encoding is stateful.  */
8a8cfb
   if (codecvt->__cd_in.__cd.__steps[0].__stateful)
8a8cfb
@@ -317,16 +230,10 @@ do_encoding (struct _IO_codecvt *codecvt)
8a8cfb
 }
8a8cfb
 
8a8cfb
 
8a8cfb
-static int
8a8cfb
-do_always_noconv (struct _IO_codecvt *codecvt)
8a8cfb
-{
8a8cfb
-  return 0;
8a8cfb
-}
8a8cfb
-
8a8cfb
-
8a8cfb
-static int
8a8cfb
-do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
-	   const char *from_start, const char *from_end, size_t max)
8a8cfb
+int
8a8cfb
+__libio_codecvt_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
+			const char *from_start, const char *from_end,
8a8cfb
+			size_t max)
8a8cfb
 {
8a8cfb
   int result;
8a8cfb
   const unsigned char *cp = (const unsigned char *) from_start;
8a8cfb
@@ -353,10 +260,3 @@ do_length (struct _IO_codecvt *codecvt, __mbstate_t *statep,
8a8cfb
 
8a8cfb
   return result;
8a8cfb
 }
8a8cfb
-
8a8cfb
-
8a8cfb
-static int
8a8cfb
-do_max_length (struct _IO_codecvt *codecvt)
8a8cfb
-{
8a8cfb
-  return codecvt->__cd_in.__cd.__steps[0].__max_needed_from;
8a8cfb
-}
8a8cfb
diff --git a/libio/libio.h b/libio/libio.h
8a8cfb
index c38095ff77..b985c386a2 100644
8a8cfb
--- a/libio/libio.h
8a8cfb
+++ b/libio/libio.h
8a8cfb
@@ -116,40 +116,8 @@ struct _IO_marker {
8a8cfb
   int _pos;
8a8cfb
 };
8a8cfb
 
8a8cfb
-/* This is the structure from the libstdc++ codecvt class.  */
8a8cfb
-enum __codecvt_result
8a8cfb
-{
8a8cfb
-  __codecvt_ok,
8a8cfb
-  __codecvt_partial,
8a8cfb
-  __codecvt_error,
8a8cfb
-  __codecvt_noconv
8a8cfb
-};
8a8cfb
-
8a8cfb
-/* The order of the elements in the following struct must match the order
8a8cfb
-   of the virtual functions in the libstdc++ codecvt class.  */
8a8cfb
 struct _IO_codecvt
8a8cfb
 {
8a8cfb
-  void (*__codecvt_destr) (struct _IO_codecvt *);
8a8cfb
-  enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
8a8cfb
-					     __mbstate_t *,
8a8cfb
-					     const wchar_t *,
8a8cfb
-					     const wchar_t *,
8a8cfb
-					     const wchar_t **, char *,
8a8cfb
-					     char *, char **);
8a8cfb
-  enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
8a8cfb
-						 __mbstate_t *, char *,
8a8cfb
-						 char *, char **);
8a8cfb
-  enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
8a8cfb
-					    __mbstate_t *,
8a8cfb
-					    const char *, const char *,
8a8cfb
-					    const char **, wchar_t *,
8a8cfb
-					    wchar_t *, wchar_t **);
8a8cfb
-  int (*__codecvt_do_encoding) (struct _IO_codecvt *);
8a8cfb
-  int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
8a8cfb
-  int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
8a8cfb
-			      const char *, const char *, size_t);
8a8cfb
-  int (*__codecvt_do_max_length) (struct _IO_codecvt *);
8a8cfb
-
8a8cfb
   _IO_iconv_t __cd_in;
8a8cfb
   _IO_iconv_t __cd_out;
8a8cfb
 };
8a8cfb
diff --git a/libio/libioP.h b/libio/libioP.h
8a8cfb
index 7bdec86a62..66afaa8968 100644
8a8cfb
--- a/libio/libioP.h
8a8cfb
+++ b/libio/libioP.h
8a8cfb
@@ -476,7 +476,6 @@ extern const struct _IO_jump_t _IO_streambuf_jumps;
8a8cfb
 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
8a8cfb
 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
8a8cfb
 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
8a8cfb
-extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
8a8cfb
 extern int _IO_do_write (FILE *, const char *, size_t);
8a8cfb
 libc_hidden_proto (_IO_do_write)
8a8cfb
 extern int _IO_new_do_write (FILE *, const char *, size_t);
8a8cfb
@@ -932,4 +931,32 @@ IO_validate_vtable (const struct _IO_jump_t *vtable)
8a8cfb
   return vtable;
8a8cfb
 }
8a8cfb
 
8a8cfb
+/* Character set conversion.  */
8a8cfb
+
8a8cfb
+enum __codecvt_result
8a8cfb
+{
8a8cfb
+  __codecvt_ok,
8a8cfb
+  __codecvt_partial,
8a8cfb
+  __codecvt_error,
8a8cfb
+  __codecvt_noconv
8a8cfb
+};
8a8cfb
+
8a8cfb
+enum __codecvt_result __libio_codecvt_out (struct _IO_codecvt *,
8a8cfb
+					   __mbstate_t *,
8a8cfb
+					   const wchar_t *,
8a8cfb
+					   const wchar_t *,
8a8cfb
+					   const wchar_t **, char *,
8a8cfb
+					   char *, char **)
8a8cfb
+  attribute_hidden;
8a8cfb
+enum __codecvt_result __libio_codecvt_in (struct _IO_codecvt *,
8a8cfb
+					  __mbstate_t *,
8a8cfb
+					  const char *, const char *,
8a8cfb
+					  const char **, wchar_t *,
8a8cfb
+					  wchar_t *, wchar_t **)
8a8cfb
+  attribute_hidden;
8a8cfb
+int __libio_codecvt_encoding (struct _IO_codecvt *) attribute_hidden;
8a8cfb
+int __libio_codecvt_length (struct _IO_codecvt *, __mbstate_t *,
8a8cfb
+			    const char *, const char *, size_t)
8a8cfb
+  attribute_hidden;
8a8cfb
+
8a8cfb
 #endif /* libioP.h.  */
8a8cfb
diff --git a/libio/wfileops.c b/libio/wfileops.c
8a8cfb
index 69fbb62a02..f1863db638 100644
8a8cfb
--- a/libio/wfileops.c
8a8cfb
+++ b/libio/wfileops.c
8a8cfb
@@ -72,11 +72,11 @@ _IO_wdo_write (FILE *fp, const wchar_t *data, size_t to_do)
8a8cfb
 	    }
8a8cfb
 
8a8cfb
 	  /* Now convert from the internal format into the external buffer.  */
8a8cfb
-	  result = (*cc->__codecvt_do_out) (cc, &fp->_wide_data->_IO_state,
8a8cfb
-					    data, data + to_do, &new_data,
8a8cfb
-					    write_ptr,
8a8cfb
-					    buf_end,
8a8cfb
-					    &write_ptr);
8a8cfb
+	  result = __libio_codecvt_out (cc, &fp->_wide_data->_IO_state,
8a8cfb
+					data, data + to_do, &new_data,
8a8cfb
+					write_ptr,
8a8cfb
+					buf_end,
8a8cfb
+					&write_ptr);
8a8cfb
 
8a8cfb
 	  /* Write out what we produced so far.  */
8a8cfb
 	  if (_IO_new_do_write (fp, write_base, write_ptr - write_base) == EOF)
8a8cfb
@@ -140,12 +140,12 @@ _IO_wfile_underflow (FILE *fp)
8a8cfb
       fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
8a8cfb
       fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
8a8cfb
 	fp->_wide_data->_IO_buf_base;
8a8cfb
-      status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
8a8cfb
-				       fp->_IO_read_ptr, fp->_IO_read_end,
8a8cfb
-				       &read_stop,
8a8cfb
-				       fp->_wide_data->_IO_read_ptr,
8a8cfb
-				       fp->_wide_data->_IO_buf_end,
8a8cfb
-				       &fp->_wide_data->_IO_read_end);
8a8cfb
+      status = __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
8a8cfb
+				   fp->_IO_read_ptr, fp->_IO_read_end,
8a8cfb
+				   &read_stop,
8a8cfb
+				   fp->_wide_data->_IO_read_ptr,
8a8cfb
+				   fp->_wide_data->_IO_buf_end,
8a8cfb
+				   &fp->_wide_data->_IO_read_end);
8a8cfb
 
8a8cfb
       fp->_IO_read_base = fp->_IO_read_ptr;
8a8cfb
       fp->_IO_read_ptr = (char *) read_stop;
8a8cfb
@@ -266,11 +266,11 @@ _IO_wfile_underflow (FILE *fp)
8a8cfb
       naccbuf += to_copy;
8a8cfb
       from = accbuf;
8a8cfb
     }
8a8cfb
-  status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
8a8cfb
-				   from, to, &read_ptr_copy,
8a8cfb
-				   fp->_wide_data->_IO_read_end,
8a8cfb
-				   fp->_wide_data->_IO_buf_end,
8a8cfb
-				   &fp->_wide_data->_IO_read_end);
8a8cfb
+  status = __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
8a8cfb
+			       from, to, &read_ptr_copy,
8a8cfb
+			       fp->_wide_data->_IO_read_end,
8a8cfb
+			       fp->_wide_data->_IO_buf_end,
8a8cfb
+			       &fp->_wide_data->_IO_read_end);
8a8cfb
 
8a8cfb
   if (__glibc_unlikely (naccbuf != 0))
8a8cfb
     fp->_IO_read_ptr += MAX (0, read_ptr_copy - &accbuf[naccbuf - to_copy]);
8a8cfb
@@ -372,12 +372,12 @@ _IO_wfile_underflow_mmap (FILE *fp)
8a8cfb
   fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
8a8cfb
   fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_ptr =
8a8cfb
     fp->_wide_data->_IO_buf_base;
8a8cfb
-  (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
8a8cfb
-			  fp->_IO_read_ptr, fp->_IO_read_end,
8a8cfb
-			  &read_stop,
8a8cfb
-			  fp->_wide_data->_IO_read_ptr,
8a8cfb
-			  fp->_wide_data->_IO_buf_end,
8a8cfb
-			  &fp->_wide_data->_IO_read_end);
8a8cfb
+  __libio_codecvt_in (cd, &fp->_wide_data->_IO_state,
8a8cfb
+		      fp->_IO_read_ptr, fp->_IO_read_end,
8a8cfb
+		      &read_stop,
8a8cfb
+		      fp->_wide_data->_IO_read_ptr,
8a8cfb
+		      fp->_wide_data->_IO_buf_end,
8a8cfb
+		      &fp->_wide_data->_IO_read_end);
8a8cfb
 
8a8cfb
   fp->_IO_read_ptr = (char *) read_stop;
8a8cfb
 
8a8cfb
@@ -495,7 +495,7 @@ _IO_wfile_sync (FILE *fp)
8a8cfb
       struct _IO_codecvt *cv = fp->_codecvt;
8a8cfb
       off64_t new_pos;
8a8cfb
 
8a8cfb
-      int clen = (*cv->__codecvt_do_encoding) (cv);
8a8cfb
+      int clen = __libio_codecvt_encoding (cv);
8a8cfb
 
8a8cfb
       if (clen > 0)
8a8cfb
 	/* It is easy, a fixed number of input bytes are used for each
8a8cfb
@@ -511,9 +511,9 @@ _IO_wfile_sync (FILE *fp)
8a8cfb
 	  size_t wnread = (fp->_wide_data->_IO_read_ptr
8a8cfb
 			   - fp->_wide_data->_IO_read_base);
8a8cfb
 	  fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
8a8cfb
-	  nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state,
8a8cfb
-					      fp->_IO_read_base,
8a8cfb
-					      fp->_IO_read_end, wnread);
8a8cfb
+	  nread = __libio_codecvt_length (cv, &fp->_wide_data->_IO_state,
8a8cfb
+					  fp->_IO_read_base,
8a8cfb
+					  fp->_IO_read_end, wnread);
8a8cfb
 	  fp->_IO_read_ptr = fp->_IO_read_base + nread;
8a8cfb
 	  delta = -(fp->_IO_read_end - fp->_IO_read_base - nread);
8a8cfb
 	}
8a8cfb
@@ -548,7 +548,7 @@ adjust_wide_data (FILE *fp, bool do_convert)
8a8cfb
 {
8a8cfb
   struct _IO_codecvt *cv = fp->_codecvt;
8a8cfb
 
8a8cfb
-  int clen = (*cv->__codecvt_do_encoding) (cv);
8a8cfb
+  int clen = __libio_codecvt_encoding (cv);
8a8cfb
 
8a8cfb
   /* Take the easy way out for constant length encodings if we don't need to
8a8cfb
      convert.  */
8a8cfb
@@ -565,12 +565,12 @@ adjust_wide_data (FILE *fp, bool do_convert)
8a8cfb
     {
8a8cfb
 
8a8cfb
       fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
8a8cfb
-      status = (*cv->__codecvt_do_in) (cv, &fp->_wide_data->_IO_state,
8a8cfb
-				       fp->_IO_read_base, fp->_IO_read_ptr,
8a8cfb
-				       &read_stop,
8a8cfb
-				       fp->_wide_data->_IO_read_base,
8a8cfb
-				       fp->_wide_data->_IO_buf_end,
8a8cfb
-				       &fp->_wide_data->_IO_read_end);
8a8cfb
+      status = __libio_codecvt_in (cv, &fp->_wide_data->_IO_state,
8a8cfb
+				   fp->_IO_read_base, fp->_IO_read_ptr,
8a8cfb
+				   &read_stop,
8a8cfb
+				   fp->_wide_data->_IO_read_base,
8a8cfb
+				   fp->_wide_data->_IO_buf_end,
8a8cfb
+				   &fp->_wide_data->_IO_read_end);
8a8cfb
 
8a8cfb
       /* Should we return EILSEQ?  */
8a8cfb
       if (__glibc_unlikely (status == __codecvt_error))
8a8cfb
@@ -648,7 +648,7 @@ do_ftell_wide (FILE *fp)
8a8cfb
 	}
8a8cfb
 
8a8cfb
       struct _IO_codecvt *cv = fp->_codecvt;
8a8cfb
-      int clen = (*cv->__codecvt_do_encoding) (cv);
8a8cfb
+      int clen = __libio_codecvt_encoding (cv);
8a8cfb
 
8a8cfb
       if (!unflushed_writes)
8a8cfb
 	{
8a8cfb
@@ -663,9 +663,9 @@ do_ftell_wide (FILE *fp)
8a8cfb
 
8a8cfb
 	      size_t delta = wide_read_ptr - wide_read_base;
8a8cfb
 	      __mbstate_t state = fp->_wide_data->_IO_last_state;
8a8cfb
-	      nread = (*cv->__codecvt_do_length) (cv, &state,
8a8cfb
-						  fp->_IO_read_base,
8a8cfb
-						  fp->_IO_read_end, delta);
8a8cfb
+	      nread = __libio_codecvt_length (cv, &state,
8a8cfb
+					      fp->_IO_read_base,
8a8cfb
+					      fp->_IO_read_end, delta);
8a8cfb
 	      offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
8a8cfb
 	    }
8a8cfb
 	}
8a8cfb
@@ -688,9 +688,8 @@ do_ftell_wide (FILE *fp)
8a8cfb
 	      enum __codecvt_result status;
8a8cfb
 
8a8cfb
 	      __mbstate_t state = fp->_wide_data->_IO_last_state;
8a8cfb
-	      status = (*cv->__codecvt_do_out) (cv, &state,
8a8cfb
-						in, in + delta, &in,
8a8cfb
-						out, out + outsize, &outstop);
8a8cfb
+	      status = __libio_codecvt_out (cv, &state, in, in + delta, &in,
8a8cfb
+					    out, out + outsize, &outstop);
8a8cfb
 
8a8cfb
 	      /* We don't check for __codecvt_partial because it can be
8a8cfb
 		 returned on one of two conditions: either the output
8a8cfb
@@ -801,7 +800,7 @@ _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode)
8a8cfb
 	 find out which position in the external buffer corresponds to
8a8cfb
 	 the current position in the internal buffer.  */
8a8cfb
       cv = fp->_codecvt;
8a8cfb
-      clen = (*cv->__codecvt_do_encoding) (cv);
8a8cfb
+      clen = __libio_codecvt_encoding (cv);
8a8cfb
 
8a8cfb
       if (mode != 0 || !was_writing)
8a8cfb
 	{
8a8cfb
@@ -819,10 +818,10 @@ _IO_wfile_seekoff (FILE *fp, off64_t offset, int dir, int mode)
8a8cfb
 	      delta = (fp->_wide_data->_IO_read_ptr
8a8cfb
 		       - fp->_wide_data->_IO_read_base);
8a8cfb
 	      fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
8a8cfb
-	      nread = (*cv->__codecvt_do_length) (cv,
8a8cfb
-						  &fp->_wide_data->_IO_state,
8a8cfb
-						  fp->_IO_read_base,
8a8cfb
-						  fp->_IO_read_end, delta);
8a8cfb
+	      nread = __libio_codecvt_length (cv,
8a8cfb
+					      &fp->_wide_data->_IO_state,
8a8cfb
+					      fp->_IO_read_base,
8a8cfb
+					      fp->_IO_read_end, delta);
8a8cfb
 	      fp->_IO_read_ptr = fp->_IO_read_base + nread;
8a8cfb
 	      fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
8a8cfb
 	      offset -= fp->_IO_read_end - fp->_IO_read_base - nread;