From 43d5d34099e61b4e7d339dc2266d0116bf2c16f6 Mon Sep 17 00:00:00 2001 From: prnmxfqg4 Date: Fri, 24 Jun 2022 19:55:08 +0800 Subject: [PATCH] =?UTF-8?q?educoder=E4=B8=8D=E6=94=AF=E6=8C=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E6=88=96=E5=8E=8B=E7=BC=A9=E5=8C=85=E7=9A=84?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=EF=BC=8C=E6=89=80=E4=BB=A5=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E6=9A=82=E5=8F=91=E5=8D=95=E4=B8=AA.c=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E6=98=BE=E7=A4=BA=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0=20=E6=9C=AC=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E4=BA=8Elinux/kernel=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=BC=96=E8=AF=91=E5=86=85=E6=A0=B8=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E7=94=B1=E4=BA=8E=E6=B2=A1=E6=9C=89=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=85=B6=E4=BB=96=E8=A6=81=E6=B1=82=E7=9A=84sys?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BC=9A=E6=8A=A5=E9=94=99=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E4=B8=8D=E5=BD=B1=E5=93=8Dboch=E4=B8=AD=E5=BE=97=E5=87=BA?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys.c | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 sys.c diff --git a/sys.c b/sys.c new file mode 100644 index 0000000..dcc01ac --- /dev/null +++ b/sys.c @@ -0,0 +1,299 @@ +/* + * linux/kernel/sys.c + * + * (C) 1991 Linus Torvalds + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +int sys_ftime() +{ + return -ENOSYS; +} + +int sys_break() +{ + return -ENOSYS; +} + +int sys_ptrace() +{ + return -ENOSYS; +} + +int sys_stty() +{ + return -ENOSYS; +} + +int sys_gtty() +{ + return -ENOSYS; +} + +int sys_rename() +{ + return -ENOSYS; +} + +int sys_prof() +{ + return -ENOSYS; +} + +int sys_setregid(int rgid, int egid) +{ + if (rgid>0) { + if ((current->gid == rgid) || + suser()) + current->gid = rgid; + else + return(-EPERM); + } + if (egid>0) { + if ((current->gid == egid) || + (current->egid == egid) || + suser()) { + current->egid = egid; + current->sgid = egid; + } else + return(-EPERM); + } + return 0; +} + +int sys_setgid(int gid) +{ +/* return(sys_setregid(gid, gid)); */ + if (suser()) + current->gid = current->egid = current->sgid = gid; + else if ((gid == current->gid) || (gid == current->sgid)) + current->egid = gid; + else + return -EPERM; + return 0; +} + +int sys_acct() +{ + return -ENOSYS; +} + +int sys_phys() +{ + return -ENOSYS; +} + +int sys_lock() +{ + return -ENOSYS; +} + +int sys_mpx() +{ + return -ENOSYS; +} + +int sys_ulimit() +{ + return -ENOSYS; +} + +int sys_time(long * tloc) +{ + int i; + + i = CURRENT_TIME; + if (tloc) { + verify_area(tloc,4); + put_fs_long(i,(unsigned long *)tloc); + } + return i; +} + +/* + * Unprivileged users may change the real user id to the effective uid + * or vice versa. + */ +int sys_setreuid(int ruid, int euid) +{ + int old_ruid = current->uid; + + if (ruid>0) { + if ((current->euid==ruid) || + (old_ruid == ruid) || + suser()) + current->uid = ruid; + else + return(-EPERM); + } + if (euid>0) { + if ((old_ruid == euid) || + (current->euid == euid) || + suser()) { + current->euid = euid; + current->suid = euid; + } else { + current->uid = old_ruid; + return(-EPERM); + } + } + return 0; +} + +int sys_setuid(int uid) +{ +/* return(sys_setreuid(uid, uid)); */ + if (suser()) + current->uid = current->euid = current->suid = uid; + else if ((uid == current->uid) || (uid == current->suid)) + current->euid = uid; + else + return -EPERM; + return(0); +} + +int sys_stime(long * tptr) +{ + if (!suser()) + return -EPERM; + startup_time = get_fs_long((unsigned long *)tptr) - jiffies/HZ; + return 0; +} + +int sys_times(struct tms * tbuf) +{ + if (tbuf) { + verify_area(tbuf,sizeof *tbuf); + put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime); + put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime); + put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime); + put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime); + } + return jiffies; +} + +int sys_brk(unsigned long end_data_seg) +{ + if (end_data_seg >= current->end_code && + end_data_seg < current->start_stack - 16384) + current->brk = end_data_seg; + return current->brk; +} + +/* + * This needs some heave checking ... + * I just haven't get the stomach for it. I also don't fully + * understand sessions/pgrp etc. Let somebody who does explain it. + */ +int sys_setpgid(int pid, int pgid) +{ + int i; + + if (!pid) + pid = current->pid; + if (!pgid) + pgid = current->pid; + for (i=0 ; ipid==pid) { + if (task[i]->leader) + return -EPERM; + if (task[i]->session != current->session) + return -EPERM; + task[i]->pgrp = pgid; + return 0; + } + return -ESRCH; +} + +int sys_getpgrp(void) +{ + return current->pgrp; +} + +int sys_setsid(void) +{ + if (current->leader && !suser()) + return -EPERM; + current->leader = 1; + current->session = current->pgrp = current->pid; + current->tty = -1; + return current->pgrp; +} + +int sys_getgroups() +{ + return -ENOSYS; +} + +int sys_setgroups() +{ + return -ENOSYS; +} + +int sys_uname(struct utsname * name) +{ + static struct utsname thisname = { + "linux .0","nodename","release ","version ","machine " + }; + int i; + + if (!name) return -ERROR; + verify_area(name,sizeof *name); + for(i=0;iumask; + + current->umask = mask & 0777; + return (old); +} +int sys_sleep(unsigned int seconds) +{ + sys_signal(SIGALRM,SIG_IGN); + sys_alarm(seconds); + sys_pause(); + return 0; +}