Included patch #5920: Create define to override C-library memcpy. 2 Defines are created: MEMCPY() for normal memcpy, SMEMCPY() for situations where some compilers might inline the copy and save a function call. Also replaced all calls to memcpy() with calls to (S)MEMCPY().

This commit is contained in:
goldsimon 2007-05-10 05:20:05 +00:00
parent b41520f9e2
commit 255d5a748f
18 changed files with 51 additions and 34 deletions

View File

@ -22,6 +22,11 @@ HISTORY
* [Enter new changes just after this line - do not remove this line]
++ New features:
2007-05-08 Simon Goldschmidt
* opt.h, *.c/*.h: Included patch #5920: Create define to override C-library
memcpy. 2 Defines are created: MEMCPY() for normal memcpy, SMEMCPY() for
situations where some compilers might inline the copy and save a function
call. Also replaced all calls to memcpy() with calls to (S)MEMCPY().
2007-05-08 Simon Goldschmidt
* mem.h: If MEM_LIBC_MALLOC==1, allow the defines (e.g. mem_malloc() -> malloc())

View File

@ -171,7 +171,7 @@ netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
if (buf_copy_len > len)
buf_copy_len = len;
/* copy the necessary parts of the buffer */
memcpy(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
left += buf_copy_len;
len -= buf_copy_len;
offset = 0;

View File

@ -191,7 +191,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
if (*addrlen > sizeof(sin))
*addrlen = sizeof(sin);
memcpy(addr, &sin, *addrlen);
SMEMCPY(addr, &sin, *addrlen);
newsock = alloc_socket(newconn);
if (newsock == -1) {
@ -412,7 +412,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
if (*fromlen > sizeof(sin))
*fromlen = sizeof(sin);
memcpy(from, &sin, *fromlen);
SMEMCPY(from, &sin, *fromlen);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
ip_addr_debug_print(SOCKETS_DEBUG, addr);
@ -890,7 +890,7 @@ int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
if (*namelen > sizeof(sin))
*namelen = sizeof(sin);
memcpy(name, &sin, *namelen);
SMEMCPY(name, &sin, *namelen);
sock_set_errno(sock, 0);
return 0;
}
@ -922,7 +922,7 @@ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
if (*namelen > sizeof(sin))
*namelen = sizeof(sin);
memcpy(name, &sin, *namelen);
SMEMCPY(name, &sin, *namelen);
sock_set_errno(sock, 0);
return 0;
}

View File

@ -141,7 +141,7 @@ icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
ICMPH_TYPE_SET(idur, ICMP_DUR);
ICMPH_CODE_SET(idur, t);
memcpy((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8);
SMEMCPY((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8);
/* calculate checksum */
idur->chksum = 0;
@ -179,7 +179,7 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
ICMPH_CODE_SET(tehdr, t);
/* copy fields from original packet */
memcpy((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8);
SMEMCPY((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8);
/* calculate checksum */
tehdr->chksum = 0;

View File

@ -74,7 +74,7 @@ copy_from_pbuf(struct pbuf *p, u16_t * offset,
p->len -= *offset;
while (len) {
l = len < p->len ? len : p->len;
memcpy(buffer, p->payload, l);
MEMCPY(buffer, p->payload, l);
buffer += l;
len -= l;
if (len)
@ -141,7 +141,7 @@ ip_reass(struct pbuf *p)
buffer. The timer is updated with the maximum age. */
if (ip_reasstmr == 0) {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: new packet\n"));
memcpy(iphdr, fraghdr, IP_HLEN);
SMEMCPY(iphdr, fraghdr, IP_HLEN);
ip_reasstmr = IP_REASS_MAXAGE;
ip_reassflags = 0;
/* Clear the bitmap. */
@ -277,7 +277,7 @@ ip_reass(struct pbuf *p)
("ip_reass: memcpy from %p (%"S16_F") to %p, %"S16_F" bytes\n",
(void *)&ip_reassbuf[i], i, q->payload,
q->len > ip_reasslen - i ? ip_reasslen - i : q->len));
memcpy(q->payload, &ip_reassbuf[i],
MEMCPY(q->payload, &ip_reassbuf[i],
q->len > ip_reasslen - i ? ip_reasslen - i : q->len);
i += q->len;
}
@ -333,7 +333,7 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
/* Copy the IP header in it */
iphdr = rambuf->payload;
memcpy(iphdr, p->payload, IP_HLEN);
SMEMCPY(iphdr, p->payload, IP_HLEN);
/* Save original offset */
tmp = ntohs(IPH_OFFSET(iphdr));

View File

@ -130,7 +130,7 @@ icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
idur->type = (u8_t)ICMP6_DUR;
idur->icode = (u8_t)t;
memcpy((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8);
SMEMCPY((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8);
/* calculate checksum */
idur->chksum = 0;
@ -162,7 +162,7 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
tehdr->icode = (u8_t)t;
/* copy fields from original packet */
memcpy((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8);
SMEMCPY((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8);
/* calculate checksum */
tehdr->chksum = 0;

View File

@ -58,7 +58,7 @@ ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2)
void
ip_addr_set(struct ip_addr *dest, struct ip_addr *src)
{
memcpy(dest, src, sizeof(struct ip_addr));
SMEMCPY(dest, src, sizeof(struct ip_addr));
/* dest->addr[0] = src->addr[0];
dest->addr[1] = src->addr[1];
dest->addr[2] = src->addr[2];

View File

@ -808,7 +808,7 @@ pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
/* current p_from does not fit into current p_to */
len = p_to->len - offset_to;
}
memcpy((u8_t*)p_to->payload + offset_to, (u8_t*)p_from->payload + offset_from, len);
MEMCPY((u8_t*)p_to->payload + offset_to, (u8_t*)p_from->payload + offset_from, len);
#ifdef LWIP_DEBUG
copied += len;
#endif

View File

@ -747,7 +747,7 @@ tcp_seg_copy(struct tcp_seg *seg)
if (cseg == NULL) {
return NULL;
}
memcpy((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
pbuf_ref(cseg->p);
return cseg;
}

View File

@ -213,7 +213,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
}
++queuelen;
if (arg != NULL) {
memcpy(seg->p->payload, ptr, seglen);
MEMCPY(seg->p->payload, ptr, seglen);
}
seg->dataptr = seg->p->payload;
}
@ -280,7 +280,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Copy options into data portion of segment.
Options can thus only be sent in non data carrying
segments such as SYN|ACK. */
memcpy(seg->dataptr, optdata, optlen);
SMEMCPY(seg->dataptr, optdata, optlen);
}
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_enqueue: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n",
ntohl(seg->tcphdr->seqno),

View File

@ -53,6 +53,18 @@
#define NO_SYS 0
#endif
/* override this if you have a faster implementation at hand than the one
included in your C library */
#ifndef MEMCPY
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
#endif
/* override this with care: some compilers (e.g. gcc) can inline a call to
memcpy() if the length is known at compile time and is small */
#ifndef SMEMCPY
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
#endif
/* ---------- Memory options ---------- */
#ifndef MEM_LIBC_MALLOC
#define MEM_LIBC_MALLOC 0

View File

@ -576,8 +576,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
* structure packing (not using structure copy which breaks strict-aliasing rules). */
memcpy(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
memcpy(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
/* this interface is not configured? */
if (netif->ip_addr.addr == 0) {

View File

@ -114,7 +114,7 @@ loopif_output(struct netif *netif, struct pbuf *p,
*/
ptr = r->payload;
for(q = p; q != NULL; q = q->next) {
memcpy(ptr, q->payload, q->len);
MEMCPY(ptr, q->payload, q->len);
ptr += q->len;
}

View File

@ -199,7 +199,7 @@ void MD5Final (unsigned char hash[], MD5_CTX *mdContext)
mdContext->digest[ii+3] =
(unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
}
memcpy(hash, mdContext->digest, 16);
SMEMCPY(hash, mdContext->digest, 16);
}
/* Basic MD5 step. Transforms buf based on in.

View File

@ -840,7 +840,7 @@ void ppp_send_config(
*/
void ppp_set_xaccm(int unit, ext_accm *accm)
{
memcpy(pppControl[unit].outACCM, accm, sizeof(ext_accm));
SMEMCPY(pppControl[unit].outACCM, accm, sizeof(ext_accm));
PPPDEBUG((LOG_INFO, "ppp_set_xaccm[%d]: outACCM=%X %X %X %X\n",
unit,
pppControl[unit].outACCM[0],
@ -1075,11 +1075,11 @@ int sifaddr(
st = 0;
PPPDEBUG((LOG_WARNING, "sifup[%d]: bad parms\n", pd));
} else {
memcpy(&pc->addrs.our_ipaddr, &o, sizeof(o));
memcpy(&pc->addrs.his_ipaddr, &h, sizeof(h));
memcpy(&pc->addrs.netmask, &m, sizeof(m));
memcpy(&pc->addrs.dns1, &ns1, sizeof(ns1));
memcpy(&pc->addrs.dns2, &ns2, sizeof(ns2));
SMEMCPY(&pc->addrs.our_ipaddr, &o, sizeof(o));
SMEMCPY(&pc->addrs.his_ipaddr, &h, sizeof(h));
SMEMCPY(&pc->addrs.netmask, &m, sizeof(m));
SMEMCPY(&pc->addrs.dns1, &ns1, sizeof(ns1));
SMEMCPY(&pc->addrs.dns2, &ns2, sizeof(ns2));
}
return st;
}
@ -1269,7 +1269,7 @@ static struct pbuf *pppSingleBuf(struct pbuf *p)
}
for(b = p, pl = q->payload; b != NULL; b = b->next) {
memcpy(pl, b->payload, b->len);
MEMCPY(pl, b->payload, b->len);
pl += b->len;
}
@ -1394,7 +1394,7 @@ static void pppInput(void *arg)
}
#if BYTE_ORDER == LITTLE_ENDIAN
protocol = htons(protocol);
memcpy(nb->payload, &protocol, sizeof(protocol));
SMEMCPY(nb->payload, &protocol, sizeof(protocol));
#endif
lcp_sprotrej(pd, nb->payload, nb->len);
}

View File

@ -206,7 +206,7 @@ enum NPmode {
#define DECPTR(n, cp) ((cp) -= (n))
#define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
#define BCOPY(s, d, l) memcpy((d), (s), (l))
#define BCOPY(s, d, l) MEMCPY((d), (s), (l))
#define BZERO(s, n) memset(s, 0, n)
#if PPP_DEBUG
#define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }

View File

@ -127,7 +127,7 @@ void avGenRand(char *buf, u32_t bufLen)
MD5Update(&md5, (u_char *)&randCount, sizeof(randCount));
MD5Final(tmp, &md5);
randCount++;
memcpy(buf, tmp, n);
MEMCPY(buf, tmp, n);
buf += n;
bufLen -= n;
}

View File

@ -605,7 +605,7 @@ int vj_uncompress_tcp(
bufptr = n0->payload;
for(q = np; q != NULL; q = q->next) {
memcpy(q->payload, bufptr, q->len);
MEMCPY(q->payload, bufptr, q->len);
bufptr += q->len;
}
@ -631,7 +631,7 @@ int vj_uncompress_tcp(
n0 = np;
}
LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen);
memcpy(n0->payload, &cs->cs_ip, cs->cs_hlen);
MEMCPY(n0->payload, &cs->cs_ip, cs->cs_hlen);
*nb = n0;