Skip to content

Commit 8995412

Browse files
authored
Merge pull request #207 from jcarrano/arm-alignment
Force alignment in ARM architectures
2 parents 4abefd2 + c7b6427 commit 8995412

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

libdill.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
extern "C" {
7979
#endif
8080

81+
/******************************************************************************/
82+
/* Memory alignment */
83+
/******************************************************************************/
84+
85+
/* Opaque structures will violate alignments and cause crashes on certain
86+
architectures
87+
*/
88+
89+
#if (defined __arm__) || (defined __thumb__)
90+
#define DILL_ALIGN __attribute__ ((aligned(__SIZEOF_POINTER__)))
91+
#else
92+
#define DILL_ALIGN
93+
#endif
94+
8195
/******************************************************************************/
8296
/* Helpers */
8397
/******************************************************************************/
@@ -247,7 +261,7 @@ DILL_EXPORT __attribute__((noinline)) void dill_epilogue(void);
247261
#define dill_bundle_go(bndl, fn) dill_go_(fn, NULL, 0, bndl)
248262
#define dill_bundle_go_mem(bndl, fn, ptr, len) dill_go_(fn, ptr, len, bndl)
249263

250-
struct dill_bundle_storage {char _[64];};
264+
struct dill_bundle_storage {char _[64];} DILL_ALIGN;
251265

252266
DILL_EXPORT int dill_bundle(void);
253267
DILL_EXPORT int dill_bundle_mem(struct dill_bundle_storage *mem);
@@ -281,7 +295,7 @@ struct dill_chclause {
281295
size_t len;
282296
};
283297

284-
struct dill_chstorage {char _[144];};
298+
struct dill_chstorage {char _[144];} DILL_ALIGN;
285299

286300
DILL_EXPORT int dill_chmake(
287301
int chv[2]);
@@ -473,9 +487,9 @@ DILL_EXPORT int dill_ipaddr_equal(
473487
/* TCP protocol. */
474488
/******************************************************************************/
475489

476-
struct dill_tcp_listener_storage {char _[56];};
490+
struct dill_tcp_listener_storage {char _[56];} DILL_ALIGN;
477491

478-
struct dill_tcp_storage {char _[72];};
492+
struct dill_tcp_storage {char _[72];} DILL_ALIGN;
479493

480494
DILL_EXPORT int dill_tcp_listen(
481495
struct dill_ipaddr *addr,
@@ -538,11 +552,11 @@ DILL_EXPORT int dill_tcp_fromfd_mem(
538552
/* IPC protocol. */
539553
/******************************************************************************/
540554

541-
struct dill_ipc_listener_storage {char _[24];};
555+
struct dill_ipc_listener_storage {char _[24];} DILL_ALIGN;
542556

543-
struct dill_ipc_storage {char _[72];};
557+
struct dill_ipc_storage {char _[72];} DILL_ALIGN;
544558

545-
struct dill_ipc_pair_storage {char _[144];};
559+
struct dill_ipc_pair_storage {char _[144];} DILL_ALIGN;
546560

547561
DILL_EXPORT int dill_ipc_listen(
548562
const char *addr,
@@ -621,7 +635,7 @@ DILL_EXPORT int dill_ipc_pair_mem(
621635
/* Messages are prefixed by size. */
622636
/******************************************************************************/
623637

624-
struct dill_prefix_storage {char _[56];};
638+
struct dill_prefix_storage {char _[56];} DILL_ALIGN;
625639

626640
#define DILL_PREFIX_BIG_ENDIAN 0
627641
#define DILL_PREFIX_LITTLE_ENDIAN 1
@@ -652,7 +666,7 @@ DILL_EXPORT int dill_prefix_detach(
652666
/* Messages are suffixed by specified string of bytes. */
653667
/******************************************************************************/
654668

655-
struct dill_suffix_storage {char _[128];};
669+
struct dill_suffix_storage {char _[128];} DILL_ALIGN;
656670

657671
DILL_EXPORT int dill_suffix_attach(
658672
int s,
@@ -679,7 +693,7 @@ DILL_EXPORT int dill_suffix_detach(
679693
/* Each UDP packet is treated as a separate message. */
680694
/******************************************************************************/
681695

682-
struct dill_udp_storage {char _[72];};
696+
struct dill_udp_storage {char _[72];} DILL_ALIGN;
683697

684698
DILL_EXPORT int dill_udp_open(
685699
struct dill_ipaddr *local,
@@ -725,7 +739,7 @@ DILL_EXPORT ssize_t dill_udp_recvl(
725739
/* HTTP */
726740
/******************************************************************************/
727741

728-
struct dill_http_storage {char _[1296];};
742+
struct dill_http_storage {char _[1296];} DILL_ALIGN;
729743

730744
DILL_EXPORT int dill_http_attach(
731745
int s);
@@ -793,7 +807,7 @@ DILL_EXPORT int dill_http_recvfield(
793807
/* TLS protocol. */
794808
/******************************************************************************/
795809

796-
struct dill_tls_storage {char _[72];};
810+
struct dill_tls_storage {char _[72];} DILL_ALIGN;
797811

798812
DILL_EXPORT int dill_tls_attach_server(
799813
int s,
@@ -834,7 +848,7 @@ DILL_EXPORT int dill_tls_detach(
834848
/* DTLS protocol. */
835849
/******************************************************************************/
836850

837-
struct dill_dtls_storage {char _[88];};
851+
struct dill_dtls_storage {char _[88];} DILL_ALIGN;
838852

839853
DILL_EXPORT int dill_dtls_attach_server(
840854
int s,
@@ -877,7 +891,7 @@ DILL_EXPORT int dill_dtls_detach(
877891
/* WebSockets protocol. */
878892
/******************************************************************************/
879893

880-
struct dill_ws_storage {char _[176];};
894+
struct dill_ws_storage {char _[176];} DILL_ALIGN;
881895

882896
#define DILL_WS_BINARY 0
883897
#define DILL_WS_TEXT 1
@@ -1059,7 +1073,7 @@ DILL_EXPORT int dill_socks5_proxy_sendreply(
10591073
/* Implementes terminal handshake on the top of any message-based protocol. */
10601074
/******************************************************************************/
10611075

1062-
struct dill_term_storage {char _[88];};
1076+
struct dill_term_storage {char _[88];} DILL_ALIGN;
10631077

10641078
DILL_EXPORT int dill_term_attach(
10651079
int s,

0 commit comments

Comments
 (0)