This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::sync::{Arc, Mutex}; | |
fn main() { | |
let mut stream = TcpStream::new(1); | |
let mut poll = Poll::new(); | |
poll.register(&stream); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait DisplayTrait {} | |
struct DisplayImpl<'a> { context: &'a mut () } | |
struct ViewImpl; | |
impl<D: DisplayTrait> ViewTrait<D> for ViewImpl { | |
fn display(&mut self, _: &D) {} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn main() { | |
let sys_message = String::from("Hello world from syscall!\n"); | |
syscall(sys_message).unwrap(); | |
} | |
// and: http://man7.org/linux/man-pages/man2/write.2.html | |
#[cfg(not(target_os = "windows"))] | |
#[link(name = "c")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: Save XMM6-XMM15 as well | |
STACK_SIZE = 1024 * 1024 * 8 | |
SLEEP_INTERVAL = 0.2 # give the Windows some time to kill the process if NT_TIB is not set correctly | |
# Simple Context Switch Implementation for Crystal | |
# The two interesting functions is `FiberPoc.makecontext` and `Scheduler.swapcontext`. | |
# Setting up WSL and cross compile for Win 10 see: | |
# https://github.com/crystal-lang/crystal/wiki/Porting-to-Windows |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STACK_SIZE = 1024*1024*8 | |
class Test | |
property value : UInt64 = 0 | |
property stack = Array(UInt8).new(STACK_SIZE) | |
property func : Proc(Void) = ->{} | |
property rsp : UInt64 = 0 | |
def makecontext(proc : Proc) | |
@func = proc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STACK_SIZE = 1024 * 1024 * 8 | |
SLEEP_INTERVAL = 0.5 # give Windows some time to kill the process if NT_TIB is not set correctly | |
# Simple Context Switch Implementation for Crystal | |
# The two interesting functions is `FiberPoc.makecontext` and `Scheduler.swapcontext`. | |
# Setting up WSL and cross compile for Win 10 see: | |
# https://github.com/crystal-lang/crystal/wiki/Porting-to-Windows | |
# https://github.com/crystal-lang/crystal/issues/7932 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STACK_SIZE = 1024 * 1024 * 8 | |
PUSH_POP_REG_COUNT = 7 | |
class FiberPoc | |
@stack : Array(UInt8) | |
property rsp : UInt8* = Pointer(UInt8).null | |
property f = Proc(Void).new { } | |
def initialize | |
@stack = Array.new(STACK_SIZE, 0_u8) # OK, as long as we don't push/pop -> reallocate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(asm)] | |
// Lets set a small stack size here, only 48 bytes so we can print the stack | |
// and look at it before we switch contexts | |
// ===== NOTICE FOR OSX USERS ===== | |
// You'll need to increase this size to at least 624 bytes. This will work in Rust Playground and on Windows | |
// but the extremely small stack seems to have an issue on OSX. | |
const SSIZE: isize = 48; | |
/// Do you recognize these? It's the registers described in the x86-64 ABI that we'll need to save our context. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Database-related logic, such as creating connections, CRUD on data | |
use futures::*; | |
use futures_state_stream::StateStream; | |
use tiberius::{BoxableIo, query::QueryRow, SqlConnection}; | |
// I just uncomment so RLS is happy | |
// use crate::proto::rolemanagement::v1::*; | |
// lets return a future here instead that we can then chain future futures onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For the sake of brevity I won't repeat the code we replace here instead point out | |
// that this replaces lines 307-328 in our original code | |
const BYTES_PER_PIXEL: usize = 3; | |
fn main() { | |
// {...} | |
// first allocate a zeroed Vec<u8> to hold our results. | |
// btw: this initialization method is the fastest way to ask | |
// for zeroed memory: see https://github.com/rust-lang/rust/issues/54628 | |
let mut bytes = vec![0u8; h as usize * w as usize * BYTES_PER_PIXEL]; |