<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Picolibc on XWOS</title>
    <link>/en/Docs/Note/Picolibc/</link>
    <description>Recent content in Picolibc on XWOS</description>
    <generator>Hugo</generator>
    <language>en</language>
    <atom:link href="/en/Docs/Note/Picolibc/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Thread Local Storage</title>
      <link>/en/Docs/Note/Picolibc/TLS/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/en/Docs/Note/Picolibc/TLS/</guid>
      <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;&#xA;&lt;p&gt;Thread Local Storage (TLS) refers to variables that are private to a thread.&lt;/p&gt;&#xA;&lt;p&gt;The C11 standard began supporting thread local storage, introducing the &lt;code&gt;_Thread_local&lt;/code&gt; keyword. The C2X standard introduces the &lt;code&gt;thread_local&lt;/code&gt; keyword.&#xA;The gcc and clang compilers also introduce the &lt;code&gt;__thread&lt;/code&gt; keyword.&lt;/p&gt;&#xA;&lt;p&gt;When global variables are defined using the above keywords, each thread gets a copy of this global variable and accesses its own copy.&lt;/p&gt;&#xA;&lt;h2 id=&#34;tls-models&#34;&gt;TLS Models&lt;/h2&gt;&#xA;&lt;p&gt;There are four TLS models in gcc and clang&amp;rsquo;s implementation:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Dynamic Memory Management</title>
      <link>/en/Docs/Note/Picolibc/MM/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/en/Docs/Note/Picolibc/MM/</guid>
      <description>&lt;h2 id=&#34;description&#34;&gt;Description&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;XWOS does not use the dynamic memory management algorithm provided by picolibc. It uses a memory pool algorithm:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;porting-method&#34;&gt;Porting Method&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Source path: &lt;code&gt;xwmd/libc/picolibcac/mem.c&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Rewrite picolibc&amp;rsquo;s functions:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-C&#34; data-lang=&#34;C&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;malloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; n);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;realloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; p, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; n);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;calloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; elem_nr, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; elem_sz);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;memalign&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; alignment, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; n);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;valloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; n);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;pvalloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; n);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;free&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; p);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;getpagesize&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;Functions that do not need rewriting:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-C&#34; data-lang=&#34;C&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;posix_memalign&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;**&lt;/span&gt; memptr, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; align, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; size); &lt;span style=&#34;color:#080;font-style:italic&#34;&gt;// picolibc provides an implementation based on memalign&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-style:italic&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;aligned_alloc&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; alignment, &lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;size_t&lt;/span&gt; size); &lt;span style=&#34;color:#080;font-style:italic&#34;&gt;// picolibc provides an implementation based on memalign&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;Functions not yet implemented:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;mallopt&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;malloc_usable_size&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;malloc_stats&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;mallinfo&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>errno</title>
      <link>/en/Docs/Note/Picolibc/errno/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>/en/Docs/Note/Picolibc/errno/</guid>
      <description>&lt;h2 id=&#34;porting-method&#34;&gt;Porting Method&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Set Picolibc configuration &lt;code&gt;newlib-global-errno&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;, not using the &lt;code&gt;TLS&lt;/code&gt; mechanism to implement &lt;code&gt;errno&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;Set Picolibc configuration &lt;code&gt;errno-function&lt;/code&gt; to &lt;code&gt;&#39;__errno&#39;&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;XWOS defines an &lt;code&gt;__errno&lt;/code&gt; variable in each thread object structure and re-implements the &lt;code&gt;int * __errno(void)&lt;/code&gt; function,&#xA;returning the address of the &lt;strong&gt;current&lt;/strong&gt; thread object&amp;rsquo;s &lt;code&gt;__errno&lt;/code&gt;:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-C&#34; data-lang=&#34;C&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;__errno&lt;/span&gt;(&lt;span style=&#34;color:#0b0;font-weight:bold&#34;&gt;void&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        xwos_thd_d thdd &lt;span style=&#34;color:#666&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#00a000&#34;&gt;xwos_cthd_self&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#a2f;font-weight:bold&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#666&#34;&gt;&amp;amp;&lt;/span&gt;thdd.thd&lt;span style=&#34;color:#666&#34;&gt;-&amp;gt;&lt;/span&gt;osthd.libc.error_number;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;When using the &lt;code&gt;errno&lt;/code&gt; macro from &lt;code&gt;&amp;lt;errno.h&amp;gt;&lt;/code&gt;, the thread&amp;rsquo;s own &lt;code&gt;__errno&lt;/code&gt; can be obtained, no longer depending on libgloss.&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
  </channel>
</rss>
