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