mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Get address sanitizer mostly working
This commit is contained in:
parent
1f1f3cd477
commit
7327c345f9
149 changed files with 3777 additions and 3457 deletions
|
@ -93,6 +93,10 @@ o/$(MODE)/tool/build/emulator.o: \
|
|||
OVERRIDE_COPTS += \
|
||||
-fno-sanitize=pointer-overflow
|
||||
|
||||
# $(TOOL_BUILD_OBJS): \
|
||||
# OVERRIDE_CFLAGS += \
|
||||
# -fsanitize=address
|
||||
|
||||
.PHONY: o/$(MODE)/tool/build
|
||||
o/$(MODE)/tool/build: \
|
||||
o/$(MODE)/tool/build/emucrt \
|
||||
|
|
|
@ -456,7 +456,7 @@ static void SetupDraw(void) {
|
|||
|
||||
a = 1 / 8. * tyn;
|
||||
b = 3 / 8. * tyn;
|
||||
c2y[0] = a;
|
||||
c2y[0] = a * .7;
|
||||
c2y[1] = a * 2;
|
||||
c2y[2] = a * 2 + b;
|
||||
|
||||
|
@ -1590,9 +1590,23 @@ Restart:
|
|||
LeaveScreen();
|
||||
}
|
||||
if (printstats) {
|
||||
int i;
|
||||
extern long opcount[256 * 4];
|
||||
fprintf(stderr, "taken: %,ld\n", taken);
|
||||
fprintf(stderr, "ntaken: %,ld\n", ntaken);
|
||||
fprintf(stderr, "ops: %,ld\n", ops);
|
||||
for (i = 0x51; i < 0x58; ++i) opcount[0x50] += opcount[i];
|
||||
for (i = 0x51; i < 0x58; ++i) opcount[i] = 0;
|
||||
for (i = 0x59; i < 0x60; ++i) opcount[0x58] += opcount[i];
|
||||
for (i = 0x59; i < 0x60; ++i) opcount[i] = 0;
|
||||
for (i = 0x91; i < 0x98; ++i) opcount[0x90] += opcount[i];
|
||||
for (i = 0x91; i < 0x98; ++i) opcount[i] = 0;
|
||||
for (i = 0x71; i < 0x80; ++i) opcount[0x70] += opcount[i];
|
||||
for (i = 0x71; i < 0x80; ++i) opcount[i] = 0;
|
||||
for (i = 0; i < ARRAYLEN(opcount); ++i) {
|
||||
if (!opcount[i]) continue;
|
||||
fprintf(stderr, "0x%03x %ld\n", i, opcount[i]);
|
||||
}
|
||||
}
|
||||
munmap(elf->ehdr, elf->size);
|
||||
DisFree(dis);
|
||||
|
|
|
@ -63,7 +63,9 @@ $(TOOL_BUILD_LIB_A).pkg: \
|
|||
$(TOOL_BUILD_LIB_A_OBJS) \
|
||||
$(foreach x,$(TOOL_BUILD_LIB_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/tool/build/lib/fpu.o: OVERRIDE_CFLAGS += -ffast-math
|
||||
# $(TOOL_BUILD_LIB_A_OBJS): \
|
||||
# OVERRIDE_CFLAGS += \
|
||||
# -fsanitize=address
|
||||
|
||||
TOOL_BUILD_LIB_LIBS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)))
|
||||
TOOL_BUILD_LIB_SRCS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_SRCS))
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
static double SseRoundDouble(struct Machine *m, double x) {
|
||||
switch (m->sse.rc) {
|
||||
case 0:
|
||||
return nearbyint(x);
|
||||
return rint(x);
|
||||
case 1:
|
||||
return floor(x);
|
||||
case 2:
|
||||
|
@ -134,7 +134,7 @@ static void OpPpiWpsqCvtps2pi(struct Machine *m, uint32_t rde) {
|
|||
memcpy(f, GetModrmRegisterXmmPointerRead8(m, rde), 8);
|
||||
switch (m->sse.rc) {
|
||||
case 0:
|
||||
for (i = 0; i < 2; ++i) n[i] = nearbyintf(f[i]);
|
||||
for (i = 0; i < 2; ++i) n[i] = rintf(f[i]);
|
||||
break;
|
||||
case 1:
|
||||
for (i = 0; i < 2; ++i) n[i] = floorf(f[i]);
|
||||
|
@ -250,7 +250,7 @@ static void OpVdqWpsCvtps2dq(struct Machine *m, uint32_t rde) {
|
|||
memcpy(f, GetModrmRegisterXmmPointerRead16(m, rde), 16);
|
||||
switch (m->sse.rc) {
|
||||
case 0:
|
||||
for (i = 0; i < 4; ++i) n[i] = nearbyintf(f[i]);
|
||||
for (i = 0; i < 4; ++i) n[i] = rintf(f[i]);
|
||||
break;
|
||||
case 1:
|
||||
for (i = 0; i < 4; ++i) n[i] = floorf(f[i]);
|
||||
|
|
|
@ -173,7 +173,7 @@ void Dis(struct Dis *d, struct Machine *m, int64_t addr) {
|
|||
struct DisOp op;
|
||||
long i, j, n, si, max, toto, symbol;
|
||||
unique = 0;
|
||||
max = 99999;
|
||||
max = 999999;
|
||||
DisFreeOps(&d->ops);
|
||||
for (i = 0; i < max; ++i) {
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
|
@ -224,10 +224,12 @@ void Dis(struct Dis *d, struct Machine *m, int64_t addr) {
|
|||
xed_instruction_length_decode(d->xedd, d->raw, n);
|
||||
DCHECK_GT(n, 0);
|
||||
p = DisLineCode((struct DisBuilder){d, d->xedd, addr}, d->buf);
|
||||
CHECK_LT(p - d->buf, sizeof(d->buf));
|
||||
n = d->xedd->op.error ? 1 : d->xedd->length;
|
||||
DCHECK_GT(n, 0);
|
||||
} else {
|
||||
p = DisLineData((struct DisBuilder){d, d->xedd, addr}, d->buf, d->raw, n);
|
||||
CHECK_LT(p - d->buf, sizeof(d->buf));
|
||||
}
|
||||
DCHECK_LT(p, d->buf + sizeof(d->buf));
|
||||
DCHECK_LT(strlen(d->buf), sizeof(d->buf));
|
||||
|
|
|
@ -175,8 +175,8 @@ static char *DisName(struct DisBuilder b, char *bp, const char *name,
|
|||
*/
|
||||
char *DisInst(struct DisBuilder b, char *p, const char *spec) {
|
||||
long i, n;
|
||||
char sbuf[128];
|
||||
char args[4][64];
|
||||
char sbuf[256];
|
||||
char args[4][128];
|
||||
char *s, *name, *state;
|
||||
bool hasarg, hasmodrm, hasregister, hasmemory;
|
||||
CHECK_EQ(0, (int)b.xedd->op.error);
|
||||
|
@ -190,7 +190,7 @@ char *DisInst(struct DisBuilder b, char *p, const char *spec) {
|
|||
hasarg = true;
|
||||
hasregister |= *s == '%';
|
||||
hasmemory |= *s == 'O';
|
||||
DisArg(b, args[n], s);
|
||||
CHECK_LT(DisArg(b, args[n], s) - args[n], sizeof(args[n]));
|
||||
}
|
||||
if (g_dis_high) p = DisHigh(p, g_dis_high->keyword);
|
||||
p = DisName(b, p, name, hasarg && !hasregister && hasmemory);
|
||||
|
|
|
@ -164,7 +164,7 @@ struct ElfWriter *elfwriter_open(const char *path, int mode) {
|
|||
CHECK_NE(-1, (elf->fd = open(elf->tmppath,
|
||||
O_CREAT | O_TRUNC | O_RDWR | O_EXCL, mode)));
|
||||
CHECK_NE(-1, ftruncate(elf->fd, (elf->mapsize = FRAMESIZE)));
|
||||
CHECK_NE(MAP_FAILED, (elf->map = mmap((void *)(intptr_t)kFixedMappingsStart,
|
||||
CHECK_NE(MAP_FAILED, (elf->map = mmap((void *)(intptr_t)kFixedmapStart,
|
||||
elf->mapsize, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FIXED, elf->fd, 0)));
|
||||
elf->ehdr = memcpy(elf->map, &kObjHeader, (elf->wrote = sizeof(kObjHeader)));
|
||||
|
|
|
@ -235,7 +235,7 @@ static long double FpuDiv(struct Machine *m, long double x, long double y) {
|
|||
static long double FpuRound(struct Machine *m, long double x) {
|
||||
switch (m->fpu.rc) {
|
||||
case 0:
|
||||
return nearbyintl(x);
|
||||
return rintl(x);
|
||||
case 1:
|
||||
return floorl(x);
|
||||
case 2:
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#define MUTATING true
|
||||
#define READONLY false
|
||||
#define UNCONDITIONAL true
|
||||
#define BITS (8 << RegLog2(rde))
|
||||
#define BITS (8u << RegLog2(rde))
|
||||
#define SIGN (1ull << (BITS - 1))
|
||||
#define MASK (SIGN | (SIGN - 1))
|
||||
#define SHIFTMASK (BITS - 1)
|
||||
|
@ -1330,8 +1330,8 @@ static void OpSqrtpsd(struct Machine *m, uint32_t rde) {
|
|||
}
|
||||
|
||||
static void OpRsqrtps(struct Machine *m, uint32_t rde) {
|
||||
unsigned i;
|
||||
float_v x;
|
||||
unsigned i;
|
||||
if (Rep(rde) != 3) {
|
||||
memcpy(&x, GetModrmRegisterXmmPointerRead16(m, rde), 16);
|
||||
for (i = 0; i < 4; ++i) x[i] = 1.f / sqrtf(x[i]);
|
||||
|
@ -1344,8 +1344,8 @@ static void OpRsqrtps(struct Machine *m, uint32_t rde) {
|
|||
}
|
||||
|
||||
static void OpRcpps(struct Machine *m, uint32_t rde) {
|
||||
int i;
|
||||
float_v x;
|
||||
unsigned i;
|
||||
if (Rep(rde) != 3) {
|
||||
memcpy(&x, GetModrmRegisterXmmPointerRead16(m, rde), 16);
|
||||
for (i = 0; i < 4; ++i) x[i] = 1.f / x[i];
|
||||
|
@ -1551,7 +1551,7 @@ static float_v OpAddsubps(struct Machine *m, float_v x, float_v y) {
|
|||
}
|
||||
|
||||
static float_v OpMinps(struct Machine *m, float_v x, float_v y) {
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
x[i] = MIN(x[i], y[i]);
|
||||
}
|
||||
|
@ -1559,7 +1559,7 @@ static float_v OpMinps(struct Machine *m, float_v x, float_v y) {
|
|||
}
|
||||
|
||||
static double_v OpMinpd(struct Machine *m, double_v x, double_v y) {
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
x[i] = MIN(x[i], y[i]);
|
||||
}
|
||||
|
@ -1567,7 +1567,7 @@ static double_v OpMinpd(struct Machine *m, double_v x, double_v y) {
|
|||
}
|
||||
|
||||
static float_v OpMaxps(struct Machine *m, float_v x, float_v y) {
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
x[i] = MAX(x[i], y[i]);
|
||||
}
|
||||
|
@ -1575,7 +1575,7 @@ static float_v OpMaxps(struct Machine *m, float_v x, float_v y) {
|
|||
}
|
||||
|
||||
static double_v OpMaxpd(struct Machine *m, double_v x, double_v y) {
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
x[i] = MAX(x[i], y[i]);
|
||||
}
|
||||
|
@ -1721,9 +1721,10 @@ static void OpAlubFlipRo(struct Machine *m, uint32_t rde, int h) {
|
|||
}
|
||||
|
||||
static void OpAlubi(struct Machine *m, uint32_t rde, int h) {
|
||||
uint8_t *a;
|
||||
uint8_t *a, x;
|
||||
a = GetModrmRegisterBytePointerWrite(m, rde);
|
||||
Write8(a, Alu(0, h, Read8(a), m->xedd->op.uimm0, &m->flags));
|
||||
x = Alu(0, h, Read8(a), m->xedd->op.uimm0, &m->flags);
|
||||
if (h != ALU_CMP) Write8(a, x);
|
||||
}
|
||||
|
||||
static void OpAlubiRo(struct Machine *m, uint32_t rde, int h) {
|
||||
|
@ -1761,10 +1762,10 @@ static void OpAluwFlipRo(struct Machine *m, uint32_t rde, int h) {
|
|||
|
||||
static void OpAluwi(struct Machine *m, uint32_t rde, int h) {
|
||||
uint8_t *a;
|
||||
uint64_t x;
|
||||
a = GetModrmRegisterWordPointerWriteOszRexw(m, rde);
|
||||
WriteRegisterOrMemory(
|
||||
rde, a,
|
||||
Alu(RegLog2(rde), h, ReadMemory(rde, a), m->xedd->op.uimm0, &m->flags));
|
||||
x = Alu(RegLog2(rde), h, ReadMemory(rde, a), m->xedd->op.uimm0, &m->flags);
|
||||
if (h != ALU_CMP) WriteRegisterOrMemory(rde, a, x);
|
||||
}
|
||||
|
||||
static void OpAluwiRo(struct Machine *m, uint32_t rde, int h) {
|
||||
|
@ -1823,11 +1824,32 @@ static void OpTestRaxIvds(struct Machine *m, uint32_t rde) {
|
|||
&m->flags);
|
||||
}
|
||||
|
||||
long opcount[256 * 4];
|
||||
|
||||
void ExecuteInstruction(struct Machine *m) {
|
||||
uint32_t rde;
|
||||
m->ip += m->xedd->length;
|
||||
rde = m->xedd->op.rde;
|
||||
opcount[m->xedd->op.map << 8 | m->xedd->op.opcode]++;
|
||||
switch (m->xedd->op.map << 8 | m->xedd->op.opcode) {
|
||||
CASE(0x089, OpMovEvqpGvqp(m, rde));
|
||||
CASE(0x083, OpAluwi(m, rde, ModrmReg(rde)));
|
||||
CASR(0x070, if (GetCond(m, 0x0)) OpJmp(m));
|
||||
CASR(0x071, if (GetCond(m, 0x1)) OpJmp(m));
|
||||
CASR(0x072, if (GetCond(m, 0x2)) OpJmp(m));
|
||||
CASR(0x073, if (GetCond(m, 0x3)) OpJmp(m));
|
||||
CASR(0x074, if (GetCond(m, 0x4)) OpJmp(m));
|
||||
CASR(0x075, if (GetCond(m, 0x5)) OpJmp(m));
|
||||
CASR(0x076, if (GetCond(m, 0x6)) OpJmp(m));
|
||||
CASR(0x077, if (GetCond(m, 0x7)) OpJmp(m));
|
||||
CASR(0x078, if (GetCond(m, 0x8)) OpJmp(m));
|
||||
CASR(0x079, if (GetCond(m, 0x9)) OpJmp(m));
|
||||
CASR(0x07A, if (GetCond(m, 0xa)) OpJmp(m));
|
||||
CASR(0x07B, if (GetCond(m, 0xb)) OpJmp(m));
|
||||
CASR(0x07C, if (GetCond(m, 0xc)) OpJmp(m));
|
||||
CASR(0x07D, if (GetCond(m, 0xd)) OpJmp(m));
|
||||
CASR(0x07E, if (GetCond(m, 0xe)) OpJmp(m));
|
||||
CASR(0x07F, if (GetCond(m, 0xf)) OpJmp(m));
|
||||
CASR(0x0B0 ... 0x0B7, OpMovZbIb(m, rde));
|
||||
CASR(0x0B8 ... 0x0BF, OpMovZvqpIvqp(m, rde));
|
||||
CASR(0x050 ... 0x057, OpPushZvq(m, rde));
|
||||
|
@ -1891,32 +1913,14 @@ void ExecuteInstruction(struct Machine *m) {
|
|||
CASE(0x06D, OpString(m, rde, STRING_INS));
|
||||
CASE(0x06E, OpString(m, rde, STRING_OUTS));
|
||||
CASE(0x06F, OpString(m, rde, STRING_OUTS));
|
||||
CASR(0x070, if (GetCond(m, 0x0)) OpJmp(m));
|
||||
CASR(0x071, if (GetCond(m, 0x1)) OpJmp(m));
|
||||
CASR(0x072, if (GetCond(m, 0x2)) OpJmp(m));
|
||||
CASR(0x073, if (GetCond(m, 0x3)) OpJmp(m));
|
||||
CASR(0x074, if (GetCond(m, 0x4)) OpJmp(m));
|
||||
CASR(0x075, if (GetCond(m, 0x5)) OpJmp(m));
|
||||
CASR(0x076, if (GetCond(m, 0x6)) OpJmp(m));
|
||||
CASR(0x077, if (GetCond(m, 0x7)) OpJmp(m));
|
||||
CASR(0x078, if (GetCond(m, 0x8)) OpJmp(m));
|
||||
CASR(0x079, if (GetCond(m, 0x9)) OpJmp(m));
|
||||
CASR(0x07A, if (GetCond(m, 0xa)) OpJmp(m));
|
||||
CASR(0x07B, if (GetCond(m, 0xb)) OpJmp(m));
|
||||
CASR(0x07C, if (GetCond(m, 0xc)) OpJmp(m));
|
||||
CASR(0x07D, if (GetCond(m, 0xd)) OpJmp(m));
|
||||
CASR(0x07E, if (GetCond(m, 0xe)) OpJmp(m));
|
||||
CASR(0x07F, if (GetCond(m, 0xf)) OpJmp(m));
|
||||
CASR(0x080, OpAlubi(m, rde, ModrmReg(rde)));
|
||||
CASE(0x081, OpAluwi(m, rde, ModrmReg(rde)));
|
||||
CASR(0x082, OpAlubi(m, rde, ModrmReg(rde)));
|
||||
CASE(0x083, OpAluwi(m, rde, ModrmReg(rde)));
|
||||
CASR(0x084, OpAlubRo(m, rde, TEST));
|
||||
CASE(0x085, OpAluwRo(m, rde, TEST));
|
||||
CASE(0x086, OpXchgGbEb(m, rde));
|
||||
CASE(0x087, OpXchgGvqpEvqp(m, rde));
|
||||
CASE(0x088, OpMovEbGb(m, rde));
|
||||
CASE(0x089, OpMovEvqpGvqp(m, rde));
|
||||
CASE(0x08A, OpMovGbEb(m, rde));
|
||||
CASE(0x08B, OpMovGvqpEvqp(m, rde));
|
||||
CASE(0x08C, OpMovEvqpSw(m));
|
||||
|
|
|
@ -136,7 +136,7 @@ struct Machine {
|
|||
int64_t faultaddr;
|
||||
uint8_t stash[4096];
|
||||
uint8_t xmmtype[2][8];
|
||||
struct XedDecodedInst icache[512];
|
||||
struct XedDecodedInst icache[1024];
|
||||
struct MachineFds fds;
|
||||
};
|
||||
|
||||
|
|
|
@ -117,14 +117,13 @@ union MachineVector {
|
|||
void OpSse(struct Machine *m, uint32_t rde, enum OpSseKernel kernel) {
|
||||
int i;
|
||||
uint8_t *p;
|
||||
union MachineVector x, y, t;
|
||||
union MachineVector x, y;
|
||||
p = GetModrmRegisterXmmPointerRead16(m, rde);
|
||||
if (Osz(rde)) {
|
||||
memcpy(&y, p, 16);
|
||||
} else {
|
||||
memset(&t, 0, 16);
|
||||
memcpy(&t, p, 8);
|
||||
memcpy(&y, &t, 16);
|
||||
memset(&y, 0, 16);
|
||||
memcpy(&y, p, 8);
|
||||
}
|
||||
memcpy(&x, XmmRexrReg(m, rde), 16);
|
||||
switch (kernel) {
|
||||
|
|
|
@ -219,7 +219,7 @@ void LoadRelationships(int argc, char *argv[]) {
|
|||
}
|
||||
CHECK_NE(-1, fclose(finpaths));
|
||||
}
|
||||
free_s(&line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
void GetOpts(int argc, char *argv[]) {
|
||||
|
|
|
@ -106,9 +106,13 @@ static const struct addrinfo kResolvHints = {.ai_family = AF_INET,
|
|||
.ai_protocol = IPPROTO_TCP};
|
||||
|
||||
int g_sock;
|
||||
char *g_prog;
|
||||
char *g_runitd;
|
||||
jmp_buf g_jmpbuf;
|
||||
uint16_t g_sshport, g_runitdport;
|
||||
char *g_prog, *g_runitd, *g_ssh, g_hostname[128];
|
||||
uint16_t g_sshport;
|
||||
uint16_t g_runitdport;
|
||||
char g_ssh[PATH_MAX];
|
||||
char g_hostname[128];
|
||||
|
||||
forceinline pureconst size_t GreatestTwoDivisor(size_t x) {
|
||||
return x & (~x + 1);
|
||||
|
@ -389,7 +393,7 @@ int main(int argc, char *argv[]) {
|
|||
unreachable;
|
||||
}
|
||||
if (argc < 1 + 2) ShowUsage(stderr, EX_USAGE);
|
||||
CHECK_NOTNULL((g_ssh = commandv(firstnonnull(getenv("SSH"), "ssh"))));
|
||||
CHECK_NOTNULL(commandv(firstnonnull(getenv("SSH"), "ssh"), g_ssh));
|
||||
CheckExists((g_runitd = argv[1]));
|
||||
CheckExists((g_prog = argv[2]));
|
||||
if (argc == 1 + 2) return 0; /* hosts list empty */
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
PKGS += TOOL_DEBUG
|
||||
|
||||
TOOL_DEBUG_SRCS := $(wildcard tool/debug/*.c)
|
||||
TOOL_DEBUG_OBJS = $(TOOL_DEBUG_SRCS:%.c=o/$(MODE)/%.o)
|
||||
TOOL_DEBUG_COMS = $(TOOL_DEBUG_OBJS:%.o=%.com)
|
||||
|
||||
TOOL_DEBUG_DEPS := $(call uniq, \
|
||||
$(LIBC_STR) \
|
||||
$(LIBC_RUNTIME) \
|
||||
$(LIBC_STDIO) \
|
||||
$(LIBC_X) \
|
||||
$(LIBC_LOG))
|
||||
|
||||
TOOL_DEBUG_BINS = \
|
||||
$(TOOL_DEBUG_COMS) \
|
||||
$(TOOL_DEBUG_COMS:%=%.dbg)
|
||||
|
||||
o/$(MODE)/tool/debug/%.com.dbg: \
|
||||
$(TOOL_DEBUG_DEPS) \
|
||||
o/$(MODE)/tool/debug/%.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
$(TOOL_DEBUG_OBJS): \
|
||||
$(BUILD_FILES) \
|
||||
tool/debug/debug.mk
|
||||
|
||||
.PHONY: o/$(MODE)/tool/debug
|
||||
o/$(MODE)/tool/debug: $(TOOL_DEBUG_BINS) $(TOOL_DEBUG_CHECKS)
|
|
@ -169,7 +169,7 @@
|
|||
;; * mov $'c,%eax
|
||||
;; * mov $'\n,%eax
|
||||
;;
|
||||
("[ \t,]\\$\\(\\(?:'\\(?:'\\|\\s\"\\|\\s\\.\\|.\\)\\|\\(?:0x[[:xdigit:]]+\\|0b[01]+\\|[1-9][0-9]*\\|0[0-7]*\\)\\(?:[fb]\\|u?l?l?\\)\\|[-*/&^|()%<>~+]\\|[_.[:alpha:]][-_.[:alnum:]]*\\)+\\)"
|
||||
("[ \t,]\\$\\(\\(?:'\\(?:'\\|\\s\"\\|\\s\\.\\|.\\)\\|\\(?:0x[[:xdigit:]]+\\|0b[01]+\\|[1-9][0-9]*\\|0[0-7]*\\)\\(?:[fb]\\|u?l?l?\\)\\|[-*/&^|()%<>~+]\\|[_.$[:alpha:]][-_.[:alnum:]]*\\)+\\)"
|
||||
1 font-lock-constant-face)
|
||||
|
||||
(cosmo-asm-doctag-keywords)
|
||||
|
|
|
@ -230,6 +230,21 @@
|
|||
"__builtin_lround"
|
||||
"__builtin_lroundf"
|
||||
"__builtin_lroundl"
|
||||
"__builtin_nearbyint"
|
||||
"__builtin_nearbyintf"
|
||||
"__builtin_nearbyintl"
|
||||
"__builtin_scalbn"
|
||||
"__builtin_scalbnf"
|
||||
"__builtin_scalbnl"
|
||||
"__builtin_logb"
|
||||
"__builtin_logbf"
|
||||
"__builtin_logbl"
|
||||
"__builtin_fmax"
|
||||
"__builtin_fmaxf"
|
||||
"__builtin_fmaxl"
|
||||
"__builtin_fmin"
|
||||
"__builtin_fminf"
|
||||
"__builtin_fminl"
|
||||
"__builtin_rint"
|
||||
"__builtin_rintf"
|
||||
"__builtin_rintl"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
.PHONY: o/$(MODE)/tool
|
||||
o/$(MODE)/tool: \
|
||||
o/$(MODE)/tool/build \
|
||||
o/$(MODE)/tool/debug \
|
||||
o/$(MODE)/tool/decode \
|
||||
o/$(MODE)/tool/hash \
|
||||
o/$(MODE)/tool/net \
|
||||
|
|
|
@ -218,11 +218,11 @@ static void ReadAll(int fd, void *buf, size_t n) {
|
|||
static void LoadImageOrDie(const char *path, size_t size, long yn, long xn,
|
||||
unsigned char RGB[yn][xn][4]) {
|
||||
int pid, ws, fds[3];
|
||||
const char *convert;
|
||||
char *convert, pathbuf[PATH_MAX];
|
||||
if (isempty((convert = getenv("CONVERT"))) &&
|
||||
!(IsWindows() && access((convert = "\\msys64\\mingw64\\bin\\convert.exe"),
|
||||
X_OK) != -1) &&
|
||||
!(convert = commandv("convert"))) {
|
||||
!(convert = commandv("convert", pathbuf))) {
|
||||
fputs("'convert' command not found\r\n"
|
||||
"please install imagemagick\r\n",
|
||||
stderr);
|
||||
|
|
|
@ -488,8 +488,9 @@ static int ReadAll(int fd, void *data, size_t size) {
|
|||
static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn,
|
||||
unsigned char rgb[yn][YS][xn][XS][CN]) {
|
||||
const char *convert;
|
||||
char pathbuf[PATH_MAX];
|
||||
int pid, ws, fds[3] = {STDIN_FILENO, -1, STDERR_FILENO};
|
||||
if (!(convert = commandv("convert"))) {
|
||||
if (!(convert = commandv("convert", pathbuf))) {
|
||||
fputs("error: `convert` command not found\n"
|
||||
"try: apt-get install imagemagick\n",
|
||||
stderr);
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include "tool/viz/lib/formatstringtable.h"
|
||||
#include "tool/viz/lib/stringbuilder.h"
|
||||
|
||||
static void *ConvertMatrixToStringTable(long yn, long xn, char *T[yn][xn],
|
||||
const double M[yn][xn], double digs,
|
||||
double rounder(double)) {
|
||||
void *ConvertMatrixToStringTable(long yn, long xn, char *T[yn][xn],
|
||||
const double M[yn][xn], double digs,
|
||||
double rounder(double)) {
|
||||
double f;
|
||||
long y, x;
|
||||
assert(yn && xn && !T[0][0]);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "dsp/core/half.h"
|
||||
#include "dsp/core/illumination.h"
|
||||
#include "dsp/mpeg/mpeg.h"
|
||||
#include "dsp/mpeg/ycbcrio.h"
|
||||
#include "dsp/scale/scale.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "dsp/tty/tty.h"
|
||||
|
@ -772,21 +771,6 @@ static void RenderIt(void) {
|
|||
EndRender(p);
|
||||
}
|
||||
|
||||
static noinline void SaveMpegFrame(plm_frame_t *pf) {
|
||||
static long count;
|
||||
struct Ycbcrio *m;
|
||||
if (!count) {
|
||||
if (!isdirectory("o/frames")) {
|
||||
if (!isdirectory("o")) {
|
||||
CHECK_NE(-1, mkdir("o", 0755));
|
||||
}
|
||||
CHECK_NE(-1, mkdir("o/frames", 0755));
|
||||
}
|
||||
}
|
||||
m = YcbcrioOpen(gc(xasprintf("o/frames/%04ld.ycbcrio", (count++ % 100))), pf);
|
||||
YcbcrioClose(&m);
|
||||
}
|
||||
|
||||
static void RasterIt(void) {
|
||||
static bool once;
|
||||
static void *buf;
|
||||
|
@ -873,7 +857,6 @@ static void OnVideo(plm_t *mpeg, plm_frame_t *pf, void *user) {
|
|||
if (f2_->n) {
|
||||
WARNF("video frame dropped");
|
||||
} else {
|
||||
/* if (pf3_) SaveMpegFrame(pf); */
|
||||
TranscodeVideo(pf);
|
||||
if (!f1_->n) {
|
||||
xchg(&f1_, &f2_);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libc/macros.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/madv.h"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libc/macros.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/madv.h"
|
||||
|
|
|
@ -1,75 +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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/mpeg/ycbcrio.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
|
||||
#define USAGE \
|
||||
" [FLAGS] [PATH...]\n\
|
||||
\n\
|
||||
Flags:\n\
|
||||
-h shows this information\n\
|
||||
\n"
|
||||
|
||||
static char *inpath_;
|
||||
|
||||
static void PrintUsage(int rc, FILE *f) {
|
||||
fputs("Usage: ", f);
|
||||
fputs(program_invocation_name, f);
|
||||
fputs(USAGE, f);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static void GetOpts(int *argc, char *argv[]) {
|
||||
int opt;
|
||||
while ((opt = getopt(*argc, argv, "?h")) != -1) {
|
||||
switch (opt) {
|
||||
case '?':
|
||||
case 'h':
|
||||
PrintUsage(EXIT_SUCCESS, stdout);
|
||||
default:
|
||||
PrintUsage(EX_USAGE, stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessFile(struct Ycbcrio *m) {
|
||||
/* m->frame-> */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
size_t i;
|
||||
struct Ycbcrio *m;
|
||||
GetOpts(&argc, argv);
|
||||
for (i = optind; i < argc; ++i) {
|
||||
inpath_ = argv[i];
|
||||
m = YcbcrioOpen(inpath_, NULL);
|
||||
ProcessFile(m);
|
||||
YcbcrioClose(&m);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue