google / glazier

A tool for automating the installation of the Microsoft Windows operating system on various device platforms.
Apache License 2.0
1.22k stars 90 forks source link

Any example about using DismProgressCallback? #737

Open typenoob opened 1 month ago

typenoob commented 1 month ago

Here is my code to enable netfx3 features


import (
    "fmt"
    "syscall"
    "unsafe"

    "github.com/google/glazier/go/dism"
)

func callback(current uint, total uint, data unsafe.Pointer) {
    fmt.Println(current)
}
func main() {
    s, err := dism.OpenSession(dism.DISM_ONLINE_IMAGE, "", "", dism.DismLogErrorsWarningsInfo, "", "")
    if err != nil {
        panic(err)
    }
    defer s.Close()
    path := "./sxs"
    name := "NetFx3"
    n, err1 := syscall.UTF16PtrFromString(name)
    if err1 != nil {
        panic(err1)
    }
    progress := callback
    err2 := dism.DismEnableFeature(*s.Handle, n, nil, nil, true, &path, 1, true, nil, unsafe.Pointer(&progress), nil)
    if err2 != nil {
        panic(err2)
    }
}

which returns errors

Exception 0xc0000005 0x8 0xc000109e70 0xc000109e70
PC=0xc000109e70

runtime.cgocall(0x14e420, 0x289a28)
        C:/Program Files/Go/src/runtime/cgocall.go:167 +0x3e fp=0xc000109c08 sp=0xc000109ba0 pc=0x14101e
syscall.SyscallN(0x7ffd078dd6d0?, {0xc000109c48?, 0xc00000a2bc?, 0x0?})
        C:/Program Files/Go/src/runtime/syscall_windows.go:519 +0x46 fp=0xc000109c28 sp=0xc000109c08 pc=0x148b86
syscall.Syscall12(0x6?, 0x5?, 0x7?, 0x5?, 0x1?, 0xc00000a300?, 0xc000109dc8?, 0x16a525?, 0x1bb329?, 0x1, ...)
        C:/Program Files/Go/src/runtime/syscall_windows.go:479 +0xcb fp=0xc000109d18 sp=0xc000109c28 pc=0x148b0b
github.com/google/glazier/go/dism.DismEnableFeature(0x2, 0x2b?, 0x0?, 0x0?, 0x1, 0x0?, 0x1, 0x1, 0x0?, 0xc000109e70, ...)
        C:/Users/Administrator/go/pkg/mod/github.com/google/glazier@v0.0.0-20240814164234-9e7cb89dfde9/go/dism/zdism.go:155 +0x137 fp=0xc000109dd8 sp=0xc000109d18 pc=0x190f77
main.main()
        C:/users/coyote/code/dotnet35/main.go:28 +0x245 fp=0xc000109f50 sp=0xc000109dd8 pc=0x191545
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:272 +0x27d fp=0xc000109fe0 sp=0xc000109f50 pc=0x11755d
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000109fe8 sp=0xc000109fe0 pc=0x14cca1

goroutine 2 gp=0xc00004c700 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc00004ffa8 sp=0xc00004ff88 pc=0x145b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.forcegchelper()
        C:/Program Files/Go/src/runtime/proc.go:337 +0xb8 fp=0xc00004ffe0 sp=0xc00004ffa8 pc=0x117878
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x14cca1
created by runtime.init.7 in goroutine 1
        C:/Program Files/Go/src/runtime/proc.go:325 +0x1a

goroutine 3 gp=0xc00004ca80 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000051f80 sp=0xc000051f60 pc=0x145b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.bgsweep(0xc00005e000)
        C:/Program Files/Go/src/runtime/mgcsweep.go:277 +0x94 fp=0xc000051fc8 sp=0xc000051f80 pc=0x1015d4
runtime.gcenable.gowrap1()
        C:/Program Files/Go/src/runtime/mgc.go:203 +0x25 fp=0xc000051fe0 sp=0xc000051fc8 pc=0xf5ea5
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000051fe8 sp=0xc000051fe0 pc=0x14cca1
created by runtime.gcenable in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:203 +0x66

goroutine 4 gp=0xc00004cc40 m=nil [GC scavenge wait]:
runtime.gopark(0xc00005e000?, 0x1e5968?, 0x1?, 0x0?, 0xc00004cc40?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000065f78 sp=0xc000065f58 pc=0x145b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.(*scavengerState).park(0x288960)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000065fa8 sp=0xc000065f78 pc=0xff009
runtime.bgscavenge(0xc00005e000)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000065fc8 sp=0xc000065fa8 pc=0xff57c
runtime.gcenable.gowrap2()
        C:/Program Files/Go/src/runtime/mgc.go:204 +0x25 fp=0xc000065fe0 sp=0xc000065fc8 pc=0xf5e45
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000065fe8 sp=0xc000065fe0 pc=0x14cca1
created by runtime.gcenable in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:204 +0xa5

goroutine 5 gp=0xc00004cfc0 m=nil [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000067e20 sp=0xc000067e00 pc=0x145b0e
runtime.runfinq()
        C:/Program Files/Go/src/runtime/mfinal.go:193 +0x107 fp=0xc000067fe0 sp=0xc000067e20 pc=0xf4f67
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000067fe8 sp=0xc000067fe0 pc=0x14cca1
created by runtime.createfing in goroutine 1
        C:/Program Files/Go/src/runtime/mfinal.go:163 +0x3d

goroutine 6 gp=0xc00004d180 m=nil [chan receive]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000061f18 sp=0xc000061ef8 pc=0x145b0e
runtime.chanrecv(0xc00006c0e0, 0x0, 0x1)
        C:/Program Files/Go/src/runtime/chan.go:639 +0x41e fp=0xc000061f90 sp=0xc000061f18 pc=0xe679e
runtime.chanrecv1(0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/chan.go:489 +0x12 fp=0xc000061fb8 sp=0xc000061f90 pc=0xe6372
runtime.unique_runtime_registerUniqueMapCleanup.func1(...)
        C:/Program Files/Go/src/runtime/mgc.go:1732
runtime.unique_runtime_registerUniqueMapCleanup.gowrap1()
        C:/Program Files/Go/src/runtime/mgc.go:1735 +0x2f fp=0xc000061fe0 sp=0xc000061fb8 pc=0xf8d4f
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x14cca1
created by unique.runtime_registerUniqueMapCleanup in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:1730 +0x96
rax     0xc000109e70
rbx     0x1d4f064b5e0
rcx     0x0
rdx     0x3e8
rdi     0x0
rsi     0x0
rbp     0x23893ffb59
rsp     0x23893ff9d8
r8      0x0
r9      0x3e8
r10     0xb2c52fb238515270
r11     0x0
r12     0x1d4f064b5e0
r13     0x0
r14     0x0
r15     0x1d4f064b5e0
rip     0xc000109e70
rflags  0x10202
cs      0x33
fs      0x53
gs      0x2b
exit status 2
PS C:\users\coyote\code\dotnet35> go run main.go
Exception 0xc0000005 0x8 0xc000109e70 0xc000109e70
PC=0xc000109e70

runtime.cgocall(0x99e420, 0xad9a28)
        C:/Program Files/Go/src/runtime/cgocall.go:167 +0x3e fp=0xc000109c08 sp=0xc000109ba0 pc=0x99101e
syscall.SyscallN(0x7ffd1c5bd6d0?, {0xc000109c48?, 0xc00000a2bc?, 0x0?})
        C:/Program Files/Go/src/runtime/syscall_windows.go:519 +0x46 fp=0xc000109c28 sp=0xc000109c08 pc=0x998b86
syscall.Syscall12(0x6?, 0x5?, 0x7?, 0x5?, 0x1?, 0xc00000a300?, 0xc000109dc8?, 0x9ba525?, 0xa0b329?, 0x1, ...)
        C:/Program Files/Go/src/runtime/syscall_windows.go:479 +0xcb fp=0xc000109d18 sp=0xc000109c28 pc=0x998b0b
github.com/google/glazier/go/dism.DismEnableFeature(0x2, 0x2b?, 0x0?, 0x0?, 0x1, 0x0?, 0x1, 0x1, 0x0?, 0xc000109e70, ...)
        C:/Users/Administrator/go/pkg/mod/github.com/google/glazier@v0.0.0-20240814164234-9e7cb89dfde9/go/dism/zdism.go:155 +0x137 fp=0xc000109dd8 sp=0xc000109d18 pc=0x9e0f77
main.main()
        C:/users/coyote/code/dotnet35/main.go:27 +0x245 fp=0xc000109f50 sp=0xc000109dd8 pc=0x9e1505
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:272 +0x27d fp=0xc000109fe0 sp=0xc000109f50 pc=0x96755d
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000109fe8 sp=0xc000109fe0 pc=0x99cca1

goroutine 2 gp=0xc00004c700 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc00004ffa8 sp=0xc00004ff88 pc=0x995b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.forcegchelper()
        C:/Program Files/Go/src/runtime/proc.go:337 +0xb8 fp=0xc00004ffe0 sp=0xc00004ffa8 pc=0x967878
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x99cca1
created by runtime.init.7 in goroutine 1
        C:/Program Files/Go/src/runtime/proc.go:325 +0x1a

goroutine 3 gp=0xc00004ca80 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000051f80 sp=0xc000051f60 pc=0x995b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.bgsweep(0xc00005e000)
        C:/Program Files/Go/src/runtime/mgcsweep.go:277 +0x94 fp=0xc000051fc8 sp=0xc000051f80 pc=0x9515d4
runtime.gcenable.gowrap1()
        C:/Program Files/Go/src/runtime/mgc.go:203 +0x25 fp=0xc000051fe0 sp=0xc000051fc8 pc=0x945ea5
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000051fe8 sp=0xc000051fe0 pc=0x99cca1
created by runtime.gcenable in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:203 +0x66

goroutine 4 gp=0xc00004cc40 m=nil [GC scavenge wait]:
runtime.gopark(0xc00005e000?, 0xa35940?, 0x1?, 0x0?, 0xc00004cc40?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000065f78 sp=0xc000065f58 pc=0x995b0e
runtime.goparkunlock(...)
        C:/Program Files/Go/src/runtime/proc.go:430
runtime.(*scavengerState).park(0xad8960)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000065fa8 sp=0xc000065f78 pc=0x94f009
runtime.bgscavenge(0xc00005e000)
        C:/Program Files/Go/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000065fc8 sp=0xc000065fa8 pc=0x94f57c
runtime.gcenable.gowrap2()
        C:/Program Files/Go/src/runtime/mgc.go:204 +0x25 fp=0xc000065fe0 sp=0xc000065fc8 pc=0x945e45
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000065fe8 sp=0xc000065fe0 pc=0x99cca1
created by runtime.gcenable in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:204 +0xa5

goroutine 5 gp=0xc00004cfc0 m=nil [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000067e20 sp=0xc000067e00 pc=0x995b0e
runtime.runfinq()
        C:/Program Files/Go/src/runtime/mfinal.go:193 +0x107 fp=0xc000067fe0 sp=0xc000067e20 pc=0x944f67
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000067fe8 sp=0xc000067fe0 pc=0x99cca1
created by runtime.createfing in goroutine 1
        C:/Program Files/Go/src/runtime/mfinal.go:163 +0x3d

goroutine 6 gp=0xc00004d180 m=nil [chan receive]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/proc.go:424 +0xce fp=0xc000061f18 sp=0xc000061ef8 pc=0x995b0e
runtime.chanrecv(0xc00006c0e0, 0x0, 0x1)
        C:/Program Files/Go/src/runtime/chan.go:639 +0x41e fp=0xc000061f90 sp=0xc000061f18 pc=0x93679e
runtime.chanrecv1(0x0?, 0x0?)
        C:/Program Files/Go/src/runtime/chan.go:489 +0x12 fp=0xc000061fb8 sp=0xc000061f90 pc=0x936372
runtime.unique_runtime_registerUniqueMapCleanup.func1(...)
        C:/Program Files/Go/src/runtime/mgc.go:1732
runtime.unique_runtime_registerUniqueMapCleanup.gowrap1()
        C:/Program Files/Go/src/runtime/mgc.go:1735 +0x2f fp=0xc000061fe0 sp=0xc000061fb8 pc=0x948d4f
runtime.goexit({})
        C:/Program Files/Go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x99cca1
created by unique.runtime_registerUniqueMapCleanup in goroutine 1
        C:/Program Files/Go/src/runtime/mgc.go:1730 +0x96
rax     0xc000109e70
rbx     0x21de9b2b5e0
rcx     0x0
rdx     0x3e8
rdi     0x0
rsi     0x0
rbp     0x4ea29ff9f9
rsp     0x4ea29ff878
r8      0x0
r9      0x3e8
r10     0xb2c52fb238515270
r11     0x0
r12     0x21de9b2b5e0
r13     0x0
r14     0x0
r15     0x21de9b2b5e0
rip     0xc000109e70
rflags  0x10202
cs      0x33
fs      0x53
gs      0x2b
exit status 2

Not set Progress parameter would solve it, but I hope to use Progress Callback function, appreciate to any help.

typenoob commented 1 month ago

Not related to this issue, but I believe the the type of SourcePaths in the following function should be **uint16

https://github.com/google/glazier/blob/9e7cb89dfde9571f813614ab9a41806166a6d5a6/go/dism/zdism.go#L146-L160