Subversion Repositories Kolibri OS

Rev

Rev 1635 | Rev 2138 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1635 Rev 2130
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 1615 $
8
$Revision: 2130 $
9
 
9
 
10
 
10
 
Line 149... Line 149...
149
           mov [mem_block_mask], eax
149
           mov [mem_block_mask], eax
150
           mov [mem_block_mask+4],0x80000000
150
           mov [mem_block_mask+4],0x80000000
Line 151... Line 151...
151
 
151
 
152
           mov [mem_block_list+63*4], ebx
152
           mov [mem_block_list+63*4], ebx
153
           mov byte [mem_block_map], 0xFC
153
           mov byte [mem_block_map], 0xFC
-
 
154
           mov ecx, heap_mutex
154
           and [heap_mutex], 0
155
           call mutex_init
155
           mov [heap_blocks], 4095
156
           mov [heap_blocks], 4095
156
           mov [free_blocks], 4094
157
           mov [free_blocks], 4094
157
           ret
158
           ret
Line 270... Line 271...
270
 
271
 
271
           push ebx
272
           push ebx
272
           push esi
273
           push esi
Line -... Line 274...
-
 
274
           push edi
-
 
275
 
-
 
276
           mov ecx, heap_mutex
273
           push edi
277
           call mutex_lock
274
 
278
 
275
           mov eax, [size]
279
           mov eax, [size]
276
           add eax, 4095
280
           add eax, 4095
Line 277... Line -...
277
           and eax, not 4095
-
 
278
           mov [size], eax
-
 
279
 
-
 
280
           mov ebx, heap_mutex
281
           and eax, not 4095
281
           call wait_mutex    ;ebx
282
           mov [size], eax
Line 282... Line 283...
282
 
283
 
283
           cmp eax, [heap_free]
284
           cmp eax, [heap_free]
Line 353... Line 354...
353
           mov [esi+list_bk], ecx
354
           mov [esi+list_bk], ecx
354
           mov [ecx+list_fd], esi
355
           mov [ecx+list_fd], esi
355
           mov [edx+list_bk], esi
356
           mov [edx+list_bk], esi
Line 356... Line 357...
356
 
357
 
357
           mov [esi+block_flags], USED_BLOCK
-
 
358
           mov eax, [esi+block_base]
358
           mov [esi+block_flags], USED_BLOCK
359
           mov ebx, [size]
359
           mov ebx, [size]
360
           sub [heap_free], ebx
360
           sub [heap_free], ebx
-
 
361
           mov ecx, heap_mutex
-
 
362
           call mutex_unlock
361
           and [heap_mutex], 0
363
           mov eax, [esi+block_base]
362
           pop edi
364
           pop edi
363
           pop esi
365
           pop esi
364
           pop ebx
366
           pop ebx
365
           ret
367
           ret
Line 376... Line 378...
376
           mov [edi+list_bk], ecx
378
           mov [edi+list_bk], ecx
377
           mov [ecx+list_fd], edi
379
           mov [ecx+list_fd], edi
378
           mov [edx+list_bk], edi
380
           mov [edx+list_bk], edi
Line 379... Line 381...
379
 
381
 
380
           mov [edi+block_flags], USED_BLOCK
-
 
381
           mov eax, [edi+block_base]
382
           mov [edi+block_flags], USED_BLOCK
382
           mov ebx, [size]
383
           mov ebx, [size]
383
           sub [heap_free], ebx
384
           sub [heap_free], ebx
-
 
385
           mov ecx, heap_mutex
-
 
386
           call mutex_unlock
384
           and [heap_mutex], 0
387
           mov eax, [edi+block_base]
385
           pop edi
388
           pop edi
386
           pop esi
389
           pop esi
387
           pop ebx
390
           pop ebx
388
           ret
391
           ret
-
 
392
.error:
-
 
393
           mov ecx, heap_mutex
389
.error:
394
           call mutex_unlock
390
           xor eax, eax
-
 
391
           mov [heap_mutex], eax
395
           xor eax, eax
392
           pop edi
396
           pop edi
393
           pop esi
397
           pop esi
394
           pop ebx
398
           pop ebx
395
           ret
399
           ret
Line 398... Line 402...
398
align 4
402
align 4
399
proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
403
proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
400
           push ebx
404
           push ebx
401
           push esi
405
           push esi
402
           push edi
406
           push edi
-
 
407
 
403
           mov ebx, heap_mutex
408
           mov ecx, heap_mutex
404
           call wait_mutex    ;ebx
409
           call mutex_lock
Line 405... Line 410...
405
 
410
 
406
           mov eax, [base]
411
           mov eax, [base]
407
           mov esi, [mem_used.fd]
412
           mov esi, [mem_used.fd]
408
@@:
413
@@:
Line 489... Line 494...
489
           jz @f
494
           jz @f
490
           mov [esi+list_bk], edi
495
           mov [esi+list_bk], edi
491
@@:
496
@@:
492
           bts [mem_block_mask], eax
497
           bts [mem_block_mask], eax
493
.m_eq:
498
.m_eq:
-
 
499
           mov ecx, heap_mutex
-
 
500
           call mutex_unlock
494
           xor eax, eax
501
           xor eax, eax
495
           mov [heap_mutex], eax
-
 
496
           dec eax
502
           not eax
497
           pop edi
503
           pop edi
498
           pop esi
504
           pop esi
499
           pop ebx
505
           pop ebx
500
           ret
506
           ret
501
.insert:
507
.insert:
Line 511... Line 517...
511
           jz @f
517
           jz @f
512
           mov [edi+list_bk], esi
518
           mov [edi+list_bk], esi
513
@@:
519
@@:
514
           bts [mem_block_mask], eax
520
           bts [mem_block_mask], eax
515
           mov [esi+block_flags],FREE_BLOCK
521
           mov [esi+block_flags],FREE_BLOCK
-
 
522
           mov ecx, heap_mutex
-
 
523
           call mutex_unlock
516
           xor eax, eax
524
           xor eax, eax
517
           mov [heap_mutex], eax
-
 
518
           dec eax
525
           not eax
519
           pop edi
526
           pop edi
520
           pop esi
527
           pop esi
521
           pop ebx
528
           pop ebx
522
           ret
529
           ret
523
.fail:
530
.fail:
-
 
531
           mov ecx, heap_mutex
-
 
532
           call mutex_unlock
524
           xor eax, eax
533
           xor eax, eax
525
           mov [heap_mutex], eax
-
 
526
           pop edi
534
           pop edi
527
           pop esi
535
           pop esi
528
           pop ebx
536
           pop ebx
529
           ret
537
           ret
530
endp
538
endp
Line 605... Line 613...
605
 
613
 
606
align 4
614
align 4
607
proc kernel_free stdcall, base:dword
615
proc kernel_free stdcall, base:dword
Line 608... Line 616...
608
           push ebx esi
616
           push ebx esi
609
 
617
 
Line 610... Line 618...
610
           mov ebx, heap_mutex
618
           mov ecx, heap_mutex
611
           call wait_mutex    ;ebx
619
           call mutex_lock
612
 
620
 
613
           mov eax, [base]
621
           mov eax, [base]
Line 622... Line 630...
622
           jmp @b
630
           jmp @b
623
.found:
631
.found:
624
           cmp [esi+block_flags], USED_BLOCK
632
           cmp [esi+block_flags], USED_BLOCK
625
           jne .fail
633
           jne .fail
Line 626... Line 634...
626
 
634
 
Line 627... Line -...
627
           and [heap_mutex], 0
-
 
628
 
635
           call mutex_unlock
629
           push ecx
636
 
630
           mov ecx, [esi+block_size];
637
           mov ecx, [esi+block_size];
631
           shr ecx, 12
-
 
632
           call release_pages   ;eax, ecx
638
           shr ecx, 12
633
           pop ecx
639
           call release_pages   ;eax, ecx
634
           stdcall free_kernel_space, [base]
640
           stdcall free_kernel_space, [base]
635
           pop esi ebx
641
           pop esi ebx
-
 
642
           ret
636
           ret
643
.fail:
637
.fail:
-
 
638
           xor eax, eax
644
           call mutex_unlock
639
           mov [heap_mutex], eax
645
           xor eax, eax
640
           pop esi ebx
646
           pop esi ebx
Line 641... Line 647...
641
           ret
647
           ret