mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-08 10:50:28 +00:00
clang-format
This commit is contained in:
parent
dc6fd43177
commit
3b2b724ac7
3 changed files with 38 additions and 40 deletions
|
@ -40,7 +40,7 @@ static bool CanExecute(const char *path) {
|
||||||
|
|
||||||
bool IsAPEMagic(char buf[8]) {
|
bool IsAPEMagic(char buf[8]) {
|
||||||
return READ64LE(buf) == READ64LE("MZqFpD='") ||
|
return READ64LE(buf) == READ64LE("MZqFpD='") ||
|
||||||
READ64LE(buf) == READ64LE("JTqFpD='");
|
READ64LE(buf) == READ64LE("JTqFpD='");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsApeBinary(const char *path) {
|
static bool IsApeBinary(const char *path) {
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/calls/calls.h"
|
|
||||||
#include "libc/calls/blockcancel.internal.h"
|
#include "libc/calls/blockcancel.internal.h"
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/cp.internal.h"
|
#include "libc/calls/cp.internal.h"
|
||||||
#include "libc/calls/execve-sysv.internal.h"
|
#include "libc/calls/execve-sysv.internal.h"
|
||||||
#include "libc/calls/struct/stat.internal.h"
|
#include "libc/calls/struct/stat.internal.h"
|
||||||
|
@ -51,9 +51,9 @@ static bool IsAPEFd(const int fd) {
|
||||||
static int fexecve_impl(const int fd, char *const argv[], char *const envp[]) {
|
static int fexecve_impl(const int fd, char *const argv[], char *const envp[]) {
|
||||||
int rc;
|
int rc;
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
char path[14 + 12];
|
char path[14 + 12];
|
||||||
FormatInt32(stpcpy(path, "/proc/self/fd/"), fd);
|
FormatInt32(stpcpy(path, "/proc/self/fd/"), fd);
|
||||||
rc = __sys_execve(path, argv, envp);
|
rc = __sys_execve(path, argv, envp);
|
||||||
} else if (IsFreebsd()) {
|
} else if (IsFreebsd()) {
|
||||||
rc = sys_fexecve(fd, argv, envp);
|
rc = sys_fexecve(fd, argv, envp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,43 +63,41 @@ static int fexecve_impl(const int fd, char *const argv[], char *const envp[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PTF_NUM = 1 << 0,
|
PTF_NUM = 1 << 0,
|
||||||
PTF_NUM2 = 1 << 1,
|
PTF_NUM2 = 1 << 1,
|
||||||
PTF_NUM3 = 1 << 2,
|
PTF_NUM3 = 1 << 2,
|
||||||
PTF_ANY = 1 << 3
|
PTF_ANY = 1 << 3
|
||||||
} PTF_PARSE;
|
} PTF_PARSE;
|
||||||
|
|
||||||
static bool ape_to_elf(void *ape, const size_t apesize) {
|
static bool ape_to_elf(void *ape, const size_t apesize) {
|
||||||
static const char printftok[] = "printf '";
|
static const char printftok[] = "printf '";
|
||||||
static const size_t printftoklen = sizeof(printftok)-1;
|
static const size_t printftoklen = sizeof(printftok) - 1;
|
||||||
const char *tok = memmem(ape, apesize, printftok, printftoklen);
|
const char *tok = memmem(ape, apesize, printftok, printftoklen);
|
||||||
if(tok) {
|
if (tok) {
|
||||||
tok += printftoklen;
|
tok += printftoklen;
|
||||||
uint8_t *dest = ape;
|
uint8_t *dest = ape;
|
||||||
PTF_PARSE state = PTF_ANY;
|
PTF_PARSE state = PTF_ANY;
|
||||||
uint8_t value = 0;
|
uint8_t value = 0;
|
||||||
for(;tok < (const char*)(dest+apesize); tok++) {
|
for (; tok < (const char *)(dest + apesize); tok++) {
|
||||||
if((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) && (*tok >= '0' && *tok <= '7')) {
|
if ((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) &&
|
||||||
|
(*tok >= '0' && *tok <= '7')) {
|
||||||
value = (value << 3) | (*tok - '0');
|
value = (value << 3) | (*tok - '0');
|
||||||
state <<= 1;
|
state <<= 1;
|
||||||
if(state & PTF_ANY) {
|
if (state & PTF_ANY) {
|
||||||
*dest++ = value;
|
*dest++ = value;
|
||||||
}
|
}
|
||||||
}
|
} else if (state & PTF_NUM) {
|
||||||
else if(state & PTF_NUM) {
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
if (state & (PTF_NUM2 | PTF_NUM3)) {
|
||||||
if(state & (PTF_NUM2 | PTF_NUM3)) {
|
|
||||||
*dest++ = value;
|
*dest++ = value;
|
||||||
}
|
}
|
||||||
if(*tok == '\\') {
|
if (*tok == '\\') {
|
||||||
state = PTF_NUM;
|
state = PTF_NUM;
|
||||||
value = 0;
|
value = 0;
|
||||||
} else if(*tok == '\'') {
|
} else if (*tok == '\'') {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
*dest++ = *tok;
|
*dest++ = *tok;
|
||||||
state = PTF_ANY;
|
state = PTF_ANY;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +114,7 @@ static int ape_fd_to_mem_elf_fd(const int infd, char *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(sys_fstat(infd, &st) == -1) {
|
if (sys_fstat(infd, &st) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -139,8 +137,8 @@ static int ape_fd_to_mem_elf_fd(const int infd, char *path) {
|
||||||
rc = sys_ftruncate(fd, st.st_size, st.st_size);
|
rc = sys_ftruncate(fd, st.st_size, st.st_size);
|
||||||
END_CANCELLATION_POINT;
|
END_CANCELLATION_POINT;
|
||||||
if ((rc != -1) &&
|
if ((rc != -1) &&
|
||||||
((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
|
((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||||
0)) != MAP_FAILED)) {
|
fd, 0)) != MAP_FAILED)) {
|
||||||
ssize_t readRc;
|
ssize_t readRc;
|
||||||
BEGIN_CANCELLATION_POINT;
|
BEGIN_CANCELLATION_POINT;
|
||||||
readRc = sys_pread(infd, space, st.st_size, 0, 0);
|
readRc = sys_pread(infd, space, st.st_size, 0, 0);
|
||||||
|
@ -184,9 +182,9 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
|
||||||
STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv),
|
STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv),
|
||||||
DescribeStringList(envp));
|
DescribeStringList(envp));
|
||||||
rc = fexecve_impl(fd, argv, envp);
|
rc = fexecve_impl(fd, argv, envp);
|
||||||
if((errno == ENOEXEC) && (IsLinux() || IsFreebsd()) && IsAPEFd(fd)) {
|
if ((errno == ENOEXEC) && (IsLinux() || IsFreebsd()) && IsAPEFd(fd)) {
|
||||||
const int newfd = ape_fd_to_mem_elf_fd(fd, NULL);
|
const int newfd = ape_fd_to_mem_elf_fd(fd, NULL);
|
||||||
if(newfd != -1) {
|
if (newfd != -1) {
|
||||||
rc = fexecve_impl(newfd, argv, envp);
|
rc = fexecve_impl(newfd, argv, envp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,21 +2,21 @@
|
||||||
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_
|
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_
|
||||||
#include "libc/runtime/symbolic.h"
|
#include "libc/runtime/symbolic.h"
|
||||||
|
|
||||||
#define SHM_ANON SYMBOLIC(SHM_ANON)
|
#define SHM_ANON SYMBOLIC(SHM_ANON)
|
||||||
#define SHM_DEST SYMBOLIC(SHM_DEST)
|
#define SHM_DEST SYMBOLIC(SHM_DEST)
|
||||||
#define SHM_EXEC SYMBOLIC(SHM_EXEC)
|
#define SHM_EXEC SYMBOLIC(SHM_EXEC)
|
||||||
#define SHM_HUGETLB SYMBOLIC(SHM_HUGETLB)
|
#define SHM_HUGETLB SYMBOLIC(SHM_HUGETLB)
|
||||||
#define SHM_INFO SYMBOLIC(SHM_INFO)
|
#define SHM_INFO SYMBOLIC(SHM_INFO)
|
||||||
#define SHM_LOCK SYMBOLIC(SHM_LOCK)
|
#define SHM_LOCK SYMBOLIC(SHM_LOCK)
|
||||||
#define SHM_LOCKED SYMBOLIC(SHM_LOCKED)
|
#define SHM_LOCKED SYMBOLIC(SHM_LOCKED)
|
||||||
#define SHM_NORESERVE SYMBOLIC(SHM_NORESERVE)
|
#define SHM_NORESERVE SYMBOLIC(SHM_NORESERVE)
|
||||||
#define SHM_R SYMBOLIC(SHM_R)
|
#define SHM_R SYMBOLIC(SHM_R)
|
||||||
#define SHM_RDONLY SYMBOLIC(SHM_RDONLY)
|
#define SHM_RDONLY SYMBOLIC(SHM_RDONLY)
|
||||||
#define SHM_REMAP SYMBOLIC(SHM_REMAP)
|
#define SHM_REMAP SYMBOLIC(SHM_REMAP)
|
||||||
#define SHM_RND SYMBOLIC(SHM_RND)
|
#define SHM_RND SYMBOLIC(SHM_RND)
|
||||||
#define SHM_STAT SYMBOLIC(SHM_STAT)
|
#define SHM_STAT SYMBOLIC(SHM_STAT)
|
||||||
#define SHM_UNLOCK SYMBOLIC(SHM_UNLOCK)
|
#define SHM_UNLOCK SYMBOLIC(SHM_UNLOCK)
|
||||||
#define SHM_W SYMBOLIC(SHM_W)
|
#define SHM_W SYMBOLIC(SHM_W)
|
||||||
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue