[test] embed_windows

This commit is contained in:
maze.y2b@gmail.com 2021-11-27 21:23:34 +08:00
parent 35cf39e415
commit 828ff82ff2
6 changed files with 89 additions and 7 deletions

View file

@ -10,6 +10,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"sync/atomic" "sync/atomic"
"time" "time"
_ "unsafe" _ "unsafe"
@ -31,7 +32,7 @@ type rateJuggler struct {
changing int32 changing int32
} }
var WintunTunnelType = "Clash" var WintunTunnelType = "Clash.Meta"
var WintunStaticRequestedGUID *windows.GUID var WintunStaticRequestedGUID *windows.GUID
//go:linkname procyield runtime.procyield //go:linkname procyield runtime.procyield
@ -67,6 +68,7 @@ func (tun *tunWindows) ForceMTU(mtu int) {
func (tun *tunWindows) Read0(buff []byte, offset int) (int, error) { func (tun *tunWindows) Read0(buff []byte, offset int) (int, error) {
tun.running.Add(1) tun.running.Add(1)
defer tun.running.Done() defer tun.running.Done()
retry: retry:
if atomic.LoadInt32(&tun.close) == 1 { if atomic.LoadInt32(&tun.close) == 1 {

View file

@ -0,0 +1,21 @@
package wintun
// Copyright 2020 MeshStep Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
import (
_ "embed"
)
//go:embed static/386/wintun.dll
var ddlContent []byte

View file

@ -0,0 +1,21 @@
package wintun
// Copyright 2020 MeshStep Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
import (
_ "embed"
)
//go:embed static/amd64/wintun.dll
var ddlContent []byte

View file

@ -0,0 +1,21 @@
package wintun
// Copyright 2020 MeshStep Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
import (
_ "embed"
)
//go:embed static/arm/wintun.dll
var ddlContent []byte

View file

@ -0,0 +1,21 @@
package wintun
// Copyright 2020 MeshStep Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
import (
_ "embed"
)
//go:embed static/arm64/wintun.dll
var ddlContent []byte

View file

@ -7,6 +7,7 @@ package wintun
import ( import (
"fmt" "fmt"
"golang.zx2c4.com/wireguard/windows/driver/memmod"
"sync" "sync"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
@ -78,12 +79,7 @@ func (d *lazyDLL) Load() error {
return nil return nil
} }
//const ( module, err := memmod.LoadLibrary(ddlContent)
// LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x00000200
// LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
//)
//module, err := windows.LoadLibraryEx(d.Name, 0, LOAD_LIBRARY_SEARCH_APPLICATION_DIR|LOAD_LIBRARY_SEARCH_SYSTEM32)
module, err := windows.LoadLibraryEx(C.Path.GetAssetLocation(d.Name), 0, windows.LOAD_WITH_ALTERED_SEARCH_PATH)
if err != nil { if err != nil {
return fmt.Errorf("Unable to load library: %w", err) return fmt.Errorf("Unable to load library: %w", err)
} }