sys_sparc_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. // SPDX-License-Identifier: GPL-2.0
  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/signal.h>
  11. #include <linux/sched/mm.h>
  12. #include <linux/sched/debug.h>
  13. #include <linux/fs.h>
  14. #include <linux/file.h>
  15. #include <linux/mm.h>
  16. #include <linux/sem.h>
  17. #include <linux/msg.h>
  18. #include <linux/shm.h>
  19. #include <linux/stat.h>
  20. #include <linux/mman.h>
  21. #include <linux/utsname.h>
  22. #include <linux/smp.h>
  23. #include <linux/slab.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/ipc.h>
  26. #include <linux/personality.h>
  27. #include <linux/random.h>
  28. #include <linux/export.h>
  29. #include <linux/context_tracking.h>
  30. #include <linux/timex.h>
  31. #include <linux/uaccess.h>
  32. #include <asm/utrap.h>
  33. #include <asm/unistd.h>
  34. #include "entry.h"
  35. #include "kernel.h"
  36. #include "systbls.h"
  37. /* #define DEBUG_UNIMP_SYSCALL */
  38. SYSCALL_DEFINE0(getpagesize)
  39. {
  40. return PAGE_SIZE;
  41. }
  42. /* Does addr --> addr+len fall within 4GB of the VA-space hole or
  43. * overflow past the end of the 64-bit address space?
  44. */
  45. static inline int invalid_64bit_range(unsigned long addr, unsigned long len)
  46. {
  47. unsigned long va_exclude_start, va_exclude_end;
  48. va_exclude_start = VA_EXCLUDE_START;
  49. va_exclude_end = VA_EXCLUDE_END;
  50. if (unlikely(len >= va_exclude_start))
  51. return 1;
  52. if (unlikely((addr + len) < addr))
  53. return 1;
  54. if (unlikely((addr >= va_exclude_start && addr < va_exclude_end) ||
  55. ((addr + len) >= va_exclude_start &&
  56. (addr + len) < va_exclude_end)))
  57. return 1;
  58. return 0;
  59. }
  60. /* These functions differ from the default implementations in
  61. * mm/mmap.c in two ways:
  62. *
  63. * 1) For file backed MAP_SHARED mmap()'s we D-cache color align,
  64. * for fixed such mappings we just validate what the user gave us.
  65. * 2) For 64-bit tasks we avoid mapping anything within 4GB of
  66. * the spitfire/niagara VA-hole.
  67. */
  68. static inline unsigned long COLOR_ALIGN(unsigned long addr,
  69. unsigned long pgoff)
  70. {
  71. unsigned long base = (addr+SHMLBA-1)&~(SHMLBA-1);
  72. unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
  73. return base + off;
  74. }
  75. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
  76. {
  77. struct mm_struct *mm = current->mm;
  78. struct vm_area_struct * vma;
  79. unsigned long task_size = TASK_SIZE;
  80. int do_color_align;
  81. struct vm_unmapped_area_info info = {};
  82. if (flags & MAP_FIXED) {
  83. /* We do not accept a shared mapping if it would violate
  84. * cache aliasing constraints.
  85. */
  86. if ((flags & MAP_SHARED) &&
  87. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  88. return -EINVAL;
  89. return addr;
  90. }
  91. if (test_thread_flag(TIF_32BIT))
  92. task_size = STACK_TOP32;
  93. if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
  94. return -ENOMEM;
  95. do_color_align = 0;
  96. if (filp || (flags & MAP_SHARED))
  97. do_color_align = 1;
  98. if (addr) {
  99. if (do_color_align)
  100. addr = COLOR_ALIGN(addr, pgoff);
  101. else
  102. addr = PAGE_ALIGN(addr);
  103. vma = find_vma(mm, addr);
  104. if (task_size - len >= addr &&
  105. (!vma || addr + len <= vm_start_gap(vma)))
  106. return addr;
  107. }
  108. info.length = len;
  109. info.low_limit = TASK_UNMAPPED_BASE;
  110. info.high_limit = min(task_size, VA_EXCLUDE_START);
  111. info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  112. info.align_offset = pgoff << PAGE_SHIFT;
  113. addr = vm_unmapped_area(&info);
  114. if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
  115. VM_BUG_ON(addr != -ENOMEM);
  116. info.low_limit = VA_EXCLUDE_END;
  117. info.high_limit = task_size;
  118. addr = vm_unmapped_area(&info);
  119. }
  120. return addr;
  121. }
  122. unsigned long
  123. arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
  124. const unsigned long len, const unsigned long pgoff,
  125. const unsigned long flags, vm_flags_t vm_flags)
  126. {
  127. struct vm_area_struct *vma;
  128. struct mm_struct *mm = current->mm;
  129. unsigned long task_size = STACK_TOP32;
  130. unsigned long addr = addr0;
  131. int do_color_align;
  132. struct vm_unmapped_area_info info = {};
  133. /* This should only ever run for 32-bit processes. */
  134. BUG_ON(!test_thread_flag(TIF_32BIT));
  135. if (flags & MAP_FIXED) {
  136. /* We do not accept a shared mapping if it would violate
  137. * cache aliasing constraints.
  138. */
  139. if ((flags & MAP_SHARED) &&
  140. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  141. return -EINVAL;
  142. return addr;
  143. }
  144. if (unlikely(len > task_size))
  145. return -ENOMEM;
  146. do_color_align = 0;
  147. if (filp || (flags & MAP_SHARED))
  148. do_color_align = 1;
  149. /* requesting a specific address */
  150. if (addr) {
  151. if (do_color_align)
  152. addr = COLOR_ALIGN(addr, pgoff);
  153. else
  154. addr = PAGE_ALIGN(addr);
  155. vma = find_vma(mm, addr);
  156. if (task_size - len >= addr &&
  157. (!vma || addr + len <= vm_start_gap(vma)))
  158. return addr;
  159. }
  160. info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  161. info.length = len;
  162. info.low_limit = PAGE_SIZE;
  163. info.high_limit = mm->mmap_base;
  164. info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
  165. info.align_offset = pgoff << PAGE_SHIFT;
  166. addr = vm_unmapped_area(&info);
  167. /*
  168. * A failed mmap() very likely causes application failure,
  169. * so fall back to the bottom-up function here. This scenario
  170. * can happen with large stack limits and large mmap()
  171. * allocations.
  172. */
  173. if (addr & ~PAGE_MASK) {
  174. VM_BUG_ON(addr != -ENOMEM);
  175. info.flags = 0;
  176. info.low_limit = TASK_UNMAPPED_BASE;
  177. info.high_limit = STACK_TOP32;
  178. addr = vm_unmapped_area(&info);
  179. }
  180. return addr;
  181. }
  182. /* Try to align mapping such that we align it as much as possible. */
  183. unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
  184. {
  185. unsigned long align_goal, addr = -ENOMEM;
  186. if (flags & MAP_FIXED) {
  187. /* Ok, don't mess with it. */
  188. return mm_get_unmapped_area(current->mm, NULL, orig_addr, len, pgoff, flags);
  189. }
  190. flags &= ~MAP_SHARED;
  191. align_goal = PAGE_SIZE;
  192. if (len >= (4UL * 1024 * 1024))
  193. align_goal = (4UL * 1024 * 1024);
  194. else if (len >= (512UL * 1024))
  195. align_goal = (512UL * 1024);
  196. else if (len >= (64UL * 1024))
  197. align_goal = (64UL * 1024);
  198. do {
  199. addr = mm_get_unmapped_area(current->mm, NULL, orig_addr,
  200. len + (align_goal - PAGE_SIZE), pgoff, flags);
  201. if (!(addr & ~PAGE_MASK)) {
  202. addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
  203. break;
  204. }
  205. if (align_goal == (4UL * 1024 * 1024))
  206. align_goal = (512UL * 1024);
  207. else if (align_goal == (512UL * 1024))
  208. align_goal = (64UL * 1024);
  209. else
  210. align_goal = PAGE_SIZE;
  211. } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
  212. /* Mapping is smaller than 64K or larger areas could not
  213. * be obtained.
  214. */
  215. if (addr & ~PAGE_MASK)
  216. addr = mm_get_unmapped_area(current->mm, NULL, orig_addr, len, pgoff, flags);
  217. return addr;
  218. }
  219. EXPORT_SYMBOL(get_fb_unmapped_area);
  220. /* Essentially the same as PowerPC. */
  221. static unsigned long mmap_rnd(void)
  222. {
  223. unsigned long rnd = 0UL;
  224. if (current->flags & PF_RANDOMIZE) {
  225. unsigned long val = get_random_long();
  226. if (test_thread_flag(TIF_32BIT))
  227. rnd = (val % (1UL << (23UL-PAGE_SHIFT)));
  228. else
  229. rnd = (val % (1UL << (30UL-PAGE_SHIFT)));
  230. }
  231. return rnd << PAGE_SHIFT;
  232. }
  233. void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
  234. {
  235. unsigned long random_factor = mmap_rnd();
  236. unsigned long gap;
  237. /*
  238. * Fall back to the standard layout if the personality
  239. * bit is set, or if the expected stack growth is unlimited:
  240. */
  241. gap = rlim_stack->rlim_cur;
  242. if (!test_thread_flag(TIF_32BIT) ||
  243. (current->personality & ADDR_COMPAT_LAYOUT) ||
  244. gap == RLIM_INFINITY ||
  245. sysctl_legacy_va_layout) {
  246. mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
  247. clear_bit(MMF_TOPDOWN, &mm->flags);
  248. } else {
  249. /* We know it's 32-bit */
  250. unsigned long task_size = STACK_TOP32;
  251. if (gap < 128 * 1024 * 1024)
  252. gap = 128 * 1024 * 1024;
  253. if (gap > (task_size / 6 * 5))
  254. gap = (task_size / 6 * 5);
  255. mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
  256. set_bit(MMF_TOPDOWN, &mm->flags);
  257. }
  258. }
  259. /*
  260. * sys_pipe() is the normal C calling standard for creating
  261. * a pipe. It's not the way unix traditionally does this, though.
  262. */
  263. SYSCALL_DEFINE0(sparc_pipe)
  264. {
  265. int fd[2];
  266. int error;
  267. error = do_pipe_flags(fd, 0);
  268. if (error)
  269. goto out;
  270. current_pt_regs()->u_regs[UREG_I1] = fd[1];
  271. error = fd[0];
  272. out:
  273. return error;
  274. }
  275. /*
  276. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  277. *
  278. * This is really horribly ugly.
  279. */
  280. SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second,
  281. unsigned long, third, void __user *, ptr, long, fifth)
  282. {
  283. long err;
  284. if (!IS_ENABLED(CONFIG_SYSVIPC))
  285. return -ENOSYS;
  286. /* No need for backward compatibility. We can start fresh... */
  287. if (call <= SEMTIMEDOP) {
  288. switch (call) {
  289. case SEMOP:
  290. err = ksys_semtimedop(first, ptr,
  291. (unsigned int)second, NULL);
  292. goto out;
  293. case SEMTIMEDOP:
  294. err = ksys_semtimedop(first, ptr, (unsigned int)second,
  295. (const struct __kernel_timespec __user *)
  296. (unsigned long) fifth);
  297. goto out;
  298. case SEMGET:
  299. err = ksys_semget(first, (int)second, (int)third);
  300. goto out;
  301. case SEMCTL: {
  302. err = ksys_old_semctl(first, second,
  303. (int)third | IPC_64,
  304. (unsigned long) ptr);
  305. goto out;
  306. }
  307. default:
  308. err = -ENOSYS;
  309. goto out;
  310. }
  311. }
  312. if (call <= MSGCTL) {
  313. switch (call) {
  314. case MSGSND:
  315. err = ksys_msgsnd(first, ptr, (size_t)second,
  316. (int)third);
  317. goto out;
  318. case MSGRCV:
  319. err = ksys_msgrcv(first, ptr, (size_t)second, fifth,
  320. (int)third);
  321. goto out;
  322. case MSGGET:
  323. err = ksys_msgget((key_t)first, (int)second);
  324. goto out;
  325. case MSGCTL:
  326. err = ksys_old_msgctl(first, (int)second | IPC_64, ptr);
  327. goto out;
  328. default:
  329. err = -ENOSYS;
  330. goto out;
  331. }
  332. }
  333. if (call <= SHMCTL) {
  334. switch (call) {
  335. case SHMAT: {
  336. ulong raddr;
  337. err = do_shmat(first, ptr, (int)second, &raddr, SHMLBA);
  338. if (!err) {
  339. if (put_user(raddr,
  340. (ulong __user *) third))
  341. err = -EFAULT;
  342. }
  343. goto out;
  344. }
  345. case SHMDT:
  346. err = ksys_shmdt(ptr);
  347. goto out;
  348. case SHMGET:
  349. err = ksys_shmget(first, (size_t)second, (int)third);
  350. goto out;
  351. case SHMCTL:
  352. err = ksys_old_shmctl(first, (int)second | IPC_64, ptr);
  353. goto out;
  354. default:
  355. err = -ENOSYS;
  356. goto out;
  357. }
  358. } else {
  359. err = -ENOSYS;
  360. }
  361. out:
  362. return err;
  363. }
  364. SYSCALL_DEFINE1(sparc64_personality, unsigned long, personality)
  365. {
  366. long ret;
  367. if (personality(current->personality) == PER_LINUX32 &&
  368. personality(personality) == PER_LINUX)
  369. personality |= PER_LINUX32;
  370. ret = sys_personality(personality);
  371. if (personality(ret) == PER_LINUX32)
  372. ret &= ~PER_LINUX32;
  373. return ret;
  374. }
  375. int sparc_mmap_check(unsigned long addr, unsigned long len)
  376. {
  377. if (test_thread_flag(TIF_32BIT)) {
  378. if (len >= STACK_TOP32)
  379. return -EINVAL;
  380. if (addr > STACK_TOP32 - len)
  381. return -EINVAL;
  382. } else {
  383. if (len >= VA_EXCLUDE_START)
  384. return -EINVAL;
  385. if (invalid_64bit_range(addr, len))
  386. return -EINVAL;
  387. }
  388. return 0;
  389. }
  390. /* Linux version of mmap */
  391. SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  392. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  393. unsigned long, off)
  394. {
  395. unsigned long retval = -EINVAL;
  396. if ((off + PAGE_ALIGN(len)) < off)
  397. goto out;
  398. if (off & ~PAGE_MASK)
  399. goto out;
  400. retval = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  401. out:
  402. return retval;
  403. }
  404. SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len)
  405. {
  406. if (invalid_64bit_range(addr, len))
  407. return -EINVAL;
  408. return vm_munmap(addr, len);
  409. }
  410. SYSCALL_DEFINE5(64_mremap, unsigned long, addr, unsigned long, old_len,
  411. unsigned long, new_len, unsigned long, flags,
  412. unsigned long, new_addr)
  413. {
  414. if (test_thread_flag(TIF_32BIT))
  415. return -EINVAL;
  416. return sys_mremap(addr, old_len, new_len, flags, new_addr);
  417. }
  418. SYSCALL_DEFINE0(nis_syscall)
  419. {
  420. static int count;
  421. struct pt_regs *regs = current_pt_regs();
  422. /* Don't make the system unusable, if someone goes stuck */
  423. if (count++ > 5)
  424. return -ENOSYS;
  425. printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
  426. #ifdef DEBUG_UNIMP_SYSCALL
  427. show_regs (regs);
  428. #endif
  429. return -ENOSYS;
  430. }
  431. /* #define DEBUG_SPARC_BREAKPOINT */
  432. asmlinkage void sparc_breakpoint(struct pt_regs *regs)
  433. {
  434. enum ctx_state prev_state = exception_enter();
  435. if (test_thread_flag(TIF_32BIT)) {
  436. regs->tpc &= 0xffffffff;
  437. regs->tnpc &= 0xffffffff;
  438. }
  439. #ifdef DEBUG_SPARC_BREAKPOINT
  440. printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
  441. #endif
  442. force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->tpc);
  443. #ifdef DEBUG_SPARC_BREAKPOINT
  444. printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
  445. #endif
  446. exception_exit(prev_state);
  447. }
  448. SYSCALL_DEFINE2(getdomainname, char __user *, name, int, len)
  449. {
  450. int nlen, err;
  451. char tmp[__NEW_UTS_LEN + 1];
  452. if (len < 0)
  453. return -EINVAL;
  454. down_read(&uts_sem);
  455. nlen = strlen(utsname()->domainname) + 1;
  456. err = -EINVAL;
  457. if (nlen > len)
  458. goto out_unlock;
  459. memcpy(tmp, utsname()->domainname, nlen);
  460. up_read(&uts_sem);
  461. if (copy_to_user(name, tmp, nlen))
  462. return -EFAULT;
  463. return 0;
  464. out_unlock:
  465. up_read(&uts_sem);
  466. return err;
  467. }
  468. SYSCALL_DEFINE1(sparc_adjtimex, struct __kernel_timex __user *, txc_p)
  469. {
  470. struct __kernel_timex txc;
  471. struct __kernel_old_timeval *tv = (void *)&txc.time;
  472. int ret;
  473. /* Copy the user data space into the kernel copy
  474. * structure. But bear in mind that the structures
  475. * may change
  476. */
  477. if (copy_from_user(&txc, txc_p, sizeof(txc)))
  478. return -EFAULT;
  479. /*
  480. * override for sparc64 specific timeval type: tv_usec
  481. * is 32 bit wide instead of 64-bit in __kernel_timex
  482. */
  483. txc.time.tv_usec = tv->tv_usec;
  484. ret = do_adjtimex(&txc);
  485. tv->tv_usec = txc.time.tv_usec;
  486. return copy_to_user(txc_p, &txc, sizeof(txc)) ? -EFAULT : ret;
  487. }
  488. SYSCALL_DEFINE2(sparc_clock_adjtime, const clockid_t, which_clock,
  489. struct __kernel_timex __user *, txc_p)
  490. {
  491. struct __kernel_timex txc;
  492. struct __kernel_old_timeval *tv = (void *)&txc.time;
  493. int ret;
  494. if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) {
  495. pr_err_once("process %d (%s) attempted a POSIX timer syscall "
  496. "while CONFIG_POSIX_TIMERS is not set\n",
  497. current->pid, current->comm);
  498. return -ENOSYS;
  499. }
  500. /* Copy the user data space into the kernel copy
  501. * structure. But bear in mind that the structures
  502. * may change
  503. */
  504. if (copy_from_user(&txc, txc_p, sizeof(txc)))
  505. return -EFAULT;
  506. /*
  507. * override for sparc64 specific timeval type: tv_usec
  508. * is 32 bit wide instead of 64-bit in __kernel_timex
  509. */
  510. txc.time.tv_usec = tv->tv_usec;
  511. ret = do_clock_adjtime(which_clock, &txc);
  512. tv->tv_usec = txc.time.tv_usec;
  513. return copy_to_user(txc_p, &txc, sizeof(txc)) ? -EFAULT : ret;
  514. }
  515. SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
  516. utrap_handler_t, new_p, utrap_handler_t, new_d,
  517. utrap_handler_t __user *, old_p,
  518. utrap_handler_t __user *, old_d)
  519. {
  520. if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
  521. return -EINVAL;
  522. if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
  523. if (old_p) {
  524. if (!current_thread_info()->utraps) {
  525. if (put_user(NULL, old_p))
  526. return -EFAULT;
  527. } else {
  528. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  529. return -EFAULT;
  530. }
  531. }
  532. if (old_d) {
  533. if (put_user(NULL, old_d))
  534. return -EFAULT;
  535. }
  536. return 0;
  537. }
  538. if (!current_thread_info()->utraps) {
  539. current_thread_info()->utraps =
  540. kcalloc(UT_TRAP_INSTRUCTION_31 + 1, sizeof(long),
  541. GFP_KERNEL);
  542. if (!current_thread_info()->utraps)
  543. return -ENOMEM;
  544. current_thread_info()->utraps[0] = 1;
  545. } else {
  546. if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
  547. current_thread_info()->utraps[0] > 1) {
  548. unsigned long *p = current_thread_info()->utraps;
  549. current_thread_info()->utraps =
  550. kmalloc_array(UT_TRAP_INSTRUCTION_31 + 1,
  551. sizeof(long),
  552. GFP_KERNEL);
  553. if (!current_thread_info()->utraps) {
  554. current_thread_info()->utraps = p;
  555. return -ENOMEM;
  556. }
  557. p[0]--;
  558. current_thread_info()->utraps[0] = 1;
  559. memcpy(current_thread_info()->utraps+1, p+1,
  560. UT_TRAP_INSTRUCTION_31*sizeof(long));
  561. }
  562. }
  563. if (old_p) {
  564. if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
  565. return -EFAULT;
  566. }
  567. if (old_d) {
  568. if (put_user(NULL, old_d))
  569. return -EFAULT;
  570. }
  571. current_thread_info()->utraps[type] = (long)new_p;
  572. return 0;
  573. }
  574. SYSCALL_DEFINE1(memory_ordering, unsigned long, model)
  575. {
  576. struct pt_regs *regs = current_pt_regs();
  577. if (model >= 3)
  578. return -EINVAL;
  579. regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
  580. return 0;
  581. }
  582. SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act,
  583. struct sigaction __user *, oact, void __user *, restorer,
  584. size_t, sigsetsize)
  585. {
  586. struct k_sigaction new_ka, old_ka;
  587. int ret;
  588. /* XXX: Don't preclude handling different sized sigset_t's. */
  589. if (sigsetsize != sizeof(sigset_t))
  590. return -EINVAL;
  591. if (act) {
  592. new_ka.ka_restorer = restorer;
  593. if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  594. return -EFAULT;
  595. }
  596. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  597. if (!ret && oact) {
  598. if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  599. return -EFAULT;
  600. }
  601. return ret;
  602. }
  603. SYSCALL_DEFINE0(kern_features)
  604. {
  605. return KERN_FEATURE_MIXED_MODE_STACK;
  606. }