sys_sparc_64.c 17 KB

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