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.
- Loading branch information
Showing
7 changed files
with
308 additions
and
11 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
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,77 @@ | ||
package libc | ||
|
||
import unsafe "unsafe" | ||
|
||
func Popen(cmd *int8, mode *int8) *Struct__IO_FILE { | ||
var p [2]int32 | ||
var op int32 | ||
var e int32 | ||
var pid int32 | ||
var f *Struct__IO_FILE | ||
var fa _cgoa_19_popen | ||
if int32(*mode) == 'r' { | ||
op = int32(0) | ||
} else if int32(*mode) == 'w' { | ||
op = int32(1) | ||
} else { | ||
*__errno_location() = int32(22) | ||
return (*Struct__IO_FILE)(nil) | ||
} | ||
if pipe2((*int32)(unsafe.Pointer(&p)), int32(524288)) != 0 { | ||
return (*Struct__IO_FILE)(nil) | ||
} | ||
f = Fdopen(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(op)*4)), mode) | ||
if !(f != nil) { | ||
__syscall1(int64(6), int64(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(0))*4)))) | ||
__syscall1(int64(6), int64(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1))*4)))) | ||
return (*Struct__IO_FILE)(nil) | ||
} | ||
var __need_unlock int32 = func() int32 { | ||
if f.Lock >= int32(0) { | ||
return __lockfile(f) | ||
} else { | ||
return int32(0) | ||
} | ||
}() | ||
if *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)) == int32(1)-op { | ||
var tmp int32 = fcntl(int32(1)-op, int32(1030), int32(0)) | ||
if tmp < int32(0) { | ||
e = *__errno_location() | ||
goto fail | ||
} | ||
__syscall1(int64(6), int64(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)))) | ||
*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)) = tmp | ||
} | ||
e = int32(12) | ||
if !(posix_spawn_file_actions_init(&fa) != 0) { | ||
if !(posix_spawn_file_actions_adddup2(&fa, *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)), int32(1)-op) != 0) { | ||
if !(func() (_cgo_ret int32) { | ||
_cgo_addr := &e | ||
*_cgo_addr = posix_spawn(&pid, (*int8)(unsafe.Pointer(&[8]int8{'/', 'b', 'i', 'n', '/', 's', 'h', '\x00'})), &fa, nil, (**int8)(unsafe.Pointer(&[4]*int8{(*int8)(unsafe.Pointer(&[3]int8{'s', 'h', '\x00'})), (*int8)(unsafe.Pointer(&[3]int8{'-', 'c', '\x00'})), (*int8)(unsafe.Pointer(cmd)), nil})), __environ) | ||
return *_cgo_addr | ||
}() != 0) { | ||
posix_spawn_file_actions_destroy(&fa) | ||
f.Pipe_pid = pid | ||
if !(Strchr(mode, 'e') != nil) { | ||
fcntl(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(op)*4)), int32(2), int32(0)) | ||
} | ||
__syscall1(int64(6), int64(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)))) | ||
for { | ||
if __need_unlock != 0 { | ||
__unlockfile(f) | ||
} | ||
if true { | ||
break | ||
} | ||
} | ||
return f | ||
} | ||
} | ||
posix_spawn_file_actions_destroy(&fa) | ||
} | ||
fail: | ||
Fclose(f) | ||
__syscall1(int64(6), int64(*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&p)))) + uintptr(int32(1)-op)*4)))) | ||
*__errno_location() = e | ||
return (*Struct__IO_FILE)(nil) | ||
} |
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,109 @@ | ||
package libc | ||
|
||
import unsafe "unsafe" | ||
|
||
func _cgos_mul32_sqrtf(a uint32, b uint32) uint32 { | ||
return uint32(uint64(a) * uint64(b) >> int32(32)) | ||
} | ||
func Sqrtf(x float32) float32 { | ||
var ix uint32 | ||
var m uint32 | ||
var m1 uint32 | ||
var m0 uint32 | ||
var even uint32 | ||
var ey uint32 | ||
ix = *(*uint32)(unsafe.Pointer(&_cgoz_18_sqrtf{x})) | ||
if func() int64 { | ||
if ix-uint32(8388608) >= uint32(2130706432) { | ||
return 1 | ||
} else { | ||
return 0 | ||
} | ||
}() == int64(0) { | ||
if ix*uint32(2) == uint32(0) { | ||
return x | ||
} | ||
if ix == uint32(2139095040) { | ||
return x | ||
} | ||
if ix > uint32(2139095040) { | ||
return __math_invalidf(x) | ||
} | ||
ix = *(*uint32)(unsafe.Pointer(&_cgoz_19_sqrtf{x * 8388608})) | ||
ix -= uint32(192937984) | ||
} | ||
even = ix & uint32(8388608) | ||
m1 = ix<<int32(8) | uint32(2147483648) | ||
m0 = ix << int32(7) & uint32(2147483647) | ||
m = func() uint32 { | ||
if even != 0 { | ||
return m0 | ||
} else { | ||
return m1 | ||
} | ||
}() | ||
ey = ix >> int32(1) | ||
ey += uint32(532676608) | ||
ey &= uint32(2139095040) | ||
const _cgos_three_sqrtf uint32 = uint32(3221225472) | ||
var r uint32 | ||
var s uint32 | ||
var d uint32 | ||
var u uint32 | ||
var i uint32 | ||
i = ix >> int32(17) % uint32(128) | ||
r = uint32(*(*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__rsqrt_tab)))) + uintptr(i)*2))) << int32(16) | ||
s = _cgos_mul32_sqrtf(m, r) | ||
d = _cgos_mul32_sqrtf(s, r) | ||
u = _cgos_three_sqrtf - d | ||
r = _cgos_mul32_sqrtf(r, u) << int32(1) | ||
s = _cgos_mul32_sqrtf(s, u) << int32(1) | ||
d = _cgos_mul32_sqrtf(s, r) | ||
u = _cgos_three_sqrtf - d | ||
s = _cgos_mul32_sqrtf(s, u) | ||
s = (s - uint32(1)) >> int32(6) | ||
var d0 uint32 | ||
var d1 uint32 | ||
var d2 uint32 | ||
var y float32 | ||
var t float32 | ||
d0 = m<<int32(16) - s*s | ||
d1 = s - d0 | ||
d2 = d1 + s + uint32(1) | ||
s += d1 >> int32(31) | ||
s &= uint32(8388607) | ||
s |= ey | ||
y = *(*float32)(unsafe.Pointer(&_cgoz_20_sqrtf{s})) | ||
if int32(1) != 0 { | ||
var tiny uint32 = uint32(func() int32 { | ||
if func() int64 { | ||
if d2 == uint32(0) { | ||
return 1 | ||
} else { | ||
return 0 | ||
} | ||
}() == int64(0) { | ||
return int32(0) | ||
} else { | ||
return int32(16777216) | ||
} | ||
}()) | ||
tiny |= (d1 ^ d2) & uint32(2147483648) | ||
t = *(*float32)(unsafe.Pointer(&_cgoz_21_sqrtf{tiny})) | ||
y = eval_as_float(y + t) | ||
} | ||
return y | ||
} | ||
|
||
type _cgoz_18_sqrtf struct { | ||
_f float32 | ||
} | ||
type _cgoz_19_sqrtf struct { | ||
_f float32 | ||
} | ||
type _cgoz_20_sqrtf struct { | ||
_i uint32 | ||
} | ||
type _cgoz_21_sqrtf struct { | ||
_i uint32 | ||
} |
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,70 @@ | ||
package libc | ||
|
||
import unsafe "unsafe" | ||
|
||
type _cgos_cookie_vswprintf struct { | ||
ws *uint32 | ||
l uint64 | ||
} | ||
|
||
func _cgos_sw_write_vswprintf(f *Struct__IO_FILE, s *uint8, l uint64) uint64 { | ||
var l0 uint64 = l | ||
var i int32 = int32(0) | ||
var c *_cgos_cookie_vswprintf = (*_cgos_cookie_vswprintf)(f.Cookie) | ||
if uintptr(unsafe.Pointer(s)) != uintptr(unsafe.Pointer((*uint8)(unsafe.Pointer(f.Wbase)))) && _cgos_sw_write_vswprintf(f, f.Wbase, uint64(uintptr(unsafe.Pointer(f.Wpos))-uintptr(unsafe.Pointer(f.Wbase)))) == uint64(18446744073709551615) { | ||
return uint64(18446744073709551615) | ||
} | ||
for c.l != 0 && l != 0 && func() (_cgo_ret int32) { | ||
_cgo_addr := &i | ||
*_cgo_addr = Mbtowc(c.ws, (*int8)(unsafe.Pointer(s)), l) | ||
return *_cgo_addr | ||
}() >= int32(0) { | ||
*(*uintptr)(unsafe.Pointer(&s)) += uintptr(i) | ||
l -= uint64(i) | ||
c.l-- | ||
*(*uintptr)(unsafe.Pointer(&c.ws)) += 4 | ||
} | ||
*c.ws = uint32(0) | ||
if i < int32(0) { | ||
f.Wpos = func() (_cgo_ret *uint8) { | ||
_cgo_addr := &f.Wbase | ||
*_cgo_addr = func() (_cgo_ret *uint8) { | ||
_cgo_addr := &f.Wend | ||
*_cgo_addr = (*uint8)(nil) | ||
return *_cgo_addr | ||
}() | ||
return *_cgo_addr | ||
}() | ||
f.Flags |= uint32(32) | ||
return uint64(i) | ||
} | ||
f.Wend = (*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(f.Buf)) + uintptr(f.Buf_size))) | ||
f.Wpos = func() (_cgo_ret *uint8) { | ||
_cgo_addr := &f.Wbase | ||
*_cgo_addr = f.Buf | ||
return *_cgo_addr | ||
}() | ||
return l0 | ||
} | ||
func vswprintf(s *uint32, n uint64, fmt *uint32, ap []interface { | ||
}) int32 { | ||
var r int32 | ||
var buf [256]uint8 | ||
var c _cgos_cookie_vswprintf = _cgos_cookie_vswprintf{s, n - uint64(1)} | ||
var f Struct__IO_FILE = Struct__IO_FILE{0, nil, nil, nil, nil, nil, nil, nil, nil, _cgos_sw_write_vswprintf, nil, (*uint8)(unsafe.Pointer(&buf)), 256, nil, nil, 0, 0, 0, 0, -1, -1, unsafe.Pointer(&c), 0, nil, nil, nil, 0, 0, nil, nil, nil} | ||
if !(n != 0) { | ||
return -1 | ||
} else if n > uint64(2147483647) { | ||
*__errno_location() = int32(75) | ||
return -1 | ||
} | ||
r = vfwprintf(&f, fmt, ap) | ||
_cgos_sw_write_vswprintf(&f, nil, uint64(0)) | ||
return func() int32 { | ||
if uint64(r) >= n { | ||
return -1 | ||
} else { | ||
return r | ||
} | ||
}() | ||
} |