osf_sys.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  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(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(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. if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  994. return -EINVAL;
  995. memset(&r, 0, sizeof(r));
  996. switch (who) {
  997. case RUSAGE_SELF:
  998. task_cputime(current, &utime, &stime);
  999. jiffies_to_timeval32(utime, &r.ru_utime);
  1000. jiffies_to_timeval32(stime, &r.ru_stime);
  1001. r.ru_minflt = current->min_flt;
  1002. r.ru_majflt = current->maj_flt;
  1003. break;
  1004. case RUSAGE_CHILDREN:
  1005. jiffies_to_timeval32(current->signal->cutime, &r.ru_utime);
  1006. jiffies_to_timeval32(current->signal->cstime, &r.ru_stime);
  1007. r.ru_minflt = current->signal->cmin_flt;
  1008. r.ru_majflt = current->signal->cmaj_flt;
  1009. break;
  1010. }
  1011. return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
  1012. }
  1013. SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
  1014. struct rusage32 __user *, ur)
  1015. {
  1016. struct rusage r;
  1017. long ret, err;
  1018. unsigned int status = 0;
  1019. mm_segment_t old_fs;
  1020. if (!ur)
  1021. return sys_wait4(pid, ustatus, options, NULL);
  1022. old_fs = get_fs();
  1023. set_fs (KERNEL_DS);
  1024. ret = sys_wait4(pid, (unsigned int __user *) &status, options,
  1025. (struct rusage __user *) &r);
  1026. set_fs (old_fs);
  1027. if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
  1028. return -EFAULT;
  1029. err = 0;
  1030. err |= put_user(status, ustatus);
  1031. err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
  1032. err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
  1033. err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
  1034. err |= __put_user(r.ru_stime.tv_usec, &ur->ru_stime.tv_usec);
  1035. err |= __put_user(r.ru_maxrss, &ur->ru_maxrss);
  1036. err |= __put_user(r.ru_ixrss, &ur->ru_ixrss);
  1037. err |= __put_user(r.ru_idrss, &ur->ru_idrss);
  1038. err |= __put_user(r.ru_isrss, &ur->ru_isrss);
  1039. err |= __put_user(r.ru_minflt, &ur->ru_minflt);
  1040. err |= __put_user(r.ru_majflt, &ur->ru_majflt);
  1041. err |= __put_user(r.ru_nswap, &ur->ru_nswap);
  1042. err |= __put_user(r.ru_inblock, &ur->ru_inblock);
  1043. err |= __put_user(r.ru_oublock, &ur->ru_oublock);
  1044. err |= __put_user(r.ru_msgsnd, &ur->ru_msgsnd);
  1045. err |= __put_user(r.ru_msgrcv, &ur->ru_msgrcv);
  1046. err |= __put_user(r.ru_nsignals, &ur->ru_nsignals);
  1047. err |= __put_user(r.ru_nvcsw, &ur->ru_nvcsw);
  1048. err |= __put_user(r.ru_nivcsw, &ur->ru_nivcsw);
  1049. return err ? err : ret;
  1050. }
  1051. /*
  1052. * I don't know what the parameters are: the first one
  1053. * seems to be a timeval pointer, and I suspect the second
  1054. * one is the time remaining.. Ho humm.. No documentation.
  1055. */
  1056. SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
  1057. struct timeval32 __user *, remain)
  1058. {
  1059. struct timeval tmp;
  1060. unsigned long ticks;
  1061. if (get_tv32(&tmp, sleep))
  1062. goto fault;
  1063. ticks = timeval_to_jiffies(&tmp);
  1064. ticks = schedule_timeout_interruptible(ticks);
  1065. if (remain) {
  1066. jiffies_to_timeval(ticks, &tmp);
  1067. if (put_tv32(remain, &tmp))
  1068. goto fault;
  1069. }
  1070. return 0;
  1071. fault:
  1072. return -EFAULT;
  1073. }
  1074. struct timex32 {
  1075. unsigned int modes; /* mode selector */
  1076. long offset; /* time offset (usec) */
  1077. long freq; /* frequency offset (scaled ppm) */
  1078. long maxerror; /* maximum error (usec) */
  1079. long esterror; /* estimated error (usec) */
  1080. int status; /* clock command/status */
  1081. long constant; /* pll time constant */
  1082. long precision; /* clock precision (usec) (read only) */
  1083. long tolerance; /* clock frequency tolerance (ppm)
  1084. * (read only)
  1085. */
  1086. struct timeval32 time; /* (read only) */
  1087. long tick; /* (modified) usecs between clock ticks */
  1088. long ppsfreq; /* pps frequency (scaled ppm) (ro) */
  1089. long jitter; /* pps jitter (us) (ro) */
  1090. int shift; /* interval duration (s) (shift) (ro) */
  1091. long stabil; /* pps stability (scaled ppm) (ro) */
  1092. long jitcnt; /* jitter limit exceeded (ro) */
  1093. long calcnt; /* calibration intervals (ro) */
  1094. long errcnt; /* calibration errors (ro) */
  1095. long stbcnt; /* stability limit exceeded (ro) */
  1096. int :32; int :32; int :32; int :32;
  1097. int :32; int :32; int :32; int :32;
  1098. int :32; int :32; int :32; int :32;
  1099. };
  1100. SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
  1101. {
  1102. struct timex txc;
  1103. int ret;
  1104. /* copy relevant bits of struct timex. */
  1105. if (copy_from_user(&txc, txc_p, offsetof(struct timex32, time)) ||
  1106. copy_from_user(&txc.tick, &txc_p->tick, sizeof(struct timex32) -
  1107. offsetof(struct timex32, time)))
  1108. return -EFAULT;
  1109. ret = do_adjtimex(&txc);
  1110. if (ret < 0)
  1111. return ret;
  1112. /* copy back to timex32 */
  1113. if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
  1114. (copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
  1115. offsetof(struct timex32, tick))) ||
  1116. (put_tv32(&txc_p->time, &txc.time)))
  1117. return -EFAULT;
  1118. return ret;
  1119. }
  1120. /* Get an address range which is currently unmapped. Similar to the
  1121. generic version except that we know how to honor ADDR_LIMIT_32BIT. */
  1122. static unsigned long
  1123. arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
  1124. unsigned long limit)
  1125. {
  1126. struct vm_unmapped_area_info info;
  1127. info.flags = 0;
  1128. info.length = len;
  1129. info.low_limit = addr;
  1130. info.high_limit = limit;
  1131. info.align_mask = 0;
  1132. info.align_offset = 0;
  1133. return vm_unmapped_area(&info);
  1134. }
  1135. unsigned long
  1136. arch_get_unmapped_area(struct file *filp, unsigned long addr,
  1137. unsigned long len, unsigned long pgoff,
  1138. unsigned long flags)
  1139. {
  1140. unsigned long limit;
  1141. /* "32 bit" actually means 31 bit, since pointers sign extend. */
  1142. if (current->personality & ADDR_LIMIT_32BIT)
  1143. limit = 0x80000000;
  1144. else
  1145. limit = TASK_SIZE;
  1146. if (len > limit)
  1147. return -ENOMEM;
  1148. if (flags & MAP_FIXED)
  1149. return addr;
  1150. /* First, see if the given suggestion fits.
  1151. The OSF/1 loader (/sbin/loader) relies on us returning an
  1152. address larger than the requested if one exists, which is
  1153. a terribly broken way to program.
  1154. That said, I can see the use in being able to suggest not
  1155. merely specific addresses, but regions of memory -- perhaps
  1156. this feature should be incorporated into all ports? */
  1157. if (addr) {
  1158. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
  1159. if (addr != (unsigned long) -ENOMEM)
  1160. return addr;
  1161. }
  1162. /* Next, try allocating at TASK_UNMAPPED_BASE. */
  1163. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
  1164. len, limit);
  1165. if (addr != (unsigned long) -ENOMEM)
  1166. return addr;
  1167. /* Finally, try allocating in low memory. */
  1168. addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
  1169. return addr;
  1170. }
  1171. #ifdef CONFIG_OSF4_COMPAT
  1172. /* Clear top 32 bits of iov_len in the user's buffer for
  1173. compatibility with old versions of OSF/1 where iov_len
  1174. was defined as int. */
  1175. static int
  1176. osf_fix_iov_len(const struct iovec __user *iov, unsigned long count)
  1177. {
  1178. unsigned long i;
  1179. for (i = 0 ; i < count ; i++) {
  1180. int __user *iov_len_high = (int __user *)&iov[i].iov_len + 1;
  1181. if (put_user(0, iov_len_high))
  1182. return -EFAULT;
  1183. }
  1184. return 0;
  1185. }
  1186. SYSCALL_DEFINE3(osf_readv, unsigned long, fd,
  1187. const struct iovec __user *, vector, unsigned long, count)
  1188. {
  1189. if (unlikely(personality(current->personality) == PER_OSF4))
  1190. if (osf_fix_iov_len(vector, count))
  1191. return -EFAULT;
  1192. return sys_readv(fd, vector, count);
  1193. }
  1194. SYSCALL_DEFINE3(osf_writev, unsigned long, fd,
  1195. const struct iovec __user *, vector, unsigned long, count)
  1196. {
  1197. if (unlikely(personality(current->personality) == PER_OSF4))
  1198. if (osf_fix_iov_len(vector, count))
  1199. return -EFAULT;
  1200. return sys_writev(fd, vector, count);
  1201. }
  1202. #endif
  1203. SYSCALL_DEFINE2(osf_getpriority, int, which, int, who)
  1204. {
  1205. int prio = sys_getpriority(which, who);
  1206. if (prio >= 0) {
  1207. /* Return value is the unbiased priority, i.e. 20 - prio.
  1208. This does result in negative return values, so signal
  1209. no error */
  1210. force_successful_syscall_return();
  1211. prio = 20 - prio;
  1212. }
  1213. return prio;
  1214. }
  1215. SYSCALL_DEFINE0(getxuid)
  1216. {
  1217. current_pt_regs()->r20 = sys_geteuid();
  1218. return sys_getuid();
  1219. }
  1220. SYSCALL_DEFINE0(getxgid)
  1221. {
  1222. current_pt_regs()->r20 = sys_getegid();
  1223. return sys_getgid();
  1224. }
  1225. SYSCALL_DEFINE0(getxpid)
  1226. {
  1227. current_pt_regs()->r20 = sys_getppid();
  1228. return sys_getpid();
  1229. }
  1230. SYSCALL_DEFINE0(alpha_pipe)
  1231. {
  1232. int fd[2];
  1233. int res = do_pipe_flags(fd, 0);
  1234. if (!res) {
  1235. /* The return values are in $0 and $20. */
  1236. current_pt_regs()->r20 = fd[1];
  1237. res = fd[0];
  1238. }
  1239. return res;
  1240. }
  1241. SYSCALL_DEFINE1(sethae, unsigned long, val)
  1242. {
  1243. current_pt_regs()->hae = val;
  1244. return 0;
  1245. }