data_type
large_stringclasses
3 values
source
large_stringclasses
29 values
code
large_stringlengths
98
49.4M
filepath
large_stringlengths
5
161
message
large_stringclasses
234 values
commit
large_stringclasses
234 values
subject
large_stringclasses
418 values
critique
large_stringlengths
101
1.26M
metadata
dict
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use core::{marker::PhantomData, ptr::NonNull}; use super::NonNullPtr; use crate::util::Either; // If both `L` and `R` have at least one alignment bit (i.e., their alignments are at least 2), we // can use the alignment bit to indicate whether a pointer is `L` or `R`, so it's possi...
ostd/src/sync/rcu/non_null/either.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! This module provides a trait and some auxiliary types to help abstract and //! work with non-null pointers. mod either; use core::{marker::PhantomData, mem::ManuallyDrop, ops::Deref, ptr::NonNull}; use crate::prelude::*; /// A trait that abstracts non-null pointers. /// /// ...
ostd/src/sync/rcu/non_null/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! Atomic Mode //! //! Multitasking, while powerful, can sometimes lead to undesirable //! or catastrophic consequences if being misused. //! For instance, a user of OSTD might accidentally write an IRQ handler //! that relies on mutexes, //! which could attempt to sleep within an ...
ostd/src/task/atomic_mode.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use core::sync::atomic::Ordering; use crate::{ arch::mm::tlb_flush_addr_range, cpu::{AtomicCpuSet, CpuSet, PinCurrentCpu}, impl_frame_meta_for, irq::DisabledLocalIrqGuard, mm::{ FrameAllocOptions, PAGE_SIZE, kspace::kvirt_area::KVirtArea, ...
ostd/src/task/kernel_stack.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! Tasks are the unit of code execution. pub mod atomic_mode; mod kernel_stack; mod preempt; mod processor; pub mod scheduler; mod utils; use core::{ any::Any, borrow::Borrow, cell::{Cell, SyncUnsafeCell}, ops::Deref, ptr::NonNull, sync::atomic::AtomicBool...
ostd/src/task/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use alloc::sync::Arc; use core::{ptr::NonNull, sync::atomic::Ordering}; use super::{POST_SCHEDULE_HANDLER, PRE_SCHEDULE_HANDLER, Task}; use crate::{ arch::task::{context_switch, first_context_switch}, cpu_local_cell, irq::DisabledLocalIrqGuard, }; cpu_local_cell! { ...
ostd/src/task/processor.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use alloc::fmt; /// Always [`Sync`], but unsafe to reference the data. pub(super) struct ForceSync<T>(T); impl<T> fmt::Debug for ForceSync<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ForceSync").finish_non_exhaustive() } } // SA...
ostd/src/task/utils.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! This module maintains preemption-related information for the current task //! on a CPU with a single 32-bit, CPU-local integer value. //! //! * Bits from 0 to 30 represents an unsigned counter called `guard_count`, //! which is the number of `DisabledPreemptGuard` instances he...
ostd/src/task/preempt/cpu_local.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use crate::{sync::GuardTransfer, task::atomic_mode::InAtomicMode}; /// A guard for disable preempt. #[clippy::has_significant_drop] #[must_use] #[derive(Debug)] pub struct DisabledPreemptGuard { // This private field prevents user from constructing values of this type directly....
ostd/src/task/preempt/guard.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 pub(super) mod cpu_local; mod guard; pub use self::guard::{DisabledPreemptGuard, disable_preempt}; /// Halts the CPU until interrupts if no preemption is required. /// /// This function will return if: /// - preemption is required when calling this function, /// - preemption is ...
ostd/src/task/preempt/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use alloc::{boxed::Box, collections::VecDeque, sync::Arc, vec::Vec}; use super::{EnqueueFlags, LocalRunQueue, Scheduler, UpdateFlags, info::CommonSchedInfo}; use crate::{ cpu::{CpuId, PinCurrentCpu, num_cpus}, sync::SpinLock, task::{Task, disable_preempt}, util::id_...
ostd/src/task/scheduler/fifo_scheduler.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! Scheduling related information in a task. use core::sync::atomic::{AtomicU32, Ordering}; use crate::{cpu::CpuId, task::Task}; /// Fields of a task that OSTD will never touch. /// /// The type ought to be defined by the OSTD user and injected into the task. /// They are not pa...
ostd/src/task/scheduler/info.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! Task scheduling. //! //! # Scheduler Injection //! //! The task scheduler of an OS is a complex beast, //! and the most suitable scheduling algorithm often depends on the target usage scenario. //! To avoid code bloat and offer flexibility, //! OSTD does not include a gigantic, ...
ostd/src/task/scheduler/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use core::{ sync::atomic::{AtomicU64, Ordering}, time::Duration, }; use super::TIMER_FREQ; /// Jiffies is a term used to denote the units of time measurement by the kernel. /// /// A jiffy represents one tick of the system timer interrupt, /// whose frequency is equal to [...
ostd/src/timer/jiffies.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! The timer support. mod jiffies; use alloc::{boxed::Box, vec::Vec}; use core::{cell::RefCell, sync::atomic::Ordering}; pub use jiffies::Jiffies; use crate::{ arch::trap::TrapFrame, cpu::{CpuId, PinCurrentCpu}, cpu_local, irq, }; /// The timer frequency in Hz. ///...
ostd/src/timer/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 /// A type containing either a [`Left`] value `L` or a [`Right`] value `R`. /// /// [`Left`]: Self::Left /// [`Right`]: Self::Right #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Either<L, R> { /// Contains the left value Left(L), /// Contains the right value ...
ostd/src/util/either.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! A fixed-size set of unique IDs. //! //! This module introduces two abstract data collection types. //! The first one is [`IdSet<I>`], //! a set that contains at most `I::cardinality()` items, //! each of which represents a unique ID of type `I`. //! The second one is [`AtomicIdS...
ostd/src/util/id_set.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 /// Asserts that a boolean expression is `true` at compile-time. /// /// Rust provides [`const` blocks], which can be used flexibly within methods, but cannot be used /// directly at the top level. This macro serves as a helper to perform compile-time assertions /// outside of metho...
ostd/src/util/macros.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! Utility types and methods. mod either; pub mod id_set; mod macros; pub(crate) mod ops; pub(crate) mod range_alloc; pub(crate) mod range_counter; pub use either::Either;
ostd/src/util/mod.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use core::ops::Range; /// Calculates the [difference] of two [`Range`]s, i.e., `a - b`. /// /// This method will return 0, 1, or 2 ranges. All returned ranges are /// guaranteed to be non-empty and non-overlapping. The returned ranges /// will be sorted in ascending order. /// /// ...
ostd/src/util/ops.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 use alloc::collections::btree_map::BTreeMap; use core::ops::Range; use crate::sync::{PreemptDisabled, SpinLock, SpinLockGuard}; pub struct RangeAllocator { fullrange: Range<usize>, freelist: SpinLock<Option<BTreeMap<usize, FreeRange>>>, } /// An error returned when alloca...
ostd/src/util/range_alloc.rs
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 //! A data structure that tracks a contiguous range of counters. // TODO: A segment tree can optimize every operations to `O(log(range size))`. // We just keep it simple for now, since it should just be used for small // ranges like DMA and I/O memory. use alloc::{collections::btr...
ostd/src/util/range_counter.rs
null
null
null
null
null
source
asterinas
# Test Suites This directory contains the testing infrastructure for Asterinas, organized into two complementary testing approaches. ## Test Types ### Initramfs-Based Tests ([`initramfs/`](initramfs/)) Tests running in a minimal initramfs environment. Best for: - System call validation - Core functionality testing ...
test/README.md
null
null
null
null
null
source
asterinas
# Initramfs-Based Test Suites This directory contains the test suites of Asterinas running in initramfs, including various test programs, benchmarks, syscall test suites, and necessary configuration files. The structure of the test directory is designed to be modular and flexible, supporting multiple CPU architectures...
test/initramfs/README.md
null
null
null
null
null
source
asterinas
/* SPDX-License-Identifier: MPL-2.0 */ /* * A framework for writing general tests. * * A general test typically consists of two parts, the setup part and the * test part. The setup part contains setup functions that set up the context * for the subsequent tests to run. The setup functions cannot fail, and if they...
test/initramfs/src/apps/common/test.h
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "../common/test.h" #define INPUT_DIR "/dev/input" #define MAX_EVDEV_DEVICES 16 static int evdev_fds[MAX_EVDEV_DEVI...
test/initramfs/src/apps/device/evdev.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <linux/fb.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/wait.h> #include <uni...
test/initramfs/src/apps/device/framebuffer.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <fcntl.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include <sys/sysmacros.h> #include <sys/poll.h> #include "../common/test.h" #define DEVICE_PATH "/dev/full" #define READ_SIZE 100 int fd; char buffer[READ_SIZE]; FN_SETUP(open) { fd = CHECK(open(DE...
test/initramfs/src/apps/device/full.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <unistd.h> #include <sys/mman.h> #include <sys/fcntl.h> #include "../common/test.h" #define PAGE_SIZE 4096 FN_TEST(short_rw) { int fd; char *buf; fd = TEST_SUCC(open("/dev/random", O_RDONLY)); buf = TEST_SUCC(mmap(NULL, PAGE_SIZE * 3, PROT_READ | PROT_WRITE, ...
test/initramfs/src/apps/device/random.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <pty.h> #include <poll.h> #include "../../common/test.h" int master; int slave; char slave_name[256]; #define POLL_EVENTS (POLLIN | POLLOUT | POLLRDHUP | POLLPRI | POLLRDNORM) void open_and_s...
test/initramfs/src/apps/device/pty/close_pty.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <pty.h> #include <poll.h> #include <sys/wait.h> #include "../../common/test.h" #define DEV_PTMX "/dev/ptmx" int master; int slave; char slave_name[128]; ...
test/initramfs/src/apps/device/pty/open_ptmx.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <pty.h> int main() { int master, slave; char name[256]; struct termios term; if (openpty(&master, &slave, name, NULL, NULL) == -1) { perror("openpty"); exit(EXIT_FAI...
test/initramfs/src/apps/device/pty/open_pty.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "../../common/test.h" #include <pthread.h> #include <pty.h> #include <unistd.h> #include <sys/ioctl.h> static int master, slave; FN_SETUP(openpty) { CHECK(openpty(&master, &slave, NULL, NULL, NULL)); } END_SETUP() static int write_repeat(int fd, char c, size_t n) { wh...
test/initramfs/src/apps/device/pty/pty_blocking.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include <pty.h> #include <poll.h> #include "../../common/test.h" int master; int slave; struct pollfd pfd; #define POLL_EVENTS (POLLIN | POLLOUT | POLLRDHUP | PO...
test/initramfs/src/apps/device/pty/pty_packet_mode.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <dirent.h> #include <fcntl.h> #include <limits.h> #include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/wait.h> #include <u...
test/initramfs/src/apps/fs/chroot/chroot_jail.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/sysmacros.h> #include "../../common/test.h" #define NULL_DEVICE_PATH "/ext2/my_null_device" #define ZERO_...
test/initramfs/src/apps/fs/ext2/mknod.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include "../../common/test.h" #define SERVER_ADDRESS "/ext2/my_unix_server" FN_TEST(ext2_unix_socket) { int sk_se...
test/initramfs/src/apps/fs/ext2/unix_socket.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> void test_fdatasync_on_fs(const char *directory) { char filepath[256]; snprintf(filepath, sizeof(filepath), "%s/test_fdatasync.txt", directory); int fd = open(filepath, O_WRON...
test/initramfs/src/apps/fs/fdatasync/fdatasync.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <errno.h> #include <fcntl.h> #include <poll.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/ioctl.h> #include <time...
test/initramfs/src/apps/fs/inotify/inotify_align.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <errno.h> #include <fcntl.h> #include <poll.h> #include <signal.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/inotify.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <time....
test/initramfs/src/apps/fs/inotify/inotify_poll.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <sys/inotify.h> #include <sys/fcntl.h> #include <unistd.h> #include "../../common/test.h" #define TEST_FILE "/tmp/test1" FN_TEST(unlink_add) { int inotify_fd, fd, wd; inotify_fd = TEST_SUCC(inotify_init1(O_NONBLOCK)); fd = TEST_RES(open(TEST_FILE, O_CREAT | O_WRONLY,...
test/initramfs/src/apps/fs/inotify/inotify_unlink.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #define OVERLAYDIR "/overlay" #define LOWERDIR1 OVERLAYDIR "/lower1" #define LOWERDIR2 OVERLAYDIR...
test/initramfs/src/apps/fs/overlayfs/ovl_test.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <fcntl.h> #include <wait.h> #include "../../common/test.h" FN_TEST(negative_cache_pid) { pid_t pid, pid2; char path[20]; int i, status; pid = TEST_SUCC(getpid()); // These paths may not yet exist, but we cannot cache negativ...
test/initramfs/src/apps/fs/procfs/dentry_cache.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> #include <stdint.h> #include <string.h> #include "../../common/test.h" #define PAGE_SIZE 4096 #define ORIG_STR "...
test/initramfs/src/apps/fs/procfs/pid_mem.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <sys/mman.h> #include <sys/types.h> #include <linux/memfd.h> #include <sys/ioctl.h> #include <linux/fs.h> #include "../../common/test.h" char memfd_path[64]; FN_SETUP(cre...
test/initramfs/src/apps/fs/pseudofs/memfd_access_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "pseudo_file_create.h" static int readlink_check(int fd, const char *expect_prefix, int check_ino) { char path[64]; char buf[256]; struct stat st; fd_path(fd, path, sizeof(path)); ssize_t len = readlink(path, buf, sizeof(buf) - 1); if (len < 0) return -1; buf[len...
test/initramfs/src/apps/fs/pseudofs/pseudo_dentry.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 FN_SETUP(cleanup) { CHECK(close(pipe_1[0])); CHECK(close(pipe_1[1])); CHECK(close(pipe_2[0])); CHECK(close(pipe_2[1])); CHECK(close(sock[0])); CHECK(close(sock[1])); CHECK(close(epoll_fd)); CHECK(close(event_fd)); CHECK(close(timer_fd)); CHECK(close(signal_fd)); CHECK(clo...
test/initramfs/src/apps/fs/pseudofs/pseudo_file_cleanup.h
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <string.h> #include <sys/socket.h> #include <sys/eventfd.h> #include <sys/timerfd.h> #include <sys/signalfd.h> #include <sys/epoll.h> #include <sys/in...
test/initramfs/src/apps/fs/pseudofs/pseudo_file_create.h
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "pseudo_file_create.h" static int get_mode(int fd) { char path[64]; struct stat st; fd_path(fd, path, sizeof(path)); if (stat(path, &st) < 0) return -1; return st.st_mode & 0777; } static int set_mode(int fd, int mode) { char path[64]; fd_path(fd, path, sizeof...
test/initramfs/src/apps/fs/pseudofs/pseudo_inode.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "pseudo_file_create.h" static int read_fdinfo_mnt_id(int fd) { char path[64], line[256]; FILE *f; fdinfo_path(fd, path, sizeof(path)); f = fopen(path, "r"); if (!f) return -1; int mnt_id = -1; while (fgets(line, sizeof(line), f)) { if (CHECK(sscanf(line, "mnt_...
test/initramfs/src/apps/fs/pseudofs/pseudo_mount.c
null
null
null
null
null
source
asterinas
# SPDX-License-Identifier: MPL-2.0 .global _start .section .text _start: call print_message call print_message call print_message mov $60, %rax # syscall number of exit mov $0, %rdi # exit code syscall get_pid: mov $39, %rax sysca...
test/initramfs/src/apps/hello_world/in_assembly/hello.S
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> int main() { printf("hello world from hello_c!\n"); return 0; }
test/initramfs/src/apps/hello_world/in_c/hello.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> int main() { printf("hello world from hello_pie!\n"); return 0; }
test/initramfs/src/apps/hello_world/in_c_pie/hello.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "../../common/test.h" #include <unistd.h> #include <sys/epoll.h> FN_TEST(epoll_add_del) { int fildes[2]; int epfd, rfd, wfd, rfd2; struct epoll_event ev; // Setup pipes TEST_SUCC(pipe(fildes)); rfd = fildes[0]; wfd = fildes[1]; TEST_SUCC(write(wfd, "", 1)); // S...
test/initramfs/src/apps/io/epoll/epoll_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/epoll.h> #include <signal.h> #include <sys/wait.h> #include <string.h> // Signal handler for SIGUSR1 static void handle_sigusr1(int sig) { (void)!write(STDOUT_FILENO, "SIGUSR1 handled\n", 16); } int main(voi...
test/initramfs/src/apps/io/epoll/epoll_pwait.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/epoll.h> #include <sys/wait.h> #include <string.h> int main(void) { int pipefd[2]; // Array to store pipe file descriptors pid_t cpid; // Child process ID char buf[1024]; // Read buffer struct epoll_event ...
test/initramfs/src/apps/io/epoll/epoll_wait.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include "../../common/test.h" #include <unistd.h> #include <sys/poll.h> FN_TEST(poll_nval) { int fildes[2]; int rfd, wfd; struct pollfd fds[3]; TEST_SUCC(pipe(fildes)); rfd = fildes[0]; wfd = fildes[1]; TEST_SUCC(write(wfd, "", 1)); fds[0].fd = rfd; fds[1].fd = 1000; f...
test/initramfs/src/apps/io/epoll/poll_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <err.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <sys/eventfd.h> #include <unistd.h> int main() { int efd; uint64_t u; ssize_t s; uint64_t values[] = { 11, 222, 3333 }; size_t length = sizeof(values) / sizeof(values[0]); efd = eventfd(0...
test/initramfs/src/apps/io/eventfd2/eventfd2.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/file.h> #include <poll.h> #include "../../common/test.h" #define FILENAME "/tmp/testfile" #define DIRNAME "/tmp" #define PAGE_SIZE 4096 static struct flock f_rdl...
test/initramfs/src/apps/io/file_io/access_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include "../../common/test.h" #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> static int fd; FN_SETUP(open) { fd = CHECK(open("/etc/passwd", O_RDONLY)); } END_SETUP() FN_TEST(dup_out_of_range) { // `-1` is out of the allowe...
test/initramfs/src/apps/io/file_io/file_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <time.h> #define KB 1024 #define MB (1024 * KB) #define BUFFER_SIZE (4 * KB) #define FILE_SIZE (256 * MB) #define NUM_OF_CALLS 1000000 int fill_file(in...
test/initramfs/src/apps/io/file_io/file_io.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdint.h> #include <sys/fcntl.h> #include <sys/socket.h> #include <sys/uio.h> #include <unistd.h> #include "../../common/test.h" static char buf[16]; static struct iovec iov_long[UIO_MAXIOV + 2]; static struct iovec iov_inv[2]; FN_SETUP(iov) { int i; for (i = 0; i <=...
test/initramfs/src/apps/io/file_io/iovec_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include "../../common/test.h" #include <signal.h> #include <string.h> #include <sys/poll.h> #include <unistd.h> FN_SETUP() { signal(SIGPIPE, SIG_IGN); } END_SETUP() FN_TEST(close_without_data_then_read) { int fildes[2]; char buf[8] = { 0 }; CHECK(pipe(fi...
test/initramfs/src/apps/ipc/pipe/pipe_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <unistd.h> #include <sys/mman.h> #include <stdio.h> #include "../../common/test.h" #define PAGE_SIZE 4096 static void *page; static int rfd, wfd; FN_SETUP(short_read_and_write) { int fildes[2]; page = mmap((void *)0x20000000, PAGE_SIZE, PROT_READ | PROT_WRITE, ...
test/initramfs/src/apps/ipc/pipe/short_rw.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <sys/shm.h> #include <sys/stat.h> #include <sys/mman.h> // ============================================================================ // Helper macros // ===================...
test/initramfs/src/apps/ipc/shm/posix_shm.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h> #include <sys/wait.h> // Make the value not at the page boundary to uncover more bugs #define OFFSET 2 void do_test(int shared_flag, int init_value, int new_value, int expected_value) { volatile int ...
test/initramfs/src/apps/memory/mmap/mmap_and_fork.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <sys/fcntl.h> #include <sys/mman.h> #include <unistd.h> #include <string.h> #include "../../common/test.h" #define PAGE_SIZE 4096 const char *filename = "testfile"; FN_TEST(mprotect_shared_writable_mapping_on_read_only_file) { int fd = TEST_SUCC(ope...
test/initramfs/src/apps/memory/mmap/mmap_and_mprotect.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <sys/fcntl.h> #include <sys/mman.h> #include <unistd.h> #include <string.h> #include "../../common/test.h" #define PAGE_SIZE 4096 FN_TEST(mremap) { char *addr = TEST_SUCC(mmap(NULL, 5 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_AN...
test/initramfs/src/apps/memory/mmap/mmap_and_mremap.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <sys/mman.h> #include <sys/fcntl.h> #include <unistd.h> #include "../../common/test.h" #define PAGE_SIZE 4096 FN_TEST(mmap_beyond_the_file) { const char *filename = "mmap_test_file"; int fd = TEST_SUCC(open(filename, O_CREAT | O_RDWR, 0600)); TEST_SUCC(ftruncate(fd, 2...
test/initramfs/src/apps/memory/mmap/mmap_beyond_the_file.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <sys/mman.h> #include <sys/fcntl.h> #include <unistd.h> #include "../../common/test.h" #define PAGE_SIZE 4096 static void *valid_addr; static void *avail_addr; static int fd; FN_SETUP(init) { valid_addr = CHECK_WITH(mmap(NULL, PAGE_SIZE * 2, PROT_RE...
test/initramfs/src/apps/memory/mmap/mmap_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <sys/mman.h> #include "../../common/test.h" static char *start_addr; #define PAGE_SIZE 4096 FN_SETUP(init) { start_addr = CHECK_WITH(mmap(NULL, PAGE_SIZE * 4, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0), _ret != MAP_FAILED); CHECK(munmap(start_addr + P...
test/initramfs/src/apps/memory/mmap/mmap_holes.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <sys/mman.h> #include <sys/fcntl.h> #include <unistd.h> #include "../../common/test.h" #define FILE_NAME "/tmp/mmap_readahead.txt" #define PAGE_SIZE 4096 #define NR_PAGES 16 static char *addr; FN_SETUP(mmap_readahead) { int fd; fd = CHECK(open(FILE_NAME, O_RDWR | O_...
test/initramfs/src/apps/memory/mmap/mmap_readahead.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <sys/stat.h> #define FILE_PATH "test.dat" #define FILE_SIZE 4096 #define CONTENT "shared filebacked mmap test!" void create_file(const char *path, size_...
test/initramfs/src/apps/memory/mmap/mmap_shared_filebacked.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include "../../common/test.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/mman.h> #include <fcntl.h> #define PAGE_SIZE 4096 #define NUM_PAGES 1024 #define TOTAL_SIZE (PAGE_SIZE * NUM_PAGES) typedef enum rss_ty...
test/initramfs/src/apps/memory/mmap/mmap_vmrss.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <arpa/inet.h> #include <netinet/in.h> #include <stdio.h> #include <sys/socket.h> #include <unistd.h> static int new_bound_socket(struct sockaddr_in *addr) { int sockfd; sockfd = socket(PF_INET, SOCK_STREAM, 0); if (sockfd < 0) { perror("new_bound_socket: socket"); ...
test/initramfs/src/apps/network/listen_backlog.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <net/if.h> #include <netlink/route/addr.h> #include <unistd.h> #include "../common/test.h" #define ETHER_NAME "eth0" #define LOOPBACK_NAME "lo" #define SUCC(expr) ((expr), 0) int find_lo_and_eth0_by_libc(struct if_nameindex *if_ni) { int found_links = 0; for (struct ...
test/initramfs/src/apps/network/netlink_route.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <netlink/netlink.h> #include <unistd.h> #include "../common/test.h" static struct sockaddr_nl sk_addr = { .nl_family = AF_NETLINK }; #define C_PORT 1001 #define S_PORT 1002 static int sk_unbound; static int sk_bound; static int sk_connected; FN_SETUP(unbound) { sk_unb...
test/initramfs/src/apps/network/rtnl_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <arpa/inet.h> #include <netinet/in.h> #include <stdio.h> #include <sys/socket.h> #include <sys/wait.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> static int new_bound_socket(struct sockaddr_in *addr) { int sockfd; sockfd = socket(PF_INET, SOCK_STREAM, 0);...
test/initramfs/src/apps/network/send_buf_full.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <stdbool.h> #include "../common/test.h" int sk_sender; int sk_receiver; struct socka...
test/initramfs/src/apps/network/sendmmsg.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <sys/socket.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define MESG1 "Hello from child" #define MESG2 "Hello from parent" int main() { int sockets[2], child; char buf[1024]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) { ...
test/initramfs/src/apps/network/socketpair.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <unistd.h> #include <arpa/inet.h> #include "../common/test.h" int sk_unbound; int sk_listen; int sk_connected; int sk_accepted; int sk_udp; struct sockaddr_in l...
test/initramfs/src/apps/network/sockoption.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 /* * UNIX stream socket-related socket options. */ #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/un.h> #include <stdbool.h> #include <sys/wait.h> #include "../common/test.h" s...
test/initramfs/src/apps/network/sockoption_unix.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #define PORT 8080 int main() { int sock = 0; struct sockaddr_in serv_addr; char *hello = "Hello from client"; char buffer[1024] = { 0 }; // Create socket if ((sock = socket...
test/initramfs/src/apps/network/tcp_client.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <unistd.h> #include <sys/signal.h> #include <sys/socket.h> #include <sys/poll.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include "../common/test.h" static struct sockaddr_in sk_addr; #define C_PORT htons(0x1234) #define S_PORT htons(0x1235) FN...
test/initramfs/src/apps/network/tcp_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <sys/signal.h> #include <sys/socket.h> #include <sys/poll.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <stddef.h> #include "../common/test.h" #define S_PORT htons(0x1238) struct sockaddr_in sk_addr...
test/initramfs/src/apps/network/tcp_poll.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <unistd.h> #include <sys/signal.h> #include <sys/socket.h> #include <sys/poll.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include "../common/test.h" int sock1; int sock2; int sock3; struct sockaddr_in addr; socklen_t addrlen; FN_SETUP(init) { ...
test/initramfs/src/apps/network/tcp_reuseaddr.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #define PORT 8080 int main() { int server_fd, new_socket; struct sockaddr_in address; int opt = 1; int addrlen = sizeof(address); char buffer[1024] = { 0 }; char *hello = "H...
test/initramfs/src/apps/network/tcp_server.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> #include "../common/test.h" #define SENDER_BIND_ADDR "127.0.0.1" #define SENDER_PORT 12345 #define BROADCAST_ADDR "127.255.255.255" #define RECEIVE_PORT 12346 #define MESSAGE "Hello from broadc...
test/initramfs/src/apps/network/udp_broadcast.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #define SERVER_IP "127.0.0.1" #define SERVER_PORT 1234 #define BUFFER_SIZE 1024 int main() { int sock_fd; char buffer[BUFFER_SIZE...
test/initramfs/src/apps/network/udp_client.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <unistd.h> #include <sys/signal.h> #include <sys/socket.h> #include <sys/poll.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include "../common/test.h" static struct sockaddr_in sk_addr; #define C_PORT htons(0x1234) FN_SETUP(general) { sk_addr.si...
test/initramfs/src/apps/network/udp_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #define SERVER_IP "127.0.0.1" #define SERVER_PORT 1234 #define BUFFER_SIZE 1024 int main() { int sock_fd; char buffer[BUFFER_SIZE...
test/initramfs/src/apps/network/udp_server.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <netlink/netlink.h> #include <unistd.h> #include <sys/socket.h> #include "../common/test.h" static struct sockaddr_nl sk_addr = { .nl_family = AF_NETLINK }; #define C_PORT 1001 #define S_PORT 1002 static int sk_unbound; static int sk_bound; static int sk_connected; FN_...
test/initramfs/src/apps/network/uevent_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #define SOCKET_NAME "/tmp/test.sock" #define BUFFER_SIZE 128 int main() { int client_fd; struct sockaddr_un server_addr, peer_addr; ...
test/initramfs/src/apps/network/unix_client.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE #include <unistd.h> #include <stddef.h> #include <sys/poll.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/wait.h> #include "../common/test.h" static int sk_unbound; static int sk_bound; static int sk_connected; #define UNIX_ADDR(path) \ ((struc...
test/initramfs/src/apps/network/unix_datagram_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define SOCK_TYPE SOCK_SEQPACKET #include "unix_streamlike_prologue.h" FN_TEST(sendto) { char buf[1] = { 'z' }; TEST_ERRNO(sendto(sk_unbound, buf, 1, 0, &LISTEN_ADDR, LISTEN_ADDRLEN), ENOTCONN); TEST_ERRNO(sendto(sk_bound, buf, 1, 0, &LISTEN_ADDR2, LISTEN_ADDRLEN2), E...
test/initramfs/src/apps/network/unix_seqpacket_err.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #define SOCKET_NAME "/tmp/test.sock" #define BUFFER_SIZE 128 int main() { int server_fd, accepted_fd; struct sockaddr_un server_addr,...
test/initramfs/src/apps/network/unix_server.c
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #define SOCK_TYPE SOCK_STREAM #include "unix_streamlike_prologue.h" FN_TEST(sendto) { char buf[1] = { 'z' }; TEST_ERRNO(sendto(sk_unbound, buf, 1, 0, &LISTEN_ADDR, LISTEN_ADDRLEN), EOPNOTSUPP); TEST_ERRNO(sendto(sk_bound, buf, 1, 0, &LISTEN_ADDR2, LISTEN_ADDRLEN2), EO...
test/initramfs/src/apps/network/unix_stream_err.c
null
null
null
null
null
source
asterinas
/* SPDX-License-Identifier: MPL-2.0 */ FN_SETUP(cleanup) { CHECK(close(sk_unbound)); CHECK(close(sk_bound)); CHECK(close(sk_listen)); CHECK(close(sk_connected)); CHECK(close(sk_accepted)); CHECK(unlink(BOUND_ADDR.sun_path)); CHECK(unlink(LISTEN_ADDR.sun_path)); } END_SETUP()
test/initramfs/src/apps/network/unix_streamlike_epilogue.h
null
null
null
null
null
source
asterinas
/* SPDX-License-Identifier: MPL-2.0 */ #define _GNU_SOURCE #include <sys/socket.h> #include <sys/un.h> #include <sys/poll.h> #include <sys/epoll.h> #include <sys/wait.h> #include <fcntl.h> #include <unistd.h> #include <stddef.h> #include "../common/test.h" FN_SETUP(general) { signal(SIGPIPE, SIG_IGN); } END_SETUP(...
test/initramfs/src/apps/network/unix_streamlike_prologue.h
null
null
null
null
null
source
asterinas
// SPDX-License-Identifier: MPL-2.0 #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <linux/vm_sockets.h> #include <unistd.h> #include <string.h> #define PORT 1234 int main() { int sock; char buffer[1024] = { 0 }; FILE *commandFile; struct sockaddr_vm serv_addr; commandFile = fopen("./vs...
test/initramfs/src/apps/network/vsock/vsock_client.c
null
null
null
null
null