1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/capability.h>
26#include <linux/file.h>
27#include <linux/fs.h>
28#include <linux/namei.h>
29#include <linux/sched.h>
30#include <linux/slab.h>
31#include <linux/smp_lock.h>
32#include <linux/syscalls.h>
33#include <linux/utsname.h>
34#include <linux/vfs.h>
35#include <linux/vmalloc.h>
36
37#include <asm/errno.h>
38#include <asm/pgalloc.h>
39#include <asm/uaccess.h>
40
41unsigned long hpux_brk(unsigned long addr)
42{
43
44 return sys_brk(addr + PAGE_SIZE);
45}
46
47int hpux_sbrk(void)
48{
49 return -ENOSYS;
50}
51
52
53
54int hpux_nice(int priority_change)
55{
56 return -ENOSYS;
57}
58
59int hpux_ptrace(void)
60{
61 return -ENOSYS;
62}
63
64int hpux_wait(int __user *stat_loc)
65{
66 return sys_waitpid(-1, stat_loc, 0);
67}
68
69int hpux_setpgrp(void)
70{
71 return sys_setpgid(0,0);
72}
73
74int hpux_setpgrp3(void)
75{
76 return hpux_setpgrp();
77}
78
79#define _SC_CPU_VERSION 10001
80#define _SC_OPEN_MAX 4
81#define CPU_PA_RISC1_1 0x210
82
83int hpux_sysconf(int which)
84{
85 switch (which) {
86 case _SC_CPU_VERSION:
87 return CPU_PA_RISC1_1;
88 case _SC_OPEN_MAX:
89 return INT_MAX;
90 default:
91 return -EINVAL;
92 }
93}
94
95
96
97#define HPUX_UTSLEN 9
98#define HPUX_SNLEN 15
99
100struct hpux_utsname {
101 char sysname[HPUX_UTSLEN];
102 char nodename[HPUX_UTSLEN];
103 char release[HPUX_UTSLEN];
104 char version[HPUX_UTSLEN];
105 char machine[HPUX_UTSLEN];
106 char idnumber[HPUX_SNLEN];
107} ;
108
109struct hpux_ustat {
110 int32_t f_tfree;
111 u_int32_t f_tinode;
112 char f_fname[6];
113 char f_fpack[6];
114 u_int32_t f_blksize;
115};
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138static int hpux_ustat(dev_t dev, struct hpux_ustat __user *ubuf)
139{
140 struct super_block *s;
141 struct hpux_ustat tmp;
142 struct kstatfs sbuf;
143 int err = -EINVAL;
144
145 s = user_get_super(dev);
146 if (s == NULL)
147 goto out;
148 err = vfs_statfs(s->s_root, &sbuf);
149 drop_super(s);
150 if (err)
151 goto out;
152
153 memset(&tmp,0,sizeof(tmp));
154
155 tmp.f_tfree = (int32_t)sbuf.f_bfree;
156 tmp.f_tinode = (u_int32_t)sbuf.f_ffree;
157 tmp.f_blksize = (u_int32_t)sbuf.f_bsize;
158
159 err = copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
160out:
161 return err;
162}
163
164
165
166
167
168
169
170typedef int32_t hpux_fsid_t[2];
171typedef uint16_t hpux_site_t;
172
173struct hpux_statfs {
174 int32_t f_type;
175 int32_t f_bsize;
176 int32_t f_blocks;
177 int32_t f_bfree;
178 int32_t f_bavail;
179 int32_t f_files;
180 int32_t f_ffree;
181 hpux_fsid_t f_fsid;
182 int32_t f_magic;
183 int32_t f_featurebits;
184 int32_t f_spare[4];
185 hpux_site_t f_cnode;
186 int16_t f_pad;
187};
188
189static int vfs_statfs_hpux(struct dentry *dentry, struct hpux_statfs *buf)
190{
191 struct kstatfs st;
192 int retval;
193
194 retval = vfs_statfs(dentry, &st);
195 if (retval)
196 return retval;
197
198 memset(buf, 0, sizeof(*buf));
199 buf->f_type = st.f_type;
200 buf->f_bsize = st.f_bsize;
201 buf->f_blocks = st.f_blocks;
202 buf->f_bfree = st.f_bfree;
203 buf->f_bavail = st.f_bavail;
204 buf->f_files = st.f_files;
205 buf->f_ffree = st.f_ffree;
206 buf->f_fsid[0] = st.f_fsid.val[0];
207 buf->f_fsid[1] = st.f_fsid.val[1];
208
209 return 0;
210}
211
212
213asmlinkage long hpux_statfs(const char __user *pathname,
214 struct hpux_statfs __user *buf)
215{
216 struct path path;
217 int error;
218
219 error = user_path(pathname, &path);
220 if (!error) {
221 struct hpux_statfs tmp;
222 error = vfs_statfs_hpux(path.dentry, &tmp);
223 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
224 error = -EFAULT;
225 path_put(&path);
226 }
227 return error;
228}
229
230asmlinkage long hpux_fstatfs(unsigned int fd, struct hpux_statfs __user * buf)
231{
232 struct file *file;
233 struct hpux_statfs tmp;
234 int error;
235
236 error = -EBADF;
237 file = fget(fd);
238 if (!file)
239 goto out;
240 error = vfs_statfs_hpux(file->f_path.dentry, &tmp);
241 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
242 error = -EFAULT;
243 fput(file);
244 out:
245 return error;
246}
247
248
249
250
251
252
253
254
255
256
257
258static int hpux_uname(struct hpux_utsname __user *name)
259{
260 int error;
261
262 if (!name)
263 return -EFAULT;
264 if (!access_ok(VERIFY_WRITE,name,sizeof(struct hpux_utsname)))
265 return -EFAULT;
266
267 down_read(&uts_sem);
268
269 error = __copy_to_user(&name->sysname, &utsname()->sysname,
270 HPUX_UTSLEN - 1);
271 error |= __put_user(0, name->sysname + HPUX_UTSLEN - 1);
272 error |= __copy_to_user(&name->nodename, &utsname()->nodename,
273 HPUX_UTSLEN - 1);
274 error |= __put_user(0, name->nodename + HPUX_UTSLEN - 1);
275 error |= __copy_to_user(&name->release, &utsname()->release,
276 HPUX_UTSLEN - 1);
277 error |= __put_user(0, name->release + HPUX_UTSLEN - 1);
278 error |= __copy_to_user(&name->version, &utsname()->version,
279 HPUX_UTSLEN - 1);
280 error |= __put_user(0, name->version + HPUX_UTSLEN - 1);
281 error |= __copy_to_user(&name->machine, &utsname()->machine,
282 HPUX_UTSLEN - 1);
283 error |= __put_user(0, name->machine + HPUX_UTSLEN - 1);
284
285 up_read(&uts_sem);
286
287
288
289
290#if 0
291 error |= __put_user(0,name->idnumber);
292 error |= __put_user(0,name->idnumber+HPUX_SNLEN-1);
293#endif
294
295 error = error ? -EFAULT : 0;
296
297 return error;
298}
299
300
301
302
303int hpux_utssys(char __user *ubuf, int n, int type)
304{
305 int len;
306 int error;
307 switch( type ) {
308 case 0:
309
310 return hpux_uname((struct hpux_utsname __user *)ubuf);
311 break ;
312 case 1:
313
314 return -EFAULT ;
315 break ;
316 case 2:
317
318 return hpux_ustat(new_decode_dev(n),
319 (struct hpux_ustat __user *)ubuf);
320 break;
321 case 3:
322
323
324
325
326
327
328
329 if (!capable(CAP_SYS_ADMIN))
330 return -EPERM;
331
332 if ( n <= 0 )
333 return -EINVAL ;
334
335 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
336 return sys_sethostname(ubuf, len);
337 break ;
338 case 4:
339
340
341
342
343 if (!capable(CAP_SYS_ADMIN))
344 return -EPERM;
345
346 if ( n <= 0 )
347 return -EINVAL ;
348
349 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
350 return sys_sethostname(ubuf, len);
351 break ;
352 case 5:
353
354
355
356
357
358 if ( n <= 0 )
359 return -EINVAL ;
360 return sys_gethostname(ubuf, n);
361 break ;
362 case 6:
363
364
365
366
367
368
369
370
371 if (!capable(CAP_SYS_ADMIN))
372 return -EPERM;
373
374 if ( n <= 0 )
375 return -EINVAL ;
376
377 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
378
379
380 down_write(&uts_sem);
381 error = -EFAULT;
382 if (!copy_from_user(utsname()->sysname, ubuf, len)) {
383 utsname()->sysname[len] = 0;
384 error = 0;
385 }
386 up_write(&uts_sem);
387 return error;
388 break ;
389 case 7:
390
391
392
393
394
395
396
397
398 if (!capable(CAP_SYS_ADMIN))
399 return -EPERM;
400
401 if ( n <= 0 )
402 return -EINVAL ;
403
404 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
405
406
407 down_write(&uts_sem);
408 error = -EFAULT;
409 if (!copy_from_user(utsname()->release, ubuf, len)) {
410 utsname()->release[len] = 0;
411 error = 0;
412 }
413 up_write(&uts_sem);
414 return error;
415 break ;
416 default:
417
418
419
420 return -EFAULT ;
421 }
422}
423
424int hpux_getdomainname(char __user *name, int len)
425{
426 int nlen;
427 int err = -EFAULT;
428
429 down_read(&uts_sem);
430
431 nlen = strlen(utsname()->domainname) + 1;
432
433 if (nlen < len)
434 len = nlen;
435 if(len > __NEW_UTS_LEN)
436 goto done;
437 if(copy_to_user(name, utsname()->domainname, len))
438 goto done;
439 err = 0;
440done:
441 up_read(&uts_sem);
442 return err;
443
444}
445
446int hpux_pipe(int *kstack_fildes)
447{
448 return do_pipe_flags(kstack_fildes, 0);
449}
450
451
452int hpux_lockf(int fildes, int function, off_t size)
453{
454 return 0;
455}
456
457int hpux_sysfs(int opcode, unsigned long arg1, unsigned long arg2)
458{
459 char *fsname = NULL;
460 int len = 0;
461 int fstype;
462
463
464
465 printk(KERN_DEBUG "in hpux_sysfs\n");
466 printk(KERN_DEBUG "hpux_sysfs called with opcode = %d\n", opcode);
467 printk(KERN_DEBUG "hpux_sysfs called with arg1='%lx'\n", arg1);
468
469 if ( opcode == 1 ) {
470 char __user *user_fsname = (char __user *)arg1;
471 len = strlen_user(user_fsname);
472 printk(KERN_DEBUG "len of arg1 = %d\n", len);
473 if (len == 0)
474 return 0;
475 fsname = kmalloc(len, GFP_KERNEL);
476 if (!fsname) {
477 printk(KERN_DEBUG "failed to kmalloc fsname\n");
478 return 0;
479 }
480
481 if (copy_from_user(fsname, user_fsname, len)) {
482 printk(KERN_DEBUG "failed to copy_from_user fsname\n");
483 kfree(fsname);
484 return 0;
485 }
486
487
488 fsname[len] = '\0';
489
490 printk(KERN_DEBUG "that is '%s' as (char *)\n", fsname);
491 if ( !strcmp(fsname, "hfs") ) {
492 fstype = 0;
493 } else {
494 fstype = 0;
495 }
496
497 kfree(fsname);
498
499 printk(KERN_DEBUG "returning fstype=%d\n", fstype);
500 return fstype;
501 }
502
503
504 return 0;
505}
506
507
508
509static const char * const syscall_names[] = {
510 "nosys",
511 "exit",
512 "fork",
513 "read",
514 "write",
515 "open",
516 "close",
517 "wait",
518 "creat",
519 "link",
520 "unlink",
521 "execv",
522 "chdir",
523 "time",
524 "mknod",
525 "chmod",
526 "chown",
527 "brk",
528 "lchmod",
529 "lseek",
530 "getpid",
531 "mount",
532 "umount",
533 "setuid",
534 "getuid",
535 "stime",
536 "ptrace",
537 "alarm",
538 NULL,
539 "pause",
540 "utime",
541 "stty",
542 "gtty",
543 "access",
544 "nice",
545 "ftime",
546 "sync",
547 "kill",
548 "stat",
549 "setpgrp3",
550 "lstat",
551 "dup",
552 "pipe",
553 "times",
554 "profil",
555 "ki_call",
556 "setgid",
557 "getgid",
558 NULL,
559 NULL,
560 NULL,
561 "acct",
562 "set_userthreadid",
563 NULL,
564 "ioctl",
565 "reboot",
566 "symlink",
567 "utssys",
568 "readlink",
569 "execve",
570 "umask",
571 "chroot",
572 "fcntl",
573 "ulimit",
574 NULL,
575 NULL,
576 "vfork",
577 NULL,
578 NULL,
579 NULL,
580 NULL,
581 "mmap",
582 NULL,
583 "munmap",
584 "mprotect",
585 "madvise",
586 "vhangup",
587 "swapoff",
588 NULL,
589 "getgroups",
590 "setgroups",
591 "getpgrp2",
592 "setpgid/setpgrp2",
593 "setitimer",
594 "wait3",
595 "swapon",
596 "getitimer",
597 NULL,
598 NULL,
599 NULL,
600 "dup2",
601 NULL,
602 "fstat",
603 "select",
604 NULL,
605 "fsync",
606 "setpriority",
607 NULL,
608 NULL,
609 NULL,
610 "getpriority",
611 NULL,
612 NULL,
613 NULL,
614 NULL,
615 NULL,
616 NULL,
617 NULL,
618 "sigvector",
619 "sigblock",
620 "sigsetmask",
621 "sigpause",
622 "sigstack",
623 NULL,
624 NULL,
625 NULL,
626 "gettimeofday",
627 "getrusage",
628 NULL,
629 NULL,
630 "readv",
631 "writev",
632 "settimeofday",
633 "fchown",
634 "fchmod",
635 NULL,
636 "setresuid",
637 "setresgid",
638 "rename",
639 "truncate",
640 "ftruncate",
641 NULL,
642 "sysconf",
643 NULL,
644 NULL,
645 NULL,
646 "mkdir",
647 "rmdir",
648 NULL,
649 "sigcleanup",
650 "setcore",
651 NULL,
652 "gethostid",
653 "sethostid",
654 "getrlimit",
655 "setrlimit",
656 NULL,
657 NULL,
658 "quotactl",
659 "get_sysinfo",
660 NULL,
661 "privgrp",
662 "rtprio",
663 "plock",
664 NULL,
665 "lockf",
666 "semget",
667 NULL,
668 "semop",
669 "msgget",
670 NULL,
671 "msgsnd",
672 "msgrcv",
673 "shmget",
674 NULL,
675 "shmat",
676 "shmdt",
677 NULL,
678 "csp/nsp_init",
679 "cluster",
680 "mkrnod",
681 "test",
682 "unsp_open",
683 NULL,
684 "getcontext",
685 "osetcontext",
686 "bigio",
687 "pipenode",
688 "lsync",
689 "getmachineid",
690 "cnodeid/mysite",
691 "cnodes/sitels",
692 "swapclients",
693 "rmtprocess",
694 "dskless_stats",
695 "sigprocmask",
696 "sigpending",
697 "sigsuspend",
698 "sigaction",
699 NULL,
700 "nfssvc",
701 "getfh",
702 "getdomainname",
703 "setdomainname",
704 "async_daemon",
705 "getdirentries",
706 NULL,
707 NULL,
708 "vfsmount",
709 NULL,
710 "waitpid",
711 NULL,
712 NULL,
713 NULL,
714 NULL,
715 NULL,
716 NULL,
717 NULL,
718 NULL,
719 NULL,
720 NULL,
721 NULL,
722 NULL,
723 NULL,
724 NULL,
725 NULL,
726 NULL,
727 NULL,
728 NULL,
729 NULL,
730 NULL,
731 NULL,
732 NULL,
733 NULL,
734 "sigsetreturn",
735 "sigsetstatemask",
736 "bfactl",
737 "cs",
738 "cds",
739 NULL,
740 "pathconf",
741 "fpathconf",
742 NULL,
743 NULL,
744 "nfs_fcntl",
745 "ogetacl",
746 "ofgetacl",
747 "osetacl",
748 "ofsetacl",
749 "pstat",
750 "getaudid",
751 "setaudid",
752 "getaudproc",
753 "setaudproc",
754 "getevent",
755 "setevent",
756 "audwrite",
757 "audswitch",
758 "audctl",
759 "ogetaccess",
760 "fsctl",
761 "ulconnect",
762 "ulcontrol",
763 "ulcreate",
764 "uldest",
765 "ulrecv",
766 "ulrecvcn",
767 "ulsend",
768 "ulshutdown",
769 "swapfs",
770 "fss",
771 NULL,
772 NULL,
773 NULL,
774 NULL,
775 NULL,
776 NULL,
777 "tsync",
778 "getnumfds",
779 "poll",
780 "getmsg",
781 "putmsg",
782 "fchdir",
783 "getmount_cnt",
784 "getmount_entry",
785 "accept",
786 "bind",
787 "connect",
788 "getpeername",
789 "getsockname",
790 "getsockopt",
791 "listen",
792 "recv",
793 "recvfrom",
794 "recvmsg",
795 "send",
796 "sendmsg",
797 "sendto",
798 "setsockopt",
799 "shutdown",
800 "socket",
801 "socketpair",
802 "proc_open",
803 "proc_close",
804 "proc_send",
805 "proc_recv",
806 "proc_sendrecv",
807 "proc_syscall",
808 "ipccreate",
809 "ipcname",
810 "ipcnamerase",
811 "ipclookup",
812 "ipcselect",
813 "ipcconnect",
814 "ipcrecvcn",
815 "ipcsend",
816 "ipcrecv",
817 "ipcgetnodename",
818 "ipcsetnodename",
819 "ipccontrol",
820 "ipcshutdown",
821 "ipcdest",
822 "semctl",
823 "msgctl",
824 "shmctl",
825 "mpctl",
826 "exportfs",
827 "getpmsg",
828 "putpmsg",
829 "strioctl",
830 "msync",
831 "msleep",
832 "mwakeup",
833 "msem_init",
834 "msem_remove",
835 "adjtime",
836 "kload",
837 "fattach",
838 "fdetach",
839 "serialize",
840 "statvfs",
841 "fstatvfs",
842 "lchown",
843 "getsid",
844 "sysfs",
845 NULL,
846 NULL,
847 "sched_setparam",
848 "sched_getparam",
849 "sched_setscheduler",
850 "sched_getscheduler",
851 "sched_yield",
852 "sched_get_priority_max",
853 "sched_get_priority_min",
854 "sched_rr_get_interval",
855 "clock_settime",
856 "clock_gettime",
857 "clock_getres",
858 "timer_create",
859 "timer_delete",
860 "timer_settime",
861 "timer_gettime",
862 "timer_getoverrun",
863 "nanosleep",
864 "toolbox",
865 NULL,
866 "getdents",
867 "getcontext",
868 "sysinfo",
869 "fcntl64",
870 "ftruncate64",
871 "fstat64",
872 "getdirentries64",
873 "getrlimit64",
874 "lockf64",
875 "lseek64",
876 "lstat64",
877 "mmap64",
878 "setrlimit64",
879 "stat64",
880 "truncate64",
881 "ulimit64",
882 NULL,
883 NULL,
884 NULL,
885 NULL,
886 NULL,
887 NULL,
888 NULL,
889 NULL,
890 "setcontext",
891 "sigaltstack",
892 "waitid",
893 "setpgrp",
894 "recvmsg2",
895 "sendmsg2",
896 "socket2",
897 "socketpair2",
898 "setregid",
899 "lwp_create",
900 "lwp_terminate",
901 "lwp_wait",
902 "lwp_suspend",
903 "lwp_resume",
904 "lwp_self",
905 "lwp_abort_syscall",
906 "lwp_info",
907 "lwp_kill",
908 "ksleep",
909 "kwakeup",
910 "ksleep_abort",
911 "lwp_proc_info",
912 "lwp_exit",
913 "lwp_continue",
914 "getacl",
915 "fgetacl",
916 "setacl",
917 "fsetacl",
918 "getaccess",
919 "lwp_mutex_init",
920 "lwp_mutex_lock_sys",
921 "lwp_mutex_unlock",
922 "lwp_cond_init",
923 "lwp_cond_signal",
924 "lwp_cond_broadcast",
925 "lwp_cond_wait_sys",
926 "lwp_getscheduler",
927 "lwp_setscheduler",
928 "lwp_getprivate",
929 "lwp_setprivate",
930 "lwp_detach",
931 "mlock",
932 "munlock",
933 "mlockall",
934 "munlockall",
935 "shm_open",
936 "shm_unlink",
937 "sigqueue",
938 "sigwaitinfo",
939 "sigtimedwait",
940 "sigwait",
941 "aio_read",
942 "aio_write",
943 "lio_listio",
944 "aio_error",
945 "aio_return",
946 "aio_cancel",
947 "aio_suspend",
948 "aio_fsync",
949 "mq_open",
950 "mq_unlink",
951 "mq_send",
952 "mq_receive",
953 "mq_notify",
954 "mq_setattr",
955 "mq_getattr",
956 "ksem_open",
957 "ksem_unlink",
958 "ksem_close",
959 "ksem_destroy",
960 "lw_sem_incr",
961 "lw_sem_decr",
962 "lw_sem_read",
963 "mq_close",
964};
965static const int syscall_names_max = 453;
966
967int
968hpux_unimplemented(unsigned long arg1,unsigned long arg2,unsigned long arg3,
969 unsigned long arg4,unsigned long arg5,unsigned long arg6,
970 unsigned long arg7,unsigned long sc_num)
971{
972
973
974
975 const char *name = NULL;
976 if ( sc_num <= syscall_names_max && sc_num >= 0 ) {
977 name = syscall_names[sc_num];
978 }
979
980 if ( name ) {
981 printk(KERN_DEBUG "Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
982 sc_num, name);
983 } else {
984 printk(KERN_DEBUG "Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
985 sc_num);
986 }
987
988 printk(KERN_DEBUG " Args: %lx %lx %lx %lx %lx %lx %lx\n",
989 arg1, arg2, arg3, arg4, arg5, arg6, arg7);
990
991 return -ENOSYS;
992}
993