diff options
author | hunt <hunt> | 2005-03-09 21:30:05 +0000 |
---|---|---|
committer | hunt <hunt> | 2005-03-09 21:30:05 +0000 |
commit | 204b456c7c08bc40ffe1f21575461d92a544e92b (patch) | |
tree | d4eeb73b11437d723be1e91e0a431f2bd3bed025 /runtime/alloc.h | |
parent | 67b4cc78da121e708a21e96786cb373201e4f6ff (diff) | |
download | systemtap-steved-204b456c7c08bc40ffe1f21575461d92a544e92b.tar.gz systemtap-steved-204b456c7c08bc40ffe1f21575461d92a544e92b.tar.xz systemtap-steved-204b456c7c08bc40ffe1f21575461d92a544e92b.zip |
Initial runtime checkin.
Diffstat (limited to 'runtime/alloc.h')
-rw-r--r-- | runtime/alloc.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/runtime/alloc.h b/runtime/alloc.h new file mode 100644 index 00000000..13bd6766 --- /dev/null +++ b/runtime/alloc.h @@ -0,0 +1,71 @@ +enum errorcode { ERR_NONE=0, ERR_NO_MEM }; +enum errorcode _stp_error = ERR_NONE; + +/** Allocates memory within a probe. + * This is used for small allocations from within a running + * probe where the process cannot sleep. + * @param len Number of bytes to allocate. + * @return a valid pointer on success or NULL on failure. + * @bug Currently uses kmalloc (GFP_ATOMIC). + */ + +inline void *_stp_alloc(size_t len) +{ + void *ptr = kmalloc(len, GFP_ATOMIC); + if (ptr == NULL) + _stp_error = ERR_NO_MEM; + return ptr; +} + +/** Allocates and clears memory within a probe. + * This is used for small allocations from within a running + * probe where the process cannot sleep. + * @param len Number of bytes to allocate. + * @return a valid pointer on success or NULL on failure. + * @bug Currently uses kmalloc (GFP_ATOMIC). + */ + +inline void *_stp_calloc(size_t len) +{ + void *ptr = _stp_alloc(len); + if (ptr) + memset(ptr, 0, len); + return ptr; +} + +/** Allocates and clears memory outside a probe. + * This is typically used in the module initialization to + * allocate new maps, lists, etc. + * @param len Number of bytes to allocate. + * @return a valid pointer on success or NULL on failure. + */ + +inline void *_stp_valloc(size_t len) +{ + void *ptr = vmalloc(len); + if (ptr) + memset(ptr, 0, len); + else + _stp_error = ERR_NO_MEM; + return ptr; +} + +/** Frees memory allocated by _stp_alloc or _stp_calloc. + * @param ptr pointer to memory to free + */ + +inline void _stp_free(void *ptr) +{ + if (ptr) + kfree(ptr); +} + +/** Frees memory allocated by _stp_valloc. + * @param ptr pointer to memory to free + */ + +inline void _stp_vfree(void *ptr) +{ + if (ptr) + vfree(ptr); +} |