if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
- return nil, fmt.Errorf("Unable to put into IFHEAD mode: %v", errno)
+ return nil, fmt.Errorf("Unable to put into IFHEAD mode: %w", errno)
}
// Open control sockets
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
- return nil, fmt.Errorf("Unable to get nd6 flags for %s: %v", assignedName, errno)
+ return nil, fmt.Errorf("Unable to get nd6 flags for %s: %w", assignedName, errno)
}
ndireq.Flags = ndireq.Flags &^ ND6_IFF_AUTO_LINKLOCAL
ndireq.Flags = ndireq.Flags | ND6_IFF_NO_DAD
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
- return nil, fmt.Errorf("Unable to set nd6 flags for %s: %v", assignedName, errno)
+ return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
}
// Rename the interface
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
- return nil, fmt.Errorf("Failed to rename %s to %s: %v", assignedName, name, errno)
+ return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
}
return CreateTUNFromFile(tunFile, mtu)
var err error
WintunPool, err = wintun.MakePool("WireGuard")
if err != nil {
- panic(fmt.Errorf("Failed to make pool: %v", err))
+ panic(fmt.Errorf("Failed to make pool: %w", err))
}
}
// If so, we delete it, in case it has weird residual configuration.
_, err = wt.Delete(true)
if err != nil {
- return nil, fmt.Errorf("Error deleting already existing interface: %v", err)
+ return nil, fmt.Errorf("Error deleting already existing interface: %w", err)
}
}
wt, _, err = WintunPool.CreateAdapter(ifname, requestedGUID)
if err != nil {
- return nil, fmt.Errorf("Error creating interface: %v", err)
+ return nil, fmt.Errorf("Error creating interface: %w", err)
}
forcedMTU := 1420
if err != nil {
_, err = tun.wt.Delete(false)
close(tun.events)
- return nil, fmt.Errorf("Error starting session: %v", err)
+ return nil, fmt.Errorf("Error starting session: %w", err)
}
tun.readWait = tun.session.ReadWaitEvent()
return tun, nil
case windows.ERROR_INVALID_DATA:
return 0, errors.New("Send ring corrupt")
}
- return 0, fmt.Errorf("Read failed: %v", err)
+ return 0, fmt.Errorf("Read failed: %w", err)
}
}
case windows.ERROR_BUFFER_OVERFLOW:
return 0, nil // Dropping when ring is full.
}
- return 0, fmt.Errorf("Write failed: %v", err)
+ return 0, fmt.Errorf("Write failed: %w", err)
}
// LUID returns Windows interface instance ID.
const ourModule windows.Handle = 0
resInfo, err := resource.FindByName(ourModule, d.Name, resource.RT_RCDATA)
if err != nil {
- return fmt.Errorf("Unable to find \"%v\" RCDATA resource: %v", d.Name, err)
+ return fmt.Errorf("Unable to find \"%v\" RCDATA resource: %w", d.Name, err)
}
data, err := resource.Load(ourModule, resInfo)
if err != nil {
- return fmt.Errorf("Unable to load resource: %v", err)
+ return fmt.Errorf("Unable to load resource: %w", err)
}
module, err := memmod.LoadLibrary(data)
if err != nil {
- return fmt.Errorf("Unable to load library: %v", err)
+ return fmt.Errorf("Unable to load library: %w", err)
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&d.module)), unsafe.Pointer(module))
err := p.dll.Load()
if err != nil {
- return fmt.Errorf("Error loading %v DLL: %v", p.dll.Name, err)
+ return fmt.Errorf("Error loading %v DLL: %w", p.dll.Name, err)
}
addr, err := p.dll.module.ProcAddressByName(p.Name)
if err != nil {
- return fmt.Errorf("Error getting %v address: %v", p.Name, err)
+ return fmt.Errorf("Error getting %v address: %w", p.Name, err)
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.addr)), unsafe.Pointer(addr))
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
- return fmt.Errorf("Error allocating section: %v", err)
+ return fmt.Errorf("Error allocating section: %w", err)
}
// Always use position from file to support alignments smaller than page size (allocation above will align to page size).
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
- return fmt.Errorf("Error allocating memory block: %v", err)
+ return fmt.Errorf("Error allocating memory block: %w", err)
}
// Always use position from file to support alignments smaller than page size (allocation above will align to page size).
var oldProtect uint32
err := windows.VirtualProtect(sectionData.address, sectionData.size, protect, &oldProtect)
if err != nil {
- return fmt.Errorf("Error protecting memory page: %v", err)
+ return fmt.Errorf("Error protecting memory page: %w", err)
}
return nil
err := module.finalizeSection(§ionData)
if err != nil {
- return fmt.Errorf("Error finalizing section: %v", err)
+ return fmt.Errorf("Error finalizing section: %w", err)
}
sectionData.address = sectionAddress
sectionData.alignedAddress = alignedAddress
sectionData.last = true
err := module.finalizeSection(§ionData)
if err != nil {
- return fmt.Errorf("Error finalizing section: %v", err)
+ return fmt.Errorf("Error finalizing section: %w", err)
}
return nil
}
}
default:
- return false, fmt.Errorf("Unsupported relocation: %v", relType)
+ return false, fmt.Errorf("Unsupported relocation: %w", relType)
}
}
for !isBadReadPtr(uintptr(unsafe.Pointer(importDesc)), unsafe.Sizeof(*importDesc)) && importDesc.Name != 0 {
handle, err := loadLibraryA((*byte)(a2p(module.codeBase + uintptr(importDesc.Name))))
if err != nil {
- return fmt.Errorf("Error loading module: %v", err)
+ return fmt.Errorf("Error loading module: %w", err)
}
var thunkRef, funcRef *uintptr
if importDesc.OriginalFirstThunk() != 0 {
}
if err != nil {
windows.FreeLibrary(handle)
- return fmt.Errorf("Error getting function address: %v", err)
+ return fmt.Errorf("Error getting function address: %w", err)
}
thunkRef = (*uintptr)(a2p(uintptr(unsafe.Pointer(thunkRef)) + unsafe.Sizeof(*thunkRef)))
funcRef = (*uintptr)(a2p(uintptr(unsafe.Pointer(funcRef)) + unsafe.Sizeof(*funcRef)))
windows.MEM_RESERVE|windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
- err = fmt.Errorf("Error allocating code: %v", err)
+ err = fmt.Errorf("Error allocating code: %w", err)
return
}
}
err = module.check4GBBoundaries(alignedImageSize)
if err != nil {
- err = fmt.Errorf("Error reallocating code: %v", err)
+ err = fmt.Errorf("Error reallocating code: %w", err)
return
}
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
- err = fmt.Errorf("Error allocating headers: %v", err)
+ err = fmt.Errorf("Error allocating headers: %w", err)
return
}
// Copy PE header to code.
// Copy sections from DLL file block to new memory location.
err = module.copySections(addr, size, oldHeader)
if err != nil {
- err = fmt.Errorf("Error copying sections: %v", err)
+ err = fmt.Errorf("Error copying sections: %w", err)
return
}
if locationDelta != 0 {
module.isRelocated, err = module.performBaseRelocation(locationDelta)
if err != nil {
- err = fmt.Errorf("Error relocating module: %v", err)
+ err = fmt.Errorf("Error relocating module: %w", err)
return
}
} else {
// Load required dlls and adjust function table of imports.
err = module.buildImportTable()
if err != nil {
- err = fmt.Errorf("Error building import table: %v", err)
+ err = fmt.Errorf("Error building import table: %w", err)
return
}
// Mark memory pages depending on section headers and release sections that are marked as "discardable".
err = module.finalizeSections()
if err != nil {
- err = fmt.Errorf("Error finalizing sections: %v", err)
+ err = fmt.Errorf("Error finalizing sections: %w", err)
return
}
windows.MEM_RESERVE|windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
- return fmt.Errorf("Error allocating memory block: %v", err)
+ return fmt.Errorf("Error allocating memory block: %w", err)
}
}
return
func Load(module, resInfo windows.Handle) (data []byte, err error) {
size, err := sizeofResource(module, resInfo)
if err != nil {
- err = fmt.Errorf("Unable to size resource: %v", err)
+ err = fmt.Errorf("Unable to size resource: %w", err)
return
}
resData, err := loadResource(module, resInfo)
if err != nil {
- err = fmt.Errorf("Unable to load resource: %v", err)
+ err = fmt.Errorf("Unable to load resource: %w", err)
return
}
ptr, err := lockResource(resData)
if err != nil {
- err = fmt.Errorf("Unable to lock resource: %v", err)
+ err = fmt.Errorf("Unable to lock resource: %w", err)
return
}
unsafeSlice(unsafe.Pointer(&data), unsafe.Pointer(ptr), int(size))