tor  0.4.2.1-alpha-dev
Macros | Typedefs | Functions
memarea.h File Reference
#include <stddef.h>

Go to the source code of this file.

Macros

#define memarea_drop_all(area)
 

Typedefs

typedef struct memarea_t memarea_t
 

Functions

memarea_tmemarea_new (void)
 
void memarea_drop_all_ (memarea_t *area)
 
void memarea_clear (memarea_t *area)
 
int memarea_owns_ptr (const memarea_t *area, const void *ptr)
 
void * memarea_alloc (memarea_t *area, size_t sz)
 
void * memarea_alloc_zero (memarea_t *area, size_t sz)
 
void * memarea_memdup (memarea_t *area, const void *s, size_t n)
 
char * memarea_strdup (memarea_t *area, const char *s)
 
char * memarea_strndup (memarea_t *area, const char *s, size_t n)
 
void memarea_get_stats (memarea_t *area, size_t *allocated_out, size_t *used_out)
 
void memarea_assert_ok (memarea_t *area)
 

Detailed Description

Header for memarea.c.

Definition in file memarea.h.

Macro Definition Documentation

◆ memarea_drop_all

#define memarea_drop_all (   area)
Value:
do { \
memarea_drop_all_(area); \
(area) = NULL; \
} while (0)

Definition at line 19 of file memarea.h.

Function Documentation

◆ memarea_alloc()

void* memarea_alloc ( memarea_t area,
size_t  sz 
)

Return a pointer to a chunk of memory in area of at least sz bytes. sz should be significantly smaller than the area's chunk size, though we can deal if it isn't.

Definition at line 209 of file memarea.c.

References alloc_chunk(), CHECK_SENTINEL, CHUNK_HEADER_SIZE, CHUNK_SIZE, memarea_t::first, memarea_chunk_t::mem_size, memarea_chunk_t::next_chunk, memarea_chunk_t::next_mem, realign_pointer(), SIZE_T_CEILING, and tor_assert().

Referenced by cdline_linecpy(), consensus_split_lines(), memarea_alloc_zero(), memarea_memdup(), memarea_strndup(), and storage_dir_save_labeled_to_file().

◆ memarea_alloc_zero()

void* memarea_alloc_zero ( memarea_t area,
size_t  sz 
)

As memarea_alloc(), but clears the memory it returns.

Definition at line 248 of file memarea.c.

References memarea_alloc().

◆ memarea_assert_ok()

void memarea_assert_ok ( memarea_t area)

◆ memarea_clear()

void memarea_clear ( memarea_t area)

Forget about having allocated anything in area, and free some of the backing storage associated with it, as appropriate. Invalidates all pointers returned from memarea_alloc() for this area.

Definition at line 178 of file memarea.c.

References memarea_t::first, memarea_chunk_free_unchecked(), memarea_chunk_t::next_chunk, and memarea_chunk_t::next_mem.

Referenced by rend_parse_client_keys().

◆ memarea_drop_all_()

void memarea_drop_all_ ( memarea_t area)

Free area, invalidating all pointers returned from memarea_alloc() and friends for this area

Definition at line 163 of file memarea.c.

References memarea_t::first, memarea_chunk_free_unchecked(), memarea_chunk_t::next_chunk, and tor_free.

◆ memarea_get_stats()

void memarea_get_stats ( memarea_t area,
size_t *  allocated_out,
size_t *  used_out 
)

Set allocated_out to the number of bytes allocated in area, and used_out to the number of bytes currently used.

Definition at line 289 of file memarea.c.

References CHECK_SENTINEL, CHUNK_HEADER_SIZE, memarea_t::first, memarea_chunk_t::mem_size, memarea_chunk_t::next_chunk, memarea_chunk_t::next_mem, and tor_assert().

◆ memarea_memdup()

void* memarea_memdup ( memarea_t area,
const void *  s,
size_t  n 
)

As memdup, but returns the memory from area.

Definition at line 257 of file memarea.c.

References memarea_alloc().

Referenced by cdline_linecpy(), and memarea_strdup().

◆ memarea_new()

memarea_t* memarea_new ( void  )

Allocate and return new memarea.

Definition at line 153 of file memarea.c.

Referenced by consensus_diff_apply(), rend_parse_client_keys(), router_parse_entry_from_string(), and storage_dir_save_labeled_to_file().

◆ memarea_owns_ptr()

int memarea_owns_ptr ( const memarea_t area,
const void *  p 
)

Return true iff p is in a range that has been returned by an allocation from area.

Definition at line 194 of file memarea.c.

References memarea_t::first, and memarea_chunk_t::next_chunk.

◆ memarea_strdup()

char* memarea_strdup ( memarea_t area,
const char *  s 
)

As strdup, but returns the memory from area.

Definition at line 266 of file memarea.c.

References memarea_memdup().

◆ memarea_strndup()

char* memarea_strndup ( memarea_t area,
const char *  s,
size_t  n 
)

As strndup, but returns the memory from area.

Definition at line 273 of file memarea.c.

References memarea_alloc(), SIZE_T_CEILING, and tor_assert().

Referenced by get_token_arguments().