Open ccckmit opened 2 years ago
執行結果:
程式碼
// 修改自 -- https://github.com/spencertipping/jit-tutorial/blob/master/jitproto.c #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h> #include <sys/mman.h>
typedef int(*fn)(int);
int main() { char *memory = mmap(NULL, // address 4096, // size PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, // fd (not used here) 0); // offset (not used here) assert(memory != NULL); char code[] = { 0x8d,0x47,0x03,0xc3 };
memcpy(memory, code, 4); fn f = (fn) memory;
printf("plus3(5) = %d\n", (*f)(5)); munmap(f, 4096); return 0; }
110910506林庭光 https://github.com/Lin610313/sp110b/wiki/work3.md
資工二 110910539 鄭智陽 這裡
資工二 110910511 蘇郁晴 https://github.com/yucing/sp110b/wiki/e3.md
資工二 110911542 邵南翔 https://github.com/zraiz/sp110b/blob/master/Homework/03/Homework3.md
110910563陳威宇 https://github.com/daniel74859641/-/wiki/hw3
資工二 110911543 何文旺 https://github.com/WForU/sp110b/wiki/HW3.md
110910515 陳文吉 https://github.com/RyanChen-01/sp110b/wiki/hw3.md
110910504趙唯安 https://github.com/wei-annn/sp110b/wiki/hw3.md
函數範例: plus3.c
編譯
仿照
https://gitlab.com/ccc110/sp/-/blob/master/06-obj/02-jit/03-objdump/jitAdd.c
寫一個 jitPlus3.c
然後編譯執行