osf_sys.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. /*
  2. * linux/arch/alpha/kernel/osf_sys.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. */
  6. /*
  7. * This file handles some of the stranger OSF/1 system call interfaces.
  8. * Some of the system calls expect a non-C calling standard, others have
  9. * special parameter blocks..
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/sched.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/smp.h>
  16. #include <linux/stddef.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/unistd.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/user.h>
  21. #include <linux/utsname.h>
  22. #include <linux/time.h>
  23. #include <linux/timex.h>
  24. #include <linux/major.h>
  25. #include <linux/stat.h>
  26. #include <linux/mman.h>
  27. #include <linux/shm.h>
  28. #include <linux/poll.h>
  29. #include <linux/file.h>
  30. #include <linux/types.h>
  31. #include <linux/ipc.h>
  32. #include <linux/namei.h>
  33. #include <linux/uio.h>
  34. #include <linux/vfs.h>
  35. #include <linux/rcupdate.h>
  36. #include <linux/slab.h>
  37. #include <asm/fpu.h>
  38. #include <asm/io.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/sysinfo.h>
  41. #include <asm/thread_info.h>
  42. #include <asm/hwrpb.h>
  43. #include <asm/processor.h>
  44. /*
  45. * Brk needs to return an error. Still support Linux's brk(0) query idiom,
  46. * which OSF programs just shouldn't be doing. We're still not quite
  47. * identical to OSF as we don't return 0 on success, but doing otherwise
  48. * would require changes to libc. Hopefully this is good enough.
  49. */
  50. SYSCALL_DEFINE1(osf_brk, unsigned long, brk)
  51. {
  52. unsigned long retval = sys_brk(brk);
  53. if (brk && brk != retval)
  54. retval = -ENOMEM;
  55. return retval;
  56. }
  57. /*
  58. * This is pure guess-work..
  59. */
  60. SYSCALL_DEFINE4(osf_set_program_attributes, unsigned long, text_start,
  61. unsigned long, text_len, unsigned long, bss_start,
  62. unsigned long, bss_len)
  63. {
  64. struct mm_struct *mm;
  65. mm = current->mm;
  66. mm->end_code = bss_start + bss_len;
  67. mm->start_brk = bss_start + bss_len;
  68. mm->brk = bss_start + bss_len;
  69. #if 0
  70. printk("set_program_attributes(%lx %lx %lx %lx)\n",
  71. text_start, text_len, bss_start, bss_len);
  72. #endif
  73. return 0;
  74. }
  75. /*
  76. * OSF/1 directory handling functions...
  77. *
  78. * The "getdents()" interface is much more sane: the "basep" stuff is
  79. * braindamage (it can't really handle filesystems where the directory
  80. * offset differences aren't the same as "d_reclen").
  81. */
  82. #define NAME_OFFSET offsetof (struct osf_dirent, d_name)
  83. struct osf_dirent {
  84. unsigned int d_ino;
  85. unsigned short d_reclen;
  86. unsigned short d_namlen;
  87. char d_name[1];
  88. };
  89. struct osf_dirent_callback {
  90. struct dir_context ctx;
  91. struct osf_dirent __user *dirent;
  92. long __user *basep;
  93. unsigned int count;
  94. int error;
  95. };
  96. static int
  97. osf_filldir(struct dir_context *ctx, const char *name, int namlen,
  98. loff_t offset, u64 ino, unsigned int d_type)
  99. {
  100. struct osf_dirent __user *dirent;
  101. struct osf_dirent_callback *buf =
  102. container_of(ctx, struct osf_dirent_callback, ctx);
  103. unsigned int reclen = ALIGN(NAME_OFFSET + namlen + 1, sizeof(u32));
  104. unsigned int d_ino;
  105. buf->error = -EINVAL; /* only used if we fail */
  106. if (reclen > buf->count)
  107. return -EINVAL;
  108. d_ino = ino;
  109. if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
  110. buf->error = -EOVERFLOW;
  111. return -EOVERFLOW;
  112. }
  113. if (buf->basep) {
  114. if (put_user(offset, buf->basep))
  115. goto Efault;
  116. buf->basep = NULL;
  117. }
  118. dirent = buf->dirent;
  119. if (put_user(d_ino, &dirent->d_ino) ||
  120. put_user(namlen, &dirent->d_namlen) ||
  121. put_user(reclen, &dirent->d_reclen) ||
  122. copy_to_user(dirent->d_name, name, namlen) ||
  123. put_user(0, dirent->d_name + namlen))
  124. goto Efault;
  125. dirent = (void __user *)dirent + reclen;
  126. buf->dirent = dirent;
  127. buf->count -= reclen;
  128. return 0;
  129. Efault:
  130. buf->error = -EFAULT;
  131. return -EFAULT;
  132. }
  133. SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
  134. struct osf_dirent __user *, dirent, unsigned int, count,
  135. long __user *, basep)
  136. {
  137. int error;
  138. struct fd arg = fdget_pos(fd);
  139. struct osf_dirent_callback buf = {
  140. .ctx.actor = osf_filldir,
  141. .dirent = dirent,
  142. .basep = basep,
  143. .count = count
  144. };
  145. if (!arg.file)
  146. return -EBADF;
  147. error = iterate_dir(arg.file, &buf.ctx);
  148. if (error >= 0)
  149. error = buf.error;
  150. if (count != buf.count)
  151. error = count - buf.count;
  152. fdput_pos(arg);
  153. return error;
  154. }
  155. #undef NAME_OFFSET
  156. SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len,
  157. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  158. unsigned long, off)
  159. {
  160. unsigned long ret = -EINVAL;
  161. #if 0
  162. if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
  163. printk("%s: unimplemented OSF mmap flags %04lx\n",
  164. current->comm, flags);
  165. #endif
  166. if ((off + PAGE_ALIGN(len)) < off)
  167. goto out;
  168. if (off & ~PAGE_MASK)
  169. goto out;
  170. ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  171. out:
  172. return ret;
  173. }
  174. struct osf_stat {
  175. int st_dev;
  176. int st_pad1;
  177. unsigned st_mode;
  178. unsigned short st_nlink;
  179. short st_nlink_reserved;
  180. unsigned st_uid;
  181. unsigned st_gid;
  182. int st_rdev;
  183. int st_ldev;
  184. long st_size;
  185. int st_pad2;
  186. int st_uatime;
  187. int st_pad3;
  188. int st_umtime;
  189. int st_pad4;
  190. int st_uctime;
  191. int st_pad5;
  192. int st_pad6;
  193. unsigned st_flags;
  194. unsigned st_gen;
  195. long st_spare[4];
  196. unsigned st_ino;
  197. int st_ino_reserved;
  198. int st_atime;
  199. int st_atime_reserved;
  200. int st_mtime;
  201. int st_mtime_reserved;
  202. int st_ctime;
  203. int st_ctime_reserved;
  204. long st_blksize;
  205. long st_blocks;
  206. };
  207. /*
  208. * The OSF/1 statfs structure is much larger, but this should
  209. * match the beginning, at least.
  210. */
  211. struct osf_statfs {
  212. short f_type;
  213. short f_flags;
  214. int f_fsize;
  215. int f_bsize;
  216. int f_blocks;
  217. int f_bfree;
  218. int f_bavail;
  219. int f_files;
  220. int f_ffree;
  221. __kernel_fsid_t f_fsid;
  222. };
  223. struct osf_statfs64 {
  224. short f_type;
  225. short f_flags;
  226. int f_pad1;
  227. int f_pad2;
  228. int f_pad3;
  229. int f_pad4;
  230. int f_pad5;
  231. int f_pad6;
  232. int f_pad7;
  233. __kernel_fsid_t f_fsid;
  234. u_short f_namemax;
  235. short f_reserved1;
  236. int f_spare[8];
  237. char f_pad8[90];
  238. char f_pad9[90];
  239. long mount_info[10];
  240. u_long f_flags2;
  241. long f_spare2[14];
  242. long f_fsize;
  243. long f_bsize;
  244. long f_blocks;
  245. long f_bfree;
  246. long f_bavail;
  247. long f_files;
  248. long f_ffree;
  249. };
  250. static int
  251. linux_to_osf_stat(struct kstat *lstat, struct osf_stat __user *osf_stat)
  252. {
  253. struct osf_stat tmp = { 0 };
  254. tmp.st_dev = lstat->dev;
  255. tmp.st_mode = lstat->mode;
  256. tmp.st_nlink = lstat->nlink;
  257. tmp.st_uid = from_kuid_munged(current_user_ns(), lstat->uid);
  258. tmp.st_gid = from_kgid_munged(current_user_ns(), lstat->gid);
  259. tmp.st_rdev = lstat->rdev;
  260. tmp.st_ldev = lstat->rdev;
  261. tmp.st_size = lstat->size;
  262. tmp.st_uatime = lstat->atime.tv_nsec / 1000;
  263. tmp.st_umtime = lstat->mtime.tv_nsec / 1000;
  264. tmp.st_uctime = lstat->ctime.tv_nsec / 1000;
  265. tmp.st_ino = lstat->ino;
  266. tmp.st_atime = lstat->atime.tv_sec;
  267. tmp.st_mtime = lstat->mtime.tv_sec;
  268. tmp.st_ctime = lstat->ctime.tv_sec;
  269. tmp.st_blksize = lstat->blksize;
  270. tmp.st_blocks = lstat->blocks;
  271. return copy_to_user(osf_stat, &tmp, sizeof(tmp)) ? -EFAULT : 0;
  272. }
  273. static int
  274. linux_to_osf_statfs(struct kstatfs *linux_stat, struct osf_statfs __user *osf_stat,
  275. unsigned long bufsiz)
  276. {
  277. struct osf_statfs tmp_stat;
  278. tmp_stat.f_type = linux_stat->f_type;
  279. tmp_stat.f_flags = 0; /* mount flags */
  280. tmp_stat.f_fsize = linux_stat->f_frsize;
  281. tmp_stat.f_bsize = linux_stat->f_bsize;
  282. tmp_stat.f_blocks = linux_stat->f_blocks;
  283. tmp_stat.f_bfree = linux_stat->f_bfree;
  284. tmp_stat.f_bavail = linux_stat->f_bavail;
  285. tmp_stat.f_files = linux_stat->f_files;
  286. tmp_stat.f_ffree = linux_stat->f_ffree;
  287. tmp_stat.f_fsid = linux_stat->f_fsid;
  288. if (bufsiz > sizeof(tmp_stat))
  289. bufsiz = sizeof(tmp_stat);
  290. return copy_to_user(osf_stat, &tmp_stat, bufsiz) ? -EFAULT : 0;
  291. }
  292. static int
  293. linux_to_osf_statfs64(struct kstatfs *linux_stat, struct osf_statfs64 __user *osf_stat,
  294. unsigned long bufsiz)
  295. {
  296. struct osf_statfs64 tmp_stat = { 0 };
  297. tmp_stat.f_type = linux_stat->f_type;
  298. tmp_stat.f_fsize = linux_stat->f_frsize;
  299. tmp_stat.f_bsize = linux_stat->f_bsize;
  300. tmp_stat.f_blocks = linux_stat->f_blocks;
  301. tmp_stat.f_bfree = linux_stat->f_bfree;
  302. tmp_stat.f_bavail = linux_stat->f_bavail;
  303. tmp_stat.f_files = linux_stat->f_files;
  304. tmp_stat.f_ffree = linux_stat->f_ffree;
  305. tmp_stat.f_fsid = linux_stat->f_fsid;
  306. if (bufsiz > sizeof(tmp_stat))
  307. bufsiz = sizeof(tmp_stat);
  308. return copy_to_user(osf_stat, &tmp_stat, bufsiz) ? -EFAULT : 0;
  309. }
  310. SYSCALL_DEFINE3(osf_statfs, const char __user *, pathname,
  311. struct osf_statfs __user *, buffer, unsigned long, bufsiz)
  312. {
  313. struct kstatfs linux_stat;
  314. int error = user_statfs(pathname, &linux_stat);
  315. if (!error)
  316. error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
  317. return error;
  318. }
  319. SYSCALL_DEFINE2(osf_stat, char __user *, name, struct osf_stat __user *, buf)
  320. {
  321. struct kstat stat;
  322. int error;
  323. error = vfs_stat(name, &stat);
  324. if (error)
  325. return error;
  326. return linux_to_osf_stat(&stat, buf);
  327. }
  328. SYSCALL_DEFINE2(osf_lstat, char __user *, name, struct osf_stat __user *, buf)
  329. {
  330. struct kstat stat;
  331. int error;
  332. error = vfs_lstat(name, &stat);
  333. if (error)
  334. return error;
  335. return linux_to_osf_stat(&stat, buf);
  336. }
  337. SYSCALL_DEFINE2(osf_fstat, int, fd, struct osf_stat __user *, buf)
  338. {
  339. struct kstat stat;
  340. int error;
  341. error = vfs_fstat(fd, &stat);
  342. if (error)
  343. return error;
  344. return linux_to_osf_stat(&stat, buf);
  345. }
  346. SYSCALL_DEFINE3(osf_fstatfs, unsigned long, fd,
  347. struct osf_statfs __user *, buffer, unsigned long, bufsiz)
  348. {
  349. struct kstatfs linux_stat;
  350. int error = fd_statfs(fd, &linux_stat);
  351. if (!error)
  352. error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
  353. return error;
  354. }
  355. SYSCALL_DEFINE3(osf_statfs64, char __user *, pathname,
  356. struct osf_statfs64 __user *, buffer, unsigned long, bufsiz)
  357. {
  358. struct kstatfs linux_stat;
  359. int error = user_statfs(pathname, &linux_stat);
  360. if (!error)
  361. error = linux_to_osf_statfs64(&linux_stat, buffer, bufsiz);
  362. return error;
  363. }
  364. SYSCALL_DEFINE3(osf_fstatfs64, unsigned long, fd,
  365. struct osf_statfs64 __user *, buffer, unsigned long, bufsiz)
  366. {
  367. struct kstatfs linux_stat;
  368. int error = fd_statfs(fd, &linux_stat);
  369. if (!error)
  370. error = linux_to_osf_statfs64(&linux_stat, buffer, bufsiz);
  371. return error;
  372. }
  373. /*
  374. * Uhh.. OSF/1 mount parameters aren't exactly obvious..
  375. *
  376. * Although to be frank, neither are the native Linux/i386 ones..
  377. */
  378. struct ufs_args {
  379. char __user *devname;
  380. int flags;
  381. uid_t exroot;
  382. };
  383. struct cdfs_args {
  384. char __user *devname;
  385. int flags;
  386. uid_t exroot;
  387. /* This has lots more here, which Linux handles with the option block
  388. but I'm too lazy to do the translation into ASCII. */
  389. };
  390. struct procfs_args {
  391. char __user *devname;
  392. int flags;
  393. uid_t exroot;
  394. };
  395. /*
  396. * We can't actually handle ufs yet, so we translate UFS mounts to
  397. * ext2fs mounts. I wouldn't mind a UFS filesystem, but the UFS
  398. * layout is so braindead it's a major headache doing it.
  399. *
  400. * Just how long ago was it written? OTOH our UFS driver may be still
  401. * unhappy with OSF UFS. [CHECKME]
  402. */
  403. static int
  404. osf_ufs_mount(const char __user *dirname,
  405. struct ufs_args __user *args, int flags)
  406. {
  407. int retval;
  408. struct cdfs_args tmp;
  409. struct filename *devname;
  410. retval = -EFAULT;
  411. if (copy_from_user(&tmp, args, sizeof(tmp)))
  412. goto out;
  413. devname = getname(tmp.devname);
  414. retval = PTR_ERR(devname);
  415. if (IS_ERR(devname))
  416. goto out;
  417. retval = do_mount(devname->name, dirname, "ext2", flags, NULL);
  418. putname(devname);
  419. out:
  420. return retval;
  421. }
  422. static int
  423. osf_cdfs_mount(const char __user *dirname,
  424. struct cdfs_args __user *args, int flags)
  425. {
  426. int retval;
  427. struct cdfs_args tmp;
  428. struct filename *devname;
  429. retval = -EFAULT;
  430. if (copy_from_user(&tmp, args, sizeof(tmp)))
  431. goto out;
  432. devname = getname(tmp.devname);
  433. retval = PTR_ERR(devname);
  434. if (IS_ERR(devname))
  435. goto out;
  436. retval = do_mount(devname->name, dirname, "iso9660", flags, NULL);
  437. putname(devname);
  438. out:
  439. return retval;
  440. }
  441. static int
  442. osf_procfs_mount(const char __user *dirname,
  443. struct procfs_args __user *args, int flags)
  444. {
  445. struct procfs_args tmp;
  446. if (copy_from_user(&tmp, args, sizeof(tmp)))
  447. return -EFAULT;
  448. return do_mount("", dirname, "proc", flags, NULL);
  449. }
  450. SYSCALL_DEFINE4(osf_mount, unsigned long, typenr, const char __user *, path,
  451. int, flag, void __user *, data)
  452. {
  453. int retval;
  454. switch (typenr) {
  455. case 1:
  456. retval = osf_ufs_mount(path, data, flag);
  457. break;
  458. case 6:
  459. retval = osf_cdfs_mount(path, data, flag);
  460. break;
  461. case 9:
  462. retval = osf_procfs_mount(path, data, flag);
  463. break;
  464. default:
  465. retval = -EINVAL;
  466. printk("osf_mount(%ld, %x)\n", typenr, flag);
  467. }
  468. return retval;
  469. }
  470. SYSCALL_DEFINE1(osf_utsname, char __user *, name)
  471. {
  472. int error;
  473. down_read(&uts_sem);
  474. error = -EFAULT;
  475. if (copy_to_user(name + 0, utsname()->sysname, 32))
  476. goto out;
  477. if (copy_to_user(name + 32, utsname()->nodename, 32))
  478. goto out;
  479. if (copy_to_user(name + 64, utsname()->release, 32))
  480. goto out;
  481. if (copy_to_user(name + 96, utsname()->version, 32))
  482. goto out;
  483. if (copy_to_user(name + 128, utsname()->machine, 32))
  484. goto out;
  485. error = 0;
  486. out:
  487. up_read(&uts_sem);
  488. return error;
  489. }
  490. SYSCALL_DEFINE0(getpagesize)
  491. {
  492. return PAGE_SIZE;
  493. }
  494. SYSCALL_DEFINE0(getdtablesize)
  495. {
  496. return sysctl_nr_open;
  497. }
  498. /*
  499. * For compatibility with OSF/1 only. Use utsname(2) instead.
  500. */
  501. SYSCALL_DEFINE2(osf_getdomainname, char __user *, name, int, namelen)
  502. {
  503. unsigned len;
  504. int i;
  505. if (!access_ok(VERIFY_WRITE, name, namelen))
  506. return -EFAULT;
  507. len = namelen;
  508. if (len > 32)
  509. len = 32;
  510. down_read(&uts_sem);
  511. for (i = 0; i < len; ++i) {
  512. __put_user(utsname()->domainname[i], name + i);
  513. if (utsname()->domainname[i] == '\0')
  514. break;
  515. }
  516. up_read(&uts_sem);
  517. return 0;
  518. }
  519. /*
  520. * The following stuff should move into a header file should it ever
  521. * be labeled "officially supported." Right now, there is just enough
  522. * support to avoid applications (such as tar) printing error
  523. * messages. The attributes are not really implemented.
  524. */
  525. /*
  526. * Values for Property list entry flag
  527. */
  528. #define PLE_PROPAGATE_ON_COPY 0x1 /* cp(1) will copy entry
  529. by default */
  530. #define PLE_FLAG_MASK 0x1 /* Valid flag values */
  531. #define PLE_FLAG_ALL -1 /* All flag value */
  532. struct proplistname_args {
  533. unsigned int pl_mask;
  534. unsigned int pl_numnames;
  535. char **pl_names;
  536. };
  537. union pl_args {
  538. struct setargs {
  539. char __user *path;
  540. long follow;
  541. long nbytes;
  542. char __user *buf;
  543. } set;
  544. struct fsetargs {
  545. long fd;
  546. long nbytes;
  547. char __user *buf;
  548. } fset;
  549. struct getargs {
  550. char __user *path;
  551. long follow;
  552. struct proplistname_args __user *name_args;
  553. long nbytes;
  554. char __user *buf;
  555. int __user *min_buf_size;
  556. } get;
  557. struct fgetargs {
  558. long fd;
  559. struct proplistname_args __user *name_args;
  560. long nbytes;
  561. char __user *buf;
  562. int __user *min_buf_size;
  563. } fget;
  564. struct delargs {
  565. char __user *path;
  566. long follow;
  567. struct proplistname_args __user *name_args;
  568. } del;
  569. struct fdelargs {
  570. long fd;
  571. struct proplistname_args __user *name_args;
  572. } fdel;
  573. };
  574. enum pl_code {
  575. PL_SET = 1, PL_FSET = 2,
  576. PL_GET = 3, PL_FGET = 4,
  577. PL_DEL = 5, PL_FDEL = 6
  578. };
  579. SYSCALL_DEFINE2(osf_proplist_syscall, enum pl_code, code,
  580. union pl_args __user *, args)
  581. {
  582. long error;
  583. int __user *min_buf_size_ptr;
  584. switch (code) {
  585. case PL_SET:
  586. if (get_user(error, &args->set.nbytes))
  587. error = -EFAULT;
  588. break;
  589. case PL_FSET:
  590. if (get_user(error, &args->fset.nbytes))
  591. error = -EFAULT;
  592. break;
  593. case PL_GET:
  594. error = get_user(min_buf_size_ptr, &args->get.min_buf_size);
  595. if (error)
  596. break;
  597. error = put_user(0, min_buf_size_ptr);
  598. break;
  599. case PL_FGET:
  600. error = get_user(min_buf_size_ptr, &args->fget.min_buf_size);
  601. if (error)
  602. break;
  603. error = put_user(0, min_buf_size_ptr);
  604. break;
  605. case PL_DEL:
  606. case PL_FDEL:
  607. error = 0;
  608. break;
  609. default:
  610. error = -EOPNOTSUPP;
  611. break;
  612. };
  613. return error;
  614. }
  615. SYSCALL_DEFINE2(osf_sigstack, struct sigstack __user *, uss,
  616. struct sigstack __user *, uoss)
  617. {
  618. unsigned long usp = rdusp();
  619. unsigned long oss_sp = current->sas_ss_sp + current->sas_ss_size;
  620. unsigned long oss_os = on_sig_stack(usp);
  621. int error;
  622. if (uss) {
  623. void __user *ss_sp;
  624. error = -EFAULT;
  625. if (get_user(ss_sp, &uss->ss_sp))
  626. goto out;
  627. /* If the current stack was set with sigaltstack, don't
  628. swap stacks while we are on it. */
  629. error = -EPERM;
  630. if (current->sas_ss_sp && on_sig_stack(usp))
  631. goto out;
  632. /* Since we don't know the extent of the stack, and we don't
  633. track onstack-ness, but rather calculate it, we must
  634. presume a size. Ho hum this interface is lossy. */
  635. current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
  636. current->sas_ss_size = SIGSTKSZ;
  637. }
  638. if (uoss) {
  639. error = -EFAULT;
  640. if (! access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))
  641. || __put_user(oss_sp, &uoss->ss_sp)
  642. || __put_user(oss_os, &uoss->ss_onstack))
  643. goto out;
  644. }
  645. error = 0;
  646. out:
  647. return error;
  648. }
  649. SYSCALL_DEFINE3(osf_sysinfo, int, command, char __user *, buf, long, count)
  650. {
  651. const char *sysinfo_table[] = {
  652. utsname()->sysname,
  653. utsname()->nodename,
  654. utsname()->release,
  655. utsname()->version,
  656. utsname()->machine,
  657. "alpha", /* instruction set architecture */
  658. "dummy", /* hardware serial number */
  659. "dummy", /* hardware manufacturer */
  660. "dummy", /* secure RPC domain */
  661. };
  662. unsigned long offset;
  663. const char *res;
  664. long len, err = -EINVAL;
  665. offset = command-1;
  666. if (offset >= ARRAY_SIZE(sysinfo_table)) {
  667. /* Digital UNIX has a few unpublished interfaces here */
  668. printk("sysinfo(%d)", command);
  669. goto out;
  670. }
  671. down_read(&uts_sem);
  672. res = sysinfo_table[offset];
  673. len = strlen(res)+1;
  674. if ((unsigned long)len > (unsigned long)count)
  675. len = count;
  676. if (copy_to_user(buf, res, len))
  677. err = -EFAULT;
  678. else
  679. err = 0;
  680. up_read(&uts_sem);
  681. out:
  682. return err;
  683. }
  684. SYSCALL_DEFINE5(osf_getsysinfo, unsigned long, op, void __user *, buffer,
  685. unsigned long, nbytes, int __user *, start, void __user *, arg)
  686. {
  687. unsigned long w;
  688. struct percpu_struct *cpu;
  689. switch (op) {
  690. case GSI_IEEE_FP_CONTROL:
  691. /* Return current software fp control & status bits. */
  692. /* Note that DU doesn't verify available space here. */
  693. w = current_thread_info()->ieee_state & IEEE_SW_MASK;
  694. w = swcr_update_status(w, rdfpcr());
  695. if (put_user(w, (unsigned long __user *) buffer))
  696. return -EFAULT;
  697. return 0;
  698. case GSI_IEEE_STATE_AT_SIGNAL:
  699. /*
  700. * Not sure anybody will ever use this weird stuff. These
  701. * ops can be used (under OSF/1) to set the fpcr that should
  702. * be used when a signal handler starts executing.
  703. */
  704. break;
  705. case GSI_UACPROC:
  706. if (nbytes < sizeof(unsigned int))
  707. return -EINVAL;
  708. w = current_thread_info()->status & UAC_BITMASK;
  709. if (put_user(w, (unsigned int __user *)buffer))
  710. return -EFAULT;
  711. return 1;
  712. case GSI_PROC_TYPE:
  713. if (nbytes < sizeof(unsigned long))
  714. return -EINVAL;
  715. cpu = (struct percpu_struct*)
  716. ((char*)hwrpb + hwrpb->processor_offset);
  717. w = cpu->type;
  718. if (put_user(w, (unsigned long __user*)buffer))
  719. return -EFAULT;
  720. return 1;
  721. case GSI_GET_HWRPB:
  722. if (nbytes > sizeof(*hwrpb))
  723. return -EINVAL;
  724. if (copy_to_user(buffer, hwrpb, nbytes) != 0)
  725. return -EFAULT;
  726. return 1;
  727. default:
  728. break;
  729. }
  730. return -EOPNOTSUPP;
  731. }
  732. SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
  733. unsigned long, nbytes, int __user *, start, void __user *, arg)
  734. {
  735. switch (op) {
  736. case SSI_IEEE_FP_CONTROL: {
  737. unsigned long swcr, fpcr;
  738. unsigned int *state;
  739. /*
  740. * Alpha Architecture Handbook 4.7.7.3:
  741. * To be fully IEEE compiant, we must track the current IEEE
  742. * exception state in software, because spurious bits can be
  743. * set in the trap shadow of a software-complete insn.
  744. */
  745. if (get_user(swcr, (unsigned long __user *)buffer))
  746. return -EFAULT;
  747. state = &current_thread_info()->ieee_state;
  748. /* Update softare trap enable bits. */
  749. *state = (*state & ~IEEE_SW_MASK) | (swcr & IEEE_SW_MASK);
  750. /* Update the real fpcr. */
  751. fpcr = rdfpcr() & FPCR_DYN_MASK;
  752. fpcr |= ieee_swcr_to_fpcr(swcr);
  753. wrfpcr(fpcr);
  754. return 0;
  755. }
  756. case SSI_IEEE_RAISE_EXCEPTION: {
  757. unsigned long exc, swcr, fpcr, fex;
  758. unsigned int *state;
  759. if (get_user(exc, (unsigned long __user *)buffer))
  760. return -EFAULT;
  761. state = &current_thread_info()->ieee_state;
  762. exc &= IEEE_STATUS_MASK;
  763. /* Update softare trap enable bits. */
  764. swcr = (*state & IEEE_SW_MASK) | exc;
  765. *state |= exc;
  766. /* Update the real fpcr. */
  767. fpcr = rdfpcr();
  768. fpcr |= ieee_swcr_to_fpcr(swcr);
  769. wrfpcr(fpcr);
  770. /* If any exceptions set by this call, and are unmasked,
  771. send a signal. Old exceptions are not signaled. */
  772. fex = (exc >> IEEE_STATUS_TO_EXCSUM_SHIFT) & swcr;
  773. if (fex) {
  774. siginfo_t info;
  775. int si_code = 0;
  776. if (fex & IEEE_TRAP_ENABLE_DNO) si_code = FPE_FLTUND;
  777. if (fex & IEEE_TRAP_ENABLE_INE) si_code = FPE_FLTRES;
  778. if (fex & IEEE_TRAP_ENABLE_UNF) si_code = FPE_FLTUND;
  779. if (fex & IEEE_TRAP_ENABLE_OVF) si_code = FPE_FLTOVF;
  780. if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
  781. if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
  782. info.si_signo = SIGFPE;
  783. info.si_errno = 0;
  784. info.si_code = si_code;
  785. info.si_addr = NULL; /* FIXME */
  786. send_sig_info(SIGFPE, &info, current);
  787. }
  788. return 0;
  789. }
  790. case SSI_IEEE_STATE_AT_SIGNAL:
  791. case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
  792. /*
  793. * Not sure anybody will ever use this weird stuff. These
  794. * ops can be used (under OSF/1) to set the fpcr that should
  795. * be used when a signal handler starts executing.
  796. */
  797. break;
  798. case SSI_NVPAIRS: {
  799. unsigned __user *p = buffer;
  800. unsigned i;
  801. for (i = 0, p = buffer; i < nbytes; ++i, p += 2) {
  802. unsigned v, w, status;
  803. if (get_user(v, p) || get_user(w, p + 1))
  804. return -EFAULT;
  805. switch (v) {
  806. case SSIN_UACPROC:
  807. w &= UAC_BITMASK;
  808. status = current_thread_info()->status;
  809. status = (status & ~UAC_BITMASK) | w;
  810. current_thread_info()->status = status;
  811. break;
  812. default:
  813. return -EOPNOTSUPP;
  814. }
  815. }
  816. return 0;
  817. }
  818. case SSI_LMF:
  819. return 0;
  820. default:
  821. break;
  822. }
  823. return -EOPNOTSUPP;
  824. }
  825. /* Translations due to the fact that OSF's time_t is an int. Which
  826. affects all sorts of things, like timeval and itimerval. */
  827. extern struct timezone sys_tz;
  828. struct timeval32
  829. {
  830. int tv_sec, tv_usec;
  831. };
  832. struct itimerval32
  833. {
  834. struct timeval32 it_interval;
  835. struct timeval32 it_value;
  836. };
  837. static inline long
  838. get_tv32(struct timeval *o, struct timeval32 __user *i)
  839. {
  840. return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
  841. (__get_user(o->tv_sec, &i->tv_sec) |
  842. __get_user(o->tv_usec, &i->tv_usec)));
  843. }
  844. static inline long
  845. put_tv32(struct timeval32 __user *o, struct timeval *i)
  846. {
  847. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  848. (__put_user(i->tv_sec, &o->tv_sec) |
  849. __put_user(i->tv_usec, &o->tv_usec)));
  850. }
  851. static inline long
  852. get_it32(struct itimerval *o, struct itimerval32 __user *i)
  853. {
  854. return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
  855. (__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |
  856. __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |
  857. __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |
  858. __get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));
  859. }
  860. static inline long
  861. put_it32(struct itimerval32 __user *o, struct itimerval *i)
  862. {
  863. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  864. (__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |
  865. __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |
  866. __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |
  867. __put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));
  868. }
  869. static inline void
  870. jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
  871. {
  872. value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
  873. value->tv_sec = jiffies / HZ;
  874. }
  875. SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
  876. struct timezone __user *, tz)
  877. {
  878. if (tv) {
  879. struct timeval ktv;
  880. do_gettimeofday(&ktv);
  881. if (put_tv32(tv, &ktv))
  882. return -EFAULT;
  883. }
  884. if (tz) {
  885. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  886. return -EFAULT;
  887. }
  888. return 0;
  889. }
  890. SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
  891. struct timezone __user *, tz)
  892. {
  893. struct timespec kts;
  894. struct timezone ktz;
  895. if (tv) {
  896. if (get_tv32((struct timeval *)&kts, tv))
  897. return -EFAULT;
  898. kts.tv_nsec *= 1000;
  899. }
  900. if (tz) {
  901. if (copy_from_user(&ktz, tz, sizeof(*tz)))
  902. return -EFAULT;
  903. }
  904. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  905. }
  906. SYSCALL_DEFINE2(osf_getitimer, int, which, struct itimerval32 __user *, it)
  907. {
  908. struct itimerval kit;
  909. int error;
  910. error = do_getitimer(which, &kit);
  911. if (!error && put_it32(it, &kit))
  912. error = -EFAULT;
  913. return error;
  914. }
  915. SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
  916. struct itimerval32 __user *, out)
  917. {
  918. struct itimerval kin, kout;
  919. int error;
  920. if (in) {
  921. if (get_it32(&kin, in))
  922. return -EFAULT;
  923. } else
  924. memset(&kin, 0, sizeof(kin));
  925. error = do_setitimer(which, &kin, out ? &kout : NULL);
  926. if (error || !out)
  927. return error;
  928. if (put_it32(out, &kout))
  929. return -EFAULT;
  930. return 0;
  931. }
  932. SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
  933. struct timeval32 __user *, tvs)
  934. {
  935. struct timespec tv[2];
  936. if (tvs) {
  937. struct timeval ktvs[2];
  938. if (get_tv32(&ktvs[0], &tvs[0]) ||
  939. get_tv32(&ktvs[1], &tvs[1]))
  940. return -EFAULT;
  941. if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
  942. ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
  943. return -EINVAL;
  944. tv[0].tv_sec = ktvs[0].tv_sec;
  945. tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
  946. tv[1].tv_sec = ktvs[1].tv_sec;
  947. tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
  948. }
  949. return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
  950. }
  951. SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
  952. fd_set __user *, exp, struct timeval32 __user *, tvp)
  953. {
  954. struct timespec end_time, *to = NULL;
  955. if (tvp) {
  956. time_t sec, usec;
  957. to = &end_time;
  958. if (!access_ok(VERIFY_READ, tvp, sizeof(*tvp))
  959. || __get_user(sec, &tvp->tv_sec)
  960. || __get_user(usec, &tvp->tv_usec)) {
  961. return -EFAULT;
  962. }
  963. if (sec < 0 || usec < 0)
  964. return -EINVAL;
  965. if (poll_select_set_timeout(to, sec, usec * NSEC_PER_USEC))
  966. return -EINVAL;
  967. }
  968. /* OSF does not copy back the remaining time. */
  969. return core_sys_select(n, inp, outp, exp, to);
  970. }
  971. struct rusage32 {
  972. struct timeval32 ru_utime; /* user time used */
  973. struct timeval32 ru_stime; /* system time used */
  974. long ru_maxrss; /* maximum resident set size */
  975. long ru_ixrss; /* integral shared memory size */
  976. long ru_idrss; /* integral unshared data size */
  977. long ru_isrss; /* integral unshared stack size */
  978. long ru_minflt; /* page reclaims */
  979. long ru_majflt; /* page faults */
  980. long ru_nswap; /* swaps */
  981. long ru_inblock; /* block input operations */
  982. long ru_oublock; /* block output operations */
  983. long ru_msgsnd; /* messages sent */
  984. long ru_msgrcv; /* messages received */
  985. long ru_nsignals; /* signals received */
  986. long ru_nvcsw; /* voluntary context switches */
  987. long ru_nivcsw; /* involuntary " */
  988. };
  989. SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
  990. {
  991. struct rusage32 r;
  992. cputime_t utime, stime;
  993. unsigned long utime_jiffies, stime_jiffies;
  994. if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  995. return -EINVAL;
  996. memset(&r, 0, sizeof(r));
  997. switch (who) {
  998. case RUSAGE_SELF:
  999. task_cputime(current, &utime, &stime);
  1000. utime_jiffies = cputime_to_jiffies(utime);
  1001. stime_jiffies = cputime_to_jiffies(stime);
  1002. jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
  1003. jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
  1004. r.ru_minflt = current->min_flt;
  1005. r.ru_majflt = current->maj_flt;
  1006. break;
  1007. case RUSAGE_CHILDREN:
  1008. utime_jiffies = cputime_to_jiffies(current->signal->cutime);
  1009. stime_jiffies = cputime_to_jiffies(current->signal->cstime);
  1010. jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
  1011. jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
  1012. r.ru_minflt = current->signal->cmin_flt;
  1013. r.ru_majflt = current->signal->cmaj_flt;
  1014. break;
  1015. }
  1016. return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
  1017. }
  1018. SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
  1019. struct rusage32 __user *, ur)
  1020. {
  1021. struct rusage r;
  1022. long ret, err;
  1023. unsigned int status = 0;
  1024. mm_segment_t old_fs;
  1025. if (!ur)
  1026. return sys_wait4(pid, ustatus, options, NULL);
  1027. old_fs = get_fs();
  1028. set_fs (KERNEL_DS);
  1029. ret = sys_wait4(pid, (unsigned int __user *) &status, options,
  1030. (struct rusage __user *) &r);
  1031. set_fs (old_fs);
  1032. if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
  1033. return -EFAULT;
  1034. err = put_user(status, ustatus);
  1035. if (ret < 0)
  1036. return err ? err : ret;
  1037. err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
  1038. err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
  1039. err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
  1040. err |= __put_user(r.ru_stime.tv_usec, &ur->ru_stime.tv_usec);
  1041. err |= __put_user(r.ru_maxrss, &ur->ru_maxrss);
  1042. err |= __put_user(r.ru_ixrss, &ur->ru_ixrss);
  1043. err |= __put_user(r.ru_idrss, &ur->ru_idrss);
  1044. err |= __put_user(r.ru_isrss, &ur->ru_isrss);
  1045. err |= __put_user(r.ru_minflt, &ur->ru_minflt);
  1046. err |= __put_user(r.ru_majflt, &ur->ru_majflt);
  1047. err |= __put_user(r.ru_nswap, &ur->ru_nswap);
  1048. err |= __put_user(r.ru_inblock, &ur->ru_inblock);
  1049. err |= __put_user(r.ru_oublock, &ur->ru_oublock);
  1050. err |= __put_user(r.ru_msgsnd, &ur->ru_msgsnd);
  1051. err |= __put_user(r.ru_msgrcv, &ur->ru_msgrcv);
  1052. err |= __put_user(r.ru_nsignals, &ur->ru_nsignals);
  1053. err |= __put_user(r.ru_nvcsw, &ur->ru_nvcsw);
  1054. err |= __put_user(r.ru_nivcsw, &ur->ru_nivcsw);
  1055. return err ? err : ret;
  1056. }
  1057. /*
  1058. * I don't know what the parameters are: the first one
  1059. * seems to be a timeval pointer, and I suspect the second
  1060. * one is the time remaining.. Ho humm.. No documentation.
  1061. */
  1062. SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
  1063. struct timeval32 __user *, remain)
  1064. {
  1065. struct timeval tmp;
  1066. unsigned long ticks;
  1067. if (get_tv32(&tmp, sleep))
  1068. goto fault;
  1069. ticks = timeval_to_jiffies(&tmp);
  1070. ticks = schedule_timeout_interruptible(ticks);
  1071. if (remain) {
  1072. jiffies_to_timeval(ticks, &tmp);
  1073. if (put_tv32(remain, &tmp))
  1074. goto fault;
  1075. }
  1076. return 0;
  1077. fault:
  1078. return -EFAULT;
  1079. }
  1080. struct timex32 {
  1081. unsigned int modes; /* mode selector */
  1082. long offset; /* time offset (usec) */
  1083. long freq; /* frequency offset (scaled ppm) */
  1084. long maxerror; /* maximum error (usec) */
  1085. long esterror; /* estimated error (usec) */
  1086. int status; /* clock command/status */
  1087. long constant; /* pll time constant */
  1088. long precision; /* clock precision (usec) (read only) */
  1089. long tolerance; /* clock frequency tolerance (ppm)
  1090. * (read only)
  1091. */
  1092. struct timeval32 time; /* (read only) */
  1093. long tick; /* (modified) usecs between clock ticks */
  1094. long ppsfreq; /* pps frequency (scaled ppm) (ro) */
  1095. long jitter; /* pps jitter (us) (ro) */
  1096. int shift; /* interval duration (s) (shift) (ro) */
  1097. long stabil; /* pps stability (scaled ppm) (ro) */
  1098. long jitcnt; /* jitter limit exceeded (ro) */
  1099. long calcnt; /* calibration intervals (ro) */
  1100. long errcnt; /* calibration errors (ro) */
  1101. long stbcnt; /* stability limit exceeded (ro) */
  1102. int :32; int :32; int :32; int :32;
  1103. int :32; int :32; int :32; int :32;
  1104. int :32; int :32; int :32; int :32;
  1105. };
  1106. SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
  1107. {
  1108. struct timex txc;
  1109. int ret;
  1110. /* copy relevant bits of struct timex. */
  1111. if (copy_from_user(&txc, txc_p, offsetof(struct timex32, time)) ||
  1112. copy_from_user(&txc.tick, &txc_p->tick, sizeof(struct timex32) -
  1113. offsetof(struct timex32, time)))
  1114. return -EFAULT;
  1115. ret = do_adjtimex(&txc);
  1116. if (ret < 0)
  1117. return ret;
  1118. /* copy back to timex32 */
  1119. if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
  1120. (copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
  1121. offsetof(struct timex32, tick))) ||
  1122. (put_tv32(&txc_p->time, &txc.time)))
  1123. return -EFAULT;
  1124. return ret;
  1125. }
  1126. /* Get an address range which is currently unmapped. Similar to the
  1127. generic version except that we know how to honor ADDR_LIMIT_32BIT. */
  1128. static unsigned long
  1129. arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
  1130. unsigned long limit)
  1131. {
  1132. struct vm_unmapped_area_info info;
  1133. info.flags = 0;
  1134. info.length = len;
  1135. info.low_limit = addr;
  1136. info.high_limit = limit;
  1137. info.align_mask = 0;
  1138. info.align_offset = 0;
  1139. return vm_unmapped_area(&info);
  1140. }
  1141. unsigned long
  1142. arch_get_unmapped_area(struct file *filp, unsigned long addr,
  1143. unsigned long len, unsigned long pgoff,
  1144. unsigned long flags)
  1145. {
  1146. unsigned long limit;
  1147. /* "32 bit" actually means 31 bit, since pointers sign extend. */
  1148. if (current->personality & ADDR_LIMIT_32BIT)
  1149. limit = 0x80000000;
  1150. else
  1151. limit = TASK_SIZE;
  1152. if (len > limit)
  1153. return -ENOMEM;
  1154. if (flags & MAP_FIXED)
  1155. return addr;
  1156. /* First, see if the given suggestion fits.
  1157. The OSF/1 loader (/sbin/loader) relies on us returning an
  1158. address larger than the requested if one exists, which is
  1159. a terribly broken way to program.
  1160. That said, I can see the use in being able to suggest not
  1161. merely specific addresses, but regions of memory -- perhaps
  1162. this feature should be incorporated into all ports? */
  1163. if (addr) {
  1164. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
  1165. if (addr != (unsigned long) -ENOMEM)
  1166. return addr;
  1167. }
  1168. /* Next, try allocating at TASK_UNMAPPED_BASE. */
  1169. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
  1170. len, limit);
  1171. if (addr != (unsigned long) -ENOMEM)
  1172. return addr;
  1173. /* Finally, try allocating in low memory. */
  1174. addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
  1175. return addr;
  1176. }
  1177. #ifdef CONFIG_OSF4_COMPAT
  1178. /* Clear top 32 bits of iov_len in the user's buffer for
  1179. compatibility with old versions of OSF/1 where iov_len
  1180. was defined as int. */
  1181. static int
  1182. osf_fix_iov_len(const struct iovec __user *iov, unsigned long count)
  1183. {
  1184. unsigned long i;
  1185. for (i = 0 ; i < count ; i++) {
  1186. int __user *iov_len_high = (int __user *)&iov[i].iov_len + 1;
  1187. if (put_user(0, iov_len_high))
  1188. return -EFAULT;
  1189. }
  1190. return 0;
  1191. }
  1192. SYSCALL_DEFINE3(osf_readv, unsigned long, fd,
  1193. const struct iovec __user *, vector, unsigned long, count)
  1194. {
  1195. if (unlikely(personality(current->personality) == PER_OSF4))
  1196. if (osf_fix_iov_len(vector, count))
  1197. return -EFAULT;
  1198. return sys_readv(fd, vector, count);
  1199. }
  1200. SYSCALL_DEFINE3(osf_writev, unsigned long, fd,
  1201. const struct iovec __user *, vector, unsigned long, count)
  1202. {
  1203. if (unlikely(personality(current->personality) == PER_OSF4))
  1204. if (osf_fix_iov_len(vector, count))
  1205. return -EFAULT;
  1206. return sys_writev(fd, vector, count);
  1207. }
  1208. #endif
  1209. SYSCALL_DEFINE2(osf_getpriority, int, which, int, who)
  1210. {
  1211. int prio = sys_getpriority(which, who);
  1212. if (prio >= 0) {
  1213. /* Return value is the unbiased priority, i.e. 20 - prio.
  1214. This does result in negative return values, so signal
  1215. no error */
  1216. force_successful_syscall_return();
  1217. prio = 20 - prio;
  1218. }
  1219. return prio;
  1220. }
  1221. SYSCALL_DEFINE0(getxuid)
  1222. {
  1223. current_pt_regs()->r20 = sys_geteuid();
  1224. return sys_getuid();
  1225. }
  1226. SYSCALL_DEFINE0(getxgid)
  1227. {
  1228. current_pt_regs()->r20 = sys_getegid();
  1229. return sys_getgid();
  1230. }
  1231. SYSCALL_DEFINE0(getxpid)
  1232. {
  1233. current_pt_regs()->r20 = sys_getppid();
  1234. return sys_getpid();
  1235. }
  1236. SYSCALL_DEFINE0(alpha_pipe)
  1237. {
  1238. int fd[2];
  1239. int res = do_pipe_flags(fd, 0);
  1240. if (!res) {
  1241. /* The return values are in $0 and $20. */
  1242. current_pt_regs()->r20 = fd[1];
  1243. res = fd[0];
  1244. }
  1245. return res;
  1246. }
  1247. SYSCALL_DEFINE1(sethae, unsigned long, val)
  1248. {
  1249. current_pt_regs()->hae = val;
  1250. return 0;
  1251. }