本地 Windows 函数 IsTpmReady 抛出“太多的信号量被使用”错误。

huangapple go评论87阅读模式
英文:

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

问题

我正在尝试调用Windows中包含的TpmCoreProvisioning.dll中的TpmIsReady函数。我没有注意到代码中有什么明显的错误,但是无论如何都会抛出错误。

以下是我的代码:

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
}

我是否使用了错误的东西,或者没有释放资源?

英文:

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?

答案1

得分: 0

虽然这不是我专长的领域,正如@Eelco所提到的,大多数情况下这可能与您的防病毒软件有关。您可以按照以下检查清单进行操作:

  1. 禁用任何正在运行的防病毒软件,包括Windows Defender。
  2. 以管理员身份运行程序(我假设您可能已经尝试过这个)。
  3. 检查您是否使用的是最新版本的Windows。

如果仍然无法解决问题,请尝试执行干净启动:

  1. 按下Windows键+R,然后输入"msconfig"。
  2. 这将打开"系统配置",您需要导航到"服务"选项卡,并勾选"隐藏所有Microsoft服务"框,然后点击禁用按钮。
  3. 导航到"启动"选项卡,并以相同的方式禁用所有程序,然后在选项卡内关闭任务管理器窗口后点击应用。
  4. 重新启动计算机,然后再次运行程序。

如果仍然无法解决问题,可以尝试在安全模式下重新启动计算机(带网络连接,以便在需要时更容易搜索),然后再次尝试。

如果仍然无法解决问题:此时我不知道还有什么其他方法可以解决。但您可以尝试在另一台计算机上运行该程序,看看是否仍然出现错误。您可以重置计算机,但这可能会非常不方便。检查是否有可能引起冲突的程序或扩展。

英文:

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 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.

huangapple
  • 本文由 发表于 2022年12月18日 00:46:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/74835794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定