linux/arch/alpha/kernel/osf_sys.c
<<
>>
Prefs
   1/*
   2 *  linux/arch/alpha/kernel/osf_sys.c
   3 *
   4 *  Copyright (C) 1995  Linus Torvalds
   5 */
   6
   7/*
   8 * This file handles some of the stranger OSF/1 system call interfaces.
   9 * Some of the system calls expect a non-C calling standard, others have
  10 * special parameter blocks..
  11 */
  12
  13#include <linux/errno.h>
  14#include <linux/sched.h>
  15#include <linux/kernel.h>
  16#include <linux/mm.h>
  17#include <linux/smp.h>
  18#include <linux/smp_lock.h>
  19#include <linux/stddef.h>
  20#include <linux/syscalls.h>
  21#include <linux/unistd.h>
  22#include <linux/ptrace.h>
  23#include <linux/slab.h>
  24#include <linux/user.h>
  25#include <linux/utsname.h>
  26#include <linux/time.h>
  27#include <linux/timex.h>
  28#include <linux/major.h>
  29#include <linux/stat.h>
  30#include <linux/mman.h>
  31#include <linux/shm.h>
  32#include <linux/poll.h>
  33#include <linux/file.h>
  34#include <linux/types.h>
  35#include <linux/ipc.h>
  36#include <linux/namei.h>
  37#include <linux/uio.h>
  38#include <linux/vfs.h>
  39#include <linux/rcupdate.h>
  40
  41#include <asm/fpu.h>
  42#include <asm/io.h>
  43#include <asm/uaccess.h>
  44#include <asm/system.h>
  45#include <asm/sysinfo.h>
  46#include <asm/hwrpb.h>
  47#include <asm/processor.h>
  48
  49extern int do_pipe(int *);
  50
  51/*
  52 * Brk needs to return an error.  Still support Linux's brk(0) query idiom,
  53 * which OSF programs just shouldn't be doing.  We're still not quite
  54 * identical to OSF as we don't return 0 on success, but doing otherwise
  55 * would require changes to libc.  Hopefully this is good enough.
  56 */
  57SYSCALL_DEFINE1(osf_brk, unsigned long, brk)
  58{
  59        unsigned long retval = sys_brk(brk);
  60        if (brk && brk != retval)
  61                retval = -ENOMEM;
  62        return retval;
  63}
  64 
  65/*
  66 * This is pure guess-work..
  67 */
  68SYSCALL_DEFINE4(osf_set_program_attributes, unsigned long, text_start,
  69                unsigned long, text_len, unsigned long, bss_start,
  70                unsigned long, bss_len)
  71{
  72        struct mm_struct *mm;
  73
  74        lock_kernel();
  75        mm = current->mm;
  76        mm->end_code = bss_start + bss_len;
  77        mm->start_brk = bss_start + bss_len;
  78        mm->brk = bss_start + bss_len;
  79#if 0
  80        printk("set_program_attributes(%lx %lx %lx %lx)\n",
  81                text_start, text_len, bss_start, bss_len);
  82#endif
  83        unlock_kernel();
  84        return 0;
  85}
  86
  87/*
  88 * OSF/1 directory handling functions...
  89 *
  90 * The "getdents()" interface is much more sane: the "basep" stuff is
  91 * braindamage (it can't really handle filesystems where the directory
  92 * offset differences aren't the same as "d_reclen").
  93 */
  94#define NAME_OFFSET     offsetof (struct osf_dirent, d_name)
  95
  96struct osf_dirent {
  97        unsigned int d_ino;
  98        unsigned short d_reclen;
  99        unsigned short d_namlen;
 100        char d_name[1];
 101};
 102
 103struct osf_dirent_callback {
 104        struct osf_dirent __user *dirent;
 105        long __user *basep;
 106        unsigned int count;
 107        int error;
 108};
 109
 110static int
 111osf_filldir(void *__buf, const char *name, int namlen, loff_t offset,
 112            u64 ino, unsigned int d_type)
 113{
 114        struct osf_dirent __user *dirent;
 115        struct osf_dirent_callback *buf = (struct osf_dirent_callback *) __buf;
 116        unsigned int reclen = ALIGN(NAME_OFFSET + namlen + 1, sizeof(u32));
 117        unsigned int d_ino;
 118
 119        buf->error = -EINVAL;   /* only used if we fail */
 120        if (reclen > buf->count)
 121                return -EINVAL;
 122        d_ino = ino;
 123        if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
 124                buf->error = -EOVERFLOW;
 125                return -EOVERFLOW;
 126        }
 127        if (buf->basep) {
 128                if (put_user(offset, buf->basep))
 129                        goto Efault;
 130                buf->basep = NULL;
 131        }
 132        dirent = buf->dirent;
 133        if (put_user(d_ino, &dirent->d_ino) ||
 134            put_user(namlen, &dirent->d_namlen) ||
 135            put_user(reclen, &dirent->d_reclen) ||
 136            copy_to_user(dirent->d_name, name, namlen) ||
 137            put_user(0, dirent->d_name + namlen))
 138                goto Efault;
 139        dirent = (void __user *)dirent + reclen;
 140        buf->dirent = dirent;
 141        buf->count -= reclen;
 142        return 0;
 143Efault:
 144        buf->error = -EFAULT;
 145        return -EFAULT;
 146}
 147
 148SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
 149                struct osf_dirent __user *, dirent, unsigned int, count,
 150                long __user *, basep)
 151{
 152        int error;
 153        struct file *file;
 154        struct osf_dirent_callback buf;
 155
 156        error = -EBADF;
 157        file = fget(fd);
 158        if (!file)
 159                goto out;
 160
 161        buf.dirent = dirent;
 162        buf.basep = basep;
 163        buf.count = count;
 164        buf.error = 0;
 165
 166        error = vfs_readdir(file, osf_filldir, &buf);
 167        if (error >= 0)
 168                error = buf.error;
 169        if (count != buf.count)
 170                error = count - buf.count;
 171
 172        fput(file);
 173 out:
 174        return error;
 175}
 176
 177#undef NAME_OFFSET
 178
 179SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len,
 180                unsigned long, prot, unsigned long, flags, unsigned long, fd,
 181                unsigned long, off)
 182{
 183        struct file *file = NULL;
 184        unsigned long ret = -EBADF;
 185
 186#if 0
 187        if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
 188                printk("%s: unimplemented OSF mmap flags %04lx\n", 
 189                        current->comm, flags);
 190#endif
 191        if (!(flags & MAP_ANONYMOUS)) {
 192                file = fget(fd);
 193                if (!file)
 194                        goto out;
 195        }
 196        flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 197        down_write(&current->mm->mmap_sem);
 198        ret = do_mmap(file, addr, len, prot, flags, off);
 199        up_write(&current->mm->mmap_sem);
 200        if (file)
 201                fput(file);
 202 out:
 203        return ret;
 204}
 205
 206
 207/*
 208 * The OSF/1 statfs structure is much larger, but this should
 209 * match the beginning, at least.
 210 */
 211struct osf_statfs {
 212        short f_type;
 213        short f_flags;
 214        int f_fsize;
 215        int f_bsize;
 216        int f_blocks;
 217        int f_bfree;
 218        int f_bavail;
 219        int f_files;
 220        int f_ffree;
 221        __kernel_fsid_t f_fsid;
 222};
 223
 224static int
 225linux_to_osf_statfs(struct kstatfs *linux_stat, struct osf_statfs __user *osf_stat,
 226                    unsigned long bufsiz)
 227{
 228        struct osf_statfs tmp_stat;
 229
 230        tmp_stat.f_type = linux_stat->f_type;
 231        tmp_stat.f_flags = 0;   /* mount flags */
 232        tmp_stat.f_fsize = linux_stat->f_frsize;
 233        tmp_stat.f_bsize = linux_stat->f_bsize;
 234        tmp_stat.f_blocks = linux_stat->f_blocks;
 235        tmp_stat.f_bfree = linux_stat->f_bfree;
 236        tmp_stat.f_bavail = linux_stat->f_bavail;
 237        tmp_stat.f_files = linux_stat->f_files;
 238        tmp_stat.f_ffree = linux_stat->f_ffree;
 239        tmp_stat.f_fsid = linux_stat->f_fsid;
 240        if (bufsiz > sizeof(tmp_stat))
 241                bufsiz = sizeof(tmp_stat);
 242        return copy_to_user(osf_stat, &tmp_stat, bufsiz) ? -EFAULT : 0;
 243}
 244
 245static int
 246do_osf_statfs(struct dentry * dentry, struct osf_statfs __user *buffer,
 247              unsigned long bufsiz)
 248{
 249        struct kstatfs linux_stat;
 250        int error = vfs_statfs(dentry, &linux_stat);
 251        if (!error)
 252                error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
 253        return error;   
 254}
 255
 256SYSCALL_DEFINE3(osf_statfs, char __user *, pathname,
 257                struct osf_statfs __user *, buffer, unsigned long, bufsiz)
 258{
 259        struct path path;
 260        int retval;
 261
 262        retval = user_path(pathname, &path);
 263        if (!retval) {
 264                retval = do_osf_statfs(path.dentry, buffer, bufsiz);
 265                path_put(&path);
 266        }
 267        return retval;
 268}
 269
 270SYSCALL_DEFINE3(osf_fstatfs, unsigned long, fd,
 271                struct osf_statfs __user *, buffer, unsigned long, bufsiz)
 272{
 273        struct file *file;
 274        int retval;
 275
 276        retval = -EBADF;
 277        file = fget(fd);
 278        if (file) {
 279                retval = do_osf_statfs(file->f_path.dentry, buffer, bufsiz);
 280                fput(file);
 281        }
 282        return retval;
 283}
 284
 285/*
 286 * Uhh.. OSF/1 mount parameters aren't exactly obvious..
 287 *
 288 * Although to be frank, neither are the native Linux/i386 ones..
 289 */
 290struct ufs_args {
 291        char __user *devname;
 292        int flags;
 293        uid_t exroot;
 294};
 295
 296struct cdfs_args {
 297        char __user *devname;
 298        int flags;
 299        uid_t exroot;
 300
 301        /* This has lots more here, which Linux handles with the option block
 302           but I'm too lazy to do the translation into ASCII.  */
 303};
 304
 305struct procfs_args {
 306        char __user *devname;
 307        int flags;
 308        uid_t exroot;
 309};
 310
 311/*
 312 * We can't actually handle ufs yet, so we translate UFS mounts to
 313 * ext2fs mounts. I wouldn't mind a UFS filesystem, but the UFS
 314 * layout is so braindead it's a major headache doing it.
 315 *
 316 * Just how long ago was it written? OTOH our UFS driver may be still
 317 * unhappy with OSF UFS. [CHECKME]
 318 */
 319static int
 320osf_ufs_mount(char *dirname, struct ufs_args __user *args, int flags)
 321{
 322        int retval;
 323        struct cdfs_args tmp;
 324        char *devname;
 325
 326        retval = -EFAULT;
 327        if (copy_from_user(&tmp, args, sizeof(tmp)))
 328                goto out;
 329        devname = getname(tmp.devname);
 330        retval = PTR_ERR(devname);
 331        if (IS_ERR(devname))
 332                goto out;
 333        retval = do_mount(devname, dirname, "ext2", flags, NULL);
 334        putname(devname);
 335 out:
 336        return retval;
 337}
 338
 339static int
 340osf_cdfs_mount(char *dirname, struct cdfs_args __user *args, int flags)
 341{
 342        int retval;
 343        struct cdfs_args tmp;
 344        char *devname;
 345
 346        retval = -EFAULT;
 347        if (copy_from_user(&tmp, args, sizeof(tmp)))
 348                goto out;
 349        devname = getname(tmp.devname);
 350        retval = PTR_ERR(devname);
 351        if (IS_ERR(devname))
 352                goto out;
 353        retval = do_mount(devname, dirname, "iso9660", flags, NULL);
 354        putname(devname);
 355 out:
 356        return retval;
 357}
 358
 359static int
 360osf_procfs_mount(char *dirname, struct procfs_args __user *args, int flags)
 361{
 362        struct procfs_args tmp;
 363
 364        if (copy_from_user(&tmp, args, sizeof(tmp)))
 365                return -EFAULT;
 366
 367        return do_mount("", dirname, "proc", flags, NULL);
 368}
 369
 370SYSCALL_DEFINE4(osf_mount, unsigned long, typenr, char __user *, path,
 371                int, flag, void __user *, data)
 372{
 373        int retval = -EINVAL;
 374        char *name;
 375
 376        lock_kernel();
 377
 378        name = getname(path);
 379        retval = PTR_ERR(name);
 380        if (IS_ERR(name))
 381                goto out;
 382        switch (typenr) {
 383        case 1:
 384                retval = osf_ufs_mount(name, data, flag);
 385                break;
 386        case 6:
 387                retval = osf_cdfs_mount(name, data, flag);
 388                break;
 389        case 9:
 390                retval = osf_procfs_mount(name, data, flag);
 391                break;
 392        default:
 393                printk("osf_mount(%ld, %x)\n", typenr, flag);
 394        }
 395        putname(name);
 396 out:
 397        unlock_kernel();
 398        return retval;
 399}
 400
 401SYSCALL_DEFINE1(osf_utsname, char __user *, name)
 402{
 403        int error;
 404
 405        down_read(&uts_sem);
 406        error = -EFAULT;
 407        if (copy_to_user(name + 0, utsname()->sysname, 32))
 408                goto out;
 409        if (copy_to_user(name + 32, utsname()->nodename, 32))
 410                goto out;
 411        if (copy_to_user(name + 64, utsname()->release, 32))
 412                goto out;
 413        if (copy_to_user(name + 96, utsname()->version, 32))
 414                goto out;
 415        if (copy_to_user(name + 128, utsname()->machine, 32))
 416                goto out;
 417
 418        error = 0;
 419 out:
 420        up_read(&uts_sem);      
 421        return error;
 422}
 423
 424SYSCALL_DEFINE0(getpagesize)
 425{
 426        return PAGE_SIZE;
 427}
 428
 429SYSCALL_DEFINE0(getdtablesize)
 430{
 431        return sysctl_nr_open;
 432}
 433
 434/*
 435 * For compatibility with OSF/1 only.  Use utsname(2) instead.
 436 */
 437SYSCALL_DEFINE2(osf_getdomainname, char __user *, name, int, namelen)
 438{
 439        unsigned len;
 440        int i;
 441
 442        if (!access_ok(VERIFY_WRITE, name, namelen))
 443                return -EFAULT;
 444
 445        len = namelen;
 446        if (namelen > 32)
 447                len = 32;
 448
 449        down_read(&uts_sem);
 450        for (i = 0; i < len; ++i) {
 451                __put_user(utsname()->domainname[i], name + i);
 452                if (utsname()->domainname[i] == '\0')
 453                        break;
 454        }
 455        up_read(&uts_sem);
 456
 457        return 0;
 458}
 459
 460/*
 461 * The following stuff should move into a header file should it ever
 462 * be labeled "officially supported."  Right now, there is just enough
 463 * support to avoid applications (such as tar) printing error
 464 * messages.  The attributes are not really implemented.
 465 */
 466
 467/*
 468 * Values for Property list entry flag
 469 */
 470#define PLE_PROPAGATE_ON_COPY           0x1     /* cp(1) will copy entry
 471                                                   by default */
 472#define PLE_FLAG_MASK                   0x1     /* Valid flag values */
 473#define PLE_FLAG_ALL                    -1      /* All flag value */
 474
 475struct proplistname_args {
 476        unsigned int pl_mask;
 477        unsigned int pl_numnames;
 478        char **pl_names;
 479};
 480
 481union pl_args {
 482        struct setargs {
 483                char __user *path;
 484                long follow;
 485                long nbytes;
 486                char __user *buf;
 487        } set;
 488        struct fsetargs {
 489                long fd;
 490                long nbytes;
 491                char __user *buf;
 492        } fset;
 493        struct getargs {
 494                char __user *path;
 495                long follow;
 496                struct proplistname_args __user *name_args;
 497                long nbytes;
 498                char __user *buf;
 499                int __user *min_buf_size;
 500        } get;
 501        struct fgetargs {
 502                long fd;
 503                struct proplistname_args __user *name_args;
 504                long nbytes;
 505                char __user *buf;
 506                int __user *min_buf_size;
 507        } fget;
 508        struct delargs {
 509                char __user *path;
 510                long follow;
 511                struct proplistname_args __user *name_args;
 512        } del;
 513        struct fdelargs {
 514                long fd;
 515                struct proplistname_args __user *name_args;
 516        } fdel;
 517};
 518
 519enum pl_code {
 520        PL_SET = 1, PL_FSET = 2,
 521        PL_GET = 3, PL_FGET = 4,
 522        PL_DEL = 5, PL_FDEL = 6
 523};
 524
 525SYSCALL_DEFINE2(osf_proplist_syscall, enum pl_code, code,
 526                union pl_args __user *, args)
 527{
 528        long error;
 529        int __user *min_buf_size_ptr;
 530
 531        lock_kernel();
 532        switch (code) {
 533        case PL_SET:
 534                if (get_user(error, &args->set.nbytes))
 535                        error = -EFAULT;
 536                break;
 537        case PL_FSET:
 538                if (get_user(error, &args->fset.nbytes))
 539                        error = -EFAULT;
 540                break;
 541        case PL_GET:
 542                error = get_user(min_buf_size_ptr, &args->get.min_buf_size);
 543                if (error)
 544                        break;
 545                error = put_user(0, min_buf_size_ptr);
 546                break;
 547        case PL_FGET:
 548                error = get_user(min_buf_size_ptr, &args->fget.min_buf_size);
 549                if (error)
 550                        break;
 551                error = put_user(0, min_buf_size_ptr);
 552                break;
 553        case PL_DEL:
 554        case PL_FDEL:
 555                error = 0;
 556                break;
 557        default:
 558                error = -EOPNOTSUPP;
 559                break;
 560        };
 561        unlock_kernel();
 562        return error;
 563}
 564
 565SYSCALL_DEFINE2(osf_sigstack, struct sigstack __user *, uss,
 566                struct sigstack __user *, uoss)
 567{
 568        unsigned long usp = rdusp();
 569        unsigned long oss_sp = current->sas_ss_sp + current->sas_ss_size;
 570        unsigned long oss_os = on_sig_stack(usp);
 571        int error;
 572
 573        if (uss) {
 574                void __user *ss_sp;
 575
 576                error = -EFAULT;
 577                if (get_user(ss_sp, &uss->ss_sp))
 578                        goto out;
 579
 580                /* If the current stack was set with sigaltstack, don't
 581                   swap stacks while we are on it.  */
 582                error = -EPERM;
 583                if (current->sas_ss_sp && on_sig_stack(usp))
 584                        goto out;
 585
 586                /* Since we don't know the extent of the stack, and we don't
 587                   track onstack-ness, but rather calculate it, we must 
 588                   presume a size.  Ho hum this interface is lossy.  */
 589                current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
 590                current->sas_ss_size = SIGSTKSZ;
 591        }
 592
 593        if (uoss) {
 594                error = -EFAULT;
 595                if (! access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))
 596                    || __put_user(oss_sp, &uoss->ss_sp)
 597                    || __put_user(oss_os, &uoss->ss_onstack))
 598                        goto out;
 599        }
 600
 601        error = 0;
 602 out:
 603        return error;
 604}
 605
 606SYSCALL_DEFINE3(osf_sysinfo, int, command, char __user *, buf, long, count)
 607{
 608        char *sysinfo_table[] = {
 609                utsname()->sysname,
 610                utsname()->nodename,
 611                utsname()->release,
 612                utsname()->version,
 613                utsname()->machine,
 614                "alpha",        /* instruction set architecture */
 615                "dummy",        /* hardware serial number */
 616                "dummy",        /* hardware manufacturer */
 617                "dummy",        /* secure RPC domain */
 618        };
 619        unsigned long offset;
 620        char *res;
 621        long len, err = -EINVAL;
 622
 623        offset = command-1;
 624        if (offset >= ARRAY_SIZE(sysinfo_table)) {
 625                /* Digital UNIX has a few unpublished interfaces here */
 626                printk("sysinfo(%d)", command);
 627                goto out;
 628        }
 629
 630        down_read(&uts_sem);
 631        res = sysinfo_table[offset];
 632        len = strlen(res)+1;
 633        if (len > count)
 634                len = count;
 635        if (copy_to_user(buf, res, len))
 636                err = -EFAULT;
 637        else
 638                err = 0;
 639        up_read(&uts_sem);
 640 out:
 641        return err;
 642}
 643
 644SYSCALL_DEFINE5(osf_getsysinfo, unsigned long, op, void __user *, buffer,
 645                unsigned long, nbytes, int __user *, start, void __user *, arg)
 646{
 647        unsigned long w;
 648        struct percpu_struct *cpu;
 649
 650        switch (op) {
 651        case GSI_IEEE_FP_CONTROL:
 652                /* Return current software fp control & status bits.  */
 653                /* Note that DU doesn't verify available space here.  */
 654
 655                w = current_thread_info()->ieee_state & IEEE_SW_MASK;
 656                w = swcr_update_status(w, rdfpcr());
 657                if (put_user(w, (unsigned long __user *) buffer))
 658                        return -EFAULT;
 659                return 0;
 660
 661        case GSI_IEEE_STATE_AT_SIGNAL:
 662                /*
 663                 * Not sure anybody will ever use this weird stuff.  These
 664                 * ops can be used (under OSF/1) to set the fpcr that should
 665                 * be used when a signal handler starts executing.
 666                 */
 667                break;
 668
 669        case GSI_UACPROC:
 670                if (nbytes < sizeof(unsigned int))
 671                        return -EINVAL;
 672                w = (current_thread_info()->flags >> UAC_SHIFT) & UAC_BITMASK;
 673                if (put_user(w, (unsigned int __user *)buffer))
 674                        return -EFAULT;
 675                return 1;
 676
 677        case GSI_PROC_TYPE:
 678                if (nbytes < sizeof(unsigned long))
 679                        return -EINVAL;
 680                cpu = (struct percpu_struct*)
 681                  ((char*)hwrpb + hwrpb->processor_offset);
 682                w = cpu->type;
 683                if (put_user(w, (unsigned long  __user*)buffer))
 684                        return -EFAULT;
 685                return 1;
 686
 687        case GSI_GET_HWRPB:
 688                if (nbytes < sizeof(*hwrpb))
 689                        return -EINVAL;
 690                if (copy_to_user(buffer, hwrpb, nbytes) != 0)
 691                        return -EFAULT;
 692                return 1;
 693
 694        default:
 695                break;
 696        }
 697
 698        return -EOPNOTSUPP;
 699}
 700
 701SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
 702                unsigned long, nbytes, int __user *, start, void __user *, arg)
 703{
 704        switch (op) {
 705        case SSI_IEEE_FP_CONTROL: {
 706                unsigned long swcr, fpcr;
 707                unsigned int *state;
 708
 709                /* 
 710                 * Alpha Architecture Handbook 4.7.7.3:
 711                 * To be fully IEEE compiant, we must track the current IEEE
 712                 * exception state in software, because spurious bits can be
 713                 * set in the trap shadow of a software-complete insn.
 714                 */
 715
 716                if (get_user(swcr, (unsigned long __user *)buffer))
 717                        return -EFAULT;
 718                state = &current_thread_info()->ieee_state;
 719
 720                /* Update softare trap enable bits.  */
 721                *state = (*state & ~IEEE_SW_MASK) | (swcr & IEEE_SW_MASK);
 722
 723                /* Update the real fpcr.  */
 724                fpcr = rdfpcr() & FPCR_DYN_MASK;
 725                fpcr |= ieee_swcr_to_fpcr(swcr);
 726                wrfpcr(fpcr);
 727
 728                return 0;
 729        }
 730
 731        case SSI_IEEE_RAISE_EXCEPTION: {
 732                unsigned long exc, swcr, fpcr, fex;
 733                unsigned int *state;
 734
 735                if (get_user(exc, (unsigned long __user *)buffer))
 736                        return -EFAULT;
 737                state = &current_thread_info()->ieee_state;
 738                exc &= IEEE_STATUS_MASK;
 739
 740                /* Update softare trap enable bits.  */
 741                swcr = (*state & IEEE_SW_MASK) | exc;
 742                *state |= exc;
 743
 744                /* Update the real fpcr.  */
 745                fpcr = rdfpcr();
 746                fpcr |= ieee_swcr_to_fpcr(swcr);
 747                wrfpcr(fpcr);
 748
 749                /* If any exceptions set by this call, and are unmasked,
 750                   send a signal.  Old exceptions are not signaled.  */
 751                fex = (exc >> IEEE_STATUS_TO_EXCSUM_SHIFT) & swcr;
 752                if (fex) {
 753                        siginfo_t info;
 754                        int si_code = 0;
 755
 756                        if (fex & IEEE_TRAP_ENABLE_DNO) si_code = FPE_FLTUND;
 757                        if (fex & IEEE_TRAP_ENABLE_INE) si_code = FPE_FLTRES;
 758                        if (fex & IEEE_TRAP_ENABLE_UNF) si_code = FPE_FLTUND;
 759                        if (fex & IEEE_TRAP_ENABLE_OVF) si_code = FPE_FLTOVF;
 760                        if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
 761                        if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
 762
 763                        info.si_signo = SIGFPE;
 764                        info.si_errno = 0;
 765                        info.si_code = si_code;
 766                        info.si_addr = NULL;  /* FIXME */
 767                        send_sig_info(SIGFPE, &info, current);
 768                }
 769                return 0;
 770        }
 771
 772        case SSI_IEEE_STATE_AT_SIGNAL:
 773        case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
 774                /*
 775                 * Not sure anybody will ever use this weird stuff.  These
 776                 * ops can be used (under OSF/1) to set the fpcr that should
 777                 * be used when a signal handler starts executing.
 778                 */
 779                break;
 780
 781        case SSI_NVPAIRS: {
 782                unsigned long v, w, i;
 783                unsigned int old, new;
 784                
 785                for (i = 0; i < nbytes; ++i) {
 786
 787                        if (get_user(v, 2*i + (unsigned int __user *)buffer))
 788                                return -EFAULT;
 789                        if (get_user(w, 2*i + 1 + (unsigned int __user *)buffer))
 790                                return -EFAULT;
 791                        switch (v) {
 792                        case SSIN_UACPROC:
 793                        again:
 794                                old = current_thread_info()->flags;
 795                                new = old & ~(UAC_BITMASK << UAC_SHIFT);
 796                                new = new | (w & UAC_BITMASK) << UAC_SHIFT;
 797                                if (cmpxchg(&current_thread_info()->flags,
 798                                            old, new) != old)
 799                                        goto again;
 800                                break;
 801 
 802                        default:
 803                                return -EOPNOTSUPP;
 804                        }
 805                }
 806                return 0;
 807        }
 808 
 809        default:
 810                break;
 811        }
 812
 813        return -EOPNOTSUPP;
 814}
 815
 816/* Translations due to the fact that OSF's time_t is an int.  Which
 817   affects all sorts of things, like timeval and itimerval.  */
 818
 819extern struct timezone sys_tz;
 820
 821struct timeval32
 822{
 823    int tv_sec, tv_usec;
 824};
 825
 826struct itimerval32
 827{
 828    struct timeval32 it_interval;
 829    struct timeval32 it_value;
 830};
 831
 832static inline long
 833get_tv32(struct timeval *o, struct timeval32 __user *i)
 834{
 835        return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
 836                (__get_user(o->tv_sec, &i->tv_sec) |
 837                 __get_user(o->tv_usec, &i->tv_usec)));
 838}
 839
 840static inline long
 841put_tv32(struct timeval32 __user *o, struct timeval *i)
 842{
 843        return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
 844                (__put_user(i->tv_sec, &o->tv_sec) |
 845                 __put_user(i->tv_usec, &o->tv_usec)));
 846}
 847
 848static inline long
 849get_it32(struct itimerval *o, struct itimerval32 __user *i)
 850{
 851        return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
 852                (__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |
 853                 __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |
 854                 __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |
 855                 __get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));
 856}
 857
 858static inline long
 859put_it32(struct itimerval32 __user *o, struct itimerval *i)
 860{
 861        return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
 862                (__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |
 863                 __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |
 864                 __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |
 865                 __put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));
 866}
 867
 868static inline void
 869jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
 870{
 871        value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
 872        value->tv_sec = jiffies / HZ;
 873}
 874
 875SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
 876                struct timezone __user *, tz)
 877{
 878        if (tv) {
 879                struct timeval ktv;
 880                do_gettimeofday(&ktv);
 881                if (put_tv32(tv, &ktv))
 882                        return -EFAULT;
 883        }
 884        if (tz) {
 885                if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
 886                        return -EFAULT;
 887        }
 888        return 0;
 889}
 890
 891SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
 892                struct timezone __user *, tz)
 893{
 894        struct timespec kts;
 895        struct timezone ktz;
 896
 897        if (tv) {
 898                if (get_tv32((struct timeval *)&kts, tv))
 899                        return -EFAULT;
 900        }
 901        if (tz) {
 902                if (copy_from_user(&ktz, tz, sizeof(*tz)))
 903                        return -EFAULT;
 904        }
 905
 906        kts.tv_nsec *= 1000;
 907
 908        return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
 909}
 910
 911SYSCALL_DEFINE2(osf_getitimer, int, which, struct itimerval32 __user *, it)
 912{
 913        struct itimerval kit;
 914        int error;
 915
 916        error = do_getitimer(which, &kit);
 917        if (!error && put_it32(it, &kit))
 918                error = -EFAULT;
 919
 920        return error;
 921}
 922
 923SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
 924                struct itimerval32 __user *, out)
 925{
 926        struct itimerval kin, kout;
 927        int error;
 928
 929        if (in) {
 930                if (get_it32(&kin, in))
 931                        return -EFAULT;
 932        } else
 933                memset(&kin, 0, sizeof(kin));
 934
 935        error = do_setitimer(which, &kin, out ? &kout : NULL);
 936        if (error || !out)
 937                return error;
 938
 939        if (put_it32(out, &kout))
 940                return -EFAULT;
 941
 942        return 0;
 943
 944}
 945
 946SYSCALL_DEFINE2(osf_utimes, char __user *, filename,
 947                struct timeval32 __user *, tvs)
 948{
 949        struct timespec tv[2];
 950
 951        if (tvs) {
 952                struct timeval ktvs[2];
 953                if (get_tv32(&ktvs[0], &tvs[0]) ||
 954                    get_tv32(&ktvs[1], &tvs[1]))
 955                        return -EFAULT;
 956
 957                if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
 958                    ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
 959                        return -EINVAL;
 960
 961                tv[0].tv_sec = ktvs[0].tv_sec;
 962                tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
 963                tv[1].tv_sec = ktvs[1].tv_sec;
 964                tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
 965        }
 966
 967        return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
 968}
 969
 970#define MAX_SELECT_SECONDS \
 971        ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
 972
 973SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
 974                fd_set __user *, exp, struct timeval32 __user *, tvp)
 975{
 976        struct timespec end_time, *to = NULL;
 977        if (tvp) {
 978                time_t sec, usec;
 979
 980                to = &end_time;
 981
 982                if (!access_ok(VERIFY_READ, tvp, sizeof(*tvp))
 983                    || __get_user(sec, &tvp->tv_sec)
 984                    || __get_user(usec, &tvp->tv_usec)) {
 985                        return -EFAULT;
 986                }
 987
 988                if (sec < 0 || usec < 0)
 989                        return -EINVAL;
 990
 991                if (poll_select_set_timeout(to, sec, usec * NSEC_PER_USEC))
 992                        return -EINVAL;         
 993
 994        }
 995
 996        /* OSF does not copy back the remaining time.  */
 997        return core_sys_select(n, inp, outp, exp, to);
 998}
 999
1000struct rusage32 {
1001        struct timeval32 ru_utime;      /* user time used */
1002        struct timeval32 ru_stime;      /* system time used */
1003        long    ru_maxrss;              /* maximum resident set size */
1004        long    ru_ixrss;               /* integral shared memory size */
1005        long    ru_idrss;               /* integral unshared data size */
1006        long    ru_isrss;               /* integral unshared stack size */
1007        long    ru_minflt;              /* page reclaims */
1008        long    ru_majflt;              /* page faults */
1009        long    ru_nswap;               /* swaps */
1010        long    ru_inblock;             /* block input operations */
1011        long    ru_oublock;             /* block output operations */
1012        long    ru_msgsnd;              /* messages sent */
1013        long    ru_msgrcv;              /* messages received */
1014        long    ru_nsignals;            /* signals received */
1015        long    ru_nvcsw;               /* voluntary context switches */
1016        long    ru_nivcsw;              /* involuntary " */
1017};
1018
1019SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
1020{
1021        struct rusage32 r;
1022
1023        if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
1024                return -EINVAL;
1025
1026        memset(&r, 0, sizeof(r));
1027        switch (who) {
1028        case RUSAGE_SELF:
1029                jiffies_to_timeval32(current->utime, &r.ru_utime);
1030                jiffies_to_timeval32(current->stime, &r.ru_stime);
1031                r.ru_minflt = current->min_flt;
1032                r.ru_majflt = current->maj_flt;
1033                break;
1034        case RUSAGE_CHILDREN:
1035                jiffies_to_timeval32(current->signal->cutime, &r.ru_utime);
1036                jiffies_to_timeval32(current->signal->cstime, &r.ru_stime);
1037                r.ru_minflt = current->signal->cmin_flt;
1038                r.ru_majflt = current->signal->cmaj_flt;
1039                break;
1040        }
1041
1042        return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1043}
1044
1045SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
1046                struct rusage32 __user *, ur)
1047{
1048        struct rusage r;
1049        long ret, err;
1050        mm_segment_t old_fs;
1051
1052        if (!ur)
1053                return sys_wait4(pid, ustatus, options, NULL);
1054
1055        old_fs = get_fs();
1056                
1057        set_fs (KERNEL_DS);
1058        ret = sys_wait4(pid, ustatus, options, (struct rusage __user *) &r);
1059        set_fs (old_fs);
1060
1061        if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
1062                return -EFAULT;
1063
1064        err = 0;
1065        err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
1066        err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
1067        err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
1068        err |= __put_user(r.ru_stime.tv_usec, &ur->ru_stime.tv_usec);
1069        err |= __put_user(r.ru_maxrss, &ur->ru_maxrss);
1070        err |= __put_user(r.ru_ixrss, &ur->ru_ixrss);
1071        err |= __put_user(r.ru_idrss, &ur->ru_idrss);
1072        err |= __put_user(r.ru_isrss, &ur->ru_isrss);
1073        err |= __put_user(r.ru_minflt, &ur->ru_minflt);
1074        err |= __put_user(r.ru_majflt, &ur->ru_majflt);
1075        err |= __put_user(r.ru_nswap, &ur->ru_nswap);
1076        err |= __put_user(r.ru_inblock, &ur->ru_inblock);
1077        err |= __put_user(r.ru_oublock, &ur->ru_oublock);
1078        err |= __put_user(r.ru_msgsnd, &ur->ru_msgsnd);
1079        err |= __put_user(r.ru_msgrcv, &ur->ru_msgrcv);
1080        err |= __put_user(r.ru_nsignals, &ur->ru_nsignals);
1081        err |= __put_user(r.ru_nvcsw, &ur->ru_nvcsw);
1082        err |= __put_user(r.ru_nivcsw, &ur->ru_nivcsw);
1083
1084        return err ? err : ret;
1085}
1086
1087/*
1088 * I don't know what the parameters are: the first one
1089 * seems to be a timeval pointer, and I suspect the second
1090 * one is the time remaining.. Ho humm.. No documentation.
1091 */
1092SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
1093                struct timeval32 __user *, remain)
1094{
1095        struct timeval tmp;
1096        unsigned long ticks;
1097
1098        if (get_tv32(&tmp, sleep))
1099                goto fault;
1100
1101        ticks = timeval_to_jiffies(&tmp);
1102
1103        ticks = schedule_timeout_interruptible(ticks);
1104
1105        if (remain) {
1106                jiffies_to_timeval(ticks, &tmp);
1107                if (put_tv32(remain, &tmp))
1108                        goto fault;
1109        }
1110        
1111        return 0;
1112 fault:
1113        return -EFAULT;
1114}
1115
1116
1117struct timex32 {
1118        unsigned int modes;     /* mode selector */
1119        long offset;            /* time offset (usec) */
1120        long freq;              /* frequency offset (scaled ppm) */
1121        long maxerror;          /* maximum error (usec) */
1122        long esterror;          /* estimated error (usec) */
1123        int status;             /* clock command/status */
1124        long constant;          /* pll time constant */
1125        long precision;         /* clock precision (usec) (read only) */
1126        long tolerance;         /* clock frequency tolerance (ppm)
1127                                 * (read only)
1128                                 */
1129        struct timeval32 time;  /* (read only) */
1130        long tick;              /* (modified) usecs between clock ticks */
1131
1132        long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
1133        long jitter;            /* pps jitter (us) (ro) */
1134        int shift;              /* interval duration (s) (shift) (ro) */
1135        long stabil;            /* pps stability (scaled ppm) (ro) */
1136        long jitcnt;            /* jitter limit exceeded (ro) */
1137        long calcnt;            /* calibration intervals (ro) */
1138        long errcnt;            /* calibration errors (ro) */
1139        long stbcnt;            /* stability limit exceeded (ro) */
1140
1141        int  :32; int  :32; int  :32; int  :32;
1142        int  :32; int  :32; int  :32; int  :32;
1143        int  :32; int  :32; int  :32; int  :32;
1144};
1145
1146SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
1147{
1148        struct timex txc;
1149        int ret;
1150
1151        /* copy relevant bits of struct timex. */
1152        if (copy_from_user(&txc, txc_p, offsetof(struct timex32, time)) ||
1153            copy_from_user(&txc.tick, &txc_p->tick, sizeof(struct timex32) - 
1154                           offsetof(struct timex32, time)))
1155          return -EFAULT;
1156
1157        ret = do_adjtimex(&txc);        
1158        if (ret < 0)
1159          return ret;
1160        
1161        /* copy back to timex32 */
1162        if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
1163            (copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) - 
1164                          offsetof(struct timex32, tick))) ||
1165            (put_tv32(&txc_p->time, &txc.time)))
1166          return -EFAULT;
1167
1168        return ret;
1169}
1170
1171/* Get an address range which is currently unmapped.  Similar to the
1172   generic version except that we know how to honor ADDR_LIMIT_32BIT.  */
1173
1174static unsigned long
1175arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1176                         unsigned long limit)
1177{
1178        struct vm_area_struct *vma = find_vma(current->mm, addr);
1179
1180        while (1) {
1181                /* At this point:  (!vma || addr < vma->vm_end). */
1182                if (limit - len < addr)
1183                        return -ENOMEM;
1184                if (!vma || addr + len <= vma->vm_start)
1185                        return addr;
1186                addr = vma->vm_end;
1187                vma = vma->vm_next;
1188        }
1189}
1190
1191unsigned long
1192arch_get_unmapped_area(struct file *filp, unsigned long addr,
1193                       unsigned long len, unsigned long pgoff,
1194                       unsigned long flags)
1195{
1196        unsigned long limit;
1197
1198        /* "32 bit" actually means 31 bit, since pointers sign extend.  */
1199        if (current->personality & ADDR_LIMIT_32BIT)
1200                limit = 0x80000000;
1201        else
1202                limit = TASK_SIZE;
1203
1204        if (len > limit)
1205                return -ENOMEM;
1206
1207        if (flags & MAP_FIXED)
1208                return addr;
1209
1210        /* First, see if the given suggestion fits.
1211
1212           The OSF/1 loader (/sbin/loader) relies on us returning an
1213           address larger than the requested if one exists, which is
1214           a terribly broken way to program.
1215
1216           That said, I can see the use in being able to suggest not
1217           merely specific addresses, but regions of memory -- perhaps
1218           this feature should be incorporated into all ports?  */
1219
1220        if (addr) {
1221                addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1222                if (addr != (unsigned long) -ENOMEM)
1223                        return addr;
1224        }
1225
1226        /* Next, try allocating at TASK_UNMAPPED_BASE.  */
1227        addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1228                                         len, limit);
1229        if (addr != (unsigned long) -ENOMEM)
1230                return addr;
1231
1232        /* Finally, try allocating in low memory.  */
1233        addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
1234
1235        return addr;
1236}
1237
1238#ifdef CONFIG_OSF4_COMPAT
1239
1240/* Clear top 32 bits of iov_len in the user's buffer for
1241   compatibility with old versions of OSF/1 where iov_len
1242   was defined as int. */
1243static int
1244osf_fix_iov_len(const struct iovec __user *iov, unsigned long count)
1245{
1246        unsigned long i;
1247
1248        for (i = 0 ; i < count ; i++) {
1249                int __user *iov_len_high = (int __user *)&iov[i].iov_len + 1;
1250
1251                if (put_user(0, iov_len_high))
1252                        return -EFAULT;
1253        }
1254        return 0;
1255}
1256
1257SYSCALL_DEFINE3(osf_readv, unsigned long, fd,
1258                const struct iovec __user *, vector, unsigned long, count)
1259{
1260        if (unlikely(personality(current->personality) == PER_OSF4))
1261                if (osf_fix_iov_len(vector, count))
1262                        return -EFAULT;
1263        return sys_readv(fd, vector, count);
1264}
1265
1266SYSCALL_DEFINE3(osf_writev, unsigned long, fd,
1267                const struct iovec __user *, vector, unsigned long, count)
1268{
1269        if (unlikely(personality(current->personality) == PER_OSF4))
1270                if (osf_fix_iov_len(vector, count))
1271                        return -EFAULT;
1272        return sys_writev(fd, vector, count);
1273}
1274
1275#endif
1276
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.