vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / common / zero.c
blobfea72bc3eebdd6a838868459e7a08fdf8ba57e50
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
7 #include <Drivers.h>
8 #include <KernelExport.h>
10 #include <string.h>
13 #define DEVICE_NAME "zero"
15 int32 api_version = B_CUR_DRIVER_API_VERSION;
18 static status_t
19 zero_open(const char *name, uint32 flags, void **cookie)
21 *cookie = NULL;
22 return B_OK;
26 static status_t
27 zero_close(void *cookie)
29 return B_OK;
33 static status_t
34 zero_freecookie(void *cookie)
36 return B_OK;
40 static status_t
41 zero_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
43 return EPERM;
47 static status_t
48 zero_read(void *cookie, off_t pos, void *buffer, size_t *_length)
50 if (user_memset(buffer, 0, *_length) < B_OK)
51 return B_BAD_ADDRESS;
53 return B_OK;
57 static status_t
58 zero_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
60 return B_OK;
64 // #pragma mark -
67 status_t
68 init_hardware(void)
70 return B_OK;
74 const char **
75 publish_devices(void)
77 static const char *devices[] = {
78 DEVICE_NAME,
79 NULL
82 return devices;
86 device_hooks *
87 find_device(const char *name)
89 static device_hooks hooks = {
90 &zero_open,
91 &zero_close,
92 &zero_freecookie,
93 &zero_ioctl,
94 &zero_read,
95 &zero_write,
96 /* Leave select/deselect/readv/writev undefined. The kernel will
97 * use its own default implementation. The basic hooks above this
98 * line MUST be defined, however. */
99 NULL,
100 NULL,
101 NULL,
102 NULL
105 if (!strcmp(name, DEVICE_NAME))
106 return &hooks;
108 return NULL;
112 status_t
113 init_driver(void)
115 return B_OK;
119 void
120 uninit_driver(void)