简体   繁体   中英

Native Windows Function IsTpmReady throws "too many posts were made to a semaphore" error

I'm attempting to call the TpmIsReady function from the TpmCoreProvisioning.dll included on Windows. I don't notice anything glaringly wrong with the code, but the error is thrown regardless.

This is what I have:

package windows

import (
    "errors"
    "log"
    "syscall"
    "unsafe"
)

var (
    TPMDLL   = syscall.NewLazyDLL("TpmCoreProvisioning.dll")
    TpmReady = TPMDLL.NewProc("TpmIsReady")
)

func IsTpmReady() (bool, error) {
    var enabled byte
    ptr := (uintptr)(unsafe.Pointer(&enabled))
    _, _, err := TpmReady.Call(ptr)
    if errors.Is(err, syscall.Errno(0)) {
        return enabled == 1, nil
    }
    if DEBUG {
        log.Printf("IsTpmReady: %v", err)
    }
    return false, err
}

Am I using something incorrectly, or not freeing resources?

Although this is not really my area of expertise as @Eelco has mentioned most of the time it should be related to your antivirus. You can proceed through this checklist: 1.Disable any anti-virus you have running includes windows defender 2.Run it as administrator(I assume you would have tried this already) 3.Check if you are on the latest version of windows

If it still doesn't work try performing a clean boot by 1.Press windows + R and type "msconfig" 2.It should open "system configuration" from which you have to navigate to the "services tab" and check "Hide all Microsoft services box" and press the disable button 3.Navigate to the startup tab and disable all the programs in the same fashion then click apply after closing the task manager windows inside the tab 4.Proceed to restart your machine and run the program again

If it still.... doesn't work perhaps restart your machine in safe mode(with networking as it's easier to search something incase needed) and try again.

IF IT STILL DOESN'T WORK... At this point I don't know what else works.... but you could try running it on another machine and see if the error persists. You can reset your machine but it would be rather inconvenient...Check if you have any programs that might conflict or extensions. Unfortunately this is all i can do to help... Hope some part is found useful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM