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