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