mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Refactor some code
This commit is contained in:
parent
787b04f752
commit
9b87dd2b87
11 changed files with 43 additions and 10 deletions
16
examples/asantest.c
Normal file
16
examples/asantest.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
__static_yoink("__die");
|
||||||
|
__static_yoink("GetSymbolByAddr");
|
||||||
|
__static_yoink("malloc_inspect_all");
|
||||||
|
|
||||||
|
char *lol(int n) {
|
||||||
|
return malloc(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *(*pLol)(int) = lol;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
char *s = pLol(4);
|
||||||
|
s[4] = 1;
|
||||||
|
}
|
|
@ -39,6 +39,7 @@
|
||||||
#include "libc/nt/struct/startupinfo.h"
|
#include "libc/nt/struct/startupinfo.h"
|
||||||
#include "libc/nt/struct/startupinfoex.h"
|
#include "libc/nt/struct/startupinfoex.h"
|
||||||
#include "libc/proc/ntspawn.h"
|
#include "libc/proc/ntspawn.h"
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
@ -149,7 +150,7 @@ static textwindows int ntspawn2(struct NtSpawnArgs *a, struct SpawnBlock *sb) {
|
||||||
// this code won't call malloc in practice
|
// this code won't call malloc in practice
|
||||||
bool32 ok;
|
bool32 ok;
|
||||||
void *freeme = 0;
|
void *freeme = 0;
|
||||||
_Alignas(16) char memory[128];
|
alignas(16) char memory[128];
|
||||||
size_t size = sizeof(memory);
|
size_t size = sizeof(memory);
|
||||||
struct NtProcThreadAttributeList *alist = (void *)memory;
|
struct NtProcThreadAttributeList *alist = (void *)memory;
|
||||||
uint32_t items = !!a->opt_hParentProcess + !!a->opt_lpExplicitHandleList;
|
uint32_t items = !!a->opt_hParentProcess + !!a->opt_lpExplicitHandleList;
|
||||||
|
|
|
@ -82,7 +82,16 @@ o//libc/intrin/memcmp.o \
|
||||||
o//libc/intrin/memset.o \
|
o//libc/intrin/memset.o \
|
||||||
o//libc/intrin/memmove.o: private \
|
o//libc/intrin/memmove.o: private \
|
||||||
CFLAGS += \
|
CFLAGS += \
|
||||||
-O2 -finline -foptimize-sibling-calls
|
-O2 \
|
||||||
|
-finline \
|
||||||
|
-foptimize-sibling-calls
|
||||||
|
|
||||||
|
# make asan stack traces shorter
|
||||||
|
o/$(MODE)/libc/intrin/asanthunk.o: private \
|
||||||
|
CFLAGS += \
|
||||||
|
-Os \
|
||||||
|
$(NO_MAGIC) \
|
||||||
|
-foptimize-sibling-calls
|
||||||
|
|
||||||
o/$(MODE)/libc/intrin/bzero.o \
|
o/$(MODE)/libc/intrin/bzero.o \
|
||||||
o/$(MODE)/libc/intrin/memcmp.o \
|
o/$(MODE)/libc/intrin/memcmp.o \
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/fmt/magnumstrs.internal.h"
|
#include "libc/fmt/magnumstrs.internal.h"
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
_Alignas(1) static char strerror_buf[128];
|
alignas(1) static char strerror_buf[128];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns string describing `err`.
|
* Returns string describing `err`.
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/stdckdint.h"
|
#include "libc/stdckdint.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@
|
||||||
|
|
||||||
#ifndef MODE_DBG /* don't interfere with asan dlmalloc hooking */
|
#ifndef MODE_DBG /* don't interfere with asan dlmalloc hooking */
|
||||||
|
|
||||||
_Alignas(TINYMALLOC_MAX_ALIGN) static struct {
|
alignas(TINYMALLOC_MAX_ALIGN) static struct {
|
||||||
char memory[TINYMALLOC_MAX_BYTES];
|
char memory[TINYMALLOC_MAX_BYTES];
|
||||||
unsigned used, last, free;
|
unsigned used, last, free;
|
||||||
} heap;
|
} heap;
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/tab.internal.h"
|
#include "libc/str/tab.internal.h"
|
||||||
|
|
||||||
_Alignas(uint8_t) const uint8_t kBase36[256] = {
|
alignas(uint8_t) const uint8_t kBase36[256] = {
|
||||||
['0'] = 1, //
|
['0'] = 1, //
|
||||||
['1'] = 2, //
|
['1'] = 2, //
|
||||||
['2'] = 3, //
|
['2'] = 3, //
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/tab.internal.h"
|
#include "libc/str/tab.internal.h"
|
||||||
|
|
||||||
_Alignas(uint8_t) const uint8_t kToLower[256] = {
|
alignas(uint8_t) const uint8_t kToLower[256] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||||
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/tab.internal.h"
|
#include "libc/str/tab.internal.h"
|
||||||
|
|
||||||
_Alignas(uint8_t) const uint8_t kToUpper[256] = {
|
alignas(uint8_t) const uint8_t kToUpper[256] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||||
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
#define LWP_SUSPENDED 0x00000080
|
#define LWP_SUSPENDED 0x00000080
|
||||||
|
|
||||||
struct CloneArgs {
|
struct CloneArgs {
|
||||||
_Alignas(16) union {
|
alignas(16) union {
|
||||||
struct {
|
struct {
|
||||||
int tid;
|
int tid;
|
||||||
int this;
|
int this;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "libc/runtime/internal.h"
|
#include "libc/runtime/internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/runtime/syslib.internal.h"
|
#include "libc/runtime/syslib.internal.h"
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/locale.h"
|
#include "libc/str/locale.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/thread/posixthread.internal.h"
|
#include "libc/thread/posixthread.internal.h"
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
extern unsigned char __tls_mov_nt_rax[];
|
extern unsigned char __tls_mov_nt_rax[];
|
||||||
extern unsigned char __tls_add_nt_rax[];
|
extern unsigned char __tls_add_nt_rax[];
|
||||||
|
|
||||||
_Alignas(TLS_ALIGNMENT) static char __static_tls[6016];
|
alignas(TLS_ALIGNMENT) static char __static_tls[6016];
|
||||||
|
|
||||||
static unsigned long ParseMask(const char *str) {
|
static unsigned long ParseMask(const char *str) {
|
||||||
int c;
|
int c;
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/stdalign.internal.h"
|
||||||
#include "libc/str/tab.internal.h"
|
#include "libc/str/tab.internal.h"
|
||||||
|
|
||||||
_Alignas(int8_t) const int8_t kHexToInt[256] = {
|
alignas(int8_t) const int8_t kHexToInt[256] = {
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
|
||||||
|
|
Loading…
Reference in a new issue