This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct s_heap { | |
struct s_heap *prev; | |
struct s_heap *next; | |
t_heap_group group; | |
size_t total_size; | |
size_t free_size; | |
size_t block_count; | |
} t_heap; | |
typedef struct s_block { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export DYLD_LIBRARY_PATH=. | |
export DYLD_INSERT_LIBRARIES=libft_malloc.so | |
export DYLD_FORCE_FLAT_NAMESPACE=1 | |
$@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define HEAP_SHIFT(start) ((void *)start + sizeof(t_heap)) | |
#define BLOCK_SHIFT(start) ((void *)start + sizeof(t_block)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define TINY_HEAP_ALLOCATION_SIZE (4 * getpagesize()) | |
#define TINY_BLOCK_SIZE (TINY_HEAP_ALLOCATION_SIZE / 128) | |
#define SMALL_HEAP_ALLOCATION_SIZE (16 * getpagesize()) | |
#define SMALL_BLOCK_SIZE (SMALL_HEAP_ALLOCATION_SIZE / 128) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void *heap = (t_heap *)mmap(NULL, heap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
munmap(heap, heap->total_size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char build_msg(const char msg, size_t msg_len, size_t formatted_msg_len, bool is_little_endian) | |
{ | |
unsigned char formatted_msg; | |
size_t cursor; | |
if (!(formatted_msg = malloc(formatted_msg_len))) | |
return (NULL); | |
ft_memcpy(formatted_msg, msg, msg_len); | |
formatted_msg[msg_len] = 0b10000000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DEC(x) (x - 1) | |
// Chunks of 512 bits | |
#define MD5_CHUNK_SIZE 64 | |
// +1 for the appended '1' | |
// +8 for the size in 64 bits | |
#define MD5_CHUNKS_SIZE(len) (len + 1 + 8 + DEC(MD5_CHUNK_SIZE)) & ~DEC(MD5_CHUNK_SIZE) | |
#define MD5_CHUNK_COUNT(len) (MD5_CHUNKS_SIZE(len) / MD5_CHUNK_SIZE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint64_t ft_bswap_uint64(uint64_t x) | |
{ | |
x = ((x << 8) & 0xFF00FF00FF00FF00ULL ) | ((x >> 8) & 0x00FF00FF00FF00FFULL ); | |
x = ((x << 16) & 0xFFFF0000FFFF0000ULL ) | ((x >> 16) & 0x0000FFFF0000FFFFULL ); | |
return (x << 32) | (x >> 32); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char build_hash(uint32_t buffers, size_t buffer_count, bool is_little_endian) | |
{ | |
char hash; | |
char hash_tmp; | |
size_t buffer_i; | |
uint32_t buffer; | |
buffer_i = 0; | |
if (!(hash = ft_strnew(buffer_count 8))) | |
return (NULL); |
OlderNewer