gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r7439 - in GNUnet: . m4 src/server


From: gnunet
Subject: [GNUnet-SVN] r7439 - in GNUnet: . m4 src/server
Date: Wed, 16 Jul 2008 21:58:46 -0600 (MDT)

Author: grothoff
Date: 2008-07-16 21:58:46 -0600 (Wed, 16 Jul 2008)
New Revision: 7439

Added:
   GNUnet/m4/align.m4
Modified:
   GNUnet/configure.ac
   GNUnet/src/server/handler.c
Log:
fixing Mantis 1389

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2008-07-17 00:51:10 UTC (rev 7438)
+++ GNUnet/configure.ac 2008-07-17 03:58:46 UTC (rev 7439)
@@ -193,7 +193,9 @@
 AC_MSG_RESULT([$build_target])
 AC_SUBST(build_target)
 
+AC_UNALIGNED_64_ACCESS
 
+
 CHECK_PTHREAD
 LIBS="$PTHREAD_LIBS $LIBS"
 

Added: GNUnet/m4/align.m4
===================================================================
--- GNUnet/m4/align.m4                          (rev 0)
+++ GNUnet/m4/align.m4  2008-07-17 03:58:46 UTC (rev 7439)
@@ -0,0 +1,19 @@
+# align.m4
+dnl Copyright (C) 2008 Christian Grothoff
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License.  As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+# Define HAVE_UNALIGNED_64_ACCESS if reading a 64-bit value at a 32-bit 
aligned offset works
+# Note that the program intentionally causes a SIGBUS (so you may
+# see some message along those lines on the console).
+AC_DEFUN([AC_UNALIGNED_64_ACCESS],
+[AC_RUN_IFELSE(AC_LANG_PROGRAM([[struct S { int a,b,c;};]],
+                               [[struct S s = {0,0,0}; long long * p = &s.b; 
+                                 long long x = *p; return (int) x*x;]]),
+ AC_DEFINE([HAVE_UNALIGNED_64_ACCESS], 1, [We can access-64 bit values that 
are only 32-bit aligned]),
+ AC_DEFINE([HAVE_UNALIGNED_64_ACCESS], 0),
+ AC_DEFINE([HAVE_UNALIGNED_64_ACCESS], 0))
+])

Modified: GNUnet/src/server/handler.c
===================================================================
--- GNUnet/src/server/handler.c 2008-07-17 00:51:10 UTC (rev 7438)
+++ GNUnet/src/server/handler.c 2008-07-17 03:58:46 UTC (rev 7439)
@@ -383,6 +383,11 @@
   return ret;
 }
 
+#if HAVE_UNALIGNED_64_ACCESS
+#define ALIGN_REQUIRED sizeof(unsigned int)
+#else
+#define ALIGN_REQUIRED sizeof(unsigned long long)
+#endif
 
 /**
  * Handle a message (that was decrypted if needed).
@@ -443,10 +448,11 @@
             }
           return;
         }
-      if ((pos % sizeof (long)) != 0)
-        {
+
+      if ((pos % ALIGN_REQUIRED) != 0)
+       {
           /* correct misalignment; we allow messages to _not_ be a
-             multiple of sizeof(long) bytes (if absolutely necessary; it 
should be
+             multiple of 4-bytes (if absolutely necessary; it should be
              avoided where the cost for doing so is not prohibitive);
              however we also (need to) guaranteed word-alignment for the
              handlers; so we must re-align the message if it is
@@ -457,8 +463,8 @@
         }
       else
         {
-          part = (const GNUNET_MessageHeader *) &msg[pos];
-        }
+          part = (const GNUNET_MessageHeader *) &msg[pos];        
+       }
       pos += plen;
 
       ptyp = htons (part->type);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]