Clean up errno.
This commit is contained in:
parent
01a9779fc6
commit
9b98679885
|
@ -169,4 +169,13 @@ void libk_munmap(void* ptr, size_t size)
|
||||||
FreeKernelAddress(&addralloc);
|
FreeKernelAddress(&addralloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef errno
|
||||||
|
extern "C" { int errno; }
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
int* libk_get_errno_location(void)
|
||||||
|
{
|
||||||
|
return &errno;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sortix
|
} // namespace Sortix
|
||||||
|
|
|
@ -372,7 +372,7 @@ interrupt_handler_prepare:
|
||||||
pushq %rbp
|
pushq %rbp
|
||||||
|
|
||||||
# Push the current kernel errno value.
|
# Push the current kernel errno value.
|
||||||
movl global_errno, %ebp
|
movl errno, %ebp
|
||||||
pushq %rbp
|
pushq %rbp
|
||||||
|
|
||||||
# Push whether a signal is pending.
|
# Push whether a signal is pending.
|
||||||
|
@ -396,7 +396,7 @@ load_interrupted_registers:
|
||||||
|
|
||||||
# Restore the previous kernel errno.
|
# Restore the previous kernel errno.
|
||||||
popq %rbp
|
popq %rbp
|
||||||
movl %ebp, global_errno
|
movl %ebp, errno
|
||||||
|
|
||||||
# Remove CR2 from the stack.
|
# Remove CR2 from the stack.
|
||||||
addq $8, %rsp
|
addq $8, %rsp
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
.section .text
|
.section .text
|
||||||
.type syscall_handler, @function
|
.type syscall_handler, @function
|
||||||
syscall_handler:
|
syscall_handler:
|
||||||
movl $0, global_errno # Reset errno
|
movl $0, errno
|
||||||
|
|
||||||
pushq %rbp
|
pushq %rbp
|
||||||
movq %rsp, %rbp
|
movq %rsp, %rbp
|
||||||
|
@ -45,7 +45,7 @@ syscall_handler:
|
||||||
|
|
||||||
# Return to user-space, system call result in %rax:%rdx, errno in %ecx.
|
# Return to user-space, system call result in %rax:%rdx, errno in %ecx.
|
||||||
popq %rbp
|
popq %rbp
|
||||||
movl global_errno, %ecx
|
movl errno, %ecx
|
||||||
|
|
||||||
# Zero registers to avoid information leaks.
|
# Zero registers to avoid information leaks.
|
||||||
# rax is return value.
|
# rax is return value.
|
||||||
|
|
|
@ -369,7 +369,7 @@ fixup_relocate_stack_complete:
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
|
|
||||||
# Push the current kernel errno value.
|
# Push the current kernel errno value.
|
||||||
movl global_errno, %ebp
|
movl errno, %ebp
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
|
|
||||||
# Push whether a signal is pending.
|
# Push whether a signal is pending.
|
||||||
|
@ -394,7 +394,7 @@ load_interrupted_registers:
|
||||||
|
|
||||||
# Restore the previous kernel errno.
|
# Restore the previous kernel errno.
|
||||||
popl %ebp
|
popl %ebp
|
||||||
movl %ebp, global_errno
|
movl %ebp, errno
|
||||||
|
|
||||||
# Remove CR2 from the stack.
|
# Remove CR2 from the stack.
|
||||||
addl $4, %esp
|
addl $4, %esp
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
.type syscall_handler, @function
|
.type syscall_handler, @function
|
||||||
syscall_handler:
|
syscall_handler:
|
||||||
/* -- stack is 12 bytes from being 16-byte aligned -- */
|
/* -- stack is 12 bytes from being 16-byte aligned -- */
|
||||||
movl $0, global_errno # Reset errno
|
movl $0, errno
|
||||||
|
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
/* -- stack is 8 bytes from being 16-byte aligned -- */
|
/* -- 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.
|
# Return to user-space, system call result in %eax:%edx, errno in %ecx.
|
||||||
popl %ebp
|
popl %ebp
|
||||||
movl global_errno, %ecx
|
movl errno, %ecx
|
||||||
|
|
||||||
# Zero registers to avoid information leaks.
|
# Zero registers to avoid information leaks.
|
||||||
# eax is the return value.
|
# 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
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -18,27 +18,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#ifndef __is_sortix_libk
|
#ifndef __is_sortix_libk
|
||||||
|
|
||||||
__thread int errno = 0;
|
__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
|
#endif
|
||||||
|
|
|
@ -22,10 +22,6 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ENOTBLK 12
|
#define ENOTBLK 12
|
||||||
#define ENODEV 13
|
#define ENODEV 13
|
||||||
#define EWOULDBLOCK 14
|
#define EWOULDBLOCK 14
|
||||||
|
@ -117,6 +113,10 @@ extern "C" {
|
||||||
|
|
||||||
#define EOPNOTSUPP ENOTSUP
|
#define EOPNOTSUPP ENOTSUP
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
|
|
||||||
extern __thread int errno;
|
extern __thread int errno;
|
||||||
|
@ -124,24 +124,15 @@ extern __thread int errno;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Returns the address of the errno variable for this thread. */
|
int* libk_get_errno_location(void);
|
||||||
int* get_errno_location(void);
|
#define errno (*libk_get_errno_location())
|
||||||
|
|
||||||
/* 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())
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __USE_SORTIX
|
||||||
extern char* program_invocation_name;
|
extern char* program_invocation_name;
|
||||||
extern char* program_invocation_short_name;
|
extern char* program_invocation_short_name;
|
||||||
|
#endif
|
||||||
/* 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
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
Loading…
Reference in New Issue