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


Golang syscall.Getpagesize函数代码示例

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


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

示例1: main

func main() {
	sk := nlgo.NlSocketAlloc()
	if err := nlgo.GenlConnect(sk); err != nil {
		panic(err)
	} else if err := nlgo.GenlSendSimple(sk, nlgo.GENL_ID_CTRL, nlgo.CTRL_CMD_GETFAMILY, nlgo.CTRL_VERSION, syscall.NLM_F_DUMP); err != nil {
		panic(err)
	}
	nl80211 := nlgo.NlSocketAlloc()
	if err := nlgo.GenlConnect(nl80211); err != nil {
		panic(err)
	}

	data := make([]byte, syscall.Getpagesize())
	if n, _, _, _, err := syscall.Recvmsg(sk.Fd, data, nil, 0); err != nil {
		panic(err)
	} else if msgs, err := syscall.ParseNetlinkMessage(data[:n]); err != nil {
		log.Print("X", err)
	} else {
		for _, msg := range msgs {
			genl := *(*nlgo.GenlMsghdr)(unsafe.Pointer(&msg.Data[0]))
			if msg.Header.Type == nlgo.GENL_ID_CTRL && genl.Cmd == nlgo.CTRL_CMD_NEWFAMILY {
				if attr, err := nlgo.CtrlPolicy.Parse(msg.Data[nlgo.GENL_HDRLEN:]); err != nil {
					log.Print(err)
				} else if amap, ok := attr.(nlgo.AttrMap); !ok {
					log.Print(attr)
				} else if value := amap.Get(nlgo.CTRL_ATTR_FAMILY_NAME).(nlgo.NulString); string(value) == "nl80211" {
					log.Printf("%v", attr)
					for _, g := range amap.Get(nlgo.CTRL_ATTR_MCAST_GROUPS).(nlgo.AttrSlice).Slice() {
						group := g.Value.(nlgo.AttrMap)
						pid := group.Get(nlgo.CTRL_ATTR_MCAST_GRP_ID).(nlgo.U32)
						if err := nlgo.NlSocketAddMembership(nl80211, int(pid)); err != nil {
							log.Print(err)
						}
					}
				}
			} else {
				log.Print("UNKNOWN")
			}
		}
	}
	nlgo.NlSocketFree(sk)

	for {
		if n, _, _, _, err := syscall.Recvmsg(nl80211.Fd, data, nil, 0); err != nil {
			panic(err)
		} else if msgs, err := syscall.ParseNetlinkMessage(data[:n]); err != nil {
			log.Print("Y", err)
		} else {
			for _, msg := range msgs {
				genl := (*nlgo.GenlMsghdr)(unsafe.Pointer(&msg.Data[0]))
				if attr, err := nlgo.Nl80211Policy.Parse(msg.Data[nlgo.GENL_HDRLEN:]); err != nil {
					log.Print("Z", err)
				} else {
					log.Printf("NL80211_CMD_%s attrs=%s", nlgo.NL80211_CMD_itoa[genl.Cmd], attr)
				}
			}
		}
	}
}
开发者ID:qmsk,项目名称:nlgo,代码行数:59,代码来源:main.go

示例2: AuditSetEnabled

// AuditSetEnabled enables or disables audit in kernel.
// Provide `enabled` as 1 for enabling and 0 for disabling.
func AuditSetEnabled(s *NetlinkConnection, enabled int) error {
	var (
		status auditStatus
		err    error
	)

	status.Enabled = (uint32)(enabled)
	status.Mask = AUDIT_STATUS_ENABLED
	buff := new(bytes.Buffer)
	err = binary.Write(buff, nativeEndian(), status)
	if err != nil {
		return errors.Wrap(err, "AuditSetEnabled: binary write from auditStatus failed")
	}

	wb := newNetlinkAuditRequest(uint16(AUDIT_SET), syscall.AF_NETLINK, int(unsafe.Sizeof(status)))
	wb.Data = append(wb.Data[:], buff.Bytes()[:]...)
	if err := s.Send(wb); err != nil {
		return errors.Wrap(err, "AuditSetEnabled failed")
	}

	// Receive in just one try
	err = auditGetReply(s, syscall.Getpagesize(), 0, wb.Header.Seq)
	if err != nil {
		return errors.Wrap(err, "AuditSetEnabled failed")
	}
	return nil
}
开发者ID:arunk-s,项目名称:libaudit-go,代码行数:29,代码来源:libaudit.go

示例3: readAllEvents

func (w *Watcher) readAllEvents() {
	buf := make([]byte, syscall.Getpagesize())

	listener, _ := w.listener.(*netlinkListener)

	for {
		if w.isDone() {
			return
		}

		nr, _, err := syscall.Recvfrom(listener.sock, buf, 0)

		if err != nil {
			w.Error <- err
			continue
		}
		if nr < syscall.NLMSG_HDRLEN {
			w.Error <- syscall.EINVAL
			continue
		}

		msgs, _ := syscall.ParseNetlinkMessage(buf[:nr])

		for _, m := range msgs {
			if m.Header.Type == syscall.NLMSG_DONE {
				w.handleEventAll(m.Data)
			}
		}
	}
}
开发者ID:cloudimmunity,项目名称:pdiscover,代码行数:30,代码来源:pevents_linux.go

示例4: main

func main() {
	// Turn the eventual fault into a panic, not a program crash,
	// so that memcopy can recover.
	debug.SetPanicOnFault(true)

	size := syscall.Getpagesize()

	// Map 16 pages of data with a 4-page hole in the middle.
	data, err := syscall.Mmap(-1, 0, 16*size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
	if err != nil {
		log.Fatalf("mmap: %v", err)
	}

	// Note: Cannot call syscall.Munmap, because Munmap checks
	// that you are unmapping a whole region returned by Mmap.
	// We are trying to unmap just a hole in the middle.
	if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[8*size])), uintptr(4*size), 0); err != 0 {
		log.Fatalf("munmap: %v", err)
	}

	other := make([]byte, 16*size)

	// Check that memcopy returns the actual amount copied
	// before the fault (8*size - 5, the offset we skip in the argument).
	n, err := memcopy(data[5:], other)
	if err == nil {
		log.Fatal("no error from memcopy across memory hole")
	}
	if n != 8*size-5 {
		log.Fatal("memcopy returned %d, want %d", n, 8*size-5)
	}
}
开发者ID:wheelcomplex,项目名称:go-1,代码行数:32,代码来源:recover4.go

示例5: TestMmap

func TestMmap(t *testing.T) {
	b, err := syscall.Mmap(-1, 0, syscall.Getpagesize(), syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
	if err != nil {
		t.Fatalf("Mmap: %v", err)
	}
	if err := syscall.Munmap(b); err != nil {
		t.Fatalf("Munmap: %v", err)
	}
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:9,代码来源:mmap_unix_test.go

示例6: aufsMount

func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err error) {
	defer func() {
		if err != nil {
			Unmount(target)
		}
	}()

	// Mount options are clipped to page size(4096 bytes). If there are more
	// layers then these are remounted individually using append.

	offset := 54
	if useDirperm() {
		offset += len("dirperm1")
	}
	b := make([]byte, syscall.Getpagesize()-len(mountLabel)-offset) // room for xino & mountLabel
	bp := copy(b, fmt.Sprintf("br:%s=rw", rw))

	firstMount := true
	i := 0

	for {
		for ; i < len(ro); i++ {
			layer := fmt.Sprintf(":%s=ro+wh", ro[i])

			if firstMount {
				if bp+len(layer) > len(b) {
					break
				}
				bp += copy(b[bp:], layer)
			} else {
				data := label.FormatMountLabel(fmt.Sprintf("append%s", layer), mountLabel)
				if err = mount("none", target, "aufs", syscall.MS_REMOUNT, data); err != nil {
					return
				}
			}
		}

		if firstMount {
			opts := "dio,xino=/dev/shm/aufs.xino"
			if useDirperm() {
				opts += ",dirperm1"
			}
			data := label.FormatMountLabel(fmt.Sprintf("%s,%s", string(b[:bp]), opts), mountLabel)
			if err = mount("none", target, "aufs", 0, data); err != nil {
				return
			}
			firstMount = false
		}

		if i == len(ro) {
			break
		}
	}

	return
}
开发者ID:eldarion-gondor,项目名称:cli,代码行数:56,代码来源:aufs.go

示例7: getSystemInformation

// TODO: Import gopsutil package and use it instead of
// reinventing the wheel.
func getSystemInformation() map[string]string {
	m := make(map[string]string)

	m["OS"] = runtime.GOOS
	m["Arch"] = runtime.GOARCH
	m["Number of CPUs"] = strconv.Itoa(runtime.NumCPU())
	m["Mem Page Size (bytes)"] = strconv.Itoa(syscall.Getpagesize())

	return m
}
开发者ID:nightowlware,项目名称:sysinfo,代码行数:12,代码来源:sysinfo.go

示例8: NewRtHub

func NewRtHub() (*RtHub, error) {
	self := &RtHub{
		sock:      NlSocketAlloc(),
		lock:      &sync.Mutex{},
		unilock:   &sync.Mutex{},
		multicast: make(map[uint32][]NetlinkListener),
	}
	if err := NlConnect(self.sock, syscall.NETLINK_ROUTE); err != nil {
		NlSocketFree(self.sock)
		return nil, err
	}
	go func() {
		for {
			buf := make([]byte, syscall.Getpagesize())
			if n, _, err := syscall.Recvfrom(self.sock.Fd, buf, syscall.MSG_TRUNC); err != nil {
				if e, ok := err.(syscall.Errno); ok && e.Temporary() {
					continue
				}
				break
			} else if msgs, err := syscall.ParseNetlinkMessage(buf[:n]); err != nil {
				break
			} else {
				for _, msg := range msgs {
					multi := func() []NetlinkListener {
						self.lock.Lock()
						defer self.lock.Unlock()

						var ret []NetlinkListener
						for _, s := range self.multicast {
							ret = append(ret, s...)
						}
						return ret
					}()
					if msg.Header.Seq == self.uniseq {
						if self.unicast != nil {
							self.unicast.NetlinkListen(msg)
						}
						switch msg.Header.Type {
						case syscall.NLMSG_DONE, syscall.NLMSG_ERROR:
							self.unilock.Unlock()
						}
					}
					if msg.Header.Seq == 0 {
						for _, proc := range multi {
							proc.NetlinkListen(msg)
						}
					}
				}
			}
		}
		log.Print("rt hub loop exit")
	}()
	return self, nil
}
开发者ID:skyportsystems,项目名称:nlgo,代码行数:54,代码来源:rt_hub.go

示例9: Receive

func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, error) {
	rb := make([]byte, syscall.Getpagesize())
	nr, _, err := syscall.Recvfrom(s.fd, rb, 0)
	if err != nil {
		return nil, err
	}
	if nr < syscall.NLMSG_HDRLEN {
		return nil, ErrShortResponse
	}
	rb = rb[:nr]
	return syscall.ParseNetlinkMessage(rb)
}
开发者ID:JianfuLi,项目名称:docker,代码行数:12,代码来源:netlink_linux.go

示例10: Init

// Initialize frame buffer device
func Init(fbdev, tty string) (*Framebuffer, error) {

	var fb = new(Framebuffer)
	var err error

	fb.tty, err = os.OpenFile(tty, os.O_RDWR, os.ModeDevice)
	if err != nil {
		return nil, err
	}

	// switch to graphics mode
	// this prevents kernel modifying the video ram (vt switching/blanking, cursor, gpm mouse cursor)
	err = ioctl(fb.tty.Fd(), KDSETMODE, unsafe.Pointer(uintptr(KD_GRAPHICS)))
	if err != nil {
		fb.tty.Close()
		return nil, err
	}

	fb.dev, err = os.OpenFile(fbdev, os.O_RDWR, os.ModeDevice)
	if err != nil {
		fb.tty.Close()
		return nil, err
	}

	err = ioctl(fb.dev.Fd(), FBIOGET_FSCREENINFO, unsafe.Pointer(&fb.finfo))
	if err != nil {
		fb.dev.Close()
		fb.tty.Close()
		return nil, err
	}
	log.Debug(utils.StructPrint(&fb.finfo))

	err = ioctl(fb.dev.Fd(), FBIOGET_VSCREENINFO, unsafe.Pointer(&fb.Vinfo))
	if err != nil {
		fb.dev.Close()
		fb.tty.Close()
		return nil, err
	}
	log.Debug(utils.StructPrint(&fb.Vinfo))

	memSize := int(fb.finfo.Smem_len + uint32(fb.finfo.Smem_start&uint64(syscall.Getpagesize()-1)))

	fb.Mem, err = syscall.Mmap(int(fb.dev.Fd()), 0, memSize, PROT_READ|PROT_WRITE, MAP_SHARED)
	if err != nil {
		fb.dev.Close()
		fb.tty.Close()
		return nil, err
	}

	fb.MemOffscreen = make([]byte, memSize)

	return fb, nil
}
开发者ID:romovs,项目名称:viscum,代码行数:54,代码来源:fbdev.go

示例11: Get

// Get creates and mounts the required file system for the given id and returns the mount path.
func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
	dir := d.dir(id)
	if _, err := os.Stat(dir); err != nil {
		return "", err
	}

	diffDir := path.Join(dir, "diff")
	lowers, err := ioutil.ReadFile(path.Join(dir, lowerFile))
	if err != nil {
		// If no lower, just return diff directory
		if os.IsNotExist(err) {
			return diffDir, nil
		}
		return "", err
	}

	mergedDir := path.Join(dir, "merged")
	if count := d.ctr.Increment(mergedDir); count > 1 {
		return mergedDir, nil
	}
	defer func() {
		if err != nil {
			if c := d.ctr.Decrement(mergedDir); c <= 0 {
				syscall.Unmount(mergedDir, 0)
			}
		}
	}()

	workDir := path.Join(dir, "work")
	opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", string(lowers), path.Join(id, "diff"), path.Join(id, "work"))
	mountLabel = label.FormatMountLabel(opts, mountLabel)
	if len(mountLabel) > syscall.Getpagesize() {
		return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountLabel))
	}

	if err := mountFrom(d.home, "overlay", path.Join(id, "merged"), "overlay", mountLabel); err != nil {
		return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
	}

	// chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a
	// user namespace requires this to move a directory from lower to upper.
	rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
	if err != nil {
		return "", err
	}

	if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil {
		return "", err
	}

	return mergedDir, nil
}
开发者ID:karunchennuri,项目名称:docker,代码行数:53,代码来源:overlay.go

示例12: GenlCtrlProbeByName

// genl_ctrl_probe_by_name is not exposed in the original libnl
func GenlCtrlProbeByName(sk *NlSock, name string) (AttrMap, error) {
	if err := GenlSendSimple(sk, GENL_ID_CTRL, CTRL_CMD_GETFAMILY, CTRL_VERSION, syscall.NLM_F_DUMP); err != nil {
		return AttrMap{}, err
	}
	var ret AttrMap
	err := func() error {
		for {
			buf := make([]byte, syscall.Getpagesize())
			if nn, _, err := syscall.Recvfrom(sk.Fd, buf, syscall.MSG_TRUNC); err != nil {
				return err
			} else if nn > len(buf) {
				return NLE_MSG_TRUNC
			} else {
				buf = buf[:nn]
			}
			if msgs, err := syscall.ParseNetlinkMessage(buf); err != nil {
				return err
			} else {
				for _, msg := range msgs {
					switch msg.Header.Type {
					case GENL_ID_CTRL:
						genl := (*GenlMsghdr)(unsafe.Pointer(&msg.Data[0]))
						switch genl.Cmd {
						case CTRL_CMD_NEWFAMILY:
							if attrs, err := CtrlPolicy.Parse(msg.Data[GENL_HDRLEN:]); err != nil {
								return err
							} else if info, ok := attrs.(AttrMap); !ok {
								// shold not happen
							} else if value := info.Get(CTRL_ATTR_FAMILY_NAME); value == nil {
								// should not happen by kernel
							} else if string(value.(NulString)) == name {
								ret = info
							}
						default:
							return fmt.Errorf("unexpected command")
						}
					case syscall.NLMSG_DONE:
						return nil
					case syscall.NLMSG_ERROR:
						return fmt.Errorf("NlMsgerr=%s", (*syscall.NlMsgerr)(unsafe.Pointer(&msg.Data[0])))
					default:
						return fmt.Errorf("unexpected NlMsghdr=%s", msg.Header)
					}
				}
			}
		}
	}()
	return ret, err
}
开发者ID:qmsk,项目名称:nlgo,代码行数:50,代码来源:genl_ctrl.go

示例13: Receive

func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, error) {
	if s.fd < 0 {
		return nil, fmt.Errorf("Receive called on a closed socket")
	}
	rb := make([]byte, syscall.Getpagesize())
	nr, _, err := syscall.Recvfrom(s.fd, rb, 0)
	if err != nil {
		return nil, err
	}
	if nr < syscall.NLMSG_HDRLEN {
		return nil, fmt.Errorf("Got short response from netlink")
	}
	rb = rb[:nr]
	return syscall.ParseNetlinkMessage(rb)
}
开发者ID:rossj,项目名称:docker,代码行数:15,代码来源:nl_linux.go

示例14: main

func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() != 1 {
		usage()
	}

	f, err := os.OpenFile(flag.Arg(0), os.O_RDWR, 0644)
	ck(err)
	defer f.Close()

	fi, err := f.Stat()
	ck(err)

	pagesize := syscall.Getpagesize()
	pages := fi.Size()/int64(pagesize) - 1

	var swap [8192]byte
	put4(swap[0:], 1)
	put4(swap[4:], uint32(pages))
	seek(f, 1024)
	uuid := createUUID()
	copy(swap[4*3:], uuid)
	if *label != "" {
		i := 0
		for ; i < len(*label) && i < 16; i++ {
			swap[7*4+i] = (*label)[i]
		}
		if i < 16 {
			swap[7*4+i] = 0
		}
	}
	write(f, swap[:129*4])
	seek(f, int64(pagesize)-10)
	write(f, []byte("SWAPSPACE2"))

	syscall.Fsync(int(f.Fd()))
	f.Close()

	var str string
	if *label != "" {
		str = fmt.Sprintf(", LABEL=%s", *label)
	}
	fmt.Printf("Swapspace size: %dk%s, UUID=%s\n",
		pages*(int64(pagesize)/1024), str, showUUID(uuid))
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:46,代码来源:mkswap.go

示例15: recv

func (s *NetlinkSocket) recv(peer uint32) (*NlMsgParser, error) {
	buf := MakeAlignedByteSlice(syscall.Getpagesize())
	nr, from, err := syscall.Recvfrom(s.fd, buf, 0)
	if err != nil {
		return nil, err
	}

	switch nlfrom := from.(type) {
	case *syscall.SockaddrNetlink:
		if nlfrom.Pid != peer {
			return nil, fmt.Errorf("wrong netlink peer pid (expected %d, got %d)", peer, nlfrom.Pid)
		}

		return &NlMsgParser{data: buf[:nr], pos: 0}, nil

	default:
		return nil, fmt.Errorf("Expected netlink sockaddr, got %s", reflect.TypeOf(from))
	}
}
开发者ID:awh,项目名称:go-odp,代码行数:19,代码来源:netlink.go


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