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 int error;
449
450 lock_kernel();
451 error = do_pipe_flags(kstack_fildes, 0);
452 unlock_kernel();
453 return error;
454}
455
456
457int hpux_lockf(int fildes, int function, off_t size)
458{
459 return 0;
460}
461
462int hpux_sysfs(int opcode, unsigned long arg1, unsigned long arg2)
463{
464 char *fsname = NULL;
465 int len = 0;
466 int fstype;
467
468
469
470 printk(KERN_DEBUG "in hpux_sysfs\n");
471 printk(KERN_DEBUG "hpux_sysfs called with opcode = %d\n", opcode);
472 printk(KERN_DEBUG "hpux_sysfs called with arg1='%lx'\n", arg1);
473
474 if ( opcode == 1 ) {
475 char __user *user_fsname = (char __user *)arg1;
476 len = strlen_user(user_fsname);
477 printk(KERN_DEBUG "len of arg1 = %d\n", len);
478 if (len == 0)
479 return 0;
480 fsname = kmalloc(len, GFP_KERNEL);
481 if (!fsname) {
482 printk(KERN_DEBUG "failed to kmalloc fsname\n");
483 return 0;
484 }
485
486 if (copy_from_user(fsname, user_fsname, len)) {
487 printk(KERN_DEBUG "failed to copy_from_user fsname\n");
488 kfree(fsname);
489 return 0;
490 }
491
492
493 fsname[len] = '\0';
494
495 printk(KERN_DEBUG "that is '%s' as (char *)\n", fsname);
496 if ( !strcmp(fsname, "hfs") ) {
497 fstype = 0;
498 } else {
499 fstype = 0;
500 }
501
502 kfree(fsname);
503
504 printk(KERN_DEBUG "returning fstype=%d\n", fstype);
505 return fstype;
506 }
507
508
509 return 0;
510}
511
512
513
514static const char * const syscall_names[] = {
515 "nosys",
516 "exit",
517 "fork",
518 "read",
519 "write",
520 "open",
521 "close",
522 "wait",
523 "creat",
524 "link",
525 "unlink",
526 "execv",
527 "chdir",
528 "time",
529 "mknod",
530 "chmod",
531 "chown",
532 "brk",
533 "lchmod",
534 "lseek",
535 "getpid",
536 "mount",
537 "umount",
538 "setuid",
539 "getuid",
540 "stime",
541 "ptrace",
542 "alarm",
543 NULL,
544 "pause",
545 "utime",
546 "stty",
547 "gtty",
548 "access",
549 "nice",
550 "ftime",
551 "sync",
552 "kill",
553 "stat",
554 "setpgrp3",
555 "lstat",
556 "dup",
557 "pipe",
558 "times",
559 "profil",
560 "ki_call",
561 "setgid",
562 "getgid",
563 NULL,
564 NULL,
565 NULL,
566 "acct",
567 "set_userthreadid",
568 NULL,
569 "ioctl",
570 "reboot",
571 "symlink",
572 "utssys",
573 "readlink",
574 "execve",
575 "umask",
576 "chroot",
577 "fcntl",
578 "ulimit",
579 NULL,
580 NULL,
581 "vfork",
582 NULL,
583 NULL,
584 NULL,
585 NULL,
586 "mmap",
587 NULL,
588 "munmap",
589 "mprotect",
590 "madvise",
591 "vhangup",
592 "swapoff",
593 NULL,
594 "getgroups",
595 "setgroups",
596 "getpgrp2",
597 "setpgid/setpgrp2",
598 "setitimer",
599 "wait3",
600 "swapon",
601 "getitimer",
602 NULL,
603 NULL,
604 NULL,
605 "dup2",
606 NULL,
607 "fstat",
608 "select",
609 NULL,
610 "fsync",
611 "setpriority",
612 NULL,
613 NULL,
614 NULL,
615 "getpriority",
616 NULL,
617 NULL,
618 NULL,
619 NULL,
620 NULL,
621 NULL,
622 NULL,
623 "sigvector",
624 "sigblock",
625 "sigsetmask",
626 "sigpause",
627 "sigstack",
628 NULL,
629 NULL,
630 NULL,
631 "gettimeofday",
632 "getrusage",
633 NULL,
634 NULL,
635 "readv",
636 "writev",
637 "settimeofday",
638 "fchown",
639 "fchmod",
640 NULL,
641 "setresuid",
642 "setresgid",
643 "rename",
644 "truncate",
645 "ftruncate",
646 NULL,
647 "sysconf",
648 NULL,
649 NULL,
650 NULL,
651 "mkdir",
652 "rmdir",
653 NULL,
654 "sigcleanup",
655 "setcore",
656 NULL,
657 "gethostid",
658 "sethostid",
659 "getrlimit",
660 "setrlimit",
661 NULL,
662 NULL,
663 "quotactl",
664 "get_sysinfo",
665 NULL,
666 "privgrp",
667 "rtprio",
668 "plock",
669 NULL,
670 "lockf",
671 "semget",
672 NULL,
673 "semop",
674 "msgget",
675 NULL,
676 "msgsnd",
677 "msgrcv",
678 "shmget",
679 NULL,
680 "shmat",
681 "shmdt",
682 NULL,
683 "csp/nsp_init",
684 "cluster",
685 "mkrnod",
686 "test",
687 "unsp_open",
688 NULL,
689 "getcontext",
690 "osetcontext",
691 "bigio",
692 "pipenode",
693 "lsync",
694 "getmachineid",
695 "cnodeid/mysite",
696 "cnodes/sitels",
697 "swapclients",
698 "rmtprocess",
699 "dskless_stats",
700 "sigprocmask",
701 "sigpending",
702 "sigsuspend",
703 "sigaction",
704 NULL,
705 "nfssvc",
706 "getfh",
707 "getdomainname",
708 "setdomainname",
709 "async_daemon",
710 "getdirentries",
711 NULL,
712 NULL,
713 "vfsmount",
714 NULL,
715 "waitpid",
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 NULL,
735 NULL,
736 NULL,
737 NULL,
738 NULL,
739 "sigsetreturn",
740 "sigsetstatemask",
741 "bfactl",
742 "cs",
743 "cds",
744 NULL,
745 "pathconf",
746 "fpathconf",
747 NULL,
748 NULL,
749 "nfs_fcntl",
750 "ogetacl",
751 "ofgetacl",
752 "osetacl",
753 "ofsetacl",
754 "pstat",
755 "getaudid",
756 "setaudid",
757 "getaudproc",
758 "setaudproc",
759 "getevent",
760 "setevent",
761 "audwrite",
762 "audswitch",
763 "audctl",
764 "ogetaccess",
765 "fsctl",
766 "ulconnect",
767 "ulcontrol",
768 "ulcreate",
769 "uldest",
770 "ulrecv",
771 "ulrecvcn",
772 "ulsend",
773 "ulshutdown",
774 "swapfs",
775 "fss",
776 NULL,
777 NULL,
778 NULL,
779 NULL,
780 NULL,
781 NULL,
782 "tsync",
783 "getnumfds",
784 "poll",
785 "getmsg",
786 "putmsg",
787 "fchdir",
788 "getmount_cnt",
789 "getmount_entry",
790 "accept",
791 "bind",
792 "connect",
793 "getpeername",
794 "getsockname",
795 "getsockopt",
796 "listen",
797 "recv",
798 "recvfrom",
799 "recvmsg",
800 "send",
801 "sendmsg",
802 "sendto",
803 "setsockopt",
804 "shutdown",
805 "socket",
806 "socketpair",
807 "proc_open",
808 "proc_close",
809 "proc_send",
810 "proc_recv",
811 "proc_sendrecv",
812 "proc_syscall",
813 "ipccreate",
814 "ipcname",
815 "ipcnamerase",
816 "ipclookup",
817 "ipcselect",
818 "ipcconnect",
819 "ipcrecvcn",
820 "ipcsend",
821 "ipcrecv",
822 "ipcgetnodename",
823 "ipcsetnodename",
824 "ipccontrol",
825 "ipcshutdown",
826 "ipcdest",
827 "semctl",
828 "msgctl",
829 "shmctl",
830 "mpctl",
831 "exportfs",
832 "getpmsg",
833 "putpmsg",
834 "strioctl",
835 "msync",
836 "msleep",
837 "mwakeup",
838 "msem_init",
839 "msem_remove",
840 "adjtime",
841 "kload",
842 "fattach",
843 "fdetach",
844 "serialize",
845 "statvfs",
846 "fstatvfs",
847 "lchown",
848 "getsid",
849 "sysfs",
850 NULL,
851 NULL,
852 "sched_setparam",
853 "sched_getparam",
854 "sched_setscheduler",
855 "sched_getscheduler",
856 "sched_yield",
857 "sched_get_priority_max",
858 "sched_get_priority_min",
859 "sched_rr_get_interval",
860 "clock_settime",
861 "clock_gettime",
862 "clock_getres",
863 "timer_create",
864 "timer_delete",
865 "timer_settime",
866 "timer_gettime",
867 "timer_getoverrun",
868 "nanosleep",
869 "toolbox",
870 NULL,
871 "getdents",
872 "getcontext",
873 "sysinfo",
874 "fcntl64",
875 "ftruncate64",
876 "fstat64",
877 "getdirentries64",
878 "getrlimit64",
879 "lockf64",
880 "lseek64",
881 "lstat64",
882 "mmap64",
883 "setrlimit64",
884 "stat64",
885 "truncate64",
886 "ulimit64",
887 NULL,
888 NULL,
889 NULL,
890 NULL,
891 NULL,
892 NULL,
893 NULL,
894 NULL,
895 "setcontext",
896 "sigaltstack",
897 "waitid",
898 "setpgrp",
899 "recvmsg2",
900 "sendmsg2",
901 "socket2",
902 "socketpair2",
903 "setregid",
904 "lwp_create",
905 "lwp_terminate",
906 "lwp_wait",
907 "lwp_suspend",
908 "lwp_resume",
909 "lwp_self",
910 "lwp_abort_syscall",
911 "lwp_info",
912 "lwp_kill",
913 "ksleep",
914 "kwakeup",
915 "ksleep_abort",
916 "lwp_proc_info",
917 "lwp_exit",
918 "lwp_continue",
919 "getacl",
920 "fgetacl",
921 "setacl",
922 "fsetacl",
923 "getaccess",
924 "lwp_mutex_init",
925 "lwp_mutex_lock_sys",
926 "lwp_mutex_unlock",
927 "lwp_cond_init",
928 "lwp_cond_signal",
929 "lwp_cond_broadcast",
930 "lwp_cond_wait_sys",
931 "lwp_getscheduler",
932 "lwp_setscheduler",
933 "lwp_getprivate",
934 "lwp_setprivate",
935 "lwp_detach",
936 "mlock",
937 "munlock",
938 "mlockall",
939 "munlockall",
940 "shm_open",
941 "shm_unlink",
942 "sigqueue",
943 "sigwaitinfo",
944 "sigtimedwait",
945 "sigwait",
946 "aio_read",
947 "aio_write",
948 "lio_listio",
949 "aio_error",
950 "aio_return",
951 "aio_cancel",
952 "aio_suspend",
953 "aio_fsync",
954 "mq_open",
955 "mq_unlink",
956 "mq_send",
957 "mq_receive",
958 "mq_notify",
959 "mq_setattr",
960 "mq_getattr",
961 "ksem_open",
962 "ksem_unlink",
963 "ksem_close",
964 "ksem_destroy",
965 "lw_sem_incr",
966 "lw_sem_decr",
967 "lw_sem_read",
968 "mq_close",
969};
970static const int syscall_names_max = 453;
971
972int
973hpux_unimplemented(unsigned long arg1,unsigned long arg2,unsigned long arg3,
974 unsigned long arg4,unsigned long arg5,unsigned long arg6,
975 unsigned long arg7,unsigned long sc_num)
976{
977
978
979
980 const char *name = NULL;
981 if ( sc_num <= syscall_names_max && sc_num >= 0 ) {
982 name = syscall_names[sc_num];
983 }
984
985 if ( name ) {
986 printk(KERN_DEBUG "Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
987 sc_num, name);
988 } else {
989 printk(KERN_DEBUG "Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
990 sc_num);
991 }
992
993 printk(KERN_DEBUG " Args: %lx %lx %lx %lx %lx %lx %lx\n",
994 arg1, arg2, arg3, arg4, arg5, arg6, arg7);
995
996 return -ENOSYS;
997}
998