Skip to content

Commit d10aec5

Browse files
committed
Add documentation of mambo API used in exercise 2
The following functions are documented: --------------------------------------- In api/plugin_support.h: ------------------------ mambo_alloc mambo_free mambo_set_plugin_data mambo_get_plugin_data mambo_set_thread_plugin_data mambo_get_thread_plugin_data mambo_get_source_addr mambo_get_thread_id get_symbol_info_by_addr In api/hash_table.h: -------------------- mambo_ht_init mambo_ht_add mambo_ht_get
1 parent 5748b2a commit d10aec5

File tree

2 files changed

+115
-7
lines changed

2 files changed

+115
-7
lines changed

api/hash_table.h

+43-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
limitations under the License.
1818
*/
1919

20+
/**
21+
* @file hash_table.h
22+
*/
23+
2024
#ifndef __MAMBO_HASH_TABLE_H__
2125
#define __MAMBO_HASH_TABLE_H__
2226

@@ -43,19 +47,51 @@ typedef struct {
4347
} mambo_ht_t;
4448

4549
/**
46-
* @brief Initialises a hash-table with specific configuration.
50+
* @brief Initialises a pre-allocated hash-table.
51+
*
52+
* @pre @c index_shift must be within the range [0, 20].
53+
* @pre @c fill_factor must be within the range [10, 90].
4754
*
48-
* Initialises a hash-table
49-
*
50-
* @pre @c ctx->thread_data must not be @c NULL.
51-
*
52-
* @param ctx The context that holds the plugin state.
53-
* @return The id of the calling thread.
55+
* @param ht The hash-table to be initialised.
56+
* @param initial_size The initial size of the hash-table. Will be round up to a
57+
* power of 2.
58+
* @param index_shift How many times a key is shifted to determine the index in
59+
* the hash-table where the value belongs.
60+
* @param fill_factor The percentage of elements relative to the hash-table's
61+
* size that must be filled, to trigger a hash-table resize.
62+
* @param allow_resize If true, the hash-table will automatically resize when
63+
* resize threshold is reached.
64+
* @return Error code of the hash-table initialisation ( @c 0 for success ).
5465
*/
5566
int mambo_ht_init(mambo_ht_t *ht, size_t initial_size, int index_shift, int fill_factor, bool allow_resize);
5667
int mambo_ht_add_nolock(mambo_ht_t *ht, uintptr_t key, uintptr_t value);
68+
69+
/**
70+
* @brief Atomically adds a key-value pair to a hash-table.
71+
*
72+
* @pre @c key must be greater than 0.
73+
*
74+
* @param ht The hash-table to add the key-value pair.
75+
* @param key The key of the key-value pair.
76+
* @param value The value of the key-value pair.
77+
* @return 0 on success or -1 on error.
78+
*/
5779
int mambo_ht_add(mambo_ht_t *ht, uintptr_t key, uintptr_t value);
5880
int mambo_ht_get_nolock(mambo_ht_t *ht, uintptr_t key, uintptr_t *value);
81+
82+
/**
83+
* @brief Atomically returns a value from a key-value pair stored in a
84+
* hash-table.
85+
*
86+
* @pre @c key must be greater than 0.
87+
* @pre @c value must not be NULL.
88+
*
89+
* @param ht The hash-table to retrieve the value from.
90+
* @param key The key used to locate the value within the hash-table.
91+
* @param value Pointer to the address where the value will be stored after this
92+
* call. Unchanged on error.
93+
* @return 0 on success or -1 on error.
94+
*/
5995
int mambo_ht_get(mambo_ht_t *ht, uintptr_t key, uintptr_t *value);
6096

6197
#endif

api/plugin_support.h

+72
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,70 @@ int mambo_register_function_cb(mambo_context *ctx, char *fn_name,
219219
mambo_callback cb_pre, mambo_callback cb_post, int max_args);
220220

221221
/* Memory management */
222+
/**
223+
* @brief A wrapper of mmap to allocate memory space optimised to support the
224+
* DBM use case.
225+
*
226+
* An mmap wrapper that allocates private to MAMBO memory space with read/write
227+
* permissions.
228+
*
229+
* @param ctx The context that holds the plugin state. Currently unused.
230+
* @param size The allocation size requested. Will round up to a multiple of
231+
* page size due to calling mmap.
232+
* @return Pointer to the mapped area or @c (void*)-1 on error.
233+
*/
222234
void *mambo_alloc(mambo_context *ctx, size_t size);
235+
236+
/**
237+
* @brief Frees memory space pointed by @c ptr which must have been returned by a
238+
* previous call to mambo_alloc.
239+
*
240+
* Currently this function is just and empty wrapper.
241+
*
242+
* @param ctx The context that holds the plugin state. Currently unused.
243+
* @param ptr Pointer to memory space requested for freeing. Currently unused.
244+
*/
223245
void mambo_free(mambo_context *ctx, void *ptr);
224246

225247
/* Access plugin data */
248+
/**
249+
* @brief Stores an address holding data to a global structure, making data
250+
* accessible between callbacks of all threads running in MAMBO.
251+
*
252+
* @param ctx The context that holds the plugin state.
253+
* @param data Pointer to the address where data will be stored.
254+
* @return MAMBO_SUCCESS on success or MAMBO_INVALID_PLUGIN_ID on error.
255+
*/
226256
int mambo_set_plugin_data(mambo_context *ctx, void *data);
257+
258+
/**
259+
* @brief Retrieves an address holding data from a global structure accessible
260+
* between callbacks of all threads running in MAMBO.
261+
*
262+
* @param ctx The context that holds the plugin state.
263+
* @return Pointer to the address holding the data.
264+
*/
227265
void *mambo_get_plugin_data(mambo_context *ctx);
266+
267+
/**
268+
* @brief Stores an address holding data to a structure allocated in the calling
269+
* thread, making data accessible between callbacks of that thread running in
270+
* MAMBO.
271+
*
272+
* @param ctx The context that holds the plugin state.
273+
* @param data Pointer to the address where data will be stored.
274+
* @return MAMBO_SUCCESS on success, or MAMBO_INVALID_PLUGIN_ID or
275+
* MAMBO_INVALID_THREAD on error.
276+
*/
228277
int mambo_set_thread_plugin_data(mambo_context *ctx, void *data);
278+
279+
/**
280+
* @brief Retrieves an address holding data to a structure allocated in the
281+
* calling thread, accessible between its callbacks running in MAMBO.
282+
*
283+
* @param ctx The context that holds the plugin state.
284+
* @return Pointer to the address holding the data.
285+
*/
229286
void *mambo_get_thread_plugin_data(mambo_context *ctx);
230287

231288
/* Scratch register management */
@@ -298,6 +355,21 @@ int mambo_reserve_cc_space(mambo_context *ctx, size_t size);
298355
mambo_branch_type mambo_get_branch_type(mambo_context *ctx);
299356

300357
/* Symbol-related functions */
358+
359+
/**
360+
* @brief Uses the untranslated address of the application's instruction to
361+
* return the symbol name, the starting address of the symbol name and the
362+
* filename that this instruction belongs to.
363+
*
364+
* @param addr The untranslated address of the application's instruction.
365+
* @param sym_name Pointer to the pointer to the address where the symbol name
366+
* will be stored.
367+
* @param start_addr Pointer to the pointer to the address where the starting
368+
* address of the symbol name will be stored.
369+
* @param filename Pointer to the pointer to the address where the filename will
370+
* be stored.
371+
* @return 0 on success or -1 on error.
372+
*/
301373
int get_symbol_info_by_addr(uintptr_t addr, char **sym_name, void **start_addr, char **filename);
302374
typedef int (*stack_frame_handler)(void *data, void *addr, char *sym_name, void *symbol_start_addr, char *filename);
303375
int get_backtrace(stack_frame_t *fp, stack_frame_handler handler, void *ptr);

0 commit comments

Comments
 (0)