return nil, err
}
// size is guaranteed to be ≥1 by initializeProcThreadAttributeList.
- al := (*_PROC_THREAD_ATTRIBUTE_LIST)(unsafe.Pointer(&make([]unsafe.Pointer, (size+ptrSize-1)/ptrSize)[0]))
+ al := (*_PROC_THREAD_ATTRIBUTE_LIST)(unsafe.Pointer(&make([]byte, size)[0]))
err = initializeProcThreadAttributeList(al, maxAttrCount, 0, &size)
if err != nil {
return nil, err
import (
"os"
"path/filepath"
- "runtime"
"syscall"
"testing"
- "time"
- "unsafe"
)
func TestWin32finddata(t *testing.T) {
t.Errorf("TOKEN_ALL_ACCESS = %x, want 0xF01FF", syscall.TOKEN_ALL_ACCESS)
}
}
-
-func TestProcThreadAttributeListPointers(t *testing.T) {
- list, err := syscall.NewProcThreadAttributeList(1)
- if err != nil {
- t.Errorf("unable to create ProcThreadAttributeList: %v", err)
- }
- done := make(chan struct{})
- fds := make([]syscall.Handle, 20)
- runtime.SetFinalizer(&fds[0], func(*syscall.Handle) {
- close(done)
- })
- err = syscall.UpdateProcThreadAttribute(list, 0, syscall.PROC_THREAD_ATTRIBUTE_HANDLE_LIST, unsafe.Pointer(&fds[0]), uintptr(len(fds))*unsafe.Sizeof(fds[0]), nil, nil)
- if err != nil {
- syscall.DeleteProcThreadAttributeList(list)
- t.Errorf("unable to update ProcThreadAttributeList: %v", err)
- return
- }
- runtime.GC()
- runtime.GC()
- select {
- case <-done:
- t.Error("ProcThreadAttributeList was garbage collected unexpectedly")
- default:
- }
- syscall.DeleteProcThreadAttributeList(list)
- runtime.GC()
- runtime.GC()
- select {
- case <-done:
- case <-time.After(time.Second):
- t.Error("ProcThreadAttributeList was not garbage collected after a second")
- }
-}
package syscall
-import "unsafe"
-
const (
// Windows errors.
ERROR_FILE_NOT_FOUND Errno = 2
}
type _PROC_THREAD_ATTRIBUTE_LIST struct {
- // This is of type unsafe.Pointer, not of type byte or uintptr, because
- // the contents of it is mostly a list of pointers, and in most cases,
- // that's a list of pointers to Go-allocated objects. In order to keep
- // the GC from collecting these objects, we declare this as unsafe.Pointer.
- _ [1]unsafe.Pointer
+ _ [1]byte
}
const (