osf_sys.c 30 KB

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