Fix Reg<long double> for MSAN

On x86 `long double` has 10 bytes of meaningful data, but `sizeof(long double)` is 16 - the remaining bytes are random garbage.

Roll forward after fixing a bug in the original commit.

PiperOrigin-RevId: 368170639
Change-Id: I4a1d2d95b92eed6b71c37145726f7320cfc00ba0
This commit is contained in:
Wiktor Garbacz 2021-04-13 01:43:36 -07:00 committed by Copybara-Service
parent 141fe911f5
commit 00649577d9
5 changed files with 10 additions and 4 deletions

View File

@ -86,6 +86,7 @@ cc_library(
"//sandboxed_api/util:status",
"@com_google_absl//absl/base",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:dynamic_annotations",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",

View File

@ -75,7 +75,8 @@ add_library(sapi_sapi ${SAPI_LIB_TYPE}
)
add_library(sapi::sapi ALIAS sapi_sapi)
target_link_libraries(sapi_sapi
PRIVATE absl::flat_hash_map
PRIVATE absl::dynamic_annotations
absl::flat_hash_map
absl::memory
absl::status
absl::statusor

View File

@ -396,6 +396,8 @@ void ServeRequest(sandbox2::Comms* comms) {
}
if (ret.ret_type == v::Type::kFloat) {
// Make MSAN happy with long double.
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(&ret.float_val, sizeof(ret.float_val));
VLOG(1) << "Returned value: " << ret.float_val
<< ", Success: " << (ret.success ? "Yes" : "No");
} else {

View File

@ -24,6 +24,7 @@
#include <glog/logging.h>
#include "absl/base/casts.h"
#include "absl/base/dynamic_annotations.h"
#include "absl/base/macros.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
@ -323,6 +324,9 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret,
if (arg->GetType() == v::Type::kFloat) {
arg->GetDataFromPtr(&rfcall.args[i].arg_float,
sizeof(rfcall.args[0].arg_float));
// Make MSAN happy with long double.
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(&rfcall.args[i].arg_float,
sizeof(rfcall.args[0].arg_float));
} else {
arg->GetDataFromPtr(&rfcall.args[i].arg_int,
sizeof(rfcall.args[0].arg_int));

View File

@ -57,9 +57,7 @@ class Reg : public Callable {
"Only register-sized types are allowed as template argument "
"for class Reg.");
Reg() : Reg(static_cast<T>(0)) {}
explicit Reg(const T val) {
explicit Reg(const T val = {}) {
val_ = val;
SetLocal(&val_);
}