当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Syscall6函数代码示例

本文整理汇总了Golang中syscall.Syscall6函数的典型用法代码示例。如果您正苦于以下问题:Golang Syscall6函数的具体用法?Golang Syscall6怎么用?Golang Syscall6使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: Lgetxattr

// Lgetxattr retrieves the value of the extended attribute identified by attr
// and associated with the given path in the file system.
// It will returns a nil slice and nil error if the xattr is not set.
func Lgetxattr(path string, attr string) ([]byte, error) {
	pathBytes, err := syscall.BytePtrFromString(path)
	if err != nil {
		return nil, err
	}
	attrBytes, err := syscall.BytePtrFromString(attr)
	if err != nil {
		return nil, err
	}

	dest := make([]byte, 128)
	destBytes := unsafe.Pointer(&dest[0])
	sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
	if errno == syscall.ENODATA {
		return nil, nil
	}
	if errno == syscall.ERANGE {
		dest = make([]byte, sz)
		destBytes := unsafe.Pointer(&dest[0])
		sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
	}
	if errno != 0 {
		return nil, errno
	}

	return dest[:sz], nil
}
开发者ID:CNDonny,项目名称:scope,代码行数:30,代码来源:xattrs_linux.go

示例2: executable

func executable() (string, error) {
	var mib [4]int32
	switch runtime.GOOS {
	case "freebsd":
		mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1}
	case "darwin":
		mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1}
	}

	n := uintptr(0)
	// get length
	_, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
	if err != 0 {
		return "", err
	}
	if n == 0 { // shouldn't happen
		return "", nil
	}
	buf := make([]byte, n)
	_, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
	if err != 0 {
		return "", err
	}
	if n == 0 { // shouldn't happen
		return "", nil
	}
	p := string(buf[:n-1])
	if !filepath.IsAbs(p) {
		if cacheWDErr != nil {
			return p, cacheWDErr
		}
		p = filepath.Join(cacheWD, filepath.Clean(p))
	}
	return filepath.EvalSymlinks(p)
}
开发者ID:edrex-duex,项目名称:go4,代码行数:35,代码来源:exec_sysctl.go

示例3: sysctlCptime

func sysctlCptime(ncpu int, curcpu int, load *[C.CPUSTATES]C.long) error {
	var mib []int32

	// Use the correct mib based on the number of CPUs and fill out the
	// current CPU number in case of SMP. (0 indexed cf. self.List)
	if ncpu == 0 {
		mib = []int32{C.CTL_KERN, C.KERN_CPTIME}
	} else {
		mib = []int32{C.CTL_KERN, C.KERN_CPTIME2, int32(curcpu)}
	}

	len := len(mib)

	n := uintptr(0)
	// First we determine how much memory we'll need to pass later on (via `n`)
	_, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), uintptr(len), 0, uintptr(unsafe.Pointer(&n)), 0, 0)
	if errno != 0 || n == 0 {
		return nil
	}

	_, _, errno = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), uintptr(len), uintptr(unsafe.Pointer(load)), uintptr(unsafe.Pointer(&n)), 0, 0)
	if errno != 0 || n == 0 {
		return nil
	}

	return nil
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:27,代码来源:sigar_openbsd.go

示例4: lockEcho

func lockEcho() (quit chan int, err error) {
	echoLockMutex.Lock()
	defer echoLockMutex.Unlock()
	if echoLocked {
		err = ErrPoolWasStarted
		return
	}
	echoLocked = true

	fd := tty.Fd()
	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
		err = fmt.Errorf("Can't get terminal settings: %v", e)
		return
	}

	newState := oldState
	newState.Lflag &^= syscall.ECHO
	newState.Lflag |= syscall.ICANON | syscall.ISIG
	newState.Iflag |= syscall.ICRNL
	if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
		err = fmt.Errorf("Can't set terminal settings: %v", e)
		return
	}
	quit = make(chan int, 1)
	go catchTerminate(quit)
	return
}
开发者ID:mmp,项目名称:pb,代码行数:27,代码来源:pb_x.go

示例5: Get

func (self *CpuList) Get() error {
	mib := [2]int32{C.CTL_HW, C.HW_NCPU}
	var ncpu int

	n := uintptr(0)
	// First we determine how much memory we'll need to pass later on (via `n`)
	_, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 2, 0, uintptr(unsafe.Pointer(&n)), 0, 0)

	if errno != 0 || n == 0 {
		return nil
	}

	// Now perform the actual sysctl(3) call, storing the result in ncpu
	_, _, errno = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 2, uintptr(unsafe.Pointer(&ncpu)), uintptr(unsafe.Pointer(&n)), 0, 0)

	if errno != 0 || n == 0 {
		return nil
	}

	load := [C.CPUSTATES]C.long{C.CP_USER, C.CP_NICE, C.CP_SYS, C.CP_INTR, C.CP_IDLE}

	self.List = make([]Cpu, ncpu)
	for curcpu, _ := range self.List {
		sysctlCptime(ncpu, curcpu, &load)
		fillCpu(&self.List[curcpu], load)
	}

	return nil
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:29,代码来源:sigar_openbsd.go

示例6: inputEventsProducer

func inputEventsProducer() {
	var input k32_input
	for {
		// Wait for events
		r0, _, e1 := syscall.Syscall6(k32_WaitForMultipleObjects.Addr(), 4,
			uintptr(len(eventHandles)), uintptr(unsafe.Pointer(&eventHandles[0])), 0, 0xFFFFFFFF, 0, 0)
		if uint32(r0) == 0xFFFFFFFF {
			input_comm <- keyEvent{err: getError(e1)}
		}

		select {
		case <-cancel_comm:
			cancel_done_comm <- true
			return
		default:
		}

		// Get console input
		r0, _, e1 = syscall.Syscall6(k32_ReadConsoleInputW.Addr(), 4,
			uintptr(hConsoleIn), uintptr(unsafe.Pointer(&input)), 1, uintptr(unsafe.Pointer(&tmpArg)), 0, 0)
		if int(r0) == 0 {
			input_comm <- keyEvent{err: getError(e1)}
		}

		if input.event_type == 0x1 { // key_event
			kEvent := (*k32_event)(unsafe.Pointer(&input.event))
			ev, ok := getKeyEvent(kEvent)
			if ok {
				for i := 0; i < int(kEvent.repeat_count); i++ {
					input_comm <- ev
				}
			}
		}
	}
}
开发者ID:postfix,项目名称:keyboard-1,代码行数:35,代码来源:keyboard_windows.go

示例7: DragQueryFile

func DragQueryFile(hDrop HDROP, iFile uint) (fileName string, fileCount uint) {
	ret, _, _ := syscall.Syscall6(procDragQueryFile, 4,
		uintptr(hDrop),
		uintptr(iFile),
		0,
		0,
		0,
		0)

	fileCount = uint(ret)

	if iFile != 0xFFFFFFFF {
		buf := make([]uint16, fileCount+1)

		ret, _, _ := syscall.Syscall6(procDragQueryFile, 4,
			uintptr(hDrop),
			uintptr(iFile),
			uintptr(unsafe.Pointer(&buf[0])),
			uintptr(fileCount+1),
			0,
			0)

		if ret == 0 {
			panic("Invoke DragQueryFile error.")
		}

		fileName = syscall.UTF16ToString(buf)
	}

	return
}
开发者ID:bsiegert,项目名称:w32,代码行数:31,代码来源:shell32.go

示例8: darwinSyscall

func darwinSyscall() (*bytes.Buffer, error) {
	mib := [4]int32{_CTRL_KERN, _KERN_PROC, _KERN_PROC_ALL, 0}
	size := uintptr(0)

	_, _, errno := syscall.Syscall6(
		syscall.SYS___SYSCTL,
		uintptr(unsafe.Pointer(&mib[0])),
		4,
		0,
		uintptr(unsafe.Pointer(&size)),
		0,
		0)

	if errno != 0 {
		return nil, errno
	}

	bs := make([]byte, size)
	_, _, errno = syscall.Syscall6(
		syscall.SYS___SYSCTL,
		uintptr(unsafe.Pointer(&mib[0])),
		4,
		uintptr(unsafe.Pointer(&bs[0])),
		uintptr(unsafe.Pointer(&size)),
		0,
		0)

	if errno != 0 {
		return nil, errno
	}

	return bytes.NewBuffer(bs[0:size]), nil
}
开发者ID:codeskyblue,项目名称:gosuv,代码行数:33,代码来源:process_darwin.go

示例9: Free

func (auth *SSPIAuth) Free() {
	syscall.Syscall6(sec_fn.DeleteSecurityContext,
		1,
		uintptr(unsafe.Pointer(&auth.ctxt)),
		0, 0, 0, 0, 0)
	syscall.Syscall6(sec_fn.FreeCredentialsHandle,
		1,
		uintptr(unsafe.Pointer(&auth.cred)),
		0, 0, 0, 0, 0)
}
开发者ID:citywander,项目名称:vault,代码行数:10,代码来源:sspi_windows.go

示例10: memoryStats

func memoryStats() (*memory, error) {
	m := new(memory)

	// get page size
	pgsz_mib := []uint32{
		6, // CTL_HW
		7, // HW_PAGESIZE
	}

	pgsz := uintptr(0)

	sz := uintptr(unsafe.Sizeof(pgsz))

	_, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&pgsz_mib[0])), 2, uintptr(unsafe.Pointer(&pgsz)), uintptr(unsafe.Pointer(&sz)), 0, 0)
	if err != 0 {
		return nil, err
	}

	// get memory stats
	vm_mib := []uint32{
		2, // CTL_VM
		1, // VM_METER
	}

	// from OpenBSD /usr/include/sys/vmmeter.h
	var vmtotal struct {
		t_rq     uint16 /* length of the run queue */
		t_dw     uint16 /* jobs in ``disk wait'' (neg priority) */
		t_pw     uint16 /* jobs in page wait */
		t_sl     uint16 /* jobs sleeping in core */
		t_sw     uint16 /* swapped out runnable/short block jobs */
		t_vm     uint32 /* total virtual memory */
		t_avm    uint32 /* active virtual memory */
		t_rm     uint32 /* total real memory in use */
		t_arm    uint32 /* active real memory */
		t_vmshr  uint32 /* shared virtual memory */
		t_avmshr uint32 /* active shared virtual memory */
		t_rmshr  uint32 /* shared real memory */
		t_armshr uint32 /* active shared real memory */
		t_free   uint32 /* free memory pages */
	}

	sz = uintptr(unsafe.Sizeof(vmtotal))

	_, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&vm_mib[0])), 2, uintptr(unsafe.Pointer(&vmtotal)), uintptr(unsafe.Pointer(&sz)), 0, 0)
	if err != 0 {
		return nil, err
	}

	m.Total = uint64(vmtotal.t_avm+vmtotal.t_free) * uint64(pgsz)
	m.Usage = uint64(vmtotal.t_avm) * uint64(pgsz)

	return m, nil
}
开发者ID:GregWilson,项目名称:kite,代码行数:54,代码来源:systeminfo_openbsd.go

示例11: getCurrentExecutePath

func getCurrentExecutePath() (string, error) {
	var mib [4]int32
	switch runtime.GOOS {
	case "freebsd":
		mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1}
	case "darwin":
		mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1}
	}

	n := uintptr(0)
	// Get length.
	_, _, errNum := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
	if errNum != 0 {
		return "", errNum
	}
	if n == 0 { // This shouldn't happen.
		return "", nil
	}
	buf := make([]byte, n)
	_, _, errNum = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
	if errNum != 0 {
		return "", errNum
	}
	if n == 0 { // This shouldn't happen.
		return "", nil
	}
	for i, v := range buf {
		if v == 0 {
			buf = buf[:i]
			break
		}
	}
	var err error
	execPath := string(buf)
	// execPath will not be empty due to above checks.
	// Try to get the absolute path if the execPath is not rooted.
	if execPath[0] != '/' {
		execPath, err = getAbs(execPath)
		if err != nil {
			return execPath, err
		}
	}
	// For darwin KERN_PROCARGS may return the path to a symlink rather than the
	// actual executable.
	if runtime.GOOS == "darwin" {
		if execPath, err = filepath.EvalSymlinks(execPath); err != nil {
			return execPath, err
		}
	}
	return execPath, nil
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:51,代码来源:GetCurrentExecutePath_sysctl.go

示例12: NoEcho

func NoEcho(fd uintptr) (*Termios, error) {
	var s Termios
	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGETA), uintptr(unsafe.Pointer(&s)), 0, 0, 0); err != 0 {
		return nil, err
	}

	oldState := s
	s.Lflag &^= syscall.ECHO | ECHOE | ECHOK
	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSETA), uintptr(unsafe.Pointer(&s)), 0, 0, 0); err != 0 {
		return nil, err
	}

	return &oldState, nil
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:14,代码来源:ttyutils_darwin.go

示例13: main

func main() {
	var err error
	var b []byte
	var l uintptr

	flag.Parse()
	if len(flag.Args()) < 1 {
		flag.PrintDefaults()
		log.Fatalf("usage: kexec [flags] kernelname")
	}
	kernel := flag.Args()[0]

	if *cmdline != "" {
		b = append(b, []byte(*cmdline)...)
		l = uintptr(len(b)) + 1
	} else {
		b, err = ioutil.ReadFile("/proc/cmdline")
		if err != nil {
			log.Fatalf("%v", err)
		}
		b[len(b)-1] = 0
		l = uintptr(len(b))
	}

	p := uintptr(unsafe.Pointer(&b[0]))

	log.Printf("Loading %v\n", kernel)

	if kern, err = syscall.Open(kernel, syscall.O_RDONLY, 0); err != nil {
		log.Fatalf("%v", err)
	}

	if ramfs, err = syscall.Open(*initramfs, syscall.O_RDONLY, 0); err != nil {
		flags |= KEXEC_FILE_NO_INITRAMFS
	}

	log.Printf("command line: '%v'", string(b))
	log.Printf("%v %v %v %v %v %v", 320, uintptr(kern), uintptr(ramfs), p, l, flags)
	if *dryrun {
		log.Printf("Dry run -- exiting now")
		return
	}
	if e1, e2, err := syscall.Syscall6(320, uintptr(kern), uintptr(ramfs), l, p, flags, uintptr(0)); err != 0 {
		log.Fatalf("a %v b %v err %v", e1, e2, err)
	}

	if e1, e2, err := syscall.Syscall6(syscall.SYS_REBOOT, syscall.LINUX_REBOOT_MAGIC1, syscall.LINUX_REBOOT_MAGIC2, syscall.LINUX_REBOOT_CMD_KEXEC, 0, 0, 0); err != 0 {
		log.Fatalf("a %v b %v err %v", e1, e2, err)
	}
}
开发者ID:u-root,项目名称:u-root,代码行数:50,代码来源:kexec.go

示例14: executable

func executable() (string, error) {
	var mib [4]int32
	switch runtime.GOOS {
	case "freebsd":
		mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1}
	case "darwin":
		mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1}
	}

	n := uintptr(0)
	// get length
	_, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
	if err != 0 {
		return "", err
	}
	if n == 0 { // shouldn't happen
		return "", nil
	}
	buf := make([]byte, n)
	_, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
	if err != 0 {
		return "", err
	}
	if n == 0 { // shouldn't happen
		return "", nil
	}
	for i, v := range buf {
		if v == 0 {
			buf = buf[:i]
			break
		}
	}
	var strpath string
	if buf[0] != '/' {
		var e error
		if strpath, e = getAbs(buf); e != nil {
			return strpath, e
		}
	} else {
		strpath = string(buf)
	}
	// darwin KERN_PROCARGS may return the path to a symlink rather than the
	// actual executable
	if runtime.GOOS == "darwin" {
		if strpath, err := filepath.EvalSymlinks(strpath); err != nil {
			return strpath, err
		}
	}
	return strpath, nil
}
开发者ID:ChaitanyaRanade,项目名称:force,代码行数:50,代码来源:osext_sysctl.go

示例15: MakeCbreak

func MakeCbreak(fd int) (*termState, error) {
	var oldState termState
	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
		return nil, err
	}

	newState := oldState.termios
	newState.Iflag &^= syscall.ISTRIP | syscall.INLCR | syscall.ICRNL | syscall.IGNCR | syscall.IXON | syscall.IXOFF
	newState.Lflag &^= syscall.ECHO | syscall.ICANON
	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 {
		return nil, err
	}

	return &oldState, nil
}
开发者ID:havetisyan,项目名称:repl,代码行数:15,代码来源:repl.go


注:本文中的syscall.Syscall6函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。