本文整理汇总了Golang中github.com/lunixbochs/usercorn/go/kernel/common.Buf.Pack方法的典型用法代码示例。如果您正苦于以下问题:Golang Buf.Pack方法的具体用法?Golang Buf.Pack怎么用?Golang Buf.Pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lunixbochs/usercorn/go/kernel/common.Buf
的用法示例。
在下文中一共展示了Buf.Pack方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Pack
func Pack(buf co.Buf, i interface{}) error {
switch v := i.(type) {
case *syscall.Statfs_t:
return buf.Pack(native.StatfsToLinux(v))
default:
return argjoy.NoMatch
}
}
示例2: Lstat
func (k *PosixKernel) Lstat(path string, buf co.Buf) 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
}
示例3: Fstat
func (k *PosixKernel) Fstat(fd co.Fd, buf co.Buf) 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
}
示例4: Getcwd
func (k *PosixKernel) Getcwd(buf co.Buf, 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
}
示例5: MachVmAllocate
func (k *MachKernel) MachVmAllocate(unk int, size co.Len, addrOut co.Buf) uint64 {
mmap, err := k.U.Mmap(0, uint64(size))
if err != nil {
return posix.UINT64_MAX // FIXME
}
var tmp [8]byte
buf, _ := k.U.PackAddr(tmp[:], mmap.Addr)
if err := addrOut.Pack(buf); err != nil {
return posix.UINT64_MAX // FIXME
}
return 0
}
示例6: Recvfrom
func (k *PosixKernel) Recvfrom(fd co.Fd, buf co.Buf, size co.Len, flags int, from co.Buf, fromlen co.Len) uint64 {
p := make([]byte, size)
if n, _, err := syscall.Recvfrom(int(fd), p, flags); err != nil {
// TODO: need kernel.Pack() so we can pack a sockaddr into from
if err := buf.Pack(p); err != nil {
return UINT64_MAX // FIXME
}
return uint64(n)
} else {
return UINT64_MAX // FIXME
}
}
示例7: Stat
func (k *PosixKernel) Stat(path string, buf co.Buf) uint64 {
// TODO: centralize path hook
if strings.Contains(path, "/lib/") {
path = k.U.PrefixPath(path, false)
}
var stat syscall.Stat_t
if err := syscall.Stat(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
}
示例8: Getsockopt
func (k *PosixKernel) Getsockopt(fd co.Fd, level, opt int, valueOut, valueSizeOut co.Buf) uint64 {
// TODO: dispatch/support both addr and int types
value, err := syscall.GetsockoptInt(int(fd), level, opt)
if err != nil {
return Errno(err)
}
value32 := int32(value)
size := int32(4)
if err := valueOut.Pack(value32); err != nil {
return UINT64_MAX // FIXME
}
if err := valueSizeOut.Pack(size); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例9: Getgroups
func (k *PosixKernel) Getgroups(count int, buf co.Buf) uint64 {
groups, err := syscall.Getgroups()
if err != nil {
return Errno(err)
}
length := uint64(len(groups))
if count > 0 {
if count < len(groups) {
groups = groups[:count]
}
tmp := make([]uint32, len(groups))
for i, v := range groups {
tmp[i] = uint32(v)
}
if err := buf.Pack(tmp); err != nil {
return UINT64_MAX // FIXME
}
}
return length
}
示例10: Readlink
func (k *PosixKernel) Readlink(path string, buf co.Buf, size co.Len) uint64 {
// TODO: full proc emulation layer
// maybe have a syscall pre-hook for this after ghostrace makes it generic
// or specifically have path hooks and use that to implement prefix as well
var name string
var err error
if path == "/proc/self/exe" && k.U.OS() == "linux" {
name = k.U.Exe()
} else {
name, err = os.Readlink(path)
if err != nil {
return UINT64_MAX // FIXME
}
}
if len(name) > int(size)-1 {
name = name[:size-1]
}
if err := buf.Pack([]byte(name + "\x00")); err != nil {
return UINT64_MAX // FIXME
}
return uint64(len(name))
}
示例11: Uname
func Uname(buf co.Buf, un *models.Uname) {
buf.Pack(un)
}