Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ BIN := kexp.bin
SRC_DIR := src
BUILD_DIR := build

KEXP_NO_PTHREADS ?= 0
CFLAGS := -O3 -Iinclude \
-fPIE -fcommon -fno-omit-frame-pointer -fno-zero-initialized-in-bss \
-ffreestanding -nostdlib -nostartfiles \
-Wall -Wextra -Werror -Wno-int-conversion
-Wall -Wextra -Werror -Wno-int-conversion \
-DKEXP_NO_PTHREADS=$(KEXP_NO_PTHREADS)

SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS)) $(BUILD_DIR)/syscalls.o
Expand All @@ -22,7 +24,7 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.S
$(CC) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/$(BIN): $(OBJS) script.ld
$(CC) $(CFLAGS) -Tscript.ld $(OBJS) -o $@

Expand Down
7 changes: 7 additions & 0 deletions src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ int init_loader_args() {
}

int run_loader() {

#if defined(KEXP_NO_PTHREADS) && KEXP_NO_PTHREADS == 1
log("calling elfldr entry directly @ %#lx", loader_ctx.entry);
int (*entry)(void *) = (int (*)(void *))loader_ctx.entry;
entry((void *)&loader_ctx.args);
# else
uintptr_t pthread;
uint32_t pthread_id;

Expand All @@ -267,6 +273,7 @@ int run_loader() {
notify("failed to join thread !!");
return -1;
}
#endif

notify("elfldr returned %#lx !!", *(uint64_t *)loader_ctx.args.ret);

Expand Down