osf_sys.c 30 KB

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