sys_sparc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. /* $Id: sys_sparc.c,v 1.57 2002/02/09 19:49:30 davem Exp $
  2. * linux/arch/sparc64/kernel/sys_sparc.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/sparc
  6. * platform.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/types.h>
  10. #include <linux/sched.h>
  11. #include <linux/fs.h>
  12. #include <linux/file.h>
  13. #include <linux/mm.h>
  14. #include <linux/sem.h>
  15. #include <linux/msg.h>
  16. #include <linux/shm.h>
  17. #include <linux/stat.h>
  18. #include <linux/mman.h>
  19. #include <linux/utsname.h>
  20. #include <linux/smp.h>
  21. #include <linux/smp_lock.h>
  22. #include <linux/slab.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/ipc.h>
  25. #include <linux/personality.h>
  26. #include <linux/random.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/ipc.h>
  29. #include <asm/utrap.h>
  30. #include <asm/perfctr.h>
  31. #include <asm/a.out.h>
  32. /* #define DEBUG_UNIMP_SYSCALL */
  33. asmlinkage unsigned long sys_getpagesize(void)
  34. {
  35. return PAGE_SIZE;
  36. }
  37. #define VA_EXCLUDE_START (0x0000080000000000UL - (1UL << 32UL))
  38. #define VA_EXCLUDE_END (0xfffff80000000000UL + (1UL << 32UL))
  39. /* Does addr --> addr+len fall within 4GB of the VA-space hole or
  40. * overflow past the end of the 64-bit address space?
  41. */
  42. static inline int invalid_64bit_range(unsigned long addr, unsigned long len)
  43. {
  44. unsigned long va_exclude_start, va_exclude_end;
  45. va_exclude_start = VA_EXCLUDE_START;
  46. va_exclude_end = VA_EXCLUDE_END;
  47. if (unlikely(len >= va_exclude_start))
  48. return 1;
  49. if (unlikely((addr + len) < addr))
  50. return 1;
  51. if (unlikely((addr >= va_exclude_start && addr < va_exclude_end) ||
  52. ((addr + len) >= va_exclude_start &&
  53. (addr + len) < va_exclude_end)))
  54. return 1;
  55. return 0;
  56. }
  57. /* Does start,end straddle the VA-space hole? */
  58. static inline int straddles_64bit_va_hole(unsigned long start, unsigned long end)
  59. {
  60. unsigned long va_exclude_start, va_exclude_end;
  61. va_exclude_start = VA_EXCLUDE_START;
  62. va_exclude_end = VA_EXCLUDE_END;
  63. if (likely(start < va_exclude_start && end < va_exclude_start))
  64. return 0;
  65. if (likely(start >= va_exclude_end && end >= va_exclude_end))
  66. return 0;
  67. return 1;
  68. }
  69. /* These functions differ from the default implementations in
  70. * mm/mmap.c in two ways:
  71. *
  72. * 1) For file backed MAP_SHARED mmap()'s we D-cache color align,
  73. * for fixed such mappings we just validate what the user gave us.
  74. * 2) For 64-bit tasks we avoid mapping anything within 4GB of
  75. * the spitfire/niagara VA-hole.
  76. */
  77. static inline unsigned long COLOUR_ALIGN(unsigned long addr,
  78. unsigned long pgoff)
  79. {
  80. unsigned long base = (addr+SHMLBA-1)&~(SHMLBA-1);
  81. unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
  82. return base + off;
  83. }
  84. static inline unsigned long COLOUR_ALIGN_DOWN(unsigned long addr,
  85. unsigned long pgoff)
  86. {
  87. unsigned long base = addr & ~(SHMLBA-1);
  88. unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
  89. if (base + off <= addr)
  90. return base + off;
  91. return base - off;
  92. }
  93. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  94. {
  95. struct mm_struct *mm = current->mm;
  96. struct vm_area_struct * vma;
  97. unsigned long task_size = TASK_SIZE;
  98. unsigned long start_addr;
  99. int do_color_align;
  100. if (flags & MAP_FIXED) {
  101. /* We do not accept a shared mapping if it would violate
  102. * cache aliasing constraints.
  103. */
  104. if ((flags & MAP_SHARED) &&
  105. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  106. return -EINVAL;
  107. return addr;
  108. }
  109. if (test_thread_flag(TIF_32BIT))
  110. task_size = STACK_TOP32;
  111. if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
  112. return -ENOMEM;
  113. do_color_align = 0;
  114. if (filp || (flags & MAP_SHARED))
  115. do_color_align = 1;
  116. if (addr) {
  117. if (do_color_align)
  118. addr = COLOUR_ALIGN(addr, pgoff);
  119. else
  120. addr = PAGE_ALIGN(addr);
  121. vma = find_vma(mm, addr);
  122. if (task_size - len >= addr &&
  123. (!vma || addr + len <= vma->vm_start))
  124. return addr;
  125. }
  126. if (len > mm->cached_hole_size) {
  127. start_addr = addr = mm->free_area_cache;
  128. } else {
  129. start_addr = addr = TASK_UNMAPPED_BASE;
  130. mm->cached_hole_size = 0;
  131. }
  132. task_size -= len;
  133. full_search:
  134. if (do_color_align)
  135. addr = COLOUR_ALIGN(addr, pgoff);
  136. else
  137. addr = PAGE_ALIGN(addr);
  138. for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
  139. /* At this point: (!vma || addr < vma->vm_end). */
  140. if (addr < VA_EXCLUDE_START &&
  141. (addr + len) >= VA_EXCLUDE_START) {
  142. addr = VA_EXCLUDE_END;
  143. vma = find_vma(mm, VA_EXCLUDE_END);
  144. }
  145. if (unlikely(task_size < addr)) {
  146. if (start_addr != TASK_UNMAPPED_BASE) {
  147. start_addr = addr = TASK_UNMAPPED_BASE;
  148. mm->cached_hole_size = 0;
  149. goto full_search;
  150. }
  151. return -ENOMEM;
  152. }
  153. if (likely(!vma || addr + len <= vma->vm_start)) {
  154. /*
  155. * Remember the place where we stopped the search:
  156. */
  157. mm->free_area_cache = addr + len;
  158. return addr;
  159. }
  160. if (addr + mm->cached_hole_size < vma->vm_start)
  161. mm->cached_hole_size = vma->vm_start - addr;
  162. addr = vma->vm_end;
  163. if (do_color_align)
  164. addr = COLOUR_ALIGN(addr, pgoff);
  165. }
  166. }
  167. unsigned long
  168. arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  169. const unsigned long len, const unsigned long pgoff,
  170. const unsigned long flags)
  171. {
  172. struct vm_area_struct *vma;
  173. struct mm_struct *mm = current->mm;
  174. unsigned long task_size = STACK_TOP32;
  175. unsigned long addr = addr0;
  176. int do_color_align;
  177. /* This should only ever run for 32-bit processes. */
  178. BUG_ON(!test_thread_flag(TIF_32BIT));
  179. if (flags & MAP_FIXED) {
  180. /* We do not accept a shared mapping if it would violate
  181. * cache aliasing constraints.
  182. */
  183. if ((flags & MAP_SHARED) &&
  184. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  185. return -EINVAL;
  186. return addr;
  187. }
  188. if (unlikely(len > task_size))
  189. return -ENOMEM;
  190. do_color_align = 0;
  191. if (filp || (flags & MAP_SHARED))
  192. do_color_align = 1;
  193. /* requesting a specific address */
  194. if (addr) {
  195. if (do_color_align)
  196. addr = COLOUR_ALIGN(addr, pgoff);
  197. else
  198. addr = PAGE_ALIGN(addr);
  199. vma = find_vma(mm, addr);
  200. if (task_size - len >= addr &&
  201. (!vma || addr + len <= vma->vm_start))
  202. return addr;
  203. }
  204. /* check if free_area_cache is useful for us */
  205. if (len <= mm->cached_hole_size) {
  206. mm->cached_hole_size = 0;
  207. mm->free_area_cache = mm->mmap_base;
  208. }
  209. /* either no address requested or can't fit in requested address hole */
  210. addr = mm->free_area_cache;
  211. if (do_color_align) {
  212. unsigned long base = COLOUR_ALIGN_DOWN(addr-len, pgoff);
  213. addr = base + len;
  214. }
  215. /* make sure it can fit in the remaining address space */
  216. if (likely(addr > len)) {
  217. vma = find_vma(mm, addr-len);
  218. if (!vma || addr <= vma->vm_start) {
  219. /* remember the address as a hint for next time */
  220. return (mm->free_area_cache = addr-len);
  221. }
  222. }
  223. if (unlikely(mm->mmap_base < len))
  224. goto bottomup;
  225. addr = mm->mmap_base-len;
  226. if (do_color_align)
  227. addr = COLOUR_ALIGN_DOWN(addr, pgoff);
  228. do {
  229. /*
  230. * Lookup failure means no vma is above this address,
  231. * else if new region fits below vma->vm_start,
  232. * return with success:
  233. */
  234. vma = find_vma(mm, addr);
  235. if (likely(!vma || addr+len <= vma->vm_start)) {
  236. /* remember the address as a hint for next time */
  237. return (mm->free_area_cache = addr);
  238. }
  239. /* remember the largest hole we saw so far */
  240. if (addr + mm->cached_hole_size < vma->vm_start)
  241. mm->cached_hole_size = vma->vm_start - addr;
  242. /* try just below the current vma->vm_start */
  243. addr = vma->vm_start-len;
  244. if (do_color_align)
  245. addr = COLOUR_ALIGN_DOWN(addr, pgoff);
  246. } while (likely(len < vma->vm_start));
  247. bottomup:
  248. /*
  249. * A failed mmap() very likely causes application failure,
  250. * so fall back to the bottom-up function here. This scenario
  251. * can happen with large stack limits and large mmap()
  252. * allocations.
  253. */
  254. mm->cached_hole_size = ~0UL;
  255. mm->free_area_cache = TASK_UNMAPPED_BASE;
  256. addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
  257. /*
  258. * Restore the topdown base:
  259. */
  260. mm->free_area_cache = mm->mmap_base;
  261. mm->cached_hole_size = ~0UL;
  262. return addr;
  263. }
  264. /* Try to align mapping such that we align it as much as possible. */
  265. unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  266. {
  267. unsigned long align_goal, addr = -ENOMEM;
  268. if (flags & MAP_FIXED) {
  269. /* Ok, don't mess with it. */
  270. return get_unmapped_area(NULL, addr, len, pgoff, flags);
  271. }
  272. flags &= ~MAP_SHARED;
  273. align_goal = PAGE_SIZE;
  274. if (len >= (4UL * 1024 * 1024))
  275. align_goal = (4UL * 1024 * 1024);
  276. else if (len >= (512UL * 1024))
  277. align_goal = (512UL * 1024);
  278. else if (len >= (64UL * 1024))
  279. align_goal = (64UL * 1024);
  280. do {
  281. addr = get_unmapped_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags);
  282. if (!(addr & ~PAGE_MASK)) {
  283. addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
  284. break;
  285. }
  286. if (align_goal == (4UL * 1024 * 1024))
  287. align_goal = (512UL * 1024);
  288. else if (align_goal == (512UL * 1024))
  289. align_goal = (64UL * 1024);
  290. else
  291. align_goal = PAGE_SIZE;
  292. } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
  293. /* Mapping is smaller than 64K or larger areas could not
  294. * be obtained.
  295. */
  296. if (addr & ~PAGE_MASK)
  297. addr = get_unmapped_area(NULL, orig_addr, len, pgoff, flags);
  298. return addr;
  299. }
  300. /* Essentially the same as PowerPC... */
  301. void arch_pick_mmap_layout(struct mm_struct *mm)
  302. {
  303. unsigned long random_factor = 0UL;
  304. if (current->flags & PF_RANDOMIZE) {
  305. random_factor = get_random_int();
  306. if (test_thread_flag(TIF_32BIT))
  307. random_factor &= ((1 * 1024 * 1024) - 1);
  308. else
  309. random_factor = ((random_factor << PAGE_SHIFT) &
  310. 0xffffffffUL);
  311. }
  312. /*
  313. * Fall back to the standard layout if the personality
  314. * bit is set, or if the expected stack growth is unlimited:
  315. */
  316. if (!test_thread_flag(TIF_32BIT) ||
  317. (current->personality & ADDR_COMPAT_LAYOUT) ||
  318. current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
  319. sysctl_legacy_va_layout) {
  320. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  321. mm->get_unmapped_area = arch_get_unmapped_area;
  322. mm->unmap_area = arch_unmap_area;
  323. } else {
  324. /* We know it's 32-bit */
  325. unsigned long task_size = STACK_TOP32;
  326. unsigned long gap;
  327. gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
  328. if (gap < 128 * 1024 * 1024)
  329. gap = 128 * 1024 * 1024;
  330. if (gap > (task_size / 6 * 5))
  331. gap = (task_size / 6 * 5);
  332. mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
  333. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  334. mm->unmap_area = arch_unmap_area_topdown;
  335. }
  336. }
  337. asmlinkage unsigned long sparc_brk(unsigned long brk)
  338. {
  339. /* People could try to be nasty and use ta 0x6d in 32bit programs */
  340. if (test_thread_flag(TIF_32BIT) && brk >= STACK_TOP32)
  341. return current->mm->brk;
  342. if (unlikely(straddles_64bit_va_hole(current->mm->brk, brk)))
  343. return current->mm->brk;
  344. return sys_brk(brk);
  345. }
  346. /*
  347. * sys_pipe() is the normal C calling standard for creating
  348. * a pipe. It's not the way unix traditionally does this, though.
  349. */
  350. asmlinkage long sparc_pipe(struct pt_regs *regs)
  351. {
  352. int fd[2];
  353. int error;
  354. error = do_pipe(fd);
  355. if (error)
  356. goto out;
  357. regs->u_regs[UREG_I1] = fd[1];
  358. error = fd[0];
  359. out:
  360. return error;
  361. }
  362. /*
  363. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  364. *
  365. * This is really horribly ugly.
  366. */
  367. asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
  368. unsigned long third, void __user *ptr, long fifth)
  369. {
  370. int err;
  371. /* No need for backward compatibility. We can start fresh... */
  372. if (call <= SEMCTL) {
  373. switch (call) {
  374. case SEMOP:
  375. err = sys_semtimedop(first, ptr,
  376. (unsigned)second, NULL);
  377. goto out;
  378. case SEMTIMEDOP:
  379. err = sys_semtimedop(first, ptr, (unsigned)second,
  380. (const struct timespec __user *) fifth);
  381. goto out;
  382. case SEMGET:
  383. err = sys_semget(first, (int)second, (int)third);
  384. goto out;
  385. case SEMCTL: {
  386. union semun fourth;
  387. err = -EINVAL;
  388. if (!ptr)
  389. goto out;
  390. err = -EFAULT;
  391. if (get_user(fourth.__pad,
  392. (void __user * __user *) ptr))
  393. goto out;
  394. err = sys_semctl(first, (int)second | IPC_64,
  395. (int)third, fourth);
  396. goto out;
  397. }
  398. default:
  399. err = -ENOSYS;
  400. goto out;
  401. };
  402. }
  403. if (call <= MSGCTL) {
  404. switch (call) {
  405. case MSGSND:
  406. err = sys_msgsnd(first, ptr, (size_t)second,
  407. (int)third);
  408. goto out;
  409. case MSGRCV:
  410. err = sys_msgrcv(first, ptr, (size_t)second, fifth,
  411. (int)third);
  412. goto out;
  413. case MSGGET:
  414. err = sys_msgget((key_t)first, (int)second);
  415. goto out;
  416. case MSGCTL:
  417. err = sys_msgctl(first, (int)second | IPC_64, ptr);
  418. goto out;
  419. default:
  420. err = -ENOSYS;
  421. goto out;
  422. };
  423. }
  424. if (call <= SHMCTL) {
  425. switch (call) {
  426. case SHMAT: {
  427. ulong raddr;
  428. err = do_shmat(first, ptr, (int)second, &raddr);
  429. if (!err) {
  430. if (put_user(raddr,
  431. (ulong __user *) third))
  432. err = -EFAULT;
  433. }
  434. goto out;
  435. }
  436. case SHMDT:
  437. err = sys_shmdt(ptr);
  438. goto out;
  439. case SHMGET:
  440. err = sys_shmget(first, (size_t)second, (int)third);
  441. goto out;
  442. case SHMCTL:
  443. err = sys_shmctl(first, (int)second | IPC_64, ptr);
  444. goto out;
  445. default:
  446. err = -ENOSYS;
  447. goto out;
  448. };
  449. } else {
  450. err = -ENOSYS;
  451. }
  452. out:
  453. return err;
  454. }
  455. asmlinkage long sparc64_newuname(struct new_utsname __user *name)
  456. {
  457. int ret = sys_newuname(name);
  458. if (current->personality == PER_LINUX32 && !ret) {
  459. ret = (copy_to_user(name->machine, "sparc\0\0", 8)
  460. ? -EFAULT : 0);
  461. }
  462. return ret;
  463. }
  464. asmlinkage long sparc64_personality(unsigned long personality)
  465. {
  466. int ret;
  467. if (current->personality == PER_LINUX32 &&
  468. personality == PER_LINUX)
  469. personality = PER_LINUX32;
  470. ret = sys_personality(personality);
  471. if (ret == PER_LINUX32)
  472. ret = PER_LINUX;
  473. return ret;
  474. }
  475. int sparc64_mmap_check(unsigned long addr, unsigned long len,
  476. unsigned long flags)
  477. {
  478. if (test_thread_flag(TIF_32BIT)) {
  479. if (len >= STACK_TOP32)
  480. return -EINVAL;
  481. if ((flags & MAP_FIXED) && addr > STACK_TOP32 - len)
  482. return -EINVAL;
  483. } else {
  484. if (len >= VA_EXCLUDE_START)
  485. return -EINVAL;
  486. if ((flags & MAP_FIXED) && invalid_64bit_range(addr, len))
  487. return -EINVAL;
  488. }
  489. return 0;
  490. }
  491. /* Linux version of mmap */
  492. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  493. unsigned long prot, unsigned long flags, unsigned long fd,
  494. unsigned long off)
  495. {
  496. struct file * file = NULL;
  497. unsigned long retval = -EBADF;
  498. if (!(flags & MAP_ANONYMOUS)) {
  499. file = fget(fd);
  500. if (!file)
  501. goto out;
  502. }
  503. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  504. len = PAGE_ALIGN(len);
  505. down_write(&current->mm->mmap_sem);
  506. retval = do_mmap(file, addr, len, prot, flags, off);
  507. up_write(&current->mm->mmap_sem);
  508. if (file)
  509. fput(file);
  510. out:
  511. return retval;
  512. }
  513. asmlinkage long sys64_munmap(unsigned long addr, size_t len)
  514. {
  515. long ret;
  516. if (invalid_64bit_range(addr, len))
  517. return -EINVAL;
  518. down_write(&current->mm->mmap_sem);
  519. ret = do_munmap(current->mm, addr, len);
  520. up_write(&current->mm->mmap_sem);
  521. return ret;
  522. }
  523. extern unsigned long do_mremap(unsigned long addr,
  524. unsigned long old_len, unsigned long new_len,
  525. unsigned long flags, unsigned long new_addr);
  526. asmlinkage unsigned long sys64_mremap(unsigned long addr,
  527. unsigned long old_len, unsigned long new_len,
  528. unsigned long flags, unsigned long new_addr)
  529. {
  530. struct vm_area_struct *vma;
  531. unsigned long ret = -EINVAL;
  532. if (test_thread_flag(TIF_32BIT))
  533. goto out;
  534. if (unlikely(new_len >= VA_EXCLUDE_START))
  535. goto out;
  536. if (unlikely(invalid_64bit_range(addr, old_len)))
  537. goto out;
  538. down_write(&current->mm->mmap_sem);
  539. if (flags & MREMAP_FIXED) {
  540. if (invalid_64bit_range(new_addr, new_len))
  541. goto out_sem;
  542. } else if (invalid_64bit_range(addr, new_len)) {
  543. unsigned long map_flags = 0;
  544. struct file *file = NULL;
  545. ret = -ENOMEM;
  546. if (!(flags & MREMAP_MAYMOVE))
  547. goto out_sem;
  548. vma = find_vma(current->mm, addr);
  549. if (vma) {
  550. if (vma->vm_flags & VM_SHARED)
  551. map_flags |= MAP_SHARED;
  552. file = vma->vm_file;
  553. }
  554. /* MREMAP_FIXED checked above. */
  555. new_addr = get_unmapped_area(file, addr, new_len,
  556. vma ? vma->vm_pgoff : 0,
  557. map_flags);
  558. ret = new_addr;
  559. if (new_addr & ~PAGE_MASK)
  560. goto out_sem;
  561. flags |= MREMAP_FIXED;
  562. }
  563. ret = do_mremap(addr, old_len, new_len, flags, new_addr);
  564. out_sem:
  565. up_write(&current->mm->mmap_sem);
  566. out:
  567. return ret;
  568. }
  569. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  570. asmlinkage unsigned long c_sys_nis_syscall(struct pt_regs *regs)
  571. {
  572. static int count;
  573. /* Don't make the system unusable, if someone goes stuck */
  574. if (count++ > 5)
  575. return -ENOSYS;
  576. printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
  577. #ifdef DEBUG_UNIMP_SYSCALL
  578. show_regs (regs);
  579. #endif
  580. return -ENOSYS;
  581. }
  582. /* #define DEBUG_SPARC_BREAKPOINT */
  583. asmlinkage void sparc_breakpoint(struct pt_regs *regs)
  584. {
  585. siginfo_t info;
  586. if (test_thread_flag(TIF_32BIT)) {
  587. regs->tpc &= 0xffffffff;
  588. regs->tnpc &= 0xffffffff;
  589. }
  590. #ifdef DEBUG_SPARC_BREAKPOINT
  591. printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
  592. #endif
  593. info.si_signo = SIGTRAP;
  594. info.si_errno = 0;
  595. info.si_code = TRAP_BRKPT;
  596. info.si_addr = (void __user *)regs->tpc;
  597. info.si_trapno = 0;
  598. force_sig_info(SIGTRAP, &info, current);
  599. #ifdef DEBUG_SPARC_BREAKPOINT
  600. printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
  601. #endif
  602. }
  603. extern void check_pending(int signum);
  604. asmlinkage long sys_getdomainname(char __user *name, int len)
  605. {
  606. int nlen, err;
  607. if (len < 0)
  608. return -EINVAL;
  609. down_read(&uts_sem);
  610. nlen = strlen(system_utsname.domainname) + 1;
  611. err = -EINVAL;
  612. if (nlen > len)
  613. goto out;
  614. err = -EFAULT;
  615. if (!copy_to_user(name, system_utsname.domainname, nlen))
  616. err = 0;
  617. out:
  618. up_read(&uts_sem);
  619. return err;
  620. }
  621. asmlinkage long solaris_syscall(struct pt_regs *regs)
  622. {
  623. static int count;
  624. regs->tpc = regs->tnpc;
  625. regs->tnpc += 4;
  626. if (test_thread_flag(TIF_32BIT)) {
  627. regs->tpc &= 0xffffffff;
  628. regs->tnpc &= 0xffffffff;
  629. }
  630. if (++count <= 5) {
  631. printk ("For Solaris binary emulation you need solaris module loaded\n");
  632. show_regs (regs);
  633. }
  634. send_sig(SIGSEGV, current, 1);
  635. return -ENOSYS;
  636. }
  637. #ifndef CONFIG_SUNOS_EMUL
  638. asmlinkage long sunos_syscall(struct pt_regs *regs)
  639. {
  640. static int count;
  641. regs->tpc = regs->tnpc;
  642. regs->tnpc += 4;
  643. if (test_thread_flag(TIF_32BIT)) {
  644. regs->tpc &= 0xffffffff;
  645. regs->tnpc &= 0xffffffff;
  646. }
  647. if (++count <= 20)
  648. printk ("SunOS binary emulation not compiled in\n");
  649. force_sig(SIGSEGV, current);
  650. return -ENOSYS;
  651. }
  652. #endif
  653. asmlinkage long sys_utrap_install(utrap_entry_t type,
  654. utrap_handler_t new_p,
  655. utrap_handler_t new_d,
  656. utrap_handler_t __user *old_p,
  657. utrap_handler_t __user *old_d)
  658. {
  659. if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
  660. return -EINVAL;
  661. if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
  662. if (old_p) {
  663. if (!current_thread_info()->utraps) {
  664. if (put_user(NULL, old_p))
  665. return -EFAULT;
  666. } else {
  667. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  668. return -EFAULT;
  669. }
  670. }
  671. if (old_d) {
  672. if (put_user(NULL, old_d))
  673. return -EFAULT;
  674. }
  675. return 0;
  676. }
  677. if (!current_thread_info()->utraps) {
  678. current_thread_info()->utraps =
  679. kzalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), GFP_KERNEL);
  680. if (!current_thread_info()->utraps)
  681. return -ENOMEM;
  682. current_thread_info()->utraps[0] = 1;
  683. } else {
  684. if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
  685. current_thread_info()->utraps[0] > 1) {
  686. long *p = current_thread_info()->utraps;
  687. current_thread_info()->utraps =
  688. kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
  689. GFP_KERNEL);
  690. if (!current_thread_info()->utraps) {
  691. current_thread_info()->utraps = p;
  692. return -ENOMEM;
  693. }
  694. p[0]--;
  695. current_thread_info()->utraps[0] = 1;
  696. memcpy(current_thread_info()->utraps+1, p+1,
  697. UT_TRAP_INSTRUCTION_31*sizeof(long));
  698. }
  699. }
  700. if (old_p) {
  701. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  702. return -EFAULT;
  703. }
  704. if (old_d) {
  705. if (put_user(NULL, old_d))
  706. return -EFAULT;
  707. }
  708. current_thread_info()->utraps[type] = (long)new_p;
  709. return 0;
  710. }
  711. long sparc_memory_ordering(unsigned long model, struct pt_regs *regs)
  712. {
  713. if (model >= 3)
  714. return -EINVAL;
  715. regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
  716. return 0;
  717. }
  718. asmlinkage long sys_rt_sigaction(int sig,
  719. const struct sigaction __user *act,
  720. struct sigaction __user *oact,
  721. void __user *restorer,
  722. size_t sigsetsize)
  723. {
  724. struct k_sigaction new_ka, old_ka;
  725. int ret;
  726. /* XXX: Don't preclude handling different sized sigset_t's. */
  727. if (sigsetsize != sizeof(sigset_t))
  728. return -EINVAL;
  729. if (act) {
  730. new_ka.ka_restorer = restorer;
  731. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  732. return -EFAULT;
  733. }
  734. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  735. if (!ret && oact) {
  736. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  737. return -EFAULT;
  738. }
  739. return ret;
  740. }
  741. /* Invoked by rtrap code to update performance counters in
  742. * user space.
  743. */
  744. asmlinkage void update_perfctrs(void)
  745. {
  746. unsigned long pic, tmp;
  747. read_pic(pic);
  748. tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
  749. __put_user(tmp, current_thread_info()->user_cntd0);
  750. tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
  751. __put_user(tmp, current_thread_info()->user_cntd1);
  752. reset_pic();
  753. }
  754. asmlinkage long sys_perfctr(int opcode, unsigned long arg0, unsigned long arg1, unsigned long arg2)
  755. {
  756. int err = 0;
  757. switch(opcode) {
  758. case PERFCTR_ON:
  759. current_thread_info()->pcr_reg = arg2;
  760. current_thread_info()->user_cntd0 = (u64 __user *) arg0;
  761. current_thread_info()->user_cntd1 = (u64 __user *) arg1;
  762. current_thread_info()->kernel_cntd0 =
  763. current_thread_info()->kernel_cntd1 = 0;
  764. write_pcr(arg2);
  765. reset_pic();
  766. set_thread_flag(TIF_PERFCTR);
  767. break;
  768. case PERFCTR_OFF:
  769. err = -EINVAL;
  770. if (test_thread_flag(TIF_PERFCTR)) {
  771. current_thread_info()->user_cntd0 =
  772. current_thread_info()->user_cntd1 = NULL;
  773. current_thread_info()->pcr_reg = 0;
  774. write_pcr(0);
  775. clear_thread_flag(TIF_PERFCTR);
  776. err = 0;
  777. }
  778. break;
  779. case PERFCTR_READ: {
  780. unsigned long pic, tmp;
  781. if (!test_thread_flag(TIF_PERFCTR)) {
  782. err = -EINVAL;
  783. break;
  784. }
  785. read_pic(pic);
  786. tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
  787. err |= __put_user(tmp, current_thread_info()->user_cntd0);
  788. tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
  789. err |= __put_user(tmp, current_thread_info()->user_cntd1);
  790. reset_pic();
  791. break;
  792. }
  793. case PERFCTR_CLRPIC:
  794. if (!test_thread_flag(TIF_PERFCTR)) {
  795. err = -EINVAL;
  796. break;
  797. }
  798. current_thread_info()->kernel_cntd0 =
  799. current_thread_info()->kernel_cntd1 = 0;
  800. reset_pic();
  801. break;
  802. case PERFCTR_SETPCR: {
  803. u64 __user *user_pcr = (u64 __user *)arg0;
  804. if (!test_thread_flag(TIF_PERFCTR)) {
  805. err = -EINVAL;
  806. break;
  807. }
  808. err |= __get_user(current_thread_info()->pcr_reg, user_pcr);
  809. write_pcr(current_thread_info()->pcr_reg);
  810. current_thread_info()->kernel_cntd0 =
  811. current_thread_info()->kernel_cntd1 = 0;
  812. reset_pic();
  813. break;
  814. }
  815. case PERFCTR_GETPCR: {
  816. u64 __user *user_pcr = (u64 __user *)arg0;
  817. if (!test_thread_flag(TIF_PERFCTR)) {
  818. err = -EINVAL;
  819. break;
  820. }
  821. err |= __put_user(current_thread_info()->pcr_reg, user_pcr);
  822. break;
  823. }
  824. default:
  825. err = -EINVAL;
  826. break;
  827. };
  828. return err;
  829. }