Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>errno</code> is not always a global variable. It is only required to be an lvalue, and may be a macro hiding a function call. From <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/errno.html" rel="nofollow">the specification</a>:</p> <blockquote> <p>It is unspecified whether errno is a macro or an identifier declared with external linkage.</p> </blockquote> <p>In fact, it is usually <em>not</em> a global variable since it is usually implemented to be thread-local (and so requires a function call to retrieve a pointer to the TLS block).</p> <p>You are better off having a C wrapper that calls the assembly function and sets <code>errno</code>.</p> <hr> <p>EDIT: Since you can't use a C function (which, IMO, is senseless, since <code>errno</code> is firmly a C/POSIX concept), you will have to implement the <code>errno</code> gathering yourself. Find the definition of <code>errno</code> in <code>errno.h</code>, and implement whatever is there in assembly. For example, my <code>errno.h</code> defines <code>errno</code> as</p> <pre><code>extern int * __error(void); #define errno (*__error()) </code></pre> <p>Therefore, I would make a call to the <code>__error</code> function (which returns an <code>int *</code>), then store to the returned address. For example, here's the assembly my system produces for setting <code>errno</code>:</p> <pre><code>$ gcc -xc - -o- -S &lt;&lt;EOF #include &lt;errno.h&gt; main() { errno = 3; return 0; } EOF .section __TEXT,__text,regular,pure_instructions .globl _main .align 4, 0x90 _main: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: subq $16, %rsp Ltmp2: callq ___error movl $3, (%rax) ... </code></pre> <p>Your system will probably have a different implementation of <code>errno</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload