| 1 |
import sys |
| 2 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 3 |
from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 4 |
from rpython.jit.backend.llsupport.symbolic import WORD |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
if sys.byteorder == 'little' or sys.maxint <= 2**32: |
| 10 |
long2int = int2long = lambda x: x |
| 11 |
else: |
| 12 |
def long2int(x): return x >> 32 |
| 13 |
def int2long(x): return x << 32 |
| 14 |
|
| 15 |
def get_debug_saved_errno(cpu): |
| 16 |
return long2int(cpu._debug_tls_errno_container[3]) |
| 17 |
|
| 18 |
def set_debug_saved_errno(cpu, nerrno): |
| 19 |
assert nerrno >= 0 |
| 20 |
cpu._debug_tls_errno_container[3] = int2long(nerrno) |
| 21 |
|
| 22 |
def get_rpy_errno_offset(cpu): |
| 23 |
if cpu.translate_support_code: |
| 24 |
from rpython.rlib import rthread |
| 25 |
return rthread.tlfield_rpy_errno.getoffset() |
| 26 |
else: |
| 27 |
return 3 * WORD |
| 28 |
|
| 29 |
|
| 30 |
def get_debug_saved_alterrno(cpu): |
| 31 |
return long2int(cpu._debug_tls_errno_container[4]) |
| 32 |
|
| 33 |
def set_debug_saved_alterrno(cpu, nerrno): |
| 34 |
assert nerrno >= 0 |
| 35 |
cpu._debug_tls_errno_container[4] = int2long(nerrno) |
| 36 |
|
| 37 |
def get_alt_errno_offset(cpu): |
| 38 |
if cpu.translate_support_code: |
| 39 |
from rpython.rlib import rthread |
| 40 |
return rthread.tlfield_alt_errno.getoffset() |
| 41 |
else: |
| 42 |
return 4 * WORD |
| 43 |
|
| 44 |
|
| 45 |
def get_debug_saved_lasterror(cpu): |
| 46 |
return cpu._debug_tls_errno_container[5] |
| 47 |
|
| 48 |
def set_debug_saved_lasterror(cpu, nerrno): |
| 49 |
assert nerrno >= 0 |
| 50 |
cpu._debug_tls_errno_container[5] = nerrno |
| 51 |
|
| 52 |
def get_debug_saved_altlasterror(cpu): |
| 53 |
return cpu._debug_tls_errno_container[6] |
| 54 |
|
| 55 |
def set_debug_saved_altlasterror(cpu, nerrno): |
| 56 |
assert nerrno >= 0 |
| 57 |
cpu._debug_tls_errno_container[6] = nerrno |
| 58 |
|
| 59 |
def get_rpy_lasterror_offset(cpu): |
| 60 |
if cpu.translate_support_code: |
| 61 |
from rpython.rlib import rthread |
| 62 |
return rthread.tlfield_rpy_lasterror.getoffset() |
| 63 |
else: |
| 64 |
return 5 * WORD |
| 65 |
|
| 66 |
def get_alt_lasterror_offset(cpu): |
| 67 |
if cpu.translate_support_code: |
| 68 |
from rpython.rlib import rthread |
| 69 |
return rthread.tlfield_alt_lasterror.getoffset() |
| 70 |
else: |
| 71 |
return 6 * WORD |
| 72 |
|
| 73 |
|
| 74 |
def _fetch_addr_errno(): |
| 75 |
eci = ExternalCompilationInfo( |
| 76 |
separate_module_sources=[''' |
| 77 |
#include <errno.h> |
| 78 |
RPY_EXPORTED long fetch_addr_errno(void) { |
| 79 |
return (long)(&errno); |
| 80 |
} |
| 81 |
''']) |
| 82 |
func1_ptr = rffi.llexternal('fetch_addr_errno', [], lltype.Signed, |
| 83 |
compilation_info=eci, _nowrapper=True) |
| 84 |
return func1_ptr() |
| 85 |
|
| 86 |
def get_p_errno_offset(cpu): |
| 87 |
if cpu.translate_support_code: |
| 88 |
from rpython.rlib import rthread |
| 89 |
return rthread.tlfield_p_errno.getoffset() |
| 90 |
else: |
| 91 |
|
| 92 |
|
| 93 |
if cpu._debug_tls_errno_container[2] == 0: |
| 94 |
addr_errno = _fetch_addr_errno() |
| 95 |
assert addr_errno != 0 |
| 96 |
cpu._debug_tls_errno_container[2] = addr_errno |
| 97 |
return 2 * WORD |