mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 01:38:30 +00:00
Add APE interpreter example (#263)
This commit is contained in:
parent
5b60e5a37d
commit
969174e155
7 changed files with 210 additions and 14 deletions
|
@ -123,9 +123,9 @@
|
|||
|
||||
#define PN_XNUM 0xffff
|
||||
|
||||
#define PF_X (1 << 0)
|
||||
#define PF_W (1 << 1)
|
||||
#define PF_R (1 << 2)
|
||||
#define PF_X 1
|
||||
#define PF_W 2
|
||||
#define PF_R 4
|
||||
#define PF_MASKOS 0x0ff00000
|
||||
#define PF_MASKPROC 0xf0000000
|
||||
|
||||
|
|
16
libc/linux/execve.h
Normal file
16
libc/linux/execve.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LINUX_EXECVE_H_
|
||||
#define COSMOPOLITAN_LIBC_LINUX_EXECVE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
forceinline long LinuxExecve(const char *program, char *const argv[],
|
||||
char *const envp[]) {
|
||||
long rc;
|
||||
asm volatile("syscall"
|
||||
: "=a"(rc)
|
||||
: "0"(59), "D"(program), "S"(argv), "d"(envp)
|
||||
: "rcx", "r11", "memory");
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LINUX_EXECVE_H_ */
|
|
@ -5,14 +5,14 @@
|
|||
forceinline long LinuxMmap(void *addr, size_t size, long prot, long flags,
|
||||
long fd, long off) {
|
||||
long rc;
|
||||
asm volatile("mov\t%5,%%r10\n\t"
|
||||
"mov\t%6,%%r8\n\t"
|
||||
"mov\t%7,%%r9\n\t"
|
||||
"syscall"
|
||||
register long flags_ asm("r10") = flags;
|
||||
register long fd_ asm("r8") = fd;
|
||||
register long off_ asm("r9") = off;
|
||||
asm volatile("syscall"
|
||||
: "=a"(rc)
|
||||
: "0"(9), "D"(addr), "S"(size), "d"(prot), "g"(flags), "g"(fd),
|
||||
"g"(off)
|
||||
: "rcx", "r8", "r9", "r10", "r11", "memory");
|
||||
: "0"(9), "D"(addr), "S"(size), "d"(prot), "r"(flags_), "r"(fd_),
|
||||
"r"(off_)
|
||||
: "rcx", "r11", "memory");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,15 @@
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
wchar_t *wmemset(wchar_t *p, wchar_t c, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
p[i] = c;
|
||||
size_t i = 0;
|
||||
if (n >= 4) {
|
||||
wchar_t v __attribute__((__vector_size__(16))) = {c, c, c, c};
|
||||
do {
|
||||
__builtin_memcpy(p + i, &v, 16);
|
||||
} while ((i += 4) + 4 <= n);
|
||||
}
|
||||
while (i < n) {
|
||||
p[i++] = c;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue