@@ -241,10 +241,6 @@ void HandleAllocMsg(const size_t size, FuncRet* ret) {
241241 VLOG (1 ) << " HandleAllocMsg: size=" << size;
242242
243243 const void * allocated = malloc (size);
244- // Memory is copied to the pointer using an API that the memory sanitizer
245- // is blind to (process_vm_writev). Mark the memory as initialized here, so
246- // that the sandboxed code can still be tested using MSAN.
247- ABSL_ANNOTATE_MEMORY_IS_INITIALIZED (allocated, size);
248244
249245 ret->ret_type = v::Type::kPointer ;
250246 ret->int_val = reinterpret_cast <uintptr_t >(allocated);
@@ -257,16 +253,20 @@ void HandleReallocMsg(uintptr_t ptr, size_t size, FuncRet* ret) {
257253 << " )" ;
258254
259255 const void * reallocated = realloc (reinterpret_cast <void *>(ptr), size);
260- // Memory is copied to the pointer using an API that the memory sanitizer
261- // is blind to (process_vm_writev). Mark the memory as initialized here, so
262- // that the sandboxed code can still be tested using MSAN.
263- ABSL_ANNOTATE_MEMORY_IS_INITIALIZED (reallocated, size);
264256
265257 ret->ret_type = v::Type::kPointer ;
266258 ret->int_val = reinterpret_cast <uintptr_t >(reallocated);
267259 ret->success = true ;
268260}
269261
262+ void HandleMarkMemoryInit (uintptr_t ptr, size_t size, FuncRet* ret) {
263+ ABSL_ANNOTATE_MEMORY_IS_INITIALIZED (reinterpret_cast <void *>(ptr), size);
264+
265+ ret->ret_type = v::Type::kVoid ;
266+ ret->success = true ;
267+ ret->int_val = 0ULL ;
268+ }
269+
270270// Handles requests to free memory previously allocated by HandleAllocMsg() and
271271// HandleReallocMsg().
272272void HandleFreeMsg (uintptr_t ptr, FuncRet* ret) {
@@ -399,6 +399,12 @@ void ServeRequest(sandbox2::Comms* comms) {
399399 VLOG (1 ) << " Received Client::kMsgStrlen message" ;
400400 HandleStrlen (comms, BytesAs<const char *>(bytes), &ret);
401401 break ;
402+ case comms::kMsgMarkMemoryInit :
403+ VLOG (1 ) << " Received Client::kMsgMarkMemoryInit message" ;
404+ {
405+ auto req = BytesAs<comms::ReallocRequest>(bytes);
406+ HandleMarkMemoryInit (req.old_addr , req.size , &ret);
407+ }
402408 break ;
403409 default :
404410 LOG (FATAL ) << " Received unknown tag: " << tag;
0 commit comments