Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/arena/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::ptr::{self, NonNull};
use std::{mem, slice};

use crate::helpers::*;
use crate::sys::Syscall;
use crate::{apperr, sys};

const ALLOC_CHUNK_SIZE: usize = 64 * KIBI;
Expand Down Expand Up @@ -66,7 +67,7 @@ impl Arena {

pub fn new(capacity: usize) -> apperr::Result<Self> {
let capacity = (capacity.max(1) + ALLOC_CHUNK_SIZE - 1) & !(ALLOC_CHUNK_SIZE - 1);
let base = unsafe { sys::virtual_reserve(capacity)? };
let base = unsafe { sys::syscall::virtual_reserve(capacity)? };

Ok(Self {
base,
Expand Down Expand Up @@ -139,7 +140,8 @@ impl Arena {

if commit_new > self.capacity
|| unsafe {
sys::virtual_commit(self.base.add(commit_old), commit_new - commit_old).is_err()
sys::syscall::virtual_commit(self.base.add(commit_old), commit_new - commit_old)
.is_err()
}
{
return Err(AllocError);
Expand Down Expand Up @@ -176,7 +178,7 @@ impl Arena {
impl Drop for Arena {
fn drop(&mut self) {
if !self.is_empty() {
unsafe { sys::virtual_release(self.base, self.capacity) };
unsafe { sys::syscall::virtual_release(self.base, self.capacity) };
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/bin/edit/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};

use edit::buffer::{RcTextBuffer, TextBuffer};
use edit::helpers::{CoordType, Point};
use edit::sys::Syscall;
use edit::{apperr, path, sys};

use crate::state::DisplayablePathBuf;
Expand All @@ -31,7 +32,7 @@ impl Document {
tb.write_file(&mut file)?;
}

if let Ok(id) = sys::file_id(None, path) {
if let Ok(id) = sys::syscall::file_id(None, path) {
self.file_id = Some(id);
}

Expand All @@ -51,7 +52,7 @@ impl Document {
tb.read_file(&mut file, encoding)?;
}

if let Ok(id) = sys::file_id(None, path) {
if let Ok(id) = sys::syscall::file_id(None, path) {
self.file_id = Some(id);
}

Expand Down Expand Up @@ -145,11 +146,12 @@ impl DocumentManager {

let mut file = match Self::open_for_reading(&path) {
Ok(file) => Some(file),
Err(err) if sys::apperr_is_not_found(err) => None,
Err(err) if sys::syscall::apperr_is_not_found(err) => None,
Err(err) => return Err(err),
};

let file_id = if file.is_some() { Some(sys::file_id(file.as_ref(), &path)?) } else { None };
let file_id =
if file.is_some() { Some(sys::syscall::file_id(file.as_ref(), &path)?) } else { None };

// Check if the file is already open.
if file_id.is_some() && self.update_active(|doc| doc.file_id == file_id) {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/edit/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use edit::arena::scratch_arena;
use edit::helpers::AsciiStringHelpers;
use edit::sys;
use edit::sys::{self, Syscall};

include!(concat!(env!("OUT_DIR"), "/i18n_edit.rs"));

static mut S_LANG: LangId = LangId::en;

pub fn init() {
let scratch = scratch_arena(None);
let langs = sys::preferred_languages(&scratch);
let langs = sys::syscall::preferred_languages(&scratch);
let mut lang = LangId::en;

'outer: for l in langs {
Expand Down
25 changes: 13 additions & 12 deletions src/bin/edit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use edit::framebuffer::{self, IndexedColor};
use edit::helpers::{CoordType, KIBI, MEBI, MetricFormatter, Rect, Size};
use edit::input::{self, kbmod, vk};
use edit::oklab::StraightRgba;
use edit::sys::Syscall;
use edit::tui::*;
use edit::vt::{self, Token};
use edit::{apperr, arena_format, base64, path, sys, unicode};
Expand All @@ -51,15 +52,15 @@ fn main() -> process::ExitCode {
match run() {
Ok(()) => process::ExitCode::SUCCESS,
Err(err) => {
sys::write_stdout(&format!("{}\n", FormatApperr::from(err)));
sys::syscall::write_stdout(&format!("{}\n", FormatApperr::from(err)));
process::ExitCode::FAILURE
}
}
}

fn run() -> apperr::Result<()> {
// Init `sys` first, as everything else may depend on its functionality (IO, function pointers, etc.).
let _sys_deinit = sys::init();
let _sys_deinit = sys::syscall::init();
// Next init `arena`, so that `scratch_arena` works. `loc` depends on it.
arena::init(SCRATCH_ARENA_CAPACITY)?;
// Init the `loc` module, so that error messages are localized.
Expand All @@ -75,7 +76,7 @@ fn run() -> apperr::Result<()> {
// `handle_args` may want to print a help message (must not fail),
// and reads files (may hang; should be cancelable with Ctrl+C).
// As such, we call this after `handle_args`.
sys::switch_modes()?;
sys::syscall::switch_modes()?;

let mut vt_parser = vt::Parser::new();
let mut input_parser = input::Parser::new();
Expand Down Expand Up @@ -103,7 +104,7 @@ fn run() -> apperr::Result<()> {
tui.set_modal_default_bg(floater_bg);
tui.set_modal_default_fg(floater_fg);

sys::inject_window_size_into_stdin();
sys::syscall::inject_window_size_into_stdin();

#[cfg(feature = "debug-latency")]
let mut last_latency_width = 0;
Expand All @@ -118,7 +119,7 @@ fn run() -> apperr::Result<()> {
{
let scratch = scratch_arena(None);
let read_timeout = vt_parser.read_timeout().min(tui.read_timeout());
let Some(input) = sys::read_stdin(&scratch, read_timeout) else {
let Some(input) = sys::syscall::read_stdin(&scratch, read_timeout) else {
break;
};

Expand Down Expand Up @@ -214,7 +215,7 @@ fn run() -> apperr::Result<()> {
last_latency_width = cols;
}

sys::write_stdout(&output);
sys::syscall::write_stdout(&output);
}
}

Expand Down Expand Up @@ -263,7 +264,7 @@ fn handle_args(state: &mut State) -> apperr::Result<bool> {
cwd = parent.to_path_buf();
}

if let Some(mut file) = sys::open_stdin_if_redirected() {
if let Some(mut file) = sys::syscall::open_stdin_if_redirected() {
let doc = state.documents.add_untitled()?;
let mut tb = doc.buffer.borrow_mut();
tb.read_file(&mut file, None)?;
Expand All @@ -278,7 +279,7 @@ fn handle_args(state: &mut State) -> apperr::Result<bool> {
}

fn print_help() {
sys::write_stdout(concat!(
sys::syscall::write_stdout(concat!(
"Usage: edit [OPTIONS] [FILE[:LINE[:COLUMN]]]\n",
"Options:\n",
" -h, --help Print this help message\n",
Expand All @@ -290,7 +291,7 @@ fn print_help() {
}

fn print_version() {
sys::write_stdout(concat!("edit version ", env!("CARGO_PKG_VERSION"), "\n"));
sys::syscall::write_stdout(concat!("edit version ", env!("CARGO_PKG_VERSION"), "\n"));
}

fn draw(ctx: &mut Context, state: &mut State) {
Expand Down Expand Up @@ -527,12 +528,12 @@ impl Drop for RestoreModes {
// Same as in the beginning but in the reverse order.
// It also includes DECSCUSR 0 to reset the cursor style and DECTCEM to show the cursor.
// We specifically don't reset mode 1036, because most applications expect it to be set nowadays.
sys::write_stdout("\x1b[0 q\x1b[?25h\x1b]0;\x07\x1b[?1002;1006;2004l\x1b[?1049l");
sys::syscall::write_stdout("\x1b[0 q\x1b[?25h\x1b]0;\x07\x1b[?1002;1006;2004l\x1b[?1049l");
}
}

fn setup_terminal(tui: &mut Tui, state: &mut State, vt_parser: &mut vt::Parser) -> RestoreModes {
sys::write_stdout(concat!(
sys::syscall::write_stdout(concat!(
// 1049: Alternative Screen Buffer
// I put the ASB switch in the beginning, just in case the terminal performs
// some additional state tracking beyond the modes we enable/disable.
Expand Down Expand Up @@ -570,7 +571,7 @@ fn setup_terminal(tui: &mut Tui, state: &mut State, vt_parser: &mut vt::Parser)
// We explicitly set a high read timeout, because we're not
// waiting for user keyboard input. If we encounter a lone ESC,
// it's unlikely to be from a ESC keypress, but rather from a VT sequence.
let Some(input) = sys::read_stdin(&scratch, Duration::from_secs(3)) else {
let Some(input) = sys::syscall::read_stdin(&scratch, Duration::from_secs(3)) else {
break;
};

Expand Down
3 changes: 2 additions & 1 deletion src/bin/edit/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use edit::framebuffer::IndexedColor;
use edit::helpers::*;
use edit::oklab::StraightRgba;
use edit::sys::Syscall;
use edit::tui::*;
use edit::{apperr, buffer, icu, sys};

Expand All @@ -30,7 +31,7 @@ impl std::fmt::Display for FormatApperr {
apperr::APP_ICU_MISSING => f.write_str(loc(LocId::ErrorIcuMissing)),
apperr::Error::App(code) => write!(f, "Unknown app error code: {code}"),
apperr::Error::Icu(code) => icu::apperr_format(f, code),
apperr::Error::Sys(code) => sys::apperr_format(f, code),
apperr::Error::Sys(code) => sys::syscall::apperr_format(f, code),
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/buffer/gap_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::slice;

use crate::document::{ReadableDocument, WriteableDocument};
use crate::helpers::*;
use crate::sys::Syscall;
use crate::{apperr, sys};

#[cfg(target_pointer_width = "32")]
Expand All @@ -31,7 +32,7 @@ impl Drop for BackingBuffer {
fn drop(&mut self) {
unsafe {
if let Self::VirtualMemory(ptr, reserve) = *self {
sys::virtual_release(ptr, reserve);
sys::syscall::virtual_release(ptr, reserve);
}
}
}
Expand Down Expand Up @@ -73,7 +74,7 @@ impl GapBuffer {
buffer = BackingBuffer::Vec(Vec::new());
} else {
reserve = LARGE_CAPACITY;
text = unsafe { sys::virtual_reserve(reserve)? };
text = unsafe { sys::syscall::virtual_reserve(reserve)? };
buffer = BackingBuffer::VirtualMemory(text, reserve);
}

Expand Down Expand Up @@ -195,7 +196,9 @@ impl GapBuffer {

match &mut self.buffer {
BackingBuffer::VirtualMemory(ptr, _) => unsafe {
if sys::virtual_commit(ptr.add(bytes_old), bytes_new - bytes_old).is_err() {
if sys::syscall::virtual_commit(ptr.add(bytes_old), bytes_new - bytes_old)
.is_err()
{
return;
}
},
Expand Down
5 changes: 3 additions & 2 deletions src/icu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::ptr::{null, null_mut};

use crate::arena::{Arena, ArenaString, scratch_arena};
use crate::buffer::TextBuffer;
use crate::sys::Syscall;
use crate::unicode::Utf8Chars;
use crate::{apperr, arena_format, sys};

Expand Down Expand Up @@ -978,7 +979,7 @@ fn init_if_needed() -> apperr::Result<&'static LibraryFunctions> {
unsafe {
LIBRARY_FUNCTIONS = LibraryFunctionsState::Failed;

let Ok(icu) = sys::load_icu() else {
let Ok(icu) = sys::syscall::load_icu() else {
return;
};

Expand Down Expand Up @@ -1017,7 +1018,7 @@ fn init_if_needed() -> apperr::Result<&'static LibraryFunctions> {
#[cfg(edit_icu_renaming_auto_detect)]
let name = sys::icu_add_renaming_suffix(&scratch, name, &suffix);

let Ok(func) = sys::get_proc_address(handle, name) else {
let Ok(func) = sys::syscall::get_proc_address(handle, name) else {
debug_assert!(
false,
"Failed to load ICU function: {:?}",
Expand Down
6 changes: 3 additions & 3 deletions src/simd/memchr2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod tests {
use std::slice;

use super::*;
use crate::sys;
use crate::sys::{self, Syscall};

#[test]
fn test_empty() {
Expand Down Expand Up @@ -265,8 +265,8 @@ mod tests {
const PAGE_SIZE: usize = 64 * 1024; // 64 KiB to cover many architectures.

// 3 pages: uncommitted, committed, uncommitted
let ptr = sys::virtual_reserve(PAGE_SIZE * 3).unwrap();
sys::virtual_commit(ptr.add(PAGE_SIZE), PAGE_SIZE).unwrap();
let ptr = sys::syscall::virtual_reserve(PAGE_SIZE * 3).unwrap();
sys::syscall::virtual_commit(ptr.add(PAGE_SIZE), PAGE_SIZE).unwrap();
slice::from_raw_parts_mut(ptr.add(PAGE_SIZE).as_ptr(), PAGE_SIZE)
};

Expand Down
Loading