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