Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'fs-lzma' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Feb 1, 2018
2 parents e619520 + 8e69267 commit 3a5e448
Show file tree
Hide file tree
Showing 532 changed files with 317,331 additions and 157 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ addons:
- llvm-5.0-dev
- lld-5.0
- liblz4-dev
- squashfs-tools
- graphviz
- python3
- python3-pip

install:
# Set postfix variable
- export LLVM_POSTFIX=-5.0
Expand All @@ -47,7 +47,7 @@ install:
- |
if [[ ${TRAVIS_OS_NAME} == "osx" ]]; then
export LLVM_POSTFIX="";
brew install llvm qemu lz4 python3
brew install llvm qemu lz4 python3 squashfs
export PATH="/usr/local/opt/llvm/bin:$PATH";
fi
Expand Down
139 changes: 12 additions & 127 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
include libtransistor.mk

libtransistor_TESTS := malloc bsd_ai_packing bsd sfdnsres nv helloworld hid hexdump args ssp stdin multiple_set_heap_size vi gpu display am sdl audio_output init_fini_arrays ipc_server pthread
libtransistor_OBJECT_NAMES := crt0_common.o svc.o ipc.o tls.o util.o ipc/sm.o ipc/bsd.o ipc/nv.o ipc/hid.o ipc/ro.o ipc/nifm.o hid.o ipc/vi.o display/binder.o display/parcel.o display/surface.o gpu/gpu.o ipc/am.o display/graphic_buffer_queue.o display/display.o gfx/blit.o ipc/time.o syscalls/syscalls.o syscalls/fd.o syscalls/sched.o syscalls/socket.o ipc/audio.o ipc/bpc.o ipcserver.o
libtransistor_OBJECT_FILES := $(addprefix $(LIBTRANSISTOR_HOME)/build/lib/,$(libtransistor_OBJECT_NAMES))

pthread_SRCS= rthread_attr.c rthread_barrier.c rthread_barrier_attr.c rthread_cond.c rthread_condattr.c rthread_debug.c rthread_getcpuclockid.c rthread_internal.c rthread_mutex.c rthread_mutex_prio.c rthread_mutexattr.c rthread_once.c rthread_rwlock.c rthread_rwlockattr.c rthread_sched.c rthread_sem.c rthread_sig.c rthread_spin_lock.c rthread_thread.c rthread_tls.c sched_prio.c sys/switch/phal.c
pthread_OBJECT_FILES := $(addprefix $(LIBTRANSISTOR_HOME)/build/pthread/,$(pthread_SRCS:.c=.o))
pthread_CC_FLAGS := -I$(LIBTRANSISTOR_HOME)/pthread -I$(LIBTRANSISTOR_HOME)/pthread/sys/switch -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unused-variable -Wno-unused-function -Wno-unused-label

# for building newlib and sdl
export LD
export CC
Expand All @@ -24,126 +16,19 @@ export CFLAGS_FOR_TARGET = $(CC_FLAGS) -Wno-unused-command-line-argument -Wno-er
.SUFFIXES: # disable built-in rules
.SECONDARY: # don't delete intermediate files

.PHONY: clean clean_newlib clean_compiler-rt clean_sdl distclean

all: $(LIBTRANSISTOR_HOME)/build/lib/libtransistor.nro.a \
$(LIBTRANSISTOR_HOME)/build/lib/libtransistor.nso.a \
$(addprefix $(LIBTRANSISTOR_HOME)/build/test/test_,$(addsuffix .nro,$(libtransistor_TESTS))) \
$(addprefix $(LIBTRANSISTOR_HOME)/build/test/test_,$(addsuffix .nso,$(libtransistor_TESTS))) \
$(addprefix $(LIBTRANSISTOR_HOME)/build/test/test_,$(addsuffix .nro.so,$(libtransistor_TESTS))) \
$(addprefix $(LIBTRANSISTOR_HOME)/build/test/test_,$(addsuffix .nso.so,$(libtransistor_TESTS)))

run_tests: run_helloworld_test run_hexdump_test run_malloc_test run_bsd_ai_packing_test run_bsd_test run_sfdnsres_test run_multiple_set_heap_size_test run_init_fini_arrays_test

run_bsd_test: $(LIBTRANSISTOR_HOME)/build/test/test_bsd.nro $(LIBTRANSISTOR_HOME)/test_helpers/bsd.rb
$(RUBY) $(LIBTRANSISTOR_HOME)/test_helpers/bsd.rb $(MEPHISTO)

run_sfdnsres_test: $(LIBTRANSISTOR_HOME)/build/test/test_sfdnsres.nro
$(MEPHISTO) --enable-sockets --load-nro $<

run_ssp_test: $(LIBTRANSISTOR_HOME)/build/test/test_ssp.nro
$(MEPHISTO) --enable-sockets --load-nro $<

run_%_test: $(LIBTRANSISTOR_HOME)/build/test/test_%.nro
$(MEPHISTO) --load-nro $<

$(LIBTRANSISTOR_HOME)/build/test/%.o: $(LIBTRANSISTOR_HOME)/test/%.c $(LIBTRANSISTOR_HOME)/build/sdl2_install/lib/libSDL2.a
mkdir -p $(@D)
$(CC) $(CC_FLAGS) $(WARNINGS) -c -o $@ $<

# Disable stack protector for crt0_common
$(LIBTRANSISTOR_HOME)/build/lib/crt0_common.o: $(LIBTRANSISTOR_HOME)/lib/crt0_common.c
mkdir -p $(@D)
$(CC) $(CC_FLAGS) -I$(LIBTRANSISTOR_HOME)/pthread/ -I$(LIBTRANSISTOR_HOME)/pthread/sys/switch/ $(WARNINGS) -fno-stack-protector -c -o $@ $<

$(LIBTRANSISTOR_HOME)/build/lib/%.o: $(LIBTRANSISTOR_HOME)/lib/%.c
mkdir -p $(@D)
$(CC) $(CC_FLAGS) $(WARNINGS) -c -o $@ $<

$(LIBTRANSISTOR_HOME)/build/lib/%.o: $(LIBTRANSISTOR_HOME)/lib/%.S
mkdir -p $(@D)
$(AS) $(AS_FLAGS) $< -filetype=obj -o $@

# Pthread rules
$(LIBTRANSISTOR_HOME)/build/pthread/%.o: $(LIBTRANSISTOR_HOME)/pthread/%.c
mkdir -p $(@D)
$(CC) $(CC_FLAGS) $(WARNINGS) $(pthread_CC_FLAGS) -c -o $@ $<

$(LIBTRANSISTOR_HOME)/build/test/%.nro.so: $(LIBTRANSISTOR_HOME)/build/test/%.o $(LIBTRANSISTOR_NRO_LIB) $(LIBTRANSISTOR_COMMON_LIBS)
mkdir -p $(@D)
$(LD) $(LD_FLAGS) -o $@ $< $(LIBTRANSISTOR_NRO_LDFLAGS)

$(LIBTRANSISTOR_HOME)/build/test/%.nso.so: $(LIBTRANSISTOR_HOME)/build/test/%.o $(LIBTRANSISTOR_NSO_LIB) $(LIBTRANSISTOR_COMMON_LIBS)
mkdir -p $(@D)
$(LD) $(LD_FLAGS) -o $@ $< $(LIBTRANSISTOR_NSO_LDFLAGS)

$(LIBTRANSISTOR_NRO_LIB): $(LIBTRANSISTOR_HOME)/build/lib/crt0.nro.o $(libtransistor_OBJECT_FILES)
mkdir -p $(@D)
rm -f $@
$(AR) $(AR_FLAGS) $@ $+

$(LIBTRANSISTOR_NSO_LIB): $(LIBTRANSISTOR_HOME)/build/lib/crt0.nso.o $(libtransistor_OBJECT_FILES)
mkdir -p $(@D)
rm -f $@
$(AR) $(AR_FLAGS) $@ $+

$(LIBTRANSISTOR_HOME)/build/newlib/Makefile:
mkdir -p $(@D)
cd $(@D); $(LIBTRANSISTOR_HOME)/newlib/configure --disable-multilib --target=aarch64-none-switch --without-rdimon

$(LIBTRANSISTOR_HOME)/build/newlib/aarch64-none-switch/newlib/libm.a $(LIBTRANSISTOR_HOME)/build/newlib/aarch64-none-switch/newlib/libc.a: $(LIBTRANSISTOR_HOME)/build/newlib/Makefile
$(MAKE) -C $(LIBTRANSISTOR_HOME)/build/newlib/

$(LIBTRANSISTOR_HOME)/pthread/libpthread.a: $(pthread_OBJECT_FILES)
mkdir -p $(@D)
rm -f $@
$(AR) $(AR_FLAGS) $@ $+

$(COMPILER_RT_BUILTINS_LIB): $(LIBTRANSISTOR_HOME)/build/compiler-rt/Makefile
$(MAKE) -C $(LIBTRANSISTOR_HOME)/build/compiler-rt/

$(LIBTRANSISTOR_HOME)/build/compiler-rt/Makefile:
mkdir -p $(@D)
cd $(@D); cmake -G "Unix Makefiles" $(LIBTRANSISTOR_HOME)/compiler-rt \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCMAKE_C_COMPILER="$(CC)" \
-DCMAKE_C_FLAGS="$(CC_FLAGS)" \
-DCMAKE_C_COMPILER_TARGET="aarch64-none-linux-gnu" \
-DCMAKE_CXX_COMPILER="$(CXX)" \
-DCMAKE_CXX_FLAGS="$(CC_FLAGS)" \
-DCMAKE_CXX_COMPILER_TARGET="aarch64-none-linux-gnu" \
-DCMAKE_AR="$(AR)" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DLLVM_CONFIG_PATH=llvm-config$(LLVM_POSTFIX) \
-DCMAKE_SYSTEM_NAME=Linux

$(LIBTRANSISTOR_HOME)/build/sdl2_install/lib/libSDL2.a: $(LIBTRANSISTOR_HOME)/build/sdl2/Makefile
$(MAKE) -C $(LIBTRANSISTOR_HOME)/build/sdl2/
$(MAKE) -C $(LIBTRANSISTOR_HOME)/build/sdl2/ install

$(LIBTRANSISTOR_HOME)/build/sdl2/Makefile: $(LIBTRANSISTOR_HOME)/build/newlib/aarch64-none-switch/newlib/libm.a $(LIBTRANSISTOR_HOME)/build/newlib/aarch64-none-switch/newlib/libc.a
mkdir -p $(@D)
cd $(@D); $(LIBTRANSISTOR_HOME)/sdl2/configure "CFLAGS=$(CFLAGS)" "CC=$(CC)" "AR=$(AR)" "RANLIB=$(RANLIB)" "LDFLAGS=-L$(LIBTRANSISTOR_HOME)/build/newlib/aarch64-none-switch/newlib/ -lc -lm" --host=aarch64-none-switch --disable-audio --disable-joystick --disable-power --disable-filesystem --disable-threads --disable-cpuinfo --enable-timers --enable-video --disable-shared --enable-static --prefix=$(LIBTRANSISTOR_HOME)/build/sdl2_install/

clean:
rm -rf $(LIBTRANSISTOR_HOME)/build/lib/* $(LIBTRANSISTOR_HOME)/build/test/* $(LIBTRANSISTOR_HOME)/docs

clean_pthread:
rm -fr build/pthread
.PHONY: all

clean_newlib:
rm -rf build/newlib
default:

clean_compiler-rt:
rm -rf build/compiler-rt
include mk/lib.mk
include mk/tests.mk
include mk/pthread.mk
include mk/newlib.mk
include mk/compiler-rt.mk
include mk/sdl2.mk
include mk/liblzma.mk

clean_sdl:
rm -rf build/sdl2 build/sdl2_install
clean: clean_lib clean_test
rm -rf $(LIBTRANSISTOR_HOME)/docs

distclean: clean clean_newlib clean_compiler-rt clean_pthread clean_sdl
distclean: clean clean_newlib clean_compiler-rt clean_pthread clean_sdl2
10 changes: 10 additions & 0 deletions fs.T
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
OUTPUT_FORMAT(elf64-littleaarch64)

SECTIONS
{
.data : {
_libtransistor_squashfs_image = .;
*(.data .data*)
_libtransistor_squashfs_image_end = .;
}
}
26 changes: 18 additions & 8 deletions include/libtransistor/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,27 @@
// HID
#define LIBTRANSISTOR_ERR_HID_BAD_STRUCTURE LIBTRANSISTOR_RESULT(7001)

// FS
#define LIBTRANSISTOR_ERR_FS_INTERNAL_ERROR LIBTRANSISTOR_RESULT(8001)
#define LIBTRANSISTOR_ERR_FS_OUT_OF_DIR_ENTRIES LIBTRANSISTOR_RESULT(8002)
#define LIBTRANSISTOR_ERR_FS_NAME_TOO_LONG LIBTRANSISTOR_RESULT(8003)
#define LIBTRANSISTOR_ERR_FS_NOT_A_DIRECTORY LIBTRANSISTOR_RESULT(8004)
#define LIBTRANSISTOR_ERR_FS_NOT_A_FILE LIBTRANSISTOR_RESULT(8005)
#define LIBTRANSISTOR_ERR_FS_NOT_FOUND LIBTRANSISTOR_RESULT(8006)
#define LIBTRANSISTOR_ERR_FS_INVALID_PATH LIBTRANSISTOR_RESULT(8007)
#define LIBTRANSISTOR_ERR_FS_PATH_TOO_DEEP LIBTRANSISTOR_RESULT(8008)

// AM
#define LIBTRANSISTOR_ERR_AM_WORKAROUND_ACTIVE LIBTRANSISTOR_RESULT(8001)
#define LIBTRANSISTOR_ERR_AM_WORKAROUND_ACTIVE LIBTRANSISTOR_RESULT(9001)

// IPC Server
#define LIBTRANSISTOR_ERR_IPCSERVER_INVALID_SESSION_STATE LIBTRANSISTOR_RESULT(9001)
#define LIBTRANSISTOR_ERR_IPCSERVER_TOO_MANY_SESSIONS LIBTRANSISTOR_RESULT(9002)
#define LIBTRANSISTOR_ERR_IPCSERVER_NO_SUCH_OBJECT LIBTRANSISTOR_RESULT(9003)
#define LIBTRANSISTOR_ERR_IPCSERVER_OBJECT_NOT_ACTIVE LIBTRANSISTOR_RESULT(9004)
#define LIBTRANSISTOR_ERR_IPCSERVER_SESSION_OBJECT_WAS_DOMAIN LIBTRANSISTOR_RESULT(9005)
#define LIBTRANSISTOR_ERR_IPCSERVER_CANT_SEND_ROOT_OBJECT LIBTRANSISTOR_RESULT(9006)
#define LIBTRANSISTOR_ERR_IPCSERVER_NO_SUCH_COMMAND LIBTRANSISTOR_RESULT(9007)
#define LIBTRANSISTOR_ERR_IPCSERVER_INVALID_SESSION_STATE LIBTRANSISTOR_RESULT(10001)
#define LIBTRANSISTOR_ERR_IPCSERVER_TOO_MANY_SESSIONS LIBTRANSISTOR_RESULT(10002)
#define LIBTRANSISTOR_ERR_IPCSERVER_NO_SUCH_OBJECT LIBTRANSISTOR_RESULT(10003)
#define LIBTRANSISTOR_ERR_IPCSERVER_OBJECT_NOT_ACTIVE LIBTRANSISTOR_RESULT(10004)
#define LIBTRANSISTOR_ERR_IPCSERVER_SESSION_OBJECT_WAS_DOMAIN LIBTRANSISTOR_RESULT(10005)
#define LIBTRANSISTOR_ERR_IPCSERVER_CANT_SEND_ROOT_OBJECT LIBTRANSISTOR_RESULT(10006)
#define LIBTRANSISTOR_ERR_IPCSERVER_NO_SUCH_COMMAND LIBTRANSISTOR_RESULT(10007)

// Homebrew ABI
#define HOMEBREW_ABI_RESULT(code) MAKE_RESULT(346, code)
Expand Down
11 changes: 11 additions & 0 deletions include/libtransistor/fs/blobfd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include<stdio.h>

typedef struct {
void *data;
size_t size;
off_t head;
} blob_file;

int blobfd_create(blob_file *data, void *blob, size_t size);
13 changes: 13 additions & 0 deletions include/libtransistor/fs/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include<libtransistor/types.h>
#include<libtransistor/fs/inode.h>

#include<sys/stat.h>

result_t trn_fs_set_root(trn_inode_t *root);
result_t trn_fs_realpath(const char *path, char **resolved_path);
result_t trn_fs_open(int *fd, const char *path, int flags);
result_t trn_fs_opendir(trn_dir_t *dir, const char *path);
result_t trn_fs_chdir(const char *path);
result_t trn_fs_stat(const char *path, struct stat *st);
41 changes: 41 additions & 0 deletions include/libtransistor/fs/inode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include<libtransistor/types.h>
#include<stdlib.h>

struct trn_inode_ops_t;

typedef struct {
void *data;
struct trn_inode_ops_t *ops;
} trn_inode_t; // libTRaNsistor INODE

typedef struct {
trn_inode_t inode;
char name[256];
size_t name_size;
} trn_dirent_t;

typedef struct {
result_t (*rewind)(void *dir);
result_t (*next)(void *dir, trn_dirent_t *dirent);
void (*close)(void *dir);
} trn_dir_ops_t;

typedef struct {
void *data;
trn_dir_ops_t *ops;
} trn_dir_t;

typedef struct trn_inode_ops_t {
result_t (*is_dir)(void *inode, bool *out);
result_t (*lookup)(void *inode, trn_inode_t *out, const char *name, size_t name_length);
result_t (*release)(void *inode);

/*
Objects returned from these functions must not be invalidated if the inode is closed
before they are.
*/
result_t (*open_as_file)(void *inode, int mode, int *fd);
result_t (*open_as_dir)(void *inode, trn_dir_t *out);
} trn_inode_ops_t;
7 changes: 7 additions & 0 deletions include/libtransistor/fs/squashfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include<libtransistor/types.h>
#include<libtransistor/fs/inode.h>
#include "../../../lib/squashfs/squashfuse.h" // TODO: not this

result_t trn_sqfs_open_root(trn_inode_t *out, sqfs *fs);
Loading

0 comments on commit 3a5e448

Please sign in to comment.