Skip to content

Commit

Permalink
Squash a ton of warnings, including with gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 31, 2020
1 parent fcb0599 commit 6ae0170
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 33 deletions.
2 changes: 1 addition & 1 deletion emu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ static inline const char *reg32_name(enum reg32 reg) {
case reg_ebp: return "ebp";
case reg_esi: return "esi";
case reg_edi: return "edi";
case reg_none: return "?";
}
return "?";
}

#endif
1 change: 1 addition & 0 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
CMPXCHG8B(modrm_val,64); break;
default: UNDEFINED;
};
break;

#if OP_SIZE != 16
case 0xc8: TRACEI("bswap eax");
Expand Down
2 changes: 1 addition & 1 deletion emu/float80.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static int unbias_denormal(unsigned exp) {

__thread enum f80_rounding_mode f80_rounding_mode;

static bool round_away_from_zero(sign) {
static bool round_away_from_zero(int sign) {
return (f80_rounding_mode == round_up && !sign) ||
(f80_rounding_mode == round_down && sign);
}
Expand Down
2 changes: 1 addition & 1 deletion emu/fpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum fpu_const {
fconst_ln2 = 5,
fconst_zero = 6,
};
static float80 fpu_consts[] = {
static const float80 fpu_consts[] = {
[fconst_one] = (float80) {.signif = 0x8000000000000000, .signExp = 0x3fff},
[fconst_log2t] = (float80) {.signif = 0xd49a784bcd1b8afe, .signExp = 0x4000},
[fconst_log2e] = (float80) {.signif = 0xb8aa3b295c17f0bc, .signExp = 0x3fff},
Expand Down
12 changes: 5 additions & 7 deletions emu/modrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
struct modrm {
union {
enum reg32 reg;
int opcode;
unsigned opcode;
};
enum {
modrm_reg, modrm_mem, modrm_mem_si
} type;
union {
enum reg32 base;
int rm_opcode;
unsigned rm_opcode;
};
int32_t offset;
enum reg32 index;
Expand All @@ -30,11 +30,9 @@ struct modrm {
} shift;
};

enum {
rm_sib = reg_esp,
rm_none = reg_esp,
rm_disp32 = reg_ebp,
};
static const unsigned rm_sib = reg_esp;
static const unsigned rm_none = reg_esp;
static const unsigned rm_disp32 = reg_ebp;
#define MOD(byte) ((byte & 0b11000000) >> 6)
#define REG(byte) ((byte & 0b00111000) >> 3)
#define RM(byte) ((byte & 0b00000111) >> 0)
Expand Down
6 changes: 6 additions & 0 deletions fs/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,13 @@ const struct fd_ops socket_fdops = {
.ioctl = realfs_ioctl,
};

#if defined(__GNUC__)
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#else
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
#endif
static struct socket_call {
syscall_t func;
int args;
Expand Down
6 changes: 4 additions & 2 deletions fs/tty-real.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

void real_tty_reset_term(void);

static void real_tty_read_thread(struct tty *tty) {
static void *real_tty_read_thread(void *_tty) {
struct tty *tty = _tty;
char ch;
for (;;) {
int err = read(STDIN_FILENO, &ch, 1);
Expand All @@ -32,6 +33,7 @@ static void real_tty_read_thread(struct tty *tty) {
}
tty_input(tty, &ch, 1, 0);
}
return NULL;
}

static struct termios_ termios_from_real(struct termios real) {
Expand Down Expand Up @@ -109,7 +111,7 @@ static int real_tty_init(struct tty *tty) {
ERRNO_DIE("failed to set terminal to raw mode");
notty:

if (pthread_create(&tty->thread, NULL, (void *(*)(void *)) real_tty_read_thread, tty) < 0)
if (pthread_create(&tty->thread, NULL, real_tty_read_thread, tty) < 0)
// ok if this actually happened it would be weird AF
return _EIO;
pthread_detach(tty->thread);
Expand Down
5 changes: 3 additions & 2 deletions fs/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ static int tty_mode_ioctl(struct tty *in_tty, int cmd, void *arg) {
case TCSETSF_:
tty->bufsize = 0;
notify(&tty->consumed);
fallthrough;
case TCSETSW_:
// we have no output buffer currently
case TCSETS_:
Expand Down Expand Up @@ -704,7 +705,7 @@ static int tty_ioctl(struct fd *fd, int cmd, void *arg) {
switch (cmd) {
case TCFLSH_:
// only input flushing is currently useful
switch ((dword_t) arg) {
switch ((uintptr_t) arg) {
case TCIFLUSH_:
case TCIOFLUSH_:
tty->bufsize = 0;
Expand All @@ -719,7 +720,7 @@ static int tty_ioctl(struct fd *fd, int cmd, void *arg) {
break;

case TIOCSCTTY_:
err = tiocsctty(tty, (dword_t) arg);
err = tiocsctty(tty, (uintptr_t) arg);
break;

case TIOCGPRGP_:
Expand Down
3 changes: 3 additions & 0 deletions kernel/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ dword_t syscall_success_stub() {
return 0;
}

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
syscall_t syscall_table[] = {
[1] = (syscall_t) sys_exit,
[2] = (syscall_t) sys_fork,
Expand Down
2 changes: 1 addition & 1 deletion kernel/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int do_syslog(int type, addr_t buf_addr, int_t len) {
res = syslog_read(buf_addr, len, FIFO_LAST | FIFO_PEEK);
if (res < 0)
return res;
// fallthrough
fallthrough;
case SYSLOG_ACTION_CLEAR_:
log_max_since_clear = 0;
return 0;
Expand Down
22 changes: 16 additions & 6 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "kernel/vdso.h"
#include "emu/interrupt.h"

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#endif

int xsave_extra = 0;
int fxsave_extra = 0;
static void sigmask_set(sigset_t_ set);
Expand Down Expand Up @@ -285,9 +289,10 @@ static void receive_signal(struct sighand *sighand, struct siginfo_ *info) {
}

// install frame
(void) user_write(sp, &frame, frame_size);
// nothing we can do if that fails
// TODO do something other than nothing, like printk maybe
if (user_write(sp, &frame, frame_size)) {
printk("failed to install frame for %d at %#x\n", info->sig, sp);
deliver_signal(current, SIGSEGV_, SIGINFO_NIL);
}
}

void receive_signals() {
Expand Down Expand Up @@ -356,7 +361,10 @@ dword_t sys_rt_sigreturn() {
struct cpu_state *cpu = &current->cpu;
struct rt_sigframe_ frame;
// esp points past the first field of the frame
(void) user_get(cpu->esp - offsetof(struct rt_sigframe_, sig), frame);
if (user_get(cpu->esp - offsetof(struct rt_sigframe_, sig), frame)) {
deliver_signal(current, SIGSEGV_, SIGINFO_NIL);
return _EFAULT;
}
restore_sigcontext(&frame.uc.mcontext, cpu);

lock(&current->sighand->lock);
Expand All @@ -375,8 +383,10 @@ dword_t sys_sigreturn() {
struct cpu_state *cpu = &current->cpu;
struct sigframe_ frame;
// esp points past the first two fields of the frame
(void) user_get(cpu->esp - offsetof(struct sigframe_, sc), frame);
// TODO check for errors in that
if (user_get(cpu->esp - offsetof(struct sigframe_, sc), frame)) {
deliver_signal(current, SIGSEGV_, SIGINFO_NIL);
return _EFAULT;
}
restore_sigcontext(&frame.sc, cpu);

lock(&current->sighand->lock);
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
project('ish', 'c',
default_options: ['default_library=static', 'c_std=gnu11', 'warning_level=2'])

if meson.get_compiler('c').get_id() == 'clang'
add_project_arguments('-Wimplicit-fallthrough', '-Wtautological-constant-in-range-compare', language: 'c')
endif

log_on = get_option('log').split()
log_off = get_option('nolog').split()
foreach channel : log_on + log_off
Expand Down
11 changes: 10 additions & 1 deletion misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@
#define unlikely(x) __builtin_expect((x), 0)
#define typecheck(type, x) ({type _x = x; x;})
#define must_check __attribute__((warn_unused_result))
#define fallthrough __attribute__((fallthrough))

#if defined(__has_attribute) && __has_attribute(no_sanitize)
#define __no_instrument __attribute__((no_sanitize("address", "thread", "undefined", "leak", "memory")))
#define __no_instrument_msan
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
#undef __no_instrument_msan
#define __no_instrument_msan __attribute__((no_sanitize("memory"))
#endif
#endif
#define __no_instrument __attribute__((no_sanitize("address", "thread", "undefined", "leak"))) __no_instrument_msan
#else
#define __no_instrument
#endif
Expand Down
24 changes: 15 additions & 9 deletions tools/ptraceomatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,15 @@ static void remote_close_fd(int pid, int fd, long int80_ip) {
setregs(pid, &regs);
}

#define _ignore(x) {}; int UNUSED(x) =
#define ignore _ignore(__COUNTER__)

static void pt_copy(int pid, addr_t start, size_t size) {
if (start == 0)
return;
byte_t byte;
for (addr_t addr = start; addr < start + size; addr++) {
(void) user_get(addr, byte);
ignore user_get(addr, byte);
pt_write8(pid, addr, byte);
}
}
Expand All @@ -248,7 +251,7 @@ static void pt_copy_to_real(int pid, addr_t start, size_t size) {
byte_t byte;
for (addr_t addr = start; addr < start + size; addr++) {
pt_readn(pid, addr, &byte, sizeof(byte));
(void) user_put(addr, byte);
ignore user_put(addr, byte);
}
}

Expand Down Expand Up @@ -321,19 +324,19 @@ static void step_tracing(struct cpu_state *cpu, struct tlb *tlb, int pid, int se
pt_copy(pid, regs.rcx, regs.rdx); break;
case 102: { // socketcall
dword_t args[6];
(void) user_get(regs.rcx, args);
ignore user_get(regs.rcx, args);
dword_t len;
switch (cpu->ebx) {
case 6: // getsockname
(void) user_get(args[2], len);
;ignore user_get(args[2], len);
pt_copy(pid, args[1], len);
break;
case 8: // socketpair
pt_copy(pid, args[3], sizeof(dword_t[2]));
break;
case 12: // recvfrom
pt_copy(pid, args[1], args[2]);
(void) user_get(args[5], len);
ignore user_get(args[5], len);
pt_copy(pid, args[4], len);
break;
}
Expand All @@ -349,7 +352,7 @@ static void step_tracing(struct cpu_state *cpu, struct tlb *tlb, int pid, int se
pt_copy(pid, regs.rsi, 8); break;
case 145: { // readv
struct iovec_ vecs[regs.rdx];
(void) user_get(regs.rcx, vecs);
ignore user_get(regs.rcx, vecs);
for (unsigned i = 0; i < regs.rdx; i++)
pt_copy(pid, vecs[i].base, vecs[i].len);
break;
Expand All @@ -361,7 +364,8 @@ static void step_tracing(struct cpu_state *cpu, struct tlb *tlb, int pid, int se
case 183: // getcwd
pt_copy(pid, regs.rbx, cpu->eax); break;
case 186: // sigaltstack
if (regs.rcx != 0) pt_copy(pid, regs.rcx, sizeof(struct stack_t_)); break;
if (regs.rcx != 0) pt_copy(pid, regs.rcx, sizeof(struct stack_t_));
break;
case 195: // stat64
case 196: // lstat64
case 197: // fstat64
Expand All @@ -375,9 +379,11 @@ static void step_tracing(struct cpu_state *cpu, struct tlb *tlb, int pid, int se
case 300: // fstatat64
pt_copy(pid, regs.rdx, sizeof(struct newstat64)); break;
case 305: // readlinkat
if (cpu->eax < 0xffff000) pt_copy(pid, regs.rdx, cpu->eax); break;
if (cpu->eax < 0xffff000) pt_copy(pid, regs.rdx, cpu->eax);
break;
case 340: // prlimit
if (regs.rsi != 0) pt_copy(pid, regs.rsi, sizeof(struct rlimit_)); break;
if (regs.rsi != 0) pt_copy(pid, regs.rsi, sizeof(struct rlimit_));
break;
case 355: // getrandom
pt_copy(pid, regs.rbx, regs.rcx); break;

Expand Down
2 changes: 0 additions & 2 deletions xX_main_Xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static inline int xX_main_Xx(int argc, char *const argv[], const char *envp) {
// parse cli options
int opt;
const char *root = NULL;
bool has_root = false;
const char *workdir = NULL;
const struct fs_ops *fs = &realfs;
const char *console = "/dev/tty1";
Expand All @@ -55,7 +54,6 @@ static inline int xX_main_Xx(int argc, char *const argv[], const char *envp) {
case 'r':
case 'f':
root = optarg;
has_root = true;
if (opt == 'f')
fs = &fakefs;
break;
Expand Down

0 comments on commit 6ae0170

Please sign in to comment.