提交 23869406 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

ugh: runtime support for c++ exception handling

(links, but crashes if an exception is thrown).
上级 2a78d8e2
......@@ -32,7 +32,7 @@ COMFLAGS = -static -g -MD -m64 -O3 -Wall -Werror -DHW_$(HW) -DXV6 \
-mno-sse -mcx16 -mno-red-zone $(INCLUDES)
COMFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) -nostdinc -I$(shell $(CC) -print-file-name=include)
CFLAGS := $(COMFLAGS) -std=c99 $(CFLAGS)
CXXFLAGS := $(COMFLAGS) -std=c++0x -Wno-sign-compare -fno-exceptions -fno-rtti -fcheck-new -nostdinc++ $(CXXFLAGS)
CXXFLAGS := $(COMFLAGS) -std=c++0x -Wno-sign-compare -fno-rtti -fcheck-new -nostdinc++ $(CXXFLAGS)
ASFLAGS = -Iinclude -I$(O)/include -m64 -gdwarf-2 -MD -DHW_$(HW) -include param.h
LDFLAGS = -m elf_x86_64
......
$(O)/bin/%.o: CFLAGS:=$(CFLAGS) -DXV6_USER
$(O)/bin/%.o: CXXFLAGS:=$(CXXFLAGS) -DXV6_USER
$(O)/bin/%.o: CXXFLAGS:=$(CXXFLAGS) -DXV6_USER -fno-exceptions
UPROGS= \
bench \
......
......@@ -219,7 +219,7 @@ char* safestrcpy(char*, const char*, size_t);
extern "C" unsigned int strlen(const char*);
int strncmp(const char*, const char*, size_t);
char* strncpy(char*, const char*, size_t);
int strcmp(const char *p, const char *q);
extern "C" int strcmp(const char *p, const char *q);
// swtch.S
void swtch(struct context**, struct context*);
......
......@@ -58,13 +58,15 @@ KERN = $(O)/kernel.elf
ALL += $(KERN)
$(O)/kernel/%.o: CFLAGS+=-mcmodel=kernel -DXV6_KERNEL
$(O)/kernel/%.o: CXXFLAGS+=-mcmodel=kernel -DXV6_KERNEL
$(O)/kernel/%.o: CXXFLAGS+=-mcmodel=kernel -DXV6_KERNEL -fno-exceptions
$(KERN): $(O)/kernel/boot.o $(OBJS) $(LDEPS) kernel/kernel.ld
@echo " LD $@"
$(Q)mkdir -p $(@D)
$(Q)$(LD) $(LDFLAGS) -T kernel/kernel.ld -z max-page-size=4096 -e start \
-o $@ $(O)/kernel/boot.o $(OBJS) -L$(O) $(LFLAGS)
# $(shell $(CC) -print-file-name=libgcc_eh.a) \
# $(shell $(CC) -print-file-name=libsupc++.a)
$(O)/kernel/%.o: lib/%.cc
@echo " CXX $@"
......
......@@ -26,34 +26,12 @@ __cxa_pure_virtual(void)
panic("__cxa_pure_virtual");
}
int
__cxa_guard_acquire(s64 *guard)
{
volatile u8 *x = (u8*) guard;
volatile u32 *l = (u32*) (x+4);
pushcli();
while (xchg32(l, 1) != 0)
; /* spin */
if (*x) {
xchg32(l, 0);
popcli();
return 0;
}
return 1;
}
void
__cxa_guard_release(s64 *guard)
// Ugh: libsupc++ calls syscall(SYS_futex, ...)
extern "C" u64 syscall(void);
u64
syscall(void)
{
volatile u8 *x = (u8*) guard;
volatile u32 *l = (u32*) (x+4);
*x = 1;
__sync_synchronize();
xchg32(l, 0);
popcli();
return 0;
}
int
......@@ -91,3 +69,99 @@ atomic<u128>::compare_exchange_weak(u128 &__i1, u128 i2, memory_order __m)
}
};
extern "C" void abort(void);
void
abort(void)
{
panic("abort");
}
extern "C" void* malloc(size_t);
void*
malloc(size_t n)
{
u64* p = (u64*) kmalloc(n+8, "cpprt malloc");
*p = n;
return p+1;
}
extern "C" void free(void*);
void
free(void* vp)
{
u64* p = (u64*) vp;
kmfree(vp, p[-1]);
}
extern "C" void* realloc(void*, size_t);
void*
realloc(void* vp, size_t n)
{
u64* p = (u64*) vp;
u64* np = (u64*) malloc(n);
memcpy(np, p, p[-1]);
free(p);
return np;
}
extern "C" int dl_iterate_phdr(void);
int
dl_iterate_phdr(void)
{
return -1;
}
extern "C" int __sprintf_chk(char* buf, int flags, size_t n, const char* fmt, ...);
int
__sprintf_chk(char* buf, int flags, size_t n, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, n, fmt, ap);
va_end(ap);
return 0; // XXX
}
extern "C" void __stack_chk_fail(void);
void
__stack_chk_fail(void)
{
panic("stack_chk_fail");
}
extern "C" char* strcpy(char*, const char*);
char*
strcpy(char* dst, const char* src)
{
return strncpy(dst, src, __SIZE_MAX__);
}
// stdio stubs to satisfy libsupc++
int stderr = 1;
extern "C" int fputc(int c, int stream);
int
fputc(int c, int stream)
{
cprintf("%c", (u8) c);
return (u8) c;
}
extern "C" size_t fwrite(const void* buf, size_t n, size_t nmemb, int stream);
size_t
fwrite(const void* buf, size_t n, size_t nmemb, int stream)
{
cprintf("%s", (char*) buf);
return n;
}
extern "C" int fputs(const char* s, int stream);
int
fputs(const char* s, int stream)
{
cprintf("%s", s);
return 0;
}
$(O)/lib/%.o: CFLAGS:=$(CFLAGS) -DXV6_USER
$(O)/lib/%.o: CXXFLAGS:=$(CXXFLAGS) -DXV6_USER
$(O)/lib/%.o: CXXFLAGS:=$(CXXFLAGS) -DXV6_USER -fno-exceptions
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o fmt.o stream.o ipc.o \
threads.o crt.o wqlib.o wquser.o perf.o wqalloc.o rt.o
threads.o crt.o wqlib.o wquser.o perf.o wqalloc.o
ULIB := $(addprefix $(O)/lib/, $(ULIB))
.PRECIOUS: $(O)/lib/%.o
......
#include "types.h"
#include "user.h"
void
abort(void)
{
char* p = (char*) 1;
*p = 1;
exit();
}
int
dl_iterate_phdr(void)
{
return -1;
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论