ipcz: Fix C compile
ipcz.h should be suitable for C99 compilation.
This CL fixes some missing `struct` keywords on typenames and replaces a
bool in IpczCreateNodeOptions with an integer flags field.
Bug: None
Change-Id: I720f0e9d979962db88a2c7f755dc58cc1508611a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4275242
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1108052}
NOKEYCHECK=True
GitOrigin-RevId: a895940891dbdb33543c9591ec8725e7aa6bce2f
diff --git a/include/ipcz/ipcz.h b/include/ipcz/ipcz.h
index 2b77aca..f03d02a 100644
--- a/include/ipcz/ipcz.h
+++ b/include/ipcz/ipcz.h
@@ -544,21 +544,28 @@
} // extern "C"
#endif
+// Flags which may be passed via the `memory_flags` field of
+// IpczCreateNodeOptions to configure features of ipcz internal memory
+// allocation and usage.
+typedef uint32_t IpczMemoryFlags;
+
+// If this flag is set, the node will not attempt to expand the shared memory
+// pools it uses to allocate parcel data between itself and other nodes.
+//
+// This means more application messages may fall back onto driver I/O for
+// transmission, but also that ipcz' memory footprint will remain largely
+// constant. Note that memory may still be expanded to facilitate new portal
+// links as needed.
+#define IPCZ_MEMORY_FIXED_PARCEL_CAPACITY ((IpczMemoryFlags)(1 << 0))
+
// Options given to CreateNode() to configure the new node's behavior.
struct IPCZ_ALIGN(8) IpczCreateNodeOptions {
// The exact size of this structure in bytes. Must be set accurately before
// passing the structure to CreateNode().
size_t size;
- // If set to true this node will not attempt to expand the shared memory
- // capacity from which parcel data blocks may be allocated on its various
- // links to other nodes.
- //
- // This means more application messages may fall back onto driver I/O for
- // transmission, but also that ipcz' memory footprint will remain largely
- // constant. Note that memory may still be occasionally expanded to facilitate
- // new portal links as needed.
- bool disable_parcel_memory_expansion;
+ // See IpczMemoryFlags above.
+ IpczMemoryFlags memory_flags;
};
// See CreateNode() and the IPCZ_CREATE_NODE_* flag descriptions below.
@@ -1052,11 +1059,12 @@
// from operating correctly. For example, the is returned if ipcz was
// built against a std::atomic implementation which does not provide
// lock-free 32-bit and 64-bit atomics.
- IpczResult(IPCZ_API* CreateNode)(const struct IpczDriver* driver, // in
- IpczDriverHandle driver_node, // in
- IpczCreateNodeFlags flags, // in
- const IpczCreateNodeOptions* options, // in
- IpczHandle* node); // out
+ IpczResult(IPCZ_API* CreateNode)(
+ const struct IpczDriver* driver, // in
+ IpczDriverHandle driver_node, // in
+ IpczCreateNodeFlags flags, // in
+ const struct IpczCreateNodeOptions* options, // in
+ IpczHandle* node); // out
// ConnectNode()
// =============
@@ -1707,11 +1715,11 @@
//
// IPCZ_RESULT_INVALID_ARGUMENT if `contents` is null or malformed, or if
// `handle` is null.
- IpczResult(IPCZ_API* Box)(IpczHandle node, // in
- const IpczBoxContents* contents, // in
- uint32_t flags, // in
- const void* options, // in
- IpczHandle* handle); // out
+ IpczResult(IPCZ_API* Box)(IpczHandle node, // in
+ const struct IpczBoxContents* contents, // in
+ uint32_t flags, // in
+ const void* options, // in
+ IpczHandle* handle); // out
// Unbox()
// =======
@@ -1732,10 +1740,10 @@
//
// IPCZ_RESULT_INVALID_ARGUMENT if `handle` is invalid or does not
// reference a box, or if `contents` is null or malformed.
- IpczResult(IPCZ_API* Unbox)(IpczHandle handle, // in
- IpczUnboxFlags flags, // in
- const void* options, // in
- IpczBoxContents* contents); // out
+ IpczResult(IPCZ_API* Unbox)(IpczHandle handle, // in
+ IpczUnboxFlags flags, // in
+ const void* options, // in
+ struct IpczBoxContents* contents); // out
};
// A function which populates `api` with a table of ipcz API functions. The
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 6ca7706..4b3bbaf 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -371,6 +371,7 @@
sources = [
"api_test.cc",
"box_test.cc",
+ "compile_c_test.c",
"connect_test.cc",
"ipcz/block_allocator_test.cc",
"ipcz/buffer_pool_test.cc",
diff --git a/src/compile_c_test.c b/src/compile_c_test.c
new file mode 100644
index 0000000..c759207
--- /dev/null
+++ b/src/compile_c_test.c
@@ -0,0 +1,4 @@
+// Basic compilation test to ensure that we can include ipcz.h from a pure C
+// source file and have it compile successfully. There's no actual test to run
+// here.
+#include "ipcz/ipcz.h"
diff --git a/src/ipcz/node_link_memory.cc b/src/ipcz/node_link_memory.cc
index b4715bc..480c756 100644
--- a/src/ipcz/node_link_memory.cc
+++ b/src/ipcz/node_link_memory.cc
@@ -154,7 +154,8 @@
DriverMemoryMapping primary_buffer_memory)
: node_(std::move(node)),
allow_memory_expansion_for_parcel_data_(
- !node_->options().disable_parcel_memory_expansion),
+ (node_->options().memory_flags & IPCZ_MEMORY_FIXED_PARCEL_CAPACITY) ==
+ 0),
primary_buffer_memory_(primary_buffer_memory.bytes()),
primary_buffer_(
*reinterpret_cast<PrimaryBuffer*>(primary_buffer_memory_.data())) {
diff --git a/src/ipcz/node_link_memory_test.cc b/src/ipcz/node_link_memory_test.cc
index d7b5941..5871d3f 100644
--- a/src/ipcz/node_link_memory_test.cc
+++ b/src/ipcz/node_link_memory_test.cc
@@ -271,7 +271,7 @@
const IpczCreateNodeOptions options = {
.size = sizeof(options),
- .disable_parcel_memory_expansion = true,
+ .memory_flags = IPCZ_MEMORY_FIXED_PARCEL_CAPACITY,
};
const Ref<Node> node_c{MakeRefCounted<Node>(
Node::Type::kNormal, kTestDriver, IPCZ_INVALID_DRIVER_HANDLE, &options)};