Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_GENERIC_TERMIOS_H
0003 #define _ASM_GENERIC_TERMIOS_H
0004 
0005 
0006 #include <linux/uaccess.h>
0007 #include <uapi/asm-generic/termios.h>
0008 
0009 /*  intr=^C     quit=^\     erase=del   kill=^U
0010     eof=^D      vtime=\0    vmin=\1     sxtc=\0
0011     start=^Q    stop=^S     susp=^Z     eol=\0
0012     reprint=^R  discard=^U  werase=^W   lnext=^V
0013     eol2=\0
0014 */
0015 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
0016 
0017 /*
0018  * Translate a "termio" structure into a "termios". Ugh.
0019  */
0020 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
0021                         const struct termio __user *termio)
0022 {
0023     unsigned short tmp;
0024 
0025     if (get_user(tmp, &termio->c_iflag) < 0)
0026         goto fault;
0027     termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
0028 
0029     if (get_user(tmp, &termio->c_oflag) < 0)
0030         goto fault;
0031     termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
0032 
0033     if (get_user(tmp, &termio->c_cflag) < 0)
0034         goto fault;
0035     termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
0036 
0037     if (get_user(tmp, &termio->c_lflag) < 0)
0038         goto fault;
0039     termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
0040 
0041     if (get_user(termios->c_line, &termio->c_line) < 0)
0042         goto fault;
0043 
0044     if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
0045         goto fault;
0046 
0047     return 0;
0048 
0049  fault:
0050     return -EFAULT;
0051 }
0052 
0053 /*
0054  * Translate a "termios" structure into a "termio". Ugh.
0055  */
0056 static inline int kernel_termios_to_user_termio(struct termio __user *termio,
0057                         struct ktermios *termios)
0058 {
0059     if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
0060         put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
0061         put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
0062         put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
0063         put_user(termios->c_line,  &termio->c_line) < 0 ||
0064         copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
0065         return -EFAULT;
0066 
0067     return 0;
0068 }
0069 
0070 #ifdef TCGETS2
0071 static inline int user_termios_to_kernel_termios(struct ktermios *k,
0072                          struct termios2 __user *u)
0073 {
0074     return copy_from_user(k, u, sizeof(struct termios2));
0075 }
0076 
0077 static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
0078                          struct ktermios *k)
0079 {
0080     return copy_to_user(u, k, sizeof(struct termios2));
0081 }
0082 
0083 static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
0084                            struct termios __user *u)
0085 {
0086     return copy_from_user(k, u, sizeof(struct termios));
0087 }
0088 
0089 static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
0090                            struct ktermios *k)
0091 {
0092     return copy_to_user(u, k, sizeof(struct termios));
0093 }
0094 #else /* TCGETS2 */
0095 static inline int user_termios_to_kernel_termios(struct ktermios *k,
0096                          struct termios __user *u)
0097 {
0098     return copy_from_user(k, u, sizeof(struct termios));
0099 }
0100 
0101 static inline int kernel_termios_to_user_termios(struct termios __user *u,
0102                          struct ktermios *k)
0103 {
0104     return copy_to_user(u, k, sizeof(struct termios));
0105 }
0106 #endif /* TCGETS2 */
0107 
0108 #endif /* _ASM_GENERIC_TERMIOS_H */