fix: xorg with unit64
This commit is contained in:
parent
c3dbf2030c
commit
40f99b2b4b
|
@ -3,11 +3,5 @@
|
|||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t sz_x = sizeof(int), sz_y = 10, sz_x1 = sizeof(int) * 20;
|
||||
void *x = sf_malloc(sz_x);
|
||||
/* void *y = */ sf_malloc(sz_y);
|
||||
sf_realloc(x, sz_x1);
|
||||
|
||||
sf_show_heap();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -45,14 +45,12 @@ sf_block *get_prev_block(sf_block *block);
|
|||
sf_block *get_next_block(sf_block *block);
|
||||
void remove_list(sf_block *block);
|
||||
sf_size_t get_pow(sf_size_t pow);
|
||||
void xor_with_magic(sf_header *header);
|
||||
void add_payload(int size);
|
||||
|
||||
void *sf_malloc(sf_size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
if (sf_mem_start() == sf_mem_end())
|
||||
if (sf_initialize())
|
||||
return NULL;
|
||||
|
@ -291,16 +289,16 @@ void set_header(sf_block *block, sf_header value)
|
|||
{
|
||||
next->prev_footer = block->header;
|
||||
if ((prv_alloc & (sf_size_t)MAGIC) == 0)
|
||||
next->header = next->header & ~prv_alloc;
|
||||
next->header = next->header & ~((uint64_t)prv_alloc);
|
||||
else
|
||||
next->header = next->header | prv_alloc;
|
||||
next->header = next->header | (uint64_t)prv_alloc;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((prv_alloc & (sf_size_t)MAGIC) == 0)
|
||||
next->header = next->header | prv_alloc;
|
||||
next->header = next->header | (uint64_t)prv_alloc;
|
||||
else
|
||||
next->header = next->header & ~prv_alloc;
|
||||
next->header = next->header & ~((uint64_t)prv_alloc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,13 +333,9 @@ void set_alloc(sf_block *block, sf_size_t is_alloc)
|
|||
sf_header header = block->header ^ MAGIC;
|
||||
sf_header value = header;
|
||||
if (is_alloc)
|
||||
{
|
||||
value |= alloc;
|
||||
}
|
||||
value |= (uint64_t)alloc;
|
||||
else
|
||||
{
|
||||
value &= (~((uint64_t)alloc));
|
||||
}
|
||||
set_header(block, value);
|
||||
}
|
||||
|
||||
|
@ -350,28 +344,19 @@ void set_prv_alloc(sf_block *block, sf_size_t is_prv_allc)
|
|||
sf_header header = block->header ^ MAGIC;
|
||||
sf_header value = header;
|
||||
if (is_prv_allc)
|
||||
{
|
||||
value |= prv_alloc;
|
||||
}
|
||||
value |= (uint64_t)prv_alloc;
|
||||
else
|
||||
{
|
||||
value &= (~((uint64_t)prv_alloc));
|
||||
}
|
||||
set_header(block, value);
|
||||
}
|
||||
|
||||
void set_in_qklst(sf_block *block, sf_size_t is_in_qklst)
|
||||
{
|
||||
sf_header header = block->header ^ MAGIC;
|
||||
sf_header value = header;
|
||||
sf_header value = block->header ^ MAGIC;
|
||||
if (is_in_qklst)
|
||||
{
|
||||
value |= in_qklst;
|
||||
}
|
||||
value |= (uint64_t)in_qklst;
|
||||
else
|
||||
{
|
||||
value &= (~((uint64_t)in_qklst));
|
||||
}
|
||||
set_header(block, value);
|
||||
}
|
||||
|
||||
|
@ -500,9 +485,4 @@ void remove_list(sf_block *block)
|
|||
{
|
||||
block->body.links.next->body.links.prev = block->body.links.prev;
|
||||
block->body.links.prev->body.links.next = block->body.links.next;
|
||||
}
|
||||
|
||||
void xor_with_magic(sf_header *header)
|
||||
{
|
||||
*header ^= MAGIC;
|
||||
}
|
|
@ -254,7 +254,6 @@ Test(sfmm_basecode_suite, realloc_larger_block, .timeout = TEST_TIMEOUT)
|
|||
sf_internal_fragmentation(), 90 / 128.0);
|
||||
cr_assert_eq(sf_peak_utilization(), 90 / 1024.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), 90 / 1024.0);
|
||||
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, realloc_smaller_block_splinter, .timeout = TEST_TIMEOUT)
|
||||
|
@ -279,6 +278,10 @@ Test(sfmm_basecode_suite, realloc_smaller_block_splinter, .timeout = TEST_TIMEOU
|
|||
assert_quick_list_block_count(0, 0);
|
||||
assert_free_block_count(0, 1);
|
||||
assert_free_block_count(880, 1);
|
||||
cr_assert_eq(sf_internal_fragmentation(), 64 / 96.0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), 64 / 96.0);
|
||||
cr_assert_eq(sf_peak_utilization(), 80 / 1024.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), 80 / 1024.0);
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, realloc_smaller_block_free_block, .timeout = TEST_TIMEOUT)
|
||||
|
@ -305,6 +308,10 @@ Test(sfmm_basecode_suite, realloc_smaller_block_free_block, .timeout = TEST_TIME
|
|||
assert_quick_list_block_count(0, 0);
|
||||
assert_free_block_count(0, 1);
|
||||
assert_free_block_count(944, 1);
|
||||
cr_assert_eq(sf_internal_fragmentation(), 4 / 32.0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), 4 / 32.0);
|
||||
cr_assert_eq(sf_peak_utilization(), 64 / 1024.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), 64 / 1024.0);
|
||||
}
|
||||
|
||||
//############################################
|
||||
|
@ -344,6 +351,10 @@ Test(sfmm_basecode_suite, quicklist1, .timeout = TEST_TIMEOUT)
|
|||
cr_assert_eq(&bp->header, (char *)x6 - 8,
|
||||
"Wrong first block in free list %d: (found=%p, exp=%p)",
|
||||
i, &bp->header, (char *)x6 - 8);
|
||||
cr_assert_eq(sf_internal_fragmentation(), 0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), 0);
|
||||
cr_assert_eq(sf_peak_utilization(), 24 / 1024.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), 24 / 1024.0);
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, quicklist2, .timeout = TEST_TIMEOUT)
|
||||
|
@ -372,6 +383,10 @@ Test(sfmm_basecode_suite, quicklist2, .timeout = TEST_TIMEOUT)
|
|||
cr_assert_eq(&bp->header, (char *)x1 - 8,
|
||||
"Wrong first block in free list %d: (found=%p, exp=%p)",
|
||||
i, &bp->header, (char *)x1 - 8);
|
||||
cr_assert_eq(sf_internal_fragmentation(), 0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), 0);
|
||||
cr_assert_eq(sf_peak_utilization(), 20 / 1024.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), 20 / 1024.0);
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, realloc1, .timeout = TEST_TIMEOUT)
|
||||
|
@ -384,6 +399,10 @@ Test(sfmm_basecode_suite, realloc1, .timeout = TEST_TIMEOUT)
|
|||
assert_free_block_count(0, 2);
|
||||
assert_free_block_count(12000, 1);
|
||||
assert_free_block_count(528, 1);
|
||||
cr_assert_eq(sf_internal_fragmentation(), (12000-8)/12000.0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), (12000-8)/12000.0);
|
||||
cr_assert_eq(sf_peak_utilization(), (12000-8) / 24576.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), (12000-8) / 24576.0);
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, realloc2, .timeout = TEST_TIMEOUT)
|
||||
|
@ -402,6 +421,10 @@ Test(sfmm_basecode_suite, realloc2, .timeout = TEST_TIMEOUT)
|
|||
cr_assert_eq(114514, (int)*x3,
|
||||
"Wrong value: (found=%d, exp=%d)",
|
||||
114514, (int)*x3);
|
||||
cr_assert_eq(sf_internal_fragmentation(), (24004)/24048.0, "Wrong number of sf_internal_fragmentation(): (exp=%f, found=%f)",
|
||||
sf_internal_fragmentation(), (24004)/24048.0);
|
||||
cr_assert_eq(sf_peak_utilization(), (24004) / 24576.0, "Wrong number of sf_peak_utilization(): (exp=%f, found=%f)",
|
||||
sf_peak_utilization(), (24004) / 24576.0);
|
||||
}
|
||||
|
||||
Test(sfmm_basecode_suite, freepro, .signal = SIGABRT, .timeout = TEST_TIMEOUT)
|
||||
|
|
Loading…
Reference in New Issue
Block a user