summaryrefslogtreecommitdiff
path: root/static/freebsd/man9/DEFINE_IFUNC.9 3.html
diff options
context:
space:
mode:
Diffstat (limited to 'static/freebsd/man9/DEFINE_IFUNC.9 3.html')
-rw-r--r--static/freebsd/man9/DEFINE_IFUNC.9 3.html118
1 files changed, 0 insertions, 118 deletions
diff --git a/static/freebsd/man9/DEFINE_IFUNC.9 3.html b/static/freebsd/man9/DEFINE_IFUNC.9 3.html
deleted file mode 100644
index d7bc4b82..00000000
--- a/static/freebsd/man9/DEFINE_IFUNC.9 3.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<table class="head">
- <tr>
- <td class="head-ltitle">DEFINE_IFUNC(9)</td>
- <td class="head-vol">Kernel Developer's Manual</td>
- <td class="head-rtitle">DEFINE_IFUNC(9)</td>
- </tr>
-</table>
-<div class="manual-text">
-<section class="Sh">
-<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
-<p class="Pp"><code class="Nm">DEFINE_IFUNC</code> &#x2014;
- <span class="Nd">define a kernel function with an implementation selected at
- run-time</span></p>
-</section>
-<section class="Sh">
-<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
-<p class="Pp"><code class="In">#include
- &lt;<a class="In">machine/ifunc.h</a>&gt;</code></p>
-<p class="Pp"><code class="Fn">DEFINE_IFUNC</code>(<var class="Fa" style="white-space: nowrap;">qual</var>,
- <var class="Fa" style="white-space: nowrap;">ret_type</var>,
- <var class="Fa" style="white-space: nowrap;">name</var>,
- <var class="Fa" style="white-space: nowrap;">args</var>);</p>
-</section>
-<section class="Sh">
-<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
-<p class="Pp">ifuncs are a linker feature which allows the programmer to define
- functions whose implementation is selected at boot-time or module load-time.
- The <code class="Nm">DEFINE_IFUNC</code> macro can be used to define an
- ifunc. The selection is performed by a resolver function, which returns a
- pointer to the selected function. ifunc resolvers are invoked very early
- during the machine-dependent initialization routine, or at load time for
- dynamically loaded modules. Resolution must occur before the first call to
- an ifunc. ifunc resolution is performed after CPU features are enumerated
- and after the kernel's environment is initialized. The typical use-case for
- an ifunc is a routine whose behavior depends on optional CPU features. For
- example, newer generations of a given CPU architecture may provide an
- instruction to optimize a common operation. To avoid the overhead of testing
- for the CPU feature each time the operation is performed, an ifunc can be
- used to provide two implementations for the operation: one targeting
- platforms with the extra instruction, and one for older platforms.</p>
-<p class="Pp">Because <code class="Nm">DEFINE_IFUNC</code> is a macro that
- defines a dynamically typed function, its usage looks somewhat unusual. The
- <var class="Ar">qual</var> parameter is a list of zero or more C function
- qualifiers to be applied to the ifunc. This parameter is typically empty or
- the <code class="Dv">static</code> qualifier. <var class="Ar">ret_type</var>
- is the return type of the ifunc. <var class="Ar">name</var> is the name of
- the ifunc. <var class="Ar">args</var> is a parenthesized, comma-separated
- list of the parameter types of the function, as they would appear in a C
- function declaration.</p>
-<p class="Pp">The <code class="Nm">DEFINE_IFUNC</code> usage must be followed by
- the resolver function body. The resolver must return a function with return
- type <var class="Ar">ret_type</var> and parameter types
- <var class="Ar">args</var>. The resolver function is defined with the
- &#x2018;<code class="Li">resolver</code>&#x2019; gcc-style function
- attribute, causing the corresponding <a class="Xr">elf(5)</a> function
- symbol to be of type <code class="Dv">STT_GNU_IFUNC</code> instead of
- <code class="Dv">STT_FUNC</code>. The kernel linker invokes the resolver to
- process relocations targeting ifunc calls and PLT entries referencing such
- symbols.</p>
-</section>
-<section class="Sh">
-<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
-<p class="Pp">ifunc resolvers are executed early during boot, before most kernel
- facilities are available. They are effectively limited to checking CPU
- feature flags and tunables.</p>
-<div class="Bd Pp Li">
-<pre>static size_t
-fast_strlen(const char *s __unused)
-{
- size_t len;
-
- /* Fast, but may not be correct in all cases. */
- __asm(&quot;movq $42,%0\n&quot; : &quot;=r&quot; (len));
- return (len);
-}
-
-static size_t
-slow_strlen(const char *s)
-{
- const char *t;
-
- for (t = s; *t != '\0'; t++);
- return (t - s);
-}
-
-DEFINE_IFUNC(, size_t, strlen, (const char *))
-{
- int enabled;
-
- enabled = 1;
- TUNABLE_INT_FETCH(&quot;debug.use_fast_strlen&quot;, &amp;enabled);
- if (enabled &amp;&amp; (cpu_features &amp; CPUID_FAST_STRLEN) != 0)
- return (fast_strlen);
- else
- return (slow_strlen);
-}</pre>
-</div>
-<p class="Pp">This defines a <code class="Fn">strlen</code>() function with an
- optimized implementation for CPUs that advertise support.</p>
-</section>
-<section class="Sh">
-<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
- ALSO</a></h1>
-<p class="Pp"><a class="Xr">elf(5)</a></p>
-</section>
-<section class="Sh">
-<h1 class="Sh" id="NOTES"><a class="permalink" href="#NOTES">NOTES</a></h1>
-<p class="Pp">ifuncs require both toolchain support, to emit function symbols of
- type <code class="Dv">STT_GNU_IFUNC</code>, and kernel linker support, to
- invoke ifunc resolvers during boot or during module load.</p>
-</section>
-</div>
-<table class="foot">
- <tr>
- <td class="foot-date">March 10, 2026</td>
- <td class="foot-os">FreeBSD 15.0</td>
- </tr>
-</table>