diff options
Diffstat (limited to 'devdocs/gcc~13/bpf-built-in-functions.html')
| -rw-r--r-- | devdocs/gcc~13/bpf-built-in-functions.html | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/devdocs/gcc~13/bpf-built-in-functions.html b/devdocs/gcc~13/bpf-built-in-functions.html new file mode 100644 index 00000000..348d9f2d --- /dev/null +++ b/devdocs/gcc~13/bpf-built-in-functions.html @@ -0,0 +1,57 @@ +<div class="subsection-level-extent" id="BPF-Built-in-Functions"> <div class="nav-panel"> <p> Next: <a href="fr-v-built-in-functions" accesskey="n" rel="next">FR-V Built-in Functions</a>, Previous: <a href="blackfin-built-in-functions" accesskey="p" rel="prev">Blackfin Built-in Functions</a>, Up: <a href="target-builtins" accesskey="u" rel="up">Built-in Functions Specific to Particular Target Machines</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="subsection" id="BPF-Built-in-Functions-1"><span>6.60.12 BPF Built-in Functions<a class="copiable-link" href="#BPF-Built-in-Functions-1"> ¶</a></span></h1> <p>The following built-in functions are available for eBPF targets. </p> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fbuiltin_005fbpf_005fload_005fbyte"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">unsigned long long</code> <strong class="def-name">__builtin_bpf_load_byte</strong> <code class="def-code-arguments">(unsigned long long <var class="var">offset</var>)</code><a class="copiable-link" href="#index-_005f_005fbuiltin_005fbpf_005fload_005fbyte"> ¶</a></span> +</dt> <dd><p>Load a byte from the <code class="code">struct sk_buff</code> packet data pointed by the register <code class="code">%r6</code> and return it. </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fbuiltin_005fbpf_005fload_005fhalf"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">unsigned long long</code> <strong class="def-name">__builtin_bpf_load_half</strong> <code class="def-code-arguments">(unsigned long long <var class="var">offset</var>)</code><a class="copiable-link" href="#index-_005f_005fbuiltin_005fbpf_005fload_005fhalf"> ¶</a></span> +</dt> <dd><p>Load 16 bits from the <code class="code">struct sk_buff</code> packet data pointed by the register <code class="code">%r6</code> and return it. </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fbuiltin_005fbpf_005fload_005fword"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">unsigned long long</code> <strong class="def-name">__builtin_bpf_load_word</strong> <code class="def-code-arguments">(unsigned long long <var class="var">offset</var>)</code><a class="copiable-link" href="#index-_005f_005fbuiltin_005fbpf_005fload_005fword"> ¶</a></span> +</dt> <dd><p>Load 32 bits from the <code class="code">struct sk_buff</code> packet data pointed by the register <code class="code">%r6</code> and return it. </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fbuiltin_005fpreserve_005faccess_005findex"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void *</code> <strong class="def-name">__builtin_preserve_access_index</strong> <code class="def-code-arguments">(<var class="var">expr</var>)</code><a class="copiable-link" href="#index-_005f_005fbuiltin_005fpreserve_005faccess_005findex"> ¶</a></span> +</dt> <dd><p>BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to generate CO-RE relocation records for any accesses to aggregate data structures (struct, union, array types) in <var class="var">expr</var>. This builtin is otherwise transparent, the return value is whatever <var class="var">expr</var> evaluates to. It is also overloaded: <var class="var">expr</var> may be of any type (not necessarily a pointer), the return type is the same. Has no effect if <code class="code">-mco-re</code> is not in effect (either specified or implied). </p></dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fbuiltin_005fpreserve_005ffield_005finfo"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">unsigned int</code> <strong class="def-name">__builtin_preserve_field_info</strong> <code class="def-code-arguments">(<var class="var">expr</var>, unsigned int <var class="var">kind</var>)</code><a class="copiable-link" href="#index-_005f_005fbuiltin_005fpreserve_005ffield_005finfo"> ¶</a></span> +</dt> <dd> +<p>BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to extract information to aid in struct/union relocations. <var class="var">expr</var> is an access to a field of a struct or union. Depending on <var class="var">kind</var>, different information is returned to the program. A CO-RE relocation for the access in <var class="var">expr</var> with kind <var class="var">kind</var> is recorded if <code class="code">-mco-re</code> is in effect. </p> <p>The following values are supported for <var class="var">kind</var>: </p> +<dl class="table"> <dt><code class="code">FIELD_BYTE_OFFSET = 0</code></dt> <dd> +<p>The returned value is the offset, in bytes, of the field from the beginning of the containing structure. For bit-fields, this is the byte offset of the containing word. </p> </dd> <dt><code class="code">FIELD_BYTE_SIZE = 1</code></dt> <dd> +<p>The returned value is the size, in bytes, of the field. For bit-fields, this is the size in bytes of the containing word. </p> </dd> <dt><code class="code">FIELD_EXISTENCE = 2</code></dt> <dd> +<p>The returned value is 1 if the field exists, 0 otherwise. Always 1 at compile time. </p> </dd> <dt><code class="code">FIELD_SIGNEDNESS = 3</code></dt> <dd> +<p>The returned value is 1 if the field is signed, 0 otherwise. </p> </dd> <dt><code class="code">FIELD_LSHIFT_U64 = 4</code></dt> <dt><code class="code">FIELD_RSHIFT_U64 = 5</code></dt> <dd> +<p>The returned value is the number of bits of left- or right-shifting (respectively) needed in order to recover the original value of the field, after it has been loaded by a read of <code class="code">FIELD_BYTE_SIZE</code> bytes into an unsigned 64-bit value. Primarily useful for reading bit-field values from structures that may change between kernel versions. </p> </dd> </dl> <p>Note that the return value is a constant which is known at compile time. If the field has a variable offset then <code class="code">FIELD_BYTE_OFFSET</code>, <code class="code">FIELD_LSHIFT_U64</code>, and <code class="code">FIELD_RSHIFT_U64</code> are not supported. Similarly, if the field has a variable size then <code class="code">FIELD_BYTE_SIZE</code>, <code class="code">FIELD_LSHIFT_U64</code>, and <code class="code">FIELD_RSHIFT_U64</code> are not supported. </p> <p>For example, <code class="code">__builtin_preserve_field_info</code> can be used to reliably extract bit-field values from a structure that may change between kernel versions: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct S +{ + short a; + int x:7; + int y:5; +}; + +int +read_y (struct S *arg) +{ + unsigned long long val; + unsigned int offset + = __builtin_preserve_field_info (arg->y, FIELD_BYTE_OFFSET); + unsigned int size + = __builtin_preserve_field_info (arg->y, FIELD_BYTE_SIZE); + + /* Read size bytes from arg + offset into val. */ + bpf_probe_read (&val, size, arg + offset); + + val <<= __builtin_preserve_field_info (arg->y, FIELD_LSHIFT_U64); + + if (__builtin_preserve_field_info (arg->y, FIELD_SIGNEDNESS)) + val = ((long long) val + >> __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64)); + else + val >>= __builtin_preserve_field_info (arg->y, FIELD_RSHIFT_U64); + + return val; +}</pre> +</div> </dd> +</dl> </div> <div class="nav-panel"> <p> Next: <a href="fr-v-built-in-functions">FR-V Built-in Functions</a>, Previous: <a href="blackfin-built-in-functions">Blackfin Built-in Functions</a>, Up: <a href="target-builtins">Built-in Functions Specific to Particular Target Machines</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution"> + <p class="_attribution-p"> + © Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br> + <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/BPF-Built-in-Functions.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/BPF-Built-in-Functions.html</a> + </p> +</div> |
