sys_sparc_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /* linux/arch/sparc64/kernel/sys_sparc.c
  2. *
  3. * This file contains various random system calls that
  4. * have a non-standard calling sequence on the Linux/sparc
  5. * platform.
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/fs.h>
  11. #include <linux/file.h>
  12. #include <linux/mm.h>
  13. #include <linux/sem.h>
  14. #include <linux/msg.h>
  15. #include <linux/shm.h>
  16. #include <linux/stat.h>
  17. #include <linux/mman.h>
  18. #include <linux/utsname.h>
  19. #include <linux/smp.h>
  20. #include <linux/slab.h>
  21. #include <linux/syscalls.h>
  22. #include <linux/ipc.h>
  23. #include <linux/personality.h>
  24. #include <linux/random.h>
  25. #include <linux/export.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/utrap.h>
  28. #include <asm/unistd.h>
  29. #include "entry.h"
  30. #include "systbls.h"
  31. /* #define DEBUG_UNIMP_SYSCALL */
  32. asmlinkage unsigned long sys_getpagesize(void)
  33. {
  34. return PAGE_SIZE;
  35. }
  36. #define VA_EXCLUDE_START (0x0000080000000000UL - (1UL << 32UL))
  37. #define VA_EXCLUDE_END (0xfffff80000000000UL + (1UL << 32UL))
  38. /* Does addr --> addr+len fall within 4GB of the VA-space hole or
  39. * overflow past the end of the 64-bit address space?
  40. */
  41. static inline int invalid_64bit_range(unsigned long addr, unsigned long len)
  42. {
  43. unsigned long va_exclude_start, va_exclude_end;
  44. va_exclude_start = VA_EXCLUDE_START;
  45. va_exclude_end = VA_EXCLUDE_END;
  46. if (unlikely(len >= va_exclude_start))
  47. return 1;
  48. if (unlikely((addr + len) < addr))
  49. return 1;
  50. if (unlikely((addr >= va_exclude_start && addr < va_exclude_end) ||
  51. ((addr + len) >= va_exclude_start &&
  52. (addr + len) < va_exclude_end)))
  53. return 1;
  54. return 0;
  55. }
  56. /* Does start,end straddle the VA-space hole? */
  57. static inline int straddles_64bit_va_hole(unsigned long start, unsigned long end)
  58. {
  59. unsigned long va_exclude_start, va_exclude_end;
  60. va_exclude_start = VA_EXCLUDE_START;
  61. va_exclude_end = VA_EXCLUDE_END;
  62. if (likely(start < va_exclude_start && end < va_exclude_start))
  63. return 0;
  64. if (likely(start >= va_exclude_end && end >= va_exclude_end))
  65. return 0;
  66. return 1;
  67. }
  68. /* These functions differ from the default implementations in
  69. * mm/mmap.c in two ways:
  70. *
  71. * 1) For file backed MAP_SHARED mmap()'s we D-cache color align,
  72. * for fixed such mappings we just validate what the user gave us.
  73. * 2) For 64-bit tasks we avoid mapping anything within 4GB of
  74. * the spitfire/niagara VA-hole.
  75. */
  76. static inline unsigned long COLOUR_ALIGN(unsigned long addr,
  77. unsigned long pgoff)
  78. {
  79. unsigned long base = (addr+SHMLBA-1)&~(SHMLBA-1);
  80. unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
  81. return base + off;
  82. }
  83. static inline unsigned long COLOUR_ALIGN_DOWN(unsigned long addr,
  84. unsigned long pgoff)
  85. {
  86. unsigned long base = addr & ~(SHMLBA-1);
  87. unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
  88. if (base + off <= addr)
  89. return base + off;
  90. return base - off;
  91. }
  92. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  93. {
  94. struct mm_struct *mm = current->mm;
  95. struct vm_area_struct * vma;
  96. unsigned long task_size = TASK_SIZE;
  97. unsigned long start_addr;
  98. int do_color_align;
  99. if (flags & MAP_FIXED) {
  100. /* We do not accept a shared mapping if it would violate
  101. * cache aliasing constraints.
  102. */
  103. if ((flags & MAP_SHARED) &&
  104. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  105. return -EINVAL;
  106. return addr;
  107. }
  108. if (test_thread_flag(TIF_32BIT))
  109. task_size = STACK_TOP32;
  110. if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
  111. return -ENOMEM;
  112. do_color_align = 0;
  113. if (filp || (flags & MAP_SHARED))
  114. do_color_align = 1;
  115. if (addr) {
  116. if (do_color_align)
  117. addr = COLOUR_ALIGN(addr, pgoff);
  118. else
  119. addr = PAGE_ALIGN(addr);
  120. vma = find_vma(mm, addr);
  121. if (task_size - len >= addr &&
  122. (!vma || addr + len <= vm_start_gap(vma)))
  123. return addr;
  124. }
  125. if (len > mm->cached_hole_size) {
  126. start_addr = addr = mm->free_area_cache;
  127. } else {
  128. start_addr = addr = TASK_UNMAPPED_BASE;
  129. mm->cached_hole_size = 0;
  130. }
  131. task_size -= len;
  132. full_search:
  133. if (do_color_align)
  134. addr = COLOUR_ALIGN(addr, pgoff);
  135. else
  136. addr = PAGE_ALIGN(addr);
  137. for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
  138. /* At this point: (!vma || addr < vma->vm_end). */
  139. if (addr < VA_EXCLUDE_START &&
  140. (addr + len) >= VA_EXCLUDE_START) {
  141. addr = VA_EXCLUDE_END;
  142. vma = find_vma(mm, VA_EXCLUDE_END);
  143. }
  144. if (unlikely(task_size < addr)) {
  145. if (start_addr != TASK_UNMAPPED_BASE) {
  146. start_addr = addr = TASK_UNMAPPED_BASE;
  147. mm->cached_hole_size = 0;
  148. goto full_search;
  149. }
  150. return -ENOMEM;
  151. }
  152. if (likely(!vma || addr + len <= vma->vm_start)) {
  153. /*
  154. * Remember the place where we stopped the search:
  155. */
  156. mm->free_area_cache = addr + len;
  157. return addr;
  158. }
  159. if (addr + mm->cached_hole_size < vma->vm_start)
  160. mm->cached_hole_size = vma->vm_start - addr;
  161. addr = vma->vm_end;
  162. if (do_color_align)
  163. addr = COLOUR_ALIGN(addr, pgoff);
  164. }
  165. }
  166. unsigned long
  167. arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  168. const unsigned long len, const unsigned long pgoff,
  169. const unsigned long flags)
  170. {
  171. struct vm_area_struct *vma;
  172. struct mm_struct *mm = current->mm;
  173. unsigned long task_size = STACK_TOP32;
  174. unsigned long addr = addr0;
  175. int do_color_align;
  176. /* This should only ever run for 32-bit processes. */
  177. BUG_ON(!test_thread_flag(TIF_32BIT));
  178. if (flags & MAP_FIXED) {
  179. /* We do not accept a shared mapping if it would violate
  180. * cache aliasing constraints.
  181. */
  182. if ((flags & MAP_SHARED) &&
  183. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  184. return -EINVAL;
  185. return addr;
  186. }
  187. if (unlikely(len > task_size))
  188. return -ENOMEM;
  189. do_color_align = 0;
  190. if (filp || (flags & MAP_SHARED))
  191. do_color_align = 1;
  192. /* requesting a specific address */
  193. if (addr) {
  194. if (do_color_align)
  195. addr = COLOUR_ALIGN(addr, pgoff);
  196. else
  197. addr = PAGE_ALIGN(addr);
  198. vma = find_vma(mm, addr);
  199. if (task_size - len >= addr &&
  200. (!vma || addr + len <= vm_start_gap(vma)))
  201. return addr;
  202. }
  203. /* check if free_area_cache is useful for us */
  204. if (len <= mm->cached_hole_size) {
  205. mm->cached_hole_size = 0;
  206. mm->free_area_cache = mm->mmap_base;
  207. }
  208. /* either no address requested or can't fit in requested address hole */
  209. addr = mm->free_area_cache;
  210. if (do_color_align) {
  211. unsigned long base = COLOUR_ALIGN_DOWN(addr-len, pgoff);
  212. addr = base + len;
  213. }
  214. /* make sure it can fit in the remaining address space */
  215. if (likely(addr > len)) {
  216. vma = find_vma(mm, addr-len);
  217. if (!vma || addr <= vma->vm_start) {
  218. /* remember the address as a hint for next time */
  219. return (mm->free_area_cache = addr-len);
  220. }
  221. }
  222. if (unlikely(mm->mmap_base < len))
  223. goto bottomup;
  224. addr = mm->mmap_base-len;
  225. if (do_color_align)
  226. addr = COLOUR_ALIGN_DOWN(addr, pgoff);
  227. do {
  228. /*
  229. * Lookup failure means no vma is above this address,
  230. * else if new region fits below vma->vm_start,
  231. * return with success:
  232. */
  233. vma = find_vma(mm, addr);
  234. if (likely(!vma || addr+len <= vma->vm_start)) {
  235. /* remember the address as a hint for next time */
  236. return (mm->free_area_cache = addr);
  237. }
  238. /* remember the largest hole we saw so far */
  239. if (addr + mm->cached_hole_size < vma->vm_start)
  240. mm->cached_hole_size = vma->vm_start - addr;
  241. /* try just below the current vma->vm_start */
  242. addr = vma->vm_start-len;
  243. if (do_color_align)
  244. addr = COLOUR_ALIGN_DOWN(addr, pgoff);
  245. } while (likely(len < vma->vm_start));
  246. bottomup:
  247. /*
  248. * A failed mmap() very likely causes application failure,
  249. * so fall back to the bottom-up function here. This scenario
  250. * can happen with large stack limits and large mmap()
  251. * allocations.
  252. */
  253. mm->cached_hole_size = ~0UL;
  254. mm->free_area_cache = TASK_UNMAPPED_BASE;
  255. addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
  256. /*
  257. * Restore the topdown base:
  258. */
  259. mm->free_area_cache = mm->mmap_base;
  260. mm->cached_hole_size = ~0UL;
  261. return addr;
  262. }
  263. /* Try to align mapping such that we align it as much as possible. */
  264. unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  265. {
  266. unsigned long align_goal, addr = -ENOMEM;
  267. unsigned long (*get_area)(struct file *, unsigned long,
  268. unsigned long, unsigned long, unsigned long);
  269. get_area = current->mm->get_unmapped_area;
  270. if (flags & MAP_FIXED) {
  271. /* Ok, don't mess with it. */
  272. return get_area(NULL, orig_addr, len, pgoff, flags);
  273. }
  274. flags &= ~MAP_SHARED;
  275. align_goal = PAGE_SIZE;
  276. if (len >= (4UL * 1024 * 1024))
  277. align_goal = (4UL * 1024 * 1024);
  278. else if (len >= (512UL * 1024))
  279. align_goal = (512UL * 1024);
  280. else if (len >= (64UL * 1024))
  281. align_goal = (64UL * 1024);
  282. do {
  283. addr = get_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags);
  284. if (!(addr & ~PAGE_MASK)) {
  285. addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
  286. break;
  287. }
  288. if (align_goal == (4UL * 1024 * 1024))
  289. align_goal = (512UL * 1024);
  290. else if (align_goal == (512UL * 1024))
  291. align_goal = (64UL * 1024);
  292. else
  293. align_goal = PAGE_SIZE;
  294. } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
  295. /* Mapping is smaller than 64K or larger areas could not
  296. * be obtained.
  297. */
  298. if (addr & ~PAGE_MASK)
  299. addr = get_area(NULL, orig_addr, len, pgoff, flags);
  300. return addr;
  301. }
  302. EXPORT_SYMBOL(get_fb_unmapped_area);
  303. /* Essentially the same as PowerPC. */
  304. static unsigned long mmap_rnd(void)
  305. {
  306. unsigned long rnd = 0UL;
  307. if (current->flags & PF_RANDOMIZE) {
  308. unsigned long val = get_random_long();
  309. if (test_thread_flag(TIF_32BIT))
  310. rnd = (val % (1UL << (23UL-PAGE_SHIFT)));
  311. else
  312. rnd = (val % (1UL << (30UL-PAGE_SHIFT)));
  313. }
  314. return rnd << PAGE_SHIFT;
  315. }
  316. void arch_pick_mmap_layout(struct mm_struct *mm)
  317. {
  318. unsigned long random_factor = mmap_rnd();
  319. unsigned long gap;
  320. /*
  321. * Fall back to the standard layout if the personality
  322. * bit is set, or if the expected stack growth is unlimited:
  323. */
  324. gap = rlimit(RLIMIT_STACK);
  325. if (!test_thread_flag(TIF_32BIT) ||
  326. (current->personality & ADDR_COMPAT_LAYOUT) ||
  327. gap == RLIM_INFINITY ||
  328. sysctl_legacy_va_layout) {
  329. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  330. mm->get_unmapped_area = arch_get_unmapped_area;
  331. mm->unmap_area = arch_unmap_area;
  332. } else {
  333. /* We know it's 32-bit */
  334. unsigned long task_size = STACK_TOP32;
  335. if (gap < 128 * 1024 * 1024)
  336. gap = 128 * 1024 * 1024;
  337. if (gap > (task_size / 6 * 5))
  338. gap = (task_size / 6 * 5);
  339. mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
  340. mm->get_unmapped_area = arch_get_unmapped_area_topdown;
  341. mm->unmap_area = arch_unmap_area_topdown;
  342. }
  343. }
  344. /*
  345. * sys_pipe() is the normal C calling standard for creating
  346. * a pipe. It's not the way unix traditionally does this, though.
  347. */
  348. SYSCALL_DEFINE1(sparc_pipe_real, struct pt_regs *, regs)
  349. {
  350. int fd[2];
  351. int error;
  352. error = do_pipe_flags(fd, 0);
  353. if (error)
  354. goto out;
  355. regs->u_regs[UREG_I1] = fd[1];
  356. error = fd[0];
  357. out:
  358. return error;
  359. }
  360. /*
  361. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  362. *
  363. * This is really horribly ugly.
  364. */
  365. SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second,
  366. unsigned long, third, void __user *, ptr, long, fifth)
  367. {
  368. long err;
  369. /* No need for backward compatibility. We can start fresh... */
  370. if (call <= SEMCTL) {
  371. switch (call) {
  372. case SEMOP:
  373. err = sys_semtimedop(first, ptr,
  374. (unsigned)second, NULL);
  375. goto out;
  376. case SEMTIMEDOP:
  377. err = sys_semtimedop(first, ptr, (unsigned)second,
  378. (const struct timespec __user *)
  379. (unsigned long) fifth);
  380. goto out;
  381. case SEMGET:
  382. err = sys_semget(first, (int)second, (int)third);
  383. goto out;
  384. case SEMCTL: {
  385. err = sys_semctl(first, second,
  386. (int)third | IPC_64,
  387. (union semun) ptr);
  388. goto out;
  389. }
  390. default:
  391. err = -ENOSYS;
  392. goto out;
  393. }
  394. }
  395. if (call <= MSGCTL) {
  396. switch (call) {
  397. case MSGSND:
  398. err = sys_msgsnd(first, ptr, (size_t)second,
  399. (int)third);
  400. goto out;
  401. case MSGRCV:
  402. err = sys_msgrcv(first, ptr, (size_t)second, fifth,
  403. (int)third);
  404. goto out;
  405. case MSGGET:
  406. err = sys_msgget((key_t)first, (int)second);
  407. goto out;
  408. case MSGCTL:
  409. err = sys_msgctl(first, (int)second | IPC_64, ptr);
  410. goto out;
  411. default:
  412. err = -ENOSYS;
  413. goto out;
  414. }
  415. }
  416. if (call <= SHMCTL) {
  417. switch (call) {
  418. case SHMAT: {
  419. ulong raddr;
  420. err = do_shmat(first, ptr, (int)second, &raddr, SHMLBA);
  421. if (!err) {
  422. if (put_user(raddr,
  423. (ulong __user *) third))
  424. err = -EFAULT;
  425. }
  426. goto out;
  427. }
  428. case SHMDT:
  429. err = sys_shmdt(ptr);
  430. goto out;
  431. case SHMGET:
  432. err = sys_shmget(first, (size_t)second, (int)third);
  433. goto out;
  434. case SHMCTL:
  435. err = sys_shmctl(first, (int)second | IPC_64, ptr);
  436. goto out;
  437. default:
  438. err = -ENOSYS;
  439. goto out;
  440. }
  441. } else {
  442. err = -ENOSYS;
  443. }
  444. out:
  445. return err;
  446. }
  447. SYSCALL_DEFINE1(sparc64_personality, unsigned long, personality)
  448. {
  449. int ret;
  450. if (personality(current->personality) == PER_LINUX32 &&
  451. personality(personality) == PER_LINUX)
  452. personality |= PER_LINUX32;
  453. ret = sys_personality(personality);
  454. if (personality(ret) == PER_LINUX32)
  455. ret &= ~PER_LINUX32;
  456. return ret;
  457. }
  458. int sparc_mmap_check(unsigned long addr, unsigned long len)
  459. {
  460. if (test_thread_flag(TIF_32BIT)) {
  461. if (len >= STACK_TOP32)
  462. return -EINVAL;
  463. if (addr > STACK_TOP32 - len)
  464. return -EINVAL;
  465. } else {
  466. if (len >= VA_EXCLUDE_START)
  467. return -EINVAL;
  468. if (invalid_64bit_range(addr, len))
  469. return -EINVAL;
  470. }
  471. return 0;
  472. }
  473. /* Linux version of mmap */
  474. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  475. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  476. unsigned long, off)
  477. {
  478. unsigned long retval = -EINVAL;
  479. if ((off + PAGE_ALIGN(len)) < off)
  480. goto out;
  481. if (off & ~PAGE_MASK)
  482. goto out;
  483. retval = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  484. out:
  485. return retval;
  486. }
  487. SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len)
  488. {
  489. if (invalid_64bit_range(addr, len))
  490. return -EINVAL;
  491. return vm_munmap(addr, len);
  492. }
  493. extern unsigned long do_mremap(unsigned long addr,
  494. unsigned long old_len, unsigned long new_len,
  495. unsigned long flags, unsigned long new_addr);
  496. SYSCALL_DEFINE5(64_mremap, unsigned long, addr, unsigned long, old_len,
  497. unsigned long, new_len, unsigned long, flags,
  498. unsigned long, new_addr)
  499. {
  500. unsigned long ret = -EINVAL;
  501. if (test_thread_flag(TIF_32BIT))
  502. goto out;
  503. down_write(&current->mm->mmap_sem);
  504. ret = do_mremap(addr, old_len, new_len, flags, new_addr);
  505. up_write(&current->mm->mmap_sem);
  506. out:
  507. return ret;
  508. }
  509. /* we come to here via sys_nis_syscall so it can setup the regs argument */
  510. asmlinkage unsigned long c_sys_nis_syscall(struct pt_regs *regs)
  511. {
  512. static int count;
  513. /* Don't make the system unusable, if someone goes stuck */
  514. if (count++ > 5)
  515. return -ENOSYS;
  516. printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
  517. #ifdef DEBUG_UNIMP_SYSCALL
  518. show_regs (regs);
  519. #endif
  520. return -ENOSYS;
  521. }
  522. /* #define DEBUG_SPARC_BREAKPOINT */
  523. asmlinkage void sparc_breakpoint(struct pt_regs *regs)
  524. {
  525. siginfo_t info;
  526. if (test_thread_flag(TIF_32BIT)) {
  527. regs->tpc &= 0xffffffff;
  528. regs->tnpc &= 0xffffffff;
  529. }
  530. #ifdef DEBUG_SPARC_BREAKPOINT
  531. printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
  532. #endif
  533. info.si_signo = SIGTRAP;
  534. info.si_errno = 0;
  535. info.si_code = TRAP_BRKPT;
  536. info.si_addr = (void __user *)regs->tpc;
  537. info.si_trapno = 0;
  538. force_sig_info(SIGTRAP, &info, current);
  539. #ifdef DEBUG_SPARC_BREAKPOINT
  540. printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
  541. #endif
  542. }
  543. extern void check_pending(int signum);
  544. SYSCALL_DEFINE2(getdomainname, char __user *, name, int, len)
  545. {
  546. int nlen, err;
  547. if (len < 0)
  548. return -EINVAL;
  549. down_read(&uts_sem);
  550. nlen = strlen(utsname()->domainname) + 1;
  551. err = -EINVAL;
  552. if (nlen > len)
  553. goto out;
  554. err = -EFAULT;
  555. if (!copy_to_user(name, utsname()->domainname, nlen))
  556. err = 0;
  557. out:
  558. up_read(&uts_sem);
  559. return err;
  560. }
  561. SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
  562. utrap_handler_t, new_p, utrap_handler_t, new_d,
  563. utrap_handler_t __user *, old_p,
  564. utrap_handler_t __user *, old_d)
  565. {
  566. if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
  567. return -EINVAL;
  568. if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
  569. if (old_p) {
  570. if (!current_thread_info()->utraps) {
  571. if (put_user(NULL, old_p))
  572. return -EFAULT;
  573. } else {
  574. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  575. return -EFAULT;
  576. }
  577. }
  578. if (old_d) {
  579. if (put_user(NULL, old_d))
  580. return -EFAULT;
  581. }
  582. return 0;
  583. }
  584. if (!current_thread_info()->utraps) {
  585. current_thread_info()->utraps =
  586. kzalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), GFP_KERNEL);
  587. if (!current_thread_info()->utraps)
  588. return -ENOMEM;
  589. current_thread_info()->utraps[0] = 1;
  590. } else {
  591. if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
  592. current_thread_info()->utraps[0] > 1) {
  593. unsigned long *p = current_thread_info()->utraps;
  594. current_thread_info()->utraps =
  595. kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
  596. GFP_KERNEL);
  597. if (!current_thread_info()->utraps) {
  598. current_thread_info()->utraps = p;
  599. return -ENOMEM;
  600. }
  601. p[0]--;
  602. current_thread_info()->utraps[0] = 1;
  603. memcpy(current_thread_info()->utraps+1, p+1,
  604. UT_TRAP_INSTRUCTION_31*sizeof(long));
  605. }
  606. }
  607. if (old_p) {
  608. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  609. return -EFAULT;
  610. }
  611. if (old_d) {
  612. if (put_user(NULL, old_d))
  613. return -EFAULT;
  614. }
  615. current_thread_info()->utraps[type] = (long)new_p;
  616. return 0;
  617. }
  618. asmlinkage long sparc_memory_ordering(unsigned long model,
  619. struct pt_regs *regs)
  620. {
  621. if (model >= 3)
  622. return -EINVAL;
  623. regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
  624. return 0;
  625. }
  626. SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act,
  627. struct sigaction __user *, oact, void __user *, restorer,
  628. size_t, sigsetsize)
  629. {
  630. struct k_sigaction new_ka, old_ka;
  631. int ret;
  632. /* XXX: Don't preclude handling different sized sigset_t's. */
  633. if (sigsetsize != sizeof(sigset_t))
  634. return -EINVAL;
  635. if (act) {
  636. new_ka.ka_restorer = restorer;
  637. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  638. return -EFAULT;
  639. }
  640. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  641. if (!ret && oact) {
  642. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  643. return -EFAULT;
  644. }
  645. return ret;
  646. }
  647. /*
  648. * Do a system call from kernel instead of calling sys_execve so we
  649. * end up with proper pt_regs.
  650. */
  651. int kernel_execve(const char *filename,
  652. const char *const argv[],
  653. const char *const envp[])
  654. {
  655. long __res;
  656. register long __g1 __asm__ ("g1") = __NR_execve;
  657. register long __o0 __asm__ ("o0") = (long)(filename);
  658. register long __o1 __asm__ ("o1") = (long)(argv);
  659. register long __o2 __asm__ ("o2") = (long)(envp);
  660. asm volatile ("t 0x6d\n\t"
  661. "sub %%g0, %%o0, %0\n\t"
  662. "movcc %%xcc, %%o0, %0\n\t"
  663. : "=r" (__res), "=&r" (__o0)
  664. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
  665. : "cc");
  666. return __res;
  667. }