xref: /linux/arch/powerpc/kernel/sys_ppc32.c (revision 4f1933620f57145212cdbb1ac6ce099eeeb21c5a)
1 /*
2  * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
3  *
4  * Copyright (C) 2001 IBM
5  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * environment.
10  *
11  *      This program is free software; you can redistribute it and/or
12  *      modify it under the terms of the GNU General Public License
13  *      as published by the Free Software Foundation; either version
14  *      2 of the License, or (at your option) any later version.
15  */
16 
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/fs.h>
21 #include <linux/mm.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/resource.h>
25 #include <linux/times.h>
26 #include <linux/utsname.h>
27 #include <linux/timex.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/sem.h>
31 #include <linux/msg.h>
32 #include <linux/shm.h>
33 #include <linux/poll.h>
34 #include <linux/personality.h>
35 #include <linux/stat.h>
36 #include <linux/mman.h>
37 #include <linux/in.h>
38 #include <linux/syscalls.h>
39 #include <linux/unistd.h>
40 #include <linux/sysctl.h>
41 #include <linux/binfmts.h>
42 #include <linux/security.h>
43 #include <linux/compat.h>
44 #include <linux/ptrace.h>
45 #include <linux/elf.h>
46 
47 #include <asm/ptrace.h>
48 #include <asm/types.h>
49 #include <asm/ipc.h>
50 #include <asm/uaccess.h>
51 #include <asm/unistd.h>
52 #include <asm/semaphore.h>
53 #include <asm/time.h>
54 #include <asm/mmu_context.h>
55 #include <asm/ppc-pci.h>
56 
57 /* readdir & getdents */
58 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
59 #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
60 
61 struct old_linux_dirent32 {
62 	u32		d_ino;
63 	u32		d_offset;
64 	unsigned short	d_namlen;
65 	char		d_name[1];
66 };
67 
68 struct readdir_callback32 {
69 	struct old_linux_dirent32 __user * dirent;
70 	int count;
71 };
72 
73 static int fillonedir(void * __buf, const char * name, int namlen,
74 		                  off_t offset, ino_t ino, unsigned int d_type)
75 {
76 	struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
77 	struct old_linux_dirent32 __user * dirent;
78 
79 	if (buf->count)
80 		return -EINVAL;
81 	buf->count++;
82 	dirent = buf->dirent;
83 	put_user(ino, &dirent->d_ino);
84 	put_user(offset, &dirent->d_offset);
85 	put_user(namlen, &dirent->d_namlen);
86 	copy_to_user(dirent->d_name, name, namlen);
87 	put_user(0, dirent->d_name + namlen);
88 	return 0;
89 }
90 
91 asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
92 {
93 	int error = -EBADF;
94 	struct file * file;
95 	struct readdir_callback32 buf;
96 
97 	file = fget(fd);
98 	if (!file)
99 		goto out;
100 
101 	buf.count = 0;
102 	buf.dirent = dirent;
103 
104 	error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
105 	if (error < 0)
106 		goto out_putf;
107 	error = buf.count;
108 
109 out_putf:
110 	fput(file);
111 out:
112 	return error;
113 }
114 
115 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
116 		compat_ulong_t __user *outp, compat_ulong_t __user *exp,
117 		compat_uptr_t tvp_x)
118 {
119 	/* sign extend n */
120 	return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
121 }
122 
123 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
124 {
125 	long err;
126 
127 	if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
128 	    !new_valid_dev(stat->rdev))
129 		return -EOVERFLOW;
130 
131 	err  = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
132 	err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
133 	err |= __put_user(stat->ino, &statbuf->st_ino);
134 	err |= __put_user(stat->mode, &statbuf->st_mode);
135 	err |= __put_user(stat->nlink, &statbuf->st_nlink);
136 	err |= __put_user(stat->uid, &statbuf->st_uid);
137 	err |= __put_user(stat->gid, &statbuf->st_gid);
138 	err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
139 	err |= __put_user(stat->size, &statbuf->st_size);
140 	err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
141 	err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
142 	err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
143 	err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
144 	err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
145 	err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
146 	err |= __put_user(stat->blksize, &statbuf->st_blksize);
147 	err |= __put_user(stat->blocks, &statbuf->st_blocks);
148 	err |= __put_user(0, &statbuf->__unused4[0]);
149 	err |= __put_user(0, &statbuf->__unused4[1]);
150 
151 	return err;
152 }
153 
154 /* Note: it is necessary to treat option as an unsigned int,
155  * with the corresponding cast to a signed int to insure that the
156  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
157  * and the register representation of a signed int (msr in 64-bit mode) is performed.
158  */
159 asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
160 {
161 	return sys_sysfs((int)option, arg1, arg2);
162 }
163 
164 /* Handle adjtimex compatibility. */
165 struct timex32 {
166 	u32 modes;
167 	s32 offset, freq, maxerror, esterror;
168 	s32 status, constant, precision, tolerance;
169 	struct compat_timeval time;
170 	s32 tick;
171 	s32 ppsfreq, jitter, shift, stabil;
172 	s32 jitcnt, calcnt, errcnt, stbcnt;
173 	s32  :32; s32  :32; s32  :32; s32  :32;
174 	s32  :32; s32  :32; s32  :32; s32  :32;
175 	s32  :32; s32  :32; s32  :32; s32  :32;
176 };
177 
178 extern int do_adjtimex(struct timex *);
179 extern void ppc_adjtimex(void);
180 
181 asmlinkage long compat_sys_adjtimex(struct timex32 __user *utp)
182 {
183 	struct timex txc;
184 	int ret;
185 
186 	memset(&txc, 0, sizeof(struct timex));
187 
188 	if(get_user(txc.modes, &utp->modes) ||
189 	   __get_user(txc.offset, &utp->offset) ||
190 	   __get_user(txc.freq, &utp->freq) ||
191 	   __get_user(txc.maxerror, &utp->maxerror) ||
192 	   __get_user(txc.esterror, &utp->esterror) ||
193 	   __get_user(txc.status, &utp->status) ||
194 	   __get_user(txc.constant, &utp->constant) ||
195 	   __get_user(txc.precision, &utp->precision) ||
196 	   __get_user(txc.tolerance, &utp->tolerance) ||
197 	   __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
198 	   __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
199 	   __get_user(txc.tick, &utp->tick) ||
200 	   __get_user(txc.ppsfreq, &utp->ppsfreq) ||
201 	   __get_user(txc.jitter, &utp->jitter) ||
202 	   __get_user(txc.shift, &utp->shift) ||
203 	   __get_user(txc.stabil, &utp->stabil) ||
204 	   __get_user(txc.jitcnt, &utp->jitcnt) ||
205 	   __get_user(txc.calcnt, &utp->calcnt) ||
206 	   __get_user(txc.errcnt, &utp->errcnt) ||
207 	   __get_user(txc.stbcnt, &utp->stbcnt))
208 		return -EFAULT;
209 
210 	ret = do_adjtimex(&txc);
211 
212 	/* adjust the conversion of TB to time of day to track adjtimex */
213 	ppc_adjtimex();
214 
215 	if(put_user(txc.modes, &utp->modes) ||
216 	   __put_user(txc.offset, &utp->offset) ||
217 	   __put_user(txc.freq, &utp->freq) ||
218 	   __put_user(txc.maxerror, &utp->maxerror) ||
219 	   __put_user(txc.esterror, &utp->esterror) ||
220 	   __put_user(txc.status, &utp->status) ||
221 	   __put_user(txc.constant, &utp->constant) ||
222 	   __put_user(txc.precision, &utp->precision) ||
223 	   __put_user(txc.tolerance, &utp->tolerance) ||
224 	   __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
225 	   __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
226 	   __put_user(txc.tick, &utp->tick) ||
227 	   __put_user(txc.ppsfreq, &utp->ppsfreq) ||
228 	   __put_user(txc.jitter, &utp->jitter) ||
229 	   __put_user(txc.shift, &utp->shift) ||
230 	   __put_user(txc.stabil, &utp->stabil) ||
231 	   __put_user(txc.jitcnt, &utp->jitcnt) ||
232 	   __put_user(txc.calcnt, &utp->calcnt) ||
233 	   __put_user(txc.errcnt, &utp->errcnt) ||
234 	   __put_user(txc.stbcnt, &utp->stbcnt))
235 		ret = -EFAULT;
236 
237 	return ret;
238 }
239 
240 asmlinkage long compat_sys_pause(void)
241 {
242 	current->state = TASK_INTERRUPTIBLE;
243 	schedule();
244 
245 	return -ERESTARTNOHAND;
246 }
247 
248 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
249 {
250 	long usec;
251 
252 	if (!access_ok(VERIFY_READ, i, sizeof(*i)))
253 		return -EFAULT;
254 	if (__get_user(o->tv_sec, &i->tv_sec))
255 		return -EFAULT;
256 	if (__get_user(usec, &i->tv_usec))
257 		return -EFAULT;
258 	o->tv_nsec = usec * 1000;
259 	return 0;
260 }
261 
262 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
263 {
264 	return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
265 		(__put_user(i->tv_sec, &o->tv_sec) |
266 		 __put_user(i->tv_usec, &o->tv_usec)));
267 }
268 
269 struct sysinfo32 {
270         s32 uptime;
271         u32 loads[3];
272         u32 totalram;
273         u32 freeram;
274         u32 sharedram;
275         u32 bufferram;
276         u32 totalswap;
277         u32 freeswap;
278         unsigned short procs;
279 	unsigned short pad;
280 	u32 totalhigh;
281 	u32 freehigh;
282 	u32 mem_unit;
283 	char _f[20-2*sizeof(int)-sizeof(int)];
284 };
285 
286 asmlinkage long compat_sys_sysinfo(struct sysinfo32 __user *info)
287 {
288 	struct sysinfo s;
289 	int ret, err;
290 	int bitcount=0;
291 	mm_segment_t old_fs = get_fs ();
292 
293 	/* The __user cast is valid due to set_fs() */
294 	set_fs (KERNEL_DS);
295 	ret = sys_sysinfo((struct sysinfo __user *)&s);
296 	set_fs (old_fs);
297 
298 	/* Check to see if any memory value is too large for 32-bit and
299          * scale down if needed.
300          */
301 	if ((s.totalram >> 32) || (s.totalswap >> 32)) {
302 	    while (s.mem_unit < PAGE_SIZE) {
303 		s.mem_unit <<= 1;
304 		bitcount++;
305 	    }
306 	    s.totalram >>=bitcount;
307 	    s.freeram >>= bitcount;
308 	    s.sharedram >>= bitcount;
309 	    s.bufferram >>= bitcount;
310 	    s.totalswap >>= bitcount;
311 	    s.freeswap >>= bitcount;
312 	    s.totalhigh >>= bitcount;
313 	    s.freehigh >>= bitcount;
314 	}
315 
316 	err = put_user (s.uptime, &info->uptime);
317 	err |= __put_user (s.loads[0], &info->loads[0]);
318 	err |= __put_user (s.loads[1], &info->loads[1]);
319 	err |= __put_user (s.loads[2], &info->loads[2]);
320 	err |= __put_user (s.totalram, &info->totalram);
321 	err |= __put_user (s.freeram, &info->freeram);
322 	err |= __put_user (s.sharedram, &info->sharedram);
323 	err |= __put_user (s.bufferram, &info->bufferram);
324 	err |= __put_user (s.totalswap, &info->totalswap);
325 	err |= __put_user (s.freeswap, &info->freeswap);
326 	err |= __put_user (s.procs, &info->procs);
327 	err |= __put_user (s.totalhigh, &info->totalhigh);
328 	err |= __put_user (s.freehigh, &info->freehigh);
329 	err |= __put_user (s.mem_unit, &info->mem_unit);
330 	if (err)
331 		return -EFAULT;
332 
333 	return ret;
334 }
335 
336 
337 
338 
339 /* Translations due to time_t size differences.  Which affects all
340    sorts of things, like timeval and itimerval.  */
341 extern struct timezone sys_tz;
342 
343 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
344 {
345 	if (tv) {
346 		struct timeval ktv;
347 		do_gettimeofday(&ktv);
348 		if (put_tv32(tv, &ktv))
349 			return -EFAULT;
350 	}
351 	if (tz) {
352 		if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
353 			return -EFAULT;
354 	}
355 
356 	return 0;
357 }
358 
359 
360 
361 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
362 {
363 	struct timespec kts;
364 	struct timezone ktz;
365 
366  	if (tv) {
367 		if (get_ts32(&kts, tv))
368 			return -EFAULT;
369 	}
370 	if (tz) {
371 		if (copy_from_user(&ktz, tz, sizeof(ktz)))
372 			return -EFAULT;
373 	}
374 
375 	return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
376 }
377 
378 #ifdef CONFIG_SYSVIPC
379 long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
380 	       u32 fifth)
381 {
382 	int version;
383 
384 	version = call >> 16; /* hack for backward compatibility */
385 	call &= 0xffff;
386 
387 	switch (call) {
388 
389 	case SEMTIMEDOP:
390 		if (fifth)
391 			/* sign extend semid */
392 			return compat_sys_semtimedop((int)first,
393 						     compat_ptr(ptr), second,
394 						     compat_ptr(fifth));
395 		/* else fall through for normal semop() */
396 	case SEMOP:
397 		/* struct sembuf is the same on 32 and 64bit :)) */
398 		/* sign extend semid */
399 		return sys_semtimedop((int)first, compat_ptr(ptr), second,
400 				      NULL);
401 	case SEMGET:
402 		/* sign extend key, nsems */
403 		return sys_semget((int)first, (int)second, third);
404 	case SEMCTL:
405 		/* sign extend semid, semnum */
406 		return compat_sys_semctl((int)first, (int)second, third,
407 					 compat_ptr(ptr));
408 
409 	case MSGSND:
410 		/* sign extend msqid */
411 		return compat_sys_msgsnd((int)first, (int)second, third,
412 					 compat_ptr(ptr));
413 	case MSGRCV:
414 		/* sign extend msqid, msgtyp */
415 		return compat_sys_msgrcv((int)first, second, (int)fifth,
416 					 third, version, compat_ptr(ptr));
417 	case MSGGET:
418 		/* sign extend key */
419 		return sys_msgget((int)first, second);
420 	case MSGCTL:
421 		/* sign extend msqid */
422 		return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
423 
424 	case SHMAT:
425 		/* sign extend shmid */
426 		return compat_sys_shmat((int)first, second, third, version,
427 					compat_ptr(ptr));
428 	case SHMDT:
429 		return sys_shmdt(compat_ptr(ptr));
430 	case SHMGET:
431 		/* sign extend key_t */
432 		return sys_shmget((int)first, second, third);
433 	case SHMCTL:
434 		/* sign extend shmid */
435 		return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
436 
437 	default:
438 		return -ENOSYS;
439 	}
440 
441 	return -ENOSYS;
442 }
443 #endif
444 
445 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
446  * with the corresponding cast to a signed int to insure that the
447  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
448  * and the register representation of a signed int (msr in 64-bit mode) is performed.
449  */
450 asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
451 {
452 	mm_segment_t old_fs = get_fs();
453 	int ret;
454 	off_t of;
455 	off_t __user *up;
456 
457 	if (offset && get_user(of, offset))
458 		return -EFAULT;
459 
460 	/* The __user pointer cast is valid because of the set_fs() */
461 	set_fs(KERNEL_DS);
462 	up = offset ? (off_t __user *) &of : NULL;
463 	ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
464 	set_fs(old_fs);
465 
466 	if (offset && put_user(of, offset))
467 		return -EFAULT;
468 
469 	return ret;
470 }
471 
472 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
473 {
474 	mm_segment_t old_fs = get_fs();
475 	int ret;
476 	loff_t lof;
477 	loff_t __user *up;
478 
479 	if (offset && get_user(lof, offset))
480 		return -EFAULT;
481 
482 	/* The __user pointer cast is valid because of the set_fs() */
483 	set_fs(KERNEL_DS);
484 	up = offset ? (loff_t __user *) &lof : NULL;
485 	ret = sys_sendfile64(out_fd, in_fd, up, count);
486 	set_fs(old_fs);
487 
488 	if (offset && put_user(lof, offset))
489 		return -EFAULT;
490 
491 	return ret;
492 }
493 
494 long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
495 		  unsigned long a3, unsigned long a4, unsigned long a5,
496 		  struct pt_regs *regs)
497 {
498 	int error;
499 	char * filename;
500 
501 	filename = getname((char __user *) a0);
502 	error = PTR_ERR(filename);
503 	if (IS_ERR(filename))
504 		goto out;
505 	flush_fp_to_thread(current);
506 	flush_altivec_to_thread(current);
507 
508 	error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
509 
510 	if (error == 0) {
511 		task_lock(current);
512 		current->ptrace &= ~PT_DTRACE;
513 		task_unlock(current);
514 	}
515 	putname(filename);
516 
517 out:
518 	return error;
519 }
520 
521 /* Note: it is necessary to treat option as an unsigned int,
522  * with the corresponding cast to a signed int to insure that the
523  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
524  * and the register representation of a signed int (msr in 64-bit mode) is performed.
525  */
526 asmlinkage long compat_sys_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
527 {
528 	return sys_prctl((int)option,
529 			 (unsigned long) arg2,
530 			 (unsigned long) arg3,
531 			 (unsigned long) arg4,
532 			 (unsigned long) arg5);
533 }
534 
535 /* Note: it is necessary to treat pid as an unsigned int,
536  * with the corresponding cast to a signed int to insure that the
537  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
538  * and the register representation of a signed int (msr in 64-bit mode) is performed.
539  */
540 asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
541 {
542 	struct timespec t;
543 	int ret;
544 	mm_segment_t old_fs = get_fs ();
545 
546 	/* The __user pointer cast is valid because of the set_fs() */
547 	set_fs (KERNEL_DS);
548 	ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
549 	set_fs (old_fs);
550 	if (put_compat_timespec(&t, interval))
551 		return -EFAULT;
552 	return ret;
553 }
554 
555 /* Note: it is necessary to treat mode as an unsigned int,
556  * with the corresponding cast to a signed int to insure that the
557  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
558  * and the register representation of a signed int (msr in 64-bit mode) is performed.
559  */
560 asmlinkage long compat_sys_access(const char __user * filename, u32 mode)
561 {
562 	return sys_access(filename, (int)mode);
563 }
564 
565 
566 /* Note: it is necessary to treat mode as an unsigned int,
567  * with the corresponding cast to a signed int to insure that the
568  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
569  * and the register representation of a signed int (msr in 64-bit mode) is performed.
570  */
571 asmlinkage long compat_sys_creat(const char __user * pathname, u32 mode)
572 {
573 	return sys_creat(pathname, (int)mode);
574 }
575 
576 
577 /* Note: it is necessary to treat pid and options as unsigned ints,
578  * with the corresponding cast to a signed int to insure that the
579  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
580  * and the register representation of a signed int (msr in 64-bit mode) is performed.
581  */
582 asmlinkage long compat_sys_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
583 {
584 	return sys_waitpid((int)pid, stat_addr, (int)options);
585 }
586 
587 
588 /* Note: it is necessary to treat gidsetsize as an unsigned int,
589  * with the corresponding cast to a signed int to insure that the
590  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
591  * and the register representation of a signed int (msr in 64-bit mode) is performed.
592  */
593 asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist)
594 {
595 	return sys_getgroups((int)gidsetsize, grouplist);
596 }
597 
598 
599 /* Note: it is necessary to treat pid as an unsigned int,
600  * with the corresponding cast to a signed int to insure that the
601  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
602  * and the register representation of a signed int (msr in 64-bit mode) is performed.
603  */
604 asmlinkage long compat_sys_getpgid(u32 pid)
605 {
606 	return sys_getpgid((int)pid);
607 }
608 
609 
610 
611 /* Note: it is necessary to treat pid as an unsigned int,
612  * with the corresponding cast to a signed int to insure that the
613  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
614  * and the register representation of a signed int (msr in 64-bit mode) is performed.
615  */
616 asmlinkage long compat_sys_getsid(u32 pid)
617 {
618 	return sys_getsid((int)pid);
619 }
620 
621 
622 /* Note: it is necessary to treat pid and sig as unsigned ints,
623  * with the corresponding cast to a signed int to insure that the
624  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
625  * and the register representation of a signed int (msr in 64-bit mode) is performed.
626  */
627 asmlinkage long compat_sys_kill(u32 pid, u32 sig)
628 {
629 	return sys_kill((int)pid, (int)sig);
630 }
631 
632 
633 /* Note: it is necessary to treat mode as an unsigned int,
634  * with the corresponding cast to a signed int to insure that the
635  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
636  * and the register representation of a signed int (msr in 64-bit mode) is performed.
637  */
638 asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode)
639 {
640 	return sys_mkdir(pathname, (int)mode);
641 }
642 
643 long compat_sys_nice(u32 increment)
644 {
645 	/* sign extend increment */
646 	return sys_nice((int)increment);
647 }
648 
649 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
650 {
651 	/* sign extend n */
652 	return sys_lseek(fd, (int)offset, origin);
653 }
654 
655 /* Note: it is necessary to treat bufsiz as an unsigned int,
656  * with the corresponding cast to a signed int to insure that the
657  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
658  * and the register representation of a signed int (msr in 64-bit mode) is performed.
659  */
660 asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz)
661 {
662 	return sys_readlink(path, buf, (int)bufsiz);
663 }
664 
665 /* Note: it is necessary to treat option as an unsigned int,
666  * with the corresponding cast to a signed int to insure that the
667  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
668  * and the register representation of a signed int (msr in 64-bit mode) is performed.
669  */
670 asmlinkage long compat_sys_sched_get_priority_max(u32 policy)
671 {
672 	return sys_sched_get_priority_max((int)policy);
673 }
674 
675 
676 /* Note: it is necessary to treat policy as an unsigned int,
677  * with the corresponding cast to a signed int to insure that the
678  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
679  * and the register representation of a signed int (msr in 64-bit mode) is performed.
680  */
681 asmlinkage long compat_sys_sched_get_priority_min(u32 policy)
682 {
683 	return sys_sched_get_priority_min((int)policy);
684 }
685 
686 
687 /* Note: it is necessary to treat pid as an unsigned int,
688  * with the corresponding cast to a signed int to insure that the
689  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
690  * and the register representation of a signed int (msr in 64-bit mode) is performed.
691  */
692 asmlinkage long compat_sys_sched_getparam(u32 pid, struct sched_param __user *param)
693 {
694 	return sys_sched_getparam((int)pid, param);
695 }
696 
697 
698 /* Note: it is necessary to treat pid as an unsigned int,
699  * with the corresponding cast to a signed int to insure that the
700  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
701  * and the register representation of a signed int (msr in 64-bit mode) is performed.
702  */
703 asmlinkage long compat_sys_sched_getscheduler(u32 pid)
704 {
705 	return sys_sched_getscheduler((int)pid);
706 }
707 
708 
709 /* Note: it is necessary to treat pid as an unsigned int,
710  * with the corresponding cast to a signed int to insure that the
711  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
712  * and the register representation of a signed int (msr in 64-bit mode) is performed.
713  */
714 asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param)
715 {
716 	return sys_sched_setparam((int)pid, param);
717 }
718 
719 
720 /* Note: it is necessary to treat pid and policy as unsigned ints,
721  * with the corresponding cast to a signed int to insure that the
722  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
723  * and the register representation of a signed int (msr in 64-bit mode) is performed.
724  */
725 asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
726 {
727 	return sys_sched_setscheduler((int)pid, (int)policy, param);
728 }
729 
730 
731 /* Note: it is necessary to treat len as an unsigned int,
732  * with the corresponding cast to a signed int to insure that the
733  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
734  * and the register representation of a signed int (msr in 64-bit mode) is performed.
735  */
736 asmlinkage long compat_sys_setdomainname(char __user *name, u32 len)
737 {
738 	return sys_setdomainname(name, (int)len);
739 }
740 
741 
742 /* Note: it is necessary to treat gidsetsize as an unsigned int,
743  * with the corresponding cast to a signed int to insure that the
744  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
745  * and the register representation of a signed int (msr in 64-bit mode) is performed.
746  */
747 asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist)
748 {
749 	return sys_setgroups((int)gidsetsize, grouplist);
750 }
751 
752 
753 asmlinkage long compat_sys_sethostname(char __user *name, u32 len)
754 {
755 	/* sign extend len */
756 	return sys_sethostname(name, (int)len);
757 }
758 
759 
760 /* Note: it is necessary to treat pid and pgid as unsigned ints,
761  * with the corresponding cast to a signed int to insure that the
762  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
763  * and the register representation of a signed int (msr in 64-bit mode) is performed.
764  */
765 asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid)
766 {
767 	return sys_setpgid((int)pid, (int)pgid);
768 }
769 
770 long compat_sys_getpriority(u32 which, u32 who)
771 {
772 	/* sign extend which and who */
773 	return sys_getpriority((int)which, (int)who);
774 }
775 
776 long compat_sys_setpriority(u32 which, u32 who, u32 niceval)
777 {
778 	/* sign extend which, who and niceval */
779 	return sys_setpriority((int)which, (int)who, (int)niceval);
780 }
781 
782 long compat_sys_ioprio_get(u32 which, u32 who)
783 {
784 	/* sign extend which and who */
785 	return sys_ioprio_get((int)which, (int)who);
786 }
787 
788 long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio)
789 {
790 	/* sign extend which, who and ioprio */
791 	return sys_ioprio_set((int)which, (int)who, (int)ioprio);
792 }
793 
794 /* Note: it is necessary to treat newmask as an unsigned int,
795  * with the corresponding cast to a signed int to insure that the
796  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
797  * and the register representation of a signed int (msr in 64-bit mode) is performed.
798  */
799 asmlinkage long compat_sys_ssetmask(u32 newmask)
800 {
801 	return sys_ssetmask((int) newmask);
802 }
803 
804 asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len)
805 {
806 	/* sign extend len */
807 	return sys_syslog(type, buf, (int)len);
808 }
809 
810 
811 /* Note: it is necessary to treat mask as an unsigned int,
812  * with the corresponding cast to a signed int to insure that the
813  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
814  * and the register representation of a signed int (msr in 64-bit mode) is performed.
815  */
816 asmlinkage long compat_sys_umask(u32 mask)
817 {
818 	return sys_umask((int)mask);
819 }
820 
821 #ifdef CONFIG_SYSCTL
822 struct __sysctl_args32 {
823 	u32 name;
824 	int nlen;
825 	u32 oldval;
826 	u32 oldlenp;
827 	u32 newval;
828 	u32 newlen;
829 	u32 __unused[4];
830 };
831 
832 asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
833 {
834 	struct __sysctl_args32 tmp;
835 	int error;
836 	size_t oldlen;
837 	size_t __user *oldlenp = NULL;
838 	unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
839 
840 	if (copy_from_user(&tmp, args, sizeof(tmp)))
841 		return -EFAULT;
842 
843 	if (tmp.oldval && tmp.oldlenp) {
844 		/* Duh, this is ugly and might not work if sysctl_args
845 		   is in read-only memory, but do_sysctl does indirectly
846 		   a lot of uaccess in both directions and we'd have to
847 		   basically copy the whole sysctl.c here, and
848 		   glibc's __sysctl uses rw memory for the structure
849 		   anyway.  */
850 		oldlenp = (size_t __user *)addr;
851 		if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
852 		    put_user(oldlen, oldlenp))
853 			return -EFAULT;
854 	}
855 
856 	lock_kernel();
857 	error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
858 			  compat_ptr(tmp.oldval), oldlenp,
859 			  compat_ptr(tmp.newval), tmp.newlen);
860 	unlock_kernel();
861 	if (oldlenp) {
862 		if (!error) {
863 			if (get_user(oldlen, oldlenp) ||
864 			    put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
865 				error = -EFAULT;
866 		}
867 		copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
868 	}
869 	return error;
870 }
871 #endif
872 
873 unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
874 			  unsigned long prot, unsigned long flags,
875 			  unsigned long fd, unsigned long pgoff)
876 {
877 	/* This should remain 12 even if PAGE_SIZE changes */
878 	return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
879 }
880 
881 long compat_sys_tgkill(u32 tgid, u32 pid, int sig)
882 {
883 	/* sign extend tgid, pid */
884 	return sys_tgkill((int)tgid, (int)pid, sig);
885 }
886 
887 /*
888  * long long munging:
889  * The 32 bit ABI passes long longs in an odd even register pair.
890  */
891 
892 compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
893 			     u32 reg6, u32 poshi, u32 poslo)
894 {
895 	return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
896 }
897 
898 compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
899 			      u32 reg6, u32 poshi, u32 poslo)
900 {
901 	return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
902 }
903 
904 compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
905 {
906 	return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
907 }
908 
909 asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
910 				unsigned long high, unsigned long low)
911 {
912 	return sys_truncate(path, (high << 32) | low);
913 }
914 
915 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
916 				 unsigned long low)
917 {
918 	return sys_ftruncate(fd, (high << 32) | low);
919 }
920 
921 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
922 			  size_t len)
923 {
924 	return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
925 				  buf, len);
926 }
927 
928 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
929 		     size_t len, int advice)
930 {
931 	return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
932 			     advice);
933 }
934 
935 asmlinkage long compat_sys_add_key(const char __user *_type,
936 			      const char __user *_description,
937 			      const void __user *_payload,
938 			      u32 plen,
939 			      u32 ringid)
940 {
941 	return sys_add_key(_type, _description, _payload, plen, ringid);
942 }
943 
944 asmlinkage long compat_sys_request_key(const char __user *_type,
945 				  const char __user *_description,
946 				  const char __user *_callout_info,
947 				  u32 destringid)
948 {
949 	return sys_request_key(_type, _description, _callout_info, destringid);
950 }
951 
952