Skip to content

Commit 70cdd08

Browse files
committed
cleaned up some code that was causing warnings etc.
1 parent 80fadc4 commit 70cdd08

File tree

6 files changed

+20
-33
lines changed

6 files changed

+20
-33
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interp:
2929
$(CC) $(GCC_OPTS) shiva_transform.c -o shiva_transform.o
3030
$(CC) $(GCC_OPTS) shiva_so.c -o shiva_so.o
3131
$(CC) $(GCC_OPTS) -fno-stack-protector shiva_post_linker.c -o shiva_post_linker.o
32-
$(MUSL) -static -Wl,-undefined=system -Wl,-undefined=prctl -Wl,-undefined=pause -Wl,-undefined=puts -Wl,-undefined=putchar $(OBJ_LIST) $(STATIC_LIBS) -o $(BUILD_DIR)/shiva
32+
$(MUSL) -static $(OBJ_LIST) $(STATIC_LIBS) -o $(BUILD_DIR)/shiva
3333

3434
shiva-ld:
3535
make -C tools/shiva-ld

shiva.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,11 @@ struct shiva_trace_handler * shiva_trace_find_handler(struct shiva_ctx *, void *
803803
struct shiva_trace_bp * shiva_trace_bp_struct(void *);
804804
bool shiva_trace_set_breakpoint(shiva_ctx_t *, void * (*)(void *), uint64_t, void *, shiva_error_t *);
805805
bool shiva_trace_write(struct shiva_ctx *, pid_t, void *, const void *, size_t, shiva_error_t *);
806+
#if __x86_64__
806807
void __attribute__((naked)) shiva_trace_getregs_x86_64(struct shiva_trace_regset_x86_64 *);
807808
void __attribute__((naked)) shiva_trace_setjmp_x86_64(shiva_trace_jumpbuf_t *);
808809
void shiva_trace_longjmp_x86_64(shiva_trace_jumpbuf_t *jumpbuf, uint64_t ip);
810+
#endif
809811
uint64_t shiva_trace_base_addr(struct shiva_ctx *);
810812
/*
811813
* shiva_trace_thread.c
@@ -835,3 +837,8 @@ bool shiva_so_resolve_symbol(struct shiva_module *, char *, struct elf_symbol *,
835837
*/
836838
void shiva_post_linker(void);
837839
#endif
840+
841+
/*
842+
* debug stub to set breakpoints on.
843+
*/
844+
int test_mark(void);

shiva_analyze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ shiva_analyze_find_calls(struct shiva_ctx *ctx)
460460
symbol.bind = STB_GLOBAL;
461461
symbol.type = STT_OBJECT;
462462
symbol.visibility = STV_PROTECTED;
463-
if (elf_section_index_by_name(&ctx->elfobj, shdr.name, &symbol.shndx)
463+
if (elf_section_index_by_name(&ctx->elfobj, shdr.name, (uint64_t *)&symbol.shndx)
464464
== false) {
465465
fprintf(stderr, "Failed to find section index for %s in %s\n",
466466
shdr.name, elf_pathname(&ctx->elfobj));

shiva_module.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ resolve_pltgot_entries(struct shiva_module *linker)
590590

591591
shiva_debug("Symbol '%s' is a PLT entry, let's look it up in the shared libraries\n",
592592
symbol.name);
593-
res = shiva_so_resolve_symbol(linker, symbol.name, &tmp, &so_path);
593+
res = shiva_so_resolve_symbol(linker, (char *)symbol.name, &tmp, &so_path);
594594
if (res == false) {
595595
fprintf(stderr, "Failed to resolve symbol '%s' in shared libs\n",
596596
symbol.name);
@@ -640,7 +640,7 @@ resolve_pltgot_entries(struct shiva_module *linker)
640640
struct elf_symbol tmp;
641641
char path_out[PATH_MAX];
642642

643-
res = shiva_so_resolve_symbol(linker, symbol.name, &tmp, &so_path);
643+
res = shiva_so_resolve_symbol(linker, (char *)symbol.name, &tmp, &so_path);
644644
if (res == false) {
645645
fprintf(stderr, "Failed to resolve symbol '%s' in shared libs\n",
646646
symbol.name);
@@ -830,7 +830,7 @@ internal_symresolve(struct shiva_module *linker, char *symname,
830830
} else if (res == false && linker->mode == SHIVA_LINKING_MICROCODE_PATCH) {
831831
char *so_path;
832832

833-
res = shiva_so_resolve_symbol(linker, symname, &tmp, &so_path);
833+
res = shiva_so_resolve_symbol(linker, (char *)symname, &tmp, &so_path);
834834
if (res == true) {
835835
*type = RESOLVER_TARGET_SO_RESOLVE;
836836
*e_type = ET_DYN;
@@ -1098,7 +1098,7 @@ apply_relocation(struct shiva_module *linker, struct elf_relocation rel,
10981098
* Insert this as a delayed relocation so that the
10991099
* shiva_post_linker code can handle it later.
11001100
*/
1101-
res = shiva_so_resolve_symbol(linker, symbol.name, &tmp, &so_path);
1101+
res = shiva_so_resolve_symbol(linker, (char *)symbol.name, &tmp, &so_path);
11021102
if (res == false) {
11031103
fprintf(stderr, "Failed to resolve symbol '%s' in shared libs\n",
11041104
symbol.name);
@@ -1668,7 +1668,7 @@ calculate_bss_size(struct shiva_module *linker, size_t *out)
16681668
if (hsearch_r(e, FIND, &ep, &linker->cache.bss) != 0)
16691669
continue;
16701670
bss_entry = shiva_malloc(sizeof(*bss_entry));
1671-
bss_entry->symname = symbol.name;
1671+
bss_entry->symname = (char *)symbol.name;
16721672
bss_entry->addr = linker->bss_vaddr + var_offset;
16731673
bss_entry->offset = var_offset;
16741674
var_offset += symbol.size;
@@ -2409,7 +2409,7 @@ validate_transformations(struct shiva_ctx *ctx, struct shiva_module *linker)
24092409
sizeof(struct elf_symbol));
24102410
memcpy(&transform->source_symbol, &tf_sym,
24112411
sizeof(struct elf_symbol));
2412-
transform->name = target_sym.name;
2412+
transform->name = (char *)target_sym.name;
24132413
transform->ptr = NULL;
24142414
shiva_debug("Source symbol '%s' value: %zu size: %zu\n",
24152415
transform->source_symbol.name, transform->source_symbol.value, transform->source_symbol.size);
@@ -2579,7 +2579,7 @@ validate_transformations(struct shiva_ctx *ctx, struct shiva_module *linker)
25792579
transform->source_symbol.value);
25802580
if (elf_section_by_name(&linker->elfobj, ".text", &text_shdr) == false) {
25812581
fprintf(stderr,
2582-
"elf_section_by_name(%p, \".text\", ...) failed\n");
2582+
"elf_section_by_name(%p, \".text\", ...) failed\n", &linker->elfobj);
25832583
return false;
25842584
}
25852585
if (next_func.value == transform->source_symbol.value) {

shiva_post_linker.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ shiva_post_linker(void)
6161
ELF_PAGEALIGN(ctx_global->module.runtime->text_size,
6262
PAGE_SIZE),
6363
PROT_READ|PROT_EXEC) < 0) {
64+
fprintf(stderr, "shiva_post_linker() Unable to mark text as read-only\n");
6465
perror("mprotect");
65-
return false;
66+
exit(EXIT_FAILURE);
6667
}
6768

6869
__asm__ __volatile__ ("mov x21, %0" :: "r"(ctx_global->ulexec.entry_point));

shiva_trace.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ static bool shiva_trace_op_peek(struct shiva_ctx *, pid_t,
77
* XXX FIXME
88
* temporary version.
99
*/
10+
#if __x86_64__
1011
void __attribute__((naked)) shiva_trace_getregs_x86_64(struct shiva_trace_regset_x86_64 *regs)
1112
{
12-
#if defined(__x86_64__)
1313
__asm__ __volatile__(
1414
"movq %rax, (%rdi)\n\t"
1515
"movq %rbx, 8(%rdi)\n\t"
@@ -26,7 +26,6 @@ void __attribute__((naked)) shiva_trace_getregs_x86_64(struct shiva_trace_regset
2626
"movq %r15, 104(%rdi)\n\t"
2727
"ret\n\t"
2828
);
29-
#endif
3029
}
3130

3231
/*
@@ -37,7 +36,6 @@ void __attribute__((naked)) shiva_trace_getregs_x86_64(struct shiva_trace_regset
3736
*/
3837
void __attribute__ ((naked)) shiva_trace_setjmp_x86_64(shiva_trace_jumpbuf_t *jmpbuf)
3938
{
40-
#if defined(__x86_64__)
4139
__asm__ __volatile__(
4240
"movq %rax, 0(%rdi)\n\t"
4341
"movq %rbx, 8(%rdi)\n\t"
@@ -58,12 +56,10 @@ void __attribute__ ((naked)) shiva_trace_setjmp_x86_64(shiva_trace_jumpbuf_t *jm
5856
"xor %rax, %rax\n\t"
5957
"ret\n\t"
6058
);
61-
#endif
6259
}
6360

6461
void shiva_trace_longjmp_x86_64(shiva_trace_jumpbuf_t *jumpbuf, uint64_t ip)
6562
{
66-
#if defined(__x86_64__)
6763
__asm__ __volatile__(
6864
"movq 0(%rdi), %rax\n\t"
6965
"movq 8(%rdi), %rbx\n\t"
@@ -84,8 +80,8 @@ void shiva_trace_longjmp_x86_64(shiva_trace_jumpbuf_t *jumpbuf, uint64_t ip)
8480
__asm__ __volatile__ (
8581
"movq %0, %%rdx\n\t"
8682
"jmp *%%rdx" :: "r"(ip));
87-
#endif
8883
}
84+
#endif
8985

9086
uint64_t
9187
shiva_trace_base_addr(struct shiva_ctx *ctx)
@@ -510,28 +506,11 @@ shiva_trace_set_breakpoint(struct shiva_ctx *ctx, void * (*handler_fn)(void *),
510506
*/
511507
bp->plt_addr = branch_site->target_vaddr;
512508

513-
#if 0
514509
/*
515510
* We cannot use an hcreate cache because there's
516511
* some incompatibility when using it cross module
517512
* execution.
518513
*/
519-
val = branch_site->retaddr + ctx->ulexec.base_vaddr;
520-
sprintf(tmp, "%#lx", val);
521-
memcpy(ptr_val, &val, sizeof(val));
522-
e.key = (char *)tmp;
523-
e.data = (void *)ptr_val;
524-
printf("Adding PLT retaddr %s to cache\n", e.key);
525-
printf("data: %#lx\n", *(uint64_t *)e.data);
526-
if (hsearch_r(e, ENTER, &ep, &bp->valid_plt_retaddrs) == 0) {
527-
shiva_error_set(error, "hsearch_r failed: %s\n",
528-
strerror(errno));
529-
return false;
530-
}
531-
if (hsearch_r(e, FIND, &ep, &bp->valid_plt_retaddrs) != 0) {
532-
printf("FOUND IT: data: %#lx\n", *(uint64_t *)e.data);
533-
}
534-
#endif
535514
}
536515
}
537516
TAILQ_INSERT_TAIL(&current->bp_tqlist, bp, _linkage);

0 commit comments

Comments
 (0)