@@ -36,8 +36,9 @@ considered an APE program.
36
36
37
37
This is the canonical magic used by almost all APE programs. It enables
38
38
maximum portability between OSes. When interpreted as a shell script, it
39
- is assiging a single quoted string to an unused variable. The shell will
40
- then ignore subsequent binary content that's placed inside the string.
39
+ is assigning a single quoted string to an unused variable. The shell
40
+ will then ignore subsequent binary content that's placed inside the
41
+ string.
41
42
42
43
It is strongly recommended that this magic value be immediately followed
43
44
by a newline (\n or hex 0a) character. Some shells, e.g. FreeBSD SH and
@@ -167,12 +168,12 @@ printf '\177ELF\2\1\1\011\0\0\0\0\0\0\0\0\2\0\076\0\1\0\0\0\166\105\100\000\000\
167
168
168
169
This ` printf ` statement MUST appear in the first 8192 bytes of the APE
169
170
executable, so as to limit how much of the initial portion of a file an
170
- intepreter must load.
171
+ interpreter must load.
171
172
172
- Multiple such ` printf ` statements MAY appear in hte first 8192 bytes, in
173
+ Multiple such ` printf ` statements MAY appear in the first 8192 bytes, in
173
174
order to specify multiple architectures. For example, fat binaries built
174
175
by the ` apelink ` program (provided by Cosmo Libc) will have two encoded
175
- ELF headers, for amd64 and arm64 , each of which point into the proper
176
+ ELF headers, for AMD64 and ARM64 , each of which point into the proper
176
177
file offsets for their respective native code. Therefore, kernels and
177
178
interpreters which load the APE format directly MUST check the
178
179
` e_machine ` field of the ` Elf64_Ehdr ` that's decoded from the octal
@@ -313,7 +314,7 @@ their support vector MUST be compiled using `-mno-red-zone`. This is
313
314
because, on Windows, DLLs and other software lurking in the va-space
314
315
might use tricks like SetThreadContext() to take control of a thread
315
316
whereas on bare metal, it's also generally accepted that kernel-mode
316
- code cannot assume a red zone either due to hardware interrutps that
317
+ code cannot assume a red zone either due to hardware interrupts that
317
318
pull the exact same kinds of stunts.
318
319
319
320
APE software that only has truly System V ABI conformant OSes (e.g.
@@ -350,7 +351,7 @@ would be friction-free alternative.
350
351
351
352
It's not possible for an APE runtime that targets the full range of OSes
352
353
to use the ` tpidr_el0 ` register for TLS because Apple won't allow it. On
353
- MacOS ARM64 systems, this reigster can only be used by a runtime to
354
+ MacOS ARM64 systems, this register can only be used by a runtime to
354
355
implement the ` sched_getcpu() ` system call. It's reserved by MacOS.
355
356
356
357
#### x86-64
@@ -441,11 +442,11 @@ static void ChangeTlsFsToGs(unsigned char *p, size_t n) {
441
442
}
442
443
```
443
444
444
- By favoring `%gs` we've now ensured friction-free compatibilty for the
445
+ By favoring `%gs` we've now ensured friction-free compatibility for the
445
446
APE runtime on MacOS, Linux, and FreeBSD which are all able to conform
446
447
easily to this convention. However additional work needs to be done at
447
448
runtime when an APE program is started on Windows, OpenBSD, and NetBSD.
448
- On these platforms, all executable pages must be faulted and morped to
449
+ On these platforms, all executable pages must be faulted and morphed to
449
450
fixup the TLS instructions.
450
451
451
452
On OpenBSD and NetBSD, this is as simple as undoing the example
@@ -466,7 +467,7 @@ a privileged function, so that it can be used to disable the execute bit
466
467
on all other parts of the executable except for the privileged section,
467
468
thereby making it writable. Once this has been done, code can change.
468
469
469
- On Windows the diplacement bytes of the TLS instruction are changed to
470
+ On Windows the displacement bytes of the TLS instruction are changed to
470
471
use the `%gs:0x1480+i*8` ABI where `i` is a number assigned by the WIN32
471
472
`TlsAlloc()` API. This avoids the need to call `TlsGetValue()` which is
472
473
implemented this exact same way under the hood. Even though 0x1480 isn't
@@ -477,7 +478,7 @@ possible, to ensure an index less than 64 is returned.
477
478
478
479
### Thread Information Block (TIB)
479
480
480
- The Actually Portable Exccutable Thread Information Block (TIB) is
481
+ The Actually Portable Executable Thread Information Block (TIB) is
481
482
defined by this version of the specification as follows:
482
483
483
484
- The 64-bit TIB self-pointer is stored at offset 0x00.
@@ -520,7 +521,7 @@ Actually Portable Executable defines `char` as signed.
520
521
521
522
Therefore conformant APE software MUST use `-fsigned-char` when building
522
523
code for aarch64, as well as any other architecture that (unlike x86-64)
523
- would otherwise define `char` as being `unsigned char` by deafult .
524
+ would otherwise define `char` as being `unsigned char` by default .
524
525
525
526
This decision was one of the cases where it made sense to offer a more
526
527
consistent runtime experience for fat multi-arch binaries. However you
@@ -584,7 +585,7 @@ imposed by the executable formats that APE wraps.
584
585
happily map program headers from arbitrary file intervals (which may
585
586
overlap) onto arbitrarily virtual intervals (which don't need to be
586
587
contiguous). in order to do that, the loaders will generally use
587
- unix 's mmap() function which needs to have both page aligned
588
+ UNIX 's mmap() function which needs to have both page aligned
588
589
addresses and file offsets, even though the ELF programs headers
589
590
themselves do not. Since program headers start and stop at
590
591
potentially any byte, ELF loaders tease the intervals specified by
@@ -595,7 +596,7 @@ imposed by the executable formats that APE wraps.
595
596
don't want to; we can simply allow the offset to drift apart from the
596
597
virtual offset.
597
598
598
- 2 . PE doesn't care about congruency and instead specifies a second kind
599
+ 2 . PE doesn't care about congruence and instead specifies a second kind
599
600
of alignment. The minimum alignment of files is 512 because that's
600
601
what MS-DOS used. Where things get hairy is with PE's SizeOfHeaders
601
602
which has complex requirements. When the PE image base needs to be
@@ -694,4 +695,4 @@ to the system allocation granularity, which is generally 64kb. If you
694
695
use a function like mmap() with Cosmopolitan Libc, then the ` addr ` and
695
696
` offset ` parameters need to be aligned to ` sysconf(_SC_GRANSIZE) ` or
696
697
else your software won't work on Windows. Windows has other limitations
697
- too, such as lacking the abiilty to carve or punch holes in mappings.
698
+ too, such as lacking the ability to carve or punch holes in mappings.
0 commit comments