Delete more dead code

This commit is contained in:
Justine Tunney 2023-07-06 09:07:42 -07:00
parent 0a24b4fc3c
commit 00acd81b2f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
63 changed files with 75 additions and 1220 deletions

View file

@ -29,7 +29,6 @@
#include "libc/intrin/leaky.internal.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/tpenc.h"
#include "libc/intrin/weaken.h"
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
@ -43,6 +42,7 @@
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#include "libc/str/tab.internal.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/map.h"

View file

@ -1,47 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_RUNTIME_FSGSBASE_H_
#define COSMOPOLITAN_LIBC_RUNTIME_FSGSBASE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void *_rdfsbase(void);
void *_rdgsbase(void);
void *_wrfsbase(void *);
void *_wrgsbase(void *);
int _have_fsgsbase(void);
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define _rdfsbase() \
({ \
void *_p; \
asm("rdfsbase\t%0" : "=r"(_p)); \
_p; \
})
#define _rdgsbase() \
({ \
void *_p; \
asm("rdgsbase\t%0" : "=r"(_p)); \
_p; \
})
#define _wrfsbase(p) \
({ \
void *_p = p; \
asm volatile("wrfsbase\t%0" \
: /* no outputs */ \
: "r"(_p) \
: "memory"); \
_p; \
})
#define _wrgsbase(p) \
({ \
void *_p = p; \
asm volatile("wrgsbase\t%0" \
: /* no outputs */ \
: "r"(_p) \
: "memory"); \
_p; \
})
#endif /* GNUC && !ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_FSGSBASE_H_ */

View file

@ -1,66 +0,0 @@
/*-*- 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/dce.h"
#include "libc/errno.h"
#include "libc/intrin/fsgsbase.h"
#include "libc/nexgen32e/x86feature.h"
#ifdef __x86_64__
/**
* Returns true if FSGSBASE ISA can be used.
*
* If this function returns true (Linux 5.9+ or FreeBSD) then you should
* be able to read/write to the %gs / %fs x86 segment registers in about
* one or two clock cycles which gives you a free addition operation for
* all assembly ops that reference memory.
*
* The FSGSBASE ISA was introduced by Intel with Ivybridge (c. 2012) but
* the Linux Kernel didn't authorize us to use it until 2020, once Intel
* had to start backdooring customer kernels so that they could have it.
* AMD introduced support for the FSGSBASE ISA in Excavator, aka bdver4.
*
* @return boolean indicating if feature can be used
* @see _rdfsbase()
* @see _rdgsbase()
* @see _wrfsbase()
* @see _wrgsbase()
*/
privileged int _have_fsgsbase(void) {
// Linux 5.9 (c. 2020) introduced close_range() and fsgsbase support.
// it's cheaper to test for close_range() than handle an op crashing.
// Windows lets us use these instructions but they don't really work.
int ax;
if (X86_HAVE(FSGSBASE)) {
if (IsLinux()) {
asm volatile("syscall"
: "=a"(ax)
: "0"(436 /* close_range */), "D"(-1), "S"(-2), "d"(0)
: "rcx", "r11", "memory");
return ax == -22; // EINVAL
} else if (IsFreebsd()) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
#endif /* __x86_64__ */

View file

@ -1,31 +0,0 @@
/*-*- 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/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Reads `%fs` base address.
*
* @see _have_fsgsbase()
*/
void *(_rdfsbase)(void) {
return _rdfsbase();
}
#endif /* __x86_64__ */

View file

@ -1,31 +0,0 @@
/*-*- 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/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Reads `%gs` base address.
*
* @see _have_fsgsbase()
*/
void *(_rdgsbase)(void) {
return _rdgsbase();
}
#endif /* __x86_64__ */

View file

@ -1,68 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.internal.h"
// Encodes Thompson-Pike varint.
//
// @param edi is int to encode
// @return rax is word-encoded byte buffer
// @note invented on a napkin in a new jersey diner
.ftrace1
_tpenc: .ftrace2
.leafprologue
mov %edi,%edi
xor %eax,%eax
cmp $127,%edi
jbe 3f
bsr %edi,%ecx
mov kTpenc-7*(1+1)(,%rcx,2),%ecx
1: mov %edi,%edx
shr $6,%edi
and $0b00111111,%dl
or $0b10000000,%al
or %dl,%al
shl $8,%rax
dec %cl
jnz 1b
2: or %ch,%al
3: or %rdi,%rax
.leafepilogue
.endfn _tpenc,globl
.rodata
.balign 4
.underrun
kTpenc: .rept 4 // MSB10 (0x7FF)
.byte 1,0b11000000 // len,mark
.endr
.rept 5 // MSB15 (0xFFFF)
.byte 2,0b11100000 // len,mark
.endr
.rept 5 // MSB20 (0x1FFFFF)
.byte 3,0b11110000 // len,mark
.endr
.rept 5 // MSB25 (0x3FFFFFF)
.byte 4,0b11111000 // len,mark
.endr
.rept 6 // MSB31 (0xffffffff)
.byte 5,0b11111100 // len,mark
.endr
.zero 2
.endobj kTpenc
.overrun

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bsr.h"
#ifndef __x86_64__
static const uint16_t kTpEnc[32 - 7] = {
1 | 0300 << 8, 1 | 0300 << 8, 1 | 0300 << 8, 1 | 0300 << 8, 2 | 0340 << 8,
@ -27,6 +26,9 @@ static const uint16_t kTpEnc[32 - 7] = {
5 | 0374 << 8, 5 | 0374 << 8, 5 | 0374 << 8, 5 | 0374 << 8, 5 | 0374 << 8,
};
/**
* Encodes Thompson-Pike variable-length integer.
*/
uint64_t _tpenc(uint32_t c) {
int e, n;
uint64_t w;
@ -41,5 +43,3 @@ uint64_t _tpenc(uint32_t c) {
} while (--n);
return c | w | e >> 8;
}
#endif /* __x86_64__ */

View file

@ -1,23 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_STR_TPENC_H_
#define COSMOPOLITAN_LIBC_STR_TPENC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
uint64_t _tpenc(uint32_t) pureconst;
#if defined(__x86_64__) && defined(__MNO_RED_ZONE__) && defined(__GNUC__) && \
!defined(__STRICT_ANSI__)
#define _tpenc(CODE) \
({ \
long Edi, Buf; \
asm("call\t_tpenc" \
: "=a"(Buf), "=D"(Edi) \
: "1"((int)(CODE)) \
: "rcx", "rdx", "cc"); \
Buf; \
})
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_TPENC_H_ */

View file

@ -1,31 +0,0 @@
/*-*- 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/intrin/fsgsbase.h"
#ifdef __x86_64__
/**
* Changes `%fs` base address.
*
* @see _have_fsgsbase()
*/
void *(_wrfsbase)(void *p) {
return _wrfsbase(p);
}
#endif /* __x86_64__ */

View file

@ -1,28 +0,0 @@
/*-*- 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/intrin/fsgsbase.h"
/**
* Changes `%gs` base address.
*
* @see _have_fsgsbase()
*/
void *(_wrgsbase)(void *p) {
return _wrgsbase(p);
}

View file

@ -65,6 +65,9 @@ textwindows int WSARecv(
rc = __imp_WSARecv(s, inout_lpBuffers, dwBufferCount,
opt_out_lpNumberOfBytesRecvd, inout_lpFlags,
opt_inout_lpOverlapped, opt_lpCompletionRoutine);
if (rc == -1) {
__winerr();
}
#endif
return rc;
}

View file

@ -69,6 +69,9 @@ textwindows int WSARecvFrom(
opt_out_lpNumberOfBytesRecvd, inout_lpFlags,
opt_out_fromsockaddr, opt_inout_fromsockaddrlen,
opt_inout_lpOverlapped, opt_lpCompletionRoutine);
if (rc == -1) {
__winerr();
}
#endif
return rc;
}