summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/alloc_8h-source.html
blob: 551deccd221a2f4771fc8d49824ee44752858b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SystemTap: alloc.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>alloc.h</h1><a href="alloc_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/* -*- linux-c -*- */</span><span class="comment"></span>
00002 <span class="comment">/** @file alloc.h</span>
00003 <span class="comment"> * @brief Memory allocation functions.</span>
00004 <span class="comment"> * @todo Should really be alloc.c for consistency.</span>
00005 <span class="comment"> */</span>
00006 
00007 <span class="keyword">enum</span> errorcode { ERR_NONE=0, ERR_NO_MEM };
00008 <span class="keyword">enum</span> errorcode _stp_error = ERR_NONE;
00009 <span class="comment"></span>
00010 <span class="comment">/** Allocates memory within a probe.</span>
00011 <span class="comment"> * This is used for small allocations from within a running</span>
00012 <span class="comment"> * probe where the process cannot sleep. </span>
00013 <span class="comment"> * @param len Number of bytes to allocate.</span>
00014 <span class="comment"> * @return a valid pointer on success or NULL on failure.</span>
00015 <span class="comment"> * @bug Currently uses kmalloc (GFP_ATOMIC).</span>
00016 <span class="comment"> */</span>
00017 
<a name="l00018"></a><a class="code" href="alloc_8h.html#a3">00018</a> <span class="keywordtype">void</span> *<a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(size_t len)
00019 {
00020         <span class="keywordtype">void</span> *ptr = kmalloc(len, GFP_ATOMIC);
00021         <span class="keywordflow">if</span> (unlikely(ptr == NULL))
00022                 _stp_error = ERR_NO_MEM;
00023         <span class="keywordflow">return</span> ptr;
00024 }
00025 <span class="comment"></span>
00026 <span class="comment">/** Allocates and clears memory within a probe.</span>
00027 <span class="comment"> * This is used for small allocations from within a running</span>
00028 <span class="comment"> * probe where the process cannot sleep. </span>
00029 <span class="comment"> * @param len Number of bytes to allocate.</span>
00030 <span class="comment"> * @return a valid pointer on success or NULL on failure.</span>
00031 <span class="comment"> * @bug Currently uses kmalloc (GFP_ATOMIC).</span>
00032 <span class="comment"> */</span>
00033 
<a name="l00034"></a><a class="code" href="alloc_8h.html#a4">00034</a> <span class="keywordtype">void</span> *<a class="code" href="alloc_8h.html#a4">_stp_calloc</a>(size_t len)
00035 {
00036         <span class="keywordtype">void</span> *ptr = <a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(len);
00037         <span class="keywordflow">if</span> (likely(ptr))
00038                 memset(ptr, 0, len);
00039         <span class="keywordflow">return</span> ptr;
00040 }
00041 <span class="comment"></span>
00042 <span class="comment">/** Allocates and clears memory outside a probe.</span>
00043 <span class="comment"> * This is typically used in the module initialization to</span>
00044 <span class="comment"> * allocate new maps, lists, etc.</span>
00045 <span class="comment"> * @param len Number of bytes to allocate.</span>
00046 <span class="comment"> * @return a valid pointer on success or NULL on failure.</span>
00047 <span class="comment"> */</span>
00048 
<a name="l00049"></a><a class="code" href="alloc_8h.html#a5">00049</a> <span class="keywordtype">void</span> *<a class="code" href="alloc_8h.html#a5">_stp_valloc</a>(size_t len)
00050 {
00051         <span class="keywordtype">void</span> *ptr = vmalloc(len);
00052         <span class="keywordflow">if</span> (likely(ptr))
00053                 memset(ptr, 0, len);
00054         <span class="keywordflow">else</span>
00055                 _stp_error = ERR_NO_MEM;
00056         <span class="keywordflow">return</span> ptr;
00057 }
00058 <span class="comment"></span>
00059 <span class="comment">/** Frees memory allocated by _stp_alloc or _stp_calloc.</span>
00060 <span class="comment"> * @param ptr pointer to memory to free</span>
00061 <span class="comment"> */</span>
00062 
<a name="l00063"></a><a class="code" href="alloc_8h.html#a6">00063</a> <span class="keywordtype">void</span> <a class="code" href="alloc_8h.html#a6">_stp_free</a>(<span class="keywordtype">void</span> *ptr)
00064 {
00065         <span class="keywordflow">if</span> (likely(ptr))
00066                 kfree(ptr);
00067 }
00068 <span class="comment"></span>
00069 <span class="comment">/** Frees memory allocated by _stp_valloc.</span>
00070 <span class="comment"> * @param ptr pointer to memory to free</span>
00071 <span class="comment"> */</span>
00072 
<a name="l00073"></a><a class="code" href="alloc_8h.html#a7">00073</a> <span class="keywordtype">void</span> <a class="code" href="alloc_8h.html#a7">_stp_vfree</a>(<span class="keywordtype">void</span> *ptr)
00074 {
00075         <span class="keywordflow">if</span> (likely(ptr))
00076                 vfree(ptr);
00077 }
</pre></div></body></html>