History

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.

cinap_lenrek committed 9 years ago

Commit e3a4e2d1 parent b2e55f01 file · +10 −4Browse files

Unified · Split

kern/alloc.c+10−4
@@ -16,19 +16,25 @@ malloc(ulong n) · 15 unmodified lines
16 return mallocz(n, 1);16 return mallocz(n, 1);
17}17}
18 18
19enum {
20 SECMAGIC = 0x5ECA110C,
21};
22
19void*23void*
20secalloc(ulong n)24secalloc(ulong n)
21{25{
22 void *p = mallocz(n+sizeof(ulong), 1);26 void *p = mallocz(n+sizeof(ulong)*2, 1);
23 *(ulong*)p = n;27 ((ulong*)p)[0] = SECMAGIC;
24 return (ulong*)p+1;28 ((ulong*)p)[1] = n;
29 return (ulong*)p+2;
25}30}
26 31
27void32void
28secfree(void *p)33secfree(void *p)
29{34{
30 if(p != nil){35 if(p != nil){
36 assert(((ulong*)p)[-2] == SECMAGIC);
31 memset(p, 0, ((ulong*)p)[-1]);37 memset(p, 0, ((ulong*)p)[-1]);
32 free((ulong*)p-1);38 free((ulong*)p-2);
33 }39 }
34}40}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t