sys_sunos.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /* $Id: sys_sunos.c,v 1.137 2002/02/08 03:57:14 davem Exp $
  2. * sys_sunos.c: SunOS specific syscall compatibility support.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. *
  7. * Based upon preliminary work which is:
  8. *
  9. * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/mman.h>
  16. #include <linux/mm.h>
  17. #include <linux/swap.h>
  18. #include <linux/fs.h>
  19. #include <linux/file.h>
  20. #include <linux/resource.h>
  21. #include <linux/ipc.h>
  22. #include <linux/shm.h>
  23. #include <linux/msg.h>
  24. #include <linux/sem.h>
  25. #include <linux/signal.h>
  26. #include <linux/uio.h>
  27. #include <linux/utsname.h>
  28. #include <linux/major.h>
  29. #include <linux/stat.h>
  30. #include <linux/slab.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/capability.h>
  33. #include <linux/errno.h>
  34. #include <linux/smp.h>
  35. #include <linux/smp_lock.h>
  36. #include <linux/syscalls.h>
  37. #include <net/sock.h>
  38. #include <asm/uaccess.h>
  39. #ifndef KERNEL_DS
  40. #include <linux/segment.h>
  41. #endif
  42. #include <asm/page.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/pconf.h>
  45. #include <asm/idprom.h> /* for gethostid() */
  46. #include <asm/unistd.h>
  47. #include <asm/system.h>
  48. /* For the nfs mount emulation */
  49. #include <linux/socket.h>
  50. #include <linux/in.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs2.h>
  53. #include <linux/nfs_mount.h>
  54. /* for sunos_select */
  55. #include <linux/time.h>
  56. #include <linux/personality.h>
  57. /* NR_OPEN is now larger and dynamic in recent kernels. */
  58. #define SUNOS_NR_OPEN 256
  59. /* We use the SunOS mmap() semantics. */
  60. asmlinkage unsigned long sunos_mmap(unsigned long addr, unsigned long len,
  61. unsigned long prot, unsigned long flags,
  62. unsigned long fd, unsigned long off)
  63. {
  64. struct file * file = NULL;
  65. unsigned long retval, ret_type;
  66. if (flags & MAP_NORESERVE) {
  67. static int cnt;
  68. if (cnt++ < 10)
  69. printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
  70. current->comm);
  71. flags &= ~MAP_NORESERVE;
  72. }
  73. retval = -EBADF;
  74. if (!(flags & MAP_ANONYMOUS)) {
  75. if (fd >= SUNOS_NR_OPEN)
  76. goto out;
  77. file = fget(fd);
  78. if (!file)
  79. goto out;
  80. }
  81. retval = -EINVAL;
  82. /* If this is ld.so or a shared library doing an mmap
  83. * of /dev/zero, transform it into an anonymous mapping.
  84. * SunOS is so stupid some times... hmph!
  85. */
  86. if (file) {
  87. if (imajor(file->f_path.dentry->d_inode) == MEM_MAJOR &&
  88. iminor(file->f_path.dentry->d_inode) == 5) {
  89. flags |= MAP_ANONYMOUS;
  90. fput(file);
  91. file = NULL;
  92. }
  93. }
  94. ret_type = flags & _MAP_NEW;
  95. flags &= ~_MAP_NEW;
  96. if (!(flags & MAP_FIXED))
  97. addr = 0;
  98. else {
  99. if (ARCH_SUN4C_SUN4 &&
  100. (len > 0x20000000 ||
  101. ((flags & MAP_FIXED) &&
  102. addr < 0xe0000000 && addr + len > 0x20000000)))
  103. goto out_putf;
  104. /* See asm-sparc/uaccess.h */
  105. if (len > TASK_SIZE - PAGE_SIZE ||
  106. addr + len > TASK_SIZE - PAGE_SIZE)
  107. goto out_putf;
  108. }
  109. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  110. down_write(&current->mm->mmap_sem);
  111. retval = do_mmap(file, addr, len, prot, flags, off);
  112. up_write(&current->mm->mmap_sem);
  113. if (!ret_type)
  114. retval = ((retval < PAGE_OFFSET) ? 0 : retval);
  115. out_putf:
  116. if (file)
  117. fput(file);
  118. out:
  119. return retval;
  120. }
  121. /* lmbench calls this, just say "yeah, ok" */
  122. asmlinkage int sunos_mctl(unsigned long addr, unsigned long len, int function, char *arg)
  123. {
  124. return 0;
  125. }
  126. /* SunOS is completely broken... it returns 0 on success, otherwise
  127. * ENOMEM. For sys_sbrk() it wants the old brk value as a return
  128. * on success and ENOMEM as before on failure.
  129. */
  130. asmlinkage int sunos_brk(unsigned long brk)
  131. {
  132. int freepages, retval = -ENOMEM;
  133. unsigned long rlim;
  134. unsigned long newbrk, oldbrk;
  135. down_write(&current->mm->mmap_sem);
  136. if (ARCH_SUN4C_SUN4) {
  137. if (brk >= 0x20000000 && brk < 0xe0000000) {
  138. goto out;
  139. }
  140. }
  141. if (brk < current->mm->end_code)
  142. goto out;
  143. newbrk = PAGE_ALIGN(brk);
  144. oldbrk = PAGE_ALIGN(current->mm->brk);
  145. retval = 0;
  146. if (oldbrk == newbrk) {
  147. current->mm->brk = brk;
  148. goto out;
  149. }
  150. /*
  151. * Always allow shrinking brk
  152. */
  153. if (brk <= current->mm->brk) {
  154. current->mm->brk = brk;
  155. do_munmap(current->mm, newbrk, oldbrk-newbrk);
  156. goto out;
  157. }
  158. /*
  159. * Check against rlimit and stack..
  160. */
  161. retval = -ENOMEM;
  162. rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
  163. if (rlim >= RLIM_INFINITY)
  164. rlim = ~0;
  165. if (brk - current->mm->end_code > rlim)
  166. goto out;
  167. /*
  168. * Check against existing mmap mappings.
  169. */
  170. if (find_vma_intersection(current->mm, oldbrk, newbrk+PAGE_SIZE))
  171. goto out;
  172. /*
  173. * stupid algorithm to decide if we have enough memory: while
  174. * simple, it hopefully works in most obvious cases.. Easy to
  175. * fool it, but this should catch most mistakes.
  176. */
  177. freepages = global_page_state(NR_FILE_PAGES);
  178. freepages >>= 1;
  179. freepages += nr_free_pages();
  180. freepages += nr_swap_pages;
  181. freepages -= num_physpages >> 4;
  182. freepages -= (newbrk-oldbrk) >> PAGE_SHIFT;
  183. if (freepages < 0)
  184. goto out;
  185. /*
  186. * Ok, we have probably got enough memory - let it rip.
  187. */
  188. current->mm->brk = brk;
  189. do_brk(oldbrk, newbrk-oldbrk);
  190. retval = 0;
  191. out:
  192. up_write(&current->mm->mmap_sem);
  193. return retval;
  194. }
  195. asmlinkage unsigned long sunos_sbrk(int increment)
  196. {
  197. int error;
  198. unsigned long oldbrk;
  199. /* This should do it hopefully... */
  200. lock_kernel();
  201. oldbrk = current->mm->brk;
  202. error = sunos_brk(((int) current->mm->brk) + increment);
  203. if (!error)
  204. error = oldbrk;
  205. unlock_kernel();
  206. return error;
  207. }
  208. /* XXX Completely undocumented, and completely magic...
  209. * XXX I believe it is to increase the size of the stack by
  210. * XXX argument 'increment' and return the new end of stack
  211. * XXX area. Wheee...
  212. */
  213. asmlinkage unsigned long sunos_sstk(int increment)
  214. {
  215. lock_kernel();
  216. printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
  217. current->comm, increment);
  218. unlock_kernel();
  219. return -1;
  220. }
  221. /* Give hints to the kernel as to what paging strategy to use...
  222. * Completely bogus, don't remind me.
  223. */
  224. #define VA_NORMAL 0 /* Normal vm usage expected */
  225. #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
  226. #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
  227. #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
  228. static char *vstrings[] = {
  229. "VA_NORMAL",
  230. "VA_ABNORMAL",
  231. "VA_SEQUENTIAL",
  232. "VA_INVALIDATE",
  233. };
  234. asmlinkage void sunos_vadvise(unsigned long strategy)
  235. {
  236. /* I wanna see who uses this... */
  237. lock_kernel();
  238. printk("%s: Advises us to use %s paging strategy\n",
  239. current->comm,
  240. strategy <= 3 ? vstrings[strategy] : "BOGUS");
  241. unlock_kernel();
  242. }
  243. /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
  244. * resource limit and is for backwards compatibility with older sunos
  245. * revs.
  246. */
  247. asmlinkage long sunos_getdtablesize(void)
  248. {
  249. return SUNOS_NR_OPEN;
  250. }
  251. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  252. asmlinkage unsigned long sunos_sigblock(unsigned long blk_mask)
  253. {
  254. unsigned long old;
  255. spin_lock_irq(&current->sighand->siglock);
  256. old = current->blocked.sig[0];
  257. current->blocked.sig[0] |= (blk_mask & _BLOCKABLE);
  258. recalc_sigpending();
  259. spin_unlock_irq(&current->sighand->siglock);
  260. return old;
  261. }
  262. asmlinkage unsigned long sunos_sigsetmask(unsigned long newmask)
  263. {
  264. unsigned long retval;
  265. spin_lock_irq(&current->sighand->siglock);
  266. retval = current->blocked.sig[0];
  267. current->blocked.sig[0] = (newmask & _BLOCKABLE);
  268. recalc_sigpending();
  269. spin_unlock_irq(&current->sighand->siglock);
  270. return retval;
  271. }
  272. /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
  273. /* getdents system call, the format of the structure just has a different */
  274. /* layout (d_off+d_ino instead of d_ino+d_off) */
  275. struct sunos_dirent {
  276. long d_off;
  277. unsigned long d_ino;
  278. unsigned short d_reclen;
  279. unsigned short d_namlen;
  280. char d_name[1];
  281. };
  282. struct sunos_dirent_callback {
  283. struct sunos_dirent __user *curr;
  284. struct sunos_dirent __user *previous;
  285. int count;
  286. int error;
  287. };
  288. #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
  289. #define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
  290. static int sunos_filldir(void * __buf, const char * name, int namlen,
  291. loff_t offset, u64 ino, unsigned int d_type)
  292. {
  293. struct sunos_dirent __user *dirent;
  294. struct sunos_dirent_callback * buf = __buf;
  295. unsigned long d_ino;
  296. int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
  297. buf->error = -EINVAL; /* only used if we fail.. */
  298. if (reclen > buf->count)
  299. return -EINVAL;
  300. d_ino = ino;
  301. if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
  302. return -EOVERFLOW;
  303. dirent = buf->previous;
  304. if (dirent)
  305. put_user(offset, &dirent->d_off);
  306. dirent = buf->curr;
  307. buf->previous = dirent;
  308. put_user(d_ino, &dirent->d_ino);
  309. put_user(namlen, &dirent->d_namlen);
  310. put_user(reclen, &dirent->d_reclen);
  311. copy_to_user(dirent->d_name, name, namlen);
  312. put_user(0, dirent->d_name + namlen);
  313. dirent = (void __user *) dirent + reclen;
  314. buf->curr = dirent;
  315. buf->count -= reclen;
  316. return 0;
  317. }
  318. asmlinkage int sunos_getdents(unsigned int fd, void __user *dirent, int cnt)
  319. {
  320. struct file * file;
  321. struct sunos_dirent __user *lastdirent;
  322. struct sunos_dirent_callback buf;
  323. int error = -EBADF;
  324. if (fd >= SUNOS_NR_OPEN)
  325. goto out;
  326. file = fget(fd);
  327. if (!file)
  328. goto out;
  329. error = -EINVAL;
  330. if (cnt < (sizeof(struct sunos_dirent) + 255))
  331. goto out_putf;
  332. buf.curr = (struct sunos_dirent __user *) dirent;
  333. buf.previous = NULL;
  334. buf.count = cnt;
  335. buf.error = 0;
  336. error = vfs_readdir(file, sunos_filldir, &buf);
  337. if (error < 0)
  338. goto out_putf;
  339. lastdirent = buf.previous;
  340. error = buf.error;
  341. if (lastdirent) {
  342. put_user(file->f_pos, &lastdirent->d_off);
  343. error = cnt - buf.count;
  344. }
  345. out_putf:
  346. fput(file);
  347. out:
  348. return error;
  349. }
  350. /* Old sunos getdirentries, severely broken compatibility stuff here. */
  351. struct sunos_direntry {
  352. unsigned long d_ino;
  353. unsigned short d_reclen;
  354. unsigned short d_namlen;
  355. char d_name[1];
  356. };
  357. struct sunos_direntry_callback {
  358. struct sunos_direntry __user *curr;
  359. struct sunos_direntry __user *previous;
  360. int count;
  361. int error;
  362. };
  363. static int sunos_filldirentry(void * __buf, const char * name, int namlen,
  364. loff_t offset, u64 ino, unsigned int d_type)
  365. {
  366. struct sunos_direntry __user *dirent;
  367. struct sunos_direntry_callback *buf = __buf;
  368. unsigned long d_ino;
  369. int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
  370. buf->error = -EINVAL; /* only used if we fail.. */
  371. if (reclen > buf->count)
  372. return -EINVAL;
  373. d_ino = ino;
  374. if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
  375. return -EOVERFLOW;
  376. dirent = buf->previous;
  377. dirent = buf->curr;
  378. buf->previous = dirent;
  379. put_user(d_ino, &dirent->d_ino);
  380. put_user(namlen, &dirent->d_namlen);
  381. put_user(reclen, &dirent->d_reclen);
  382. copy_to_user(dirent->d_name, name, namlen);
  383. put_user(0, dirent->d_name + namlen);
  384. dirent = (void __user *) dirent + reclen;
  385. buf->curr = dirent;
  386. buf->count -= reclen;
  387. return 0;
  388. }
  389. asmlinkage int sunos_getdirentries(unsigned int fd, void __user *dirent,
  390. int cnt, unsigned int __user *basep)
  391. {
  392. struct file * file;
  393. struct sunos_direntry __user *lastdirent;
  394. struct sunos_direntry_callback buf;
  395. int error = -EBADF;
  396. if (fd >= SUNOS_NR_OPEN)
  397. goto out;
  398. file = fget(fd);
  399. if (!file)
  400. goto out;
  401. error = -EINVAL;
  402. if (cnt < (sizeof(struct sunos_direntry) + 255))
  403. goto out_putf;
  404. buf.curr = (struct sunos_direntry __user *) dirent;
  405. buf.previous = NULL;
  406. buf.count = cnt;
  407. buf.error = 0;
  408. error = vfs_readdir(file, sunos_filldirentry, &buf);
  409. if (error < 0)
  410. goto out_putf;
  411. lastdirent = buf.previous;
  412. error = buf.error;
  413. if (lastdirent) {
  414. put_user(file->f_pos, basep);
  415. error = cnt - buf.count;
  416. }
  417. out_putf:
  418. fput(file);
  419. out:
  420. return error;
  421. }
  422. struct sunos_utsname {
  423. char sname[9];
  424. char nname[9];
  425. char nnext[56];
  426. char rel[9];
  427. char ver[9];
  428. char mach[9];
  429. };
  430. asmlinkage int sunos_uname(struct sunos_utsname __user *name)
  431. {
  432. int ret;
  433. down_read(&uts_sem);
  434. ret = copy_to_user(&name->sname[0], &utsname()->sysname[0],
  435. sizeof(name->sname) - 1);
  436. if (!ret) {
  437. ret |= __copy_to_user(&name->nname[0], &utsname()->nodename[0],
  438. sizeof(name->nname) - 1);
  439. ret |= __put_user('\0', &name->nname[8]);
  440. ret |= __copy_to_user(&name->rel[0], &utsname()->release[0],
  441. sizeof(name->rel) - 1);
  442. ret |= __copy_to_user(&name->ver[0], &utsname()->version[0],
  443. sizeof(name->ver) - 1);
  444. ret |= __copy_to_user(&name->mach[0], &utsname()->machine[0],
  445. sizeof(name->mach) - 1);
  446. }
  447. up_read(&uts_sem);
  448. return ret ? -EFAULT : 0;
  449. }
  450. asmlinkage int sunos_nosys(void)
  451. {
  452. struct pt_regs *regs;
  453. siginfo_t info;
  454. static int cnt;
  455. lock_kernel();
  456. regs = current->thread.kregs;
  457. info.si_signo = SIGSYS;
  458. info.si_errno = 0;
  459. info.si_code = __SI_FAULT|0x100;
  460. info.si_addr = (void __user *)regs->pc;
  461. info.si_trapno = regs->u_regs[UREG_G1];
  462. send_sig_info(SIGSYS, &info, current);
  463. if (cnt++ < 4) {
  464. printk("Process makes ni_syscall number %d, register dump:\n",
  465. (int) regs->u_regs[UREG_G1]);
  466. show_regs(regs);
  467. }
  468. unlock_kernel();
  469. return -ENOSYS;
  470. }
  471. /* This is not a real and complete implementation yet, just to keep
  472. * the easy SunOS binaries happy.
  473. */
  474. asmlinkage int sunos_fpathconf(int fd, int name)
  475. {
  476. int ret;
  477. switch(name) {
  478. case _PCONF_LINK:
  479. ret = LINK_MAX;
  480. break;
  481. case _PCONF_CANON:
  482. ret = MAX_CANON;
  483. break;
  484. case _PCONF_INPUT:
  485. ret = MAX_INPUT;
  486. break;
  487. case _PCONF_NAME:
  488. ret = NAME_MAX;
  489. break;
  490. case _PCONF_PATH:
  491. ret = PATH_MAX;
  492. break;
  493. case _PCONF_PIPE:
  494. ret = PIPE_BUF;
  495. break;
  496. case _PCONF_CHRESTRICT: /* XXX Investigate XXX */
  497. ret = 1;
  498. break;
  499. case _PCONF_NOTRUNC: /* XXX Investigate XXX */
  500. case _PCONF_VDISABLE:
  501. ret = 0;
  502. break;
  503. default:
  504. ret = -EINVAL;
  505. break;
  506. }
  507. return ret;
  508. }
  509. asmlinkage int sunos_pathconf(char __user *path, int name)
  510. {
  511. int ret;
  512. ret = sunos_fpathconf(0, name); /* XXX cheese XXX */
  513. return ret;
  514. }
  515. /* SunOS mount system call emulation */
  516. asmlinkage int sunos_select(int width, fd_set __user *inp, fd_set __user *outp,
  517. fd_set __user *exp, struct timeval __user *tvp)
  518. {
  519. int ret;
  520. /* SunOS binaries expect that select won't change the tvp contents */
  521. ret = sys_select (width, inp, outp, exp, tvp);
  522. if (ret == -EINTR && tvp) {
  523. time_t sec, usec;
  524. __get_user(sec, &tvp->tv_sec);
  525. __get_user(usec, &tvp->tv_usec);
  526. if (sec == 0 && usec == 0)
  527. ret = 0;
  528. }
  529. return ret;
  530. }
  531. asmlinkage void sunos_nop(void)
  532. {
  533. return;
  534. }
  535. /* SunOS mount/umount. */
  536. #define SMNT_RDONLY 1
  537. #define SMNT_NOSUID 2
  538. #define SMNT_NEWTYPE 4
  539. #define SMNT_GRPID 8
  540. #define SMNT_REMOUNT 16
  541. #define SMNT_NOSUB 32
  542. #define SMNT_MULTI 64
  543. #define SMNT_SYS5 128
  544. struct sunos_fh_t {
  545. char fh_data [NFS_FHSIZE];
  546. };
  547. struct sunos_nfs_mount_args {
  548. struct sockaddr_in __user *addr; /* file server address */
  549. struct nfs_fh __user *fh; /* File handle to be mounted */
  550. int flags; /* flags */
  551. int wsize; /* write size in bytes */
  552. int rsize; /* read size in bytes */
  553. int timeo; /* initial timeout in .1 secs */
  554. int retrans; /* times to retry send */
  555. char __user *hostname; /* server's hostname */
  556. int acregmin; /* attr cache file min secs */
  557. int acregmax; /* attr cache file max secs */
  558. int acdirmin; /* attr cache dir min secs */
  559. int acdirmax; /* attr cache dir max secs */
  560. char __user *netname; /* server's netname */
  561. };
  562. /* Bind the socket on a local reserved port and connect it to the
  563. * remote server. This on Linux/i386 is done by the mount program,
  564. * not by the kernel.
  565. */
  566. static int
  567. sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
  568. {
  569. struct sockaddr_in local;
  570. struct sockaddr_in server;
  571. int try_port;
  572. struct socket *socket;
  573. struct inode *inode;
  574. struct file *file;
  575. int ret, result = 0;
  576. file = fget(fd);
  577. if (!file)
  578. goto out;
  579. inode = file->f_path.dentry->d_inode;
  580. socket = SOCKET_I(inode);
  581. local.sin_family = AF_INET;
  582. local.sin_addr.s_addr = INADDR_ANY;
  583. /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
  584. try_port = 1024;
  585. do {
  586. local.sin_port = htons (--try_port);
  587. ret = socket->ops->bind(socket, (struct sockaddr*)&local,
  588. sizeof(local));
  589. } while (ret && try_port > (1024 / 2));
  590. if (ret)
  591. goto out_putf;
  592. server.sin_family = AF_INET;
  593. server.sin_addr = addr->sin_addr;
  594. server.sin_port = NFS_PORT;
  595. /* Call sys_connect */
  596. ret = socket->ops->connect (socket, (struct sockaddr *) &server,
  597. sizeof (server), file->f_flags);
  598. if (ret >= 0)
  599. result = 1;
  600. out_putf:
  601. fput(file);
  602. out:
  603. return result;
  604. }
  605. static int get_default (int value, int def_value)
  606. {
  607. if (value)
  608. return value;
  609. else
  610. return def_value;
  611. }
  612. static int sunos_nfs_mount(char *dir_name, int linux_flags, void __user *data)
  613. {
  614. int server_fd, err;
  615. char *the_name, *mount_page;
  616. struct nfs_mount_data linux_nfs_mount;
  617. struct sunos_nfs_mount_args sunos_mount;
  618. /* Ok, here comes the fun part: Linux's nfs mount needs a
  619. * socket connection to the server, but SunOS mount does not
  620. * require this, so we use the information on the destination
  621. * address to create a socket and bind it to a reserved
  622. * port on this system
  623. */
  624. if (copy_from_user(&sunos_mount, data, sizeof(sunos_mount)))
  625. return -EFAULT;
  626. server_fd = sys_socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  627. if (server_fd < 0)
  628. return -ENXIO;
  629. if (copy_from_user(&linux_nfs_mount.addr,sunos_mount.addr,
  630. sizeof(*sunos_mount.addr)) ||
  631. copy_from_user(&linux_nfs_mount.root,sunos_mount.fh,
  632. sizeof(*sunos_mount.fh))) {
  633. sys_close (server_fd);
  634. return -EFAULT;
  635. }
  636. if (!sunos_nfs_get_server_fd (server_fd, &linux_nfs_mount.addr)){
  637. sys_close (server_fd);
  638. return -ENXIO;
  639. }
  640. /* Now, bind it to a locally reserved port */
  641. linux_nfs_mount.version = NFS_MOUNT_VERSION;
  642. linux_nfs_mount.flags = sunos_mount.flags;
  643. linux_nfs_mount.fd = server_fd;
  644. linux_nfs_mount.rsize = get_default (sunos_mount.rsize, 8192);
  645. linux_nfs_mount.wsize = get_default (sunos_mount.wsize, 8192);
  646. linux_nfs_mount.timeo = get_default (sunos_mount.timeo, 10);
  647. linux_nfs_mount.retrans = sunos_mount.retrans;
  648. linux_nfs_mount.acregmin = sunos_mount.acregmin;
  649. linux_nfs_mount.acregmax = sunos_mount.acregmax;
  650. linux_nfs_mount.acdirmin = sunos_mount.acdirmin;
  651. linux_nfs_mount.acdirmax = sunos_mount.acdirmax;
  652. the_name = getname(sunos_mount.hostname);
  653. if (IS_ERR(the_name))
  654. return PTR_ERR(the_name);
  655. strlcpy(linux_nfs_mount.hostname, the_name,
  656. sizeof(linux_nfs_mount.hostname));
  657. putname (the_name);
  658. mount_page = (char *) get_zeroed_page(GFP_KERNEL);
  659. if (!mount_page)
  660. return -ENOMEM;
  661. memcpy(mount_page, &linux_nfs_mount, sizeof(linux_nfs_mount));
  662. err = do_mount("", dir_name, "nfs", linux_flags, mount_page);
  663. free_page((unsigned long) mount_page);
  664. return err;
  665. }
  666. asmlinkage int
  667. sunos_mount(char __user *type, char __user *dir, int flags, void __user *data)
  668. {
  669. int linux_flags = 0;
  670. int ret = -EINVAL;
  671. char *dev_fname = NULL;
  672. char *dir_page, *type_page;
  673. if (!capable (CAP_SYS_ADMIN))
  674. return -EPERM;
  675. lock_kernel();
  676. /* We don't handle the integer fs type */
  677. if ((flags & SMNT_NEWTYPE) == 0)
  678. goto out;
  679. /* Do not allow for those flags we don't support */
  680. if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5))
  681. goto out;
  682. if (flags & SMNT_REMOUNT)
  683. linux_flags |= MS_REMOUNT;
  684. if (flags & SMNT_RDONLY)
  685. linux_flags |= MS_RDONLY;
  686. if (flags & SMNT_NOSUID)
  687. linux_flags |= MS_NOSUID;
  688. dir_page = getname(dir);
  689. ret = PTR_ERR(dir_page);
  690. if (IS_ERR(dir_page))
  691. goto out;
  692. type_page = getname(type);
  693. ret = PTR_ERR(type_page);
  694. if (IS_ERR(type_page))
  695. goto out1;
  696. if (strcmp(type_page, "ext2") == 0) {
  697. dev_fname = getname(data);
  698. } else if (strcmp(type_page, "iso9660") == 0) {
  699. dev_fname = getname(data);
  700. } else if (strcmp(type_page, "minix") == 0) {
  701. dev_fname = getname(data);
  702. } else if (strcmp(type_page, "nfs") == 0) {
  703. ret = sunos_nfs_mount (dir_page, flags, data);
  704. goto out2;
  705. } else if (strcmp(type_page, "ufs") == 0) {
  706. printk("Warning: UFS filesystem mounts unsupported.\n");
  707. ret = -ENODEV;
  708. goto out2;
  709. } else if (strcmp(type_page, "proc")) {
  710. ret = -ENODEV;
  711. goto out2;
  712. }
  713. ret = PTR_ERR(dev_fname);
  714. if (IS_ERR(dev_fname))
  715. goto out2;
  716. ret = do_mount(dev_fname, dir_page, type_page, linux_flags, NULL);
  717. if (dev_fname)
  718. putname(dev_fname);
  719. out2:
  720. putname(type_page);
  721. out1:
  722. putname(dir_page);
  723. out:
  724. unlock_kernel();
  725. return ret;
  726. }
  727. asmlinkage int sunos_setpgrp(pid_t pid, pid_t pgid)
  728. {
  729. int ret;
  730. /* So stupid... */
  731. if ((!pid || pid == current->pid) &&
  732. !pgid) {
  733. sys_setsid();
  734. ret = 0;
  735. } else {
  736. ret = sys_setpgid(pid, pgid);
  737. }
  738. return ret;
  739. }
  740. /* So stupid... */
  741. asmlinkage int sunos_wait4(pid_t pid, unsigned int __user *stat_addr,
  742. int options, struct rusage __user*ru)
  743. {
  744. int ret;
  745. ret = sys_wait4((pid ? pid : -1), stat_addr, options, ru);
  746. return ret;
  747. }
  748. asmlinkage int sunos_killpg(int pgrp, int sig)
  749. {
  750. int ret;
  751. rcu_read_lock();
  752. ret = -EINVAL;
  753. if (pgrp > 0)
  754. ret = kill_pgrp(find_pid(pgrp), sig, 0);
  755. rcu_read_unlock();
  756. return ret;
  757. }
  758. asmlinkage int sunos_audit(void)
  759. {
  760. lock_kernel();
  761. printk ("sys_audit\n");
  762. unlock_kernel();
  763. return -1;
  764. }
  765. asmlinkage unsigned long sunos_gethostid(void)
  766. {
  767. unsigned long ret;
  768. lock_kernel();
  769. ret = ((unsigned long)idprom->id_machtype << 24) |
  770. (unsigned long)idprom->id_sernum;
  771. unlock_kernel();
  772. return ret;
  773. }
  774. /* sysconf options, for SunOS compatibility */
  775. #define _SC_ARG_MAX 1
  776. #define _SC_CHILD_MAX 2
  777. #define _SC_CLK_TCK 3
  778. #define _SC_NGROUPS_MAX 4
  779. #define _SC_OPEN_MAX 5
  780. #define _SC_JOB_CONTROL 6
  781. #define _SC_SAVED_IDS 7
  782. #define _SC_VERSION 8
  783. asmlinkage long sunos_sysconf (int name)
  784. {
  785. long ret;
  786. switch (name){
  787. case _SC_ARG_MAX:
  788. ret = ARG_MAX;
  789. break;
  790. case _SC_CHILD_MAX:
  791. ret = -1; /* no limit */
  792. break;
  793. case _SC_CLK_TCK:
  794. ret = HZ;
  795. break;
  796. case _SC_NGROUPS_MAX:
  797. ret = NGROUPS_MAX;
  798. break;
  799. case _SC_OPEN_MAX:
  800. ret = OPEN_MAX;
  801. break;
  802. case _SC_JOB_CONTROL:
  803. ret = 1; /* yes, we do support job control */
  804. break;
  805. case _SC_SAVED_IDS:
  806. ret = 1; /* yes, we do support saved uids */
  807. break;
  808. case _SC_VERSION:
  809. /* mhm, POSIX_VERSION is in /usr/include/unistd.h
  810. * should it go on /usr/include/linux?
  811. */
  812. ret = 199009L;
  813. break;
  814. default:
  815. ret = -1;
  816. break;
  817. };
  818. return ret;
  819. }
  820. asmlinkage int sunos_semsys(int op, unsigned long arg1, unsigned long arg2,
  821. unsigned long arg3, void *ptr)
  822. {
  823. union semun arg4;
  824. int ret;
  825. switch (op) {
  826. case 0:
  827. /* Most arguments match on a 1:1 basis but cmd doesn't */
  828. switch(arg3) {
  829. case 4:
  830. arg3=GETPID; break;
  831. case 5:
  832. arg3=GETVAL; break;
  833. case 6:
  834. arg3=GETALL; break;
  835. case 3:
  836. arg3=GETNCNT; break;
  837. case 7:
  838. arg3=GETZCNT; break;
  839. case 8:
  840. arg3=SETVAL; break;
  841. case 9:
  842. arg3=SETALL; break;
  843. }
  844. /* sys_semctl(): */
  845. /* value to modify semaphore to */
  846. arg4.__pad = (void __user *) ptr;
  847. ret = sys_semctl((int)arg1, (int)arg2, (int)arg3, arg4 );
  848. break;
  849. case 1:
  850. /* sys_semget(): */
  851. ret = sys_semget((key_t)arg1, (int)arg2, (int)arg3);
  852. break;
  853. case 2:
  854. /* sys_semop(): */
  855. ret = sys_semop((int)arg1, (struct sembuf __user *)arg2, (unsigned)arg3);
  856. break;
  857. default:
  858. ret = -EINVAL;
  859. break;
  860. };
  861. return ret;
  862. }
  863. asmlinkage int sunos_msgsys(int op, unsigned long arg1, unsigned long arg2,
  864. unsigned long arg3, unsigned long arg4)
  865. {
  866. struct sparc_stackf *sp;
  867. unsigned long arg5;
  868. int rval;
  869. switch(op) {
  870. case 0:
  871. rval = sys_msgget((key_t)arg1, (int)arg2);
  872. break;
  873. case 1:
  874. rval = sys_msgctl((int)arg1, (int)arg2,
  875. (struct msqid_ds __user *)arg3);
  876. break;
  877. case 2:
  878. lock_kernel();
  879. sp = (struct sparc_stackf *)current->thread.kregs->u_regs[UREG_FP];
  880. arg5 = sp->xxargs[0];
  881. unlock_kernel();
  882. rval = sys_msgrcv((int)arg1, (struct msgbuf __user *)arg2,
  883. (size_t)arg3, (long)arg4, (int)arg5);
  884. break;
  885. case 3:
  886. rval = sys_msgsnd((int)arg1, (struct msgbuf __user *)arg2,
  887. (size_t)arg3, (int)arg4);
  888. break;
  889. default:
  890. rval = -EINVAL;
  891. break;
  892. }
  893. return rval;
  894. }
  895. asmlinkage int sunos_shmsys(int op, unsigned long arg1, unsigned long arg2,
  896. unsigned long arg3)
  897. {
  898. unsigned long raddr;
  899. int rval;
  900. switch(op) {
  901. case 0:
  902. /* do_shmat(): attach a shared memory area */
  903. rval = do_shmat((int)arg1,(char __user *)arg2,(int)arg3,&raddr);
  904. if (!rval)
  905. rval = (int) raddr;
  906. break;
  907. case 1:
  908. /* sys_shmctl(): modify shared memory area attr. */
  909. rval = sys_shmctl((int)arg1,(int)arg2,(struct shmid_ds __user *)arg3);
  910. break;
  911. case 2:
  912. /* sys_shmdt(): detach a shared memory area */
  913. rval = sys_shmdt((char __user *)arg1);
  914. break;
  915. case 3:
  916. /* sys_shmget(): get a shared memory area */
  917. rval = sys_shmget((key_t)arg1,(int)arg2,(int)arg3);
  918. break;
  919. default:
  920. rval = -EINVAL;
  921. break;
  922. };
  923. return rval;
  924. }
  925. #define SUNOS_EWOULDBLOCK 35
  926. /* see the sunos man page read(2v) for an explanation
  927. of this garbage. We use O_NDELAY to mark
  928. file descriptors that have been set non-blocking
  929. using 4.2BSD style calls. (tridge) */
  930. static inline int check_nonblock(int ret, int fd)
  931. {
  932. if (ret == -EAGAIN) {
  933. struct file * file = fget(fd);
  934. if (file) {
  935. if (file->f_flags & O_NDELAY)
  936. ret = -SUNOS_EWOULDBLOCK;
  937. fput(file);
  938. }
  939. }
  940. return ret;
  941. }
  942. asmlinkage int sunos_read(unsigned int fd, char __user *buf, int count)
  943. {
  944. int ret;
  945. ret = check_nonblock(sys_read(fd,buf,count),fd);
  946. return ret;
  947. }
  948. asmlinkage int sunos_readv(unsigned long fd, const struct iovec __user *vector,
  949. long count)
  950. {
  951. int ret;
  952. ret = check_nonblock(sys_readv(fd,vector,count),fd);
  953. return ret;
  954. }
  955. asmlinkage int sunos_write(unsigned int fd, char __user *buf, int count)
  956. {
  957. int ret;
  958. ret = check_nonblock(sys_write(fd,buf,count),fd);
  959. return ret;
  960. }
  961. asmlinkage int sunos_writev(unsigned long fd,
  962. const struct iovec __user *vector, long count)
  963. {
  964. int ret;
  965. ret = check_nonblock(sys_writev(fd,vector,count),fd);
  966. return ret;
  967. }
  968. asmlinkage int sunos_recv(int fd, void __user *ubuf, int size, unsigned flags)
  969. {
  970. int ret;
  971. ret = check_nonblock(sys_recv(fd,ubuf,size,flags),fd);
  972. return ret;
  973. }
  974. asmlinkage int sunos_send(int fd, void __user *buff, int len, unsigned flags)
  975. {
  976. int ret;
  977. ret = check_nonblock(sys_send(fd,buff,len,flags),fd);
  978. return ret;
  979. }
  980. asmlinkage int sunos_accept(int fd, struct sockaddr __user *sa,
  981. int __user *addrlen)
  982. {
  983. int ret;
  984. while (1) {
  985. ret = check_nonblock(sys_accept(fd,sa,addrlen),fd);
  986. if (ret != -ENETUNREACH && ret != -EHOSTUNREACH)
  987. break;
  988. }
  989. return ret;
  990. }
  991. #define SUNOS_SV_INTERRUPT 2
  992. asmlinkage int
  993. sunos_sigaction(int sig, const struct old_sigaction __user *act,
  994. struct old_sigaction __user *oact)
  995. {
  996. struct k_sigaction new_ka, old_ka;
  997. int ret;
  998. if (act) {
  999. old_sigset_t mask;
  1000. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  1001. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  1002. __get_user(new_ka.sa.sa_flags, &act->sa_flags))
  1003. return -EFAULT;
  1004. __get_user(mask, &act->sa_mask);
  1005. new_ka.sa.sa_restorer = NULL;
  1006. new_ka.ka_restorer = NULL;
  1007. siginitset(&new_ka.sa.sa_mask, mask);
  1008. new_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
  1009. }
  1010. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  1011. if (!ret && oact) {
  1012. /* In the clone() case we could copy half consistent
  1013. * state to the user, however this could sleep and
  1014. * deadlock us if we held the signal lock on SMP. So for
  1015. * now I take the easy way out and do no locking.
  1016. * But then again we don't support SunOS lwp's anyways ;-)
  1017. */
  1018. old_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
  1019. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  1020. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  1021. __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
  1022. return -EFAULT;
  1023. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  1024. }
  1025. return ret;
  1026. }
  1027. asmlinkage int sunos_setsockopt(int fd, int level, int optname,
  1028. char __user *optval, int optlen)
  1029. {
  1030. int tr_opt = optname;
  1031. int ret;
  1032. if (level == SOL_IP) {
  1033. /* Multicast socketopts (ttl, membership) */
  1034. if (tr_opt >=2 && tr_opt <= 6)
  1035. tr_opt += 30;
  1036. }
  1037. ret = sys_setsockopt(fd, level, tr_opt, optval, optlen);
  1038. return ret;
  1039. }
  1040. asmlinkage int sunos_getsockopt(int fd, int level, int optname,
  1041. char __user *optval, int __user *optlen)
  1042. {
  1043. int tr_opt = optname;
  1044. int ret;
  1045. if (level == SOL_IP) {
  1046. /* Multicast socketopts (ttl, membership) */
  1047. if (tr_opt >=2 && tr_opt <= 6)
  1048. tr_opt += 30;
  1049. }
  1050. ret = sys_getsockopt(fd, level, tr_opt, optval, optlen);
  1051. return ret;
  1052. }