Skip to content

Commit

Permalink
com: fix 386 build failure
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Klotz <[email protected]>
  • Loading branch information
dblohm7 committed Jan 23, 2024
1 parent 3ed4d48 commit cc31069
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 168 deletions.
167 changes: 0 additions & 167 deletions com/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,103 +179,6 @@ func (o SequentialStream) Write(b []byte) (int, error) {
return p.Write(b)
}

func (abi *IStreamABI) Seek(offset int64, whence int) (n int64, _ error) {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[5]

if runtime.GOARCH == "386" {
words := (*[2]uintptr)(unsafe.Pointer(&offset))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
words[0],
words[1],
uintptr(uint32(whence)),
uintptr(unsafe.Pointer(&n)),
)
hr = wingoes.HRESULT(rc)
} else {
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(offset),
uintptr(uint32(whence)),
uintptr(unsafe.Pointer(&n)),
)
hr = wingoes.HRESULT(rc)
}

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return 0, e
}

return n, nil
}

func (abi *IStreamABI) SetSize(newSize uint64) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[6]

if runtime.GOARCH == "386" {
words := (*[2]uintptr)(unsafe.Pointer(&newSize))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
words[0],
words[1],
)
hr = wingoes.HRESULT(rc)
} else {
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(newSize),
)
hr = wingoes.HRESULT(rc)
}

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}

func (abi *IStreamABI) CopyTo(dest *IStreamABI, numBytesToCopy uint64) (bytesRead, bytesWritten uint64, _ error) {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[7]

if runtime.GOARCH == "386" {
words := (*[2]uintptr)(unsafe.Pointer(&numBytesToCopy))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(unsafe.Pointer(dest)),
words[0],
words[1],
uintptr(unsafe.Pointer(&bytesRead)),
uintptr(unsafe.Pointer(&bytesWritten)),
)
hr = wingoes.HRESULT(rc)
} else {
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(unsafe.Pointer(dest)),
uintptr(numBytesToCopy),
uintptr(unsafe.Pointer(&bytesRead)),
uintptr(unsafe.Pointer(&bytesWritten)),
)
hr = wingoes.HRESULT(rc)
}

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return bytesRead, bytesWritten, e
}

return bytesRead, bytesWritten, nil
}

func (abi *IStreamABI) Commit(flags STGC) error {
method := unsafe.Slice(abi.Vtbl, 14)[8]

Expand Down Expand Up @@ -306,76 +209,6 @@ func (abi *IStreamABI) Revert() error {
return nil
}

func (abi *IStreamABI) LockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[10]

if runtime.GOARCH == "386" {
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
oWords[0],
oWords[1],
nWords[0],
nWords[1],
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)
} else {
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(offset),
uintptr(numBytes),
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)
}

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}

func (abi *IStreamABI) UnlockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[11]

if runtime.GOARCH == "386" {
oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
oWords[0],
oWords[1],
nWords[0],
nWords[1],
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)
} else {
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(offset),
uintptr(numBytes),
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)
}

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}

func (abi *IStreamABI) Stat(flags STATFLAG) (*STATSTG, error) {
result := new(STATSTG)
method := unsafe.Slice(abi.Vtbl, 14)[12]
Expand Down
130 changes: 130 additions & 0 deletions com/stream_386.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) 2023 Tailscale Inc & AUTHORS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows

package com

import (
"math"
"syscall"
"unsafe"

"github.com/dblohm7/wingoes"
)

const maxStreamRWLen = math.MaxInt32

Check failure on line 17 in com/stream_386.go

View workflow job for this annotation

GitHub Actions / build-and-test (386)

other declaration of maxStreamRWLen

func (abi *IStreamABI) Seek(offset int64, whence int) (n int64, _ error) {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[5]

words := (*[2]uintptr)(unsafe.Pointer(&offset))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
words[0],
words[1],
uintptr(uint32(whence)),
uintptr(unsafe.Pointer(&n)),
)
hr = wingoes.HRESULT(rc)

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return 0, e
}

return n, nil
}

func (abi *IStreamABI) SetSize(newSize uint64) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[6]

words := (*[2]uintptr)(unsafe.Pointer(&newSize))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
words[0],
words[1],
)
hr = wingoes.HRESULT(rc)

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}

func (abi *IStreamABI) CopyTo(dest *IStreamABI, numBytesToCopy uint64) (bytesRead, bytesWritten uint64, _ error) {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[7]

words := (*[2]uintptr)(unsafe.Pointer(&numBytesToCopy))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
uintptr(unsafe.Pointer(dest)),
words[0],
words[1],
uintptr(unsafe.Pointer(&bytesRead)),
uintptr(unsafe.Pointer(&bytesWritten)),
)
hr = wingoes.HRESULT(rc)

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return bytesRead, bytesWritten, e
}

return bytesRead, bytesWritten, nil
}

func (abi *IStreamABI) LockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[10]

oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
oWords[0],
oWords[1],
nWords[0],
nWords[1],
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}

func (abi *IStreamABI) UnlockRegion(offset, numBytes uint64, lockType LOCKTYPE) error {
var hr wingoes.HRESULT
method := unsafe.Slice(abi.Vtbl, 14)[11]

oWords := (*[2]uintptr)(unsafe.Pointer(&offset))
nWords := (*[2]uintptr)(unsafe.Pointer(&numBytes))
rc, _, _ := syscall.SyscallN(
method,
uintptr(unsafe.Pointer(abi)),
oWords[0],
oWords[1],
nWords[0],
nWords[1],
uintptr(lockType),
)
hr = wingoes.HRESULT(rc)

if e := wingoes.ErrorFromHRESULT(hr); e.Failed() {
return e
}

return nil
}
Loading

0 comments on commit cc31069

Please sign in to comment.