mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Thread secure errno(3).
This commit is contained in:
parent
f69b6c845c
commit
0618b8a68f
5 changed files with 27 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -25,20 +25,16 @@
|
|||
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#if !defined(__is_sortix_kernel)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if __STDC_HOSTED__
|
||||
|
||||
extern "C" { int __thread errno = 0; }
|
||||
|
||||
#else
|
||||
|
||||
extern "C" { int global_errno = 0; }
|
||||
extern "C" { errno_location_func_t errno_location_func = NULL; }
|
||||
|
||||
#if !defined(__is_sortix_kernel)
|
||||
extern "C" void init_error_functions()
|
||||
{
|
||||
global_errno = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" int* get_errno_location(void)
|
||||
{
|
||||
if ( errno_location_func ) { return errno_location_func(); }
|
||||
|
@ -49,3 +45,5 @@ extern "C" void set_errno_location_func(errno_location_func_t func)
|
|||
{
|
||||
errno_location_func = func;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -107,6 +107,13 @@ __BEGIN_DECLS
|
|||
|
||||
#define EOPNOTSUPP ENOTSUP
|
||||
|
||||
#if __STDC_HOSTED__
|
||||
|
||||
extern __thread int errno;
|
||||
#define errno errno
|
||||
|
||||
#else
|
||||
|
||||
/* Returns the address of the errno variable for this thread. */
|
||||
int* get_errno_location(void);
|
||||
|
||||
|
@ -117,6 +124,8 @@ void set_errno_location_func(errno_location_func_t func);
|
|||
|
||||
#define errno (*get_errno_location())
|
||||
|
||||
#endif
|
||||
|
||||
extern char* program_invocation_name;
|
||||
extern char* program_invocation_short_name;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
|||
extern "C" { char* program_invocation_name; }
|
||||
extern "C" { char* program_invocation_short_name; }
|
||||
|
||||
extern "C" void init_error_functions();
|
||||
extern "C" void init_stdio();
|
||||
extern "C" void init_signal();
|
||||
|
||||
|
@ -54,9 +53,6 @@ extern "C" void initialize_standard_library(int argc, char* argv[])
|
|||
program_invocation_name = (char*) argv0;
|
||||
program_invocation_short_name = find_last_elem((char*) argv0);
|
||||
|
||||
// Initialize stuff such as errno.
|
||||
init_error_functions();
|
||||
|
||||
// It's probably best to initialize the Unix signals early on.
|
||||
init_signal();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -37,23 +37,10 @@ asm_syscall: /* syscall num in %rax. */
|
|||
mov %rsp, %rbp
|
||||
int $0x80
|
||||
test %ecx, %ecx
|
||||
jnz 1f
|
||||
pop %rbp
|
||||
ret
|
||||
jz 1f
|
||||
mov %fs:0, %rsi
|
||||
mov %ecx, errno@tpoff(%rsi)
|
||||
1:
|
||||
push %rbx
|
||||
push %r12
|
||||
push %r13
|
||||
mov %ecx, %ebx # preserve: ret_errno
|
||||
mov %rax, %r12 # preserve: ret_low
|
||||
mov %rdx, %r13 # preserve: ret_high
|
||||
call get_errno_location # get_errno_location()
|
||||
mov %ebx, (%rax) # *get_errno_location() = ret_errno
|
||||
mov %r12, %rax # restore: ret_low
|
||||
mov %r13, %rdx # restore: ret_high
|
||||
pop %r13
|
||||
pop %r12
|
||||
pop %rbx
|
||||
pop %rbp
|
||||
ret
|
||||
.size asm_syscall, .-asm_syscall
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -49,13 +49,8 @@ asm_syscall: /* syscall num in %eax. */
|
|||
int $0x80
|
||||
test %ecx, %ecx # ret_errno & ret_errno
|
||||
jz 1f # if ( !(ret_errno & ret_errno) )
|
||||
mov %eax, %ebx # preserve: ret_low
|
||||
mov %edx, %edi # preserve: ret_high
|
||||
mov %ecx, %esi # preserve: ret_errno
|
||||
call get_errno_location # get_errno_location()
|
||||
mov %esi, (%eax) # *get_errno_location() = ret_errno
|
||||
mov %ebx, %eax # restore: ret_low
|
||||
mov %edi, %edx # restore: ret_high
|
||||
mov %gs:0, %ebx
|
||||
mov %ecx, errno@ntpoff(%ebx)
|
||||
1:
|
||||
pop %esi
|
||||
pop %edi
|
||||
|
|
Loading…
Reference in a new issue