Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-11-19 04:54:17 -06:00
commit f086abcea6
789 files changed
+149185

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
#! @file clock.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the kinds of clock a system keeps, which `system` reads on each
#! system and `std::time` gives as moments.
module system;
#! A clock a system keeps, which `system::clock` reads.
pub enum clock_kind: u8 {
#! The time of day, since 1970 began in UTC. The system sets it, so it may go
#! forward or back, as when it is corrected over a network.
wall,
#! A clock that only ever goes forward, from a start that means nothing, which
#! is what measures how long something took.
steady,
}
+99
View File
@@ -0,0 +1,99 @@
#! @file files.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains what `system` and `std::io` above it both speak of files in: what
#! kind of file something is, who may do what with it, how one is opened, where
#! a seek is measured from, and what is known of one. They are the system's, so
#! `system` names them without reaching up into the layer above it.
module system;
#! What kind of file a path names.
pub enum file_kind: u8 {
other, #! A device, a pipe, a socket, or anything else.
regular, #! A file that holds bytes.
directory, #! A directory, which holds other files.
link, #! A link to another path, which is only seen where links are not followed.
}
#! Who may do what with a file: read it, write it, or run it, each for its
#! owner, its group, and everyone else, as nine bits.
#!
#! These are the bits POSIX systems keep for every file, written in octal as
#! `0o644`, and they are given and taken as those systems keep them. Those
#! systems may also set three more, the set-user, set-group, and sticky bits,
#! which are kept as they are.
#!
#! Windows keeps less: a file is read only or it is not, and whether it runs is
#! decided by its name. There, permissions read as readable by everyone,
#! writable by everyone unless the file is read only, and runnable by everyone
#! for a directory or a program. Setting them looks only at whether the owner
#! may write, which clears or sets the file's read-only attribute. So
#! `is_read_only` and `with_read_only` mean the same on every system.
pub type permissions = u32;
pub val permissions::owner_read := 0o400; #! The owner may read it.
pub val permissions::owner_write := 0o200; #! The owner may write it.
pub val permissions::owner_execute := 0o100; #! The owner may run it, or search it where it is a directory.
pub val permissions::group_read := 0o040; #! Its group may read it.
pub val permissions::group_write := 0o020; #! Its group may write it.
pub val permissions::group_execute := 0o010; #! Its group may run it, or search it.
pub val permissions::others_read := 0o004; #! Everyone else may read it.
pub val permissions::others_write := 0o002; #! Everyone else may write it.
pub val permissions::others_execute := 0o001; #! Everyone else may run it, or search it.
#! What a new file is given, less what the system's mask of the program takes
#! away, as `0o644` from the usual mask of `0o022`.
pub val permissions::default_file := 0o666;
#! What a new directory is given, less what the system's mask takes away.
pub val permissions::default_directory := 0o777;
#! Whether no one may write the file.
#! @param this The permissions to read.
#! @returns Whether none of the three write bits is set.
pub val permissions::is_read_only: bool {
get => (this & 0o222) == 0;
}
#! Makes permissions that are read only, or that let the owner write.
#! @param this The permissions to start from.
#! @param read_only Whether no one may write the file.
#! @returns The permissions without any write bit when read only, and otherwise
#! with the owner's write bit added, leaving who else may write as it
#! was.
pub def permissions::with_read_only(&this, read_only: bool): permissions {
if read_only {
return this & 0o7555;
}
return this | 0o200;
}
#! How a file is opened, combined with `|`. A file opened without `write` or
#! `append` is opened for reading.
pub type open_flags = u32;
pub val open_flags::read := 1; #! The file is read.
pub val open_flags::write := 2; #! The file is written.
pub val open_flags::create := 4; #! The file is made where there is none, as `write` needs.
pub val open_flags::truncate := 8; #! What the file held is thrown away.
pub val open_flags::append := 16; #! Every write goes at the end; this implies `write`.
pub val open_flags::exclusive := 32; #! With `create`, opening fails where the file exists.
#! Where an offset to seek to is measured from.
pub type whence = i32;
pub val whence::start := 0; #! The start of the file.
pub val whence::current := 1; #! Where the next read or write happens.
pub val whence::end := 2; #! The end of the file.
#! What is known of a file.
pub struct file_info {
pub var kind: file_kind; #! A file, a directory, a link, or another kind.
pub var size: u64; #! In bytes. A directory's size means what its system says.
pub var permissions: permissions; #! Who may read, write, and run it.
pub var modified: i64; #! When its bytes last changed, in nanoseconds since 1970.
pub var accessed: i64; #! When it was last read, in nanoseconds since 1970.
}
+39
View File
@@ -0,0 +1,39 @@
#! @file io_error.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains why reading or writing a stream, or an operation on a file, failed,
#! which `system` reports, and `std::io`'s streams give.
module system;
#! Why an operation on a file, a directory, or the working directory failed.
#!
#! Every operating system reports its failures by numbers of its own, and
#! `system::error_of` turns them into these, so the same failure is the same
#! member everywhere. A failure the members do not name is `other`, and
#! `unexpected_end` is one `std::io` finds itself, never the system. Only a
#! program that handles a signal is ever `interrupted`, and only in a wait for
#! something to arrive: a read, or a wait for a child, which it can try again.
pub enum io_error: u8 {
other, #! A failure none of the other members names.
not_found, #! Nothing is at the path, or a directory on the way to it is missing.
permission_denied, #! The program may not do this to the file.
already_exists, #! Something is already at the path.
not_a_directory, #! A directory was needed, and the path names something else.
is_a_directory, #! A file was needed, and the path names a directory.
directory_not_empty, #! The directory still holds something.
invalid, #! A path, handle, or argument the operation cannot take.
name_too_long, #! The path, or a name within it, is longer than the system takes.
busy, #! The file is in use in a way that stops this.
read_only, #! The file system holding the file is read only.
no_space, #! The device, or the user's share of it, is full.
too_many_open, #! The program, or the system, has as many files open as it may.
cross_device, #! A file cannot be renamed onto another device.
link_loop, #! Following the links in the path went around in a circle.
broken_pipe, #! What was written to has nothing reading it any more.
unsupported, #! The system does not do this.
unexpected_end, #! The input ended before all that was asked for was read.
interrupted, #! A signal the program handles came, ending the wait early.
}
+26
View File
@@ -0,0 +1,26 @@
#! @file linux.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains `system::linux`: what Linux gives a program, declared once for std
#! and anything else that reaches the system itself. A program reaches Linux by
#! system calls, whose numbers and the layouts of what they read and write
#! differ by processor, so each processor's are in a file of its own, as
#! `x86_64.sakura`.
module system::linux when os == linux;
#! Makes a system call, as the operations here do. Its numbers, and what it
#! reads and writes, are the system's, and differ by processor.
#! @param n The number of the call.
#! @param a Its first argument.
#! @param b Its second.
#! @param c Its third.
#! @param d Its fourth.
#! @param e Its fifth.
#! @param f Its sixth.
#! @returns What the call gives, or the negated error number where it fails.
@intrinsic
pub def syscall(n: i64, a: u64, b: u64, c: u64, d: u64, e: u64, f: u64): i64;
+71
View File
@@ -0,0 +1,71 @@
#! @file x86_64.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains what `system::linux` gives of Linux on x86-64.
#!
#! What a program needs to know of Linux on x86-64: the numbers of the system
#! calls it makes, the flags that differ by processor, and
#! where `stat` writes what `file_info` is read from.
module system::linux when os == linux && arch == x86_64;
pub val call_read: i64 = 0;
pub val call_write: i64 = 1;
pub val call_open: i64 = 2;
pub val call_close: i64 = 3;
pub val call_stat: i64 = 4;
pub val call_fstat: i64 = 5;
pub val call_lstat: i64 = 6;
pub val call_poll: i64 = 7;
pub val call_lseek: i64 = 8;
pub val call_mmap: i64 = 9;
pub val call_munmap: i64 = 11;
pub val call_rt_sigaction: i64 = 13;
pub val call_rt_sigprocmask: i64 = 14;
pub val call_dup2: i64 = 33;
pub val call_nanosleep: i64 = 35;
pub val call_getpid: i64 = 39;
pub val call_fork: i64 = 57;
pub val call_execve: i64 = 59;
pub val call_wait4: i64 = 61;
pub val call_kill: i64 = 62;
pub val call_fcntl: i64 = 72;
pub val call_getcwd: i64 = 79;
pub val call_chdir: i64 = 80;
pub val call_rename: i64 = 82;
pub val call_mkdir: i64 = 83;
pub val call_rmdir: i64 = 84;
pub val call_unlink: i64 = 87;
pub val call_chmod: i64 = 90;
pub val call_fchmod: i64 = 91;
pub val call_sched_yield: i64 = 24;
pub val call_rt_sigsuspend: i64 = 130;
pub val call_gettid: i64 = 186;
pub val call_futex: i64 = 202;
pub val call_sched_getaffinity: i64 = 204;
pub val call_getdents64: i64 = 217;
pub val call_clock_gettime: i64 = 228;
pub val call_exit_group: i64 = 231;
pub val call_newfstatat: i64 = 262;
pub val call_pipe2: i64 = 293;
pub val open_directory := 0x10000u;
pub const stat_bytes: u64 = 144;
pub val stat_mode := 24u;
pub val stat_size := 48u;
pub val stat_accessed := 72u; # Seconds, then nanoseconds.
pub val stat_modified := 88u; # Seconds, then nanoseconds.
# What `fcntl` is asked: a copy of a handle at the lowest free number from
# another up, or the handle's flags, of which only close-on-exec is set.
pub val f_dupfd := 0u;
pub val f_setfd := 2u;
# How `rt_sigprocmask` changes the signals held off: adding some, or setting
# all of them.
pub val sig_block := 0u;
pub val sig_setmask := 2u;
File diff suppressed because it is too large. Load diff
+52
View File
@@ -0,0 +1,52 @@
#! @file on_linux_x86_64.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the numbers Linux gives the signals `system` names, on x86-64.
module system when os == linux && arch == x86_64;
# The number Linux gives a signal on x86-64.
def number_of(which: signal): i32 {
return match which {
hangup => 1,
interrupt => 2,
quit => 3,
kill => 9,
user1 => 10,
user2 => 12,
pipe => 13,
alarm => 14,
terminate => 15,
child => 17,
resume => 18,
stop => 19,
suspend => 20,
resized => 28,
};
}
#! The signal Linux gives a number on x86-64, where it is one `signal` names.
#! @param number The number.
#! @returns The signal, or nothing.
pub def signal_of(number: i64): maybe<signal> {
return match number {
1 => signal::hangup,
2 => signal::interrupt,
3 => signal::quit,
9 => signal::kill,
10 => signal::user1,
12 => signal::user2,
13 => signal::pipe,
14 => signal::alarm,
15 => signal::terminate,
17 => signal::child,
18 => signal::resume,
19 => signal::stop,
20 => signal::suspend,
28 => signal::resized,
else => nothing{},
};
}
File diff suppressed because it is too large. Load diff
+58
View File
@@ -0,0 +1,58 @@
#! @file on_windows_x86_64.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains what `system` needs to know of Windows on x86-64.
#!
#! What `system` needs to know of Windows on x86-64: the numbers of the
#! signals. Windows numbers none of its own, so they are Linux's on x86-64,
#! which keeps the bits `watched` gives, and the numbers `signal_of` takes, the
#! same on both.
module system when os == windows && arch == x86_64;
# The number a signal is given, as Linux gives it on x86-64.
def number_of(which: signal): i32 {
return match which {
hangup => 1,
interrupt => 2,
quit => 3,
kill => 9,
user1 => 10,
user2 => 12,
pipe => 13,
alarm => 14,
terminate => 15,
child => 17,
resume => 18,
stop => 19,
suspend => 20,
resized => 28,
};
}
#! The signal a number is given to, as Linux gives it on x86-64, where it is
#! one `signal` names.
#! @param number The number.
#! @returns The signal, or nothing.
pub def signal_of(number: i64): maybe<signal> {
return match number {
1 => signal::hangup,
2 => signal::interrupt,
3 => signal::quit,
9 => signal::kill,
10 => signal::user1,
12 => signal::user2,
13 => signal::pipe,
14 => signal::alarm,
15 => signal::terminate,
17 => signal::child,
18 => signal::resume,
19 => signal::stop,
20 => signal::suspend,
28 => signal::resized,
else => nothing{},
};
}
+262
View File
@@ -0,0 +1,262 @@
#! @file system.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains `system`, the layer of the standard library that talks to the
#! operating system, as each system provides it, and what every system shares: a
#! directory's entries, how a copy of the program stopped, and stopping the
#! program.
#!
#! The layer of the standard library that talks to the operating system, and the
#! only one that knows which system it runs on. `std::io` is written once over
#! it, for every system, and is what programs use; this layer is for what
#! `std::io` does not cover.
#!
#! Each system implements the same operations in a section of its own, as
#! `linux.sakura` and `windows.sakura` do, with the numbers that differ by
#! processor in another, as `linux_x86_64.sakura`. Another system is supported
#! by writing those two, with the same names and signatures, and nothing above
#! this layer changes, but where the system cannot do what Linux does: as
#! Windows cannot `fork`, `std::testing` says with `when` what it does there
#! instead.
#!
#! The operations are thin: they take paths as text, as `path::view` gives it,
#! and fail by giving a negative number, the error number Linux would give,
#! which another system makes of its own, and which `error_of` turns into an
#! `io_error`. Each system provides:
#!
#! ```
#! fd its handle to an open file, with fd::stdin, stdout,
#! and stderr, and `path_limit`, the longest path it takes
#! open(path, flags, mode) opens a file, as `open_flags` say, creating it with
#! the permissions `mode` gives where it is made
#! fd::read, write, put, seek, close, stat, chmod
#! stat, lstat describes the file at a path, following a link at
#! the end of it or not, into a `file_info`
#! chmod sets the permissions of the file at a path
#! mkdir, rmdir, unlink makes a directory, removes an empty one, removes a file
#! rename moves a file to another path, replacing a file there
#! getcwd, chdir reads and sets the working directory
#! dir_stream, opendir reads the names a directory holds, with their kinds
#! error_of what a failure means, as an `io_error`
#! fork, wait starts a copy of the program and waits for it,
#! which Windows starts from the start, by `respawn`
#! pipe, spawn, poll makes a pipe, starts another program, and waits,
#! for at most a while, until one of several handles
#! can be read
#! environment, null_device the variables the program started with, and the
#! path of the device that holds nothing
#! kill, raise, getpid sends a signal to a process, or to the program
#! itself, and gives the program's own number
#! ignore, restore, handle has the system throw a signal away, do what it
#! does by default, or note it for a handler
#! pause waits until a handler has run
#! clock, sleep reads the wall clock or the steady one, and waits
#! for a length of time
#! futex_wait, futex_wake waits while a word holds a value, and wakes those
#! waiting on it, which threads, and on Linux processes
#! sharing memory, wait for one another with
#! cpu_count, thread_id, how many processors the program may run on, the
#! yield_now calling thread's number, and letting others run
#! ```
#!
#! Windows also provides `respawn`, which starts a copy of the program from its
#! start, and `zone_rule`, the rule of the zone the system is set to, since it
#! keeps no files of zones.
#!
#! What every system shares of signals is here: the `signal` each is, and the
#! handlers. A handler never runs in the middle of whatever the program was
#! doing, as C's does. The system's own handler only notes that the signal came,
#! and the program's runs at its next safe point: where one of the program's own
#! functions begins, or a pass of one of its loops, in a program that handles a
#! signal somewhere. A wait the signal interrupts runs the handlers too, then
#! ends, failing with `io_error::interrupted`. So a handler may do anything a
#! function may, and never finds a container, a string, or a writer of std in
#! the middle of a change.
module system;
#! How a copy of the program that `fork` started stopped, or a program `spawn`
#! started, as `wait` gives it.
pub struct process_status {
pub var exited: bool; #! Whether it stopped by exiting, with `code`, rather than by a signal.
pub var code: i32; #! The status it exited with.
pub var signal: i32; #! The signal that stopped it, when it did not exit.
}
#! What `spawn` starts a program with, all of which it copies before the program
#! starts.
pub struct spawn_request {
#! The path of the program, which is found already.
pub var program: strview;
#! What the program is given, the first being what it is called.
pub var arguments: span<strview>;
#! The variables it is given, each as `NAME=value`.
pub var environment: span<strview>;
#! Where it runs, or empty for where this program runs.
pub var directory: strview;
#! The handle its standard input is given.
pub var input: fd;
#! The handle its standard output is given.
pub var output: fd;
#! The handle its standard error is given.
pub var error: fd;
}
#! A name a directory holds, as `dir_stream::next` gives it.
pub struct dir_entry {
pub var name: strview; #! Only good until the next entry is read.
pub var kind: file_kind; #! What the name is itself, not what a link there leads to.
}
#! Stops the program with a status, having run everything asked of it.
#!
#! Whatever the program has written is written, and nothing it has yet to do is
#! done. A status of zero says the program did what it was asked to.
#! @param code The status to stop with, which Linux reads as a byte, and
#! Windows whole.
@intrinsic
pub def exit(code: i32): void;
#! Stops the program at once, reporting where it was.
#!
#! This is for a program that has found something it cannot go on from. It is
#! not graceful: the report names the functions that were running, and the
#! status is the one every other fault gives.
@intrinsic
pub def abort(): void;
#! Starts a thread of the system running a function given a context, which the
#! backend makes: a thread of the virtual machine, or of an executable with
#! stacks of its own. `std::thread` starts threads with it.
#! @param body The function the thread runs.
#! @param context What the function is given.
#! @returns The thread's number, or a negative error number. A program
#! evaluating a constant starts none.
@intrinsic
pub def start(body: def(*mut u8): void, context: *mut u8): i64;
#! A signal the system, or another program, sends a program.
#!
#! The members are the same on every system, which numbers them in its own way.
#! Faults are not among them: reading through a null pointer, dividing by zero,
#! and the like stop the program with a report, since a fault is a mistake of
#! the program that no handler can put right.
pub enum signal: u8 {
#! SIGHUP: the terminal went away. By custom, a server reads its settings
#! again.
hangup,
#! SIGINT: Ctrl-C.
interrupt,
#! SIGQUIT: Ctrl-\.
quit,
#! SIGKILL: the program stops at once. It cannot be handled or ignored.
kill,
#! SIGUSR1: whatever the programs sending and receiving it agree on.
user1,
#! SIGUSR2: the same.
user2,
#! SIGPIPE: the program wrote to a pipe nothing reads.
pipe,
#! SIGALRM: a timer ran out.
alarm,
#! SIGTERM: the program is asked to stop.
terminate,
#! SIGCHLD: a child stopped, or was paused or resumed.
child,
#! SIGCONT: the program goes on after being paused.
resume,
#! SIGSTOP: the program is paused. It cannot be handled or ignored.
stop,
#! SIGTSTP: Ctrl-Z, asking the program to pause.
suspend,
#! SIGWINCH: the terminal changed size.
resized,
}
#! A function that handles a signal, given the signal it handles, which it owns,
#! as a functor holding what it needs: whatever it was given as.
pub type handler = function<def(signal): void>;
# How many members `signal` has.
const signal_count: u64 = 14;
# The handler of each signal, by member, which holds nothing where none was
# given, and which signals the program handles, one bit each by the system's
# number.
var handlers: handler[signal_count];
var handled: u64;
# The signals the program watches for rather than handles, one bit each by the
# system's number, and the signals taken from the system that neither `watched`
# nor the handlers have yet.
var noting: u64;
var arrived: u64;
# Whether a handler is running, so that another runs only once it returns.
var dispatching: bool;
# Has the system note a signal of its number when it comes, rather than doing
# what it would, and end the waits the signal interrupts rather than go on with
# them. Gives zero, or a negative number.
@intrinsic
def catch_signal(number: i32): i32;
# Gives the signals noted since they were last asked for, one bit each by the
# system's number, and forgets them in the same step.
@intrinsic
def take_signals(): u64;
# Runs the handlers of the signals that have come. Safe points call this, which
# std's own code has none of.
def dispatch(): void {
_ = run_handlers();
}
# Runs the handler of each signal that has come, in the order of the system's
# numbers, until none has, giving whether any ran. Within a handler it runs
# none, so the signals that come while one runs are handled once it returns. A
# signal that came before the program stopped handling it is passed over.
# Handlers run in the thread the program began with, as each system's
# `is_first_thread` finds it, so a wait another thread's signal ended runs none.
def run_handlers(): bool {
if dispatching || !is_first_thread() {
return false;
}
dispatching = true;
var ran := false;
while true {
arrived = arrived | take_signals();
val waiting := arrived & ~noting;
arrived = arrived & noting;
if waiting == 0 {
break;
}
# A handler may stop the program handling a signal that came with its own.
for number in 0u..64u {
if (((waiting & handled) >> number) & 1) == 0 {
continue;
}
val which := signal_of(number as i64) else { continue; };
# A handler is taken from its place while it runs, so one handling its own
# signal anew replaces it without closing what runs. It goes back where
# nothing replaced it, and closes where something did.
var by := move(&mut handlers[which as u64]);
if !by.holds() {
continue;
}
by(which);
ran = true;
if !handlers[which as u64].holds() {
handlers[which as u64] = move(&mut by);
}
}
}
dispatching = false;
return ran;
}
+18
View File
@@ -0,0 +1,18 @@
#! @file waits.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the functions Windows keeps for waiting on a word, of
#! `system::windows`, which `system` and the runtime wait and wake with. They are
#! a library of their own, and a file names one library on Windows.
extern import "api-ms-win-core-synch-l1-2-0.dll" when os == windows;
extern module system::windows when os == windows;
pub def WaitOnAddress(
at: *mut u32, compare: &u32, size: u64, milliseconds: u32
): i32;
pub def WakeByAddressSingle(at: *mut u32): void;
pub def WakeByAddressAll(at: *mut u32): void;
+270
View File
@@ -0,0 +1,270 @@
#! @file windows.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains `system::windows`: what Windows gives a program, declared once for
#! std, its runtime, and anything else that reaches the system itself. These are
#! the functions of `kernel32.dll`, the structs they take, as C lays them out,
#! and the numbers they are asked for and give. The functions Windows keeps for
#! waiting on a word are in `waits.sakura`, a library of their own.
extern import "kernel32.dll" when os == windows;
extern module system::windows when os == windows;
pub def GetLastError(): u32;
pub def SetLastError(code: u32): void;
pub def GetStdHandle(which: u32): u64;
pub def SetStdHandle(which: u32, handle: u64): i32;
pub def CloseHandle(handle: u64): i32;
pub def DuplicateHandle(
from_process: u64, handle: u64, to_process: u64, made: &mut u64, access: u32, inherit: i32, options: u32
): i32;
pub def CreateFileW(
name: *u16, access: u32, share: u32, security: *mut u8, disposition: u32, flags: u32, model: u64
): u64;
pub def ReOpenFile(handle: u64, access: u32, share: u32, flags: u32): u64;
pub def ReadFile(
handle: u64, into: *mut u8, length: u32, read: &mut u32, overlapped: *mut u8
): i32;
pub def WriteFile(
handle: u64, from: *u8, length: u32, written: &mut u32, overlapped: *mut u8
): i32;
pub def SetFilePointerEx(handle: u64, distance: i64, position: &mut i64, method: u32): i32;
pub def GetFileType(handle: u64): u32;
pub def GetFileInformationByHandle(handle: u64, info: &mut file_information): i32;
pub def GetFileInformationByHandleEx(handle: u64, class: u32, info: *mut u8, size: u32): i32;
pub def SetFileInformationByHandle(handle: u64, class: u32, info: *mut u8, size: u32): i32;
pub def GetFinalPathNameByHandleW(handle: u64, into: *mut u16, length: u32, flags: u32): u32;
pub def GetFileAttributesW(name: *u16): u32;
pub def SetFileAttributesW(name: *u16, attributes: u32): i32;
pub def CreateDirectoryW(name: *u16, security: *mut u8): i32;
pub def RemoveDirectoryW(name: *u16): i32;
pub def DeleteFileW(name: *u16): i32;
pub def MoveFileExW(from: *u16, to: *u16, flags: u32): i32;
pub def GetCurrentDirectoryW(length: u32, into: *mut u16): u32;
pub def SetCurrentDirectoryW(name: *u16): i32;
pub def GetFullPathNameW(name: *u16, length: u32, into: *mut u16, part: *mut u8): u32;
pub def FindFirstFileExW(
name: *u16, level: u32, data: *mut u8, search: u32, filter: *mut u8, flags: u32
): u64;
pub def FindNextFileW(find: u64, data: *mut u8): i32;
pub def FindClose(find: u64): i32;
pub def GetConsoleMode(handle: u64, mode: &mut u32): i32;
pub def GetConsoleWindow(): u64;
pub def WriteConsoleW(
handle: u64, from: *u16, length: u32, written: &mut u32, reserved: *mut u8
): i32;
pub def ReadConsoleW(
handle: u64, into: *mut u16, length: u32, read: &mut u32, control: *mut u8
): i32;
pub def CreatePipe(reading: &mut u64, writing: &mut u64, security: *mut u8, size: u32): i32;
pub def PeekNamedPipe(
handle: u64, into: *mut u8, length: u32, read: *mut u32, available: &mut u32, left: *mut u32
): i32;
pub def GetCurrentProcess(): u64;
pub def GetCurrentProcessId(): u32;
pub def GetCurrentThreadId(): u32;
pub def GetModuleFileNameW(library: u64, into: *mut u16, length: u32): u32;
pub def GetCommandLineW(): *u16;
pub def GetSystemDirectoryW(into: *mut u16, length: u32): u32;
pub def CreateProcessW(
application: *u16, command: *mut u16, process_security: *mut u8, thread_security: *mut u8, inherit: i32,
flags: u32, environment: *mut u16, directory: *u16, startup: &mut startup_information,
information: &mut process_information
): i32;
pub def InitializeProcThreadAttributeList(
list: *mut u8, count: u32, flags: u32, size: &mut u64
): i32;
pub def UpdateProcThreadAttribute(
list: *mut u8, flags: u32, attribute: u64, value: *mut u8, size: u64, previous: *mut u8, returned: *mut u64
): i32;
pub def DeleteProcThreadAttributeList(list: *mut u8): void;
pub def OpenProcess(access: u32, inherit: i32, process: u32): u64;
pub def TerminateProcess(process: u64, code: u32): i32;
pub def GetExitCodeProcess(process: u64, code: &mut u32): i32;
pub def WaitForSingleObject(handle: u64, milliseconds: u32): u32;
pub def WaitForMultipleObjects(count: u32, handles: *u64, all: i32, milliseconds: u32): u32;
pub def CreateWaitableTimerExW(security: *mut u8, name: *u16, flags: u32, access: u32): u64;
pub def SetWaitableTimer(
timer: u64, due: &i64, period: i32, routine: *mut u8, argument: *mut u8, wake: i32
): i32;
pub def Sleep(milliseconds: u32): void;
pub def SwitchToThread(): i32;
pub def GetActiveProcessorCount(group: u16): u32;
pub def GetProcessAffinityMask(process: u64, mask: &mut u64, system: &mut u64): i32;
pub def GetEnvironmentStringsW(): *mut u16;
pub def FreeEnvironmentStringsW(block: *mut u16): i32;
pub def GetSystemTimePreciseAsFileTime(time: &mut filetime): void;
pub def QueryPerformanceCounter(count: &mut i64): i32;
pub def QueryPerformanceFrequency(frequency: &mut i64): i32;
pub def GetDynamicTimeZoneInformation(into: &mut zone_information): u32;
pub def VirtualAlloc(address: u64, size: u64, kind: u32, protection: u32): u64;
pub def VirtualFree(address: u64, size: u64, kind: u32): i32;
pub def MultiByteToWideChar(page: u32, flags: u32, bytes: *u8, count: i32,
units: *mut u16, room: i32): i32;
pub def WideCharToMultiByte(
page: u32, flags: u32, wide: *u16, count: i32, into: *mut u8, size: i32, fallback: *u8, used: *mut i32
): i32;
pub def ExitProcess(code: u32): void;
pub def SetErrorMode(mode: u32): u32;
pub def OpenThread(access: u32, inherit: i32, id: u32): u64;
pub def SuspendThread(thread: u64): u32;
pub def ResumeThread(thread: u64): u32;
pub def GetThreadContext(thread: u64, context: *mut u64): i32;
pub def VirtualProtect(at: u64, size: u64, protect: u32, was: &mut u32): i32;
pub def FlushInstructionCache(process: u64, at: u64, size: u64): i32;
pub def LoadLibraryW(name: *u16): u64;
pub def FreeLibrary(handle: u64): i32;
pub def GetProcAddress(handle: u64, name: *u8): u64;
pub def GetModuleHandleW(name: *u16): u64;
pub def K32EnumProcessModules(process: u64, into: *mut u64, size: u32, needed: &mut u32): i32;
pub def CreateJobObjectW(security: *mut u8, name: *u16): u64;
pub def SetInformationJobObject(job: u64, kind: u32, information: *mut u8, length: u32): i32;
pub def AssignProcessToJobObject(job: u64, process: u64): i32;
# What the system's functions are asked for, and what they give.
pub val invalid_handle: u64 = 0xFFFFFFFFFFFFFFFF;
pub val invalid_attributes: u32 = 0xFFFFFFFF;
pub val infinite: u32 = 0xFFFFFFFF;
pub val wait_failed: u32 = 0xFFFFFFFF;
pub val generic_read: u32 = 0x80000000;
pub val generic_write: u32 = 0x40000000;
pub val append_data: u32 = 0x4;
pub val read_attributes: u32 = 0x80;
pub val write_attributes: u32 = 0x100;
pub val synchronize: u32 = 0x100000;
pub val share_all: u32 = 7; # Others may read, write, rename, and remove it.
pub val create_new: u32 = 1;
pub val create_always: u32 = 2;
pub val open_existing: u32 = 3;
pub val open_always: u32 = 4;
pub val truncate_existing: u32 = 5;
pub val backup_semantics: u32 = 0x02000000; # Lets a directory be opened.
pub val open_reparse_point: u32 = 0x00200000; # Opens a link rather than what it leads to.
pub val readonly: u32 = 0x1;
pub val directory: u32 = 0x10;
pub val device: u32 = 0x40;
pub val normal: u32 = 0x80;
pub val reparse_point: u32 = 0x400;
pub val symlink_tag: u32 = 0xA000000C;
pub val junction_tag: u32 = 0xA0000003;
pub val disk_type: u32 = 1;
pub val use_std_handles: u32 = 0x100;
pub val unicode_block: u32 = 0x400;
pub val extended_startup: u32 = 0x80000;
pub val create_no_window: u32 = 0x08000000; # A console program started gets a console no one sees.
pub val handle_list: u64 = 0x20002;
pub val same_access: u32 = 2;
pub val process_terminate: u32 = 1;
pub val control_c_exit: u32 = 0xC000013A; # What a program the console's Ctrl-C stopped exits with.
# The codes of failures the operations look for themselves.
pub val error_file_not_found: u32 = 2;
pub val error_path_not_found: u32 = 3;
pub val error_access_denied: u32 = 5;
pub val error_invalid_function: u32 = 1;
pub val error_sharing_violation: u32 = 32;
pub val error_handle_eof: u32 = 38;
pub val error_invalid_parameter: u32 = 87;
pub val error_broken_pipe: u32 = 109;
pub val error_no_more_files: u32 = 18;
pub val error_bad_exe_format: u32 = 193;
pub val error_operation_aborted: u32 = 995;
pub val error_timeout: u32 = 1460;
pub val error_cant_access_file: u32 = 1920;
# A time of the system, in tenths of microseconds since 1601 began, as two
# halves.
pub struct filetime {
pub var low: u32;
pub var high: u32;
}
# What `GetFileInformationByHandle` describes a file with.
pub struct file_information {
pub var attributes: u32;
pub var created: filetime;
pub var accessed: filetime;
pub var written: filetime;
pub var volume: u32;
pub var size_high: u32;
pub var size_low: u32;
pub var links: u32;
pub var index_high: u32;
pub var index_low: u32;
}
# What `SetFileInformationByHandle` sets a file's attributes with, leaving each
# time that is zero as it is.
pub struct basic_information {
pub var created: i64;
pub var accessed: i64;
pub var written: i64;
pub var changed: i64;
pub var attributes: u32;
}
# What a program is started with: its window, which a program of the console
# has none of, its standard streams, and a list of what more it is given.
pub struct startup_information {
pub var size: u32;
pub var reserved: *mut u16;
pub var desktop: *mut u16;
pub var title: *mut u16;
pub var x: u32;
pub var y: u32;
pub var width: u32;
pub var height: u32;
pub var columns: u32;
pub var rows: u32;
pub var fill: u32;
pub var flags: u32;
pub var show: u16;
pub var extra_size: u16;
pub var extra: *mut u8;
pub var standard_input: u64;
pub var standard_output: u64;
pub var standard_error: u64;
pub var attributes: *mut u8;
}
# What `CreateProcessW` gives of a program it started.
pub struct process_information {
pub var process: u64;
pub var thread: u64;
pub var process_id: u32;
pub var thread_id: u32;
}
# A date and time of the system, as a zone's changes are given.
pub struct system_time {
pub var year: u16;
pub var month: u16;
pub var day_of_week: u16;
pub var day: u16; # Of a change, which of the month's weeks, 5 being its last.
pub var hour: u16;
pub var minute: u16;
pub var second: u16;
pub var millisecond: u16;
}
# The zone the system is set to, as `GetDynamicTimeZoneInformation` gives it:
# minutes behind UTC, and what it calls its usual and its summer time, how far
# each is from that, and when each begins.
pub struct zone_information {
pub var bias: i32;
pub var standard_name: u16[32];
pub var standard_date: system_time;
pub var standard_bias: i32;
pub var daylight_name: u16[32];
pub var daylight_date: system_time;
pub var daylight_bias: i32;
pub var key_name: u16[128];
pub var no_daylight: u8;
}
pub const startup_bytes: u64 = 112;
pub const basic_bytes: u64 = 40;