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)] | |
fn main() { | |
use std::arch::asm; | |
let buf = "hello, world!\n"; | |
unsafe { | |
asm!("svc #0", | |
in("x0") 1, | |
in("x1") buf.as_ptr(), |
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
.data | |
msg: | |
.ascii "hello, world\n" | |
len = . - msg | |
.text | |
.global _start | |
_start: | |
mov x0, #1 |
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
#include <stdio.h> | |
#include <unistd.h> | |
int main() { | |
char buf[] = "dummy string\n"; | |
write(1, buf, 14); // write to stdout | |
int duplicated_fd = dup(1); | |
printf("duplicated fd: %d\n", duplicated_fd); |
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
#include <unistd.h> | |
#include <stdio.h> | |
int main() { | |
char buffer[10] = { 0, }; | |
int fd[2]; | |
if(pipe(fd) == -1) printf("pipe failed"); | |
printf("fd[0] == %d\n", fd[0]); |
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
#include <stdio.h> | |
#include <unistd.h> | |
int main() { | |
printf("PID: %d\n", getpid()); | |
pid_t pid = fork(); | |
printf("fork ret: %d\n", pid); | |
return 0; |
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
package main | |
import ( | |
"io" | |
"fmt" | |
) | |
type DummyReader struct { | |
} |
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
#include "control_light.h" | |
#include <stdio.h> | |
int turn_on(int id) { | |
printf("turn on %d\n", id); | |
return 0; | |
} | |
int turn_off(int id) { |
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
#include "control_light.h" | |
#include <stdio.h> | |
int turn_on(int id) { | |
printf("turn on %d\n", id); | |
return 0; | |
} | |
int turn_off(int id) { |
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 libc::{write, open, close}; | |
use libc::{O_CREAT, O_RDWR}; | |
use libc::{c_char, c_void}; | |
fn main() { | |
let filename: *const c_char = "text.txt\0".as_ptr() as *const c_char; | |
let contents: *const c_void = "hello\n".as_ptr() as *const c_void; | |
unsafe { | |
let fd = open(filename, O_CREAT | O_RDWR, 0o0644); |
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
#include <unistd.h> | |
#include <stdio.h> | |
int main() { | |
write(0, "write 0\n", 8); | |
write(1, "write 1\n", 8); | |
write(2, "write 2\n", 8); | |
fprintf(stdin, "fprintf stdin\n"); | |
fprintf(stdout, "fprintf stdout\n"); |