Native Windows Function IsTpmReady throws "too many posts were made to a semaphore" error
Matthew Barrera
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?
11 Answer
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:
- Disable any anti-virus you have running includes windows defender
- Run it as administrator(I assume you would have tried this already)
- Check if you are on the latest version of windows
If it still doesn't work try performing a clean boot by
Press windows + R and type "msconfig"
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
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
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 in case 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.
2