code: drawterm

Download patch

ref: e3a4e2d595c94744e71667c64d4497c9fab9ae0d
parent: b2e55f09f7dab23b49b186d90d89463696945505
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue May 9 18:19:58 EDT 2017

allocate 2 ulongs for secalloc() to keep it 8 byte aligned (use first ulong for magic constant)

on sparc64, secalloc needs to return 8 byte aligned pointer,
so we allocate two ulongs instead of one and use the first
one for the magic constant 0x5ECA110C.

--- a/kern/alloc.c
+++ b/kern/alloc.c
@@ -16,12 +16,17 @@
 	return mallocz(n, 1);
 }
 
+enum {
+	SECMAGIC = 0x5ECA110C,
+};
+
 void*
 secalloc(ulong n)
 {
-	void *p = mallocz(n+sizeof(ulong), 1);
-	*(ulong*)p = n;
-	return (ulong*)p+1;
+	void *p = mallocz(n+sizeof(ulong)*2, 1);
+	((ulong*)p)[0] = SECMAGIC;
+	((ulong*)p)[1] = n;
+	return (ulong*)p+2;
 }
 
 void
@@ -28,7 +33,8 @@
 secfree(void *p)
 {
 	if(p != nil){
+		assert(((ulong*)p)[-2] == SECMAGIC);
 		memset(p, 0, ((ulong*)p)[-1]);
-		free((ulong*)p-1);
+		free((ulong*)p-2);
 	}
 }