Skip to content

libsel4camkes/virtqueue: use const qualifier#137

Open
axel-h wants to merge 1 commit intoseL4:masterfrom
Hensoldt-Cyber:patch-axel-16
Open

libsel4camkes/virtqueue: use const qualifier#137
axel-h wants to merge 1 commit intoseL4:masterfrom
Hensoldt-Cyber:patch-axel-16

Conversation

@axel-h
Copy link
Member

@axel-h axel-h commented May 24, 2023

Ensure const correctness is kept. Sending a buffer implies that the buffer is not modified.

Without this change, there is always a compiler warning if a buffer with a const qualifier is passed to these APIs. Casting away the const qualifier contradicts the intention of using const.

@axel-h
Copy link
Member Author

axel-h commented May 25, 2023

It seems the test failure happens due to a race condition, where the output from different thread overlaps. Instead of echo_int: 2 we get

echo_int: client Event received!
client Event received!
Sender Event received!
2

* @return 0 on success, -1 on fail
*/
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size);
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, const void *buffer, size_t size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is also used for enqueuing buffers in the virtqueue to receive data on?

In this case send means that the buffer is being sent to the other end of the queue (the device side). If the queue is used for transmitting data then the data in the buffer would be read by the other end, but if the queue is being used for receiving data then the other side would modify the contents before sending it back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Would it make sense to separate the APIs then for the different use cases to support proper semantics?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the semantics are just enqueuing into available hands a mutable reference over, and receiving from the other queue takes it back. Whether the buffers are written to by the other side is a higher level concern depending on the protocol using the buffers.

@axel-h axel-h force-pushed the patch-axel-16 branch 2 times, most recently from 1d38a2e to 1785419 Compare February 2, 2024 11:28
Ensure const correctness is kept. Sending a buffer implies that the
buffer is not modified.

Signed-off-by: Axel Heider <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants