本文整理匯總了Golang中github.com/lunixbochs/usercorn/go/kernel/common.Obuf.Pack方法的典型用法代碼示例。如果您正苦於以下問題:Golang Obuf.Pack方法的具體用法?Golang Obuf.Pack怎麽用?Golang Obuf.Pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lunixbochs/usercorn/go/kernel/common.Obuf
的用法示例。
在下文中一共展示了Obuf.Pack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Random
func (k *CgcKernel) Random(buf co.Obuf, size uint32, ret co.Obuf) {
tmp := make([]byte, size)
n, _ := rand.Read(tmp)
tmp = tmp[:n]
buf.Pack(tmp)
ret.Pack(uint32(n))
}
示例2: Time
func (k *PosixKernel) Time(out co.Obuf) uint64 {
t := time.Now().Unix()
if out.Addr != 0 {
out.Pack(struc.Size_t(t))
}
return uint64(t)
}
示例3: ClockGettime
func (k *PosixKernel) ClockGettime(_ int, out co.Obuf) uint64 {
ts := syscall.NsecToTimespec(time.Now().UnixNano())
err := out.Pack(&native.Timespec{int64(ts.Sec), int64(ts.Nsec)})
if err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例4: Allocate
func (k *CgcKernel) Allocate(size uint32, executable int32, ret co.Obuf) int {
mmap, _ := k.U.Mmap(0, uint64(size))
mmap.Desc = "heap"
if executable != 0 {
k.U.MemProtect(mmap.Addr, mmap.Size, uc.PROT_ALL)
}
ret.Pack(uint32(mmap.Addr))
return 0
}
示例5: Transmit
func (k *CgcKernel) Transmit(fd co.Fd, buf co.Buf, size co.Len, ret co.Obuf) int {
mem, _ := k.U.MemRead(buf.Addr, uint64(size))
n, err := syscall.Write(int(fd), mem)
if err != nil {
return -1 // FIXME
}
ret.Pack(int32(n))
return 0
}
示例6: Statfs
func (k *PosixKernel) Statfs(path string, statfs co.Obuf) uint64 {
var tmp syscall.Statfs_t
if err := syscall.Statfs(path, &tmp); err != nil {
return Errno(err)
}
if err := statfs.Pack(&tmp); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例7: Socketpair
func (k *PosixKernel) Socketpair(domain, typ, proto int, vector co.Obuf) uint64 {
pair, err := syscall.Socketpair(domain, typ, proto)
if err != nil {
return Errno(err)
}
if err := vector.Pack(pair); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例8: Fstatfs
func (k *PosixKernel) Fstatfs(fd co.Fd, statfs co.Obuf) uint64 {
var tmp syscall.Statfs_t
if err := syscall.Fstatfs(int(fd), &tmp); err != nil {
return Errno(err)
}
if err := statfs.Pack(&tmp); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例9: Receive
func (k *CgcKernel) Receive(fd co.Fd, buf co.Obuf, size co.Len, ret co.Obuf) int {
tmp := make([]byte, size)
n, err := syscall.Read(int(fd), tmp)
if err != nil {
return -1 // FIXME
}
buf.Pack(tmp[:n])
ret.Pack(int32(n))
return 0
}
示例10: Lstat
func (k *PosixKernel) Lstat(path string, buf co.Obuf) uint64 {
var stat syscall.Stat_t
if err := syscall.Lstat(path, &stat); err != nil {
return Errno(err)
}
targetStat := NewTargetStat(&stat, k.U.OS(), k.U.Bits())
if err := buf.Pack(targetStat); err != nil {
panic(err)
}
return 0
}
示例11: Gettimeofday
func (k *LinuxKernel) Gettimeofday(tp co.Obuf, tz *native.Timespec) uint64 {
now := time.Now()
res := native.Timespec{
Sec: int64(now.Unix()),
Nsec: int64(now.Nanosecond()),
}
if err := tp.Pack(&res); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例12: Fstat
func (k *PosixKernel) Fstat(fd co.Fd, buf co.Obuf) uint64 {
var stat syscall.Stat_t
if err := syscall.Fstat(int(fd), &stat); err != nil {
return Errno(err)
}
targetStat := NewTargetStat(&stat, k.U.OS(), k.U.Bits())
if err := buf.Pack(targetStat); err != nil {
panic(err)
}
return 0
}
示例13: Pread64
func (k *PosixKernel) Pread64(fd co.Fd, buf co.Obuf, size co.Len, offset int64) uint64 {
p := make([]byte, size)
n, err := syscall.Pread(int(fd), p, offset)
if err != nil {
return Errno(err)
}
if err := buf.Pack(p); err != nil {
return UINT64_MAX // FIXME
}
return uint64(n)
}
示例14: Getcwd
func (k *PosixKernel) Getcwd(buf co.Obuf, size co.Len) uint64 {
wd, _ := os.Getwd()
size -= 1
if co.Len(len(wd)) > size {
wd = wd[:size]
}
if err := buf.Pack(wd + "\x00"); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例15: Read
func (k *PosixKernel) Read(fd co.Fd, buf co.Obuf, size co.Len) uint64 {
tmp := make([]byte, size)
n, err := syscall.Read(int(fd), tmp)
if err != nil {
return Errno(err)
}
if err := buf.Pack(tmp[:n]); err != nil {
return UINT64_MAX // FIXME
}
return uint64(n)
}