mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 14:38:21 +00:00
kernel: usercopy functions
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <kernel/devfs.h>
|
||||
#include <string.h>
|
||||
#include <kernel/vmm.h>
|
||||
#include <kernel/usercopy.h>
|
||||
|
||||
#define DISK_READ(desc, buf, lba, size) (desc)->read(desc->private, buf, lba, size)
|
||||
#define DISK_WRITE(desc, buf, lba, size) (desc)->write(desc->private, buf, lba, size)
|
||||
@@ -140,10 +141,11 @@ static int ioctl(int minor, unsigned long request, void *arg, int *result) {
|
||||
|
||||
switch (request) {
|
||||
case BLOCK_IOCTL_GETDESC:
|
||||
*(blockdesc_t *)arg = *desc;
|
||||
((blockdesc_t *)arg)->write = NULL;
|
||||
((blockdesc_t *)arg)->read = NULL;
|
||||
((blockdesc_t *)arg)->private = NULL;
|
||||
blockdesc_t copy = *desc;
|
||||
copy.write = NULL;
|
||||
copy.read = NULL;
|
||||
copy.private = NULL;
|
||||
ret = USERCOPY_POSSIBLY_TO_USER(arg, ©, sizeof(blockdesc_t));
|
||||
break;
|
||||
default:
|
||||
ret = ENOTTY;
|
||||
|
||||
+3
-4
@@ -6,6 +6,7 @@
|
||||
#include <kernel/devfs.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <kernel/usercopy.h>
|
||||
|
||||
typedef struct bitfield_t {
|
||||
uint32_t offset;
|
||||
@@ -177,11 +178,9 @@ static int ioctl(int minor, unsigned long request, void *arg, int *result){
|
||||
case FBIOPUT_VSCREENINFO:
|
||||
break;
|
||||
case FBIOGET_FSCREENINFO:
|
||||
*(fixinfo_t *)arg = fixinfos[minor];
|
||||
break;
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, &fixinfos[minor], sizeof(fixinfo_t));
|
||||
case FBIOGET_VSCREENINFO:
|
||||
*(varinfo_t *)arg = varinfos[minor];
|
||||
break;
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, &varinfos[minor], sizeof(varinfo_t));
|
||||
default:
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
+3
-4
@@ -3,6 +3,7 @@
|
||||
#include <spinlock.h>
|
||||
#include <logging.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/usercopy.h>
|
||||
|
||||
#define PTY_BUFFER 4096
|
||||
#define PTY_MAX 1024
|
||||
@@ -198,12 +199,10 @@ static int ioctl(int minor, unsigned long request, void *_arg, int *result) {
|
||||
|
||||
switch (request) {
|
||||
case TIOCGPTN: {
|
||||
int *arg = _arg;
|
||||
*arg = pty->minor;
|
||||
break;
|
||||
return USERCOPY_POSSIBLY_TO_USER(_arg, &pty->minor, sizeof(int));
|
||||
}
|
||||
default:
|
||||
return tty_ioctl(pty->tty, request, _arg, result);
|
||||
return tty_ioctl(pty->tty, request, _arg, result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
+31
-25
@@ -3,6 +3,7 @@
|
||||
#include <logging.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/jobctl.h>
|
||||
#include <kernel/usercopy.h>
|
||||
|
||||
#define TTY_MAX_COUNT 4096
|
||||
#define CONTROLLING_TTY_MINOR TTY_MAX_COUNT
|
||||
@@ -300,14 +301,13 @@ static int poll(int minor, polldata_t *data, int events) {
|
||||
|
||||
int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
|
||||
switch (req) {
|
||||
case TIOCGWINSZ: {
|
||||
winsize_t *w = arg;
|
||||
*w = tty->winsize;
|
||||
break;
|
||||
}
|
||||
case TIOCGWINSZ:
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, &tty->winsize, sizeof(winsize_t));
|
||||
case TIOCSWINSZ: {
|
||||
winsize_t *w = arg;
|
||||
tty->winsize = *w;
|
||||
int e = USERCOPY_POSSIBLY_FROM_USER(&tty->winsize, arg, sizeof(winsize_t));
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
proc_t *foreground = getforeground(tty);
|
||||
if (foreground) {
|
||||
jobctl_signal(foreground, SIGWINCH);
|
||||
@@ -315,18 +315,22 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TCGETS: {
|
||||
*(termios_t *)arg = tty->termios;
|
||||
break;
|
||||
}
|
||||
case TCSETS: {
|
||||
tty->termios = *(termios_t *)arg;
|
||||
break;
|
||||
}
|
||||
case TCGETS:
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, &tty->termios, sizeof(termios_t));
|
||||
case TCSETS:
|
||||
return USERCOPY_POSSIBLY_FROM_USER(&tty->termios, arg, sizeof(termios_t));
|
||||
case TIOCSCTTY: {
|
||||
int *steal = arg;
|
||||
if (steal && *steal == 1)
|
||||
printf("tty: stealing not supported\n");
|
||||
if (arg) {
|
||||
int steal;
|
||||
int e = USERCOPY_POSSIBLY_FROM_USER(&steal, arg, sizeof(int));
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
if (steal == 1) {
|
||||
printf("tty: stealing not supported\n");
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
// set as controlling tty
|
||||
jobctl_setctty(_cpu()->thread->proc, tty);
|
||||
break;
|
||||
@@ -336,14 +340,17 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
|
||||
if (foreground == NULL)
|
||||
return ENOTTY;
|
||||
|
||||
int *pgrp = arg;
|
||||
*pgrp = foreground->pid;
|
||||
int pgrp = foreground->pid;
|
||||
PROC_RELEASE(foreground);
|
||||
break;
|
||||
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, &pgrp, sizeof(int));
|
||||
}
|
||||
case TIOCSPGRP: {
|
||||
int *pgrpptr = arg;
|
||||
int pgrp = *pgrpptr;
|
||||
int pgrp;
|
||||
int e = USERCOPY_POSSIBLY_FROM_USER(&pgrp, arg, sizeof(int));
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
proc_t *proc = sched_getprocfrompid(pgrp);
|
||||
if (proc == NULL)
|
||||
return ESRCH;
|
||||
@@ -354,8 +361,7 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result) {
|
||||
}
|
||||
case TTY_IOCTL_NAME: {
|
||||
size_t len = min(strlen(tty->name) + 1, TTY_NAME_MAX);
|
||||
memcpy(arg, tty->name, len);
|
||||
break;
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, tty->name, len);
|
||||
}
|
||||
default:
|
||||
return ENOTTY;
|
||||
|
||||
Reference in New Issue
Block a user