selection.c (3eb66e91a25497065c5322b1268cbc3953642227) selection.c (496124e5e16e4974c71404bc9ddaa016156f8cb0)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * This module exports the functions:
4 *
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * This module exports the functions:
4 *
5 * 'int set_selection(struct tiocl_selection __user *, struct tty_struct *)'
5 * 'int set_selection_user(struct tiocl_selection __user *,
6 * struct tty_struct *)'
7 * 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)'
6 * 'void clear_selection(void)'
7 * 'int paste_selection(struct tty_struct *)'
8 * 'int sel_loadlut(char __user *)'
9 *
10 * Now that /dev/vcs exists, most of this can disappear again.
11 */
12
13#include <linux/module.h>

--- 61 unchanged lines hidden (view full) ---

75void clear_selection(void)
76{
77 highlight_pointer(-1); /* hide the pointer */
78 if (sel_start != -1) {
79 highlight(sel_start, sel_end);
80 sel_start = -1;
81 }
82}
8 * 'void clear_selection(void)'
9 * 'int paste_selection(struct tty_struct *)'
10 * 'int sel_loadlut(char __user *)'
11 *
12 * Now that /dev/vcs exists, most of this can disappear again.
13 */
14
15#include <linux/module.h>

--- 61 unchanged lines hidden (view full) ---

77void clear_selection(void)
78{
79 highlight_pointer(-1); /* hide the pointer */
80 if (sel_start != -1) {
81 highlight(sel_start, sel_end);
82 sel_start = -1;
83 }
84}
85EXPORT_SYMBOL_GPL(clear_selection);
83
84/*
85 * User settable table: what characters are to be considered alphabetic?
86 * 128 bits. Locked by the console lock.
87 */
88static u32 inwordLut[]={
89 0x00000000, /* control chars */
90 0x03FFE000, /* digits and "-./" */

--- 58 unchanged lines hidden (view full) ---

149 p[0] = 0xef;
150 p[1] = 0xbf;
151 p[2] = 0xbd;
152 return 3;
153 }
154}
155
156/**
86
87/*
88 * User settable table: what characters are to be considered alphabetic?
89 * 128 bits. Locked by the console lock.
90 */
91static u32 inwordLut[]={
92 0x00000000, /* control chars */
93 0x03FFE000, /* digits and "-./" */

--- 58 unchanged lines hidden (view full) ---

152 p[0] = 0xef;
153 p[1] = 0xbf;
154 p[2] = 0xbd;
155 return 3;
156 }
157}
158
159/**
157 * set_selection - set the current selection.
160 * set_selection_user - set the current selection.
158 * @sel: user selection info
159 * @tty: the console tty
160 *
161 * Invoked by the ioctl handle for the vt layer.
162 *
163 * The entire selection process is managed under the console_lock. It's
164 * a lot under the lock but its hardly a performance path
165 */
161 * @sel: user selection info
162 * @tty: the console tty
163 *
164 * Invoked by the ioctl handle for the vt layer.
165 *
166 * The entire selection process is managed under the console_lock. It's
167 * a lot under the lock but its hardly a performance path
168 */
166int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty)
169int set_selection_user(const struct tiocl_selection __user *sel,
170 struct tty_struct *tty)
167{
171{
172 struct tiocl_selection v;
173
174 if (copy_from_user(&v, sel, sizeof(*sel)))
175 return -EFAULT;
176
177 return set_selection_kernel(&v, tty);
178}
179
180int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
181{
168 struct vc_data *vc = vc_cons[fg_console].d;
169 int new_sel_start, new_sel_end, spc;
182 struct vc_data *vc = vc_cons[fg_console].d;
183 int new_sel_start, new_sel_end, spc;
170 struct tiocl_selection v;
171 char *bp, *obp;
172 int i, ps, pe, multiplier;
173 u32 c;
174 int mode;
175
176 poke_blanked_console();
184 char *bp, *obp;
185 int i, ps, pe, multiplier;
186 u32 c;
187 int mode;
188
189 poke_blanked_console();
177 if (copy_from_user(&v, sel, sizeof(*sel)))
178 return -EFAULT;
179
190
180 v.xs = min_t(u16, v.xs - 1, vc->vc_cols - 1);
181 v.ys = min_t(u16, v.ys - 1, vc->vc_rows - 1);
182 v.xe = min_t(u16, v.xe - 1, vc->vc_cols - 1);
183 v.ye = min_t(u16, v.ye - 1, vc->vc_rows - 1);
184 ps = v.ys * vc->vc_size_row + (v.xs << 1);
185 pe = v.ye * vc->vc_size_row + (v.xe << 1);
191 v->xs = min_t(u16, v->xs - 1, vc->vc_cols - 1);
192 v->ys = min_t(u16, v->ys - 1, vc->vc_rows - 1);
193 v->xe = min_t(u16, v->xe - 1, vc->vc_cols - 1);
194 v->ye = min_t(u16, v->ye - 1, vc->vc_rows - 1);
195 ps = v->ys * vc->vc_size_row + (v->xs << 1);
196 pe = v->ye * vc->vc_size_row + (v->xe << 1);
186
197
187 if (v.sel_mode == TIOCL_SELCLEAR) {
198 if (v->sel_mode == TIOCL_SELCLEAR) {
188 /* useful for screendump without selection highlights */
189 clear_selection();
190 return 0;
191 }
192
199 /* useful for screendump without selection highlights */
200 clear_selection();
201 return 0;
202 }
203
193 if (mouse_reporting() && (v.sel_mode & TIOCL_SELMOUSEREPORT)) {
194 mouse_report(tty, v.sel_mode & TIOCL_SELBUTTONMASK, v.xs, v.ys);
204 if (mouse_reporting() && (v->sel_mode & TIOCL_SELMOUSEREPORT)) {
205 mouse_report(tty, v->sel_mode & TIOCL_SELBUTTONMASK, v->xs,
206 v->ys);
195 return 0;
196 }
197
198 if (ps > pe) /* make sel_start <= sel_end */
199 swap(ps, pe);
200
201 if (sel_cons != vc_cons[fg_console].d) {
202 clear_selection();
203 sel_cons = vc_cons[fg_console].d;
204 }
205 mode = vt_do_kdgkbmode(fg_console);
206 if (mode == K_UNICODE)
207 use_unicode = 1;
208 else
209 use_unicode = 0;
210
207 return 0;
208 }
209
210 if (ps > pe) /* make sel_start <= sel_end */
211 swap(ps, pe);
212
213 if (sel_cons != vc_cons[fg_console].d) {
214 clear_selection();
215 sel_cons = vc_cons[fg_console].d;
216 }
217 mode = vt_do_kdgkbmode(fg_console);
218 if (mode == K_UNICODE)
219 use_unicode = 1;
220 else
221 use_unicode = 0;
222
211 switch (v.sel_mode)
223 switch (v->sel_mode)
212 {
213 case TIOCL_SELCHAR: /* character-by-character selection */
214 new_sel_start = ps;
215 new_sel_end = pe;
216 break;
217 case TIOCL_SELWORD: /* word-by-word selection */
218 spc = isspace(sel_pos(ps));
219 for (new_sel_start = ps; ; ps -= 2)

--- 97 unchanged lines hidden (view full) ---

317 *bp++ = '\r';
318 }
319 obp = bp;
320 }
321 }
322 sel_buffer_lth = bp - sel_buffer;
323 return 0;
324}
224 {
225 case TIOCL_SELCHAR: /* character-by-character selection */
226 new_sel_start = ps;
227 new_sel_end = pe;
228 break;
229 case TIOCL_SELWORD: /* word-by-word selection */
230 spc = isspace(sel_pos(ps));
231 for (new_sel_start = ps; ; ps -= 2)

--- 97 unchanged lines hidden (view full) ---

329 *bp++ = '\r';
330 }
331 obp = bp;
332 }
333 }
334 sel_buffer_lth = bp - sel_buffer;
335 return 0;
336}
337EXPORT_SYMBOL_GPL(set_selection_kernel);
325
326/* Insert the contents of the selection buffer into the
327 * queue of the tty associated with the current console.
328 * Invoked by ioctl().
329 *
330 * Locking: called without locks. Calls the ldisc wrongly with
331 * unsafe methods,
332 */

--- 29 unchanged lines hidden (view full) ---

362 }
363 remove_wait_queue(&vc->paste_wait, &wait);
364 __set_current_state(TASK_RUNNING);
365
366 tty_buffer_unlock_exclusive(&vc->port);
367 tty_ldisc_deref(ld);
368 return 0;
369}
338
339/* Insert the contents of the selection buffer into the
340 * queue of the tty associated with the current console.
341 * Invoked by ioctl().
342 *
343 * Locking: called without locks. Calls the ldisc wrongly with
344 * unsafe methods,
345 */

--- 29 unchanged lines hidden (view full) ---

375 }
376 remove_wait_queue(&vc->paste_wait, &wait);
377 __set_current_state(TASK_RUNNING);
378
379 tty_buffer_unlock_exclusive(&vc->port);
380 tty_ldisc_deref(ld);
381 return 0;
382}
383EXPORT_SYMBOL_GPL(paste_selection);