Refactor some code

- Write tests for cthreads
- Fix bugs in pe2.com tool
- Fix ASAN issue with GetDosEnviron()
- Consolidate the cthread header files
- Some code size optimizations for MODE=
- Attempted to squash a tls linker warning
- Attempted to get futexes working on FreeBSD
This commit is contained in:
Justine Tunney 2022-05-28 05:50:01 -07:00
parent 909e54510d
commit 425ff5dff0
61 changed files with 529 additions and 382 deletions

View file

@ -164,6 +164,14 @@ o//libc/calls/fcntl.o: \
OVERRIDE_CFLAGS += \
-Os
# we always want -Os because:
# it's early runtime mandatory and quite huge without it
o//libc/calls/getcwd.greg.o \
o//libc/calls/getcwd-nt.greg.o \
o//libc/calls/getcwd-xnu.greg.o: \
OVERRIDE_CFLAGS += \
-Os
LIBC_CALLS_LIBS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)))
LIBC_CALLS_SRCS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_SRCS))
LIBC_CALLS_HDRS = $(foreach x,$(LIBC_CALLS_ARTIFACTS),$($(x)_HDRS))

View file

@ -28,18 +28,28 @@
#define XNU_F_GETPATH 50
#define XNU_MAXPATHLEN 1024
static inline bool CopyString(char *d, const char *s, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
if (!(d[i] = s[i])) {
return true;
}
}
return false;
}
char *sys_getcwd_xnu(char *res, size_t size) {
int fd;
union metastat st[2];
char buf[XNU_MAXPATHLEN], *ret = NULL;
if ((fd = sys_openat(AT_FDCWD, ".", O_RDONLY | O_DIRECTORY, 0)) != -1) {
if (__sys_fstat(fd, &st[0]) != -1) {
if (METASTAT(st[0], st_dev) && METASTAT(st[0], st_ino)) {
if (st[0].xnu.st_dev && st[0].xnu.st_ino) {
if (__sys_fcntl(fd, XNU_F_GETPATH, (uintptr_t)buf) != -1) {
if (__sys_fstatat(AT_FDCWD, buf, &st[1], 0) != -1) {
if (METASTAT(st[0], st_dev) == METASTAT(st[1], st_dev) &&
METASTAT(st[0], st_ino) == METASTAT(st[1], st_ino)) {
if (memccpy(res, buf, '\0', size)) {
if (st[0].xnu.st_dev == st[1].xnu.st_dev &&
st[0].xnu.st_ino == st[1].xnu.st_ino) {
if (CopyString(res, buf, size)) {
ret = res;
} else {
erange();