78
78
extern "C" {
79
79
#endif
80
80
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
+
81
95
/******************************************************************************/
82
96
/* Helpers */
83
97
/******************************************************************************/
@@ -247,7 +261,7 @@ DILL_EXPORT __attribute__((noinline)) void dill_epilogue(void);
247
261
#define dill_bundle_go (bndl , fn ) dill_go_(fn, NULL, 0, bndl)
248
262
#define dill_bundle_go_mem (bndl , fn , ptr , len ) dill_go_(fn, ptr, len, bndl)
249
263
250
- struct dill_bundle_storage {char _ [64 ];};
264
+ struct dill_bundle_storage {char _ [64 ];} DILL_ALIGN ;
251
265
252
266
DILL_EXPORT int dill_bundle (void );
253
267
DILL_EXPORT int dill_bundle_mem (struct dill_bundle_storage * mem );
@@ -281,7 +295,7 @@ struct dill_chclause {
281
295
size_t len ;
282
296
};
283
297
284
- struct dill_chstorage {char _ [144 ];};
298
+ struct dill_chstorage {char _ [144 ];} DILL_ALIGN ;
285
299
286
300
DILL_EXPORT int dill_chmake (
287
301
int chv [2 ]);
@@ -473,9 +487,9 @@ DILL_EXPORT int dill_ipaddr_equal(
473
487
/* TCP protocol. */
474
488
/******************************************************************************/
475
489
476
- struct dill_tcp_listener_storage {char _ [56 ];};
490
+ struct dill_tcp_listener_storage {char _ [56 ];} DILL_ALIGN ;
477
491
478
- struct dill_tcp_storage {char _ [72 ];};
492
+ struct dill_tcp_storage {char _ [72 ];} DILL_ALIGN ;
479
493
480
494
DILL_EXPORT int dill_tcp_listen (
481
495
struct dill_ipaddr * addr ,
@@ -538,11 +552,11 @@ DILL_EXPORT int dill_tcp_fromfd_mem(
538
552
/* IPC protocol. */
539
553
/******************************************************************************/
540
554
541
- struct dill_ipc_listener_storage {char _ [24 ];};
555
+ struct dill_ipc_listener_storage {char _ [24 ];} DILL_ALIGN ;
542
556
543
- struct dill_ipc_storage {char _ [72 ];};
557
+ struct dill_ipc_storage {char _ [72 ];} DILL_ALIGN ;
544
558
545
- struct dill_ipc_pair_storage {char _ [144 ];};
559
+ struct dill_ipc_pair_storage {char _ [144 ];} DILL_ALIGN ;
546
560
547
561
DILL_EXPORT int dill_ipc_listen (
548
562
const char * addr ,
@@ -621,7 +635,7 @@ DILL_EXPORT int dill_ipc_pair_mem(
621
635
/* Messages are prefixed by size. */
622
636
/******************************************************************************/
623
637
624
- struct dill_prefix_storage {char _ [56 ];};
638
+ struct dill_prefix_storage {char _ [56 ];} DILL_ALIGN ;
625
639
626
640
#define DILL_PREFIX_BIG_ENDIAN 0
627
641
#define DILL_PREFIX_LITTLE_ENDIAN 1
@@ -652,7 +666,7 @@ DILL_EXPORT int dill_prefix_detach(
652
666
/* Messages are suffixed by specified string of bytes. */
653
667
/******************************************************************************/
654
668
655
- struct dill_suffix_storage {char _ [128 ];};
669
+ struct dill_suffix_storage {char _ [128 ];} DILL_ALIGN ;
656
670
657
671
DILL_EXPORT int dill_suffix_attach (
658
672
int s ,
@@ -679,7 +693,7 @@ DILL_EXPORT int dill_suffix_detach(
679
693
/* Each UDP packet is treated as a separate message. */
680
694
/******************************************************************************/
681
695
682
- struct dill_udp_storage {char _ [72 ];};
696
+ struct dill_udp_storage {char _ [72 ];} DILL_ALIGN ;
683
697
684
698
DILL_EXPORT int dill_udp_open (
685
699
struct dill_ipaddr * local ,
@@ -725,7 +739,7 @@ DILL_EXPORT ssize_t dill_udp_recvl(
725
739
/* HTTP */
726
740
/******************************************************************************/
727
741
728
- struct dill_http_storage {char _ [1296 ];};
742
+ struct dill_http_storage {char _ [1296 ];} DILL_ALIGN ;
729
743
730
744
DILL_EXPORT int dill_http_attach (
731
745
int s );
@@ -793,7 +807,7 @@ DILL_EXPORT int dill_http_recvfield(
793
807
/* TLS protocol. */
794
808
/******************************************************************************/
795
809
796
- struct dill_tls_storage {char _ [72 ];};
810
+ struct dill_tls_storage {char _ [72 ];} DILL_ALIGN ;
797
811
798
812
DILL_EXPORT int dill_tls_attach_server (
799
813
int s ,
@@ -834,7 +848,7 @@ DILL_EXPORT int dill_tls_detach(
834
848
/* DTLS protocol. */
835
849
/******************************************************************************/
836
850
837
- struct dill_dtls_storage {char _ [88 ];};
851
+ struct dill_dtls_storage {char _ [88 ];} DILL_ALIGN ;
838
852
839
853
DILL_EXPORT int dill_dtls_attach_server (
840
854
int s ,
@@ -877,7 +891,7 @@ DILL_EXPORT int dill_dtls_detach(
877
891
/* WebSockets protocol. */
878
892
/******************************************************************************/
879
893
880
- struct dill_ws_storage {char _ [176 ];};
894
+ struct dill_ws_storage {char _ [176 ];} DILL_ALIGN ;
881
895
882
896
#define DILL_WS_BINARY 0
883
897
#define DILL_WS_TEXT 1
@@ -1059,7 +1073,7 @@ DILL_EXPORT int dill_socks5_proxy_sendreply(
1059
1073
/* Implementes terminal handshake on the top of any message-based protocol. */
1060
1074
/******************************************************************************/
1061
1075
1062
- struct dill_term_storage {char _ [88 ];};
1076
+ struct dill_term_storage {char _ [88 ];} DILL_ALIGN ;
1063
1077
1064
1078
DILL_EXPORT int dill_term_attach (
1065
1079
int s ,
0 commit comments