Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] mem: Align heap allocations for pointers too
- X-seq: zsh-workers 55295
- From: Florian Schmaus <florian.schmaus@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Florian Schmaus <florian.schmaus@xxxxxxxxxxx>
- Subject: [PATCH] mem: Align heap allocations for pointers too
- Date: Mon, 23 Nov 2026 16:51:37 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=codasip.com; dmarc=pass action=none header.from=codasip.com; dkim=pass header.d=codasip.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HFAQl0w5KKplH2O1CyrVhN+h6X+x804GH5s2EA+O5uM=; b=HE/cppezuWp+2xiHy9Q/SEgh5NUULAkWXR8wnGWKthTnvLcUMibc1d8pB+z3Gkdk3ObcnyJnTMR2HptqYRmK08mDHR3ZRJJvvPUTIEEPazEa5AyG2rfzxNCBohAf61URSAEOsZLfYkA3CVdEs1yvBgwOTxjuSJz9xC7zt7ELF2SnEbngKV8PYMLI/k0lYQiFpgsax97Nw9zq1aT+79P3z7LiXXnKXCsSFSSaImU2PiCwg5qVhdtdv3ybe+p5bPAqJQLl8Jfqp+JQF1SRdyvyf4+qzHeeJxArMtX5kG8VN1n8QvV0FxRoLA2iRB1k/GMmuEuWrpPMEe5LDhhHm1DbnA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N18UCByRZnEwoPK6xOvsaOflm3QxuoJsP4EDC4toxU5NvJHtpd33gH8139BMv/CCPJPAdL8nr2fC2acYbs9qQn5m5YVmRRhsh8NziCNxkXf2xiwQMIVbLUC4HKIRSPxwNDPh15RDLxt+3+28ZTzz3rtdrQrxLu4V/BE9//wnKhSjH+Yyr1naTWBjfL5wLcCvBq0ocmv0z0URXiQJE+JzVMw7+5ZRvgfO1bR9gRlPlqbaVi/nMup6jO07s7CuoFUj8SFU6RLgWtDLx+BQWvji3aIA9Rj2AS0gYt812TV/6Zg7Up4e1ydICSV32cxBzYS+jLcy9vK9Vnd2rnLnY7wlPw==
- Archived-at: <https://zsh.org/workers/55295>
- List-id: <zsh-workers.zsh.org>
zhalloc() rounds the size of each allocation up to a multiple of
sizeof(union mem_align). As the union only holds a zlong and a double,
this is 8 bytes on common platforms. Allocations are carved
consecutively out of an arena, so their start addresses are only
guaranteed to be 8-byte aligned.
On CHERI [1, 2], pointers are capabilities, which on 64-bit systems are
16 bytes in size and must be 16-byte aligned. Loading or storing a
pointer in a heap allocation that is only 8-byte aligned therefore
faults.
Add a void * member to union mem_align, so that heap allocations are
suitably aligned for pointers too. This also raises the block alignment
(M_ALIGN) of the optional ZSH_MEM allocator accordingly. On platforms
where pointers are no larger than zlong and double, the size of the
union, and thus the heap layout, remains unchanged.
1: https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/
2: https://codasip.com/solutions/riscv-processor-safety-security/cheri/
---
Src/mem.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/Src/mem.c b/Src/mem.c
index 0b6f76e46b2b..5d9ba7d280a5 100644
--- a/Src/mem.c
+++ b/Src/mem.c
@@ -113,6 +113,7 @@ static int h_m[1025], h_push, h_pop, h_free;
union mem_align {
zlong l;
double d;
+ void *p;
};
#define H_ISIZE sizeof(union mem_align)
--
2.56.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author