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 | ||
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> | |
1da177e4 LT |
33 | #include <linux/poll.h> |
34 | #include <linux/personality.h> | |
35 | #include <linux/stat.h> | |
1da177e4 | 36 | #include <linux/mman.h> |
1da177e4 | 37 | #include <linux/in.h> |
1da177e4 LT |
38 | #include <linux/syscalls.h> |
39 | #include <linux/unistd.h> | |
40 | #include <linux/sysctl.h> | |
41 | #include <linux/binfmts.h> | |
1da177e4 LT |
42 | #include <linux/security.h> |
43 | #include <linux/compat.h> | |
44 | #include <linux/ptrace.h> | |
1da177e4 LT |
45 | #include <linux/elf.h> |
46 | ||
1da177e4 LT |
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> | |
1da177e4 LT |
53 | #include <asm/time.h> |
54 | #include <asm/mmu_context.h> | |
55 | #include <asm/systemcfg.h> | |
56 | ||
57 | #include "pci.h" | |
58 | ||
59 | /* readdir & getdents */ | |
60 | #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de))) | |
61 | #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1)) | |
62 | ||
63 | struct old_linux_dirent32 { | |
64 | u32 d_ino; | |
65 | u32 d_offset; | |
66 | unsigned short d_namlen; | |
67 | char d_name[1]; | |
68 | }; | |
69 | ||
70 | struct readdir_callback32 { | |
71 | struct old_linux_dirent32 __user * dirent; | |
72 | int count; | |
73 | }; | |
74 | ||
75 | static int fillonedir(void * __buf, const char * name, int namlen, | |
76 | off_t offset, ino_t ino, unsigned int d_type) | |
77 | { | |
78 | struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf; | |
79 | struct old_linux_dirent32 __user * dirent; | |
80 | ||
81 | if (buf->count) | |
82 | return -EINVAL; | |
83 | buf->count++; | |
84 | dirent = buf->dirent; | |
85 | put_user(ino, &dirent->d_ino); | |
86 | put_user(offset, &dirent->d_offset); | |
87 | put_user(namlen, &dirent->d_namlen); | |
88 | copy_to_user(dirent->d_name, name, namlen); | |
89 | put_user(0, dirent->d_name + namlen); | |
90 | return 0; | |
91 | } | |
92 | ||
93 | asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count) | |
94 | { | |
95 | int error = -EBADF; | |
96 | struct file * file; | |
97 | struct readdir_callback32 buf; | |
98 | ||
99 | file = fget(fd); | |
100 | if (!file) | |
101 | goto out; | |
102 | ||
103 | buf.count = 0; | |
104 | buf.dirent = dirent; | |
105 | ||
106 | error = vfs_readdir(file, (filldir_t)fillonedir, &buf); | |
107 | if (error < 0) | |
108 | goto out_putf; | |
109 | error = buf.count; | |
110 | ||
111 | out_putf: | |
112 | fput(file); | |
113 | out: | |
114 | return error; | |
115 | } | |
116 | ||
117 | struct linux_dirent32 { | |
118 | u32 d_ino; | |
119 | u32 d_off; | |
120 | unsigned short d_reclen; | |
121 | char d_name[1]; | |
122 | }; | |
123 | ||
124 | struct getdents_callback32 { | |
125 | struct linux_dirent32 __user * current_dir; | |
126 | struct linux_dirent32 __user * previous; | |
127 | int count; | |
128 | int error; | |
129 | }; | |
130 | ||
131 | static int filldir(void * __buf, const char * name, int namlen, off_t offset, | |
132 | ino_t ino, unsigned int d_type) | |
133 | { | |
134 | struct linux_dirent32 __user * dirent; | |
135 | struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf; | |
136 | int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2); | |
137 | ||
138 | buf->error = -EINVAL; /* only used if we fail.. */ | |
139 | if (reclen > buf->count) | |
140 | return -EINVAL; | |
141 | dirent = buf->previous; | |
142 | if (dirent) { | |
143 | if (__put_user(offset, &dirent->d_off)) | |
144 | goto efault; | |
145 | } | |
146 | dirent = buf->current_dir; | |
147 | if (__put_user(ino, &dirent->d_ino)) | |
148 | goto efault; | |
149 | if (__put_user(reclen, &dirent->d_reclen)) | |
150 | goto efault; | |
151 | if (copy_to_user(dirent->d_name, name, namlen)) | |
152 | goto efault; | |
153 | if (__put_user(0, dirent->d_name + namlen)) | |
154 | goto efault; | |
155 | if (__put_user(d_type, (char __user *) dirent + reclen - 1)) | |
156 | goto efault; | |
157 | buf->previous = dirent; | |
158 | dirent = (void __user *)dirent + reclen; | |
159 | buf->current_dir = dirent; | |
160 | buf->count -= reclen; | |
161 | return 0; | |
162 | efault: | |
163 | buf->error = -EFAULT; | |
164 | return -EFAULT; | |
165 | } | |
166 | ||
167 | asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent, | |
168 | unsigned int count) | |
169 | { | |
170 | struct file * file; | |
171 | struct linux_dirent32 __user * lastdirent; | |
172 | struct getdents_callback32 buf; | |
173 | int error; | |
174 | ||
175 | error = -EFAULT; | |
176 | if (!access_ok(VERIFY_WRITE, dirent, count)) | |
177 | goto out; | |
178 | ||
179 | error = -EBADF; | |
180 | file = fget(fd); | |
181 | if (!file) | |
182 | goto out; | |
183 | ||
184 | buf.current_dir = dirent; | |
185 | buf.previous = NULL; | |
186 | buf.count = count; | |
187 | buf.error = 0; | |
188 | ||
189 | error = vfs_readdir(file, (filldir_t)filldir, &buf); | |
190 | if (error < 0) | |
191 | goto out_putf; | |
192 | error = buf.error; | |
193 | lastdirent = buf.previous; | |
194 | if (lastdirent) { | |
195 | if (put_user(file->f_pos, &lastdirent->d_off)) | |
196 | error = -EFAULT; | |
197 | else | |
198 | error = count - buf.count; | |
199 | } | |
200 | ||
201 | out_putf: | |
202 | fput(file); | |
203 | out: | |
204 | return error; | |
205 | } | |
206 | ||
207 | asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp, | |
208 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, | |
209 | compat_uptr_t tvp_x) | |
210 | { | |
211 | /* sign extend n */ | |
212 | return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x)); | |
213 | } | |
214 | ||
215 | int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf) | |
216 | { | |
217 | long err; | |
218 | ||
219 | if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) || | |
220 | !new_valid_dev(stat->rdev)) | |
221 | return -EOVERFLOW; | |
222 | ||
223 | err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT; | |
224 | err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev); | |
225 | err |= __put_user(stat->ino, &statbuf->st_ino); | |
226 | err |= __put_user(stat->mode, &statbuf->st_mode); | |
227 | err |= __put_user(stat->nlink, &statbuf->st_nlink); | |
228 | err |= __put_user(stat->uid, &statbuf->st_uid); | |
229 | err |= __put_user(stat->gid, &statbuf->st_gid); | |
230 | err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev); | |
231 | err |= __put_user(stat->size, &statbuf->st_size); | |
232 | err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime); | |
233 | err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec); | |
234 | err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime); | |
235 | err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec); | |
236 | err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime); | |
237 | err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec); | |
238 | err |= __put_user(stat->blksize, &statbuf->st_blksize); | |
239 | err |= __put_user(stat->blocks, &statbuf->st_blocks); | |
240 | err |= __put_user(0, &statbuf->__unused4[0]); | |
241 | err |= __put_user(0, &statbuf->__unused4[1]); | |
242 | ||
243 | return err; | |
244 | } | |
245 | ||
246 | /* Note: it is necessary to treat option as an unsigned int, | |
247 | * with the corresponding cast to a signed int to insure that the | |
248 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
249 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
250 | */ | |
251 | asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2) | |
252 | { | |
253 | return sys_sysfs((int)option, arg1, arg2); | |
254 | } | |
255 | ||
256 | /* Handle adjtimex compatibility. */ | |
257 | struct timex32 { | |
258 | u32 modes; | |
259 | s32 offset, freq, maxerror, esterror; | |
260 | s32 status, constant, precision, tolerance; | |
261 | struct compat_timeval time; | |
262 | s32 tick; | |
263 | s32 ppsfreq, jitter, shift, stabil; | |
264 | s32 jitcnt, calcnt, errcnt, stbcnt; | |
265 | s32 :32; s32 :32; s32 :32; s32 :32; | |
266 | s32 :32; s32 :32; s32 :32; s32 :32; | |
267 | s32 :32; s32 :32; s32 :32; s32 :32; | |
268 | }; | |
269 | ||
270 | extern int do_adjtimex(struct timex *); | |
271 | extern void ppc_adjtimex(void); | |
272 | ||
273 | asmlinkage long sys32_adjtimex(struct timex32 __user *utp) | |
274 | { | |
275 | struct timex txc; | |
276 | int ret; | |
277 | ||
278 | memset(&txc, 0, sizeof(struct timex)); | |
279 | ||
280 | if(get_user(txc.modes, &utp->modes) || | |
281 | __get_user(txc.offset, &utp->offset) || | |
282 | __get_user(txc.freq, &utp->freq) || | |
283 | __get_user(txc.maxerror, &utp->maxerror) || | |
284 | __get_user(txc.esterror, &utp->esterror) || | |
285 | __get_user(txc.status, &utp->status) || | |
286 | __get_user(txc.constant, &utp->constant) || | |
287 | __get_user(txc.precision, &utp->precision) || | |
288 | __get_user(txc.tolerance, &utp->tolerance) || | |
289 | __get_user(txc.time.tv_sec, &utp->time.tv_sec) || | |
290 | __get_user(txc.time.tv_usec, &utp->time.tv_usec) || | |
291 | __get_user(txc.tick, &utp->tick) || | |
292 | __get_user(txc.ppsfreq, &utp->ppsfreq) || | |
293 | __get_user(txc.jitter, &utp->jitter) || | |
294 | __get_user(txc.shift, &utp->shift) || | |
295 | __get_user(txc.stabil, &utp->stabil) || | |
296 | __get_user(txc.jitcnt, &utp->jitcnt) || | |
297 | __get_user(txc.calcnt, &utp->calcnt) || | |
298 | __get_user(txc.errcnt, &utp->errcnt) || | |
299 | __get_user(txc.stbcnt, &utp->stbcnt)) | |
300 | return -EFAULT; | |
301 | ||
302 | ret = do_adjtimex(&txc); | |
303 | ||
304 | /* adjust the conversion of TB to time of day to track adjtimex */ | |
305 | ppc_adjtimex(); | |
306 | ||
307 | if(put_user(txc.modes, &utp->modes) || | |
308 | __put_user(txc.offset, &utp->offset) || | |
309 | __put_user(txc.freq, &utp->freq) || | |
310 | __put_user(txc.maxerror, &utp->maxerror) || | |
311 | __put_user(txc.esterror, &utp->esterror) || | |
312 | __put_user(txc.status, &utp->status) || | |
313 | __put_user(txc.constant, &utp->constant) || | |
314 | __put_user(txc.precision, &utp->precision) || | |
315 | __put_user(txc.tolerance, &utp->tolerance) || | |
316 | __put_user(txc.time.tv_sec, &utp->time.tv_sec) || | |
317 | __put_user(txc.time.tv_usec, &utp->time.tv_usec) || | |
318 | __put_user(txc.tick, &utp->tick) || | |
319 | __put_user(txc.ppsfreq, &utp->ppsfreq) || | |
320 | __put_user(txc.jitter, &utp->jitter) || | |
321 | __put_user(txc.shift, &utp->shift) || | |
322 | __put_user(txc.stabil, &utp->stabil) || | |
323 | __put_user(txc.jitcnt, &utp->jitcnt) || | |
324 | __put_user(txc.calcnt, &utp->calcnt) || | |
325 | __put_user(txc.errcnt, &utp->errcnt) || | |
326 | __put_user(txc.stbcnt, &utp->stbcnt)) | |
327 | ret = -EFAULT; | |
328 | ||
329 | return ret; | |
330 | } | |
331 | ||
1da177e4 LT |
332 | asmlinkage long sys32_pause(void) |
333 | { | |
334 | current->state = TASK_INTERRUPTIBLE; | |
335 | schedule(); | |
336 | ||
337 | return -ERESTARTNOHAND; | |
338 | } | |
339 | ||
1da177e4 LT |
340 | static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i) |
341 | { | |
342 | long usec; | |
343 | ||
344 | if (!access_ok(VERIFY_READ, i, sizeof(*i))) | |
345 | return -EFAULT; | |
346 | if (__get_user(o->tv_sec, &i->tv_sec)) | |
347 | return -EFAULT; | |
348 | if (__get_user(usec, &i->tv_usec)) | |
349 | return -EFAULT; | |
350 | o->tv_nsec = usec * 1000; | |
351 | return 0; | |
352 | } | |
353 | ||
354 | static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i) | |
355 | { | |
356 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || | |
357 | (__put_user(i->tv_sec, &o->tv_sec) | | |
358 | __put_user(i->tv_usec, &o->tv_usec))); | |
359 | } | |
360 | ||
361 | struct sysinfo32 { | |
362 | s32 uptime; | |
363 | u32 loads[3]; | |
364 | u32 totalram; | |
365 | u32 freeram; | |
366 | u32 sharedram; | |
367 | u32 bufferram; | |
368 | u32 totalswap; | |
369 | u32 freeswap; | |
370 | unsigned short procs; | |
371 | unsigned short pad; | |
372 | u32 totalhigh; | |
373 | u32 freehigh; | |
374 | u32 mem_unit; | |
375 | char _f[20-2*sizeof(int)-sizeof(int)]; | |
376 | }; | |
377 | ||
378 | asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info) | |
379 | { | |
380 | struct sysinfo s; | |
381 | int ret, err; | |
382 | int bitcount=0; | |
383 | mm_segment_t old_fs = get_fs (); | |
384 | ||
385 | /* The __user cast is valid due to set_fs() */ | |
386 | set_fs (KERNEL_DS); | |
387 | ret = sys_sysinfo((struct sysinfo __user *)&s); | |
388 | set_fs (old_fs); | |
389 | ||
390 | /* Check to see if any memory value is too large for 32-bit and | |
391 | * scale down if needed. | |
392 | */ | |
393 | if ((s.totalram >> 32) || (s.totalswap >> 32)) { | |
394 | while (s.mem_unit < PAGE_SIZE) { | |
395 | s.mem_unit <<= 1; | |
396 | bitcount++; | |
397 | } | |
398 | s.totalram >>=bitcount; | |
399 | s.freeram >>= bitcount; | |
400 | s.sharedram >>= bitcount; | |
401 | s.bufferram >>= bitcount; | |
402 | s.totalswap >>= bitcount; | |
403 | s.freeswap >>= bitcount; | |
404 | s.totalhigh >>= bitcount; | |
405 | s.freehigh >>= bitcount; | |
406 | } | |
407 | ||
408 | err = put_user (s.uptime, &info->uptime); | |
409 | err |= __put_user (s.loads[0], &info->loads[0]); | |
410 | err |= __put_user (s.loads[1], &info->loads[1]); | |
411 | err |= __put_user (s.loads[2], &info->loads[2]); | |
412 | err |= __put_user (s.totalram, &info->totalram); | |
413 | err |= __put_user (s.freeram, &info->freeram); | |
414 | err |= __put_user (s.sharedram, &info->sharedram); | |
415 | err |= __put_user (s.bufferram, &info->bufferram); | |
416 | err |= __put_user (s.totalswap, &info->totalswap); | |
417 | err |= __put_user (s.freeswap, &info->freeswap); | |
418 | err |= __put_user (s.procs, &info->procs); | |
419 | err |= __put_user (s.totalhigh, &info->totalhigh); | |
420 | err |= __put_user (s.freehigh, &info->freehigh); | |
421 | err |= __put_user (s.mem_unit, &info->mem_unit); | |
422 | if (err) | |
423 | return -EFAULT; | |
424 | ||
425 | return ret; | |
426 | } | |
427 | ||
428 | ||
429 | ||
430 | ||
431 | /* Translations due to time_t size differences. Which affects all | |
432 | sorts of things, like timeval and itimerval. */ | |
433 | extern struct timezone sys_tz; | |
434 | ||
435 | asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
436 | { | |
437 | if (tv) { | |
438 | struct timeval ktv; | |
439 | do_gettimeofday(&ktv); | |
440 | if (put_tv32(tv, &ktv)) | |
441 | return -EFAULT; | |
442 | } | |
443 | if (tz) { | |
444 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | |
445 | return -EFAULT; | |
446 | } | |
447 | ||
448 | return 0; | |
449 | } | |
450 | ||
451 | ||
452 | ||
453 | asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
454 | { | |
455 | struct timespec kts; | |
456 | struct timezone ktz; | |
457 | ||
458 | if (tv) { | |
459 | if (get_ts32(&kts, tv)) | |
460 | return -EFAULT; | |
461 | } | |
462 | if (tz) { | |
463 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | |
464 | return -EFAULT; | |
465 | } | |
466 | ||
467 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | |
468 | } | |
469 | ||
470 | #ifdef CONFIG_SYSVIPC | |
471 | long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, | |
472 | u32 fifth) | |
473 | { | |
474 | int version; | |
475 | ||
476 | version = call >> 16; /* hack for backward compatibility */ | |
477 | call &= 0xffff; | |
478 | ||
479 | switch (call) { | |
480 | ||
481 | case SEMTIMEDOP: | |
482 | if (fifth) | |
483 | /* sign extend semid */ | |
484 | return compat_sys_semtimedop((int)first, | |
485 | compat_ptr(ptr), second, | |
486 | compat_ptr(fifth)); | |
487 | /* else fall through for normal semop() */ | |
488 | case SEMOP: | |
489 | /* struct sembuf is the same on 32 and 64bit :)) */ | |
490 | /* sign extend semid */ | |
491 | return sys_semtimedop((int)first, compat_ptr(ptr), second, | |
492 | NULL); | |
493 | case SEMGET: | |
494 | /* sign extend key, nsems */ | |
495 | return sys_semget((int)first, (int)second, third); | |
496 | case SEMCTL: | |
497 | /* sign extend semid, semnum */ | |
498 | return compat_sys_semctl((int)first, (int)second, third, | |
499 | compat_ptr(ptr)); | |
500 | ||
501 | case MSGSND: | |
502 | /* sign extend msqid */ | |
503 | return compat_sys_msgsnd((int)first, (int)second, third, | |
504 | compat_ptr(ptr)); | |
505 | case MSGRCV: | |
506 | /* sign extend msqid, msgtyp */ | |
507 | return compat_sys_msgrcv((int)first, second, (int)fifth, | |
508 | third, version, compat_ptr(ptr)); | |
509 | case MSGGET: | |
510 | /* sign extend key */ | |
511 | return sys_msgget((int)first, second); | |
512 | case MSGCTL: | |
513 | /* sign extend msqid */ | |
514 | return compat_sys_msgctl((int)first, second, compat_ptr(ptr)); | |
515 | ||
516 | case SHMAT: | |
517 | /* sign extend shmid */ | |
518 | return compat_sys_shmat((int)first, second, third, version, | |
519 | compat_ptr(ptr)); | |
520 | case SHMDT: | |
521 | return sys_shmdt(compat_ptr(ptr)); | |
522 | case SHMGET: | |
523 | /* sign extend key_t */ | |
524 | return sys_shmget((int)first, second, third); | |
525 | case SHMCTL: | |
526 | /* sign extend shmid */ | |
527 | return compat_sys_shmctl((int)first, second, compat_ptr(ptr)); | |
528 | ||
529 | default: | |
530 | return -ENOSYS; | |
531 | } | |
532 | ||
533 | return -ENOSYS; | |
534 | } | |
535 | #endif | |
536 | ||
537 | /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, | |
538 | * with the corresponding cast to a signed int to insure that the | |
539 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
540 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
541 | */ | |
542 | asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count) | |
543 | { | |
544 | mm_segment_t old_fs = get_fs(); | |
545 | int ret; | |
546 | off_t of; | |
547 | off_t __user *up; | |
548 | ||
549 | if (offset && get_user(of, offset)) | |
550 | return -EFAULT; | |
551 | ||
552 | /* The __user pointer cast is valid because of the set_fs() */ | |
553 | set_fs(KERNEL_DS); | |
554 | up = offset ? (off_t __user *) &of : NULL; | |
555 | ret = sys_sendfile((int)out_fd, (int)in_fd, up, count); | |
556 | set_fs(old_fs); | |
557 | ||
558 | if (offset && put_user(of, offset)) | |
559 | return -EFAULT; | |
560 | ||
561 | return ret; | |
562 | } | |
563 | ||
564 | asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count) | |
565 | { | |
566 | mm_segment_t old_fs = get_fs(); | |
567 | int ret; | |
568 | loff_t lof; | |
569 | loff_t __user *up; | |
570 | ||
571 | if (offset && get_user(lof, offset)) | |
572 | return -EFAULT; | |
573 | ||
574 | /* The __user pointer cast is valid because of the set_fs() */ | |
575 | set_fs(KERNEL_DS); | |
576 | up = offset ? (loff_t __user *) &lof : NULL; | |
577 | ret = sys_sendfile64(out_fd, in_fd, up, count); | |
578 | set_fs(old_fs); | |
579 | ||
580 | if (offset && put_user(lof, offset)) | |
581 | return -EFAULT; | |
582 | ||
583 | return ret; | |
584 | } | |
585 | ||
586 | long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2, | |
587 | unsigned long a3, unsigned long a4, unsigned long a5, | |
588 | struct pt_regs *regs) | |
589 | { | |
590 | int error; | |
591 | char * filename; | |
592 | ||
593 | filename = getname((char __user *) a0); | |
594 | error = PTR_ERR(filename); | |
595 | if (IS_ERR(filename)) | |
596 | goto out; | |
597 | flush_fp_to_thread(current); | |
598 | flush_altivec_to_thread(current); | |
599 | ||
600 | error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs); | |
601 | ||
602 | if (error == 0) { | |
603 | task_lock(current); | |
604 | current->ptrace &= ~PT_DTRACE; | |
605 | task_unlock(current); | |
606 | } | |
607 | putname(filename); | |
608 | ||
609 | out: | |
610 | return error; | |
611 | } | |
612 | ||
613 | /* Set up a thread for executing a new program. */ | |
614 | void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp) | |
615 | { | |
616 | set_fs(USER_DS); | |
617 | ||
618 | /* | |
619 | * If we exec out of a kernel thread then thread.regs will not be | |
620 | * set. Do it now. | |
621 | */ | |
622 | if (!current->thread.regs) { | |
623 | unsigned long childregs = (unsigned long)current->thread_info + | |
624 | THREAD_SIZE; | |
625 | childregs -= sizeof(struct pt_regs); | |
626 | current->thread.regs = (struct pt_regs *)childregs; | |
627 | } | |
628 | ||
629 | /* | |
630 | * ELF_PLAT_INIT already clears all registers but it also sets r2. | |
631 | * So just clear r2 here. | |
632 | */ | |
633 | regs->gpr[2] = 0; | |
634 | ||
635 | regs->nip = nip; | |
636 | regs->gpr[1] = sp; | |
637 | regs->msr = MSR_USER32; | |
638 | #ifndef CONFIG_SMP | |
639 | if (last_task_used_math == current) | |
640 | last_task_used_math = 0; | |
641 | #endif /* CONFIG_SMP */ | |
642 | current->thread.fpscr = 0; | |
643 | memset(current->thread.fpr, 0, sizeof(current->thread.fpr)); | |
644 | #ifdef CONFIG_ALTIVEC | |
645 | #ifndef CONFIG_SMP | |
646 | if (last_task_used_altivec == current) | |
647 | last_task_used_altivec = 0; | |
648 | #endif /* CONFIG_SMP */ | |
649 | memset(current->thread.vr, 0, sizeof(current->thread.vr)); | |
650 | current->thread.vscr.u[0] = 0; | |
651 | current->thread.vscr.u[1] = 0; | |
652 | current->thread.vscr.u[2] = 0; | |
653 | current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */ | |
654 | current->thread.vrsave = 0; | |
655 | current->thread.used_vr = 0; | |
656 | #endif /* CONFIG_ALTIVEC */ | |
657 | } | |
658 | ||
659 | /* Note: it is necessary to treat option as an unsigned int, | |
660 | * with the corresponding cast to a signed int to insure that the | |
661 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
662 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
663 | */ | |
664 | asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5) | |
665 | { | |
666 | return sys_prctl((int)option, | |
667 | (unsigned long) arg2, | |
668 | (unsigned long) arg3, | |
669 | (unsigned long) arg4, | |
670 | (unsigned long) arg5); | |
671 | } | |
672 | ||
673 | /* Note: it is necessary to treat pid as an unsigned int, | |
674 | * with the corresponding cast to a signed int to insure that the | |
675 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
676 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
677 | */ | |
678 | asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval) | |
679 | { | |
680 | struct timespec t; | |
681 | int ret; | |
682 | mm_segment_t old_fs = get_fs (); | |
683 | ||
684 | /* The __user pointer cast is valid because of the set_fs() */ | |
685 | set_fs (KERNEL_DS); | |
686 | ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t); | |
687 | set_fs (old_fs); | |
688 | if (put_compat_timespec(&t, interval)) | |
689 | return -EFAULT; | |
690 | return ret; | |
691 | } | |
692 | ||
693 | asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) | |
694 | { | |
695 | return sys_pciconfig_read((unsigned long) bus, | |
696 | (unsigned long) dfn, | |
697 | (unsigned long) off, | |
698 | (unsigned long) len, | |
699 | compat_ptr(ubuf)); | |
700 | } | |
701 | ||
702 | asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) | |
703 | { | |
704 | return sys_pciconfig_write((unsigned long) bus, | |
705 | (unsigned long) dfn, | |
706 | (unsigned long) off, | |
707 | (unsigned long) len, | |
708 | compat_ptr(ubuf)); | |
709 | } | |
710 | ||
711 | #define IOBASE_BRIDGE_NUMBER 0 | |
712 | #define IOBASE_MEMORY 1 | |
713 | #define IOBASE_IO 2 | |
714 | #define IOBASE_ISA_IO 3 | |
715 | #define IOBASE_ISA_MEM 4 | |
716 | ||
717 | asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn) | |
718 | { | |
145d01e4 | 719 | #ifdef CONFIG_PCI |
1da177e4 LT |
720 | struct pci_controller* hose; |
721 | struct list_head *ln; | |
722 | struct pci_bus *bus = NULL; | |
723 | struct device_node *hose_node; | |
724 | ||
725 | /* Argh ! Please forgive me for that hack, but that's the | |
726 | * simplest way to get existing XFree to not lockup on some | |
727 | * G5 machines... So when something asks for bus 0 io base | |
728 | * (bus 0 is HT root), we return the AGP one instead. | |
729 | */ | |
730 | #ifdef CONFIG_PPC_PMAC | |
731 | if (systemcfg->platform == PLATFORM_POWERMAC && | |
732 | machine_is_compatible("MacRISC4")) | |
733 | if (in_bus == 0) | |
734 | in_bus = 0xf0; | |
735 | #endif /* CONFIG_PPC_PMAC */ | |
736 | ||
737 | /* That syscall isn't quite compatible with PCI domains, but it's | |
738 | * used on pre-domains setup. We return the first match | |
739 | */ | |
740 | ||
741 | for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) { | |
742 | bus = pci_bus_b(ln); | |
743 | if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate)) | |
744 | break; | |
745 | bus = NULL; | |
746 | } | |
747 | if (bus == NULL || bus->sysdata == NULL) | |
748 | return -ENODEV; | |
749 | ||
750 | hose_node = (struct device_node *)bus->sysdata; | |
751 | hose = hose_node->phb; | |
752 | ||
753 | switch (which) { | |
754 | case IOBASE_BRIDGE_NUMBER: | |
755 | return (long)hose->first_busno; | |
756 | case IOBASE_MEMORY: | |
757 | return (long)hose->pci_mem_offset; | |
758 | case IOBASE_IO: | |
759 | return (long)hose->io_base_phys; | |
760 | case IOBASE_ISA_IO: | |
761 | return (long)isa_io_base; | |
762 | case IOBASE_ISA_MEM: | |
763 | return -EINVAL; | |
764 | } | |
145d01e4 | 765 | #endif /* CONFIG_PCI */ |
1da177e4 LT |
766 | return -EOPNOTSUPP; |
767 | } | |
768 | ||
769 | ||
1da177e4 LT |
770 | /* Note: it is necessary to treat mode as an unsigned int, |
771 | * with the corresponding cast to a signed int to insure that the | |
772 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
773 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
774 | */ | |
775 | asmlinkage long sys32_access(const char __user * filename, u32 mode) | |
776 | { | |
777 | return sys_access(filename, (int)mode); | |
778 | } | |
779 | ||
780 | ||
781 | /* Note: it is necessary to treat mode as an unsigned int, | |
782 | * with the corresponding cast to a signed int to insure that the | |
783 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
784 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
785 | */ | |
786 | asmlinkage long sys32_creat(const char __user * pathname, u32 mode) | |
787 | { | |
788 | return sys_creat(pathname, (int)mode); | |
789 | } | |
790 | ||
791 | ||
792 | /* Note: it is necessary to treat pid and options as unsigned ints, | |
793 | * with the corresponding cast to a signed int to insure that the | |
794 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
795 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
796 | */ | |
797 | asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options) | |
798 | { | |
799 | return sys_waitpid((int)pid, stat_addr, (int)options); | |
800 | } | |
801 | ||
802 | ||
803 | /* Note: it is necessary to treat gidsetsize as an unsigned int, | |
804 | * with the corresponding cast to a signed int to insure that the | |
805 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
806 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
807 | */ | |
808 | asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist) | |
809 | { | |
810 | return sys_getgroups((int)gidsetsize, grouplist); | |
811 | } | |
812 | ||
813 | ||
814 | /* Note: it is necessary to treat pid as an unsigned int, | |
815 | * with the corresponding cast to a signed int to insure that the | |
816 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
817 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
818 | */ | |
819 | asmlinkage long sys32_getpgid(u32 pid) | |
820 | { | |
821 | return sys_getpgid((int)pid); | |
822 | } | |
823 | ||
824 | ||
1da177e4 LT |
825 | |
826 | /* Note: it is necessary to treat pid as an unsigned int, | |
827 | * with the corresponding cast to a signed int to insure that the | |
828 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
829 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
830 | */ | |
831 | asmlinkage long sys32_getsid(u32 pid) | |
832 | { | |
833 | return sys_getsid((int)pid); | |
834 | } | |
835 | ||
836 | ||
837 | /* Note: it is necessary to treat pid and sig as unsigned ints, | |
838 | * with the corresponding cast to a signed int to insure that the | |
839 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
840 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
841 | */ | |
842 | asmlinkage long sys32_kill(u32 pid, u32 sig) | |
843 | { | |
844 | return sys_kill((int)pid, (int)sig); | |
845 | } | |
846 | ||
847 | ||
848 | /* Note: it is necessary to treat mode as an unsigned int, | |
849 | * with the corresponding cast to a signed int to insure that the | |
850 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
851 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
852 | */ | |
853 | asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode) | |
854 | { | |
855 | return sys_mkdir(pathname, (int)mode); | |
856 | } | |
857 | ||
858 | long sys32_nice(u32 increment) | |
859 | { | |
860 | /* sign extend increment */ | |
861 | return sys_nice((int)increment); | |
862 | } | |
863 | ||
864 | off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin) | |
865 | { | |
866 | /* sign extend n */ | |
867 | return sys_lseek(fd, (int)offset, origin); | |
868 | } | |
869 | ||
870 | /* | |
871 | * This is just a version for 32-bit applications which does | |
872 | * not force O_LARGEFILE on. | |
873 | */ | |
874 | asmlinkage long sys32_open(const char __user * filename, int flags, int mode) | |
875 | { | |
876 | char * tmp; | |
877 | int fd, error; | |
878 | ||
879 | tmp = getname(filename); | |
880 | fd = PTR_ERR(tmp); | |
881 | if (!IS_ERR(tmp)) { | |
882 | fd = get_unused_fd(); | |
883 | if (fd >= 0) { | |
884 | struct file * f = filp_open(tmp, flags, mode); | |
885 | error = PTR_ERR(f); | |
886 | if (IS_ERR(f)) | |
887 | goto out_error; | |
888 | fd_install(fd, f); | |
889 | } | |
890 | out: | |
891 | putname(tmp); | |
892 | } | |
893 | return fd; | |
894 | ||
895 | out_error: | |
896 | put_unused_fd(fd); | |
897 | fd = error; | |
898 | goto out; | |
899 | } | |
900 | ||
901 | /* Note: it is necessary to treat bufsiz as an unsigned int, | |
902 | * with the corresponding cast to a signed int to insure that the | |
903 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
904 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
905 | */ | |
906 | asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz) | |
907 | { | |
908 | return sys_readlink(path, buf, (int)bufsiz); | |
909 | } | |
910 | ||
911 | /* Note: it is necessary to treat option as an unsigned int, | |
912 | * with the corresponding cast to a signed int to insure that the | |
913 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
914 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
915 | */ | |
916 | asmlinkage long sys32_sched_get_priority_max(u32 policy) | |
917 | { | |
918 | return sys_sched_get_priority_max((int)policy); | |
919 | } | |
920 | ||
921 | ||
922 | /* Note: it is necessary to treat policy as an unsigned int, | |
923 | * with the corresponding cast to a signed int to insure that the | |
924 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
925 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
926 | */ | |
927 | asmlinkage long sys32_sched_get_priority_min(u32 policy) | |
928 | { | |
929 | return sys_sched_get_priority_min((int)policy); | |
930 | } | |
931 | ||
932 | ||
933 | /* Note: it is necessary to treat pid as an unsigned int, | |
934 | * with the corresponding cast to a signed int to insure that the | |
935 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
936 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
937 | */ | |
938 | asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param) | |
939 | { | |
940 | return sys_sched_getparam((int)pid, param); | |
941 | } | |
942 | ||
943 | ||
944 | /* Note: it is necessary to treat pid as an unsigned int, | |
945 | * with the corresponding cast to a signed int to insure that the | |
946 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
947 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
948 | */ | |
949 | asmlinkage long sys32_sched_getscheduler(u32 pid) | |
950 | { | |
951 | return sys_sched_getscheduler((int)pid); | |
952 | } | |
953 | ||
954 | ||
955 | /* Note: it is necessary to treat pid as an unsigned int, | |
956 | * with the corresponding cast to a signed int to insure that the | |
957 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
958 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
959 | */ | |
960 | asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param) | |
961 | { | |
962 | return sys_sched_setparam((int)pid, param); | |
963 | } | |
964 | ||
965 | ||
966 | /* Note: it is necessary to treat pid and policy as unsigned ints, | |
967 | * with the corresponding cast to a signed int to insure that the | |
968 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
969 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
970 | */ | |
971 | asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param) | |
972 | { | |
973 | return sys_sched_setscheduler((int)pid, (int)policy, param); | |
974 | } | |
975 | ||
976 | ||
977 | /* Note: it is necessary to treat len as an unsigned int, | |
978 | * with the corresponding cast to a signed int to insure that the | |
979 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
980 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
981 | */ | |
982 | asmlinkage long sys32_setdomainname(char __user *name, u32 len) | |
983 | { | |
984 | return sys_setdomainname(name, (int)len); | |
985 | } | |
986 | ||
987 | ||
988 | /* Note: it is necessary to treat gidsetsize as an unsigned int, | |
989 | * with the corresponding cast to a signed int to insure that the | |
990 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
991 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
992 | */ | |
993 | asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist) | |
994 | { | |
995 | return sys_setgroups((int)gidsetsize, grouplist); | |
996 | } | |
997 | ||
998 | ||
999 | asmlinkage long sys32_sethostname(char __user *name, u32 len) | |
1000 | { | |
1001 | /* sign extend len */ | |
1002 | return sys_sethostname(name, (int)len); | |
1003 | } | |
1004 | ||
1005 | ||
1006 | /* Note: it is necessary to treat pid and pgid as unsigned ints, | |
1007 | * with the corresponding cast to a signed int to insure that the | |
1008 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
1009 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
1010 | */ | |
1011 | asmlinkage long sys32_setpgid(u32 pid, u32 pgid) | |
1012 | { | |
1013 | return sys_setpgid((int)pid, (int)pgid); | |
1014 | } | |
1015 | ||
79c2cc7b AB |
1016 | long sys32_getpriority(u32 which, u32 who) |
1017 | { | |
1018 | /* sign extend which and who */ | |
1019 | return sys_getpriority((int)which, (int)who); | |
1020 | } | |
1da177e4 LT |
1021 | |
1022 | long sys32_setpriority(u32 which, u32 who, u32 niceval) | |
1023 | { | |
1024 | /* sign extend which, who and niceval */ | |
1025 | return sys_setpriority((int)which, (int)who, (int)niceval); | |
1026 | } | |
1027 | ||
79c2cc7b AB |
1028 | long sys32_ioprio_get(u32 which, u32 who) |
1029 | { | |
1030 | /* sign extend which and who */ | |
1031 | return sys_ioprio_get((int)which, (int)who); | |
1032 | } | |
1033 | ||
1034 | long sys32_ioprio_set(u32 which, u32 who, u32 ioprio) | |
1035 | { | |
1036 | /* sign extend which, who and ioprio */ | |
1037 | return sys_ioprio_set((int)which, (int)who, (int)ioprio); | |
1038 | } | |
1039 | ||
1da177e4 LT |
1040 | /* Note: it is necessary to treat newmask as an unsigned int, |
1041 | * with the corresponding cast to a signed int to insure that the | |
1042 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
1043 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
1044 | */ | |
1045 | asmlinkage long sys32_ssetmask(u32 newmask) | |
1046 | { | |
1047 | return sys_ssetmask((int) newmask); | |
1048 | } | |
1049 | ||
1050 | asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len) | |
1051 | { | |
1052 | /* sign extend len */ | |
1053 | return sys_syslog(type, buf, (int)len); | |
1054 | } | |
1055 | ||
1056 | ||
1057 | /* Note: it is necessary to treat mask as an unsigned int, | |
1058 | * with the corresponding cast to a signed int to insure that the | |
1059 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
1060 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
1061 | */ | |
1062 | asmlinkage long sys32_umask(u32 mask) | |
1063 | { | |
1064 | return sys_umask((int)mask); | |
1065 | } | |
1066 | ||
1067 | #ifdef CONFIG_SYSCTL | |
1068 | struct __sysctl_args32 { | |
1069 | u32 name; | |
1070 | int nlen; | |
1071 | u32 oldval; | |
1072 | u32 oldlenp; | |
1073 | u32 newval; | |
1074 | u32 newlen; | |
1075 | u32 __unused[4]; | |
1076 | }; | |
1077 | ||
1078 | asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args) | |
1079 | { | |
1080 | struct __sysctl_args32 tmp; | |
1081 | int error; | |
1082 | size_t oldlen; | |
1083 | size_t __user *oldlenp = NULL; | |
1084 | unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7; | |
1085 | ||
1086 | if (copy_from_user(&tmp, args, sizeof(tmp))) | |
1087 | return -EFAULT; | |
1088 | ||
1089 | if (tmp.oldval && tmp.oldlenp) { | |
1090 | /* Duh, this is ugly and might not work if sysctl_args | |
1091 | is in read-only memory, but do_sysctl does indirectly | |
1092 | a lot of uaccess in both directions and we'd have to | |
1093 | basically copy the whole sysctl.c here, and | |
1094 | glibc's __sysctl uses rw memory for the structure | |
1095 | anyway. */ | |
1096 | oldlenp = (size_t __user *)addr; | |
1097 | if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) || | |
1098 | put_user(oldlen, oldlenp)) | |
1099 | return -EFAULT; | |
1100 | } | |
1101 | ||
1102 | lock_kernel(); | |
1103 | error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, | |
1104 | compat_ptr(tmp.oldval), oldlenp, | |
1105 | compat_ptr(tmp.newval), tmp.newlen); | |
1106 | unlock_kernel(); | |
1107 | if (oldlenp) { | |
1108 | if (!error) { | |
1109 | if (get_user(oldlen, oldlenp) || | |
1110 | put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp))) | |
1111 | error = -EFAULT; | |
1112 | } | |
1113 | copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); | |
1114 | } | |
1115 | return error; | |
1116 | } | |
1117 | #endif | |
1118 | ||
ce10d979 PM |
1119 | asmlinkage int sys32_uname(struct old_utsname __user * name) |
1120 | { | |
1121 | int err = 0; | |
1122 | ||
1123 | down_read(&uts_sem); | |
1124 | if (copy_to_user(name, &system_utsname, sizeof(*name))) | |
1125 | err = -EFAULT; | |
1126 | up_read(&uts_sem); | |
1127 | if (!err && personality(current->personality) == PER_LINUX32) { | |
1128 | /* change "ppc64" to "ppc" */ | |
1129 | if (__put_user(0, name->machine + 3) | |
1130 | || __put_user(0, name->machine + 4)) | |
1131 | err = -EFAULT; | |
1132 | } | |
1133 | return err; | |
1134 | } | |
1135 | ||
1da177e4 LT |
1136 | asmlinkage int sys32_olduname(struct oldold_utsname __user * name) |
1137 | { | |
1138 | int error; | |
ce10d979 | 1139 | |
1da177e4 LT |
1140 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) |
1141 | return -EFAULT; | |
1142 | ||
1143 | down_read(&uts_sem); | |
1144 | error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); | |
ce10d979 PM |
1145 | error |= __put_user(0,name->sysname+__OLD_UTS_LEN); |
1146 | error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); | |
1147 | error |= __put_user(0,name->nodename+__OLD_UTS_LEN); | |
1148 | error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); | |
1149 | error |= __put_user(0,name->release+__OLD_UTS_LEN); | |
1150 | error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); | |
1151 | error |= __put_user(0,name->version+__OLD_UTS_LEN); | |
1152 | error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN); | |
1153 | error |= __put_user(0,name->machine+__OLD_UTS_LEN); | |
1154 | if (personality(current->personality) == PER_LINUX32) { | |
1155 | /* change "ppc64" to "ppc" */ | |
1156 | error |= __put_user(0, name->machine + 3); | |
1157 | error |= __put_user(0, name->machine + 4); | |
1158 | } | |
1159 | ||
1da177e4 LT |
1160 | up_read(&uts_sem); |
1161 | ||
1162 | error = error ? -EFAULT : 0; | |
1163 | ||
1164 | return error; | |
1165 | } | |
1166 | ||
1167 | unsigned long sys32_mmap2(unsigned long addr, size_t len, | |
1168 | unsigned long prot, unsigned long flags, | |
1169 | unsigned long fd, unsigned long pgoff) | |
1170 | { | |
1171 | /* This should remain 12 even if PAGE_SIZE changes */ | |
1172 | return sys_mmap(addr, len, prot, flags, fd, pgoff << 12); | |
1173 | } | |
1174 | ||
1175 | int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv) | |
1176 | { | |
1177 | return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) || | |
1178 | __get_user(tv->tv_sec, &ctv->tv_sec) || | |
1179 | __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; | |
1180 | } | |
1181 | ||
1182 | asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs) | |
1183 | { | |
1184 | struct timeval ktvs[2], *ptr; | |
1185 | ||
1186 | ptr = NULL; | |
1187 | if (tvs) { | |
1188 | if (get_compat_timeval(&ktvs[0], &tvs[0]) || | |
1189 | get_compat_timeval(&ktvs[1], &tvs[1])) | |
1190 | return -EFAULT; | |
1191 | ptr = ktvs; | |
1192 | } | |
1193 | ||
1194 | return do_utimes(filename, ptr); | |
1195 | } | |
1196 | ||
1197 | long sys32_tgkill(u32 tgid, u32 pid, int sig) | |
1198 | { | |
1199 | /* sign extend tgid, pid */ | |
1200 | return sys_tgkill((int)tgid, (int)pid, sig); | |
1201 | } | |
1202 | ||
1203 | /* | |
1204 | * long long munging: | |
1205 | * The 32 bit ABI passes long longs in an odd even register pair. | |
1206 | */ | |
1207 | ||
1208 | compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, | |
1209 | u32 reg6, u32 poshi, u32 poslo) | |
1210 | { | |
1211 | return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); | |
1212 | } | |
1213 | ||
1214 | compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count, | |
1215 | u32 reg6, u32 poshi, u32 poslo) | |
1216 | { | |
1217 | return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); | |
1218 | } | |
1219 | ||
1220 | compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) | |
1221 | { | |
1222 | return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); | |
1223 | } | |
1224 | ||
1225 | asmlinkage int sys32_truncate64(const char __user * path, u32 reg4, | |
1226 | unsigned long high, unsigned long low) | |
1227 | { | |
1228 | return sys_truncate(path, (high << 32) | low); | |
1229 | } | |
1230 | ||
1231 | asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, | |
1232 | unsigned long low) | |
1233 | { | |
1234 | return sys_ftruncate(fd, (high << 32) | low); | |
1235 | } | |
1236 | ||
1237 | long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, | |
1238 | size_t len) | |
1239 | { | |
1240 | return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, | |
1241 | buf, len); | |
1242 | } | |
1243 | ||
1244 | long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low, | |
1245 | size_t len, int advice) | |
1246 | { | |
1247 | return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len, | |
1248 | advice); | |
1249 | } | |
1250 | ||
1251 | long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low, | |
1252 | u32 len_high, u32 len_low) | |
1253 | { | |
1254 | return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, | |
1255 | (u64)len_high << 32 | len_low, advice); | |
1256 | } | |
1257 | ||
1da177e4 LT |
1258 | long ppc32_timer_create(clockid_t clock, |
1259 | struct compat_sigevent __user *ev32, | |
1260 | timer_t __user *timer_id) | |
1261 | { | |
1262 | sigevent_t event; | |
1263 | timer_t t; | |
1264 | long err; | |
1265 | mm_segment_t savefs; | |
1266 | ||
1267 | if (ev32 == NULL) | |
1268 | return sys_timer_create(clock, NULL, timer_id); | |
1269 | ||
1270 | if (get_compat_sigevent(&event, ev32)) | |
1271 | return -EFAULT; | |
1272 | ||
1273 | if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t))) | |
1274 | return -EFAULT; | |
1275 | ||
1276 | savefs = get_fs(); | |
1277 | set_fs(KERNEL_DS); | |
1278 | /* The __user pointer casts are valid due to the set_fs() */ | |
1279 | err = sys_timer_create(clock, | |
1280 | (sigevent_t __user *) &event, | |
1281 | (timer_t __user *) &t); | |
1282 | set_fs(savefs); | |
1283 | ||
1284 | if (err == 0) | |
1285 | err = __put_user(t, timer_id); | |
1286 | ||
1287 | return err; | |
1288 | } | |
1289 | ||
1290 | asmlinkage long sys32_add_key(const char __user *_type, | |
1291 | const char __user *_description, | |
1292 | const void __user *_payload, | |
1293 | u32 plen, | |
1294 | u32 ringid) | |
1295 | { | |
1296 | return sys_add_key(_type, _description, _payload, plen, ringid); | |
1297 | } | |
1298 | ||
1299 | asmlinkage long sys32_request_key(const char __user *_type, | |
1300 | const char __user *_description, | |
1301 | const char __user *_callout_info, | |
1302 | u32 destringid) | |
1303 | { | |
1304 | return sys_request_key(_type, _description, _callout_info, destringid); | |
1305 | } | |
1306 |