mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Clean up errno.
This commit is contained in:
parent
01a9779fc6
commit
9b98679885
7 changed files with 26 additions and 44 deletions
|
@ -169,4 +169,13 @@ void libk_munmap(void* ptr, size_t size)
|
|||
FreeKernelAddress(&addralloc);
|
||||
}
|
||||
|
||||
#undef errno
|
||||
extern "C" { int errno; }
|
||||
|
||||
extern "C"
|
||||
int* libk_get_errno_location(void)
|
||||
{
|
||||
return &errno;
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
|
|
@ -372,7 +372,7 @@ interrupt_handler_prepare:
|
|||
pushq %rbp
|
||||
|
||||
# Push the current kernel errno value.
|
||||
movl global_errno, %ebp
|
||||
movl errno, %ebp
|
||||
pushq %rbp
|
||||
|
||||
# Push whether a signal is pending.
|
||||
|
@ -396,7 +396,7 @@ load_interrupted_registers:
|
|||
|
||||
# Restore the previous kernel errno.
|
||||
popq %rbp
|
||||
movl %ebp, global_errno
|
||||
movl %ebp, errno
|
||||
|
||||
# Remove CR2 from the stack.
|
||||
addq $8, %rsp
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
.section .text
|
||||
.type syscall_handler, @function
|
||||
syscall_handler:
|
||||
movl $0, global_errno # Reset errno
|
||||
movl $0, errno
|
||||
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
|
@ -45,7 +45,7 @@ syscall_handler:
|
|||
|
||||
# Return to user-space, system call result in %rax:%rdx, errno in %ecx.
|
||||
popq %rbp
|
||||
movl global_errno, %ecx
|
||||
movl errno, %ecx
|
||||
|
||||
# Zero registers to avoid information leaks.
|
||||
# rax is return value.
|
||||
|
|
|
@ -369,7 +369,7 @@ fixup_relocate_stack_complete:
|
|||
pushl %ebp
|
||||
|
||||
# Push the current kernel errno value.
|
||||
movl global_errno, %ebp
|
||||
movl errno, %ebp
|
||||
pushl %ebp
|
||||
|
||||
# Push whether a signal is pending.
|
||||
|
@ -394,7 +394,7 @@ load_interrupted_registers:
|
|||
|
||||
# Restore the previous kernel errno.
|
||||
popl %ebp
|
||||
movl %ebp, global_errno
|
||||
movl %ebp, errno
|
||||
|
||||
# Remove CR2 from the stack.
|
||||
addl $4, %esp
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
.type syscall_handler, @function
|
||||
syscall_handler:
|
||||
/* -- stack is 12 bytes from being 16-byte aligned -- */
|
||||
movl $0, global_errno # Reset errno
|
||||
movl $0, errno
|
||||
|
||||
pushl %ebp
|
||||
/* -- stack is 8 bytes from being 16-byte aligned -- */
|
||||
|
@ -69,7 +69,7 @@ syscall_handler:
|
|||
|
||||
# Return to user-space, system call result in %eax:%edx, errno in %ecx.
|
||||
popl %ebp
|
||||
movl global_errno, %ecx
|
||||
movl errno, %ecx
|
||||
|
||||
# Zero registers to avoid information leaks.
|
||||
# eax is the return value.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2012, 2014 Jonas 'Sortie' Termansen.
|
||||
* Copyright (c) 2011, 2012, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -18,27 +18,9 @@
|
|||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __is_sortix_libk
|
||||
|
||||
__thread int errno = 0;
|
||||
|
||||
#else
|
||||
|
||||
int global_errno = 0;
|
||||
errno_location_func_t errno_location_func = NULL;
|
||||
|
||||
int* get_errno_location(void)
|
||||
{
|
||||
if ( errno_location_func )
|
||||
return errno_location_func();
|
||||
return &global_errno;
|
||||
}
|
||||
|
||||
void set_errno_location_func(errno_location_func_t func)
|
||||
{
|
||||
errno_location_func = func;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,10 +22,6 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ENOTBLK 12
|
||||
#define ENODEV 13
|
||||
#define EWOULDBLOCK 14
|
||||
|
@ -117,6 +113,10 @@ extern "C" {
|
|||
|
||||
#define EOPNOTSUPP ENOTSUP
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||
|
||||
extern __thread int errno;
|
||||
|
@ -124,24 +124,15 @@ extern __thread int errno;
|
|||
|
||||
#else
|
||||
|
||||
/* Returns the address of the errno variable for this thread. */
|
||||
int* get_errno_location(void);
|
||||
|
||||
/* get_errno_location will forward the request to a user-specified function if
|
||||
specified, or if NULL, will return the global thread-shared errno value. */
|
||||
typedef int* (*errno_location_func_t)(void);
|
||||
void set_errno_location_func(errno_location_func_t func);
|
||||
|
||||
#define errno (*get_errno_location())
|
||||
int* libk_get_errno_location(void);
|
||||
#define errno (*libk_get_errno_location())
|
||||
|
||||
#endif
|
||||
|
||||
#if __USE_SORTIX
|
||||
extern char* program_invocation_name;
|
||||
extern char* program_invocation_short_name;
|
||||
|
||||
/* Satisfy broken programs that expect these to be macros. */
|
||||
#define program_invocation_name program_invocation_name
|
||||
#define program_invocation_short_name program_invocation_short_name
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
Loading…
Reference in a new issue