Understanding OS-Backed Event Queues, System Calls, and Cross-Platform Abstractions 58 Y ou'll probably be familiar with the first two lines now, as they're the same as we wrote for our raw syscall example. We get the pointer to the buffer where our text is stored and the length of that buffer. Next is our call to the write function in libc, which needs to be wrapped in an unsafe block since Rust can't guarantee safety when calling external functions. Y ou might wonder how we know that the value 1 refers to the file handle of stdout. Y ou'll meet this situation a lot when writing syscalls from Rust. Usually, constants are defined in the C header files, so we need to manually search them up and look for these definitions. 1 is always the file handle to stdout on UNIX systems, so it's easy to remember. Note Wrapping the libc functions and providing these constants is exactly what the create libc (https://github. com/rust-lang/libc ) provides for us. Most of the time, you can use that instead of doing all the manual work of linking to and defining functions as we do here. Lastly, we have the error handling, and you'll see this all the time when using FFI. C functions often use a specific integer to indicate if the function call was successful or not. In the case of this write call, the function will either return the number of bytes written or, if there is an error, it will return the value-1. Y ou'll find this information easily by reading the man-pages (https://man7. org/ linux/man-pages/index. html ) for Linux. If there is an error, we use the built-in function in Rust's standard library to query the OS for the last error it reported for this process and convert that to a rust io::Error type. If you run this function using cargo run, you will see this output: Hello world from syscall! Using Windows API On Windows, things work a bit differently. While UNIX models almost everything as “files” you interact with, Windows uses other abstractions. On Windows, you get a handle that represents some object you can interact with in specific ways depending on exactly what kind of handle you have. We will use the same main function as before, but we need to link to different functions in the Windows API and make changes to our syscall function. ch03/b-normal-syscall #[link(name = "kernel32")] extern "system" { fn Get Std Handle(n Std Handle: i32)-> i32; fn Write Console W(