This repository has been archived by the owner on May 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use github.com/petermattis/goid to impl syscall
- Loading branch information
Showing
20 changed files
with
160 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#ifndef _C2GO_PTHREAD_H | ||
#define _C2GO_PTHREAD_H | ||
#ifndef _C2GO_PTHREAD_ARCH_H | ||
#define _C2GO_PTHREAD_ARCH_H | ||
|
||
// uintptr_t __get_tp(); | ||
// | ||
// #define TLS_ABOVE_TP | ||
// #define GAP_ABOVE_TP 8 | ||
// #define MC_PC arm_pc | ||
|
||
#endif // _C2GO_PTHREAD_H | ||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
struct pthread { | ||
int tid; | ||
int errno_val; | ||
long sys_r1; // syscall_ret r1 | ||
locale_t locale; | ||
}; | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef _C2GO_STDIO_IMPL_H | ||
#define _C2GO_STDIO_IMPL_H | ||
|
||
#ifndef _C2GO_SYSCALL_H | ||
#include "syscall.h" | ||
#endif | ||
|
||
#undef _STDIO_IMPL_H | ||
#include "../../src/internal/stdio_impl.h" | ||
|
||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef _C2GO_SYSCALL_H | ||
#define _C2GO_SYSCALL_H | ||
|
||
#ifndef _C2GO_SYSCALL_ARCH_H | ||
#include "syscall_arch.h" | ||
#endif | ||
|
||
#undef _INTERNAL_SYSCALL_H | ||
#include "../../src/internal/syscall.h" | ||
|
||
#define __SYSCALL_R1_DISP(b,...) \ | ||
__SYSCALL_CONCAT(__SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__)),_r1)(__VA_ARGS__) | ||
|
||
#define __syscall_r1(...) __SYSCALL_R1_DISP(__syscall,__VA_ARGS__) | ||
|
||
#define __syscall1_r1(n,a) __syscall1_r1(n,__scc(a)) | ||
#define __syscall2_r1(n,a,b) __syscall2_r1(n,__scc(a),__scc(b)) | ||
#define __syscall3_r1(n,a,b,c) __syscall3_r1(n,__scc(a),__scc(b),__scc(c)) | ||
#define __syscall4_r1(n,a,b,c,d) __syscall4_r1(n,__scc(a),__scc(b),__scc(c),__scc(d)) | ||
#define __syscall5_r1(n,a,b,c,d,e) __syscall5_r1(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) | ||
#define __syscall6_r1(n,a,b,c,d,e,f) __syscall6_r1(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) | ||
#define __syscall7_r1(n,a,b,c,d,e,f,g) __syscall7_r1(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g)) | ||
|
||
#undef syscall | ||
#define syscall(...) __syscall_r1(__VA_ARGS__) | ||
|
||
#endif |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package libc | ||
|
||
func __lseek(fd int32, offset int64, whence int32) int64 { | ||
return int64(__syscall_ret(uint64(__syscall3(int64(199), int64(fd), int64(offset), int64(whence))))) | ||
return int64(__syscall3_r1(int64(199), int64(fd), int64(offset), int64(whence))) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package libc | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/petermattis/goid" | ||
) | ||
|
||
var ( | ||
gtls sync.Map | ||
) | ||
|
||
func __pthread_self() *struct___pthread { | ||
var self *struct___pthread | ||
id := goid.Get() | ||
ret, ok := gtls.Load(id) | ||
if !ok { | ||
self = &struct___pthread{tid: int32(id)} | ||
gtls.Store(id, self) | ||
} else { | ||
self = ret.(*struct___pthread) | ||
} | ||
return self | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,86 @@ | ||
package libc | ||
|
||
import "syscall" | ||
import ( | ||
"syscall" | ||
) | ||
|
||
var g_r1 uintptr // TODO: goroutine safe | ||
func __syscall0(n int64) int64 { | ||
r1, _, ret := syscall.Syscall(uintptr(n), 0, 0, 0) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall0_r1(n int64) int64 { | ||
r1, _, _ := syscall.Syscall(uintptr(n), 0, 0, 0) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall1(n int64, a int64) int64 { | ||
var ret syscall.Errno | ||
g_r1, _, ret = syscall.Syscall(uintptr(n), uintptr(a), 0, 0) | ||
r1, _, ret := syscall.Syscall(uintptr(n), uintptr(a), 0, 0) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall1_r1(n int64, a int64) int64 { | ||
r1, _, _ := syscall.Syscall(uintptr(n), uintptr(a), 0, 0) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall2(n int64, a, b int64) int64 { | ||
var ret syscall.Errno | ||
g_r1, _, ret = syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), 0) | ||
r1, _, ret := syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), 0) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall2_r1(n int64, a, b int64) int64 { | ||
r1, _, _ := syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), 0) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall3(n int64, a int64, b int64, c int64) int64 { | ||
var ret syscall.Errno | ||
g_r1, _, ret = syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), uintptr(c)) | ||
r1, _, ret := syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), uintptr(c)) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall3_r1(n int64, a int64, b int64, c int64) int64 { | ||
r1, _, _ := syscall.Syscall(uintptr(n), uintptr(a), uintptr(b), uintptr(c)) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall4(n int64, a int64, b int64, c int64, d int64) int64 { | ||
var ret syscall.Errno | ||
g_r1, _, ret = syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), 0, 0) | ||
r1, _, ret := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), 0, 0) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall4_r1(n int64, a int64, b int64, c int64, d int64) int64 { | ||
r1, _, _ := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), 0, 0) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall5(n int64, a int64, b int64, c int64, d int64, e int64) int64 { | ||
r1, _, ret := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), 0) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall5_r1(n int64, a int64, b int64, c int64, d int64, e int64) int64 { | ||
r1, _, _ := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), 0) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall6(n int64, a int64, b int64, c int64, d int64, e int64, f int64) int64 { | ||
var ret syscall.Errno | ||
g_r1, _, ret = syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), uintptr(f)) | ||
r1, _, ret := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), uintptr(f)) | ||
__pthread_self().sys_r1 = int64(r1) | ||
return int64(ret) | ||
} | ||
|
||
func __syscall6_r1(n int64, a int64, b int64, c int64, d int64, e int64, f int64) int64 { | ||
r1, _, _ := syscall.Syscall6(uintptr(n), uintptr(a), uintptr(b), uintptr(c), uintptr(d), uintptr(e), uintptr(f)) | ||
return int64(r1) | ||
} | ||
|
||
func __syscall_ret(uint64) int64 { | ||
return int64(g_r1) | ||
return __pthread_self().sys_r1 | ||
} |