Lines Matching refs:sh

319     ((char*)(p) >= sh.arena && (char*)(p) < &sh.arena[sh.arena_size])
321 ((char*)(p) >= (char*)sh.freelist && (char*)(p) < (char*)&sh.freelist[sh.freelist_size])
342 static SH sh; variable
346 ossl_ssize_t list = sh.freelist_size - 1; in sh_getlist()
347 size_t bit = (sh.arena_size + ptr - sh.arena) / sh.minsize; in sh_getlist()
350 if (TESTBIT(sh.bittable, bit)) in sh_getlist()
363 OPENSSL_assert(list >= 0 && list < sh.freelist_size); in sh_testbit()
364 OPENSSL_assert(((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0); in sh_testbit()
365 bit = (ONE << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); in sh_testbit()
366 OPENSSL_assert(bit > 0 && bit < sh.bittable_size); in sh_testbit()
374 OPENSSL_assert(list >= 0 && list < sh.freelist_size); in sh_clearbit()
375 OPENSSL_assert(((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0); in sh_clearbit()
376 bit = (ONE << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); in sh_clearbit()
377 OPENSSL_assert(bit > 0 && bit < sh.bittable_size); in sh_clearbit()
386 OPENSSL_assert(list >= 0 && list < sh.freelist_size); in sh_setbit()
387 OPENSSL_assert(((ptr - sh.arena) & ((sh.arena_size >> list) - 1)) == 0); in sh_setbit()
388 bit = (ONE << list) + ((ptr - sh.arena) / (sh.arena_size >> list)); in sh_setbit()
389 OPENSSL_assert(bit > 0 && bit < sh.bittable_size); in sh_setbit()
441 memset(&sh, 0, sizeof(sh)); in sh_init()
471 sh.arena_size = size; in sh_init()
472 sh.minsize = minsize; in sh_init()
473 sh.bittable_size = (sh.arena_size / sh.minsize) * 2; in sh_init()
476 if (sh.bittable_size >> 3 == 0) in sh_init()
479 sh.freelist_size = -1; in sh_init()
480 for (i = sh.bittable_size; i; i >>= 1) in sh_init()
481 sh.freelist_size++; in sh_init()
483 sh.freelist = OPENSSL_zalloc(sh.freelist_size * sizeof(char *)); in sh_init()
484 OPENSSL_assert(sh.freelist != NULL); in sh_init()
485 if (sh.freelist == NULL) in sh_init()
488 sh.bittable = OPENSSL_zalloc(sh.bittable_size >> 3); in sh_init()
489 OPENSSL_assert(sh.bittable != NULL); in sh_init()
490 if (sh.bittable == NULL) in sh_init()
493 sh.bitmalloc = OPENSSL_zalloc(sh.bittable_size >> 3); in sh_init()
494 OPENSSL_assert(sh.bitmalloc != NULL); in sh_init()
495 if (sh.bitmalloc == NULL) in sh_init()
517 sh.map_size = pgsize + sh.arena_size + pgsize; in sh_init()
521 sh.map_result = mmap(NULL, sh.map_size, in sh_init()
527 sh.map_result = MAP_FAILED; in sh_init()
529 sh.map_result = mmap(NULL, sh.map_size, in sh_init()
535 if (sh.map_result == MAP_FAILED) in sh_init()
538 sh.map_result = VirtualAlloc(NULL, sh.map_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); in sh_init()
540 if (sh.map_result == NULL) in sh_init()
544 sh.arena = (char *)(sh.map_result + pgsize); in sh_init()
545 sh_setbit(sh.arena, 0, sh.bittable); in sh_init()
546 sh_add_to_list(&sh.freelist[0], sh.arena); in sh_init()
553 if (mprotect(sh.map_result, pgsize, PROT_NONE) < 0) in sh_init()
556 if (VirtualProtect(sh.map_result, pgsize, PAGE_NOACCESS, &flOldProtect) == FALSE) in sh_init()
561 aligned = (pgsize + sh.arena_size + (pgsize - 1)) & ~(pgsize - 1); in sh_init()
563 if (mprotect(sh.map_result + aligned, pgsize, PROT_NONE) < 0) in sh_init()
566 if (VirtualProtect(sh.map_result + aligned, pgsize, PAGE_NOACCESS, &flOldProtect) == FALSE) in sh_init()
571 if (syscall(SYS_mlock2, sh.arena, sh.arena_size, MLOCK_ONFAULT) < 0) { in sh_init()
573 if (mlock(sh.arena, sh.arena_size) < 0) in sh_init()
580 if (VirtualLock(sh.arena, sh.arena_size) == FALSE) in sh_init()
583 if (mlock(sh.arena, sh.arena_size) < 0) in sh_init()
587 if (madvise(sh.arena, sh.arena_size, MADV_DONTDUMP) < 0) in sh_init()
600 OPENSSL_free(sh.freelist); in sh_done()
601 OPENSSL_free(sh.bittable); in sh_done()
602 OPENSSL_free(sh.bitmalloc); in sh_done()
604 if (sh.map_result != MAP_FAILED && sh.map_size) in sh_done()
605 munmap(sh.map_result, sh.map_size); in sh_done()
607 if (sh.map_result != NULL && sh.map_size) in sh_done()
608 VirtualFree(sh.map_result, 0, MEM_RELEASE); in sh_done()
610 memset(&sh, 0, sizeof(sh)); in sh_done()
623 bit = (ONE << list) + (ptr - sh.arena) / (sh.arena_size >> list); in sh_find_my_buddy()
626 if (TESTBIT(sh.bittable, bit) && !TESTBIT(sh.bitmalloc, bit)) in sh_find_my_buddy()
627 chunk = sh.arena + ((bit & ((ONE << list) - 1)) * (sh.arena_size >> list)); in sh_find_my_buddy()
638 if (size > sh.arena_size) in sh_malloc()
641 list = sh.freelist_size - 1; in sh_malloc()
642 for (i = sh.minsize; i < size; i <<= 1) in sh_malloc()
649 if (sh.freelist[slist] != NULL) in sh_malloc()
656 char *temp = sh.freelist[slist]; in sh_malloc()
659 OPENSSL_assert(!sh_testbit(temp, slist, sh.bitmalloc)); in sh_malloc()
660 sh_clearbit(temp, slist, sh.bittable); in sh_malloc()
662 OPENSSL_assert(temp != sh.freelist[slist]); in sh_malloc()
668 OPENSSL_assert(!sh_testbit(temp, slist, sh.bitmalloc)); in sh_malloc()
669 sh_setbit(temp, slist, sh.bittable); in sh_malloc()
670 sh_add_to_list(&sh.freelist[slist], temp); in sh_malloc()
671 OPENSSL_assert(sh.freelist[slist] == temp); in sh_malloc()
674 temp += sh.arena_size >> slist; in sh_malloc()
675 OPENSSL_assert(!sh_testbit(temp, slist, sh.bitmalloc)); in sh_malloc()
676 sh_setbit(temp, slist, sh.bittable); in sh_malloc()
677 sh_add_to_list(&sh.freelist[slist], temp); in sh_malloc()
678 OPENSSL_assert(sh.freelist[slist] == temp); in sh_malloc()
680 OPENSSL_assert(temp-(sh.arena_size >> slist) == sh_find_my_buddy(temp, slist)); in sh_malloc()
684 chunk = sh.freelist[list]; in sh_malloc()
685 OPENSSL_assert(sh_testbit(chunk, list, sh.bittable)); in sh_malloc()
686 sh_setbit(chunk, list, sh.bitmalloc); in sh_malloc()
709 OPENSSL_assert(sh_testbit(ptr, list, sh.bittable)); in sh_free()
710 sh_clearbit(ptr, list, sh.bitmalloc); in sh_free()
711 sh_add_to_list(&sh.freelist[list], ptr); in sh_free()
717 OPENSSL_assert(!sh_testbit(ptr, list, sh.bitmalloc)); in sh_free()
718 sh_clearbit(ptr, list, sh.bittable); in sh_free()
720 OPENSSL_assert(!sh_testbit(ptr, list, sh.bitmalloc)); in sh_free()
721 sh_clearbit(buddy, list, sh.bittable); in sh_free()
731 OPENSSL_assert(!sh_testbit(ptr, list, sh.bitmalloc)); in sh_free()
732 sh_setbit(ptr, list, sh.bittable); in sh_free()
733 sh_add_to_list(&sh.freelist[list], ptr); in sh_free()
734 OPENSSL_assert(sh.freelist[list] == ptr); in sh_free()
746 OPENSSL_assert(sh_testbit(ptr, list, sh.bittable)); in sh_actual_size()
747 return sh.arena_size / (ONE << list); in sh_actual_size()