Skip to content

Instantly share code, notes, and snippets.

@yodalee
yodalee / dummysyscall.c
Created November 11, 2016 18:55
AOS HW2 system call that collect info of caller process
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/syscalls.h>
#include <uapi/linux/errno.h>
#include <asm/uaccess.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/sched.h>
#include <stdio.h>
int main(int argc, const char *argv[])
{
int n = 1;
// little endian if true
if(*(char *)&n == 1)
printf("Litt\n");
else
printf("Big\n");
signed int lval = 0xFEDCBA98 << 32;
@yodalee
yodalee / swap_list.c
Created September 3, 2016 17:16
swap list
#include <stdio.h>
#include <stddef.h>
typedef struct _List {
struct _List *next;
int val;
} List;
enum {
SWAPSUCCESS,
@yodalee
yodalee / text decode serialize
Created April 26, 2015 12:55
Discuss the implementation of textdecoder serialize function
fn serialize(mut self, stream: &[u8]) -> &[u8] {
match self.encoding.name() {
"utf-8" | "utf-16be" | "utf-16le" if (!self.ignoreBOM && !self.BOMseen) => {
match stream.get(0) {
Some(token) => {
self.BOMseen = true;
if *token == 0xFEFF {
stream.slice_from(1)
} else {
stream
uint32_t working_thread = 0;
working_thread = htonl(check_working(global_server->pool)); //get working thread num
fd = open(global_server->arg.fifofile, O_WRONLY | O_NONBLOCK);
if (fd == -1) {
fprintf(stderr, "open fifo file fail\n");
return;
}
write(fd, &working_thread, sizeof(uint32_t));
close(fd);
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
int i;
pid_t pid;
if (argc != 2) {
fprintf(stderr, "Usage: zombie num\n");
@yodalee
yodalee / sendmeta.c
Last active December 27, 2015 01:49
分享一下我寫的內容,是沒講得太清楚啦lol
//先解釋一下助教寫的login流程
//csiebox_server.c:login()
info->conn_fd = conn_fd;
server->client[conn_fd] = info; //有關這個client的資料都存在這裡,例如家目錄
header.res.status = CSIEBOX_PROTOCOL_STATUS_OK;
header.res.client_id = info->conn_fd; //把client_id送給client
//........
send_message(conn_fd, &header, sizeof(header)); //送出,反正送用send_message,等資料用recv_message