2 * linux/kernel/compat.c
4 * Kernel compatibililty routines for e.g. 32 bit syscall support
7 * Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/linkage.h>
15 #include <linux/compat.h>
16 #include <linux/errno.h>
17 #include <linux/time.h>
18 #include <linux/signal.h>
19 #include <linux/sched.h> /* for MAX_SCHEDULE_TIMEOUT */
20 #include <linux/syscalls.h>
21 #include <linux/unistd.h>
22 #include <linux/security.h>
23 #include <linux/timex.h>
24 #include <linux/migrate.h>
25 #include <linux/posix-timers.h>
26 #include <linux/times.h>
27 #include <linux/ptrace.h>
29 #include <asm/uaccess.h>
32 * Note that the native side is already converted to a timespec, because
33 * that's what we want anyway.
35 static int compat_get_timeval(struct timespec
*o
,
36 struct compat_timeval __user
*i
)
40 if (get_user(o
->tv_sec
, &i
->tv_sec
) ||
41 get_user(usec
, &i
->tv_usec
))
43 o
->tv_nsec
= usec
* 1000;
47 static int compat_put_timeval(struct compat_timeval __user
*o
,
50 return (put_user(i
->tv_sec
, &o
->tv_sec
) ||
51 put_user(i
->tv_usec
, &o
->tv_usec
)) ? -EFAULT
: 0;
54 asmlinkage
long compat_sys_gettimeofday(struct compat_timeval __user
*tv
,
55 struct timezone __user
*tz
)
59 do_gettimeofday(&ktv
);
60 if (compat_put_timeval(tv
, &ktv
))
64 if (copy_to_user(tz
, &sys_tz
, sizeof(sys_tz
)))
71 asmlinkage
long compat_sys_settimeofday(struct compat_timeval __user
*tv
,
72 struct timezone __user
*tz
)
78 if (compat_get_timeval(&kts
, tv
))
82 if (copy_from_user(&ktz
, tz
, sizeof(ktz
)))
86 return do_sys_settimeofday(tv
? &kts
: NULL
, tz
? &ktz
: NULL
);
89 int get_compat_timespec(struct timespec
*ts
, const struct compat_timespec __user
*cts
)
91 return (!access_ok(VERIFY_READ
, cts
, sizeof(*cts
)) ||
92 __get_user(ts
->tv_sec
, &cts
->tv_sec
) ||
93 __get_user(ts
->tv_nsec
, &cts
->tv_nsec
)) ? -EFAULT
: 0;
96 int put_compat_timespec(const struct timespec
*ts
, struct compat_timespec __user
*cts
)
98 return (!access_ok(VERIFY_WRITE
, cts
, sizeof(*cts
)) ||
99 __put_user(ts
->tv_sec
, &cts
->tv_sec
) ||
100 __put_user(ts
->tv_nsec
, &cts
->tv_nsec
)) ? -EFAULT
: 0;
103 static long compat_nanosleep_restart(struct restart_block
*restart
)
105 struct compat_timespec __user
*rmtp
;
110 restart
->nanosleep
.rmtp
= (struct timespec __user
*) &rmt
;
113 ret
= hrtimer_nanosleep_restart(restart
);
117 rmtp
= restart
->nanosleep
.compat_rmtp
;
119 if (rmtp
&& put_compat_timespec(&rmt
, rmtp
))
126 asmlinkage
long compat_sys_nanosleep(struct compat_timespec __user
*rqtp
,
127 struct compat_timespec __user
*rmtp
)
129 struct timespec tu
, rmt
;
133 if (get_compat_timespec(&tu
, rqtp
))
136 if (!timespec_valid(&tu
))
141 ret
= hrtimer_nanosleep(&tu
,
142 rmtp
? (struct timespec __user
*)&rmt
: NULL
,
143 HRTIMER_MODE_REL
, CLOCK_MONOTONIC
);
147 struct restart_block
*restart
148 = ¤t_thread_info()->restart_block
;
150 restart
->fn
= compat_nanosleep_restart
;
151 restart
->nanosleep
.compat_rmtp
= rmtp
;
153 if (rmtp
&& put_compat_timespec(&rmt
, rmtp
))
160 static inline long get_compat_itimerval(struct itimerval
*o
,
161 struct compat_itimerval __user
*i
)
163 return (!access_ok(VERIFY_READ
, i
, sizeof(*i
)) ||
164 (__get_user(o
->it_interval
.tv_sec
, &i
->it_interval
.tv_sec
) |
165 __get_user(o
->it_interval
.tv_usec
, &i
->it_interval
.tv_usec
) |
166 __get_user(o
->it_value
.tv_sec
, &i
->it_value
.tv_sec
) |
167 __get_user(o
->it_value
.tv_usec
, &i
->it_value
.tv_usec
)));
170 static inline long put_compat_itimerval(struct compat_itimerval __user
*o
,
173 return (!access_ok(VERIFY_WRITE
, o
, sizeof(*o
)) ||
174 (__put_user(i
->it_interval
.tv_sec
, &o
->it_interval
.tv_sec
) |
175 __put_user(i
->it_interval
.tv_usec
, &o
->it_interval
.tv_usec
) |
176 __put_user(i
->it_value
.tv_sec
, &o
->it_value
.tv_sec
) |
177 __put_user(i
->it_value
.tv_usec
, &o
->it_value
.tv_usec
)));
180 asmlinkage
long compat_sys_getitimer(int which
,
181 struct compat_itimerval __user
*it
)
183 struct itimerval kit
;
186 error
= do_getitimer(which
, &kit
);
187 if (!error
&& put_compat_itimerval(it
, &kit
))
192 asmlinkage
long compat_sys_setitimer(int which
,
193 struct compat_itimerval __user
*in
,
194 struct compat_itimerval __user
*out
)
196 struct itimerval kin
, kout
;
200 if (get_compat_itimerval(&kin
, in
))
203 memset(&kin
, 0, sizeof(kin
));
205 error
= do_setitimer(which
, &kin
, out
? &kout
: NULL
);
208 if (put_compat_itimerval(out
, &kout
))
213 static compat_clock_t
clock_t_to_compat_clock_t(clock_t x
)
215 return compat_jiffies_to_clock_t(clock_t_to_jiffies(x
));
218 asmlinkage
long compat_sys_times(struct compat_tms __user
*tbuf
)
222 struct compat_tms tmp
;
225 /* Convert our struct tms to the compat version. */
226 tmp
.tms_utime
= clock_t_to_compat_clock_t(tms
.tms_utime
);
227 tmp
.tms_stime
= clock_t_to_compat_clock_t(tms
.tms_stime
);
228 tmp
.tms_cutime
= clock_t_to_compat_clock_t(tms
.tms_cutime
);
229 tmp
.tms_cstime
= clock_t_to_compat_clock_t(tms
.tms_cstime
);
230 if (copy_to_user(tbuf
, &tmp
, sizeof(tmp
)))
233 force_successful_syscall_return();
234 return compat_jiffies_to_clock_t(jiffies
);
238 * Assumption: old_sigset_t and compat_old_sigset_t are both
239 * types that can be passed to put_user()/get_user().
242 asmlinkage
long compat_sys_sigpending(compat_old_sigset_t __user
*set
)
246 mm_segment_t old_fs
= get_fs();
249 ret
= sys_sigpending((old_sigset_t __user
*) &s
);
252 ret
= put_user(s
, set
);
256 asmlinkage
long compat_sys_sigprocmask(int how
, compat_old_sigset_t __user
*set
,
257 compat_old_sigset_t __user
*oset
)
263 if (set
&& get_user(s
, set
))
267 ret
= sys_sigprocmask(how
,
268 set
? (old_sigset_t __user
*) &s
: NULL
,
269 oset
? (old_sigset_t __user
*) &s
: NULL
);
273 ret
= put_user(s
, oset
);
277 asmlinkage
long compat_sys_setrlimit(unsigned int resource
,
278 struct compat_rlimit __user
*rlim
)
282 mm_segment_t old_fs
= get_fs ();
284 if (resource
>= RLIM_NLIMITS
)
287 if (!access_ok(VERIFY_READ
, rlim
, sizeof(*rlim
)) ||
288 __get_user(r
.rlim_cur
, &rlim
->rlim_cur
) ||
289 __get_user(r
.rlim_max
, &rlim
->rlim_max
))
292 if (r
.rlim_cur
== COMPAT_RLIM_INFINITY
)
293 r
.rlim_cur
= RLIM_INFINITY
;
294 if (r
.rlim_max
== COMPAT_RLIM_INFINITY
)
295 r
.rlim_max
= RLIM_INFINITY
;
297 ret
= sys_setrlimit(resource
, (struct rlimit __user
*) &r
);
302 #ifdef COMPAT_RLIM_OLD_INFINITY
304 asmlinkage
long compat_sys_old_getrlimit(unsigned int resource
,
305 struct compat_rlimit __user
*rlim
)
309 mm_segment_t old_fs
= get_fs();
312 ret
= sys_old_getrlimit(resource
, &r
);
316 if (r
.rlim_cur
> COMPAT_RLIM_OLD_INFINITY
)
317 r
.rlim_cur
= COMPAT_RLIM_INFINITY
;
318 if (r
.rlim_max
> COMPAT_RLIM_OLD_INFINITY
)
319 r
.rlim_max
= COMPAT_RLIM_INFINITY
;
321 if (!access_ok(VERIFY_WRITE
, rlim
, sizeof(*rlim
)) ||
322 __put_user(r
.rlim_cur
, &rlim
->rlim_cur
) ||
323 __put_user(r
.rlim_max
, &rlim
->rlim_max
))
331 asmlinkage
long compat_sys_getrlimit (unsigned int resource
,
332 struct compat_rlimit __user
*rlim
)
336 mm_segment_t old_fs
= get_fs();
339 ret
= sys_getrlimit(resource
, (struct rlimit __user
*) &r
);
342 if (r
.rlim_cur
> COMPAT_RLIM_INFINITY
)
343 r
.rlim_cur
= COMPAT_RLIM_INFINITY
;
344 if (r
.rlim_max
> COMPAT_RLIM_INFINITY
)
345 r
.rlim_max
= COMPAT_RLIM_INFINITY
;
347 if (!access_ok(VERIFY_WRITE
, rlim
, sizeof(*rlim
)) ||
348 __put_user(r
.rlim_cur
, &rlim
->rlim_cur
) ||
349 __put_user(r
.rlim_max
, &rlim
->rlim_max
))
355 int put_compat_rusage(const struct rusage
*r
, struct compat_rusage __user
*ru
)
357 if (!access_ok(VERIFY_WRITE
, ru
, sizeof(*ru
)) ||
358 __put_user(r
->ru_utime
.tv_sec
, &ru
->ru_utime
.tv_sec
) ||
359 __put_user(r
->ru_utime
.tv_usec
, &ru
->ru_utime
.tv_usec
) ||
360 __put_user(r
->ru_stime
.tv_sec
, &ru
->ru_stime
.tv_sec
) ||
361 __put_user(r
->ru_stime
.tv_usec
, &ru
->ru_stime
.tv_usec
) ||
362 __put_user(r
->ru_maxrss
, &ru
->ru_maxrss
) ||
363 __put_user(r
->ru_ixrss
, &ru
->ru_ixrss
) ||
364 __put_user(r
->ru_idrss
, &ru
->ru_idrss
) ||
365 __put_user(r
->ru_isrss
, &ru
->ru_isrss
) ||
366 __put_user(r
->ru_minflt
, &ru
->ru_minflt
) ||
367 __put_user(r
->ru_majflt
, &ru
->ru_majflt
) ||
368 __put_user(r
->ru_nswap
, &ru
->ru_nswap
) ||
369 __put_user(r
->ru_inblock
, &ru
->ru_inblock
) ||
370 __put_user(r
->ru_oublock
, &ru
->ru_oublock
) ||
371 __put_user(r
->ru_msgsnd
, &ru
->ru_msgsnd
) ||
372 __put_user(r
->ru_msgrcv
, &ru
->ru_msgrcv
) ||
373 __put_user(r
->ru_nsignals
, &ru
->ru_nsignals
) ||
374 __put_user(r
->ru_nvcsw
, &ru
->ru_nvcsw
) ||
375 __put_user(r
->ru_nivcsw
, &ru
->ru_nivcsw
))
380 asmlinkage
long compat_sys_getrusage(int who
, struct compat_rusage __user
*ru
)
384 mm_segment_t old_fs
= get_fs();
387 ret
= sys_getrusage(who
, (struct rusage __user
*) &r
);
393 if (put_compat_rusage(&r
, ru
))
400 compat_sys_wait4(compat_pid_t pid
, compat_uint_t __user
*stat_addr
, int options
,
401 struct compat_rusage __user
*ru
)
404 return sys_wait4(pid
, stat_addr
, options
, NULL
);
409 mm_segment_t old_fs
= get_fs();
414 (unsigned int __user
*) &status
: NULL
),
415 options
, (struct rusage __user
*) &r
);
419 if (put_compat_rusage(&r
, ru
))
421 if (stat_addr
&& put_user(status
, stat_addr
))
428 asmlinkage
long compat_sys_waitid(int which
, compat_pid_t pid
,
429 struct compat_siginfo __user
*uinfo
, int options
,
430 struct compat_rusage __user
*uru
)
435 mm_segment_t old_fs
= get_fs();
437 memset(&info
, 0, sizeof(info
));
440 ret
= sys_waitid(which
, pid
, (siginfo_t __user
*)&info
, options
,
441 uru
? (struct rusage __user
*)&ru
: NULL
);
444 if ((ret
< 0) || (info
.si_signo
== 0))
448 ret
= put_compat_rusage(&ru
, uru
);
453 BUG_ON(info
.si_code
& __SI_MASK
);
454 info
.si_code
|= __SI_CHLD
;
455 return copy_siginfo_to_user32(uinfo
, &info
);
458 static int compat_get_user_cpu_mask(compat_ulong_t __user
*user_mask_ptr
,
459 unsigned len
, struct cpumask
*new_mask
)
463 if (len
< cpumask_size())
464 memset(new_mask
, 0, cpumask_size());
465 else if (len
> cpumask_size())
466 len
= cpumask_size();
468 k
= cpumask_bits(new_mask
);
469 return compat_get_bitmap(k
, user_mask_ptr
, len
* 8);
472 asmlinkage
long compat_sys_sched_setaffinity(compat_pid_t pid
,
474 compat_ulong_t __user
*user_mask_ptr
)
476 cpumask_var_t new_mask
;
479 if (!alloc_cpumask_var(&new_mask
, GFP_KERNEL
))
482 retval
= compat_get_user_cpu_mask(user_mask_ptr
, len
, new_mask
);
486 retval
= sched_setaffinity(pid
, new_mask
);
488 free_cpumask_var(new_mask
);
492 asmlinkage
long compat_sys_sched_getaffinity(compat_pid_t pid
, unsigned int len
,
493 compat_ulong_t __user
*user_mask_ptr
)
498 if ((len
* BITS_PER_BYTE
) < nr_cpu_ids
)
500 if (len
& (sizeof(compat_ulong_t
)-1))
503 if (!alloc_cpumask_var(&mask
, GFP_KERNEL
))
506 ret
= sched_getaffinity(pid
, mask
);
508 size_t retlen
= min_t(size_t, len
, cpumask_size());
510 if (compat_put_bitmap(user_mask_ptr
, cpumask_bits(mask
), retlen
* 8))
515 free_cpumask_var(mask
);
520 int get_compat_itimerspec(struct itimerspec
*dst
,
521 const struct compat_itimerspec __user
*src
)
523 if (get_compat_timespec(&dst
->it_interval
, &src
->it_interval
) ||
524 get_compat_timespec(&dst
->it_value
, &src
->it_value
))
529 int put_compat_itimerspec(struct compat_itimerspec __user
*dst
,
530 const struct itimerspec
*src
)
532 if (put_compat_timespec(&src
->it_interval
, &dst
->it_interval
) ||
533 put_compat_timespec(&src
->it_value
, &dst
->it_value
))
538 long compat_sys_timer_create(clockid_t which_clock
,
539 struct compat_sigevent __user
*timer_event_spec
,
540 timer_t __user
*created_timer_id
)
542 struct sigevent __user
*event
= NULL
;
544 if (timer_event_spec
) {
545 struct sigevent kevent
;
547 event
= compat_alloc_user_space(sizeof(*event
));
548 if (get_compat_sigevent(&kevent
, timer_event_spec
) ||
549 copy_to_user(event
, &kevent
, sizeof(*event
)))
553 return sys_timer_create(which_clock
, event
, created_timer_id
);
556 long compat_sys_timer_settime(timer_t timer_id
, int flags
,
557 struct compat_itimerspec __user
*new,
558 struct compat_itimerspec __user
*old
)
562 struct itimerspec newts
, oldts
;
566 if (get_compat_itimerspec(&newts
, new))
570 err
= sys_timer_settime(timer_id
, flags
,
571 (struct itimerspec __user
*) &newts
,
572 (struct itimerspec __user
*) &oldts
);
574 if (!err
&& old
&& put_compat_itimerspec(old
, &oldts
))
579 long compat_sys_timer_gettime(timer_t timer_id
,
580 struct compat_itimerspec __user
*setting
)
584 struct itimerspec ts
;
588 err
= sys_timer_gettime(timer_id
,
589 (struct itimerspec __user
*) &ts
);
591 if (!err
&& put_compat_itimerspec(setting
, &ts
))
596 long compat_sys_clock_settime(clockid_t which_clock
,
597 struct compat_timespec __user
*tp
)
603 if (get_compat_timespec(&ts
, tp
))
607 err
= sys_clock_settime(which_clock
,
608 (struct timespec __user
*) &ts
);
613 long compat_sys_clock_gettime(clockid_t which_clock
,
614 struct compat_timespec __user
*tp
)
622 err
= sys_clock_gettime(which_clock
,
623 (struct timespec __user
*) &ts
);
625 if (!err
&& put_compat_timespec(&ts
, tp
))
630 long compat_sys_clock_getres(clockid_t which_clock
,
631 struct compat_timespec __user
*tp
)
639 err
= sys_clock_getres(which_clock
,
640 (struct timespec __user
*) &ts
);
642 if (!err
&& tp
&& put_compat_timespec(&ts
, tp
))
647 static long compat_clock_nanosleep_restart(struct restart_block
*restart
)
652 struct compat_timespec
*rmtp
= restart
->nanosleep
.compat_rmtp
;
654 restart
->nanosleep
.rmtp
= (struct timespec __user
*) &tu
;
657 err
= clock_nanosleep_restart(restart
);
660 if ((err
== -ERESTART_RESTARTBLOCK
) && rmtp
&&
661 put_compat_timespec(&tu
, rmtp
))
664 if (err
== -ERESTART_RESTARTBLOCK
) {
665 restart
->fn
= compat_clock_nanosleep_restart
;
666 restart
->nanosleep
.compat_rmtp
= rmtp
;
671 long compat_sys_clock_nanosleep(clockid_t which_clock
, int flags
,
672 struct compat_timespec __user
*rqtp
,
673 struct compat_timespec __user
*rmtp
)
677 struct timespec in
, out
;
678 struct restart_block
*restart
;
680 if (get_compat_timespec(&in
, rqtp
))
685 err
= sys_clock_nanosleep(which_clock
, flags
,
686 (struct timespec __user
*) &in
,
687 (struct timespec __user
*) &out
);
690 if ((err
== -ERESTART_RESTARTBLOCK
) && rmtp
&&
691 put_compat_timespec(&out
, rmtp
))
694 if (err
== -ERESTART_RESTARTBLOCK
) {
695 restart
= ¤t_thread_info()->restart_block
;
696 restart
->fn
= compat_clock_nanosleep_restart
;
697 restart
->nanosleep
.compat_rmtp
= rmtp
;
703 * We currently only need the following fields from the sigevent
704 * structure: sigev_value, sigev_signo, sig_notify and (sometimes
705 * sigev_notify_thread_id). The others are handled in user mode.
706 * We also assume that copying sigev_value.sival_int is sufficient
707 * to keep all the bits of sigev_value.sival_ptr intact.
709 int get_compat_sigevent(struct sigevent
*event
,
710 const struct compat_sigevent __user
*u_event
)
712 memset(event
, 0, sizeof(*event
));
713 return (!access_ok(VERIFY_READ
, u_event
, sizeof(*u_event
)) ||
714 __get_user(event
->sigev_value
.sival_int
,
715 &u_event
->sigev_value
.sival_int
) ||
716 __get_user(event
->sigev_signo
, &u_event
->sigev_signo
) ||
717 __get_user(event
->sigev_notify
, &u_event
->sigev_notify
) ||
718 __get_user(event
->sigev_notify_thread_id
,
719 &u_event
->sigev_notify_thread_id
))
723 long compat_get_bitmap(unsigned long *mask
, const compat_ulong_t __user
*umask
,
724 unsigned long bitmap_size
)
729 unsigned long nr_compat_longs
;
731 /* align bitmap up to nearest compat_long_t boundary */
732 bitmap_size
= ALIGN(bitmap_size
, BITS_PER_COMPAT_LONG
);
734 if (!access_ok(VERIFY_READ
, umask
, bitmap_size
/ 8))
737 nr_compat_longs
= BITS_TO_COMPAT_LONGS(bitmap_size
);
739 for (i
= 0; i
< BITS_TO_LONGS(bitmap_size
); i
++) {
742 for (j
= 0; j
< sizeof(m
)/sizeof(um
); j
++) {
744 * We dont want to read past the end of the userspace
745 * bitmap. We must however ensure the end of the
746 * kernel bitmap is zeroed.
748 if (nr_compat_longs
-- > 0) {
749 if (__get_user(um
, umask
))
756 m
|= (long)um
<< (j
* BITS_PER_COMPAT_LONG
);
764 long compat_put_bitmap(compat_ulong_t __user
*umask
, unsigned long *mask
,
765 unsigned long bitmap_size
)
770 unsigned long nr_compat_longs
;
772 /* align bitmap up to nearest compat_long_t boundary */
773 bitmap_size
= ALIGN(bitmap_size
, BITS_PER_COMPAT_LONG
);
775 if (!access_ok(VERIFY_WRITE
, umask
, bitmap_size
/ 8))
778 nr_compat_longs
= BITS_TO_COMPAT_LONGS(bitmap_size
);
780 for (i
= 0; i
< BITS_TO_LONGS(bitmap_size
); i
++) {
783 for (j
= 0; j
< sizeof(m
)/sizeof(um
); j
++) {
787 * We dont want to write past the end of the userspace
790 if (nr_compat_longs
-- > 0) {
791 if (__put_user(um
, umask
))
805 sigset_from_compat (sigset_t
*set
, compat_sigset_t
*compat
)
807 switch (_NSIG_WORDS
) {
808 case 4: set
->sig
[3] = compat
->sig
[6] | (((long)compat
->sig
[7]) << 32 );
809 case 3: set
->sig
[2] = compat
->sig
[4] | (((long)compat
->sig
[5]) << 32 );
810 case 2: set
->sig
[1] = compat
->sig
[2] | (((long)compat
->sig
[3]) << 32 );
811 case 1: set
->sig
[0] = compat
->sig
[0] | (((long)compat
->sig
[1]) << 32 );
816 compat_sys_rt_sigtimedwait (compat_sigset_t __user
*uthese
,
817 struct compat_siginfo __user
*uinfo
,
818 struct compat_timespec __user
*uts
, compat_size_t sigsetsize
)
825 long ret
, timeout
= 0;
827 if (sigsetsize
!= sizeof(sigset_t
))
830 if (copy_from_user(&s32
, uthese
, sizeof(compat_sigset_t
)))
832 sigset_from_compat(&s
, &s32
);
833 sigdelsetmask(&s
,sigmask(SIGKILL
)|sigmask(SIGSTOP
));
837 if (get_compat_timespec (&t
, uts
))
839 if (t
.tv_nsec
>= 1000000000L || t
.tv_nsec
< 0
844 spin_lock_irq(¤t
->sighand
->siglock
);
845 sig
= dequeue_signal(current
, &s
, &info
);
847 timeout
= MAX_SCHEDULE_TIMEOUT
;
849 timeout
= timespec_to_jiffies(&t
)
850 +(t
.tv_sec
|| t
.tv_nsec
);
852 current
->real_blocked
= current
->blocked
;
853 sigandsets(¤t
->blocked
, ¤t
->blocked
, &s
);
856 spin_unlock_irq(¤t
->sighand
->siglock
);
858 timeout
= schedule_timeout_interruptible(timeout
);
860 spin_lock_irq(¤t
->sighand
->siglock
);
861 sig
= dequeue_signal(current
, &s
, &info
);
862 current
->blocked
= current
->real_blocked
;
863 siginitset(¤t
->real_blocked
, 0);
867 spin_unlock_irq(¤t
->sighand
->siglock
);
872 if (copy_siginfo_to_user32(uinfo
, &info
))
876 ret
= timeout
?-EINTR
:-EAGAIN
;
883 compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid
, compat_pid_t pid
, int sig
,
884 struct compat_siginfo __user
*uinfo
)
888 if (copy_siginfo_from_user32(&info
, uinfo
))
890 return do_rt_tgsigqueueinfo(tgid
, pid
, sig
, &info
);
893 #ifdef __ARCH_WANT_COMPAT_SYS_TIME
895 /* compat_time_t is a 32 bit "long" and needs to get converted. */
897 asmlinkage
long compat_sys_time(compat_time_t __user
* tloc
)
902 do_gettimeofday(&tv
);
906 if (put_user(i
,tloc
))
909 force_successful_syscall_return();
913 asmlinkage
long compat_sys_stime(compat_time_t __user
*tptr
)
918 if (get_user(tv
.tv_sec
, tptr
))
923 err
= security_settime(&tv
, NULL
);
927 do_settimeofday(&tv
);
931 #endif /* __ARCH_WANT_COMPAT_SYS_TIME */
933 #ifdef __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
934 asmlinkage
long compat_sys_rt_sigsuspend(compat_sigset_t __user
*unewset
, compat_size_t sigsetsize
)
937 compat_sigset_t newset32
;
939 /* XXX: Don't preclude handling different sized sigset_t's. */
940 if (sigsetsize
!= sizeof(sigset_t
))
943 if (copy_from_user(&newset32
, unewset
, sizeof(compat_sigset_t
)))
945 sigset_from_compat(&newset
, &newset32
);
946 sigdelsetmask(&newset
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
948 spin_lock_irq(¤t
->sighand
->siglock
);
949 current
->saved_sigmask
= current
->blocked
;
950 current
->blocked
= newset
;
952 spin_unlock_irq(¤t
->sighand
->siglock
);
954 current
->state
= TASK_INTERRUPTIBLE
;
956 set_restore_sigmask();
957 return -ERESTARTNOHAND
;
959 #endif /* __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND */
961 asmlinkage
long compat_sys_adjtimex(struct compat_timex __user
*utp
)
966 memset(&txc
, 0, sizeof(struct timex
));
968 if (!access_ok(VERIFY_READ
, utp
, sizeof(struct compat_timex
)) ||
969 __get_user(txc
.modes
, &utp
->modes
) ||
970 __get_user(txc
.offset
, &utp
->offset
) ||
971 __get_user(txc
.freq
, &utp
->freq
) ||
972 __get_user(txc
.maxerror
, &utp
->maxerror
) ||
973 __get_user(txc
.esterror
, &utp
->esterror
) ||
974 __get_user(txc
.status
, &utp
->status
) ||
975 __get_user(txc
.constant
, &utp
->constant
) ||
976 __get_user(txc
.precision
, &utp
->precision
) ||
977 __get_user(txc
.tolerance
, &utp
->tolerance
) ||
978 __get_user(txc
.time
.tv_sec
, &utp
->time
.tv_sec
) ||
979 __get_user(txc
.time
.tv_usec
, &utp
->time
.tv_usec
) ||
980 __get_user(txc
.tick
, &utp
->tick
) ||
981 __get_user(txc
.ppsfreq
, &utp
->ppsfreq
) ||
982 __get_user(txc
.jitter
, &utp
->jitter
) ||
983 __get_user(txc
.shift
, &utp
->shift
) ||
984 __get_user(txc
.stabil
, &utp
->stabil
) ||
985 __get_user(txc
.jitcnt
, &utp
->jitcnt
) ||
986 __get_user(txc
.calcnt
, &utp
->calcnt
) ||
987 __get_user(txc
.errcnt
, &utp
->errcnt
) ||
988 __get_user(txc
.stbcnt
, &utp
->stbcnt
))
991 ret
= do_adjtimex(&txc
);
993 if (!access_ok(VERIFY_WRITE
, utp
, sizeof(struct compat_timex
)) ||
994 __put_user(txc
.modes
, &utp
->modes
) ||
995 __put_user(txc
.offset
, &utp
->offset
) ||
996 __put_user(txc
.freq
, &utp
->freq
) ||
997 __put_user(txc
.maxerror
, &utp
->maxerror
) ||
998 __put_user(txc
.esterror
, &utp
->esterror
) ||
999 __put_user(txc
.status
, &utp
->status
) ||
1000 __put_user(txc
.constant
, &utp
->constant
) ||
1001 __put_user(txc
.precision
, &utp
->precision
) ||
1002 __put_user(txc
.tolerance
, &utp
->tolerance
) ||
1003 __put_user(txc
.time
.tv_sec
, &utp
->time
.tv_sec
) ||
1004 __put_user(txc
.time
.tv_usec
, &utp
->time
.tv_usec
) ||
1005 __put_user(txc
.tick
, &utp
->tick
) ||
1006 __put_user(txc
.ppsfreq
, &utp
->ppsfreq
) ||
1007 __put_user(txc
.jitter
, &utp
->jitter
) ||
1008 __put_user(txc
.shift
, &utp
->shift
) ||
1009 __put_user(txc
.stabil
, &utp
->stabil
) ||
1010 __put_user(txc
.jitcnt
, &utp
->jitcnt
) ||
1011 __put_user(txc
.calcnt
, &utp
->calcnt
) ||
1012 __put_user(txc
.errcnt
, &utp
->errcnt
) ||
1013 __put_user(txc
.stbcnt
, &utp
->stbcnt
) ||
1014 __put_user(txc
.tai
, &utp
->tai
))
1021 asmlinkage
long compat_sys_move_pages(pid_t pid
, unsigned long nr_pages
,
1022 compat_uptr_t __user
*pages32
,
1023 const int __user
*nodes
,
1027 const void __user
* __user
*pages
;
1030 pages
= compat_alloc_user_space(nr_pages
* sizeof(void *));
1031 for (i
= 0; i
< nr_pages
; i
++) {
1034 if (get_user(p
, pages32
+ i
) ||
1035 put_user(compat_ptr(p
), pages
+ i
))
1038 return sys_move_pages(pid
, nr_pages
, pages
, nodes
, status
, flags
);
1041 asmlinkage
long compat_sys_migrate_pages(compat_pid_t pid
,
1042 compat_ulong_t maxnode
,
1043 const compat_ulong_t __user
*old_nodes
,
1044 const compat_ulong_t __user
*new_nodes
)
1046 unsigned long __user
*old
= NULL
;
1047 unsigned long __user
*new = NULL
;
1048 nodemask_t tmp_mask
;
1049 unsigned long nr_bits
;
1052 nr_bits
= min_t(unsigned long, maxnode
- 1, MAX_NUMNODES
);
1053 size
= ALIGN(nr_bits
, BITS_PER_LONG
) / 8;
1055 if (compat_get_bitmap(nodes_addr(tmp_mask
), old_nodes
, nr_bits
))
1057 old
= compat_alloc_user_space(new_nodes
? size
* 2 : size
);
1059 new = old
+ size
/ sizeof(unsigned long);
1060 if (copy_to_user(old
, nodes_addr(tmp_mask
), size
))
1064 if (compat_get_bitmap(nodes_addr(tmp_mask
), new_nodes
, nr_bits
))
1067 new = compat_alloc_user_space(size
);
1068 if (copy_to_user(new, nodes_addr(tmp_mask
), size
))
1071 return sys_migrate_pages(pid
, nr_bits
+ 1, old
, new);
1075 struct compat_sysinfo
{
1089 char _f
[20-2*sizeof(u32
)-sizeof(int)];
1093 compat_sys_sysinfo(struct compat_sysinfo __user
*info
)
1099 /* Check to see if any memory value is too large for 32-bit and scale
1102 if ((s
.totalram
>> 32) || (s
.totalswap
>> 32)) {
1105 while (s
.mem_unit
< PAGE_SIZE
) {
1110 s
.totalram
>>= bitcount
;
1111 s
.freeram
>>= bitcount
;
1112 s
.sharedram
>>= bitcount
;
1113 s
.bufferram
>>= bitcount
;
1114 s
.totalswap
>>= bitcount
;
1115 s
.freeswap
>>= bitcount
;
1116 s
.totalhigh
>>= bitcount
;
1117 s
.freehigh
>>= bitcount
;
1120 if (!access_ok(VERIFY_WRITE
, info
, sizeof(struct compat_sysinfo
)) ||
1121 __put_user (s
.uptime
, &info
->uptime
) ||
1122 __put_user (s
.loads
[0], &info
->loads
[0]) ||
1123 __put_user (s
.loads
[1], &info
->loads
[1]) ||
1124 __put_user (s
.loads
[2], &info
->loads
[2]) ||
1125 __put_user (s
.totalram
, &info
->totalram
) ||
1126 __put_user (s
.freeram
, &info
->freeram
) ||
1127 __put_user (s
.sharedram
, &info
->sharedram
) ||
1128 __put_user (s
.bufferram
, &info
->bufferram
) ||
1129 __put_user (s
.totalswap
, &info
->totalswap
) ||
1130 __put_user (s
.freeswap
, &info
->freeswap
) ||
1131 __put_user (s
.procs
, &info
->procs
) ||
1132 __put_user (s
.totalhigh
, &info
->totalhigh
) ||
1133 __put_user (s
.freehigh
, &info
->freehigh
) ||
1134 __put_user (s
.mem_unit
, &info
->mem_unit
))