vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / generic / tty / module.cpp
bloba45eccbed69e7e494c4c7243a0ba515e06c500e7
1 /*
2 * Copyright 2010, Michael Lotz, mmlr@mlotz.ch.
3 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the Haiku License.
5 */
7 #include <new>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include <lock.h>
15 #include <tty/tty_module.h>
17 #include "tty_private.h"
19 struct mutex gGlobalTTYLock;
20 struct mutex gTTYCookieLock;
21 struct recursive_lock gTTYRequestLock;
24 static status_t
25 init_tty_module()
27 // create the request mutex
28 recursive_lock_init(&gTTYRequestLock, "tty requests");
30 // create the global mutex
31 mutex_init(&gGlobalTTYLock, "tty global");
33 // create the cookie mutex
34 mutex_init(&gTTYCookieLock, "tty cookies");
36 return B_OK;
40 static void
41 uninit_tty_module()
43 recursive_lock_destroy(&gTTYRequestLock);
44 mutex_destroy(&gTTYCookieLock);
45 mutex_destroy(&gGlobalTTYLock);
49 static int32
50 tty_module_std_ops(int32 op, ...)
52 switch (op) {
53 case B_MODULE_INIT:
54 return init_tty_module();
56 case B_MODULE_UNINIT:
57 uninit_tty_module();
58 return B_OK;
61 return B_BAD_VALUE;
65 static struct tty_module_info sTTYModule = {
67 B_TTY_MODULE_NAME,
68 0, //B_KEEP_LOADED,
69 tty_module_std_ops
72 &tty_create,
73 &tty_destroy,
74 &tty_create_cookie,
75 &tty_close_cookie,
76 &tty_destroy_cookie,
77 &tty_read,
78 &tty_write,
79 &tty_control,
80 &tty_select,
81 &tty_deselect,
82 &tty_hardware_signal
86 module_info *modules[] = {
87 (module_info *)&sTTYModule,
88 NULL