osf_sys.c 30 KB

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