vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / busses / random / VirtioRNGPrivate.h
blob60a4921ee810a5ff428903d97f6b5071aa8f3586
1 /*
2 * Copyright 2013, Jérôme Duval, korli@users.berlios.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef VIRTIO_RNG_PRIVATE_H
6 #define VIRTIO_RNG_PRIVATE_H
9 #include <condition_variable.h>
10 #include <lock.h>
11 #include "random.h"
12 #include <virtio.h>
15 //#define TRACE_VIRTIO_RNG
16 #ifdef TRACE_VIRTIO_RNG
17 # define TRACE(x...) dprintf("virtio_rng: " x)
18 #else
19 # define TRACE(x...) ;
20 #endif
21 #define ERROR(x...) dprintf("\33[33mvirtio_rng:\33[0m " x)
22 #define CALLED() TRACE("CALLED %s\n", __PRETTY_FUNCTION__)
25 extern device_manager_info* gDeviceManager;
26 extern random_for_controller_interface *gRandom;
29 #define BUFFER_SIZE 16
32 class VirtioRNGDevice {
33 public:
34 VirtioRNGDevice(device_node* node);
35 ~VirtioRNGDevice();
37 status_t InitCheck();
39 status_t Read(void* buffer, size_t* numBytes);
42 private:
43 static void _RequestCallback(void* driverCookie,
44 void *cookie);
45 void _RequestInterrupt();
47 device_node* fNode;
49 virtio_device_interface* fVirtio;
50 virtio_device* fVirtioDevice;
52 status_t fStatus;
53 uint32 fFeatures;
54 ::virtio_queue fVirtioQueue;
56 physical_entry fEntry;
57 uint8 fBuffer[BUFFER_SIZE];
58 uint32 fOffset;
60 spinlock fInterruptLock;
61 ConditionVariable fInterruptCondition;
62 ConditionVariableEntry fInterruptConditionEntry;
63 bool fExpectsInterrupt;
67 #endif // VIRTIO_RNG_PRIVATE_H