MCPcopy Create free account
hub / github.com/Bananymous/banan-os / aligned_alloc

Function aligned_alloc

userspace/libraries/LibC/malloc.cpp:386–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384
385 memcpy(new_ptr, ptr, BAN::Math::min(old_alloc_size, size));
386
387 free(ptr);
388
389 return new_ptr;
390}
391
392void* calloc(size_t nmemb, size_t size)
393{
394 if (BAN::Math::will_multiplication_overflow(nmemb, size))
395 {
396 errno = ENOMEM;
397 return nullptr;
398 }
399
400 const size_t total = nmemb * size;
401
402 void* ptr = malloc(total);
403 if (ptr == nullptr)
404 return nullptr;
405
406 if (total < s_mmap_threshold)
407 memset(ptr, 0, total);
408 return ptr;
409}
410
411void* reallocarray(void* ptr, size_t nmemb, size_t size)
412{
413 if (BAN::Math::will_multiplication_overflow(nmemb, size))
414 {
415 errno = ENOMEM;
416 return nullptr;
417 }
418
419 return realloc(ptr, nmemb * size);
420}
421
422void* aligned_alloc(size_t alignment, size_t size)
423{

Callers 1

posix_memalignFunction · 0.85

Calls 3

is_power_of_twoFunction · 0.85
mallocFunction · 0.85
mmapFunction · 0.85

Tested by

no test coverage detected