linux32.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. /*
  2. * Conversion between 32-bit and 64-bit native system calls.
  3. *
  4. * Copyright (C) 2000 Silicon Graphics, Inc.
  5. * Written by Ulf Carlsson (ulfc@engr.sgi.com)
  6. * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com)
  7. */
  8. #include <linux/config.h>
  9. #include <linux/compiler.h>
  10. #include <linux/mm.h>
  11. #include <linux/errno.h>
  12. #include <linux/file.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/highuid.h>
  15. #include <linux/dirent.h>
  16. #include <linux/resource.h>
  17. #include <linux/highmem.h>
  18. #include <linux/time.h>
  19. #include <linux/times.h>
  20. #include <linux/poll.h>
  21. #include <linux/slab.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/filter.h>
  24. #include <linux/shm.h>
  25. #include <linux/sem.h>
  26. #include <linux/msg.h>
  27. #include <linux/icmpv6.h>
  28. #include <linux/syscalls.h>
  29. #include <linux/sysctl.h>
  30. #include <linux/utime.h>
  31. #include <linux/utsname.h>
  32. #include <linux/personality.h>
  33. #include <linux/timex.h>
  34. #include <linux/dnotify.h>
  35. #include <linux/module.h>
  36. #include <linux/binfmts.h>
  37. #include <linux/security.h>
  38. #include <linux/compat.h>
  39. #include <linux/vfs.h>
  40. #include <net/sock.h>
  41. #include <net/scm.h>
  42. #include <asm/ipc.h>
  43. #include <asm/sim.h>
  44. #include <asm/uaccess.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/mman.h>
  47. /* Use this to get at 32-bit user passed pointers. */
  48. /* A() macro should be used for places where you e.g.
  49. have some internal variable u32 and just want to get
  50. rid of a compiler warning. AA() has to be used in
  51. places where you want to convert a function argument
  52. to 32bit pointer or when you e.g. access pt_regs
  53. structure and want to consider 32bit registers only.
  54. */
  55. #define A(__x) ((unsigned long)(__x))
  56. #define AA(__x) ((unsigned long)((int)__x))
  57. #ifdef __MIPSEB__
  58. #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
  59. #endif
  60. #ifdef __MIPSEL__
  61. #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
  62. #endif
  63. /*
  64. * Revalidate the inode. This is required for proper NFS attribute caching.
  65. */
  66. int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
  67. {
  68. struct compat_stat tmp;
  69. if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev))
  70. return -EOVERFLOW;
  71. memset(&tmp, 0, sizeof(tmp));
  72. tmp.st_dev = new_encode_dev(stat->dev);
  73. tmp.st_ino = stat->ino;
  74. tmp.st_mode = stat->mode;
  75. tmp.st_nlink = stat->nlink;
  76. SET_UID(tmp.st_uid, stat->uid);
  77. SET_GID(tmp.st_gid, stat->gid);
  78. tmp.st_rdev = new_encode_dev(stat->rdev);
  79. tmp.st_size = stat->size;
  80. tmp.st_atime = stat->atime.tv_sec;
  81. tmp.st_mtime = stat->mtime.tv_sec;
  82. tmp.st_ctime = stat->ctime.tv_sec;
  83. #ifdef STAT_HAVE_NSEC
  84. tmp.st_atime_nsec = stat->atime.tv_nsec;
  85. tmp.st_mtime_nsec = stat->mtime.tv_nsec;
  86. tmp.st_ctime_nsec = stat->ctime.tv_nsec;
  87. #endif
  88. tmp.st_blocks = stat->blocks;
  89. tmp.st_blksize = stat->blksize;
  90. return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
  91. }
  92. asmlinkage unsigned long
  93. sys32_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  94. unsigned long flags, unsigned long fd, unsigned long pgoff)
  95. {
  96. struct file * file = NULL;
  97. unsigned long error;
  98. error = -EINVAL;
  99. if (!(flags & MAP_ANONYMOUS)) {
  100. error = -EBADF;
  101. file = fget(fd);
  102. if (!file)
  103. goto out;
  104. }
  105. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  106. down_write(&current->mm->mmap_sem);
  107. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  108. up_write(&current->mm->mmap_sem);
  109. if (file)
  110. fput(file);
  111. out:
  112. return error;
  113. }
  114. asmlinkage int sys_truncate64(const char *path, unsigned int high,
  115. unsigned int low)
  116. {
  117. if ((int)high < 0)
  118. return -EINVAL;
  119. return sys_truncate(path, ((long) high << 32) | low);
  120. }
  121. asmlinkage int sys_ftruncate64(unsigned int fd, unsigned int high,
  122. unsigned int low)
  123. {
  124. if ((int)high < 0)
  125. return -EINVAL;
  126. return sys_ftruncate(fd, ((long) high << 32) | low);
  127. }
  128. /*
  129. * sys_execve() executes a new program.
  130. */
  131. asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs)
  132. {
  133. int error;
  134. char * filename;
  135. filename = getname(compat_ptr(regs.regs[4]));
  136. error = PTR_ERR(filename);
  137. if (IS_ERR(filename))
  138. goto out;
  139. error = compat_do_execve(filename, compat_ptr(regs.regs[5]),
  140. compat_ptr(regs.regs[6]), &regs);
  141. putname(filename);
  142. out:
  143. return error;
  144. }
  145. struct dirent32 {
  146. unsigned int d_ino;
  147. unsigned int d_off;
  148. unsigned short d_reclen;
  149. char d_name[NAME_MAX + 1];
  150. };
  151. static void
  152. xlate_dirent(void *dirent64, void *dirent32, long n)
  153. {
  154. long off;
  155. struct dirent *dirp;
  156. struct dirent32 *dirp32;
  157. off = 0;
  158. while (off < n) {
  159. dirp = (struct dirent *)(dirent64 + off);
  160. dirp32 = (struct dirent32 *)(dirent32 + off);
  161. off += dirp->d_reclen;
  162. dirp32->d_ino = dirp->d_ino;
  163. dirp32->d_off = (unsigned int)dirp->d_off;
  164. dirp32->d_reclen = dirp->d_reclen;
  165. strncpy(dirp32->d_name, dirp->d_name, dirp->d_reclen - ((3 * 4) + 2));
  166. }
  167. return;
  168. }
  169. asmlinkage long
  170. sys32_getdents(unsigned int fd, void * dirent32, unsigned int count)
  171. {
  172. long n;
  173. void *dirent64;
  174. dirent64 = (void *)((unsigned long)(dirent32 + (sizeof(long) - 1)) & ~(sizeof(long) - 1));
  175. if ((n = sys_getdents(fd, dirent64, count - (dirent64 - dirent32))) < 0)
  176. return(n);
  177. xlate_dirent(dirent64, dirent32, n);
  178. return(n);
  179. }
  180. asmlinkage int old_readdir(unsigned int fd, void * dirent, unsigned int count);
  181. asmlinkage int
  182. sys32_readdir(unsigned int fd, void * dirent32, unsigned int count)
  183. {
  184. int n;
  185. struct dirent dirent64;
  186. if ((n = old_readdir(fd, &dirent64, count)) < 0)
  187. return(n);
  188. xlate_dirent(&dirent64, dirent32, dirent64.d_reclen);
  189. return(n);
  190. }
  191. asmlinkage int
  192. sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
  193. {
  194. return compat_sys_wait4(pid, stat_addr, options, NULL);
  195. }
  196. struct sysinfo32 {
  197. s32 uptime;
  198. u32 loads[3];
  199. u32 totalram;
  200. u32 freeram;
  201. u32 sharedram;
  202. u32 bufferram;
  203. u32 totalswap;
  204. u32 freeswap;
  205. u16 procs;
  206. u32 totalhigh;
  207. u32 freehigh;
  208. u32 mem_unit;
  209. char _f[8];
  210. };
  211. asmlinkage int sys32_sysinfo(struct sysinfo32 *info)
  212. {
  213. struct sysinfo s;
  214. int ret, err;
  215. mm_segment_t old_fs = get_fs ();
  216. set_fs (KERNEL_DS);
  217. ret = sys_sysinfo(&s);
  218. set_fs (old_fs);
  219. err = put_user (s.uptime, &info->uptime);
  220. err |= __put_user (s.loads[0], &info->loads[0]);
  221. err |= __put_user (s.loads[1], &info->loads[1]);
  222. err |= __put_user (s.loads[2], &info->loads[2]);
  223. err |= __put_user (s.totalram, &info->totalram);
  224. err |= __put_user (s.freeram, &info->freeram);
  225. err |= __put_user (s.sharedram, &info->sharedram);
  226. err |= __put_user (s.bufferram, &info->bufferram);
  227. err |= __put_user (s.totalswap, &info->totalswap);
  228. err |= __put_user (s.freeswap, &info->freeswap);
  229. err |= __put_user (s.procs, &info->procs);
  230. err |= __put_user (s.totalhigh, &info->totalhigh);
  231. err |= __put_user (s.freehigh, &info->freehigh);
  232. err |= __put_user (s.mem_unit, &info->mem_unit);
  233. if (err)
  234. return -EFAULT;
  235. return ret;
  236. }
  237. #define RLIM_INFINITY32 0x7fffffff
  238. #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
  239. struct rlimit32 {
  240. int rlim_cur;
  241. int rlim_max;
  242. };
  243. #ifdef __MIPSEB__
  244. asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy,
  245. int length_hi, int length_lo)
  246. #endif
  247. #ifdef __MIPSEL__
  248. asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy,
  249. int length_lo, int length_hi)
  250. #endif
  251. {
  252. loff_t length;
  253. length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo;
  254. return sys_truncate(path, length);
  255. }
  256. #ifdef __MIPSEB__
  257. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
  258. int length_hi, int length_lo)
  259. #endif
  260. #ifdef __MIPSEL__
  261. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
  262. int length_lo, int length_hi)
  263. #endif
  264. {
  265. loff_t length;
  266. length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo;
  267. return sys_ftruncate(fd, length);
  268. }
  269. static inline long
  270. get_tv32(struct timeval *o, struct compat_timeval *i)
  271. {
  272. return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
  273. (__get_user(o->tv_sec, &i->tv_sec) |
  274. __get_user(o->tv_usec, &i->tv_usec)));
  275. }
  276. static inline long
  277. put_tv32(struct compat_timeval *o, struct timeval *i)
  278. {
  279. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  280. (__put_user(i->tv_sec, &o->tv_sec) |
  281. __put_user(i->tv_usec, &o->tv_usec)));
  282. }
  283. extern struct timezone sys_tz;
  284. asmlinkage int
  285. sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
  286. {
  287. if (tv) {
  288. struct timeval ktv;
  289. do_gettimeofday(&ktv);
  290. if (put_tv32(tv, &ktv))
  291. return -EFAULT;
  292. }
  293. if (tz) {
  294. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  295. return -EFAULT;
  296. }
  297. return 0;
  298. }
  299. static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
  300. {
  301. long usec;
  302. if (!access_ok(VERIFY_READ, i, sizeof(*i)))
  303. return -EFAULT;
  304. if (__get_user(o->tv_sec, &i->tv_sec))
  305. return -EFAULT;
  306. if (__get_user(usec, &i->tv_usec))
  307. return -EFAULT;
  308. o->tv_nsec = usec * 1000;
  309. return 0;
  310. }
  311. asmlinkage int
  312. sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
  313. {
  314. struct timespec kts;
  315. struct timezone ktz;
  316. if (tv) {
  317. if (get_ts32(&kts, tv))
  318. return -EFAULT;
  319. }
  320. if (tz) {
  321. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  322. return -EFAULT;
  323. }
  324. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  325. }
  326. asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high,
  327. unsigned int offset_low, loff_t * result,
  328. unsigned int origin)
  329. {
  330. return sys_llseek(fd, offset_high, offset_low, result, origin);
  331. }
  332. /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
  333. lseek back to original location. They fail just like lseek does on
  334. non-seekable files. */
  335. asmlinkage ssize_t sys32_pread(unsigned int fd, char * buf,
  336. size_t count, u32 unused, u64 a4, u64 a5)
  337. {
  338. ssize_t ret;
  339. struct file * file;
  340. ssize_t (*read)(struct file *, char *, size_t, loff_t *);
  341. loff_t pos;
  342. ret = -EBADF;
  343. file = fget(fd);
  344. if (!file)
  345. goto bad_file;
  346. if (!(file->f_mode & FMODE_READ))
  347. goto out;
  348. pos = merge_64(a4, a5);
  349. ret = rw_verify_area(READ, file, &pos, count);
  350. if (ret)
  351. goto out;
  352. ret = -EINVAL;
  353. if (!file->f_op || !(read = file->f_op->read))
  354. goto out;
  355. if (pos < 0)
  356. goto out;
  357. ret = -ESPIPE;
  358. if (!(file->f_mode & FMODE_PREAD))
  359. goto out;
  360. ret = read(file, buf, count, &pos);
  361. if (ret > 0)
  362. dnotify_parent(file->f_dentry, DN_ACCESS);
  363. out:
  364. fput(file);
  365. bad_file:
  366. return ret;
  367. }
  368. asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char * buf,
  369. size_t count, u32 unused, u64 a4, u64 a5)
  370. {
  371. ssize_t ret;
  372. struct file * file;
  373. ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
  374. loff_t pos;
  375. ret = -EBADF;
  376. file = fget(fd);
  377. if (!file)
  378. goto bad_file;
  379. if (!(file->f_mode & FMODE_WRITE))
  380. goto out;
  381. pos = merge_64(a4, a5);
  382. ret = rw_verify_area(WRITE, file, &pos, count);
  383. if (ret)
  384. goto out;
  385. ret = -EINVAL;
  386. if (!file->f_op || !(write = file->f_op->write))
  387. goto out;
  388. if (pos < 0)
  389. goto out;
  390. ret = -ESPIPE;
  391. if (!(file->f_mode & FMODE_PWRITE))
  392. goto out;
  393. ret = write(file, buf, count, &pos);
  394. if (ret > 0)
  395. dnotify_parent(file->f_dentry, DN_MODIFY);
  396. out:
  397. fput(file);
  398. bad_file:
  399. return ret;
  400. }
  401. asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid,
  402. struct compat_timespec *interval)
  403. {
  404. struct timespec t;
  405. int ret;
  406. mm_segment_t old_fs = get_fs ();
  407. set_fs (KERNEL_DS);
  408. ret = sys_sched_rr_get_interval(pid, &t);
  409. set_fs (old_fs);
  410. if (put_user (t.tv_sec, &interval->tv_sec) ||
  411. __put_user (t.tv_nsec, &interval->tv_nsec))
  412. return -EFAULT;
  413. return ret;
  414. }
  415. struct msgbuf32 { s32 mtype; char mtext[1]; };
  416. struct ipc_perm32
  417. {
  418. key_t key;
  419. __compat_uid_t uid;
  420. __compat_gid_t gid;
  421. __compat_uid_t cuid;
  422. __compat_gid_t cgid;
  423. compat_mode_t mode;
  424. unsigned short seq;
  425. };
  426. struct ipc64_perm32 {
  427. key_t key;
  428. __compat_uid_t uid;
  429. __compat_gid_t gid;
  430. __compat_uid_t cuid;
  431. __compat_gid_t cgid;
  432. compat_mode_t mode;
  433. unsigned short seq;
  434. unsigned short __pad1;
  435. unsigned int __unused1;
  436. unsigned int __unused2;
  437. };
  438. struct semid_ds32 {
  439. struct ipc_perm32 sem_perm; /* permissions .. see ipc.h */
  440. compat_time_t sem_otime; /* last semop time */
  441. compat_time_t sem_ctime; /* last change time */
  442. u32 sem_base; /* ptr to first semaphore in array */
  443. u32 sem_pending; /* pending operations to be processed */
  444. u32 sem_pending_last; /* last pending operation */
  445. u32 undo; /* undo requests on this array */
  446. unsigned short sem_nsems; /* no. of semaphores in array */
  447. };
  448. struct semid64_ds32 {
  449. struct ipc64_perm32 sem_perm;
  450. compat_time_t sem_otime;
  451. compat_time_t sem_ctime;
  452. unsigned int sem_nsems;
  453. unsigned int __unused1;
  454. unsigned int __unused2;
  455. };
  456. struct msqid_ds32
  457. {
  458. struct ipc_perm32 msg_perm;
  459. u32 msg_first;
  460. u32 msg_last;
  461. compat_time_t msg_stime;
  462. compat_time_t msg_rtime;
  463. compat_time_t msg_ctime;
  464. u32 wwait;
  465. u32 rwait;
  466. unsigned short msg_cbytes;
  467. unsigned short msg_qnum;
  468. unsigned short msg_qbytes;
  469. compat_ipc_pid_t msg_lspid;
  470. compat_ipc_pid_t msg_lrpid;
  471. };
  472. struct msqid64_ds32 {
  473. struct ipc64_perm32 msg_perm;
  474. compat_time_t msg_stime;
  475. unsigned int __unused1;
  476. compat_time_t msg_rtime;
  477. unsigned int __unused2;
  478. compat_time_t msg_ctime;
  479. unsigned int __unused3;
  480. unsigned int msg_cbytes;
  481. unsigned int msg_qnum;
  482. unsigned int msg_qbytes;
  483. compat_pid_t msg_lspid;
  484. compat_pid_t msg_lrpid;
  485. unsigned int __unused4;
  486. unsigned int __unused5;
  487. };
  488. struct shmid_ds32 {
  489. struct ipc_perm32 shm_perm;
  490. int shm_segsz;
  491. compat_time_t shm_atime;
  492. compat_time_t shm_dtime;
  493. compat_time_t shm_ctime;
  494. compat_ipc_pid_t shm_cpid;
  495. compat_ipc_pid_t shm_lpid;
  496. unsigned short shm_nattch;
  497. };
  498. struct shmid64_ds32 {
  499. struct ipc64_perm32 shm_perm;
  500. compat_size_t shm_segsz;
  501. compat_time_t shm_atime;
  502. compat_time_t shm_dtime;
  503. compat_time_t shm_ctime;
  504. compat_pid_t shm_cpid;
  505. compat_pid_t shm_lpid;
  506. unsigned int shm_nattch;
  507. unsigned int __unused1;
  508. unsigned int __unused2;
  509. };
  510. struct ipc_kludge32 {
  511. u32 msgp;
  512. s32 msgtyp;
  513. };
  514. static int
  515. do_sys32_semctl(int first, int second, int third, void *uptr)
  516. {
  517. union semun fourth;
  518. u32 pad;
  519. int err, err2;
  520. struct semid64_ds s;
  521. mm_segment_t old_fs;
  522. if (!uptr)
  523. return -EINVAL;
  524. err = -EFAULT;
  525. if (get_user (pad, (u32 *)uptr))
  526. return err;
  527. if ((third & ~IPC_64) == SETVAL)
  528. fourth.val = (int)pad;
  529. else
  530. fourth.__pad = (void *)A(pad);
  531. switch (third & ~IPC_64) {
  532. case IPC_INFO:
  533. case IPC_RMID:
  534. case IPC_SET:
  535. case SEM_INFO:
  536. case GETVAL:
  537. case GETPID:
  538. case GETNCNT:
  539. case GETZCNT:
  540. case GETALL:
  541. case SETVAL:
  542. case SETALL:
  543. err = sys_semctl (first, second, third, fourth);
  544. break;
  545. case IPC_STAT:
  546. case SEM_STAT:
  547. fourth.__pad = &s;
  548. old_fs = get_fs();
  549. set_fs(KERNEL_DS);
  550. err = sys_semctl(first, second, third | IPC_64, fourth);
  551. set_fs(old_fs);
  552. if (third & IPC_64) {
  553. struct semid64_ds32 *usp64 = (struct semid64_ds32 *) A(pad);
  554. if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) {
  555. err = -EFAULT;
  556. break;
  557. }
  558. err2 = __put_user(s.sem_perm.key, &usp64->sem_perm.key);
  559. err2 |= __put_user(s.sem_perm.uid, &usp64->sem_perm.uid);
  560. err2 |= __put_user(s.sem_perm.gid, &usp64->sem_perm.gid);
  561. err2 |= __put_user(s.sem_perm.cuid, &usp64->sem_perm.cuid);
  562. err2 |= __put_user(s.sem_perm.cgid, &usp64->sem_perm.cgid);
  563. err2 |= __put_user(s.sem_perm.mode, &usp64->sem_perm.mode);
  564. err2 |= __put_user(s.sem_perm.seq, &usp64->sem_perm.seq);
  565. err2 |= __put_user(s.sem_otime, &usp64->sem_otime);
  566. err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime);
  567. err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems);
  568. } else {
  569. struct semid_ds32 *usp32 = (struct semid_ds32 *) A(pad);
  570. if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) {
  571. err = -EFAULT;
  572. break;
  573. }
  574. err2 = __put_user(s.sem_perm.key, &usp32->sem_perm.key);
  575. err2 |= __put_user(s.sem_perm.uid, &usp32->sem_perm.uid);
  576. err2 |= __put_user(s.sem_perm.gid, &usp32->sem_perm.gid);
  577. err2 |= __put_user(s.sem_perm.cuid, &usp32->sem_perm.cuid);
  578. err2 |= __put_user(s.sem_perm.cgid, &usp32->sem_perm.cgid);
  579. err2 |= __put_user(s.sem_perm.mode, &usp32->sem_perm.mode);
  580. err2 |= __put_user(s.sem_perm.seq, &usp32->sem_perm.seq);
  581. err2 |= __put_user(s.sem_otime, &usp32->sem_otime);
  582. err2 |= __put_user(s.sem_ctime, &usp32->sem_ctime);
  583. err2 |= __put_user(s.sem_nsems, &usp32->sem_nsems);
  584. }
  585. if (err2)
  586. err = -EFAULT;
  587. break;
  588. default:
  589. err = - EINVAL;
  590. break;
  591. }
  592. return err;
  593. }
  594. static int
  595. do_sys32_msgsnd (int first, int second, int third, void *uptr)
  596. {
  597. struct msgbuf32 *up = (struct msgbuf32 *)uptr;
  598. struct msgbuf *p;
  599. mm_segment_t old_fs;
  600. int err;
  601. if (second < 0)
  602. return -EINVAL;
  603. p = kmalloc (second + sizeof (struct msgbuf)
  604. + 4, GFP_USER);
  605. if (!p)
  606. return -ENOMEM;
  607. err = get_user (p->mtype, &up->mtype);
  608. if (err)
  609. goto out;
  610. err |= __copy_from_user (p->mtext, &up->mtext, second);
  611. if (err)
  612. goto out;
  613. old_fs = get_fs ();
  614. set_fs (KERNEL_DS);
  615. err = sys_msgsnd (first, p, second, third);
  616. set_fs (old_fs);
  617. out:
  618. kfree (p);
  619. return err;
  620. }
  621. static int
  622. do_sys32_msgrcv (int first, int second, int msgtyp, int third,
  623. int version, void *uptr)
  624. {
  625. struct msgbuf32 *up;
  626. struct msgbuf *p;
  627. mm_segment_t old_fs;
  628. int err;
  629. if (!version) {
  630. struct ipc_kludge32 *uipck = (struct ipc_kludge32 *)uptr;
  631. struct ipc_kludge32 ipck;
  632. err = -EINVAL;
  633. if (!uptr)
  634. goto out;
  635. err = -EFAULT;
  636. if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32)))
  637. goto out;
  638. uptr = (void *)AA(ipck.msgp);
  639. msgtyp = ipck.msgtyp;
  640. }
  641. if (second < 0)
  642. return -EINVAL;
  643. err = -ENOMEM;
  644. p = kmalloc (second + sizeof (struct msgbuf) + 4, GFP_USER);
  645. if (!p)
  646. goto out;
  647. old_fs = get_fs ();
  648. set_fs (KERNEL_DS);
  649. err = sys_msgrcv (first, p, second + 4, msgtyp, third);
  650. set_fs (old_fs);
  651. if (err < 0)
  652. goto free_then_out;
  653. up = (struct msgbuf32 *)uptr;
  654. if (put_user (p->mtype, &up->mtype) ||
  655. __copy_to_user (&up->mtext, p->mtext, err))
  656. err = -EFAULT;
  657. free_then_out:
  658. kfree (p);
  659. out:
  660. return err;
  661. }
  662. static int
  663. do_sys32_msgctl (int first, int second, void *uptr)
  664. {
  665. int err = -EINVAL, err2;
  666. struct msqid64_ds m;
  667. struct msqid_ds32 *up32 = (struct msqid_ds32 *)uptr;
  668. struct msqid64_ds32 *up64 = (struct msqid64_ds32 *)uptr;
  669. mm_segment_t old_fs;
  670. switch (second & ~IPC_64) {
  671. case IPC_INFO:
  672. case IPC_RMID:
  673. case MSG_INFO:
  674. err = sys_msgctl (first, second, (struct msqid_ds *)uptr);
  675. break;
  676. case IPC_SET:
  677. if (second & IPC_64) {
  678. if (!access_ok(VERIFY_READ, up64, sizeof(*up64))) {
  679. err = -EFAULT;
  680. break;
  681. }
  682. err = __get_user(m.msg_perm.uid, &up64->msg_perm.uid);
  683. err |= __get_user(m.msg_perm.gid, &up64->msg_perm.gid);
  684. err |= __get_user(m.msg_perm.mode, &up64->msg_perm.mode);
  685. err |= __get_user(m.msg_qbytes, &up64->msg_qbytes);
  686. } else {
  687. if (!access_ok(VERIFY_READ, up32, sizeof(*up32))) {
  688. err = -EFAULT;
  689. break;
  690. }
  691. err = __get_user(m.msg_perm.uid, &up32->msg_perm.uid);
  692. err |= __get_user(m.msg_perm.gid, &up32->msg_perm.gid);
  693. err |= __get_user(m.msg_perm.mode, &up32->msg_perm.mode);
  694. err |= __get_user(m.msg_qbytes, &up32->msg_qbytes);
  695. }
  696. if (err)
  697. break;
  698. old_fs = get_fs();
  699. set_fs(KERNEL_DS);
  700. err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m);
  701. set_fs(old_fs);
  702. break;
  703. case IPC_STAT:
  704. case MSG_STAT:
  705. old_fs = get_fs();
  706. set_fs(KERNEL_DS);
  707. err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m);
  708. set_fs(old_fs);
  709. if (second & IPC_64) {
  710. if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) {
  711. err = -EFAULT;
  712. break;
  713. }
  714. err2 = __put_user(m.msg_perm.key, &up64->msg_perm.key);
  715. err2 |= __put_user(m.msg_perm.uid, &up64->msg_perm.uid);
  716. err2 |= __put_user(m.msg_perm.gid, &up64->msg_perm.gid);
  717. err2 |= __put_user(m.msg_perm.cuid, &up64->msg_perm.cuid);
  718. err2 |= __put_user(m.msg_perm.cgid, &up64->msg_perm.cgid);
  719. err2 |= __put_user(m.msg_perm.mode, &up64->msg_perm.mode);
  720. err2 |= __put_user(m.msg_perm.seq, &up64->msg_perm.seq);
  721. err2 |= __put_user(m.msg_stime, &up64->msg_stime);
  722. err2 |= __put_user(m.msg_rtime, &up64->msg_rtime);
  723. err2 |= __put_user(m.msg_ctime, &up64->msg_ctime);
  724. err2 |= __put_user(m.msg_cbytes, &up64->msg_cbytes);
  725. err2 |= __put_user(m.msg_qnum, &up64->msg_qnum);
  726. err2 |= __put_user(m.msg_qbytes, &up64->msg_qbytes);
  727. err2 |= __put_user(m.msg_lspid, &up64->msg_lspid);
  728. err2 |= __put_user(m.msg_lrpid, &up64->msg_lrpid);
  729. if (err2)
  730. err = -EFAULT;
  731. } else {
  732. if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) {
  733. err = -EFAULT;
  734. break;
  735. }
  736. err2 = __put_user(m.msg_perm.key, &up32->msg_perm.key);
  737. err2 |= __put_user(m.msg_perm.uid, &up32->msg_perm.uid);
  738. err2 |= __put_user(m.msg_perm.gid, &up32->msg_perm.gid);
  739. err2 |= __put_user(m.msg_perm.cuid, &up32->msg_perm.cuid);
  740. err2 |= __put_user(m.msg_perm.cgid, &up32->msg_perm.cgid);
  741. err2 |= __put_user(m.msg_perm.mode, &up32->msg_perm.mode);
  742. err2 |= __put_user(m.msg_perm.seq, &up32->msg_perm.seq);
  743. err2 |= __put_user(m.msg_stime, &up32->msg_stime);
  744. err2 |= __put_user(m.msg_rtime, &up32->msg_rtime);
  745. err2 |= __put_user(m.msg_ctime, &up32->msg_ctime);
  746. err2 |= __put_user(m.msg_cbytes, &up32->msg_cbytes);
  747. err2 |= __put_user(m.msg_qnum, &up32->msg_qnum);
  748. err2 |= __put_user(m.msg_qbytes, &up32->msg_qbytes);
  749. err2 |= __put_user(m.msg_lspid, &up32->msg_lspid);
  750. err2 |= __put_user(m.msg_lrpid, &up32->msg_lrpid);
  751. if (err2)
  752. err = -EFAULT;
  753. }
  754. break;
  755. }
  756. return err;
  757. }
  758. static int
  759. do_sys32_shmat (int first, int second, int third, int version, void *uptr)
  760. {
  761. unsigned long raddr;
  762. u32 *uaddr = (u32 *)A((u32)third);
  763. int err = -EINVAL;
  764. if (version == 1)
  765. return err;
  766. err = do_shmat (first, uptr, second, &raddr);
  767. if (err)
  768. return err;
  769. err = put_user (raddr, uaddr);
  770. return err;
  771. }
  772. struct shm_info32 {
  773. int used_ids;
  774. u32 shm_tot, shm_rss, shm_swp;
  775. u32 swap_attempts, swap_successes;
  776. };
  777. static int
  778. do_sys32_shmctl (int first, int second, void *uptr)
  779. {
  780. struct shmid64_ds32 *up64 = (struct shmid64_ds32 *)uptr;
  781. struct shmid_ds32 *up32 = (struct shmid_ds32 *)uptr;
  782. struct shm_info32 *uip = (struct shm_info32 *)uptr;
  783. int err = -EFAULT, err2;
  784. struct shmid64_ds s64;
  785. mm_segment_t old_fs;
  786. struct shm_info si;
  787. struct shmid_ds s;
  788. switch (second & ~IPC_64) {
  789. case IPC_INFO:
  790. second = IPC_INFO; /* So that we don't have to translate it */
  791. case IPC_RMID:
  792. case SHM_LOCK:
  793. case SHM_UNLOCK:
  794. err = sys_shmctl(first, second, (struct shmid_ds *)uptr);
  795. break;
  796. case IPC_SET:
  797. if (second & IPC_64) {
  798. err = get_user(s.shm_perm.uid, &up64->shm_perm.uid);
  799. err |= get_user(s.shm_perm.gid, &up64->shm_perm.gid);
  800. err |= get_user(s.shm_perm.mode, &up64->shm_perm.mode);
  801. } else {
  802. err = get_user(s.shm_perm.uid, &up32->shm_perm.uid);
  803. err |= get_user(s.shm_perm.gid, &up32->shm_perm.gid);
  804. err |= get_user(s.shm_perm.mode, &up32->shm_perm.mode);
  805. }
  806. if (err)
  807. break;
  808. old_fs = get_fs();
  809. set_fs(KERNEL_DS);
  810. err = sys_shmctl(first, second & ~IPC_64, &s);
  811. set_fs(old_fs);
  812. break;
  813. case IPC_STAT:
  814. case SHM_STAT:
  815. old_fs = get_fs();
  816. set_fs(KERNEL_DS);
  817. err = sys_shmctl(first, second | IPC_64, (void *) &s64);
  818. set_fs(old_fs);
  819. if (err < 0)
  820. break;
  821. if (second & IPC_64) {
  822. if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) {
  823. err = -EFAULT;
  824. break;
  825. }
  826. err2 = __put_user(s64.shm_perm.key, &up64->shm_perm.key);
  827. err2 |= __put_user(s64.shm_perm.uid, &up64->shm_perm.uid);
  828. err2 |= __put_user(s64.shm_perm.gid, &up64->shm_perm.gid);
  829. err2 |= __put_user(s64.shm_perm.cuid, &up64->shm_perm.cuid);
  830. err2 |= __put_user(s64.shm_perm.cgid, &up64->shm_perm.cgid);
  831. err2 |= __put_user(s64.shm_perm.mode, &up64->shm_perm.mode);
  832. err2 |= __put_user(s64.shm_perm.seq, &up64->shm_perm.seq);
  833. err2 |= __put_user(s64.shm_atime, &up64->shm_atime);
  834. err2 |= __put_user(s64.shm_dtime, &up64->shm_dtime);
  835. err2 |= __put_user(s64.shm_ctime, &up64->shm_ctime);
  836. err2 |= __put_user(s64.shm_segsz, &up64->shm_segsz);
  837. err2 |= __put_user(s64.shm_nattch, &up64->shm_nattch);
  838. err2 |= __put_user(s64.shm_cpid, &up64->shm_cpid);
  839. err2 |= __put_user(s64.shm_lpid, &up64->shm_lpid);
  840. } else {
  841. if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) {
  842. err = -EFAULT;
  843. break;
  844. }
  845. err2 = __put_user(s64.shm_perm.key, &up32->shm_perm.key);
  846. err2 |= __put_user(s64.shm_perm.uid, &up32->shm_perm.uid);
  847. err2 |= __put_user(s64.shm_perm.gid, &up32->shm_perm.gid);
  848. err2 |= __put_user(s64.shm_perm.cuid, &up32->shm_perm.cuid);
  849. err2 |= __put_user(s64.shm_perm.cgid, &up32->shm_perm.cgid);
  850. err2 |= __put_user(s64.shm_perm.mode, &up32->shm_perm.mode);
  851. err2 |= __put_user(s64.shm_perm.seq, &up32->shm_perm.seq);
  852. err2 |= __put_user(s64.shm_atime, &up32->shm_atime);
  853. err2 |= __put_user(s64.shm_dtime, &up32->shm_dtime);
  854. err2 |= __put_user(s64.shm_ctime, &up32->shm_ctime);
  855. err2 |= __put_user(s64.shm_segsz, &up32->shm_segsz);
  856. err2 |= __put_user(s64.shm_nattch, &up32->shm_nattch);
  857. err2 |= __put_user(s64.shm_cpid, &up32->shm_cpid);
  858. err2 |= __put_user(s64.shm_lpid, &up32->shm_lpid);
  859. }
  860. if (err2)
  861. err = -EFAULT;
  862. break;
  863. case SHM_INFO:
  864. old_fs = get_fs();
  865. set_fs(KERNEL_DS);
  866. err = sys_shmctl(first, second, (void *)&si);
  867. set_fs(old_fs);
  868. if (err < 0)
  869. break;
  870. err2 = put_user(si.used_ids, &uip->used_ids);
  871. err2 |= __put_user(si.shm_tot, &uip->shm_tot);
  872. err2 |= __put_user(si.shm_rss, &uip->shm_rss);
  873. err2 |= __put_user(si.shm_swp, &uip->shm_swp);
  874. err2 |= __put_user(si.swap_attempts, &uip->swap_attempts);
  875. err2 |= __put_user (si.swap_successes, &uip->swap_successes);
  876. if (err2)
  877. err = -EFAULT;
  878. break;
  879. default:
  880. err = -EINVAL;
  881. break;
  882. }
  883. return err;
  884. }
  885. static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems,
  886. const struct compat_timespec *timeout32)
  887. {
  888. struct compat_timespec t32;
  889. struct timespec *t64 = compat_alloc_user_space(sizeof(*t64));
  890. if (copy_from_user(&t32, timeout32, sizeof(t32)))
  891. return -EFAULT;
  892. if (put_user(t32.tv_sec, &t64->tv_sec) ||
  893. put_user(t32.tv_nsec, &t64->tv_nsec))
  894. return -EFAULT;
  895. return sys_semtimedop(semid, tsems, nsems, t64);
  896. }
  897. asmlinkage long
  898. sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth)
  899. {
  900. int version, err;
  901. version = call >> 16; /* hack for backward compatibility */
  902. call &= 0xffff;
  903. switch (call) {
  904. case SEMOP:
  905. /* struct sembuf is the same on 32 and 64bit :)) */
  906. err = sys_semtimedop (first, (struct sembuf *)AA(ptr), second,
  907. NULL);
  908. break;
  909. case SEMTIMEDOP:
  910. err = sys32_semtimedop (first, (struct sembuf *)AA(ptr), second,
  911. (const struct compat_timespec __user *)AA(fifth));
  912. break;
  913. case SEMGET:
  914. err = sys_semget (first, second, third);
  915. break;
  916. case SEMCTL:
  917. err = do_sys32_semctl (first, second, third,
  918. (void *)AA(ptr));
  919. break;
  920. case MSGSND:
  921. err = do_sys32_msgsnd (first, second, third,
  922. (void *)AA(ptr));
  923. break;
  924. case MSGRCV:
  925. err = do_sys32_msgrcv (first, second, fifth, third,
  926. version, (void *)AA(ptr));
  927. break;
  928. case MSGGET:
  929. err = sys_msgget ((key_t) first, second);
  930. break;
  931. case MSGCTL:
  932. err = do_sys32_msgctl (first, second, (void *)AA(ptr));
  933. break;
  934. case SHMAT:
  935. err = do_sys32_shmat (first, second, third,
  936. version, (void *)AA(ptr));
  937. break;
  938. case SHMDT:
  939. err = sys_shmdt ((char *)A(ptr));
  940. break;
  941. case SHMGET:
  942. err = sys_shmget (first, (unsigned)second, third);
  943. break;
  944. case SHMCTL:
  945. err = do_sys32_shmctl (first, second, (void *)AA(ptr));
  946. break;
  947. default:
  948. err = -EINVAL;
  949. break;
  950. }
  951. return err;
  952. }
  953. asmlinkage long sys32_shmat(int shmid, char __user *shmaddr,
  954. int shmflg, int32_t *addr)
  955. {
  956. unsigned long raddr;
  957. int err;
  958. err = do_shmat(shmid, shmaddr, shmflg, &raddr);
  959. if (err)
  960. return err;
  961. return put_user(raddr, addr);
  962. }
  963. struct sysctl_args32
  964. {
  965. compat_caddr_t name;
  966. int nlen;
  967. compat_caddr_t oldval;
  968. compat_caddr_t oldlenp;
  969. compat_caddr_t newval;
  970. compat_size_t newlen;
  971. unsigned int __unused[4];
  972. };
  973. #ifdef CONFIG_SYSCTL
  974. asmlinkage long sys32_sysctl(struct sysctl_args32 *args)
  975. {
  976. struct sysctl_args32 tmp;
  977. int error;
  978. size_t oldlen, *oldlenp = NULL;
  979. unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7;
  980. if (copy_from_user(&tmp, args, sizeof(tmp)))
  981. return -EFAULT;
  982. if (tmp.oldval && tmp.oldlenp) {
  983. /* Duh, this is ugly and might not work if sysctl_args
  984. is in read-only memory, but do_sysctl does indirectly
  985. a lot of uaccess in both directions and we'd have to
  986. basically copy the whole sysctl.c here, and
  987. glibc's __sysctl uses rw memory for the structure
  988. anyway. */
  989. if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) ||
  990. put_user(oldlen, (size_t *)addr))
  991. return -EFAULT;
  992. oldlenp = (size_t *)addr;
  993. }
  994. lock_kernel();
  995. error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval),
  996. oldlenp, (void *)A(tmp.newval), tmp.newlen);
  997. unlock_kernel();
  998. if (oldlenp) {
  999. if (!error) {
  1000. if (get_user(oldlen, (size_t *)addr) ||
  1001. put_user(oldlen, (u32 *)A(tmp.oldlenp)))
  1002. error = -EFAULT;
  1003. }
  1004. copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
  1005. }
  1006. return error;
  1007. }
  1008. #endif /* CONFIG_SYSCTL */
  1009. asmlinkage long sys32_newuname(struct new_utsname * name)
  1010. {
  1011. int ret = 0;
  1012. down_read(&uts_sem);
  1013. if (copy_to_user(name,&system_utsname,sizeof *name))
  1014. ret = -EFAULT;
  1015. up_read(&uts_sem);
  1016. if (current->personality == PER_LINUX32 && !ret)
  1017. if (copy_to_user(name->machine, "mips\0\0\0", 8))
  1018. ret = -EFAULT;
  1019. return ret;
  1020. }
  1021. asmlinkage int sys32_personality(unsigned long personality)
  1022. {
  1023. int ret;
  1024. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  1025. personality = PER_LINUX32;
  1026. ret = sys_personality(personality);
  1027. if (ret == PER_LINUX32)
  1028. ret = PER_LINUX;
  1029. return ret;
  1030. }
  1031. /* ustat compatibility */
  1032. struct ustat32 {
  1033. compat_daddr_t f_tfree;
  1034. compat_ino_t f_tinode;
  1035. char f_fname[6];
  1036. char f_fpack[6];
  1037. };
  1038. extern asmlinkage long sys_ustat(dev_t dev, struct ustat * ubuf);
  1039. asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32)
  1040. {
  1041. int err;
  1042. struct ustat tmp;
  1043. struct ustat32 tmp32;
  1044. mm_segment_t old_fs = get_fs();
  1045. set_fs(KERNEL_DS);
  1046. err = sys_ustat(dev, &tmp);
  1047. set_fs (old_fs);
  1048. if (err)
  1049. goto out;
  1050. memset(&tmp32,0,sizeof(struct ustat32));
  1051. tmp32.f_tfree = tmp.f_tfree;
  1052. tmp32.f_tinode = tmp.f_tinode;
  1053. err = copy_to_user(ubuf32,&tmp32,sizeof(struct ustat32)) ? -EFAULT : 0;
  1054. out:
  1055. return err;
  1056. }
  1057. /* Handle adjtimex compatibility. */
  1058. struct timex32 {
  1059. u32 modes;
  1060. s32 offset, freq, maxerror, esterror;
  1061. s32 status, constant, precision, tolerance;
  1062. struct compat_timeval time;
  1063. s32 tick;
  1064. s32 ppsfreq, jitter, shift, stabil;
  1065. s32 jitcnt, calcnt, errcnt, stbcnt;
  1066. s32 :32; s32 :32; s32 :32; s32 :32;
  1067. s32 :32; s32 :32; s32 :32; s32 :32;
  1068. s32 :32; s32 :32; s32 :32; s32 :32;
  1069. };
  1070. extern int do_adjtimex(struct timex *);
  1071. asmlinkage int sys32_adjtimex(struct timex32 *utp)
  1072. {
  1073. struct timex txc;
  1074. int ret;
  1075. memset(&txc, 0, sizeof(struct timex));
  1076. if (get_user(txc.modes, &utp->modes) ||
  1077. __get_user(txc.offset, &utp->offset) ||
  1078. __get_user(txc.freq, &utp->freq) ||
  1079. __get_user(txc.maxerror, &utp->maxerror) ||
  1080. __get_user(txc.esterror, &utp->esterror) ||
  1081. __get_user(txc.status, &utp->status) ||
  1082. __get_user(txc.constant, &utp->constant) ||
  1083. __get_user(txc.precision, &utp->precision) ||
  1084. __get_user(txc.tolerance, &utp->tolerance) ||
  1085. __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  1086. __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  1087. __get_user(txc.tick, &utp->tick) ||
  1088. __get_user(txc.ppsfreq, &utp->ppsfreq) ||
  1089. __get_user(txc.jitter, &utp->jitter) ||
  1090. __get_user(txc.shift, &utp->shift) ||
  1091. __get_user(txc.stabil, &utp->stabil) ||
  1092. __get_user(txc.jitcnt, &utp->jitcnt) ||
  1093. __get_user(txc.calcnt, &utp->calcnt) ||
  1094. __get_user(txc.errcnt, &utp->errcnt) ||
  1095. __get_user(txc.stbcnt, &utp->stbcnt))
  1096. return -EFAULT;
  1097. ret = do_adjtimex(&txc);
  1098. if (put_user(txc.modes, &utp->modes) ||
  1099. __put_user(txc.offset, &utp->offset) ||
  1100. __put_user(txc.freq, &utp->freq) ||
  1101. __put_user(txc.maxerror, &utp->maxerror) ||
  1102. __put_user(txc.esterror, &utp->esterror) ||
  1103. __put_user(txc.status, &utp->status) ||
  1104. __put_user(txc.constant, &utp->constant) ||
  1105. __put_user(txc.precision, &utp->precision) ||
  1106. __put_user(txc.tolerance, &utp->tolerance) ||
  1107. __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  1108. __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  1109. __put_user(txc.tick, &utp->tick) ||
  1110. __put_user(txc.ppsfreq, &utp->ppsfreq) ||
  1111. __put_user(txc.jitter, &utp->jitter) ||
  1112. __put_user(txc.shift, &utp->shift) ||
  1113. __put_user(txc.stabil, &utp->stabil) ||
  1114. __put_user(txc.jitcnt, &utp->jitcnt) ||
  1115. __put_user(txc.calcnt, &utp->calcnt) ||
  1116. __put_user(txc.errcnt, &utp->errcnt) ||
  1117. __put_user(txc.stbcnt, &utp->stbcnt))
  1118. ret = -EFAULT;
  1119. return ret;
  1120. }
  1121. asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset,
  1122. s32 count)
  1123. {
  1124. mm_segment_t old_fs = get_fs();
  1125. int ret;
  1126. off_t of;
  1127. if (offset && get_user(of, offset))
  1128. return -EFAULT;
  1129. set_fs(KERNEL_DS);
  1130. ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
  1131. set_fs(old_fs);
  1132. if (offset && put_user(of, offset))
  1133. return -EFAULT;
  1134. return ret;
  1135. }
  1136. asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
  1137. size_t count)
  1138. {
  1139. return sys_readahead(fd, merge_64(a2, a3), count);
  1140. }
  1141. /* Argument list sizes for sys_socketcall */
  1142. #define AL(x) ((x) * sizeof(unsigned int))
  1143. static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
  1144. AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
  1145. AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
  1146. #undef AL
  1147. /*
  1148. * System call vectors.
  1149. *
  1150. * Argument checking cleaned up. Saved 20% in size.
  1151. * This function doesn't need to set the kernel lock because
  1152. * it is set by the callees.
  1153. */
  1154. asmlinkage long sys32_socketcall(int call, unsigned int *args32)
  1155. {
  1156. unsigned int a[6];
  1157. unsigned int a0,a1;
  1158. int err;
  1159. extern asmlinkage long sys_socket(int family, int type, int protocol);
  1160. extern asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen);
  1161. extern asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen);
  1162. extern asmlinkage long sys_listen(int fd, int backlog);
  1163. extern asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen);
  1164. extern asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len);
  1165. extern asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len);
  1166. extern asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec);
  1167. extern asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags);
  1168. extern asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags,
  1169. struct sockaddr __user *addr, int addr_len);
  1170. extern asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags);
  1171. extern asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags,
  1172. struct sockaddr __user *addr, int __user *addr_len);
  1173. extern asmlinkage long sys_shutdown(int fd, int how);
  1174. extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen);
  1175. extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int *optlen);
  1176. extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
  1177. extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags);
  1178. if(call<1||call>SYS_RECVMSG)
  1179. return -EINVAL;
  1180. /* copy_from_user should be SMP safe. */
  1181. if (copy_from_user(a, args32, socketcall_nargs[call]))
  1182. return -EFAULT;
  1183. a0=a[0];
  1184. a1=a[1];
  1185. switch(call)
  1186. {
  1187. case SYS_SOCKET:
  1188. err = sys_socket(a0,a1,a[2]);
  1189. break;
  1190. case SYS_BIND:
  1191. err = sys_bind(a0,(struct sockaddr __user *)A(a1), a[2]);
  1192. break;
  1193. case SYS_CONNECT:
  1194. err = sys_connect(a0, (struct sockaddr __user *)A(a1), a[2]);
  1195. break;
  1196. case SYS_LISTEN:
  1197. err = sys_listen(a0,a1);
  1198. break;
  1199. case SYS_ACCEPT:
  1200. err = sys_accept(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
  1201. break;
  1202. case SYS_GETSOCKNAME:
  1203. err = sys_getsockname(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
  1204. break;
  1205. case SYS_GETPEERNAME:
  1206. err = sys_getpeername(a0, (struct sockaddr __user *)A(a1), (int __user *)A(a[2]));
  1207. break;
  1208. case SYS_SOCKETPAIR:
  1209. err = sys_socketpair(a0,a1, a[2], (int __user *)A(a[3]));
  1210. break;
  1211. case SYS_SEND:
  1212. err = sys_send(a0, (void __user *)A(a1), a[2], a[3]);
  1213. break;
  1214. case SYS_SENDTO:
  1215. err = sys_sendto(a0,(void __user *)A(a1), a[2], a[3],
  1216. (struct sockaddr __user *)A(a[4]), a[5]);
  1217. break;
  1218. case SYS_RECV:
  1219. err = sys_recv(a0, (void __user *)A(a1), a[2], a[3]);
  1220. break;
  1221. case SYS_RECVFROM:
  1222. err = sys_recvfrom(a0, (void __user *)A(a1), a[2], a[3],
  1223. (struct sockaddr __user *)A(a[4]), (int __user *)A(a[5]));
  1224. break;
  1225. case SYS_SHUTDOWN:
  1226. err = sys_shutdown(a0,a1);
  1227. break;
  1228. case SYS_SETSOCKOPT:
  1229. err = sys_setsockopt(a0, a1, a[2], (char __user *)A(a[3]), a[4]);
  1230. break;
  1231. case SYS_GETSOCKOPT:
  1232. err = sys_getsockopt(a0, a1, a[2], (char __user *)A(a[3]), (int __user *)A(a[4]));
  1233. break;
  1234. case SYS_SENDMSG:
  1235. err = sys_sendmsg(a0, (struct msghdr __user *) A(a1), a[2]);
  1236. break;
  1237. case SYS_RECVMSG:
  1238. err = sys_recvmsg(a0, (struct msghdr __user *) A(a1), a[2]);
  1239. break;
  1240. default:
  1241. err = -EINVAL;
  1242. break;
  1243. }
  1244. return err;
  1245. }