diff options
author | Ralf Baechle <ralf@linux-mips.org> | 1997-04-29 21:13:14 +0000 |
---|---|---|
committer | <ralf@linux-mips.org> | 1997-04-29 21:13:14 +0000 |
commit | 19c9bba94152148523ba0f7ef7cffe3d45656b11 (patch) | |
tree | 40b1cb534496a7f1ca0f5c314a523c69f1fee464 /drivers/char/vt.c | |
parent | 7206675c40394c78a90e74812bbdbf8cf3cca1be (diff) |
Import of Linux/MIPS 2.1.36
Diffstat (limited to 'drivers/char/vt.c')
-rw-r--r-- | drivers/char/vt.c | 946 |
1 files changed, 535 insertions, 411 deletions
diff --git a/drivers/char/vt.c b/drivers/char/vt.c index d5cd08183..0f4957971 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -6,8 +6,10 @@ * Dynamic diacritical handling - aeb@cwi.nl - Dec 1993 * Dynamic keymap and string allocation - aeb@cwi.nl - May 1994 * Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995 + * Some code moved for less code duplication - Andi Kleen - Mar 1997 */ +#include <linux/config.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/sched.h> @@ -29,7 +31,7 @@ #include "diacr.h" #include "selection.h" -extern char vt_dont_switch; +char vt_dont_switch = 0; extern struct tty_driver console_driver; #define VT_IS_IN_USE(i) (console_driver.table[i] && console_driver.table[i]->count) @@ -58,7 +60,7 @@ extern int getkeycode(unsigned int scancode); extern int setkeycode(unsigned int scancode, unsigned int keycode); extern void compute_shiftstate(void); extern void complete_change_console(unsigned int new_console); -extern int vt_waitactive(void); +extern int vt_waitactive(int vt); extern void do_blank_screen(int nopowersave); extern unsigned int keymap_count; @@ -80,6 +82,7 @@ extern int con_get_font(char * fontmap); extern int con_set_cmap(unsigned char *cmap); extern int con_get_cmap(unsigned char *cmap); extern void reset_palette(int currcons); +extern void set_palette(void) ; extern int con_adjust_height(unsigned long fontheight); extern int video_mode_512ch; @@ -193,7 +196,272 @@ void (*kd_mksound)(unsigned int hz, unsigned int ticks) = _kd_nullsound; #else void (*kd_mksound)(unsigned int hz, unsigned int ticks) = _kd_mksound; #endif - + + +#define i (tmp.kb_index) +#define s (tmp.kb_table) +#define v (tmp.kb_value) +static inline int +do_kdsk_ioctl(int cmd, struct kbentry *user_kbe, int perm, struct kbd_struct *kbd) +{ + struct kbentry tmp; + ushort *key_map, val, ov; + + if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry))) + return -EFAULT; + if (i >= NR_KEYS || s >= MAX_NR_KEYMAPS) + return -EINVAL; + + switch (cmd) { + case KDGKBENT: + key_map = key_maps[s]; + if (key_map) { + val = U(key_map[i]); + if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES) + val = K_HOLE; + } else + val = (i ? K_HOLE : K_NOSUCHMAP); + return __put_user(val, &user_kbe->kb_value); + case KDSKBENT: + if (!perm) + return -EPERM; + if (!i && v == K_NOSUCHMAP) { + /* disallocate map */ + key_map = key_maps[s]; + if (s && key_map) { + key_maps[s] = 0; + if (key_map[0] == U(K_ALLOCATED)) { + kfree_s(key_map, sizeof(plain_map)); + keymap_count--; + } + } + break; + } + + if (KTYP(v) < NR_TYPES) { + if (KVAL(v) > max_vals[KTYP(v)]) + return -EINVAL; + } else + if (kbd->kbdmode != VC_UNICODE) + return -EINVAL; + + /* assignment to entry 0 only tests validity of args */ + if (!i) + break; + + if (!(key_map = key_maps[s])) { + int j; + + if (keymap_count >= MAX_NR_OF_USER_KEYMAPS && !suser()) + return -EPERM; + + key_map = (ushort *) kmalloc(sizeof(plain_map), + GFP_KERNEL); + if (!key_map) + return -ENOMEM; + key_maps[s] = key_map; + key_map[0] = U(K_ALLOCATED); + for (j = 1; j < NR_KEYS; j++) + key_map[j] = U(K_HOLE); + keymap_count++; + } + ov = U(key_map[i]); + if (v == ov) + break; /* nothing to do */ + /* + * Attention Key. + */ + if (((ov == K_SAK) || (v == K_SAK)) && !suser()) + return -EPERM; + key_map[i] = U(v); + if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT)) + compute_shiftstate(); + break; + } + return 0; +} +#undef i +#undef s +#undef v + +static inline int +do_kbkeycode_ioctl(int cmd, struct kbkeycode *user_kbkc, int perm) +{ + struct kbkeycode tmp; + int kc = 0; + + if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode))) + return -EFAULT; + switch (cmd) { + case KDGETKEYCODE: + kc = getkeycode(tmp.scancode); + if (kc >= 0) + kc = __put_user(kc, &user_kbkc->keycode); + break; + case KDSETKEYCODE: + if (!perm) + return -EPERM; + kc = setkeycode(tmp.scancode, tmp.keycode); + break; + } + return kc; +} + +static inline int +do_kdgkb_ioctl(int cmd, struct kbsentry *user_kdgkb, int perm) +{ + struct kbsentry tmp; + char *p; + u_char *q; + int sz; + int delta; + char *first_free, *fj, *fnw; + int i, j, k; + + /* we mostly copy too much here (512bytes), but who cares ;) */ + if (copy_from_user(&tmp, user_kdgkb, sizeof(struct kbsentry))) + return -EFAULT; + tmp.kb_string[sizeof(tmp.kb_string)-1] = '\0'; + if (tmp.kb_func >= MAX_NR_FUNC) + return -EINVAL; + i = tmp.kb_func; + + switch (cmd) { + case KDGKBSENT: + sz = sizeof(tmp.kb_string) - 1; /* sz should have been + a struct member */ + q = user_kdgkb->kb_string; + p = func_table[i]; + if(p) + for ( ; *p && sz; p++, sz--) + __put_user(*p, q++); + __put_user('\0', q); + return ((p && *p) ? -EOVERFLOW : 0); + case KDSKBSENT: + if (!perm) + return -EPERM; + + q = func_table[i]; + first_free = funcbufptr + (funcbufsize - funcbufleft); + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) + ; + if (j < MAX_NR_FUNC) + fj = func_table[j]; + else + fj = first_free; + + delta = (q ? -strlen(q) : 1) + strlen(tmp.kb_string); + if (delta <= funcbufleft) { /* it fits in current buf */ + if (j < MAX_NR_FUNC) { + memmove(fj + delta, fj, first_free - fj); + for (k = j; k < MAX_NR_FUNC; k++) + if (func_table[k]) + func_table[k] += delta; + } + if (!q) + func_table[i] = fj; + funcbufleft -= delta; + } else { /* allocate a larger buffer */ + sz = 256; + while (sz < funcbufsize - funcbufleft + delta) + sz <<= 1; + fnw = (char *) kmalloc(sz, GFP_KERNEL); + if(!fnw) + return -ENOMEM; + + if (!q) + func_table[i] = fj; + if (fj > funcbufptr) + memmove(fnw, funcbufptr, fj - funcbufptr); + for (k = 0; k < j; k++) + if (func_table[k]) + func_table[k] = fnw + (func_table[k] - funcbufptr); + + if (first_free > fj) { + memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj); + for (k = j; k < MAX_NR_FUNC; k++) + if (func_table[k]) + func_table[k] = fnw + (func_table[k] - funcbufptr) + delta; + } + if (funcbufptr != func_buf) + kfree_s(funcbufptr, funcbufsize); + funcbufptr = fnw; + funcbufleft = funcbufleft - delta + sz - funcbufsize; + funcbufsize = sz; + } + strcpy(func_table[i], tmp.kb_string); + break; + } + return 0; +} + +static inline int +do_fontx_ioctl(int cmd, struct consolefontdesc *user_cfd, int perm) +{ + int nchar; + struct consolefontdesc cfdarg; + int i = 0; + + if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc))) + return -EFAULT; + if (vt_cons[fg_console]->vc_mode != KD_TEXT) + return -EINVAL; + + switch (cmd) { + case PIO_FONTX: + if (!perm) + return -EPERM; + if ( cfdarg.charcount == 256 || + cfdarg.charcount == 512 ) { + i = con_set_font(cfdarg.chardata, + cfdarg.charcount == 512); + if (i) + return i; + i = con_adjust_height(cfdarg.charheight); + return (i <= 0) ? i : kd_size_changed(i, 0); + } else + return -EINVAL; + case GIO_FONTX: + i = cfdarg.charcount; + cfdarg.charcount = nchar = video_mode_512ch ? 512 : 256; + cfdarg.charheight = video_font_height; + __copy_to_user(user_cfd, &cfdarg, + sizeof(struct consolefontdesc)); + if ( cfdarg.chardata ) + { + if ( i < nchar ) + return -ENOMEM; + return con_get_font(cfdarg.chardata); + } else + return 0; + } + return 0; +} + +static inline int +do_unimap_ioctl(int cmd, struct unimapdesc *user_ud,int perm) +{ + struct unimapdesc tmp; + int i = 0; + + if (copy_from_user(&tmp, user_ud, sizeof tmp)) + return -EFAULT; + if (tmp.entries) { + i = verify_area(VERIFY_WRITE, tmp.entries, + tmp.entry_ct*sizeof(struct unipair)); + if (i) return i; + } + switch (cmd) { + case PIO_UNIMAP: + if (!perm) + return -EPERM; + return con_set_unimap(tmp.entry_ct, tmp.entries); + case GIO_UNIMAP: + return con_get_unimap(tmp.entry_ct, &(user_ud->entry_ct), tmp.entries); + } + return 0; +} + /* * We handle the console-specific ioctl's here. We allow the * capability to modify any console, not just the fg_console. @@ -219,7 +487,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, perm = 0; if (current->tty == tty || suser()) perm = 1; - + kbd = kbd_table + console; switch (cmd) { case KIOCSOUND: @@ -251,10 +519,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, /* * this is naive. */ - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned char)); - if (!i) - put_user(KB_101, (char *) arg); - return i; + ucval = KB_101; + goto setchar; #ifndef __alpha__ /* @@ -311,10 +577,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, return 0; case KDGETMODE: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(int)); - if (!i) - put_user(vt_cons[console]->vc_mode, (int *) arg); - return i; + ucval = vt_cons[console]->vc_mode; + goto setint; case KDMAPDISP: case KDUNMAPDISP: @@ -350,15 +614,11 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, return 0; case KDGKBMODE: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(int)); - if (!i) { - ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW : + ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW : (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW : (kbd->kbdmode == VC_UNICODE) ? K_UNICODE : K_XLATE); - put_user(ucval, (int *) arg); - } - return i; + goto setint; /* this could be folded into KDSKBMODE, but for compatibility reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */ @@ -376,253 +636,21 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, return 0; case KDGKBMETA: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(int)); - if (!i) { - ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : - K_METABIT); - put_user(ucval, (int *) arg); - } - return i; + ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT); + setint: + return put_user(ucval, (int *)arg); case KDGETKEYCODE: - { - struct kbkeycode * const a = (struct kbkeycode *)arg; - unsigned int sc; - int kc; - - i = verify_area(VERIFY_WRITE, (void *)a, sizeof(struct kbkeycode)); - if (i) - return i; - get_user(sc, &a->scancode); - kc = getkeycode(sc); - if (kc < 0) - return kc; - put_user(kc, &a->keycode); - return 0; - } - case KDSETKEYCODE: - { - struct kbkeycode * const a = (struct kbkeycode *)arg; - unsigned int sc, kc; - - if (!perm) - return -EPERM; - i = verify_area(VERIFY_READ, (void *)a, sizeof(struct kbkeycode)); - if (i) - return i; - get_user(sc, &a->scancode); - get_user(kc, &a->keycode); - return setkeycode(sc, kc); - } + return do_kbkeycode_ioctl(cmd, (struct kbkeycode *)arg, perm); case KDGKBENT: - { - struct kbentry * const a = (struct kbentry *)arg; - ushort *key_map, val; - u_char s; - - i = verify_area(VERIFY_WRITE, (void *)a, sizeof(struct kbentry)); - if (i) - return i; - get_user(i, &a->kb_index); - if (i >= NR_KEYS) - return -EINVAL; - get_user(s, &a->kb_table); - if (s >= MAX_NR_KEYMAPS) - return -EINVAL; - key_map = key_maps[s]; - if (key_map) { - val = U(key_map[i]); - if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES) - val = K_HOLE; - } else - val = (i ? K_HOLE : K_NOSUCHMAP); - put_user(val, &a->kb_value); - return 0; - } - case KDSKBENT: - { - const struct kbentry * a = (struct kbentry *)arg; - ushort *key_map; - u_char s; - u_short v, ov; - - if (!perm) - return -EPERM; - i = verify_area(VERIFY_READ, (const void *)a, sizeof(struct kbentry)); - if (i) - return i; - get_user(i, &a->kb_index); - if (i >= NR_KEYS) - return -EINVAL; - get_user(s, &a->kb_table); - if (s >= MAX_NR_KEYMAPS) - return -EINVAL; - get_user(v, &a->kb_value); - if (!i && v == K_NOSUCHMAP) { - /* disallocate map */ - key_map = key_maps[s]; - if (s && key_map) { - key_maps[s] = 0; - if (key_map[0] == U(K_ALLOCATED)) { - kfree_s(key_map, sizeof(plain_map)); - keymap_count--; - } - } - return 0; - } - - if (KTYP(v) < NR_TYPES) { - if (KVAL(v) > max_vals[KTYP(v)]) - return -EINVAL; - } else - if (kbd->kbdmode != VC_UNICODE) - return -EINVAL; - - /* assignment to entry 0 only tests validity of args */ - if (!i) - return 0; - - if (!(key_map = key_maps[s])) { - int j; - - if (keymap_count >= MAX_NR_OF_USER_KEYMAPS && !suser()) - return -EPERM; - - key_map = (ushort *) kmalloc(sizeof(plain_map), - GFP_KERNEL); - if (!key_map) - return -ENOMEM; - key_maps[s] = key_map; - key_map[0] = U(K_ALLOCATED); - for (j = 1; j < NR_KEYS; j++) - key_map[j] = U(K_HOLE); - keymap_count++; - } - ov = U(key_map[i]); - if (v == ov) - return 0; /* nothing to do */ - /* - * Only the Superuser can set or unset the Secure - * Attention Key. - */ - if (((ov == K_SAK) || (v == K_SAK)) && !suser()) - return -EPERM; - key_map[i] = U(v); - if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT)) - compute_shiftstate(); - return 0; - } + return do_kdsk_ioctl(cmd, (struct kbentry *)arg, perm, kbd); case KDGKBSENT: - { - struct kbsentry *a = (struct kbsentry *)arg; - char *p; - u_char *q; - int sz; - - i = verify_area(VERIFY_WRITE, (void *)a, sizeof(struct kbsentry)); - if (i) - return i; - get_user(i, &a->kb_func); - if (i >= MAX_NR_FUNC || i < 0) - return -EINVAL; - sz = sizeof(a->kb_string) - 1; /* sz should have been - a struct member */ - q = a->kb_string; - p = func_table[i]; - if(p) - for ( ; *p && sz; p++, sz--) - put_user(*p, q++); - put_user('\0', q); - return ((p && *p) ? -EOVERFLOW : 0); - } - case KDSKBSENT: - { - struct kbsentry * const a = (struct kbsentry *)arg; - int delta; - char *first_free, *fj, *fnw; - int j, k, sz; - u_char *p; - char *q; - - if (!perm) - return -EPERM; - i = verify_area(VERIFY_READ, (void *)a, sizeof(struct kbsentry)); - if (i) - return i; - get_user(i, &a->kb_func); - if (i >= MAX_NR_FUNC) - return -EINVAL; - q = func_table[i]; - - first_free = funcbufptr + (funcbufsize - funcbufleft); - for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) ; - if (j < MAX_NR_FUNC) - fj = func_table[j]; - else - fj = first_free; - - delta = (q ? -strlen(q) : 1); - sz = sizeof(a->kb_string); /* sz should have been - a struct member */ - for (p = a->kb_string; sz; p++,sz--) { - unsigned char uc; - get_user(uc, p); - if (!uc) - break; - delta++; - } - if (!sz) - return -EOVERFLOW; - if (delta <= funcbufleft) { /* it fits in current buf */ - if (j < MAX_NR_FUNC) { - memmove(fj + delta, fj, first_free - fj); - for (k = j; k < MAX_NR_FUNC; k++) - if (func_table[k]) - func_table[k] += delta; - } - if (!q) - func_table[i] = fj; - funcbufleft -= delta; - } else { /* allocate a larger buffer */ - sz = 256; - while (sz < funcbufsize - funcbufleft + delta) - sz <<= 1; - fnw = (char *) kmalloc(sz, GFP_KERNEL); - if(!fnw) - return -ENOMEM; - - if (!q) - func_table[i] = fj; - if (fj > funcbufptr) - memmove(fnw, funcbufptr, fj - funcbufptr); - for (k = 0; k < j; k++) - if (func_table[k]) - func_table[k] = fnw + (func_table[k] - funcbufptr); - - if (first_free > fj) { - memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj); - for (k = j; k < MAX_NR_FUNC; k++) - if (func_table[k]) - func_table[k] = fnw + (func_table[k] - funcbufptr) + delta; - } - if (funcbufptr != func_buf) - kfree_s(funcbufptr, funcbufsize); - funcbufptr = fnw; - funcbufleft = funcbufleft - delta + sz - funcbufsize; - funcbufsize = sz; - } - for (p = a->kb_string, q = func_table[i]; ; p++, q++) { - get_user(*q, p); - if (!*q) - break; - } - return 0; - } + return do_kdgkb_ioctl(cmd, (struct kbsentry *)arg, perm); case KDGKBDIACR: { @@ -631,8 +659,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, i = verify_area(VERIFY_WRITE, (void *) a, sizeof(struct kbdiacrs)); if (i) return i; - put_user(accent_table_size, &a->kb_cnt); - copy_to_user(a->kbdiacr, accent_table, + __put_user(accent_table_size, &a->kb_cnt); + __copy_to_user(a->kbdiacr, accent_table, accent_table_size*sizeof(struct kbdiacr)); return 0; } @@ -647,23 +675,19 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, i = verify_area(VERIFY_READ, (void *) a, sizeof(struct kbdiacrs)); if (i) return i; - get_user(ct,&a->kb_cnt); + __get_user(ct,&a->kb_cnt); if (ct >= MAX_DIACR) return -EINVAL; accent_table_size = ct; - copy_from_user(accent_table, a->kbdiacr, ct*sizeof(struct kbdiacr)); + __copy_from_user(accent_table, a->kbdiacr, ct*sizeof(struct kbdiacr)); return 0; } /* the ioctls below read/set the flags usually shown in the leds */ /* don't use them - they will go away without warning */ case KDGKBLED: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned char)); - if (i) - return i; - put_user(kbd->ledflagstate | - (kbd->default_ledflagstate << 4), (char *) arg); - return 0; + ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4); + goto setchar; case KDSKBLED: if (!perm) @@ -678,11 +702,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, /* the ioctls below only set the lights, not the functions */ /* for those, see KDGKBLED and KDSKBLED above */ case KDGETLED: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned char)); - if (i) - return i; - put_user(getledstate(), (char *) arg); - return 0; + ucval = getledstate(); + setchar: + return put_user(ucval, (char*)arg); case KDSETLED: if (!perm) @@ -714,21 +736,15 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, case VT_SETMODE: { - struct vt_mode *vtmode = (struct vt_mode *)arg; - char mode; + struct vt_mode tmp; if (!perm) return -EPERM; - i = verify_area(VERIFY_READ, (void *)vtmode, sizeof(struct vt_mode)); - if (i) - return i; - get_user(mode, &vtmode->mode); - if (mode != VT_AUTO && mode != VT_PROCESS) + if (copy_from_user(&tmp, (void*)arg, sizeof(struct vt_mode))) + return -EFAULT; + if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) return -EINVAL; - vt_cons[console]->vt_mode.mode = mode; - get_user(vt_cons[console]->vt_mode.waitv, &vtmode->waitv); - get_user(vt_cons[console]->vt_mode.relsig, &vtmode->relsig); - get_user(vt_cons[console]->vt_mode.acqsig, &vtmode->acqsig); + vt_cons[console]->vt_mode = tmp; /* the frsig is ignored, so we set it to 0 */ vt_cons[console]->vt_mode.frsig = 0; vt_cons[console]->vt_pid = current->pid; @@ -738,19 +754,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, } case VT_GETMODE: - { - struct vt_mode *vtmode = (struct vt_mode *)arg; - - i = verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct vt_mode)); - if (i) - return i; - put_user(vt_cons[console]->vt_mode.mode, &vtmode->mode); - put_user(vt_cons[console]->vt_mode.waitv, &vtmode->waitv); - put_user(vt_cons[console]->vt_mode.relsig, &vtmode->relsig); - put_user(vt_cons[console]->vt_mode.acqsig, &vtmode->acqsig); - put_user(vt_cons[console]->vt_mode.frsig, &vtmode->frsig); - return 0; - } + return copy_to_user((void*)arg, &(vt_cons[console]->vt_mode), + sizeof(struct vt_mode)) ? -EFAULT : 0; /* * Returns global vt state. Note that VT 0 is always open, since @@ -765,27 +770,23 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, i = verify_area(VERIFY_WRITE,(void *)vtstat, sizeof(struct vt_stat)); if (i) return i; - put_user(fg_console + 1, &vtstat->v_active); + __put_user(fg_console + 1, &vtstat->v_active); state = 1; /* /dev/tty0 is always open */ for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask; ++i, mask <<= 1) if (VT_IS_IN_USE(i)) state |= mask; - put_user(state, &vtstat->v_state); - return 0; + return __put_user(state, &vtstat->v_state); } /* * Returns the first available (non-opened) console. */ case VT_OPENQRY: - i = verify_area(VERIFY_WRITE, (void *) arg, sizeof(int)); - if (i) - return i; for (i = 0; i < MAX_NR_CONSOLES; ++i) if (! VT_IS_IN_USE(i)) break; - put_user(i < MAX_NR_CONSOLES ? (i+1) : -1, (int *) arg); - return 0; + ucval = i < MAX_NR_CONSOLES ? (i+1) : -1; + goto setint; /* * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num, @@ -812,13 +813,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, return -EPERM; if (arg == 0 || arg > MAX_NR_CONSOLES) return -ENXIO; - arg--; - while (fg_console != arg) - { - if (vt_waitactive() < 0) - return -EINTR; - } - return 0; + return vt_waitactive(arg-1); /* * If a vt is under process control, the kernel will not switch to it @@ -914,8 +909,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, i = verify_area(VERIFY_READ, (void *)vtsizes, sizeof(struct vt_sizes)); if (i) return i; - get_user(ll, &vtsizes->v_rows); - get_user(cc, &vtsizes->v_cols); + __get_user(ll, &vtsizes->v_rows); + __get_user(cc, &vtsizes->v_cols); i = vc_resize(ll, cc); return i ? i : kd_size_changed(ll, cc); } @@ -929,19 +924,19 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, i = verify_area(VERIFY_READ, (void *)vtconsize, sizeof(struct vt_consize)); if (i) return i; - get_user(ll, &vtconsize->v_rows); - get_user(cc, &vtconsize->v_cols); - get_user(vlin, &vtconsize->v_vlin); - get_user(clin, &vtconsize->v_clin); - get_user(vcol, &vtconsize->v_vcol); - get_user(ccol, &vtconsize->v_ccol); + __get_user(ll, &vtconsize->v_rows); + __get_user(cc, &vtconsize->v_cols); + __get_user(vlin, &vtconsize->v_vlin); + __get_user(clin, &vtconsize->v_clin); + __get_user(vcol, &vtconsize->v_vcol); + __get_user(ccol, &vtconsize->v_ccol); vlin = vlin ? vlin : video_scan_lines; if ( clin ) { if ( ll ) { if ( ll != vlin/clin ) - return EINVAL; /* Parameters don't add up */ + return -EINVAL; /* Parameters don't add up */ } else ll = vlin/clin; @@ -951,14 +946,14 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, if ( cc ) { if ( cc != vcol/ccol ) - return EINVAL; + return -EINVAL; } else cc = vcol/ccol; } if ( clin > 32 ) - return EINVAL; + return -EINVAL; if ( vlin ) video_scan_lines = vlin; @@ -999,30 +994,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, /* con_get_cmap() defined in console.c */ case PIO_FONTX: - { - struct consolefontdesc cfdarg; - - if (!perm) - return -EPERM; - if (vt_cons[fg_console]->vc_mode != KD_TEXT) - return -EINVAL; - i = verify_area(VERIFY_READ, (void *)arg, - sizeof(struct consolefontdesc)); - if (i) return i; - copy_from_user(&cfdarg, (void *)arg, - sizeof(struct consolefontdesc)); - - if ( cfdarg.charcount == 256 || - cfdarg.charcount == 512 ) { - i = con_set_font(cfdarg.chardata, - cfdarg.charcount == 512); - if (i) - return i; - i = con_adjust_height(cfdarg.charheight); - return (i <= 0) ? i : kd_size_changed(i, 0); - } else - return -EINVAL; - } + case GIO_FONTX: + return do_fontx_ioctl(cmd, (struct consolefontdesc *)arg, perm); case PIO_FONTRESET: { @@ -1048,32 +1021,6 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, #endif } - case GIO_FONTX: - { - struct consolefontdesc cfdarg; - int nchar; - - if (vt_cons[fg_console]->vc_mode != KD_TEXT) - return -EINVAL; - i = verify_area(VERIFY_WRITE, (void *)arg, - sizeof(struct consolefontdesc)); - if (i) return i; - copy_from_user(&cfdarg, (void *) arg, - sizeof(struct consolefontdesc)); - i = cfdarg.charcount; - cfdarg.charcount = nchar = video_mode_512ch ? 512 : 256; - cfdarg.charheight = video_font_height; - copy_to_user((void *) arg, &cfdarg, - sizeof(struct consolefontdesc)); - if ( cfdarg.chardata ) - { - if ( i < nchar ) - return -ENOMEM; - return con_get_font(cfdarg.chardata); - } else - return 0; - } - case PIO_SCRNMAP: if (!perm) return -EPERM; @@ -1094,52 +1041,16 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, { struct unimapinit ui; if (!perm) return -EPERM; - i = verify_area(VERIFY_READ, (void *)arg, sizeof(struct unimapinit)); - if (i) - return i; - copy_from_user(&ui, (void *)arg, sizeof(struct unimapinit)); + i = copy_from_user(&ui, (void *)arg, sizeof(struct unimapinit)); + if (i) return -EFAULT; con_clear_unimap(&ui); return 0; } case PIO_UNIMAP: - { struct unimapdesc *ud; - u_short ct; - struct unipair *list; - - if (!perm) - return -EPERM; - i = verify_area(VERIFY_READ, (void *)arg, sizeof(struct unimapdesc)); - if (i == 0) { - ud = (struct unimapdesc *) arg; - get_user(ct, &ud->entry_ct); - get_user(list, &ud->entries); - i = verify_area(VERIFY_READ, (void *) list, - ct*sizeof(struct unipair)); - } - if (i) - return i; - return con_set_unimap(ct, list); - } - case GIO_UNIMAP: - { struct unimapdesc *ud; - u_short ct; - struct unipair *list; - - i = verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct unimapdesc)); - if (i == 0) { - ud = (struct unimapdesc *) arg; - get_user(ct, &ud->entry_ct); - get_user(list, &ud->entries); - if (ct) - i = verify_area(VERIFY_WRITE, (void *) list, - ct*sizeof(struct unipair)); - } - if (i) - return i; - return con_get_unimap(ct, &(ud->entry_ct), list); - } + return do_unimap_ioctl(cmd, (struct unimapdesc *)arg, perm); + case VT_LOCKSWITCH: if (!suser()) return -EPERM; @@ -1154,3 +1065,216 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, return -ENOIOCTLCMD; } } + +/* + * Sometimes we want to wait until a particular VT has been activated. We + * do it in a very simple manner. Everybody waits on a single queue and + * get woken up at once. Those that are satisfied go on with their business, + * while those not ready go back to sleep. Seems overkill to add a wait + * to each vt just for this - usually this does nothing! + */ +static struct wait_queue *vt_activate_queue = NULL; + +/* + * Sleeps until a vt is activated, or the task is interrupted. Returns + * 0 if activation, -EINTR if interrupted. + */ +int vt_waitactive(int vt) +{ + int retval; + struct wait_queue wait = { current, NULL }; + + add_wait_queue(&vt_activate_queue, &wait); + for (;;) { + current->state = TASK_INTERRUPTIBLE; + retval = 0; + if (vt == fg_console) + break; + retval = -EINTR; + if (current->signal & ~current->blocked) + break; + schedule(); + } + remove_wait_queue(&vt_activate_queue, &wait); + current->state = TASK_RUNNING; + return retval; +} + +#define vt_wake_waitactive() wake_up(&vt_activate_queue) + +void reset_vc(unsigned int new_console) +{ + vt_cons[new_console]->vc_mode = KD_TEXT; + kbd_table[new_console].kbdmode = VC_XLATE; + vt_cons[new_console]->vt_mode.mode = VT_AUTO; + vt_cons[new_console]->vt_mode.waitv = 0; + vt_cons[new_console]->vt_mode.relsig = 0; + vt_cons[new_console]->vt_mode.acqsig = 0; + vt_cons[new_console]->vt_mode.frsig = 0; + vt_cons[new_console]->vt_pid = -1; + vt_cons[new_console]->vt_newvt = -1; + reset_palette (new_console) ; +} + +/* + * Performs the back end of a vt switch + */ +void complete_change_console(unsigned int new_console) +{ + unsigned char old_vc_mode; + + if ((new_console == fg_console) || (vt_dont_switch)) + return; + if (!vc_cons_allocated(new_console)) + return; + last_console = fg_console; + + /* + * If we're switching, we could be going from KD_GRAPHICS to + * KD_TEXT mode or vice versa, which means we need to blank or + * unblank the screen later. + */ + old_vc_mode = vt_cons[fg_console]->vc_mode; + update_screen(new_console); + + /* + * If this new console is under process control, send it a signal + * telling it that it has acquired. Also check if it has died and + * clean up (similar to logic employed in change_console()) + */ + if (vt_cons[new_console]->vt_mode.mode == VT_PROCESS) + { + /* + * Send the signal as privileged - kill_proc() will + * tell us if the process has gone or something else + * is awry + */ + if (kill_proc(vt_cons[new_console]->vt_pid, + vt_cons[new_console]->vt_mode.acqsig, + 1) != 0) + { + /* + * The controlling process has died, so we revert back to + * normal operation. In this case, we'll also change back + * to KD_TEXT mode. I'm not sure if this is strictly correct + * but it saves the agony when the X server dies and the screen + * remains blanked due to KD_GRAPHICS! It would be nice to do + * this outside of VT_PROCESS but there is no single process + * to account for and tracking tty count may be undesirable. + */ + reset_vc(new_console); + } + } + + /* + * We do this here because the controlling process above may have + * gone, and so there is now a new vc_mode + */ + if (old_vc_mode != vt_cons[new_console]->vc_mode) + { + if (vt_cons[new_console]->vc_mode == KD_TEXT) + do_unblank_screen(); + else + do_blank_screen(1); + } + + /* Set the colour palette for this VT */ + if (vt_cons[new_console]->vc_mode == KD_TEXT) + set_palette() ; + +#ifdef CONFIG_SUN_CONSOLE + if (old_vc_mode != vt_cons[new_console]->vc_mode) + { + extern void set_cursor(int currcons); + extern void hide_cursor(void); + + if (old_vc_mode == KD_GRAPHICS) + { + extern void sun_clear_margin(void); + extern void render_screen(void); + + sun_clear_margin(); + render_screen(); + set_cursor(fg_console); + } + else + hide_cursor(); + } +#endif + /* + * Wake anyone waiting for their VT to activate + */ + vt_wake_waitactive(); + return; +} + +/* + * Performs the front-end of a vt switch + */ +void change_console(unsigned int new_console) +{ + if ((new_console == fg_console) || (vt_dont_switch)) + return; + if (!vc_cons_allocated(new_console)) + return; + + /* + * If this vt is in process mode, then we need to handshake with + * that process before switching. Essentially, we store where that + * vt wants to switch to and wait for it to tell us when it's done + * (via VT_RELDISP ioctl). + * + * We also check to see if the controlling process still exists. + * If it doesn't, we reset this vt to auto mode and continue. + * This is a cheap way to track process control. The worst thing + * that can happen is: we send a signal to a process, it dies, and + * the switch gets "lost" waiting for a response; hopefully, the + * user will try again, we'll detect the process is gone (unless + * the user waits just the right amount of time :-) and revert the + * vt to auto control. + */ + if (vt_cons[fg_console]->vt_mode.mode == VT_PROCESS) + { + /* + * Send the signal as privileged - kill_proc() will + * tell us if the process has gone or something else + * is awry + */ + if (kill_proc(vt_cons[fg_console]->vt_pid, + vt_cons[fg_console]->vt_mode.relsig, + 1) == 0) + { + /* + * It worked. Mark the vt to switch to and + * return. The process needs to send us a + * VT_RELDISP ioctl to complete the switch. + */ + vt_cons[fg_console]->vt_newvt = new_console; + return; + } + + /* + * The controlling process has died, so we revert back to + * normal operation. In this case, we'll also change back + * to KD_TEXT mode. I'm not sure if this is strictly correct + * but it saves the agony when the X server dies and the screen + * remains blanked due to KD_GRAPHICS! It would be nice to do + * this outside of VT_PROCESS but there is no single process + * to account for and tracking tty count may be undesirable. + */ + reset_vc(fg_console); + + /* + * Fall through to normal (VT_AUTO) handling of the switch... + */ + } + + /* + * Ignore all switches in KD_GRAPHICS+VT_AUTO mode + */ + if (vt_cons[fg_console]->vc_mode == KD_GRAPHICS) + return; + + complete_change_console(new_console); +} + |