From 41b9d8be8da58769f9f4b9cf662994ece9a7cc6d Mon Sep 17 00:00:00 2001 From: "Alexey Teplov (" Date: Tue, 13 Oct 2009 06:47:08 +0000 Subject: [PATCH] insert a 'align 4' git-svn-id: svn://kolibrios.org@1210 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/malloc.inc | 70 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/kernel/trunk/core/malloc.inc b/kernel/trunk/core/malloc.inc index 0b9bfd3b8b..0f38be7ef8 100644 --- a/kernel/trunk/core/malloc.inc +++ b/kernel/trunk/core/malloc.inc @@ -20,6 +20,7 @@ $Revision$ ; esi= nb ; ebx= idx ; +align 4 malloc: push esi @@ -68,6 +69,7 @@ malloc: jne @F btr [mst.smallmap], ebx +align 4 @@: ; B->fd = F; @@ -90,10 +92,12 @@ malloc: pop edi pop ebp +align 4 .done: pop esi mov [mst.mutex], 0 ret +align 4 .split: lea ebx, [edx+8] ;ebx=mem @@ -135,12 +139,16 @@ malloc: mov eax, ebx pop esi ret +align 4 .small: ; if (ms.treemap != 0 && (mem = malloc_small(nb)) != 0) - - cmp [mst.treemap], 0 - je .from_top +;;;;;;;;;;; start a change + mov eax,[mst.treemap] + test eax,eax +;;;;;;;;;;; end the change +; cmp [mst.treemap], 0 + jz .from_top mov eax, esi call malloc_small test eax, eax @@ -148,6 +156,7 @@ malloc: pop esi and [mst.mutex], 0 ret +align 4 .large: ; if (ms.treemap != 0 && (mem = malloc_large(nb)) != 0) @@ -158,6 +167,7 @@ malloc: call malloc_large ;esi= nb test eax, eax jne .done +align 4 .from_top: ; if (nb < ms.topsize) @@ -187,6 +197,7 @@ malloc: pop esi and [mst.mutex], 0 ret +align 4 .fail: xor eax, eax pop esi @@ -247,13 +258,16 @@ free: cmp eax, edx jne @F and [mst.smallmap], ecx +align 4 @@: mov [eax+12], edx ;F->bk = B; mov [edx+8], eax ;B->fd = F jmp .next +align 4 .unlink_large: mov edx, edi call unlink_large_chunk +align 4 .next: ; if(next->head & PINUSE_BIT) @@ -284,12 +298,15 @@ free: or eax, 1 mov [mst.top], edi mov [edi+4], eax +align 4 .fail2: and [mst.mutex], 0 pop esi +align 4 .fail: pop edi ret +align 4 @@: ; nsize = next->head & ~INUSE_BITS; @@ -312,6 +329,7 @@ free: mov ecx, eax shr ecx, 3 btr [mst.smallmap], ecx +align 4 @@: mov [edx+12], ebx ;F->bk = B @@ -333,6 +351,7 @@ free: mov ecx, edi pop edi jmp insert_chunk +align 4 .unl_large: ; unlink_large_chunk((tchunkptr)next); @@ -356,6 +375,7 @@ free: mov ecx, edi pop edi jmp insert_chunk +align 4 .fix_next: ; (p+psize)->prev_foot = psize; @@ -409,6 +429,7 @@ insert_chunk: pop esi and [mst.mutex], 0 ret +align 4 .large: mov ebx, eax call insert_large_chunk @@ -457,6 +478,7 @@ insert_large_chunk: ; *H = X; mov dword [edx], esi jmp .done +align 4 .tree: ; T = *H; @@ -475,7 +497,7 @@ insert_large_chunk: shl eax, cl ;eax= K jmp .loop - +align 4 .not_eq_size: ; C = &(T->child[(K >> 31) & 1]); @@ -492,6 +514,7 @@ insert_large_chunk: ; T = *C; mov edx, edi +align 4 .loop: ; for (;;) @@ -517,11 +540,12 @@ insert_large_chunk: mov [esi+8], eax mov [esi+12], edx ret - +align 4 .insert_child: ; *C = X; mov [ecx], esi +align 4 .done: ; X->parent = T; @@ -549,6 +573,7 @@ unlink_large_chunk: mov [ecx+12], eax ;F->bk = R; mov [eax+8], ecx ;R->fd = F jmp .parent +align 4 @@: mov eax, [edx+20] test eax, eax @@ -560,6 +585,7 @@ unlink_large_chunk: test eax, eax lea esi, [edx+16] je .l2 +align 4 .loop: cmp dword [eax+20], 0 lea ecx, [eax+20] @@ -568,14 +594,18 @@ unlink_large_chunk: cmp dword [eax+16], 0 lea ecx, [eax+16] je .l1 +align 4 @@: mov eax, [ecx] mov esi, ecx jmp .loop +align 4 .l1: mov dword [esi], 0 +align 4 .l2: pop esi +align 4 .parent: test edi, edi je .done @@ -593,17 +623,21 @@ unlink_large_chunk: btr [mst.treemap], ecx pop edi ret +align 4 .l3: cmp [edi+16], edx jne @F mov [edi+16], eax jmp .l4 +align 4 @@: mov [edi+20], eax +align 4 .l4: test eax, eax je .done +align 4 .l5: mov [eax+24], edi mov ecx, [edx+16] @@ -612,6 +646,7 @@ unlink_large_chunk: mov [eax+16], ecx mov [ecx+24], eax +align 4 .l6: mov edx, [edx+20] test edx, edx @@ -619,6 +654,7 @@ unlink_large_chunk: mov [eax+20], edx mov [edx+24], eax +align 4 .done: pop edi ret @@ -641,8 +677,10 @@ malloc_small: mov edi, [ecx+4] and edi, -4 sub edi, esi +align 4 .loop: mov ebx, ecx +align 4 .loop_1: ; while ((t = leftmost_child(t)) != 0) @@ -652,8 +690,10 @@ malloc_small: jz @F mov ecx, eax jmp .l1 +align 4 @@: mov ecx, [ecx+20] +align 4 .l1: test ecx, ecx jz .unlink @@ -704,6 +744,7 @@ malloc_small: lea eax, [ebx+8] ret +align 4 .split: ; v->head = nb|PINUSE_BIT|CINUSE_BIT; @@ -736,6 +777,7 @@ malloc_small: pop ebp lea eax, [ebx+8] ret +align 4 .large: lea eax, [ebx+8] push eax @@ -789,17 +831,20 @@ malloc_large: jne @F xor ecx, ecx jmp .l1 +align 4 @@: mov edx, ecx shr edx, 1 mov ecx, 37 sub ecx, edx +align 4 .l1: mov edx, ebx shl edx, cl ; rst = 0; mov [.rst], ebp +align 4 .loop: ; trem = (t->head & ~INUSE_BITS) - nb; @@ -819,6 +864,7 @@ malloc_large: mov ebp, eax mov edi, ecx je .l2 +align 4 @@: ; rt = t->child[1]; @@ -840,6 +886,7 @@ malloc_large: ; rst = rt; mov [.rst], ecx +align 4 @@: ; if (t == 0) @@ -850,9 +897,11 @@ malloc_large: add edx, edx jmp .loop +align 4 @@: ; t = rst; mov eax, [.rst] +align 4 .l2: ; if (t == 0 && v == 0) @@ -861,6 +910,7 @@ malloc_large: test ebp, ebp jne .l7 mov ecx, [.idx] +align 4 .l3: ; leftbits = (-1<head & ~INUSE_BITS) - nb; @@ -896,6 +948,7 @@ malloc_large: mov edi, ecx ; v = t; mov ebp, eax +align 4 @@: ; t = leftmost_child(t); @@ -905,20 +958,24 @@ malloc_large: je @F mov eax, ecx jmp .l6 +align 4 @@: mov eax, [eax+20] +align 4 .l6: ; while (t != 0) test eax, eax jne .l4 +align 4 .l5: ; if (v != 0) test ebp, ebp jz .done +align 4 .l7: ; r = chunk_plus_offset((mchunkptr)v, nb); @@ -949,6 +1006,7 @@ malloc_large: pop edi pop ebp ret +align 4 .large: ; v->head = nb|PINUSE_BIT|CINUSE_BIT; @@ -973,6 +1031,7 @@ malloc_large: pop edi pop ebp ret +align 4 .done: add esp, 8 pop edi @@ -989,6 +1048,7 @@ init_malloc: mov [mst.topsize], 128*1024 mov dword [eax+4], (128*1024) or 1 mov eax, mst.smallbins +align 4 @@: mov [eax+8], eax mov [eax+12], eax