diff --git a/src/Makefile b/src/Makefile index a2f7984b8..e6a404fac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -262,9 +262,9 @@ EMPTY:= SPACE:=$(EMPTY) $(EMPTY) CLANG_TIDY_HEADER_FILTER=$(PWD)/($(subst $(SPACE),|,$(LINTER_HEADERS))) -CXXFLAGS+=$(OPTFLAGS) -std=c++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) -CFLAGS+=$(OPTFLAGS) -std=c99 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) -LDFLAGS+=$(UBFLAGS) $(MYLDFLAGS) +CXXFLAGS+=$(OPTFLAGS) -std=c++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) +CFLAGS+=$(OPTFLAGS) -std=c99 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) +LDFLAGS+=$(UBFLAGS) COVERAGE_WORKLOAD=\ dhrystone 100; \ @@ -289,6 +289,10 @@ $(error invalid value for COVERAGE_TOOLCHAIN: $(COVERAGE_TOOLCHAIN)) endif endif +CXXFLAGS+=$(MYCXXFLAGS) +CFLAGS+=$(MYCFLAGS) +LDFLAGS+=$(MYLDFLAGS) + all: luacartesi grpc hash c-api jsonrpc-remote-cartesi-machine .PHONY: all generate use clean test lint format format-lua check-format check-format-lua luacartesi libcartesi grpc hash c-api compile_flags.txt diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index cc70975aa..0977a5321 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -84,8 +83,6 @@ int cm_result_failure(char **err_msg) try { throw; } catch (std::exception &e) { return CM_ERROR_REGEX_ERROR; } catch (std::ios_base::failure &ex) { return CM_ERROR_SYSTEM_IOS_BASE_FAILURE; - } catch (std::filesystem::filesystem_error &ex) { - return CM_ERROR_FILESYSTEM_ERROR; } catch (std::runtime_error &ex) { return CM_ERROR_RUNTIME_ERROR; } catch (std::bad_typeid &ex) { diff --git a/src/machine.cpp b/src/machine.cpp index 11354de32..2142b59c1 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -364,13 +363,19 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) : const std::string flash_description = "flash drive "s + std::to_string(i++); // Auto detect flash drive image length if (f.length == UINT64_C(-1)) { - std::error_code ec; - f.length = std::filesystem::file_size(f.image_filename, ec); - if (ec) { - throw std::system_error{ec.value(), ec.category(), + auto fp = unique_fopen(f.image_filename.c_str(), "rb"); + if (fseek(fp.get(), 0, SEEK_END) != 0) { + throw std::system_error{errno, std::generic_category(), "unable to obtain length of image file '"s + f.image_filename + "' when initializing "s + flash_description}; } + const auto length = ftell(fp.get()); + if (length < 0) { + throw std::system_error{errno, std::generic_category(), + "unable to obtain length of image file '"s + f.image_filename + "' when initializing "s + + flash_description}; + } + f.length = length; } register_pma_entry(make_flash_drive_pma_entry(flash_description, f)); } diff --git a/src/tty.cpp b/src/tty.cpp index 61a225237..6097cdfdf 100644 --- a/src/tty.cpp +++ b/src/tty.cpp @@ -22,9 +22,12 @@ #include #include #include -#include #include +#ifndef NO_TERMIOS +#include +#endif + #include "tty.h" namespace cartesi { @@ -34,13 +37,16 @@ static const int CONSOLE_BUF_SIZE = 1024; ///< Number of characters in console i /// \brief TTY global state struct tty_state { bool initialized{false}; - int ttyfd{-1}; - termios oldtty{}; std::array buf{}; ssize_t buf_pos{}; ssize_t buf_len{}; +#ifndef NO_TERMIOS + int ttyfd{-1}; + termios oldtty{}; +#endif }; +#ifndef NO_TERMIOS static int new_ttyfd(const char *path) { int fd{}; do { @@ -66,6 +72,7 @@ static int get_ttyfd(void) { // NOLINTEND(bugprone-assignment-in-if-condition) return -1; } +#endif static bool try_read_chars_from_stdin(uint64_t wait, char *data, size_t max_len, long *actual_len) { const int fd_max{0}; @@ -98,6 +105,7 @@ void tty_initialize(void) { throw std::runtime_error("TTY already initialized."); } s->initialized = true; +#ifndef NO_TERMIOS // NOLINTNEXTLINE(bugprone-assignment-in-if-condition) if ((s->ttyfd = get_ttyfd()) >= 0) { struct termios tty {}; @@ -129,6 +137,7 @@ void tty_initialize(void) { tcsetattr(s->ttyfd, TCSANOW, &tty); //??D Should we check to see if changes stuck? } +#endif } void tty_finalize(void) { @@ -137,11 +146,13 @@ void tty_finalize(void) { throw std::runtime_error("TTY not initialized"); } s->initialized = false; +#ifndef NO_TERMIOS if (s->ttyfd >= 0) { tcsetattr(s->ttyfd, TCSANOW, &s->oldtty); close(s->ttyfd); s->ttyfd = -1; } +#endif } void tty_poll_console(uint64_t wait) { diff --git a/third-party/xkcp/Makefile b/third-party/xkcp/Makefile index f2124036b..3fbaced8f 100644 --- a/third-party/xkcp/Makefile +++ b/third-party/xkcp/Makefile @@ -1,5 +1,5 @@ -LIB_CFLAGS+=-O2 -g0 -fvisibility=hidden -fPIC -LIB_CFLAGS+=-fno-stack-protector -D_FORTIFY_SOURCE=0 +CFLAGS=-O2 -g0 +LIB_CFLAGS=-fvisibility=hidden -fPIC -fno-stack-protector -D_FORTIFY_SOURCE=0 XKCP_DIR=XKCP-f7fe32a80f0c6600d1c5db50392a43265d3bba9a XKCP_LIBS=$(XKCP_DIR)/bin/libXKCP.a @@ -20,7 +20,7 @@ $(XKCP_DIR)/bin: $(MAKE) -C $(XKCP_DIR) $(XKCP_DIR)/bin/generic64/libXKCP.a: $(XKCP_DIR)/bin - $(MAKE) -C $(XKCP_DIR) generic64/libXKCP.a CC=$(CC) AR=$(AR) CFLAGS="$(CFLAGS) $(LIB_CFLAGS)" + $(MAKE) -C $(XKCP_DIR) generic64/libXKCP.a CC=$(CC) AR=$(AR) CFLAGS="$(CFLAGS) $(LIB_CFLAGS) $(MYCFLAGS)" $(XKCP_DIR)/bin/libXKCP.a: $(XKCP_DIR)/bin/generic64/libXKCP.a cp $< $@ @@ -30,7 +30,7 @@ $(XKCP_DIR)/bin/libXKCP_AVX.a: ARCHFLAGS=-mavx $(XKCP_DIR)/bin/libXKCP_AVX2.a: ARCHFLAGS=-mavx2 $(XKCP_DIR)/bin/libXKCP_AVX512.a: ARCHFLAGS=-march=skylake-avx512 $(XKCP_DIR)/bin/libXKCP_%.a: $(XKCP_DIR)/bin/libXKCP.a - $(MAKE) -C $(XKCP_DIR) $*/libXKCP.a CC=$(CC) AR=$(AR) CFLAGS="$(CFLAGS) $(ARCHFLAGS) $(LIB_CFLAGS)" + $(MAKE) -C $(XKCP_DIR) $*/libXKCP.a CC=$(CC) AR=$(AR) CFLAGS="$(ARCHFLAGS) $(CFLAGS) $(LIB_CFLAGS) $(MYCFLAGS)" # prefix all library symbols with the target extension objcopy --prefix-symbols $*_ \ $(XKCP_DIR)/bin/$*/libXKCP.a $@