osf_sys.c 34 KB

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