vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / bus_managers / ps2 / packet_buffer.h
blob409c63eaa5515d387145fc95a09791cb2da03477
1 /*
2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef PACKET_BUFFER_H
6 #define PACKET_BUFFER_H
9 #include <KernelExport.h>
10 #include <OS.h>
13 struct ring_buffer;
16 /** The idea behind this packet buffer is to have multi-threading safe
17 * implementation that can be used in interrupts on top of the
18 * ring_buffer implementation provided by the kernel.
19 * It uses a spinlock for synchronization.
21 * IOW if you don't have such high restrictions in your environment,
22 * you better don't want to use it at all.
24 struct packet_buffer {
25 struct ring_buffer* buffer;
26 spinlock lock;
30 struct packet_buffer* create_packet_buffer(size_t size);
31 void delete_packet_buffer(struct packet_buffer* buffer);
33 void packet_buffer_clear(struct packet_buffer* buffer);
34 size_t packet_buffer_readable(struct packet_buffer* buffer);
35 size_t packet_buffer_writable(struct packet_buffer *buffer);
36 void packet_buffer_flush(struct packet_buffer* buffer, size_t bytes);
37 size_t packet_buffer_read(struct packet_buffer* buffer, uint8* data, size_t
38 length);
39 size_t packet_buffer_write(struct packet_buffer* buffer, const uint8* data,
40 size_t length);
42 #endif /* PACKET_BUFFER_H */