danakjavi: chrome
alexmos: content
avi: ui as well please
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Exo was reverted but files I own are LGTM
cc/layers/heads_up_display_layer_impl.cc
cc/resources/cross_thread_shared_bitmap.h
cc/test/pixel_test.cc
content/browser/renderer_host/render_process_host_impl.cc
services/test/echo/echo_service.cc
third_party/blink/renderer/platform/graphics/canvas_resource.cc
Commit-Queue | +1 |
buffers[GetSensorReadingSharedBufferOffset(type)];
A woopsie in the SensorReadingSharedBuffer code made spans crash on OOB. The GetSensorReadingSharedBufferOffset() gives an index into the SensorReadingSharedBuffer array, but it does it in number of bytes, not in the number of SensorReadingSharedBuffers. So we have to divide by the sizeof(SensorReadingSharedBuffer).
I thought about changing GetSensorReadingSharedBufferOffset() to return the array offset instead of the byte offset, but it gets stored in a bunch of places that I did not change in this CL.
Code-Review | +1 |
Still LGTM, but I wonder if `GetMemoryAsSpan<char>` could be replaced by something else in some places. `base::as_writable_byte_span(...)`? Or `base::as_string_view(...)`? This is probably optional, but I think it may be useful for teaching future code readers about the generic `span` utilities in `//base` (rather than using a one-off/specific API of shared memory).
new (mapped_region_.mapping.memory()) SharedVersionType;
danakjIs the removal of this placement `new` intentional? IIUC after removal the `GetMemoryAs` below will return uninitialized/non-constructed bytes, which seems wrong?
Łukasz AnforowiczSharedVersionType is an atomic primitive type which is trivially constructed and trivially copyable. So the compiler sees a valid object here. Its value is not important for doing store().
If the placement new were important then we would also need to go through the returned pointer to use it (which we were not).
Acknowledged. Thank you for explaining.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
This change meets the code coverage requirements.
Code-Coverage | +1 |
rockot and bajones are OOO oops
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
The remaining 5 services/ files are trivial / just api change so I think we can OO those ones
Code-Review | +1 |
Owners-Override | +1 |
// TODO(rockot): This function should give back a span instead of an unbounded
Ideally this would be a crbug.
new (mapped_region_.mapping.memory()) SharedVersionType;
I guess as long as MSan doesn't complain... it's a bit of a weird situation though. Technically we need to new it to begin its lifetime, don't we?
new (mapped_region_.mapping.memory()) SharedVersionType;
I guess as long as MSan doesn't complain... it's a bit of a weird situation though. Technically we need to new it to begin its lifetime, don't we?
Sorta but not. We should be laundering in the GetMemoryAs() method to introduce a providence barrier.
The objects in SharedMemory come pre-formed generally, we don't (and can't) call constructors on objects already formed in SharedMemory.
As they are trivially copyable they are understood to be valid objects by the compiler (modulo launder).
Still LGTM, but I wonder if `GetMemoryAsSpan<char>` could be replaced by something else in some places. `base::as_writable_byte_span(...)`? Or `base::as_string_view(...)`? This is probably optional, but I think it may be useful for teaching future code readers about the generic `span` utilities in `//base` (rather than using a one-off/specific API of shared memory).
Done
// TODO(rockot): This function should give back a span instead of an unbounded
Ideally this would be a crbug.
Done
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
This change meets the code coverage requirements.
Code-Coverage | +1 |
19 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/browser/enterprise/connectors/analysis/content_analysis_delegate_unittest.cc
Insertions: 2, Deletions: 1.
@@ -4,6 +4,7 @@
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"
+#include <algorithm>
#include <map>
#include <set>
#include <string>
@@ -107,7 +108,7 @@
base::ReadOnlySharedMemoryRegion create_page(size_t size) {
base::MappedReadOnlyRegion page =
base::ReadOnlySharedMemoryRegion::Create(size);
- std::ranges::fill(page.mapping.GetMemoryAsSpan<char>(), 'a');
+ std::ranges::fill(base::span(page.mapping), 'a');
return std::move(page.region);
}
```
```
The name of the file: chrome/browser/enterprise/connectors/analysis/content_analysis_delegate_browsertest.cc
Insertions: 1, Deletions: 1.
@@ -1811,7 +1811,7 @@
constexpr int64_t kLargeSize = 51 * 1024 * 1024;
base::MappedReadOnlyRegion page =
base::ReadOnlySharedMemoryRegion::Create(kLargeSize);
- std::ranges::fill(page.mapping.GetMemoryAsSpan<char>(), 'a');
+ std::ranges::fill(base::span(page.mapping), 'a');
data.page = std::move(page.region);
ASSERT_TRUE(ContentAnalysisDelegate::IsEnabled(browser()->profile(),
```
```
The name of the file: mojo/core/platform_wrapper_unittest.cc
Insertions: 2, Deletions: 2.
@@ -134,7 +134,7 @@
auto region = base::UnsafeSharedMemoryRegion::Create(kMessage.size());
base::WritableSharedMemoryMapping buffer = region.Map();
CHECK(buffer.IsValid());
- buffer.GetMemoryAsSpan<char>().copy_from(kMessage);
+ base::as_writable_chars(base::span(buffer)).copy_from(kMessage);
RunTestClient("ReadPlatformSharedBuffer", [&](MojoHandle h) {
// Wrap the shared memory handle and send it to the child along with the
@@ -229,7 +229,7 @@
ASSERT_TRUE(region.IsValid());
base::WritableSharedMemoryMapping mapping = region.Map();
- EXPECT_EQ(base::span(message), mapping.GetMemoryAsSpan<char>());
+ EXPECT_EQ(base::as_byte_span(message), base::span(mapping));
// Verify that the received buffer's internal GUID was preserved in transit.
EXPECT_EQ(MOJO_RESULT_OK, WaitForSignals(h, MOJO_HANDLE_SIGNAL_READABLE));
```
```
The name of the file: chrome/browser/ash/extensions/file_manager/image_loader_private_api.cc
Insertions: 1, Deletions: 1.
@@ -245,7 +245,7 @@
Respond(Error("Failed allocate memory for PDF file"));
return;
}
- pdf_region.mapping.GetMemoryAsSpan<char>().copy_from(content);
+ base::as_writable_chars(base::span(pdf_region.mapping)).copy_from(content);
DCHECK(!pdf_thumbnailer_.is_bound());
GetPdfService()->BindPdfThumbnailer(
pdf_thumbnailer_.BindNewPipeAndPassReceiver());
```
```
The name of the file: mojo/core/ipcz_driver/shared_buffer_mapping.cc
Insertions: 2, Deletions: 2.
@@ -28,8 +28,8 @@
if (!m.IsValid()) {
return nullptr;
}
- // TODO(rockot): This function should give back a span instead of an unbounded
- // pointer.
+ // TODO(crbug.com/355607629): This function should give back a span instead of
+ // an unbounded pointer.
*memory = const_cast<uint8_t*>(m.data());
return std::make_unique<typename RegionType::MappingType>(std::move(m));
}
```
```
The name of the file: mojo/public/cpp/base/shared_memory_unittest.cc
Insertions: 9, Deletions: 6.
@@ -13,14 +13,15 @@
TEST(SharedMemoryMojomTest, ReadOnly) {
auto region = base::ReadOnlySharedMemoryRegion::Create(64);
const std::string kTestData = "Hello, world!";
- region.mapping.GetMemoryAsSpan<char>().copy_prefix_from(kTestData);
+ base::as_writable_chars(base::span(region.mapping))
+ .copy_prefix_from(kTestData);
base::ReadOnlySharedMemoryRegion read_only_out;
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
mojo_base::mojom::ReadOnlySharedMemoryRegion>(region.region,
read_only_out));
base::ReadOnlySharedMemoryMapping mapping = read_only_out.Map();
- EXPECT_EQ(region.mapping.GetMemoryAsSpan<char>().first(kTestData.size()),
+ EXPECT_EQ(base::as_chars(base::span(region.mapping)).first(kTestData.size()),
kTestData);
}
@@ -29,7 +30,7 @@
auto region = base::WritableSharedMemoryRegion::Create(64);
auto mapping = region.Map();
const std::string kTestData = "Hello, world!";
- mapping.GetMemoryAsSpan<char>().copy_prefix_from(kTestData);
+ base::as_writable_chars(base::span(mapping)).copy_prefix_from(kTestData);
base::WritableSharedMemoryRegion writable_out;
ASSERT_TRUE(
@@ -37,7 +38,8 @@
mojo_base::mojom::WritableSharedMemoryRegion>(region, writable_out));
mapping = writable_out.Map();
- EXPECT_EQ(mapping.GetMemoryAsSpan<char>().first(kTestData.size()), kTestData);
+ EXPECT_EQ(base::as_chars(base::span(mapping)).first(kTestData.size()),
+ kTestData);
}
#endif // BUILDFLAG(USE_BLINK)
@@ -45,12 +47,13 @@
auto region = base::UnsafeSharedMemoryRegion::Create(64);
auto mapping = region.Map();
const std::string kTestData = "Hello, world!";
- mapping.GetMemoryAsSpan<char>().copy_prefix_from(kTestData);
+ base::as_writable_chars(base::span(mapping)).copy_prefix_from(kTestData);
base::UnsafeSharedMemoryRegion unsafe_out;
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
mojo_base::mojom::UnsafeSharedMemoryRegion>(region, unsafe_out));
mapping = unsafe_out.Map();
- EXPECT_EQ(mapping.GetMemoryAsSpan<char>().first(kTestData.size()), kTestData);
+ EXPECT_EQ(base::as_chars(base::span(mapping)).first(kTestData.size()),
+ kTestData);
}
```
```
The name of the file: mojo/public/cpp/platform/tests/platform_handle_unittest.cc
Insertions: 2, Deletions: 2.
@@ -158,7 +158,7 @@
PlatformHandle SetUpSharedMemory() {
auto region = base::UnsafeSharedMemoryRegion::Create(kTestData.size());
auto mapping = region.Map();
- mapping.GetMemoryAsSpan<char>().copy_from(kTestData);
+ base::as_writable_chars(base::span(mapping)).copy_from(kTestData);
auto generic_region =
base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(region));
@@ -184,7 +184,7 @@
auto region =
base::UnsafeSharedMemoryRegion::Deserialize(std::move(generic_region));
auto mapping = region.Map();
- std::string contents(base::as_string_view(mapping.GetMemoryAsSpan<char>()));
+ std::string contents(base::as_string_view(mapping));
// Let |handle| retain ownership.
generic_region = base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
```
Deprecate SharedMemoryRegion memory(), replace it with data() and spans
The accessor returns an unbounded void* which is dangerous to use.
Callers should instead use GetMemoryAsSpan() or GetMemoryAs(). To ease
this we introduce `uint8_t* data()` which allows SharedMemoryMappings
to convert implicitly or explicitly to base::span<uint8_t>.
We enable unsafe-buffer-usage warning in the shared memory unit tests,
which mostly required changing tests to use span apis instead of
working with the unbounded pointer accessor. The span apis
return the same pointer but with a length attached.
Other code is changed to span(mapping), GetMemoryAsSpan() or
GetMemoryAs(). These require the types being pulled out of shared
memory are trivially copyable. However a couple classes used in this
way in devices were _not_ trivially copyable. This can cause UB.
These classes wanted to be trivially copyable but could not be
because of the out-of-line ctor requirements of the chromium clang
plugin. So we template these and use a type alias to avoid rewriting
1000 LOC with useless template arguments. This works around the clang
plugin for now.
R=luk...@chromium.org
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |