• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang common.Buf类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/lunixbochs/usercorn/go/kernel/common.Buf的典型用法代码示例。如果您正苦于以下问题:Golang Buf类的具体用法?Golang Buf怎么用?Golang Buf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Buf类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Sendto

func (k *PosixKernel) Sendto(fd co.Fd, buf co.Buf, size co.Len, flags int, sa syscall.Sockaddr, socklen co.Len) uint64 {
	msg := make([]byte, size)
	if err := buf.Unpack(msg); err != nil {
		return UINT64_MAX // FIXME
	}
	return Errno(syscall.Sendto(int(fd), msg, flags, sa))
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:7,代码来源:socket.go


示例2: 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
	}
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:8,代码来源:pack.go


示例3: Write

func (k *PosixKernel) Write(fd co.Fd, buf co.Buf, size co.Len) uint64 {
	tmp := make([]byte, size)
	if err := buf.Unpack(tmp); err != nil {
		return UINT64_MAX // FIXME
	}
	n, err := syscall.Write(int(fd), tmp)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:11,代码来源:io.go


示例4: 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
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:11,代码来源:io.go


示例5: 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
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:11,代码来源:io.go


示例6: 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
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:11,代码来源:io.go


示例7: Pwrite64

func (k *PosixKernel) Pwrite64(fd co.Fd, buf co.Buf, size co.Len, offset int64) uint64 {
	p := make([]byte, size)
	if err := buf.Unpack(p); err != nil {
		return UINT64_MAX // FIXME
	}
	n, err := syscall.Pwrite(int(fd), p, offset)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:11,代码来源:io.go


示例8: 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
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:12,代码来源:mman.go


示例9: 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
	}
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:12,代码来源:socket.go


示例10: Setsockopt

func (k *PosixKernel) Setsockopt(fd co.Fd, level, opt int, valueIn co.Buf, size int) uint64 {
	// TODO: dispatch/support all setsockopt types
	if size != 4 {
		fmt.Fprintf(os.Stderr, "WARNING: unsupported Setsockopt type %d\n", size)
		return UINT64_MAX // FIXME
	}
	var value int32
	if err := valueIn.Unpack(&value); err != nil {
		return UINT64_MAX // FIXME
	}
	if err := syscall.SetsockoptInt(int(fd), level, opt, opt); err != nil {
		return Errno(err)
	}
	return 0
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:15,代码来源:socket.go


示例11: Pipe

func (k *PosixKernel) Pipe(files co.Buf) uint64 {
	var fds [2]int
	err := syscall.Pipe(fds[:])
	if err == nil {
		st := files.Struc()
		err := st.Pack(int32(fds[0]))
		if err == nil {
			err = st.Pack(int32(fds[1]))
		}
		if err != nil {
			return UINT64_MAX // FIXME
		}
	}
	return Errno(err)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:15,代码来源:io.go


示例12: 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
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:15,代码来源:io.go


示例13: Socketcall

func (k *LinuxKernel) Socketcall(index int, params co.Buf) uint64 {
	if name, ok := socketCallMap[index]; ok {
		if sys := co.Lookup(k.U, k, name); sys != nil {
			rawArgs := make([]uint32, len(sys.In))
			if err := params.Unpack(rawArgs); err != nil {
				return posix.UINT64_MAX
			}
			args := make([]uint64, len(rawArgs))
			for i, v := range rawArgs {
				args[i] = uint64(v)
			}
			return sys.Call(args)
		}
	}
	return posix.UINT64_MAX // FIXME
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:16,代码来源:linux.go


示例14: 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
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:16,代码来源:socket.go


示例15: Sendfile

func (k *LinuxKernel) Sendfile(out, in co.Fd, off co.Buf, count uint64) uint64 {
	// TODO: the in_fd argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket).
	outFile := out.File()
	inFile := in.File()
	var offset struc.Off_t
	if off.Addr != 0 {
		if err := off.Unpack(&offset); err != nil {
			return UINT64_MAX // FIXME
		}
	}
	written, err := io.CopyN(outFile, inFile, int64(count))
	// TODO: is EOF handling correct here?
	if (err != nil && err != io.EOF) || written < 0 {
		return UINT64_MAX // FIXME
	}
	return uint64(written)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:17,代码来源:io.go


示例16: iovecIter

func iovecIter(stream co.Buf, count uint64, bits uint) <-chan Iovec64 {
	ret := make(chan Iovec64)
	go func() {
		for i := uint64(0); i < count; i++ {
			if bits == 64 {
				var iovec Iovec64
				stream.Unpack(&iovec)
				ret <- iovec
			} else {
				var iv32 Iovec32
				stream.Unpack(&iv32)
				ret <- Iovec64{uint64(iv32.Base), uint64(iv32.Len)}
			}
		}
		close(ret)
	}()
	return ret
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:18,代码来源:iovec.go


示例17: 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
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:20,代码来源:user.go


示例18: 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))
}
开发者ID:practicalswift,项目名称:usercorn,代码行数:22,代码来源:io.go


示例19: Sockaddr

func Sockaddr(buf common.Buf, length int) syscall.Sockaddr {
	var port [2]byte
	order := buf.K.U.ByteOrder()
	// TODO: handle insufficient length
	var family uint16
	if err := buf.Unpack(&family); err != nil {
		return nil
	}
	// TODO: handle errors?
	st := buf.Struc()
	switch family {
	case AF_LOCAL:
		var a SockaddrUnix
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_INET:
		var a SockaddrInet4
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_INET6:
		var a SockaddrInet6
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_PACKET:
		var a SockaddrLinklayer
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_NETLINK:
		var a SockaddrNetlink
		st.Unpack(&a)
		return sockaddrToNative(&a)
	}
	return nil
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:38,代码来源:sockaddr.go


示例20: Fdwait

func (k *CgcKernel) Fdwait(nfds int, reads, writes, timeoutBuf co.Buf, readyFds co.Obuf) int {
	var readSet, writeSet *native.Fdset32
	var timeout native.Timespec
	reads.Unpack(&readSet)
	writes.Unpack(&writeSet)
	timeoutBuf.Unpack(&timeout)

	readNative := readSet.Native()
	writeNative := writeSet.Native()

	n, err := native.Select(nfds, readNative, writeNative, &timeout)
	if err != nil {
		return -1 // FIXME?
	} else {
		readyFds.Pack(int32(n))
	}
	return 0
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:18,代码来源:cgc.go



注:本文中的github.com/lunixbochs/usercorn/go/kernel/common.Buf类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang common.Obuf类代码示例发布时间:2022-05-23
下一篇:
Golang utils.Uid函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap