536
GLIBC232_RAWMEMCHR(m_libc_so_star, rawmemchr)
586
GLIBC232_RAWMEMCHR(m_libc_soname, rawmemchr)
589
/* glibc variant of strcpy that checks the dest is big enough.
590
Copied from glibc-2.5/debug/test-strcpy_chk.c. */
591
#define GLIBC25___STRCPY_CHK(soname,fnname) \
592
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
593
(char* dst, const char* src, SizeT len); \
594
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
595
(char* dst, const char* src, SizeT len) \
597
extern void _exit(int status); \
601
while ((*dst++ = *src++) != '\0') \
606
VALGRIND_PRINTF_BACKTRACE( \
607
"*** strcpy_chk: buffer overflow detected ***: " \
608
"program terminated"); \
614
GLIBC25___STRCPY_CHK(m_libc_soname, __strcpy_chk)
617
/* glibc variant of stpcpy that checks the dest is big enough.
618
Copied from glibc-2.5/debug/test-stpcpy_chk.c. */
619
#define GLIBC25___STPCPY_CHK(soname,fnname) \
620
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
621
(char* dst, const char* src, SizeT len); \
622
char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
623
(char* dst, const char* src, SizeT len) \
625
extern void _exit(int status); \
628
while ((*dst++ = *src++) != '\0') \
633
VALGRIND_PRINTF_BACKTRACE( \
634
"*** stpcpy_chk: buffer overflow detected ***: " \
635
"program terminated"); \
641
GLIBC25___STPCPY_CHK(m_libc_soname, __stpcpy_chk)
645
#define GLIBC25_MEMPCPY(soname, fnname) \
646
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
647
( void *dst, const void *src, SizeT len ); \
648
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
649
( void *dst, const void *src, SizeT len ) \
653
SizeT len_saved = len; \
658
if (is_overlap(dst, src, len, len)) \
659
RECORD_OVERLAP_ERROR("mempcpy", dst, src, len); \
662
d = (char *)dst + len - 1; \
663
s = (char *)src + len - 1; \
667
} else if ( dst < src ) { \
674
return (void*)( ((char*)dst) + len_saved ); \
677
GLIBC25_MEMPCPY(m_libc_soname, mempcpy)
678
GLIBC25_MEMPCPY(m_ld_so_1, mempcpy) /* ld.so.1 */
681
#define GLIBC26___MEMCPY_CHK(soname, fnname) \
682
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
683
(void* dst, const void* src, SizeT len, SizeT dstlen ); \
684
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
685
(void* dst, const void* src, SizeT len, SizeT dstlen ) \
687
extern void _exit(int status); \
691
if (dstlen < len) goto badness; \
696
if (is_overlap(dst, src, len, len)) \
697
RECORD_OVERLAP_ERROR("memcpy_chk", dst, src, len); \
700
d = (char *)dst + len - 1; \
701
s = (char *)src + len - 1; \
705
} else if ( dst < src ) { \
714
VALGRIND_PRINTF_BACKTRACE( \
715
"*** memcpy_chk: buffer overflow detected ***: " \
716
"program terminated"); \
722
GLIBC26___MEMCPY_CHK(m_libc_soname, __memcpy_chk)
725
/*------------------------------------------------------------*/
726
/*--- Improve definedness checking of process environment ---*/
727
/*------------------------------------------------------------*/
729
#if defined(VGO_linux)
732
int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string);
733
int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string)
737
const char* p = string;
738
VALGRIND_GET_ORIG_FN(fn);
739
/* Now by walking over the string we magically produce
740
traces when hitting undefined memory. */
744
CALL_FN_W_W(result, fn, string);
749
int VG_WRAP_FUNCTION_ZU(m_libc_soname, unsetenv) (const char* name);
750
int VG_WRAP_FUNCTION_ZU(m_libc_soname, unsetenv) (const char* name)
754
const char* p = name;
755
VALGRIND_GET_ORIG_FN(fn);
756
/* Now by walking over the string we magically produce
757
traces when hitting undefined memory. */
761
CALL_FN_W_W(result, fn, name);
766
int VG_WRAP_FUNCTION_ZU(m_libc_soname, setenv)
767
(const char* name, const char* value, int overwrite);
768
int VG_WRAP_FUNCTION_ZU(m_libc_soname, setenv)
769
(const char* name, const char* value, int overwrite)
774
VALGRIND_GET_ORIG_FN(fn);
775
/* Now by walking over the string we magically produce
776
traces when hitting undefined memory. */
778
for (p = name; *p; p++)
781
for (p = value; *p; p++)
783
VALGRIND_CHECK_VALUE_IS_DEFINED (overwrite);
784
CALL_FN_W_WWW(result, fn, name, value, overwrite);
788
#endif /* defined(VGO_linux) */
791
/*------------------------------------------------------------*/
792
/*--- AIX stuff only after this point ---*/
793
/*------------------------------------------------------------*/
795
/* Generate replacements for strcat, strncat, strcpy, strncpy, strcmp
796
in the given soname. */
797
#define Str5FNs(_soname) \
798
STRCAT(_soname, strcat) \
799
STRNCAT(_soname, strncat) \
800
STRCPY(_soname, strcpy) \
801
STRNCPY(_soname, strncpy) \
802
STRCMP(_soname, strcmp)
804
#if defined(VGP_ppc32_aix5)
805
Str5FNs(NONE) /* in main exe */
806
Str5FNs(libCZdaZLshrcoreZdoZR) /* libC.a(shrcore.o) */
807
Str5FNs(libX11ZdaZLshr4ZdoZR) /* libX11.a(shr4.o) */
808
Str5FNs(libXmZdaZLshrZaZdoZR) /* libXm.a(shr*.o) */
809
Str5FNs(libXtZdaZLshr4ZdoZR) /* libXt.a(shr4.o) */
810
Str5FNs(libppeZurZdaZLdynamicZdoZR) /* libppe_r.a(dynamic.o) */
811
Str5FNs(libodmZdaZLshrZdoZR) /* libodm.a(shr.o) */
812
Str5FNs(libmpiZurZdaZLmpicoreZurZdoZR) /* libmpi_r.a(mpicore_r.o) */
813
Str5FNs(libmpiZurZdaZLmpipoeZurZdoZR) /* libmpi_r.a(mpipoe_r.o) */
814
Str5FNs(libmpiZurZdaZLmpciZurZdoZR) /* libmpi_r.a(mpci_r.o) */
815
Str5FNs(libslurmZdso) /* libslurm.so */
816
Str5FNs(libglibZdso) /* libglib.so */
817
Str5FNs(libIMZdaZLshrZdoZR) /* libIM.a(shr.o) */
818
Str5FNs(libiconvZdaZLshr4ZdoZR) /* libiconv.a(shr4.o) */
819
Str5FNs(libGLZdaZLshrZdoZR) /* libGL.a(shr.o) */
820
Str5FNs(libgdkZdso) /* libgdk.so */
821
Str5FNs(libcursesZdaZLshr42ZdoZR) /* libcurses.a(shr42.o) */
822
Str5FNs(libqtZda) /* libqt.a */
823
Str5FNs(ZaZLlibglibZhZaZdsoZaZR) /* *(libglib-*.so*) */
824
Str5FNs(ZaZLlibfontconfigZdsoZaZR) /* *(libfontconfig.so*) */
825
Str5FNs(libQtZaa) /* libQt*.a */
827
#if defined(VGP_ppc64_aix5)
828
Str5FNs(NONE) /* in main exe */
829
Str5FNs(libX11ZdaZLshrZu64ZdoZR) /* libX11.a(shr_64.o) */
830
Str5FNs(libiconvZdaZLshr4Zu64ZdoZR) /* libiconv.a(shr4_64.o) */
831
Str5FNs(libGLZdaZLshrZu64ZdoZR) /* libGL.a(shr_64.o) */
832
Str5FNs(libppeZurZdaZLdynamic64ZdoZR) /* libppe_r.a(dynamic64.o) */
833
Str5FNs(libodmZdaZLshrZu64ZdoZR) /* libodm.a(shr_64.o) */
834
Str5FNs(libmpiZurZdaZLmpicore64ZurZdoZR) /* libmpi_r.a(mpicore64_r.o) */
835
Str5FNs(libmpiZurZdaZLmpipoe64ZurZdoZR) /* libmpi_r.a(mpipoe64_r.o) */
836
Str5FNs(libCZdaZLshrcoreZu64ZdoZR) /* libC.a(shrcore_64.o) */
837
Str5FNs(libmpiZurZdaZLmpci64ZurZdoZR) /* libmpi_r.a(mpci64_r.o) */
838
Str5FNs(libqtZda) /* libqt.a */
839
Str5FNs(ZaZLlibglibZhZaZdsoZaZR) /* *(libglib-*.so*) */
840
Str5FNs(ZaZLlibfontconfigZdsoZaZR) /* *(libfontconfig.so*) */
841
Str5FNs(libQtZaa) /* libQt*.a */
845
/* AIX's libm contains a sqrt implementation which does a nasty thing:
846
it loads the initial estimate of the root into a FP register, but
847
only the upper half of the number is initialised data. Hence the
848
least significant 32 mantissa bits are undefined, and it then uses
849
Newton-Raphson iteration to compute the final, defined result.
850
This fools memcheck completely; the only solution I can think of is
851
provide our own substitute. The _FAST variant is almost right
852
except the result is not correctly rounded. The _EXACT variant,
853
which is selected by default, is always right; but it's also pretty
856
#if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
857
#define SQRT_FAST(soname, fnname) \
858
double VG_REPLACE_FUNCTION_ZU(soname,fnname)( double x ); \
859
double VG_REPLACE_FUNCTION_ZU(soname,fnname)( double x ) \
861
static UInt T1[32] = \
862
{ 0, 1024, 3062, 5746, 9193, 13348, \
863
18162, 23592, 29598, 36145, 43202, 50740, \
864
58733, 67158, 75992, 85215, 83599, 71378, \
865
60428, 50647, 41945, 34246, 27478, 21581, \
866
16499, 12183, 8588, 5674, 3403, 1742, \
868
UInt x0, x1, sign, expo, mant0, bIGENDIAN = 1; \
869
union { UInt w[2]; double d; } u; \
871
x0 = u.w[1 - bIGENDIAN]; /* high half */ \
872
x1 = u.w[bIGENDIAN]; /* low half */ \
874
expo = (x0 >> 20) & 0x7FF; \
875
mant0 = x0 & 0xFFFFF; \
876
if ( (sign == 0 && expo >= 1 && expo <= 0x7FE) /* +normal */ \
877
|| (sign == 0 && expo == 0 \
878
&& (mant0 | x1) > 0) /* +denorm */) { \
879
/* common case; do Newton-Raphson */ \
880
/* technically k should be signed int32, but since we're \
881
always entering here with x > 0, doesn't matter that it's \
884
UInt k = (x0>>1) + 0x1ff80000; \
885
u.w[1 - bIGENDIAN] = k - T1[31&(k>>15)]; \
886
u.w[bIGENDIAN] = 0; \
890
y = y-(y-x/y)/2.0 ; \
893
if ( (sign == 1 && expo >= 1 && expo <= 0x7FE) /* -normal */ \
894
|| (sign == 1 && expo == 0 \
895
&& (mant0 | x1) > 0) /* -denorm */) { \
896
u.w[1 - bIGENDIAN] = 0xFFF00000; \
897
u.w[bIGENDIAN] = 0x1; \
898
return u.d; /* -Inf -> NaN */ \
900
if ((expo | mant0 | x1) == 0) \
901
return x; /* +/-zero -> self */ \
902
if (expo == 0x7FF && (mant0 | x1) == 0) { \
904
return x; /* +Inf -> self */ \
905
u.w[1 - bIGENDIAN] = 0xFFF00000; \
906
u.w[bIGENDIAN] = 0x1; \
907
return u.d; /* -Inf -> NaN */ \
909
/* must be +/- NaN */ \
910
return x; /* +/-NaN -> self */ \
913
#define SQRT_EXACT(soname, fnname) \
915
* ==================================================== \
916
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. \
918
* Developed at SunPro, a Sun Microsystems, Inc. business. \
919
* Permission to use, copy, modify, and distribute this \
920
* software is freely granted, provided that this notice \
922
* ==================================================== \
925
* Return correctly rounded sqrt. \
926
* ------------------------------------------ \
927
* | Use the hardware sqrt if you have one | \
928
* ------------------------------------------ \
930
* Bit by bit method using integer arithmetic. (Slow, but portable) \
932
* Scale x to y in [1,4) with even powers of 2: \
933
* find an integer k such that 1 <= (y=x*2^(2k)) < 4, then \
934
* sqrt(x) = 2^k * sqrt(y) \
935
* 2. Bit by bit computation \
936
* Let q = sqrt(y) truncated to i bit after binary point (q = 1), \
939
* s = 2*q , and y = 2 * ( y - q ). (1) \
942
* To compute q from q , one checks whether \
946
* (q + 2 ) <= y. (2) \
949
* If (2) is false, then q = q ; otherwise q = q + 2 . \
952
* With some algebric manipulation, it is not difficult to see \
953
* that (2) is equivalent to \
958
* The advantage of (3) is that s and y can be computed by \
960
* the following recurrence formula: \
963
* s = s , y = y ; (4) \
968
* s = s + 2 , y = y - s - 2 (5) \
972
* One may easily use induction to prove (4) and (5). \
973
* Note. Since the left hand side of (3) contain only i+2 bits, \
974
* it does not necessary to do a full (53-bit) comparison \
976
* 3. Final rounding \
977
* After generating the 53 bits result, we compute one more bit. \
978
* Together with the remainder, we can decide whether the \
979
* result is exact, bigger than 1/2ulp, or less than 1/2ulp \
980
* (it will never equal to 1/2ulp). \
981
* The rounding mode can be detected by checking whether \
982
* huge + tiny is equal to huge, and whether huge - tiny is \
983
* equal to huge for some floating point number "huge" and "tiny". \
986
* sqrt(+-0) = +-0 ... exact \
988
* sqrt(-ve) = NaN ... with invalid signal \
989
* sqrt(NaN) = NaN ... with invalid signal for signaling NaN \
992
double VG_REPLACE_FUNCTION_ZU(soname,fnname)( double x ); \
993
double VG_REPLACE_FUNCTION_ZU(soname,fnname)( double x ) \
995
const Int bIGENDIAN = 1; \
996
const double one = 1.0, tiny=1.0e-300; \
998
Int sign = (Int)0x80000000; \
999
Int ix0,s0,q,m,t,i; \
1000
UInt r,t1,s1,ix1,q1; \
1001
union { UInt w[2]; double d; } u; \
1003
ix0 = u.w[1-bIGENDIAN]; \
1004
ix1 = u.w[bIGENDIAN]; \
1006
/* take care of Inf and NaN */ \
1007
if((ix0&0x7ff00000)==0x7ff00000) { \
1008
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf \
1009
sqrt(-inf)=sNaN */ \
1011
/* take care of zero */ \
1013
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ \
1015
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ \
1019
if(m==0) { /* subnormal x */ \
1022
ix0 |= (ix1>>11); ix1 <<= 21; \
1024
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; \
1026
ix0 |= (ix1>>(32-i)); \
1029
m -= 1023; /* unbias exponent */ \
1030
ix0 = (ix0&0x000fffff)|0x00100000; \
1031
if(m&1){ /* odd m, double x to make it even */ \
1032
ix0 += ix0 + ((ix1&sign)>>31); \
1035
m >>= 1; /* m = [m/2] */ \
1036
/* generate sqrt(x) bit by bit */ \
1037
ix0 += ix0 + ((ix1&sign)>>31); \
1039
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ \
1040
r = 0x00200000; /* r = moving bit from right to left */ \
1048
ix0 += ix0 + ((ix1&sign)>>31); \
1056
if((t<ix0)||((t==ix0)&&(t1<=ix1))) { \
1058
if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1; \
1060
if (ix1 < t1) ix0 -= 1; \
1064
ix0 += ix0 + ((ix1&sign)>>31); \
1068
/* use floating add to find out rounding direction */ \
1069
if((ix0|ix1)!=0) { \
1070
z = one-tiny; /* trigger inexact flag */ \
1073
if (q1==(UInt)0xffffffff) { q1=0; q += 1;} \
1075
if (q1==(UInt)0xfffffffe) q+=1; \
1081
ix0 = (q>>1)+0x3fe00000; \
1083
if ((q&1)==1) ix1 |= sign; \
1085
ix0 = u.w[1-bIGENDIAN] = ix0; \
1086
ix1 = u.w[bIGENDIAN] = ix1; \
1092
SQRT_FAST(NONE, sqrt) /* xlC generates these */
1093
SQRT_FAST(NONE, _sqrt) /* xlf generates these */
1095
SQRT_EXACT(NONE, sqrt) /* xlC generates these */
1096
SQRT_EXACT(NONE, _sqrt) /* xlf generates these */
1099
#endif /* defined(VGP_ppc32_aix5) */
539
1101
/*--------------------------------------------------------------------*/