Refactor some code

This commit is contained in:
Justine Tunney 2024-05-22 12:09:55 -07:00
parent 787b04f752
commit 9b87dd2b87
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 43 additions and 10 deletions

16
examples/asantest.c Normal file
View 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;
}

View file

@ -39,6 +39,7 @@
#include "libc/nt/struct/startupinfo.h"
#include "libc/nt/struct/startupinfoex.h"
#include "libc/proc/ntspawn.h"
#include "libc/stdalign.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
#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
bool32 ok;
void *freeme = 0;
_Alignas(16) char memory[128];
alignas(16) char memory[128];
size_t size = sizeof(memory);
struct NtProcThreadAttributeList *alist = (void *)memory;
uint32_t items = !!a->opt_hParentProcess + !!a->opt_lpExplicitHandleList;

View file

@ -82,7 +82,16 @@ o//libc/intrin/memcmp.o \
o//libc/intrin/memset.o \
o//libc/intrin/memmove.o: private \
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/memcmp.o \

View file

@ -18,9 +18,10 @@
*/
#include "libc/dce.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/stdalign.internal.h"
#include "libc/str/str.h"
_Alignas(1) static char strerror_buf[128];
alignas(1) static char strerror_buf[128];
/**
* Returns string describing `err`.

View file

@ -16,6 +16,7 @@
#include "libc/assert.h"
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/stdalign.internal.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
@ -29,7 +30,7 @@
#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];
unsigned used, last, free;
} heap;

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdalign.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, //
['1'] = 2, //
['2'] = 3, //

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdalign.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,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdalign.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,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, ' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')',

View file

@ -78,7 +78,7 @@
#define LWP_SUSPENDED 0x00000080
struct CloneArgs {
_Alignas(16) union {
alignas(16) union {
struct {
int tid;
int this;

View file

@ -35,6 +35,7 @@
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/syslib.internal.h"
#include "libc/stdalign.internal.h"
#include "libc/str/locale.h"
#include "libc/str/str.h"
#include "libc/thread/posixthread.internal.h"
@ -47,7 +48,7 @@
extern unsigned char __tls_mov_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) {
int c;

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdalign.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, // 0x10
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20