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
1616 return mallocz(n, 1);
1717 }
1818
19+enum {
20+ SECMAGIC = 0x5ECA110C,
21+};
22+
1923 void*
2024 secalloc(ulong n)
2125 {
22− void *p = mallocz(n+sizeof(ulong), 1);
23− *(ulong*)p = n;
24− return (ulong*)p+1;
26+ void *p = mallocz(n+sizeof(ulong)*2, 1);
27+ ((ulong*)p)[0] = SECMAGIC;
28+ ((ulong*)p)[1] = n;
29+ return (ulong*)p+2;
2530 }
2631
2732 void
2833 secfree(void *p)
2934 {
3035 if(p != nil){
36+ assert(((ulong*)p)[-2] == SECMAGIC);
3137 memset(p, 0, ((ulong*)p)[-1]);
32− free((ulong*)p-1);
38+ free((ulong*)p-2);
3339 }
3440 }

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