本文整理汇总了Golang中runtime.KeepAlive函数的典型用法代码示例。如果您正苦于以下问题:Golang KeepAlive函数的具体用法?Golang KeepAlive怎么用?Golang KeepAlive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了KeepAlive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Load
// Load
//
// If there is an error, it will be of type *Error.
func (mgc *Magic) Load(files ...string) (bool, error) {
mgc.Lock()
defer mgc.Unlock()
runtime.KeepAlive(mgc.magic)
if mgc.cookie == nil {
return false, mgc.error()
}
var cfiles *C.char
runtime.KeepAlive(cfiles)
defer C.free(unsafe.Pointer(cfiles))
// Assemble the list of custom Magic files into a colon-separated
// list that is required by the underlying Magic library, otherwise
// defer to the default list of paths provided by the Magic library.
if len(files) > 0 {
cfiles = C.CString(strings.Join(files, ":"))
} else {
cfiles = C.magic_getpath_wrapper()
}
if rv := C.magic_load_wrapper(mgc.cookie, cfiles, C.int(mgc.flags)); rv < 0 {
return false, mgc.error()
}
mgc.path = strings.Split(C.GoString(cfiles), ":")
return true, nil
}
示例2: File
// File
//
// If there is an error, it will be of type *Error.
func (mgc *Magic) File(filename string) (string, error) {
mgc.Lock()
defer mgc.Unlock()
runtime.KeepAlive(mgc.magic)
if mgc.cookie == nil {
return "", mgc.error()
}
cfilename := C.CString(filename)
runtime.KeepAlive(cfilename)
defer C.free(unsafe.Pointer(cfilename))
cstring := C.magic_file_wrapper(mgc.cookie, cfilename, C.int(mgc.flags))
if cstring == nil {
rv, err := Version()
if err != nil && err.(*Error).Errno != int(syscall.ENOSYS) {
return "", err
}
// Handle the case when the "ERROR" flag is set regardless
// of the current version of the underlying Magic library.
//
// Prior to version 5.15 the correct behaviour that concerns
// the following IEEE 1003.1 standards was broken:
//
// http://pubs.opengroup.org/onlinepubs/007904975/utilities/file.html
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html
//
// This is an attempt to mitigate the problem and correct
// it to achieve the desired behaviour as per the standards.
if mgc.flags&ERROR != 0 {
return "", mgc.error()
} else if rv < 515 {
C.magic_errno(mgc.cookie)
cstring = C.magic_error(mgc.cookie)
}
}
// XXX(kwilczynski): This case should not happen, ever.
if cstring == nil {
return "", &Error{-1, "unknown result or nil pointer"}
}
// Depending on the version of the underlying
// Magic library the magic_file() function can
// fail and either yield no results or return
// the "(null)" string instead. Often this
// would indicate that an older version of
// the Magic library is in use.
s := C.GoString(cstring)
if s == "" || s == "(null)" {
return "", &Error{-1, "empty or invalid result"}
}
return s, nil
}
示例3: CreateJobObject
func CreateJobObject(sa *syscall.SecurityAttributes, name *uint16) (syscall.Handle, error) {
r1, _, e1 := procCreateJobObjectW.Call(
uintptr(unsafe.Pointer(sa)),
uintptr(unsafe.Pointer(name)))
runtime.KeepAlive(sa)
runtime.KeepAlive(name)
if int(r1) == 0 {
return syscall.InvalidHandle, os.NewSyscallError("CreateJobObject", e1)
}
return syscall.Handle(r1), nil
}
示例4: SetUserObjectSecurity
func SetUserObjectSecurity(obj syscall.Handle, sid uint32, desc []byte) error {
r1, _, e1 := procSetUserObjectSecurity.Call(
uintptr(obj),
uintptr(unsafe.Pointer(&sid)),
uintptr(unsafe.Pointer(&desc[0])))
runtime.KeepAlive(&sid)
runtime.KeepAlive(&desc)
if int(r1) == 0 {
return os.NewSyscallError("SetUserObjectSecurity", e1)
}
return nil
}
示例5: AddAccessAllowedAce
func AddAccessAllowedAce(acl *Acl, revision, mask uint32, sid *syscall.SID) error {
r1, _, e1 := procAddAccessAllowedAce.Call(
uintptr(unsafe.Pointer(acl)),
uintptr(revision),
uintptr(mask),
uintptr(unsafe.Pointer(sid)))
runtime.KeepAlive(acl)
runtime.KeepAlive(sid)
if int(r1) == 0 {
return os.NewSyscallError("AddAccessAllowedAce", e1)
}
return nil
}
示例6: SetSecurityDescriptorDacl
func SetSecurityDescriptorDacl(sd []byte, present bool, acl *Acl, defaulted bool) error {
r1, _, e1 := procSetSecurityDescriptorDacl.Call(
uintptr(unsafe.Pointer(&sd[0])),
uintptr(boolToUint32(present)),
uintptr(unsafe.Pointer(acl)),
uintptr(boolToUint32(defaulted)))
runtime.KeepAlive(sd)
runtime.KeepAlive(acl)
if int(r1) == 0 {
return os.NewSyscallError("SetSecurityDescriptorDacl", e1)
}
return nil
}
示例7: CreateWindowStation
func CreateWindowStation(winsta *uint16, flags, desiredAccess uint32, sa *syscall.SecurityAttributes) (Hwinsta, error) {
r1, _, e1 := procCreateWindowStationW.Call(
uintptr(unsafe.Pointer(winsta)),
uintptr(flags),
uintptr(desiredAccess),
uintptr(unsafe.Pointer(sa)))
runtime.KeepAlive(winsta)
runtime.KeepAlive(sa)
if int(r1) == 0 {
return Hwinsta(r1), os.NewSyscallError("CreateWindowStation", e1)
}
return Hwinsta(r1), nil
}
示例8: AddAce
func AddAce(acl *Acl, revision, startIndex uint32, ace *Ace, size uint32) error {
r1, _, e1 := procAddAce.Call(
uintptr(unsafe.Pointer(acl)),
uintptr(revision),
uintptr(startIndex),
uintptr(unsafe.Pointer(ace)),
uintptr(size))
runtime.KeepAlive(acl)
runtime.KeepAlive(ace)
if int(r1) == 0 {
return os.NewSyscallError("AddAce", e1)
}
return nil
}
示例9: f
func f(x *big, start int64) {
if delta := inuse() - start; delta < 9<<20 {
println("after alloc: expected delta at least 9MB, got: ", delta)
}
runtime.KeepAlive(x)
x = nil
if delta := inuse() - start; delta > 1<<20 {
println("after drop: expected delta below 1MB, got: ", delta)
}
x = new(big)
if delta := inuse() - start; delta < 9<<20 {
println("second alloc: expected delta at least 9MB, got: ", delta)
}
runtime.KeepAlive(x)
}
示例10: CreateDesktop
func CreateDesktop(desktop, device *uint16, devmode uintptr, flags, desiredAccess uint32, sa *syscall.SecurityAttributes) (Hdesk, error) {
r1, _, e1 := procCreateDesktopW.Call(
uintptr(unsafe.Pointer(desktop)),
uintptr(unsafe.Pointer(device)),
devmode,
uintptr(flags),
uintptr(desiredAccess),
uintptr(unsafe.Pointer(sa)))
runtime.KeepAlive(desktop)
runtime.KeepAlive(device)
runtime.KeepAlive(sa)
if int(r1) == 0 {
return Hdesk(r1), os.NewSyscallError("CreateDesktop", e1)
}
return Hdesk(r1), nil
}
示例11: evict
func (pd *pollDesc) evict() {
pd.closing = true
if pd.fd != nil {
syscall.StopIO(pd.fd.sysfd)
runtime.KeepAlive(pd.fd)
}
}
示例12: LogonUser
func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32) (token syscall.Handle, err error) {
r1, _, e1 := procLogonUserW.Call(
uintptr(unsafe.Pointer(username)),
uintptr(unsafe.Pointer(domain)),
uintptr(unsafe.Pointer(password)),
uintptr(logonType),
uintptr(logonProvider),
uintptr(unsafe.Pointer(&token)))
runtime.KeepAlive(username)
runtime.KeepAlive(domain)
runtime.KeepAlive(password)
if int(r1) == 0 {
return syscall.InvalidHandle, os.NewSyscallError("LogonUser", e1)
}
return
}
示例13: FlagsSlice
// FlagsSlice returns a slice containing each distinct flag that
// is currently set and included as a part of the current value
// (bitmask) of flags. Results are sorted in an ascending order.
// If there is an error, it will be of type *Error.
func (mgc *Magic) FlagsSlice() ([]int, error) {
mgc.Lock()
defer mgc.Unlock()
runtime.KeepAlive(mgc.magic)
if mgc.cookie == nil {
return []int{}, mgc.error()
}
if mgc.flags == 0 {
return []int{0}, nil
}
var n int
var flags []int
// Split current value (bitmask) into a list
// of distinct flags (bits) currently set.
for i := mgc.flags; i > 0; i = i - n {
n = int(math.Log2(float64(i)))
n = int(math.Pow(2, float64(n)))
flags = append(flags, n)
}
sort.Ints(flags)
return flags, nil
}
示例14: InitializeSecurityDescriptor
func InitializeSecurityDescriptor(sd []byte) error {
r1, _, e1 := procInitializeSecurityDescriptor.Call(
uintptr(unsafe.Pointer(&sd[0])),
SECURITY_DESCRIPTOR_REVISION)
runtime.KeepAlive(sd)
if int(r1) == 0 {
return os.NewSyscallError("InitializeSecurityDescriptor", e1)
}
return nil
}
示例15: init
func (pd *pollDesc) init(fd *netFD) error {
serverInit.Do(runtime_pollServerInit)
ctx, errno := runtime_pollOpen(uintptr(fd.sysfd))
runtime.KeepAlive(fd)
if errno != 0 {
return syscall.Errno(errno)
}
pd.runtimeCtx = ctx
return nil
}