summaryrefslogtreecommitdiff
path: root/sys/modules/lua/lua.c
diff options
context:
space:
mode:
authorrin <rin@NetBSD.org>2021-08-07 04:19:31 +0000
committerrin <rin@NetBSD.org>2021-08-07 04:19:31 +0000
commit6831ca07b18e59371378ad5a38479d5c68fa924d (patch)
tree834c04ac47d80d7831216e66c369c9a5a6874dff /sys/modules/lua/lua.c
parent3033f5457259a6fd04054590a91f9e822da7c8eb (diff)
Make sure that buffers allocated by lua_alloc() are aligned to 8-byte
boundaries as done by kmem_alloc(9). Fix alignment faults on armv5te; GCC emits ldrd/strd instructions for memory operands that are guaranteed to be aligned properly. Drop unnecessary __packed attribute from alloc_header_t at the same time.
Diffstat (limited to 'sys/modules/lua/lua.c')
-rw-r--r--sys/modules/lua/lua.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/sys/modules/lua/lua.c b/sys/modules/lua/lua.c
index b1e30ccef9c..00f966b8036 100644
--- a/sys/modules/lua/lua.c
+++ b/sys/modules/lua/lua.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lua.c,v 1.25 2021/06/29 22:40:53 dholland Exp $ */
+/* $NetBSD: lua.c,v 1.26 2021/08/07 04:19:31 rin Exp $ */
/*
* Copyright (c) 2011 - 2017 by Marc Balmer <mbalmer@NetBSD.org>.
@@ -547,14 +547,18 @@ lua_require(lua_State *L)
typedef struct {
size_t size;
-} __packed alloc_header_t;
+} alloc_header_t;
static void *
lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
void *nptr = NULL;
- const size_t hdr_size = sizeof(alloc_header_t);
+ /*
+ * Make sure that buffers allocated by lua_alloc() are aligned to
+ * 8-byte boundaries as done by kmem_alloc(9).
+ */
+ const size_t hdr_size = roundup(sizeof(alloc_header_t), 8);
alloc_header_t *hdr = (alloc_header_t *) ((char *) ptr - hdr_size);
if (nsize == 0) { /* freeing */