mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-17 16:10:29 +00:00
Mint APE Loader v1.7
This change reduces the memory requirements of your APE Loader by 10x, in terms of virtual memory size, thanks to the help of alloca(). We're also now creating argument blocks with the same layout across systems.
This commit is contained in:
parent
d967a94c9a
commit
1d8937d528
31 changed files with 367 additions and 656 deletions
|
@ -1,123 +0,0 @@
|
|||
/*-*- mode:asm; 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"
|
||||
|
||||
.macro .e local:req linux:req
|
||||
.globl \local
|
||||
.long \local-kLinuxErrnos
|
||||
.byte \linux
|
||||
.endm
|
||||
|
||||
// Lookup table translating errnos between systems.
|
||||
//
|
||||
// @see libc/sysv/systemfive.S
|
||||
.rodata
|
||||
.balign 4
|
||||
kLinuxErrnos:
|
||||
.e EPERM,1
|
||||
.e ENOENT,2
|
||||
.e ESRCH,3
|
||||
.e EINTR,4
|
||||
.e EIO,5
|
||||
.e ENXIO,6
|
||||
.e E2BIG,7
|
||||
.e ENOEXEC,8
|
||||
.e EBADF,9
|
||||
.e ECHILD,10
|
||||
.e EAGAIN,11
|
||||
.e ENOMEM,12
|
||||
.e EACCES,13
|
||||
.e EFAULT,14
|
||||
.e ENOTBLK,15
|
||||
.e EBUSY,16
|
||||
.e EEXIST,17
|
||||
.e EXDEV,18
|
||||
.e ENODEV,19
|
||||
.e ENOTDIR,20
|
||||
.e EISDIR,21
|
||||
.e EINVAL,22
|
||||
.e ENFILE,23
|
||||
.e EMFILE,24
|
||||
.e ENOTTY,25
|
||||
.e ETXTBSY,26
|
||||
.e EFBIG,27
|
||||
.e ENOSPC,28
|
||||
.e ESPIPE,29
|
||||
.e EROFS,30
|
||||
.e EMLINK,31
|
||||
.e EPIPE,32
|
||||
.e EDOM,33
|
||||
.e ERANGE,34
|
||||
.e EDEADLK,35
|
||||
.e ENAMETOOLONG,36
|
||||
.e ENOLCK,37
|
||||
.e ENOSYS,38
|
||||
.e ENOTEMPTY,39
|
||||
.e ELOOP,40
|
||||
.e ENOMSG,42
|
||||
.e EIDRM,43
|
||||
.e EUSERS,87
|
||||
.e ENOTSOCK,88
|
||||
.e EDESTADDRREQ,89
|
||||
.e EMSGSIZE,90
|
||||
.e EPROTOTYPE,91
|
||||
.e ENOPROTOOPT,92
|
||||
.e EPROTONOSUPPORT,93
|
||||
.e ESOCKTNOSUPPORT,94
|
||||
.e EOPNOTSUPP,95
|
||||
.e EPFNOSUPPORT,96
|
||||
.e EAFNOSUPPORT,97
|
||||
.e EADDRINUSE,98
|
||||
.e EADDRNOTAVAIL,99
|
||||
.e EL2NSYNC,45
|
||||
.e EL3HLT,46
|
||||
.e EL3RST,47
|
||||
.e ELNRNG,48
|
||||
.e ETIME,62
|
||||
.e ENONET,64
|
||||
.e EREMOTE,66
|
||||
.e EPROTO,71
|
||||
.e EBADMSG,74
|
||||
.e EOVERFLOW,75
|
||||
.e EILSEQ,84
|
||||
.e ERESTART,85
|
||||
.e ENETDOWN,100
|
||||
.e ENETUNREACH,101
|
||||
.e ENETRESET,102
|
||||
.e ECONNABORTED,103
|
||||
.e ECONNRESET,104
|
||||
.e ENOBUFS,105
|
||||
.e EISCONN,106
|
||||
.e ENOTCONN,107
|
||||
.e ESHUTDOWN,108
|
||||
.e ETOOMANYREFS,109
|
||||
.e ETIMEDOUT,110
|
||||
.e ECONNREFUSED,111
|
||||
.e EHOSTDOWN,112
|
||||
.e EHOSTUNREACH,113
|
||||
.e EALREADY,114
|
||||
.e EINPROGRESS,115
|
||||
.e ESTALE,116
|
||||
.e EDQUOT,122
|
||||
.e ECANCELED,125
|
||||
.e EOWNERDEAD,130
|
||||
.e ENOTRECOVERABLE,131
|
||||
.long 0
|
||||
.byte 0
|
||||
.endobj kLinuxErrnos,globl
|
|
@ -1,56 +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 2021 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 "tool/build/lib/lines.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
struct Lines *NewLines(void) {
|
||||
return calloc(1, sizeof(struct Lines));
|
||||
}
|
||||
|
||||
void FreeLines(struct Lines *lines) {
|
||||
size_t i;
|
||||
for (i = 0; i < lines->n; ++i) {
|
||||
free(lines->p[i]);
|
||||
}
|
||||
free(lines);
|
||||
}
|
||||
|
||||
void AppendLine(struct Lines *lines, const char *s, size_t n) {
|
||||
lines->p = realloc(lines->p, ++lines->n * sizeof(*lines->p));
|
||||
lines->p[lines->n - 1] = strndup(s, n);
|
||||
}
|
||||
|
||||
void AppendLines(struct Lines *lines, const char *s) {
|
||||
const char *p;
|
||||
for (;;) {
|
||||
p = strchr(s, '\n');
|
||||
if (p) {
|
||||
AppendLine(lines, s, p - s);
|
||||
s = p + 1;
|
||||
} else {
|
||||
if (*s) {
|
||||
// gcc11 whines about SIZE_MAX > PTRDIFF_MAX
|
||||
AppendLine(lines, s, PTRDIFF_MAX);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_LINES_H_
|
||||
#define COSMOPOLITAN_TOOL_BUILD_LIB_LINES_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct Lines {
|
||||
size_t n;
|
||||
char **p;
|
||||
};
|
||||
|
||||
struct Lines *NewLines(void);
|
||||
void FreeLines(struct Lines *);
|
||||
void AppendLine(struct Lines *, const char *, size_t);
|
||||
void AppendLines(struct Lines *, const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_LINES_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue