Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libisns fix gcc aliasing issues.
details: https://anonhg.NetBSD.org/src/rev/bf9fdf2b9ec7
branches: trunk
changeset: 768469:bf9fdf2b9ec7
user: christos <christos%NetBSD.org@localhost>
date: Wed Aug 17 10:08:43 2011 +0000
description:
fix gcc aliasing issues.
diffstat:
lib/libisns/Makefile | 6 +-----
lib/libisns/isns_pdu.h | 46 ++++++++++++++++++++++++++--------------------
lib/libisns/isns_util.h | 3 ++-
3 files changed, 29 insertions(+), 26 deletions(-)
diffs (110 lines):
diff -r 9520f1c96560 -r bf9fdf2b9ec7 lib/libisns/Makefile
--- a/lib/libisns/Makefile Wed Aug 17 09:56:03 2011 +0000
+++ b/lib/libisns/Makefile Wed Aug 17 10:08:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2011/06/21 02:32:55 mrg Exp $
+# $NetBSD: Makefile,v 1.3 2011/08/17 10:08:43 christos Exp $
.include <bsd.own.mk>
@@ -14,7 +14,3 @@
WARNS= 4
.include <bsd.lib.mk>
-
-.if ${HAVE_GCC} >= 45
-COPTS.isns_pdu.c+= -fno-strict-aliasing
-.endif
diff -r 9520f1c96560 -r bf9fdf2b9ec7 lib/libisns/isns_pdu.h
--- a/lib/libisns/isns_pdu.h Wed Aug 17 09:56:03 2011 +0000
+++ b/lib/libisns/isns_pdu.h Wed Aug 17 10:08:43 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: isns_pdu.h,v 1.1.1.1 2011/01/16 01:22:50 agc Exp $ */
+/* $NetBSD: isns_pdu.h,v 1.2 2011/08/17 10:08:43 christos Exp $ */
/*-
* Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
@@ -37,8 +37,10 @@
#define _ISNS_PDU_H_
#include <pthread.h>
+#include <string.h>
#include "isns_defs.h"
+#include "isns_util.h"
#define ISNSP_VERSION (0x0001)
@@ -101,32 +103,36 @@
/*
* TLV buffer access/manipulation-related macros.
*/
-#define ISNS_TLV_HDR_SIZE 8
+#define ISNS_TLV_HDR_SIZE (sizeof(uint32_t) * 2)
#define ISNS_PAD4_LEN(n) (uint32_t)(((n)+3) & ~0x03)
#define ISNS_PAD4_BYTES(n) ((4 - ((n) & 0x03)) & 0x03)
-#define ISNS_TLV_TAG_REF(_buf) \
- (*(uint32_t *)(void *)(_buf))
-#define ISNS_TLV_GET_TAG(_buf) \
- isns_ntohl(ISNS_TLV_TAG_REF(_buf))
-#define ISNS_TLV_SET_TAG(_buf, _tag) \
- do { \
- ISNS_TLV_TAG_REF(_buf) = isns_htonl(_tag); \
- } while (/* CONSTCOND */0)
+static inline uint32_t ISNS_TLV_GET_TAG(const void *buf) {
+ uint32_t tag;
+ memcpy(&tag, buf, sizeof(tag));
+ return isns_ntohl(tag);
+}
+
+static inline void ISNS_TLV_SET_TAG(void *buf, uint32_t tag) {
+ tag = isns_htonl(tag);
+ memcpy(buf, &tag, sizeof(tag));
+}
-#define ISNS_TLV_LEN_REF(_buf) \
- (*(uint32_t *)(void *)((uint8_t *)(_buf)+4))
-#define ISNS_TLV_GET_LEN(_buf) \
- isns_ntohl(ISNS_TLV_LEN_REF(_buf))
-#define ISNS_TLV_SET_LEN(_buf, _len) \
- do { \
- ISNS_TLV_LEN_REF(_buf) = isns_htonl(_len); \
- } while (/* CONSTCOND */0)
+static inline uint32_t ISNS_TLV_GET_LEN(const void *buf) {
+ uint32_t len;
+ memcpy(&len, (const uint8_t *)buf + sizeof(len), sizeof(len));
+ return isns_ntohl(len);
+}
-#define ISNS_TLV_DATA_PTR(_buf) \
- ((void *)((uint8_t *)(_buf)+8))
+static inline void ISNS_TLV_SET_LEN(void *buf, uint32_t len) {
+ len = isns_htonl(len);
+ memcpy((uint8_t *)buf + sizeof(len), &len, sizeof(len));
+}
+static inline void *ISNS_TLV_DATA_PTR(void *buf) {
+ return (uint8_t *)buf + ISNS_TLV_HDR_SIZE;
+}
/*
* ISNS transaction and PDU structs.
diff -r 9520f1c96560 -r bf9fdf2b9ec7 lib/libisns/isns_util.h
--- a/lib/libisns/isns_util.h Wed Aug 17 09:56:03 2011 +0000
+++ b/lib/libisns/isns_util.h Wed Aug 17 10:08:43 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: isns_util.h,v 1.1.1.1 2011/01/16 01:22:50 agc Exp $ */
+/* $NetBSD: isns_util.h,v 1.2 2011/08/17 10:08:43 christos Exp $ */
/*-
* Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
@@ -48,6 +48,7 @@
#define ARRAY_ELEMS(a) (sizeof(a)/sizeof((a)[0]))
+struct isns_config_s;
int isns_issue_cmd(struct isns_config_s *, uint8_t);
int isns_issue_cmd_with_data(struct isns_config_s *, uint8_t,
uint8_t *, int);
Home |
Main Index |
Thread Index |
Old Index