Removed hand-coded memcpy(), memset(), etc.

The rationale for the hand-coded versions was that the functions were not
guaranteed to be async-signal-safe and since itimer() and signals are being used
then it was necessary to provide own versions of it.
My guess is that the programmer knew the standards, but did't consider that the
environment in which the program would be used in would not have a problem with
this. Besides, memcpy, memset, etc. will be marked async-signal-safe in the next
IEEE Std 1003.1. See http://austingroupbugs.net/view.php?id=692#c1609 for
details. In particular this fragment "there are no known implementations where
these functions cannot be safely used in aysnc-signal-safe code."
This commit is contained in:
Ivan Skytte Jørgensen
2015-12-07 18:09:20 +01:00
parent 99e7c72fe1
commit 8a193adf8a
4 changed files with 6 additions and 35 deletions

11
Mem.cpp

@ -1851,17 +1851,6 @@ int32_t Mem::printBits ( void *src, int32_t srcBits , int32_t nb ) {
return 0;
}
// ass = async signal safe, dumb ass
void memset_ass ( register void *dest , register const char c , int32_t len ) {
register char *end = (char *)dest + len;
// JAB: so... the optimizer should take care of the extra
// register declaration for d, below... see note below.
register char *d = (char *)dest;
// JAB: gcc-3.4 did not like the cast in the previous version
// while ( dest < end ) *((char *)dest)++ = c;
while ( d < end ) { *d++ = c; }
}
// . TODO: avoid byteCopy by copying remnant bytes
// . ass = async signal safe, dumb ass

4
Mem.h

@ -53,10 +53,6 @@ uint64_t getHighestLitBitValueLL ( uint64_t bits ) ;
uint32_t reverseBits ( uint32_t x ) ;
// async signal safe functions
//void memcpy_ass ( register void *dest , register const void *src , int32_t len ) ;
void memset_ass ( register void *dst , register const char c , int32_t len ) ;
inline int gbstrlen ( const char *s ) {
if ( ! s ) { char *xx=NULL;*xx=0; }
return strlen(s);

@ -166,7 +166,7 @@ void UdpSlot::connect ( UdpProtocol *proto ,
// we will clear on demand using m_numBitsInitialized logic
// in UdpSlot.h
int32_t size = (char *)&m_sentBits2 - (char *)this ;
memset_ass ( (char *)this , 0 , size );
memset ( (char *)this , 0 , size );
// store this info
m_proto = proto ;
m_ip = ip ; // keep in network order
@ -777,9 +777,7 @@ int32_t UdpSlot::sendDatagramOrAck ( int sock, bool allowResends, int64_t now ){
g_udpServer.m_outsiderBytesOut += dgramSize;
}
// not async signal safe
//bzero ( &(to.sin_zero) , 8 );
memset_ass ( (char *)&(to.sin_zero), 0 , 8 );
memset ( (char *)&(to.sin_zero), 0 , 8 );
// debug msg
//log("sendto");
// debug msg
@ -1091,9 +1089,7 @@ int32_t UdpSlot::sendAck ( int sock , int64_t now ,
// to.sin_addr.s_addr = m_host->m_ip;
//}
// not async sig safe
//bzero ( &(to.sin_zero) , 8 );
memset_ass ( (char *)&(to.sin_zero), 0 , 8 );
memset ( (char *)&(to.sin_zero), 0 , 8 );
// stat count
if ( cancelTrans ) g_cancelAcksSent++;
// . this socket should be non-blocking (i.e. return immediately)

@ -12,21 +12,11 @@
// fix on 64-bit architectures so sizeof(uint96_t) is 12, not 16!
//#pragma pack(0)
//#define gbmemcpy memcpy_ass
//#define memset memset_ass
extern int g_inMemcpy;
//#define gbmemcpy(xx,yy,zz) {g_inMemcpy=1;memcpy(xx,yy,zz);g_inMemcpy=0;}
// use bcopy() since when doing real-time profiling in Profiler.cpp
// it interrupts the code with a signal and then calls backtrace() which
// itself calls memcpy(). so if it interrupted the code in an memcpy()
// it causes a segfault because memcpy() is not async safe.
#define gbmemcpy(xx,yy,zz) {bcopy(yy,xx,zz); }
// i guess use bcopy for this now too!
#define memcpy_ass(xx,yy,zz) {bcopy(yy,xx,zz); }
//The two gbmem* functions below are legacy. Don't use them in new code
#define gbmemcpy(xx,yy,zz) memcpy(xx,yy,zz)
#define memcpy_ass(xx,yy,zz) memcpy(xx,yy,zz)