Source-Changes-HG archive

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

[src/trunk]: src/sys/modules/lua Make sure that buffers allocated by lua_allo...



details:   https://anonhg.NetBSD.org/src/rev/3a4ff773c136
branches:  trunk
changeset: 1022777:3a4ff773c136
user:      rin <rin%NetBSD.org@localhost>
date:      Sat Aug 07 04:19:31 2021 +0000

description:
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:

 sys/modules/lua/lua.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r 8d00b1f56192 -r 3a4ff773c136 sys/modules/lua/lua.c
--- a/sys/modules/lua/lua.c     Sat Aug 07 03:28:42 2021 +0000
+++ b/sys/modules/lua/lua.c     Sat Aug 07 04:19:31 2021 +0000
@@ -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@localhost>.
@@ -547,14 +547,18 @@
 
 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 */



Home | Main Index | Thread Index | Old Index