osf_sys.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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 = ksys_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. char tmp[5 * 32];
  478. down_read(&uts_sem);
  479. memcpy(tmp + 0 * 32, utsname()->sysname, 32);
  480. memcpy(tmp + 1 * 32, utsname()->nodename, 32);
  481. memcpy(tmp + 2 * 32, utsname()->release, 32);
  482. memcpy(tmp + 3 * 32, utsname()->version, 32);
  483. memcpy(tmp + 4 * 32, utsname()->machine, 32);
  484. up_read(&uts_sem);
  485. if (copy_to_user(name, tmp, sizeof(tmp)))
  486. return -EFAULT;
  487. return 0;
  488. }
  489. SYSCALL_DEFINE0(getpagesize)
  490. {
  491. return PAGE_SIZE;
  492. }
  493. SYSCALL_DEFINE0(getdtablesize)
  494. {
  495. return sysctl_nr_open;
  496. }
  497. /*
  498. * For compatibility with OSF/1 only. Use utsname(2) instead.
  499. */
  500. SYSCALL_DEFINE2(osf_getdomainname, char __user *, name, int, namelen)
  501. {
  502. int len, err = 0;
  503. char *kname;
  504. char tmp[32];
  505. if (namelen < 0 || namelen > 32)
  506. namelen = 32;
  507. down_read(&uts_sem);
  508. kname = utsname()->domainname;
  509. len = strnlen(kname, namelen);
  510. len = min(len + 1, namelen);
  511. memcpy(tmp, kname, len);
  512. up_read(&uts_sem);
  513. if (copy_to_user(name, tmp, len))
  514. return -EFAULT;
  515. return 0;
  516. }
  517. /*
  518. * The following stuff should move into a header file should it ever
  519. * be labeled "officially supported." Right now, there is just enough
  520. * support to avoid applications (such as tar) printing error
  521. * messages. The attributes are not really implemented.
  522. */
  523. /*
  524. * Values for Property list entry flag
  525. */
  526. #define PLE_PROPAGATE_ON_COPY 0x1 /* cp(1) will copy entry
  527. by default */
  528. #define PLE_FLAG_MASK 0x1 /* Valid flag values */
  529. #define PLE_FLAG_ALL -1 /* All flag value */
  530. struct proplistname_args {
  531. unsigned int pl_mask;
  532. unsigned int pl_numnames;
  533. char **pl_names;
  534. };
  535. union pl_args {
  536. struct setargs {
  537. char __user *path;
  538. long follow;
  539. long nbytes;
  540. char __user *buf;
  541. } set;
  542. struct fsetargs {
  543. long fd;
  544. long nbytes;
  545. char __user *buf;
  546. } fset;
  547. struct getargs {
  548. char __user *path;
  549. long follow;
  550. struct proplistname_args __user *name_args;
  551. long nbytes;
  552. char __user *buf;
  553. int __user *min_buf_size;
  554. } get;
  555. struct fgetargs {
  556. long fd;
  557. struct proplistname_args __user *name_args;
  558. long nbytes;
  559. char __user *buf;
  560. int __user *min_buf_size;
  561. } fget;
  562. struct delargs {
  563. char __user *path;
  564. long follow;
  565. struct proplistname_args __user *name_args;
  566. } del;
  567. struct fdelargs {
  568. long fd;
  569. struct proplistname_args __user *name_args;
  570. } fdel;
  571. };
  572. enum pl_code {
  573. PL_SET = 1, PL_FSET = 2,
  574. PL_GET = 3, PL_FGET = 4,
  575. PL_DEL = 5, PL_FDEL = 6
  576. };
  577. SYSCALL_DEFINE2(osf_proplist_syscall, enum pl_code, code,
  578. union pl_args __user *, args)
  579. {
  580. long error;
  581. int __user *min_buf_size_ptr;
  582. switch (code) {
  583. case PL_SET:
  584. if (get_user(error, &args->set.nbytes))
  585. error = -EFAULT;
  586. break;
  587. case PL_FSET:
  588. if (get_user(error, &args->fset.nbytes))
  589. error = -EFAULT;
  590. break;
  591. case PL_GET:
  592. error = get_user(min_buf_size_ptr, &args->get.min_buf_size);
  593. if (error)
  594. break;
  595. error = put_user(0, min_buf_size_ptr);
  596. break;
  597. case PL_FGET:
  598. error = get_user(min_buf_size_ptr, &args->fget.min_buf_size);
  599. if (error)
  600. break;
  601. error = put_user(0, min_buf_size_ptr);
  602. break;
  603. case PL_DEL:
  604. case PL_FDEL:
  605. error = 0;
  606. break;
  607. default:
  608. error = -EOPNOTSUPP;
  609. break;
  610. };
  611. return error;
  612. }
  613. SYSCALL_DEFINE2(osf_sigstack, struct sigstack __user *, uss,
  614. struct sigstack __user *, uoss)
  615. {
  616. unsigned long usp = rdusp();
  617. unsigned long oss_sp = current->sas_ss_sp + current->sas_ss_size;
  618. unsigned long oss_os = on_sig_stack(usp);
  619. int error;
  620. if (uss) {
  621. void __user *ss_sp;
  622. error = -EFAULT;
  623. if (get_user(ss_sp, &uss->ss_sp))
  624. goto out;
  625. /* If the current stack was set with sigaltstack, don't
  626. swap stacks while we are on it. */
  627. error = -EPERM;
  628. if (current->sas_ss_sp && on_sig_stack(usp))
  629. goto out;
  630. /* Since we don't know the extent of the stack, and we don't
  631. track onstack-ness, but rather calculate it, we must
  632. presume a size. Ho hum this interface is lossy. */
  633. current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
  634. current->sas_ss_size = SIGSTKSZ;
  635. }
  636. if (uoss) {
  637. error = -EFAULT;
  638. if (put_user(oss_sp, &uoss->ss_sp) ||
  639. put_user(oss_os, &uoss->ss_onstack))
  640. goto out;
  641. }
  642. error = 0;
  643. out:
  644. return error;
  645. }
  646. SYSCALL_DEFINE3(osf_sysinfo, int, command, char __user *, buf, long, count)
  647. {
  648. const char *sysinfo_table[] = {
  649. utsname()->sysname,
  650. utsname()->nodename,
  651. utsname()->release,
  652. utsname()->version,
  653. utsname()->machine,
  654. "alpha", /* instruction set architecture */
  655. "dummy", /* hardware serial number */
  656. "dummy", /* hardware manufacturer */
  657. "dummy", /* secure RPC domain */
  658. };
  659. unsigned long offset;
  660. const char *res;
  661. long len;
  662. char tmp[__NEW_UTS_LEN + 1];
  663. offset = command-1;
  664. if (offset >= ARRAY_SIZE(sysinfo_table)) {
  665. /* Digital UNIX has a few unpublished interfaces here */
  666. printk("sysinfo(%d)", command);
  667. return -EINVAL;
  668. }
  669. down_read(&uts_sem);
  670. res = sysinfo_table[offset];
  671. len = strlen(res)+1;
  672. if ((unsigned long)len > (unsigned long)count)
  673. len = count;
  674. memcpy(tmp, res, len);
  675. up_read(&uts_sem);
  676. if (copy_to_user(buf, tmp, len))
  677. return -EFAULT;
  678. return 0;
  679. }
  680. SYSCALL_DEFINE5(osf_getsysinfo, unsigned long, op, void __user *, buffer,
  681. unsigned long, nbytes, int __user *, start, void __user *, arg)
  682. {
  683. unsigned long w;
  684. struct percpu_struct *cpu;
  685. switch (op) {
  686. case GSI_IEEE_FP_CONTROL:
  687. /* Return current software fp control & status bits. */
  688. /* Note that DU doesn't verify available space here. */
  689. w = current_thread_info()->ieee_state & IEEE_SW_MASK;
  690. w = swcr_update_status(w, rdfpcr());
  691. if (put_user(w, (unsigned long __user *) buffer))
  692. return -EFAULT;
  693. return 0;
  694. case GSI_IEEE_STATE_AT_SIGNAL:
  695. /*
  696. * Not sure anybody will ever use this weird stuff. These
  697. * ops can be used (under OSF/1) to set the fpcr that should
  698. * be used when a signal handler starts executing.
  699. */
  700. break;
  701. case GSI_UACPROC:
  702. if (nbytes < sizeof(unsigned int))
  703. return -EINVAL;
  704. w = current_thread_info()->status & UAC_BITMASK;
  705. if (put_user(w, (unsigned int __user *)buffer))
  706. return -EFAULT;
  707. return 1;
  708. case GSI_PROC_TYPE:
  709. if (nbytes < sizeof(unsigned long))
  710. return -EINVAL;
  711. cpu = (struct percpu_struct*)
  712. ((char*)hwrpb + hwrpb->processor_offset);
  713. w = cpu->type;
  714. if (put_user(w, (unsigned long __user*)buffer))
  715. return -EFAULT;
  716. return 1;
  717. case GSI_GET_HWRPB:
  718. if (nbytes > sizeof(*hwrpb))
  719. return -EINVAL;
  720. if (copy_to_user(buffer, hwrpb, nbytes) != 0)
  721. return -EFAULT;
  722. return 1;
  723. default:
  724. break;
  725. }
  726. return -EOPNOTSUPP;
  727. }
  728. SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
  729. unsigned long, nbytes, int __user *, start, void __user *, arg)
  730. {
  731. switch (op) {
  732. case SSI_IEEE_FP_CONTROL: {
  733. unsigned long swcr, fpcr;
  734. unsigned int *state;
  735. /*
  736. * Alpha Architecture Handbook 4.7.7.3:
  737. * To be fully IEEE compiant, we must track the current IEEE
  738. * exception state in software, because spurious bits can be
  739. * set in the trap shadow of a software-complete insn.
  740. */
  741. if (get_user(swcr, (unsigned long __user *)buffer))
  742. return -EFAULT;
  743. state = &current_thread_info()->ieee_state;
  744. /* Update softare trap enable bits. */
  745. *state = (*state & ~IEEE_SW_MASK) | (swcr & IEEE_SW_MASK);
  746. /* Update the real fpcr. */
  747. fpcr = rdfpcr() & FPCR_DYN_MASK;
  748. fpcr |= ieee_swcr_to_fpcr(swcr);
  749. wrfpcr(fpcr);
  750. return 0;
  751. }
  752. case SSI_IEEE_RAISE_EXCEPTION: {
  753. unsigned long exc, swcr, fpcr, fex;
  754. unsigned int *state;
  755. if (get_user(exc, (unsigned long __user *)buffer))
  756. return -EFAULT;
  757. state = &current_thread_info()->ieee_state;
  758. exc &= IEEE_STATUS_MASK;
  759. /* Update softare trap enable bits. */
  760. swcr = (*state & IEEE_SW_MASK) | exc;
  761. *state |= exc;
  762. /* Update the real fpcr. */
  763. fpcr = rdfpcr();
  764. fpcr |= ieee_swcr_to_fpcr(swcr);
  765. wrfpcr(fpcr);
  766. /* If any exceptions set by this call, and are unmasked,
  767. send a signal. Old exceptions are not signaled. */
  768. fex = (exc >> IEEE_STATUS_TO_EXCSUM_SHIFT) & swcr;
  769. if (fex) {
  770. int si_code = FPE_FLTUNK;
  771. if (fex & IEEE_TRAP_ENABLE_DNO) si_code = FPE_FLTUND;
  772. if (fex & IEEE_TRAP_ENABLE_INE) si_code = FPE_FLTRES;
  773. if (fex & IEEE_TRAP_ENABLE_UNF) si_code = FPE_FLTUND;
  774. if (fex & IEEE_TRAP_ENABLE_OVF) si_code = FPE_FLTOVF;
  775. if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
  776. if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
  777. send_sig_fault(SIGFPE, si_code,
  778. (void __user *)NULL, /* FIXME */
  779. 0, current);
  780. }
  781. return 0;
  782. }
  783. case SSI_IEEE_STATE_AT_SIGNAL:
  784. case SSI_IEEE_IGNORE_STATE_AT_SIGNAL:
  785. /*
  786. * Not sure anybody will ever use this weird stuff. These
  787. * ops can be used (under OSF/1) to set the fpcr that should
  788. * be used when a signal handler starts executing.
  789. */
  790. break;
  791. case SSI_NVPAIRS: {
  792. unsigned __user *p = buffer;
  793. unsigned i;
  794. for (i = 0, p = buffer; i < nbytes; ++i, p += 2) {
  795. unsigned v, w, status;
  796. if (get_user(v, p) || get_user(w, p + 1))
  797. return -EFAULT;
  798. switch (v) {
  799. case SSIN_UACPROC:
  800. w &= UAC_BITMASK;
  801. status = current_thread_info()->status;
  802. status = (status & ~UAC_BITMASK) | w;
  803. current_thread_info()->status = status;
  804. break;
  805. default:
  806. return -EOPNOTSUPP;
  807. }
  808. }
  809. return 0;
  810. }
  811. case SSI_LMF:
  812. return 0;
  813. default:
  814. break;
  815. }
  816. return -EOPNOTSUPP;
  817. }
  818. /* Translations due to the fact that OSF's time_t is an int. Which
  819. affects all sorts of things, like timeval and itimerval. */
  820. extern struct timezone sys_tz;
  821. struct timeval32
  822. {
  823. int tv_sec, tv_usec;
  824. };
  825. struct itimerval32
  826. {
  827. struct timeval32 it_interval;
  828. struct timeval32 it_value;
  829. };
  830. static inline long
  831. get_tv32(struct timespec64 *o, struct timeval32 __user *i)
  832. {
  833. struct timeval32 tv;
  834. if (copy_from_user(&tv, i, sizeof(struct timeval32)))
  835. return -EFAULT;
  836. o->tv_sec = tv.tv_sec;
  837. o->tv_nsec = tv.tv_usec * NSEC_PER_USEC;
  838. return 0;
  839. }
  840. static inline long
  841. put_tv32(struct timeval32 __user *o, struct timespec64 *i)
  842. {
  843. return copy_to_user(o, &(struct timeval32){
  844. .tv_sec = i->tv_sec,
  845. .tv_usec = i->tv_nsec / NSEC_PER_USEC},
  846. sizeof(struct timeval32));
  847. }
  848. static inline long
  849. put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i)
  850. {
  851. return copy_to_user(o, &(struct timeval32){
  852. .tv_sec = i->tv_sec,
  853. .tv_usec = i->tv_usec},
  854. sizeof(struct timeval32));
  855. }
  856. static inline long
  857. get_it32(struct itimerval *o, struct itimerval32 __user *i)
  858. {
  859. struct itimerval32 itv;
  860. if (copy_from_user(&itv, i, sizeof(struct itimerval32)))
  861. return -EFAULT;
  862. o->it_interval.tv_sec = itv.it_interval.tv_sec;
  863. o->it_interval.tv_usec = itv.it_interval.tv_usec;
  864. o->it_value.tv_sec = itv.it_value.tv_sec;
  865. o->it_value.tv_usec = itv.it_value.tv_usec;
  866. return 0;
  867. }
  868. static inline long
  869. put_it32(struct itimerval32 __user *o, struct itimerval *i)
  870. {
  871. return copy_to_user(o, &(struct itimerval32){
  872. .it_interval.tv_sec = o->it_interval.tv_sec,
  873. .it_interval.tv_usec = o->it_interval.tv_usec,
  874. .it_value.tv_sec = o->it_value.tv_sec,
  875. .it_value.tv_usec = o->it_value.tv_usec},
  876. sizeof(struct itimerval32));
  877. }
  878. static inline void
  879. jiffies_to_timeval32(unsigned long jiffies, struct timeval32 *value)
  880. {
  881. value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
  882. value->tv_sec = jiffies / HZ;
  883. }
  884. SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
  885. struct timezone __user *, tz)
  886. {
  887. if (tv) {
  888. struct timespec64 kts;
  889. ktime_get_real_ts64(&kts);
  890. if (put_tv32(tv, &kts))
  891. return -EFAULT;
  892. }
  893. if (tz) {
  894. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  895. return -EFAULT;
  896. }
  897. return 0;
  898. }
  899. SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
  900. struct timezone __user *, tz)
  901. {
  902. struct timespec64 kts;
  903. struct timezone ktz;
  904. if (tv) {
  905. if (get_tv32(&kts, tv))
  906. return -EFAULT;
  907. }
  908. if (tz) {
  909. if (copy_from_user(&ktz, tz, sizeof(*tz)))
  910. return -EFAULT;
  911. }
  912. return do_sys_settimeofday64(tv ? &kts : NULL, tz ? &ktz : NULL);
  913. }
  914. asmlinkage long sys_ni_posix_timers(void);
  915. SYSCALL_DEFINE2(osf_getitimer, int, which, struct itimerval32 __user *, it)
  916. {
  917. struct itimerval kit;
  918. int error;
  919. if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
  920. return sys_ni_posix_timers();
  921. error = do_getitimer(which, &kit);
  922. if (!error && put_it32(it, &kit))
  923. error = -EFAULT;
  924. return error;
  925. }
  926. SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
  927. struct itimerval32 __user *, out)
  928. {
  929. struct itimerval kin, kout;
  930. int error;
  931. if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
  932. return sys_ni_posix_timers();
  933. if (in) {
  934. if (get_it32(&kin, in))
  935. return -EFAULT;
  936. } else
  937. memset(&kin, 0, sizeof(kin));
  938. error = do_setitimer(which, &kin, out ? &kout : NULL);
  939. if (error || !out)
  940. return error;
  941. if (put_it32(out, &kout))
  942. return -EFAULT;
  943. return 0;
  944. }
  945. SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
  946. struct timeval32 __user *, tvs)
  947. {
  948. struct timespec64 tv[2];
  949. if (tvs) {
  950. if (get_tv32(&tv[0], &tvs[0]) ||
  951. get_tv32(&tv[1], &tvs[1]))
  952. return -EFAULT;
  953. if (tv[0].tv_nsec < 0 || tv[0].tv_nsec >= 1000000000 ||
  954. tv[1].tv_nsec < 0 || tv[1].tv_nsec >= 1000000000)
  955. return -EINVAL;
  956. }
  957. return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
  958. }
  959. SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
  960. fd_set __user *, exp, struct timeval32 __user *, tvp)
  961. {
  962. struct timespec64 end_time, *to = NULL;
  963. if (tvp) {
  964. struct timespec64 tv;
  965. to = &end_time;
  966. if (get_tv32(&tv, tvp))
  967. return -EFAULT;
  968. if (tv.tv_sec < 0 || tv.tv_nsec < 0)
  969. return -EINVAL;
  970. if (poll_select_set_timeout(to, tv.tv_sec, tv.tv_nsec))
  971. return -EINVAL;
  972. }
  973. /* OSF does not copy back the remaining time. */
  974. return core_sys_select(n, inp, outp, exp, to);
  975. }
  976. struct rusage32 {
  977. struct timeval32 ru_utime; /* user time used */
  978. struct timeval32 ru_stime; /* system time used */
  979. long ru_maxrss; /* maximum resident set size */
  980. long ru_ixrss; /* integral shared memory size */
  981. long ru_idrss; /* integral unshared data size */
  982. long ru_isrss; /* integral unshared stack size */
  983. long ru_minflt; /* page reclaims */
  984. long ru_majflt; /* page faults */
  985. long ru_nswap; /* swaps */
  986. long ru_inblock; /* block input operations */
  987. long ru_oublock; /* block output operations */
  988. long ru_msgsnd; /* messages sent */
  989. long ru_msgrcv; /* messages received */
  990. long ru_nsignals; /* signals received */
  991. long ru_nvcsw; /* voluntary context switches */
  992. long ru_nivcsw; /* involuntary " */
  993. };
  994. SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
  995. {
  996. struct rusage32 r;
  997. u64 utime, stime;
  998. unsigned long utime_jiffies, stime_jiffies;
  999. if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  1000. return -EINVAL;
  1001. memset(&r, 0, sizeof(r));
  1002. switch (who) {
  1003. case RUSAGE_SELF:
  1004. task_cputime(current, &utime, &stime);
  1005. utime_jiffies = nsecs_to_jiffies(utime);
  1006. stime_jiffies = nsecs_to_jiffies(stime);
  1007. jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
  1008. jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
  1009. r.ru_minflt = current->min_flt;
  1010. r.ru_majflt = current->maj_flt;
  1011. break;
  1012. case RUSAGE_CHILDREN:
  1013. utime_jiffies = nsecs_to_jiffies(current->signal->cutime);
  1014. stime_jiffies = nsecs_to_jiffies(current->signal->cstime);
  1015. jiffies_to_timeval32(utime_jiffies, &r.ru_utime);
  1016. jiffies_to_timeval32(stime_jiffies, &r.ru_stime);
  1017. r.ru_minflt = current->signal->cmin_flt;
  1018. r.ru_majflt = current->signal->cmaj_flt;
  1019. break;
  1020. }
  1021. return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
  1022. }
  1023. SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
  1024. struct rusage32 __user *, ur)
  1025. {
  1026. struct rusage r;
  1027. long err = kernel_wait4(pid, ustatus, options, &r);
  1028. if (err <= 0)
  1029. return err;
  1030. if (!ur)
  1031. return err;
  1032. if (put_tv_to_tv32(&ur->ru_utime, &r.ru_utime))
  1033. return -EFAULT;
  1034. if (put_tv_to_tv32(&ur->ru_stime, &r.ru_stime))
  1035. return -EFAULT;
  1036. if (copy_to_user(&ur->ru_maxrss, &r.ru_maxrss,
  1037. sizeof(struct rusage32) - offsetof(struct rusage32, ru_maxrss)))
  1038. return -EFAULT;
  1039. return err;
  1040. }
  1041. /*
  1042. * I don't know what the parameters are: the first one
  1043. * seems to be a timeval pointer, and I suspect the second
  1044. * one is the time remaining.. Ho humm.. No documentation.
  1045. */
  1046. SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
  1047. struct timeval32 __user *, remain)
  1048. {
  1049. struct timespec64 tmp;
  1050. unsigned long ticks;
  1051. if (get_tv32(&tmp, sleep))
  1052. goto fault;
  1053. ticks = timespec64_to_jiffies(&tmp);
  1054. ticks = schedule_timeout_interruptible(ticks);
  1055. if (remain) {
  1056. jiffies_to_timespec64(ticks, &tmp);
  1057. if (put_tv32(remain, &tmp))
  1058. goto fault;
  1059. }
  1060. return 0;
  1061. fault:
  1062. return -EFAULT;
  1063. }
  1064. struct timex32 {
  1065. unsigned int modes; /* mode selector */
  1066. long offset; /* time offset (usec) */
  1067. long freq; /* frequency offset (scaled ppm) */
  1068. long maxerror; /* maximum error (usec) */
  1069. long esterror; /* estimated error (usec) */
  1070. int status; /* clock command/status */
  1071. long constant; /* pll time constant */
  1072. long precision; /* clock precision (usec) (read only) */
  1073. long tolerance; /* clock frequency tolerance (ppm)
  1074. * (read only)
  1075. */
  1076. struct timeval32 time; /* (read only) */
  1077. long tick; /* (modified) usecs between clock ticks */
  1078. long ppsfreq; /* pps frequency (scaled ppm) (ro) */
  1079. long jitter; /* pps jitter (us) (ro) */
  1080. int shift; /* interval duration (s) (shift) (ro) */
  1081. long stabil; /* pps stability (scaled ppm) (ro) */
  1082. long jitcnt; /* jitter limit exceeded (ro) */
  1083. long calcnt; /* calibration intervals (ro) */
  1084. long errcnt; /* calibration errors (ro) */
  1085. long stbcnt; /* stability limit exceeded (ro) */
  1086. int :32; int :32; int :32; int :32;
  1087. int :32; int :32; int :32; int :32;
  1088. int :32; int :32; int :32; int :32;
  1089. };
  1090. SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
  1091. {
  1092. struct timex txc;
  1093. int ret;
  1094. /* copy relevant bits of struct timex. */
  1095. if (copy_from_user(&txc, txc_p, offsetof(struct timex32, time)) ||
  1096. copy_from_user(&txc.tick, &txc_p->tick, sizeof(struct timex32) -
  1097. offsetof(struct timex32, tick)))
  1098. return -EFAULT;
  1099. ret = do_adjtimex(&txc);
  1100. if (ret < 0)
  1101. return ret;
  1102. /* copy back to timex32 */
  1103. if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
  1104. (copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
  1105. offsetof(struct timex32, tick))) ||
  1106. (put_tv_to_tv32(&txc_p->time, &txc.time)))
  1107. return -EFAULT;
  1108. return ret;
  1109. }
  1110. /* Get an address range which is currently unmapped. Similar to the
  1111. generic version except that we know how to honor ADDR_LIMIT_32BIT. */
  1112. static unsigned long
  1113. arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
  1114. unsigned long limit)
  1115. {
  1116. struct vm_unmapped_area_info info;
  1117. info.flags = 0;
  1118. info.length = len;
  1119. info.low_limit = addr;
  1120. info.high_limit = limit;
  1121. info.align_mask = 0;
  1122. info.align_offset = 0;
  1123. return vm_unmapped_area(&info);
  1124. }
  1125. unsigned long
  1126. arch_get_unmapped_area(struct file *filp, unsigned long addr,
  1127. unsigned long len, unsigned long pgoff,
  1128. unsigned long flags)
  1129. {
  1130. unsigned long limit;
  1131. /* "32 bit" actually means 31 bit, since pointers sign extend. */
  1132. if (current->personality & ADDR_LIMIT_32BIT)
  1133. limit = 0x80000000;
  1134. else
  1135. limit = TASK_SIZE;
  1136. if (len > limit)
  1137. return -ENOMEM;
  1138. if (flags & MAP_FIXED)
  1139. return addr;
  1140. /* First, see if the given suggestion fits.
  1141. The OSF/1 loader (/sbin/loader) relies on us returning an
  1142. address larger than the requested if one exists, which is
  1143. a terribly broken way to program.
  1144. That said, I can see the use in being able to suggest not
  1145. merely specific addresses, but regions of memory -- perhaps
  1146. this feature should be incorporated into all ports? */
  1147. if (addr) {
  1148. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
  1149. if (addr != (unsigned long) -ENOMEM)
  1150. return addr;
  1151. }
  1152. /* Next, try allocating at TASK_UNMAPPED_BASE. */
  1153. addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
  1154. len, limit);
  1155. if (addr != (unsigned long) -ENOMEM)
  1156. return addr;
  1157. /* Finally, try allocating in low memory. */
  1158. addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
  1159. return addr;
  1160. }
  1161. #ifdef CONFIG_OSF4_COMPAT
  1162. /* Clear top 32 bits of iov_len in the user's buffer for
  1163. compatibility with old versions of OSF/1 where iov_len
  1164. was defined as int. */
  1165. static int
  1166. osf_fix_iov_len(const struct iovec __user *iov, unsigned long count)
  1167. {
  1168. unsigned long i;
  1169. for (i = 0 ; i < count ; i++) {
  1170. int __user *iov_len_high = (int __user *)&iov[i].iov_len + 1;
  1171. if (put_user(0, iov_len_high))
  1172. return -EFAULT;
  1173. }
  1174. return 0;
  1175. }
  1176. SYSCALL_DEFINE3(osf_readv, unsigned long, fd,
  1177. const struct iovec __user *, vector, unsigned long, count)
  1178. {
  1179. if (unlikely(personality(current->personality) == PER_OSF4))
  1180. if (osf_fix_iov_len(vector, count))
  1181. return -EFAULT;
  1182. return sys_readv(fd, vector, count);
  1183. }
  1184. SYSCALL_DEFINE3(osf_writev, unsigned long, fd,
  1185. const struct iovec __user *, vector, unsigned long, count)
  1186. {
  1187. if (unlikely(personality(current->personality) == PER_OSF4))
  1188. if (osf_fix_iov_len(vector, count))
  1189. return -EFAULT;
  1190. return sys_writev(fd, vector, count);
  1191. }
  1192. #endif
  1193. SYSCALL_DEFINE2(osf_getpriority, int, which, int, who)
  1194. {
  1195. int prio = sys_getpriority(which, who);
  1196. if (prio >= 0) {
  1197. /* Return value is the unbiased priority, i.e. 20 - prio.
  1198. This does result in negative return values, so signal
  1199. no error */
  1200. force_successful_syscall_return();
  1201. prio = 20 - prio;
  1202. }
  1203. return prio;
  1204. }
  1205. SYSCALL_DEFINE0(getxuid)
  1206. {
  1207. current_pt_regs()->r20 = sys_geteuid();
  1208. return sys_getuid();
  1209. }
  1210. SYSCALL_DEFINE0(getxgid)
  1211. {
  1212. current_pt_regs()->r20 = sys_getegid();
  1213. return sys_getgid();
  1214. }
  1215. SYSCALL_DEFINE0(getxpid)
  1216. {
  1217. current_pt_regs()->r20 = sys_getppid();
  1218. return sys_getpid();
  1219. }
  1220. SYSCALL_DEFINE0(alpha_pipe)
  1221. {
  1222. int fd[2];
  1223. int res = do_pipe_flags(fd, 0);
  1224. if (!res) {
  1225. /* The return values are in $0 and $20. */
  1226. current_pt_regs()->r20 = fd[1];
  1227. res = fd[0];
  1228. }
  1229. return res;
  1230. }
  1231. SYSCALL_DEFINE1(sethae, unsigned long, val)
  1232. {
  1233. current_pt_regs()->hae = val;
  1234. return 0;
  1235. }