aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-03-02 19:15:05 +0000
committerNick Mathewson <nickm@torproject.org>2009-03-02 19:15:05 +0000
commit9f8d095e0fa66dfa5087d5d23028b5caa3a87989 (patch)
tree25a414ab2b342e34f3aff851e76a358269ec40a8 /src/common
parentaa154d846afaf38efeaf44bc55af6fc26bb180bd (diff)
downloadtor-9f8d095e0fa66dfa5087d5d23028b5caa3a87989.tar.gz
tor-9f8d095e0fa66dfa5087d5d23028b5caa3a87989.zip
Add and use set/get_uint64 on onion tags. [bug 604; backportable]
It seems that 64-bit Sparc Solaris demands 64-bit-aligned access to uint64_t, but does not 64-bit-align the stack-allocated char array we use for cpuworker tags. So this patch adds a set/get_uint64 pair, and uses them to access the conn_id field in the tag. svn:r18743
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c26
-rw-r--r--src/common/compat.h2
2 files changed, 26 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 23efe0b656..8fd6d9bc15 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -449,8 +449,21 @@ get_uint32(const char *cp)
return v;
}
/**
+ * Read a 32-bit value beginning at <b>cp</b>. Equivalent to
+ * *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid
+ * unaligned memory access.
+ */
+uint64_t
+get_uint64(const char *cp)
+{
+ uint64_t v;
+ memcpy(&v,cp,8);
+ return v;
+}
+
+/**
* Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
- * *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid
+ * *(uint16_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint16(char *cp, uint16_t v)
@@ -459,13 +472,22 @@ set_uint16(char *cp, uint16_t v)
}
/**
* Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
- * *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid
+ * *(uint32_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint32(char *cp, uint32_t v)
{
memcpy(cp,&v,4);
}
+/**
+ * Set a 64-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
+ * *(uint64_t*)(cp) = v, but will not cause segfaults on platforms that forbid
+ * unaligned memory access. */
+void
+set_uint64(char *cp, uint64_t v)
+{
+ memcpy(cp,&v,8);
+}
/**
* Rename the file <b>from</b> to the file <b>to</b>. On unix, this is
diff --git a/src/common/compat.h b/src/common/compat.h
index 7e8c83a297..b80bdd1222 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -450,8 +450,10 @@ const char *get_uname(void);
uint16_t get_uint16(const char *cp) ATTR_PURE ATTR_NONNULL((1));
uint32_t get_uint32(const char *cp) ATTR_PURE ATTR_NONNULL((1));
+uint64_t get_uint64(const char *cp) ATTR_PURE ATTR_NONNULL((1));
void set_uint16(char *cp, uint16_t v) ATTR_NONNULL((1));
void set_uint32(char *cp, uint32_t v) ATTR_NONNULL((1));
+void set_uint64(char *cp, uint64_t v) ATTR_NONNULL((1));
/* These uint8 variants are defined to make the code more uniform. */
#define get_uint8(cp) (*(const uint8_t*)(cp))