- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们编写了可在 Windows 和 Ubuntu 上编译的 C++ 代码。我想使用安全函数 memset_s
将我的应用程序中的缓冲区清零。
Windows 和 Ubuntu 16.04 都不包含 __STDC_LIB_EXT1__
宏的定义,所以我无法使用 C++11 提供的 memset_s
。
在 Windows 上,我有 SecureZeroMemory
可以防止编译器优化。在 Ubuntu 16.04(GCC 5.4 版)上,我正在寻找 SecureZeroMemory
等效库函数(这将阻止编译器优化)。
如果你能建议我在 linux 中的库函数,这将非常有帮助,结束选项是 linux 平台的手动实现 memset_s
提前致谢
最佳答案
如果你想确保内存归零并且这个操作没有被编译器优化(因为 as-if 规则),你可以放置一个“优化器屏障”:
void always_memset(void* dest,int ch,size_t count){
memset(dest,ch,count);
//Make the compiler believe that you are using memory
//including memory referenced by dest
asm volatile("" : : :"memory");//it is possible to be more subtle.
}
然后 memset_s
可以很容易地通过在先决条件检查之后调用这个函数来实现。
关于c++ - Linux (gcc 5.4) 中是否有任何特定于 Windows 的 SecureZeroMemory 等效库函数可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53606684/
我找到了一些示例代码,如下所示: addrinfo hints; SecureZeroMemory(&hints, sizeof(hints)); 这里有使用 SecureZeroMemory() 的
WinAPI 中有一个 SecureZeroMemory() 函数,用于在不再需要缓冲区时删除用于存储密码/加密 key /类似内容的内存。它与 ZeroMemory() 的不同之处在于它的调用不会被
谁能帮我理解为什么我的代码在第一段代码中的 delete[] szPassword 上失败?我知道 szPassword 只是复制“a”,而 st2 等于 8: TCHAR *szPassword =
我知道有一个 SecureZeroMemory C中的函数函数实现在 中定义作为RtlSecureZeroMemory功能。 QNS:如何SecureZeroMemory在Delphi中使用? De
Mac OS X 是否有等同于 RtlSecureZeroMemory 的版本?/SecureZeroMemory ,一个将内存块清零的函数,但调用不会被编译器优化掉? 最佳答案 编写自己的函数: v
This MSND article说 SecureZeroMemory() 适用于在内存中存储了一段时间的敏感数据应该确保在不再需要时尽快覆盖的情况。 this SO question的答案解释为什么
我们编写了可在 Windows 和 Ubuntu 上编译的 C++ 代码。我想使用安全函数 memset_s 将我的应用程序中的缓冲区清零。 Windows 和 Ubuntu 16.04 都不包含 _
我是一名优秀的程序员,十分优秀!