Memory allocation implementation details
[D-BUS internal implementation details]

internals of dbus_malloc() etc. More...

Data Structures

struct  ShutdownClosure
 This struct represents a function to be called on shutdown. More...

Defines

#define GUARD_VALUE   0xdeadbeef
 value stored in guard padding for debugging buffer overrun
#define GUARD_INFO_SIZE   8
 size of the information about the block stored in guard mode
#define GUARD_START_PAD   16
 size of the GUARD_VALUE-filled padding after the header info
#define GUARD_END_PAD   16
 size of the GUARD_VALUE-filled padding at the end of the block
#define GUARD_START_OFFSET   (GUARD_START_PAD + GUARD_INFO_SIZE)
 size of stuff at start of block
#define GUARD_EXTRA_SIZE   (GUARD_START_OFFSET + GUARD_END_PAD)
 total extra size over the requested allocation for guard stuff

Typedefs

typedef ShutdownClosure ShutdownClosure
 Represents a function to be called on shutdown.

Enumerations

enum  BlockSource {
  SOURCE_UNKNOWN, SOURCE_MALLOC, SOURCE_REALLOC, SOURCE_MALLOC_ZERO,
  SOURCE_REALLOC_NULL
}
 Where the block came from.

Functions

dbus_bool_t _dbus_disable_mem_pools (void)
 Whether to turn off mem pools, useful for leak checking.
void _dbus_set_fail_alloc_counter (int until_next_fail)
 Sets the number of allocations until we simulate a failed allocation.
int _dbus_get_fail_alloc_counter (void)
 Gets the number of successful allocs until we'll simulate a failed alloc.
void _dbus_set_fail_alloc_failures (int failures_per_failure)
 Sets how many mallocs to fail when the fail alloc counter reaches 0.
int _dbus_get_fail_alloc_failures (void)
 Gets the number of failures we'll have when the fail malloc counter reaches 0.
dbus_bool_t _dbus_decrement_fail_alloc_counter (void)
 Called when about to alloc some memory; if it returns TRUE, then the allocation should fail.
int _dbus_get_malloc_blocks_outstanding (void)
 Get the number of outstanding malloc()'d blocks.
dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction func, void *data)
 Register a cleanup function to be called exactly once the next time dbus_shutdown() is called.
dbus_bool_t _dbus_memory_test (void)
 Unit test for DBusMemory.

Variables

int _dbus_current_generation = 1
 _dbus_current_generation is used to track each time that dbus_shutdown() is called, so we can reinit things after it's been called.

Detailed Description

internals of dbus_malloc() etc.

Implementation details related to allocating and releasing blocks of memory.


Function Documentation

dbus_bool_t _dbus_decrement_fail_alloc_counter void   ) 
 

Called when about to alloc some memory; if it returns TRUE, then the allocation should fail.

If it returns FALSE, then the allocation should not fail.

Returns:
TRUE if this alloc should fail

Definition at line 244 of file dbus-memory.c.

References _DBUS_INT_MAX, _dbus_print_backtrace(), FALSE, and TRUE.

Referenced by _dbus_mem_pool_alloc(), dbus_malloc(), dbus_malloc0(), and dbus_realloc().

dbus_bool_t _dbus_disable_mem_pools void   ) 
 

Whether to turn off mem pools, useful for leak checking.

Returns:
TRUE if mempools should not be used.

Definition at line 170 of file dbus-memory.c.

Referenced by _dbus_mem_pool_alloc(), and _dbus_mem_pool_dealloc().

int _dbus_get_fail_alloc_counter void   ) 
 

Gets the number of successful allocs until we'll simulate a failed alloc.

Returns:
current counter value

Definition at line 203 of file dbus-memory.c.

Referenced by _dbus_mem_pool_alloc(), and _dbus_test_oom_handling().

int _dbus_get_fail_alloc_failures void   ) 
 

Gets the number of failures we'll have when the fail malloc counter reaches 0.

Returns:
number of failures planned

Definition at line 229 of file dbus-memory.c.

int _dbus_get_malloc_blocks_outstanding void   ) 
 

Get the number of outstanding malloc()'d blocks.

Returns:
number of blocks

Definition at line 284 of file dbus-memory.c.

dbus_bool_t _dbus_memory_test void   ) 
 

Unit test for DBusMemory.

Returns:
TRUE on success.

Definition at line 784 of file dbus-memory.c.

References _dbus_assert_not_reached, dbus_malloc(), dbus_realloc(), NULL, and TRUE.

dbus_bool_t _dbus_register_shutdown_func DBusShutdownFunction  func,
void *  data
 

Register a cleanup function to be called exactly once the next time dbus_shutdown() is called.

Parameters:
func the function
data data to pass to the function
Returns:
FALSE on not enough memory

Definition at line 711 of file dbus-memory.c.

References _DBUS_LOCK, _DBUS_UNLOCK, ShutdownClosure::data, dbus_new, FALSE, ShutdownClosure::func, ShutdownClosure::next, NULL, and TRUE.

void _dbus_set_fail_alloc_counter int  until_next_fail  ) 
 

Sets the number of allocations until we simulate a failed allocation.

If set to 0, the next allocation to run fails; if set to 1, one succeeds then the next fails; etc. Set to _DBUS_INT_MAX to not fail anything.

Parameters:
until_next_fail number of successful allocs before one fails

Definition at line 185 of file dbus-memory.c.

Referenced by _dbus_mem_pool_alloc(), and _dbus_test_oom_handling().

void _dbus_set_fail_alloc_failures int  failures_per_failure  ) 
 

Sets how many mallocs to fail when the fail alloc counter reaches 0.

Parameters:
failures_per_failure number to fail

Definition at line 217 of file dbus-memory.c.

Referenced by _dbus_test_oom_handling().


Variable Documentation

int _dbus_current_generation = 1
 

_dbus_current_generation is used to track each time that dbus_shutdown() is called, so we can reinit things after it's been called.

It is simply incremented each time we shut down.

Definition at line 682 of file dbus-memory.c.

Referenced by _dbus_connection_new_for_transport(), _dbus_connection_ref_unlocked(), dbus_connection_close(), dbus_connection_ref(), dbus_connection_unref(), dbus_message_ref(), dbus_message_unref(), and dbus_threads_init().


Generated on Tue Jul 7 15:14:02 2009 for D-BUS by  doxygen 1.4.6