// // Dis VM // File: sys_utils.h // Author: arr // #ifndef _DISVM_SRC_VM_SYS_SYS_UTILS_H_ #define _DISVM_SRC_VM_SYS_SYS_UTILS_H_ #include #include #include #include #include namespace disvm { namespace runtime { namespace sys { // Prints the format and arguments to the supplied buffer. // Returns the number of bytes written. word_t printf_to_buffer( const vm_string_t &msg_fmt, byte_t *msg_args, pointer_t base, const std::size_t buffer_size, char *buffer); // Prints the format and arguments to the supplied dynamic buffer. // Returns the number of bytes written. word_t printf_to_dynamic_buffer( const vm_string_t &msg_fmt, byte_t *msg_args, pointer_t base, std::vector &buffer); enum class cfs_flags_t { none, atomic, ensure_create, }; DEFINE_ENUM_FLAG_OPERATORS(cfs_flags_t); std::unique_ptr create_file_stream(const char *path, std::ios::openmode mode, cfs_flags_t flags = sys::cfs_flags_t::none); const word_t vm_invalid_fd = -1; // The first three FD records are optimized for lock-less access. word_t create_fd_record(vm_alloc_t *fd_alloc); vm_alloc_t * fetch_fd_record(word_t fd); void drop_fd_record(word_t fd); } } } #endif // _DISVM_SRC_VM_SYS_SYS_UTILS_H_