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