Fix stdio regression

This change fixes a nasty regression caused by
80b211e314 which deadlocked.

This change also causes MbedTLS to prefer the ChaCha ciphersuite on
older CPUs that don't have AES hardware instructions.
This commit is contained in:
Justine Tunney 2022-05-19 00:34:15 -07:00
parent 9208c83f7a
commit 6e52cba37a
14 changed files with 232 additions and 51 deletions

View file

@ -23,7 +23,7 @@
// @return byte in range 0..255, or -1 w/ errno
// @see fgetc_unlocked()
getchar:
lea stdin(%rip),%rdi
mov stdin(%rip),%rdi
mov %rdi,%r11
ezlea fgetc_unlocked,ax
jmp stdio_unlock

View file

@ -23,7 +23,7 @@
// @return wide character or -1 on EOF or error
// @see fgetwc_unlocked()
getwchar:
lea stdin(%rip),%rdi
mov stdin(%rip),%rdi
mov %rdi,%r11
ezlea fgetwc_unlocked,ax
jmp stdio_unlock

View file

@ -24,7 +24,7 @@
// @return c (as unsigned char) if written or -1 w/ errno
// @see fputc_unlocked()
putchar:
lea stdout(%rip),%rsi
mov stdout(%rip),%rsi
mov %rsi,%r11
ezlea fputc_unlocked,ax
jmp stdio_unlock

View file

@ -24,7 +24,7 @@
// @return wc if written or -1 w/ errno
// @see fputwc_unlocked()
putwchar:
lea stdout(%rip),%rsi
mov stdout(%rip),%rsi
mov %rsi,%r11
ezlea fputwc_unlocked,ax
jmp stdio_unlock

View file

@ -17,7 +17,11 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/nexgen32e/threaded.h"
asm(".weak\t__asan_init");
asm(".weak\t__asan_register_globals");
asm(".weak\t__asan_unregister_globals");
asm(".weak\t__asan_version_mismatch_check_v8");
/**
* Global variable for last error.
@ -32,14 +36,3 @@
* @see __errno_location() stable abi
*/
errno_t __errno;
/**
* Returns address of errno variable.
*
* @see __initialize_tls()
* @see __install_tls()
*/
privileged nocallersavedregisters errno_t *(__errno_location)(void) {
if (!__tls_enabled) return &__errno;
return (errno_t *)(__get_tls() + 0x3c);
}

View file

@ -0,0 +1,31 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/nexgen32e/threaded.h"
/**
* Returns address of errno variable.
*
* @see __initialize_tls()
* @see __install_tls()
*/
privileged nocallersavedregisters errno_t *(__errno_location)(void) {
if (!__tls_enabled) return &__errno;
return (errno_t *)(__get_tls() + 0x3c);
}

View file

@ -37,7 +37,8 @@ LIBC_SYSV_A_FILES := \
libc/sysv/restorert.S \
libc/sysv/syscall.S \
libc/sysv/systemfive.S \
libc/sysv/errno.greg.c \
libc/sysv/errno_location.greg.c \
libc/sysv/errno.c \
libc/sysv/strace.greg.c \
libc/sysv/describeos.greg.c \
$(wildcard libc/sysv/consts/*) \
@ -75,12 +76,6 @@ o/libc/sysv/consts/syscon.internal.inc: \
libc/macros-cpp.internal.inc \
libc/macros.internal.inc
# we can't use asan and ubsan because:
# we're higher in the topological order of things
o/$(MODE)/libc/sysv/errno.greg.o: \
OVERRIDE_CFLAGS += \
-fno-sanitize=all
#───────────────────────────────────────────────────────────────────────────────
LIBC_SYSV_CALLS = \