blob: 376f2213079190f65196b0e3f6554f0f55834183 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/stddef.h>
19#include <linux/syscalls.h>
20#include <linux/unistd.h>
21#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/user.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#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 Sarma4fb3a532005-09-16 19:28:13 -070037#include <linux/rcupdate.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/fpu.h>
41#include <asm/io.h>
42#include <asm/uaccess.h>
43#include <asm/system.h>
44#include <asm/sysinfo.h>
45#include <asm/hwrpb.h>
46#include <asm/processor.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/*
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 Kokshayskye5d9a902009-01-29 14:25:18 -080054SYSCALL_DEFINE1(osf_brk, unsigned long, brk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
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 Kokshayskye5d9a902009-01-29 14:25:18 -080065SYSCALL_DEFINE4(osf_set_program_attributes, unsigned long, text_start,
66 unsigned long, text_len, unsigned long, bss_start,
67 unsigned long, bss_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 struct mm_struct *mm;
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 mm = current->mm;
72 mm->end_code = bss_start + bss_len;
Ivan Kokshaysky2444e562008-04-24 16:54:50 +040073 mm->start_brk = bss_start + bss_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 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 Torvalds1da177e2005-04-16 15:20:36 -070079 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 Torvalds1da177e2005-04-16 15:20:36 -070090
91struct osf_dirent {
92 unsigned int d_ino;
93 unsigned short d_reclen;
94 unsigned short d_namlen;
95 char d_name[1];
96};
97
98struct osf_dirent_callback {
99 struct osf_dirent __user *dirent;
100 long __user *basep;
101 unsigned int count;
102 int error;
103};
104
105static int
106osf_filldir(void *__buf, const char *name, int namlen, loff_t offset,
David Howellsafefdbb2006-10-03 01:13:46 -0700107 u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 struct osf_dirent __user *dirent;
110 struct osf_dirent_callback *buf = (struct osf_dirent_callback *) __buf;
Milind Arun Choudhary180e53a2007-05-06 14:50:36 -0700111 unsigned int reclen = ALIGN(NAME_OFFSET + namlen + 1, sizeof(u32));
David Howellsafefdbb2006-10-03 01:13:46 -0700112 unsigned int d_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 buf->error = -EINVAL; /* only used if we fail */
115 if (reclen > buf->count)
116 return -EINVAL;
David Howellsafefdbb2006-10-03 01:13:46 -0700117 d_ino = ino;
Al Viro645e68e2008-08-11 23:51:22 -0400118 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
119 buf->error = -EOVERFLOW;
David Howellsafefdbb2006-10-03 01:13:46 -0700120 return -EOVERFLOW;
Al Viro645e68e2008-08-11 23:51:22 -0400121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (buf->basep) {
123 if (put_user(offset, buf->basep))
Al Viro645e68e2008-08-11 23:51:22 -0400124 goto Efault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 buf->basep = NULL;
126 }
127 dirent = buf->dirent;
Al Viro645e68e2008-08-11 23:51:22 -0400128 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 Torvalds1da177e2005-04-16 15:20:36 -0700132 put_user(0, dirent->d_name + namlen))
Al Viro645e68e2008-08-11 23:51:22 -0400133 goto Efault;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 dirent = (void __user *)dirent + reclen;
135 buf->dirent = dirent;
136 buf->count -= reclen;
137 return 0;
Al Viro645e68e2008-08-11 23:51:22 -0400138Efault:
139 buf->error = -EFAULT;
140 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800143SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
144 struct osf_dirent __user *, dirent, unsigned int, count,
145 long __user *, basep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 int error;
148 struct file *file;
149 struct osf_dirent_callback buf;
150
151 error = -EBADF;
152 file = fget(fd);
153 if (!file)
154 goto out;
155
156 buf.dirent = dirent;
157 buf.basep = basep;
158 buf.count = count;
159 buf.error = 0;
160
161 error = vfs_readdir(file, osf_filldir, &buf);
Al Viro53c9c5c2008-08-24 07:29:52 -0400162 if (error >= 0)
163 error = buf.error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 if (count != buf.count)
165 error = count - buf.count;
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 fput(file);
168 out:
169 return error;
170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#undef NAME_OFFSET
173
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800174SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len,
175 unsigned long, prot, unsigned long, flags, unsigned long, fd,
176 unsigned long, off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Al Virof8b72562009-11-30 17:37:04 -0500178 unsigned long ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180#if 0
181 if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
182 printk("%s: unimplemented OSF mmap flags %04lx\n",
183 current->comm, flags);
184#endif
Al Virof8b72562009-11-30 17:37:04 -0500185 if ((off + PAGE_ALIGN(len)) < off)
186 goto out;
187 if (off & ~PAGE_MASK)
188 goto out;
189 ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 out:
191 return ret;
192}
193
194
195/*
196 * The OSF/1 statfs structure is much larger, but this should
197 * match the beginning, at least.
198 */
199struct osf_statfs {
200 short f_type;
201 short f_flags;
202 int f_fsize;
203 int f_bsize;
204 int f_blocks;
205 int f_bfree;
206 int f_bavail;
207 int f_files;
208 int f_ffree;
209 __kernel_fsid_t f_fsid;
210};
211
212static int
213linux_to_osf_statfs(struct kstatfs *linux_stat, struct osf_statfs __user *osf_stat,
214 unsigned long bufsiz)
215{
216 struct osf_statfs tmp_stat;
217
218 tmp_stat.f_type = linux_stat->f_type;
219 tmp_stat.f_flags = 0; /* mount flags */
220 tmp_stat.f_fsize = linux_stat->f_frsize;
221 tmp_stat.f_bsize = linux_stat->f_bsize;
222 tmp_stat.f_blocks = linux_stat->f_blocks;
223 tmp_stat.f_bfree = linux_stat->f_bfree;
224 tmp_stat.f_bavail = linux_stat->f_bavail;
225 tmp_stat.f_files = linux_stat->f_files;
226 tmp_stat.f_ffree = linux_stat->f_ffree;
227 tmp_stat.f_fsid = linux_stat->f_fsid;
228 if (bufsiz > sizeof(tmp_stat))
229 bufsiz = sizeof(tmp_stat);
230 return copy_to_user(osf_stat, &tmp_stat, bufsiz) ? -EFAULT : 0;
231}
232
Al Viroc8b91ac2011-03-12 10:41:39 -0500233SYSCALL_DEFINE3(osf_statfs, const char __user *, pathname,
234 struct osf_statfs __user *, buffer, unsigned long, bufsiz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 struct kstatfs linux_stat;
Al Viroc8b91ac2011-03-12 10:41:39 -0500237 int error = user_statfs(pathname, &linux_stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (!error)
239 error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
240 return error;
241}
242
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800243SYSCALL_DEFINE3(osf_fstatfs, unsigned long, fd,
244 struct osf_statfs __user *, buffer, unsigned long, bufsiz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Al Viroc8b91ac2011-03-12 10:41:39 -0500246 struct kstatfs linux_stat;
247 int error = fd_statfs(fd, &linux_stat);
248 if (!error)
249 error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
250 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
253/*
254 * Uhh.. OSF/1 mount parameters aren't exactly obvious..
255 *
256 * Although to be frank, neither are the native Linux/i386 ones..
257 */
258struct ufs_args {
259 char __user *devname;
260 int flags;
261 uid_t exroot;
262};
263
264struct cdfs_args {
265 char __user *devname;
266 int flags;
267 uid_t exroot;
268
269 /* This has lots more here, which Linux handles with the option block
270 but I'm too lazy to do the translation into ASCII. */
271};
272
273struct procfs_args {
274 char __user *devname;
275 int flags;
276 uid_t exroot;
277};
278
279/*
280 * We can't actually handle ufs yet, so we translate UFS mounts to
281 * ext2fs mounts. I wouldn't mind a UFS filesystem, but the UFS
282 * layout is so braindead it's a major headache doing it.
283 *
284 * Just how long ago was it written? OTOH our UFS driver may be still
285 * unhappy with OSF UFS. [CHECKME]
286 */
287static int
288osf_ufs_mount(char *dirname, struct ufs_args __user *args, int flags)
289{
290 int retval;
291 struct cdfs_args tmp;
292 char *devname;
293
294 retval = -EFAULT;
295 if (copy_from_user(&tmp, args, sizeof(tmp)))
296 goto out;
297 devname = getname(tmp.devname);
298 retval = PTR_ERR(devname);
299 if (IS_ERR(devname))
300 goto out;
301 retval = do_mount(devname, dirname, "ext2", flags, NULL);
302 putname(devname);
303 out:
304 return retval;
305}
306
307static int
308osf_cdfs_mount(char *dirname, struct cdfs_args __user *args, int flags)
309{
310 int retval;
311 struct cdfs_args tmp;
312 char *devname;
313
314 retval = -EFAULT;
315 if (copy_from_user(&tmp, args, sizeof(tmp)))
316 goto out;
317 devname = getname(tmp.devname);
318 retval = PTR_ERR(devname);
319 if (IS_ERR(devname))
320 goto out;
321 retval = do_mount(devname, dirname, "iso9660", flags, NULL);
322 putname(devname);
323 out:
324 return retval;
325}
326
327static int
328osf_procfs_mount(char *dirname, struct procfs_args __user *args, int flags)
329{
330 struct procfs_args tmp;
331
332 if (copy_from_user(&tmp, args, sizeof(tmp)))
333 return -EFAULT;
334
335 return do_mount("", dirname, "proc", flags, NULL);
336}
337
David Howellsc7887322010-08-11 11:26:22 +0100338SYSCALL_DEFINE4(osf_mount, unsigned long, typenr, const char __user *, path,
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800339 int, flag, void __user *, data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Roel Kluin77079db2010-03-05 13:42:28 -0800341 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 char *name;
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 name = getname(path);
345 retval = PTR_ERR(name);
346 if (IS_ERR(name))
347 goto out;
348 switch (typenr) {
349 case 1:
350 retval = osf_ufs_mount(name, data, flag);
351 break;
352 case 6:
353 retval = osf_cdfs_mount(name, data, flag);
354 break;
355 case 9:
356 retval = osf_procfs_mount(name, data, flag);
357 break;
358 default:
Roel Kluin77079db2010-03-05 13:42:28 -0800359 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 printk("osf_mount(%ld, %x)\n", typenr, flag);
361 }
362 putname(name);
363 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return retval;
365}
366
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800367SYSCALL_DEFINE1(osf_utsname, char __user *, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 int error;
370
371 down_read(&uts_sem);
372 error = -EFAULT;
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700373 if (copy_to_user(name + 0, utsname()->sysname, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 goto out;
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700375 if (copy_to_user(name + 32, utsname()->nodename, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 goto out;
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700377 if (copy_to_user(name + 64, utsname()->release, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 goto out;
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700379 if (copy_to_user(name + 96, utsname()->version, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 goto out;
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700381 if (copy_to_user(name + 128, utsname()->machine, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 goto out;
383
384 error = 0;
385 out:
386 up_read(&uts_sem);
387 return error;
388}
389
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800390SYSCALL_DEFINE0(getpagesize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 return PAGE_SIZE;
393}
394
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800395SYSCALL_DEFINE0(getdtablesize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Eric Dumazet9cfe0152008-02-06 01:37:16 -0800397 return sysctl_nr_open;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400/*
401 * For compatibility with OSF/1 only. Use utsname(2) instead.
402 */
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800403SYSCALL_DEFINE2(osf_getdomainname, char __user *, name, int, namelen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405 unsigned len;
406 int i;
407
408 if (!access_ok(VERIFY_WRITE, name, namelen))
409 return -EFAULT;
410
411 len = namelen;
412 if (namelen > 32)
413 len = 32;
414
415 down_read(&uts_sem);
416 for (i = 0; i < len; ++i) {
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700417 __put_user(utsname()->domainname[i], name + i);
418 if (utsname()->domainname[i] == '\0')
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420 }
421 up_read(&uts_sem);
422
423 return 0;
424}
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426/*
427 * The following stuff should move into a header file should it ever
428 * be labeled "officially supported." Right now, there is just enough
429 * support to avoid applications (such as tar) printing error
430 * messages. The attributes are not really implemented.
431 */
432
433/*
434 * Values for Property list entry flag
435 */
436#define PLE_PROPAGATE_ON_COPY 0x1 /* cp(1) will copy entry
437 by default */
438#define PLE_FLAG_MASK 0x1 /* Valid flag values */
439#define PLE_FLAG_ALL -1 /* All flag value */
440
441struct proplistname_args {
442 unsigned int pl_mask;
443 unsigned int pl_numnames;
444 char **pl_names;
445};
446
447union pl_args {
448 struct setargs {
449 char __user *path;
450 long follow;
451 long nbytes;
452 char __user *buf;
453 } set;
454 struct fsetargs {
455 long fd;
456 long nbytes;
457 char __user *buf;
458 } fset;
459 struct getargs {
460 char __user *path;
461 long follow;
462 struct proplistname_args __user *name_args;
463 long nbytes;
464 char __user *buf;
465 int __user *min_buf_size;
466 } get;
467 struct fgetargs {
468 long fd;
469 struct proplistname_args __user *name_args;
470 long nbytes;
471 char __user *buf;
472 int __user *min_buf_size;
473 } fget;
474 struct delargs {
475 char __user *path;
476 long follow;
477 struct proplistname_args __user *name_args;
478 } del;
479 struct fdelargs {
480 long fd;
481 struct proplistname_args __user *name_args;
482 } fdel;
483};
484
485enum pl_code {
486 PL_SET = 1, PL_FSET = 2,
487 PL_GET = 3, PL_FGET = 4,
488 PL_DEL = 5, PL_FDEL = 6
489};
490
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800491SYSCALL_DEFINE2(osf_proplist_syscall, enum pl_code, code,
492 union pl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 long error;
495 int __user *min_buf_size_ptr;
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 switch (code) {
498 case PL_SET:
499 if (get_user(error, &args->set.nbytes))
500 error = -EFAULT;
501 break;
502 case PL_FSET:
503 if (get_user(error, &args->fset.nbytes))
504 error = -EFAULT;
505 break;
506 case PL_GET:
507 error = get_user(min_buf_size_ptr, &args->get.min_buf_size);
508 if (error)
509 break;
510 error = put_user(0, min_buf_size_ptr);
511 break;
512 case PL_FGET:
513 error = get_user(min_buf_size_ptr, &args->fget.min_buf_size);
514 if (error)
515 break;
516 error = put_user(0, min_buf_size_ptr);
517 break;
518 case PL_DEL:
519 case PL_FDEL:
520 error = 0;
521 break;
522 default:
523 error = -EOPNOTSUPP;
524 break;
525 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return error;
527}
528
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800529SYSCALL_DEFINE2(osf_sigstack, struct sigstack __user *, uss,
530 struct sigstack __user *, uoss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
532 unsigned long usp = rdusp();
533 unsigned long oss_sp = current->sas_ss_sp + current->sas_ss_size;
534 unsigned long oss_os = on_sig_stack(usp);
535 int error;
536
537 if (uss) {
538 void __user *ss_sp;
539
540 error = -EFAULT;
541 if (get_user(ss_sp, &uss->ss_sp))
542 goto out;
543
544 /* If the current stack was set with sigaltstack, don't
545 swap stacks while we are on it. */
546 error = -EPERM;
547 if (current->sas_ss_sp && on_sig_stack(usp))
548 goto out;
549
550 /* Since we don't know the extent of the stack, and we don't
551 track onstack-ness, but rather calculate it, we must
552 presume a size. Ho hum this interface is lossy. */
553 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
554 current->sas_ss_size = SIGSTKSZ;
555 }
556
557 if (uoss) {
558 error = -EFAULT;
559 if (! access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))
560 || __put_user(oss_sp, &uoss->ss_sp)
561 || __put_user(oss_os, &uoss->ss_onstack))
562 goto out;
563 }
564
565 error = 0;
566 out:
567 return error;
568}
569
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800570SYSCALL_DEFINE3(osf_sysinfo, int, command, char __user *, buf, long, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Joe Perches31019072010-09-14 04:23:47 -0400572 const char *sysinfo_table[] = {
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700573 utsname()->sysname,
574 utsname()->nodename,
575 utsname()->release,
576 utsname()->version,
577 utsname()->machine,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 "alpha", /* instruction set architecture */
579 "dummy", /* hardware serial number */
580 "dummy", /* hardware manufacturer */
581 "dummy", /* secure RPC domain */
582 };
583 unsigned long offset;
Joe Perches31019072010-09-14 04:23:47 -0400584 const char *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 long len, err = -EINVAL;
586
587 offset = command-1;
Tobias Klauser25c87162006-07-30 03:03:23 -0700588 if (offset >= ARRAY_SIZE(sysinfo_table)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /* Digital UNIX has a few unpublished interfaces here */
590 printk("sysinfo(%d)", command);
591 goto out;
592 }
Tobias Klauser25c87162006-07-30 03:03:23 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 down_read(&uts_sem);
595 res = sysinfo_table[offset];
596 len = strlen(res)+1;
597 if (len > count)
598 len = count;
599 if (copy_to_user(buf, res, len))
600 err = -EFAULT;
601 else
602 err = 0;
603 up_read(&uts_sem);
604 out:
605 return err;
606}
607
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800608SYSCALL_DEFINE5(osf_getsysinfo, unsigned long, op, void __user *, buffer,
609 unsigned long, nbytes, int __user *, start, void __user *, arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
611 unsigned long w;
612 struct percpu_struct *cpu;
613
614 switch (op) {
615 case GSI_IEEE_FP_CONTROL:
616 /* Return current software fp control & status bits. */
617 /* Note that DU doesn't verify available space here. */
618
619 w = current_thread_info()->ieee_state & IEEE_SW_MASK;
620 w = swcr_update_status(w, rdfpcr());
621 if (put_user(w, (unsigned long __user *) buffer))
622 return -EFAULT;
623 return 0;
624
625 case GSI_IEEE_STATE_AT_SIGNAL:
626 /*
627 * Not sure anybody will ever use this weird stuff. These
628 * ops can be used (under OSF/1) to set the fpcr that should
629 * be used when a signal handler starts executing.
630 */
631 break;
632
633 case GSI_UACPROC:
634 if (nbytes < sizeof(unsigned int))
635 return -EINVAL;
636 w = (current_thread_info()->flags >> UAC_SHIFT) & UAC_BITMASK;
637 if (put_user(w, (unsigned int __user *)buffer))
638 return -EFAULT;
639 return 1;
640
641 case GSI_PROC_TYPE:
642 if (nbytes < sizeof(unsigned long))
643 return -EINVAL;
644 cpu = (struct percpu_struct*)
645 ((char*)hwrpb + hwrpb->processor_offset);
646 w = cpu->type;
647 if (put_user(w, (unsigned long __user*)buffer))
648 return -EFAULT;
649 return 1;
650
651 case GSI_GET_HWRPB:
652 if (nbytes < sizeof(*hwrpb))
653 return -EINVAL;
654 if (copy_to_user(buffer, hwrpb, nbytes) != 0)
655 return -EFAULT;
656 return 1;
657
658 default:
659 break;
660 }
661
662 return -EOPNOTSUPP;
663}
664
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800665SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
666 unsigned long, nbytes, int __user *, start, void __user *, arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
668 switch (op) {
669 case SSI_IEEE_FP_CONTROL: {
670 unsigned long swcr, fpcr;
671 unsigned int *state;
672
673 /*
674 * Alpha Architecture Handbook 4.7.7.3:
675 * To be fully IEEE compiant, we must track the current IEEE
Simon Arlottc3a2dde2007-10-20 01:04:37 +0200676 * exception state in software, because spurious bits can be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 * set in the trap shadow of a software-complete insn.
678 */
679
680 if (get_user(swcr, (unsigned long __user *)buffer))
681 return -EFAULT;
682 state = &current_thread_info()->ieee_state;
683
684 /* Update softare trap enable bits. */
685 *state = (*state & ~IEEE_SW_MASK) | (swcr & IEEE_SW_MASK);
686
687 /* Update the real fpcr. */
688 fpcr = rdfpcr() & FPCR_DYN_MASK;
689 fpcr |= ieee_swcr_to_fpcr(swcr);
690 wrfpcr(fpcr);
691
692 return 0;
693 }
694
695 case SSI_IEEE_RAISE_EXCEPTION: {
696 unsigned long exc, swcr, fpcr, fex;
697 unsigned int *state;
698
699 if (get_user(exc, (unsigned long __user *)buffer))
700 return -EFAULT;
701 state = &current_thread_info()->ieee_state;
702 exc &= IEEE_STATUS_MASK;
703
704 /* Update softare trap enable bits. */
705 swcr = (*state & IEEE_SW_MASK) | exc;
706 *state |= exc;
707
708 /* Update the real fpcr. */
709 fpcr = rdfpcr();
710 fpcr |= ieee_swcr_to_fpcr(swcr);
711 wrfpcr(fpcr);
712
713 /* If any exceptions set by this call, and are unmasked,
714 send a signal. Old exceptions are not signaled. */
715 fex = (exc >> IEEE_STATUS_TO_EXCSUM_SHIFT) & swcr;
716 if (fex) {
717 siginfo_t info;
718 int si_code = 0;
719
720 if (fex & IEEE_TRAP_ENABLE_DNO) si_code = FPE_FLTUND;
721 if (fex & IEEE_TRAP_ENABLE_INE) si_code = FPE_FLTRES;
722 if (fex & IEEE_TRAP_ENABLE_UNF) si_code = FPE_FLTUND;
723 if (fex & IEEE_TRAP_ENABLE_OVF) si_code = FPE_FLTOVF;
724 if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
725 if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
726
727 info.si_signo = SIGFPE;
728 info.si_errno = 0;
729 info.si_code = si_code;
730 info.si_addr = NULL; /* FIXME */
731 send_sig_info(SIGFPE, &info, current);
732 }
733 return 0;
734 }
735
736 case SSI_IEEE_STATE_AT_SIGNAL:
737 case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
738 /*
739 * Not sure anybody will ever use this weird stuff. These
740 * ops can be used (under OSF/1) to set the fpcr that should
741 * be used when a signal handler starts executing.
742 */
743 break;
744
745 case SSI_NVPAIRS: {
746 unsigned long v, w, i;
747 unsigned int old, new;
748
749 for (i = 0; i < nbytes; ++i) {
750
751 if (get_user(v, 2*i + (unsigned int __user *)buffer))
752 return -EFAULT;
753 if (get_user(w, 2*i + 1 + (unsigned int __user *)buffer))
754 return -EFAULT;
755 switch (v) {
756 case SSIN_UACPROC:
757 again:
758 old = current_thread_info()->flags;
759 new = old & ~(UAC_BITMASK << UAC_SHIFT);
760 new = new | (w & UAC_BITMASK) << UAC_SHIFT;
761 if (cmpxchg(&current_thread_info()->flags,
762 old, new) != old)
763 goto again;
764 break;
765
766 default:
767 return -EOPNOTSUPP;
768 }
769 }
770 return 0;
771 }
772
773 default:
774 break;
775 }
776
777 return -EOPNOTSUPP;
778}
779
780/* Translations due to the fact that OSF's time_t is an int. Which
781 affects all sorts of things, like timeval and itimerval. */
782
783extern struct timezone sys_tz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785struct timeval32
786{
787 int tv_sec, tv_usec;
788};
789
790struct itimerval32
791{
792 struct timeval32 it_interval;
793 struct timeval32 it_value;
794};
795
796static inline long
797get_tv32(struct timeval *o, struct timeval32 __user *i)
798{
799 return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
800 (__get_user(o->tv_sec, &i->tv_sec) |
801 __get_user(o->tv_usec, &i->tv_usec)));
802}
803
804static inline long
805put_tv32(struct timeval32 __user *o, struct timeval *i)
806{
807 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
808 (__put_user(i->tv_sec, &o->tv_sec) |
809 __put_user(i->tv_usec, &o->tv_usec)));
810}
811
812static inline long
813get_it32(struct itimerval *o, struct itimerval32 __user *i)
814{
815 return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
816 (__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |
817 __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |
818 __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |
819 __get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));
820}
821
822static inline long
823put_it32(struct itimerval32 __user *o, struct itimerval *i)
824{
825 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
826 (__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |
827 __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |
828 __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |
829 __put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));
830}
831
832static inline void
833jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
834{
835 value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
836 value->tv_sec = jiffies / HZ;
837}
838
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800839SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
840 struct timezone __user *, tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
842 if (tv) {
843 struct timeval ktv;
844 do_gettimeofday(&ktv);
845 if (put_tv32(tv, &ktv))
846 return -EFAULT;
847 }
848 if (tz) {
849 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
850 return -EFAULT;
851 }
852 return 0;
853}
854
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800855SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
856 struct timezone __user *, tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 struct timespec kts;
859 struct timezone ktz;
860
861 if (tv) {
862 if (get_tv32((struct timeval *)&kts, tv))
863 return -EFAULT;
864 }
865 if (tz) {
866 if (copy_from_user(&ktz, tz, sizeof(*tz)))
867 return -EFAULT;
868 }
869
870 kts.tv_nsec *= 1000;
871
872 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
873}
874
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800875SYSCALL_DEFINE2(osf_getitimer, int, which, struct itimerval32 __user *, it)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
877 struct itimerval kit;
878 int error;
879
880 error = do_getitimer(which, &kit);
881 if (!error && put_it32(it, &kit))
882 error = -EFAULT;
883
884 return error;
885}
886
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800887SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
888 struct itimerval32 __user *, out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
890 struct itimerval kin, kout;
891 int error;
892
893 if (in) {
894 if (get_it32(&kin, in))
895 return -EFAULT;
896 } else
897 memset(&kin, 0, sizeof(kin));
898
899 error = do_setitimer(which, &kin, out ? &kout : NULL);
900 if (error || !out)
901 return error;
902
903 if (put_it32(out, &kout))
904 return -EFAULT;
905
906 return 0;
907
908}
909
David Howellsc7887322010-08-11 11:26:22 +0100910SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800911 struct timeval32 __user *, tvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700913 struct timespec tv[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 if (tvs) {
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700916 struct timeval ktvs[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (get_tv32(&ktvs[0], &tvs[0]) ||
918 get_tv32(&ktvs[1], &tvs[1]))
919 return -EFAULT;
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700920
921 if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
922 ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
923 return -EINVAL;
924
925 tv[0].tv_sec = ktvs[0].tv_sec;
926 tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
927 tv[1].tv_sec = ktvs[1].tv_sec;
928 tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 }
930
Ulrich Drepper1c710c82007-05-08 00:33:25 -0700931 return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800934SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
935 fd_set __user *, exp, struct timeval32 __user *, tvp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Arjan van de Ven14e2acd2008-10-06 13:01:53 -0700937 struct timespec end_time, *to = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (tvp) {
939 time_t sec, usec;
940
Arjan van de Ven14e2acd2008-10-06 13:01:53 -0700941 to = &end_time;
942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (!access_ok(VERIFY_READ, tvp, sizeof(*tvp))
944 || __get_user(sec, &tvp->tv_sec)
945 || __get_user(usec, &tvp->tv_usec)) {
Al Viroa2dcb442008-04-23 14:05:15 -0400946 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
949 if (sec < 0 || usec < 0)
Al Viroa2dcb442008-04-23 14:05:15 -0400950 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Arjan van de Ven14e2acd2008-10-06 13:01:53 -0700952 if (poll_select_set_timeout(to, sec, usec * NSEC_PER_USEC))
953 return -EINVAL;
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 }
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 /* OSF does not copy back the remaining time. */
Arjan van de Ven14e2acd2008-10-06 13:01:53 -0700958 return core_sys_select(n, inp, outp, exp, to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
961struct rusage32 {
962 struct timeval32 ru_utime; /* user time used */
963 struct timeval32 ru_stime; /* system time used */
964 long ru_maxrss; /* maximum resident set size */
965 long ru_ixrss; /* integral shared memory size */
966 long ru_idrss; /* integral unshared data size */
967 long ru_isrss; /* integral unshared stack size */
968 long ru_minflt; /* page reclaims */
969 long ru_majflt; /* page faults */
970 long ru_nswap; /* swaps */
971 long ru_inblock; /* block input operations */
972 long ru_oublock; /* block output operations */
973 long ru_msgsnd; /* messages sent */
974 long ru_msgrcv; /* messages received */
975 long ru_nsignals; /* signals received */
976 long ru_nvcsw; /* voluntary context switches */
977 long ru_nivcsw; /* involuntary " */
978};
979
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -0800980SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
982 struct rusage32 r;
983
984 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
985 return -EINVAL;
986
987 memset(&r, 0, sizeof(r));
988 switch (who) {
989 case RUSAGE_SELF:
990 jiffies_to_timeval32(current->utime, &r.ru_utime);
991 jiffies_to_timeval32(current->stime, &r.ru_stime);
992 r.ru_minflt = current->min_flt;
993 r.ru_majflt = current->maj_flt;
994 break;
995 case RUSAGE_CHILDREN:
996 jiffies_to_timeval32(current->signal->cutime, &r.ru_utime);
997 jiffies_to_timeval32(current->signal->cstime, &r.ru_stime);
998 r.ru_minflt = current->signal->cmin_flt;
999 r.ru_majflt = current->signal->cmaj_flt;
1000 break;
1001 }
1002
1003 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
1004}
1005
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -08001006SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
1007 struct rusage32 __user *, ur)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
1009 struct rusage r;
1010 long ret, err;
1011 mm_segment_t old_fs;
1012
1013 if (!ur)
1014 return sys_wait4(pid, ustatus, options, NULL);
1015
1016 old_fs = get_fs();
1017
1018 set_fs (KERNEL_DS);
1019 ret = sys_wait4(pid, ustatus, options, (struct rusage __user *) &r);
1020 set_fs (old_fs);
1021
1022 if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
1023 return -EFAULT;
1024
1025 err = 0;
1026 err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
1027 err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
1028 err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
1029 err |= __put_user(r.ru_stime.tv_usec, &ur->ru_stime.tv_usec);
1030 err |= __put_user(r.ru_maxrss, &ur->ru_maxrss);
1031 err |= __put_user(r.ru_ixrss, &ur->ru_ixrss);
1032 err |= __put_user(r.ru_idrss, &ur->ru_idrss);
1033 err |= __put_user(r.ru_isrss, &ur->ru_isrss);
1034 err |= __put_user(r.ru_minflt, &ur->ru_minflt);
1035 err |= __put_user(r.ru_majflt, &ur->ru_majflt);
1036 err |= __put_user(r.ru_nswap, &ur->ru_nswap);
1037 err |= __put_user(r.ru_inblock, &ur->ru_inblock);
1038 err |= __put_user(r.ru_oublock, &ur->ru_oublock);
1039 err |= __put_user(r.ru_msgsnd, &ur->ru_msgsnd);
1040 err |= __put_user(r.ru_msgrcv, &ur->ru_msgrcv);
1041 err |= __put_user(r.ru_nsignals, &ur->ru_nsignals);
1042 err |= __put_user(r.ru_nvcsw, &ur->ru_nvcsw);
1043 err |= __put_user(r.ru_nivcsw, &ur->ru_nivcsw);
1044
1045 return err ? err : ret;
1046}
1047
1048/*
1049 * I don't know what the parameters are: the first one
1050 * seems to be a timeval pointer, and I suspect the second
1051 * one is the time remaining.. Ho humm.. No documentation.
1052 */
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -08001053SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
1054 struct timeval32 __user *, remain)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
1056 struct timeval tmp;
1057 unsigned long ticks;
1058
1059 if (get_tv32(&tmp, sleep))
1060 goto fault;
1061
Nishanth Aravamudan24d568e2005-05-16 21:53:55 -07001062 ticks = timeval_to_jiffies(&tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Nishanth Aravamudan20c6abd2005-09-10 00:27:25 -07001064 ticks = schedule_timeout_interruptible(ticks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 if (remain) {
Nishanth Aravamudan24d568e2005-05-16 21:53:55 -07001067 jiffies_to_timeval(ticks, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 if (put_tv32(remain, &tmp))
1069 goto fault;
1070 }
1071
1072 return 0;
1073 fault:
1074 return -EFAULT;
1075}
1076
1077
1078struct timex32 {
1079 unsigned int modes; /* mode selector */
1080 long offset; /* time offset (usec) */
1081 long freq; /* frequency offset (scaled ppm) */
1082 long maxerror; /* maximum error (usec) */
1083 long esterror; /* estimated error (usec) */
1084 int status; /* clock command/status */
1085 long constant; /* pll time constant */
1086 long precision; /* clock precision (usec) (read only) */
1087 long tolerance; /* clock frequency tolerance (ppm)
1088 * (read only)
1089 */
1090 struct timeval32 time; /* (read only) */
1091 long tick; /* (modified) usecs between clock ticks */
1092
1093 long ppsfreq; /* pps frequency (scaled ppm) (ro) */
1094 long jitter; /* pps jitter (us) (ro) */
1095 int shift; /* interval duration (s) (shift) (ro) */
1096 long stabil; /* pps stability (scaled ppm) (ro) */
1097 long jitcnt; /* jitter limit exceeded (ro) */
1098 long calcnt; /* calibration intervals (ro) */
1099 long errcnt; /* calibration errors (ro) */
1100 long stbcnt; /* stability limit exceeded (ro) */
1101
1102 int :32; int :32; int :32; int :32;
1103 int :32; int :32; int :32; int :32;
1104 int :32; int :32; int :32; int :32;
1105};
1106
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -08001107SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
1109 struct timex txc;
1110 int ret;
1111
1112 /* copy relevant bits of struct timex. */
1113 if (copy_from_user(&txc, txc_p, offsetof(struct timex32, time)) ||
1114 copy_from_user(&txc.tick, &txc_p->tick, sizeof(struct timex32) -
1115 offsetof(struct timex32, time)))
1116 return -EFAULT;
1117
1118 ret = do_adjtimex(&txc);
1119 if (ret < 0)
1120 return ret;
1121
1122 /* copy back to timex32 */
1123 if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
1124 (copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
1125 offsetof(struct timex32, tick))) ||
1126 (put_tv32(&txc_p->time, &txc.time)))
1127 return -EFAULT;
1128
1129 return ret;
1130}
1131
1132/* Get an address range which is currently unmapped. Similar to the
1133 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
1134
1135static unsigned long
1136arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1137 unsigned long limit)
1138{
1139 struct vm_area_struct *vma = find_vma(current->mm, addr);
1140
1141 while (1) {
1142 /* At this point: (!vma || addr < vma->vm_end). */
1143 if (limit - len < addr)
1144 return -ENOMEM;
1145 if (!vma || addr + len <= vma->vm_start)
1146 return addr;
1147 addr = vma->vm_end;
1148 vma = vma->vm_next;
1149 }
1150}
1151
1152unsigned long
1153arch_get_unmapped_area(struct file *filp, unsigned long addr,
1154 unsigned long len, unsigned long pgoff,
1155 unsigned long flags)
1156{
1157 unsigned long limit;
1158
1159 /* "32 bit" actually means 31 bit, since pointers sign extend. */
1160 if (current->personality & ADDR_LIMIT_32BIT)
1161 limit = 0x80000000;
1162 else
1163 limit = TASK_SIZE;
1164
1165 if (len > limit)
1166 return -ENOMEM;
1167
Benjamin Herrenschmidt4b87b3b2007-05-06 14:50:06 -07001168 if (flags & MAP_FIXED)
1169 return addr;
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /* First, see if the given suggestion fits.
1172
1173 The OSF/1 loader (/sbin/loader) relies on us returning an
1174 address larger than the requested if one exists, which is
1175 a terribly broken way to program.
1176
1177 That said, I can see the use in being able to suggest not
1178 merely specific addresses, but regions of memory -- perhaps
1179 this feature should be incorporated into all ports? */
1180
1181 if (addr) {
1182 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1183 if (addr != (unsigned long) -ENOMEM)
1184 return addr;
1185 }
1186
1187 /* Next, try allocating at TASK_UNMAPPED_BASE. */
1188 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1189 len, limit);
1190 if (addr != (unsigned long) -ENOMEM)
1191 return addr;
1192
1193 /* Finally, try allocating in low memory. */
1194 addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
1195
1196 return addr;
1197}
1198
1199#ifdef CONFIG_OSF4_COMPAT
1200
1201/* Clear top 32 bits of iov_len in the user's buffer for
1202 compatibility with old versions of OSF/1 where iov_len
1203 was defined as int. */
1204static int
1205osf_fix_iov_len(const struct iovec __user *iov, unsigned long count)
1206{
1207 unsigned long i;
1208
1209 for (i = 0 ; i < count ; i++) {
1210 int __user *iov_len_high = (int __user *)&iov[i].iov_len + 1;
1211
1212 if (put_user(0, iov_len_high))
1213 return -EFAULT;
1214 }
1215 return 0;
1216}
1217
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -08001218SYSCALL_DEFINE3(osf_readv, unsigned long, fd,
1219 const struct iovec __user *, vector, unsigned long, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
1221 if (unlikely(personality(current->personality) == PER_OSF4))
1222 if (osf_fix_iov_len(vector, count))
1223 return -EFAULT;
1224 return sys_readv(fd, vector, count);
1225}
1226
Ivan Kokshayskye5d9a902009-01-29 14:25:18 -08001227SYSCALL_DEFINE3(osf_writev, unsigned long, fd,
1228 const struct iovec __user *, vector, unsigned long, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
1230 if (unlikely(personality(current->personality) == PER_OSF4))
1231 if (osf_fix_iov_len(vector, count))
1232 return -EFAULT;
1233 return sys_writev(fd, vector, count);
1234}
1235
1236#endif