Home >Backend Development >Golang >Native Windows function IsTpmReady throws 'Too many posts to semaphore' error

Native Windows function IsTpmReady throws 'Too many posts to semaphore' error

王林
王林forward
2024-02-09 16:21:30927browse

本机 Windows 函数 IsTpmReady 抛出“对信号量发布了太多帖子”错误

php Xiaobian Yuzai encountered an error when using the native Windows function IsTpmReady. The error message was "Too many posts were posted to the semaphore". This error may prevent the program from running properly, so a solution needs to be found. The following will introduce how to solve this error, I hope it will be helpful to you.

Question content

I am trying to call the tpmisready function from the tpmcoreprovisioning.dll included on windows. I don't notice anything obviously 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 the wrong thing, or not freeing resources?

Solution

Although this is not really my area of ​​expertise as @Eelco mentioned most of the time it should have something to do with your antivirus. You can continue through this checklist:

  1. Disable any antivirus software you are running, including Windows Defender
  2. Run it as administrator (I'm assuming you've already tried this)
  3. Check that you are using the latest version of Windows

If it still doesn't work, try performing a clean boot

  1. Press windows R and enter "msconfig"

  2. It should open the "System Configuration" from which you have to navigate to the "Services Tab" and check the "Hide all Microsoft Services box" and then press the Disable button

  3. Navigate to the Startup tab and disable all programs in the same way and click Apply after closing the Task Manager window inside the tab

  4. Continue to restart the computer and run the program again

If it still doesn't work, maybe restart your computer in safe mode (using networking as it's easier to search for something if you need to) and try again.

If it still doesn't work: At this point I don't know what else might work. But you can try running it on another computer and see if the error persists. You can reset the machine, but this can be inconvenient. Check if you have any programs that may be conflicting or extending.

The above is the detailed content of Native Windows function IsTpmReady throws 'Too many posts to semaphore' error. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete