1 /* $Id: sys_sunos32.c,v 1.64 2002/02/09 19:49:31 davem Exp $
2 * sys_sunos32.c: SunOS binary compatibility layer on sparc64.
4 * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Based upon preliminary work which is:
9 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/types.h>
15 #include <linux/capability.h>
16 #include <linux/compat.h>
17 #include <linux/mman.h>
19 #include <linux/swap.h>
21 #include <linux/file.h>
22 #include <linux/resource.h>
23 #include <linux/ipc.h>
24 #include <linux/shm.h>
25 #include <linux/msg.h>
26 #include <linux/sem.h>
27 #include <linux/signal.h>
28 #include <linux/uio.h>
29 #include <linux/utsname.h>
30 #include <linux/major.h>
31 #include <linux/stat.h>
32 #include <linux/slab.h>
33 #include <linux/pagemap.h>
34 #include <linux/errno.h>
35 #include <linux/smp.h>
36 #include <linux/smp_lock.h>
37 #include <linux/syscalls.h>
39 #include <asm/uaccess.h>
41 #include <asm/pgtable.h>
42 #include <asm/pconf.h>
43 #include <asm/idprom.h> /* for gethostid() */
44 #include <asm/unistd.h>
45 #include <asm/system.h>
46 #include <asm/compat_signal.h>
48 /* For the nfs mount emulation */
49 #include <linux/socket.h>
51 #include <linux/nfs.h>
52 #include <linux/nfs2.h>
53 #include <linux/nfs_mount.h>
55 /* for sunos_select */
56 #include <linux/time.h>
57 #include <linux/personality.h>
61 #include <net/compat.h>
63 #define SUNOS_NR_OPEN 256
65 asmlinkage u32
sunos_mmap(u32 addr
, u32 len
, u32 prot
, u32 flags
, u32 fd
, u32 off
)
67 struct file
*file
= NULL
;
68 unsigned long retval
, ret_type
;
70 if (flags
& MAP_NORESERVE
) {
73 printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
75 flags
&= ~MAP_NORESERVE
;
78 if (!(flags
& MAP_ANONYMOUS
)) {
80 if (fd
>= SUNOS_NR_OPEN
)
85 inode
= file
->f_path
.dentry
->d_inode
;
86 if (imajor(inode
) == MEM_MAJOR
&& iminor(inode
) == 5) {
87 flags
|= MAP_ANONYMOUS
;
94 if (!(flags
& MAP_FIXED
))
96 else if (len
> 0xf0000000 || addr
> 0xf0000000 - len
)
98 ret_type
= flags
& _MAP_NEW
;
101 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
102 down_write(¤t
->mm
->mmap_sem
);
103 retval
= do_mmap(file
,
104 (unsigned long) addr
, (unsigned long) len
,
105 (unsigned long) prot
, (unsigned long) flags
,
106 (unsigned long) off
);
107 up_write(¤t
->mm
->mmap_sem
);
109 retval
= ((retval
< 0xf0000000) ? 0 : retval
);
117 asmlinkage
int sunos_mctl(u32 addr
, u32 len
, int function
, u32 arg
)
122 asmlinkage
int sunos_brk(u32 baddr
)
124 int freepages
, retval
= -ENOMEM
;
126 unsigned long newbrk
, oldbrk
, brk
= (unsigned long) baddr
;
128 down_write(¤t
->mm
->mmap_sem
);
129 if (brk
< current
->mm
->end_code
)
131 newbrk
= PAGE_ALIGN(brk
);
132 oldbrk
= PAGE_ALIGN(current
->mm
->brk
);
134 if (oldbrk
== newbrk
) {
135 current
->mm
->brk
= brk
;
138 /* Always allow shrinking brk. */
139 if (brk
<= current
->mm
->brk
) {
140 current
->mm
->brk
= brk
;
141 do_munmap(current
->mm
, newbrk
, oldbrk
-newbrk
);
144 /* Check against rlimit and stack.. */
146 rlim
= current
->signal
->rlim
[RLIMIT_DATA
].rlim_cur
;
147 if (rlim
>= RLIM_INFINITY
)
149 if (brk
- current
->mm
->end_code
> rlim
)
151 /* Check against existing mmap mappings. */
152 if (find_vma_intersection(current
->mm
, oldbrk
, newbrk
+PAGE_SIZE
))
154 /* stupid algorithm to decide if we have enough memory: while
155 * simple, it hopefully works in most obvious cases.. Easy to
156 * fool it, but this should catch most mistakes.
158 freepages
= global_page_state(NR_FILE_PAGES
);
160 freepages
+= nr_free_pages();
161 freepages
+= nr_swap_pages
;
162 freepages
-= num_physpages
>> 4;
163 freepages
-= (newbrk
-oldbrk
) >> PAGE_SHIFT
;
166 /* Ok, we have probably got enough memory - let it rip. */
167 current
->mm
->brk
= brk
;
168 do_brk(oldbrk
, newbrk
-oldbrk
);
171 up_write(¤t
->mm
->mmap_sem
);
175 asmlinkage u32
sunos_sbrk(int increment
)
179 /* This should do it hopefully... */
180 oldbrk
= (int)current
->mm
->brk
;
181 error
= sunos_brk(((int) current
->mm
->brk
) + increment
);
187 asmlinkage u32
sunos_sstk(int increment
)
189 printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
190 current
->comm
, increment
);
195 /* Give hints to the kernel as to what paging strategy to use...
196 * Completely bogus, don't remind me.
198 #define VA_NORMAL 0 /* Normal vm usage expected */
199 #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
200 #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
201 #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
202 static char *vstrings
[] = {
209 asmlinkage
void sunos_vadvise(u32 strategy
)
213 /* I wanna see who uses this... */
215 printk("%s: Advises us to use %s paging strategy\n",
217 strategy
<= 3 ? vstrings
[strategy
] : "BOGUS");
220 /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
221 * resource limit and is for backwards compatibility with older sunos
224 asmlinkage
int sunos_getdtablesize(void)
226 return SUNOS_NR_OPEN
;
230 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
232 asmlinkage u32
sunos_sigblock(u32 blk_mask
)
236 spin_lock_irq(¤t
->sighand
->siglock
);
237 old
= (u32
) current
->blocked
.sig
[0];
238 current
->blocked
.sig
[0] |= (blk_mask
& _BLOCKABLE
);
240 spin_unlock_irq(¤t
->sighand
->siglock
);
244 asmlinkage u32
sunos_sigsetmask(u32 newmask
)
248 spin_lock_irq(¤t
->sighand
->siglock
);
249 retval
= (u32
) current
->blocked
.sig
[0];
250 current
->blocked
.sig
[0] = (newmask
& _BLOCKABLE
);
252 spin_unlock_irq(¤t
->sighand
->siglock
);
256 /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
257 /* getdents system call, the format of the structure just has a different */
258 /* layout (d_off+d_ino instead of d_ino+d_off) */
259 struct sunos_dirent
{
267 struct sunos_dirent_callback
{
268 struct sunos_dirent __user
*curr
;
269 struct sunos_dirent __user
*previous
;
274 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
275 #define ROUND_UP(x) (((x)+sizeof(s32)-1) & ~(sizeof(s32)-1))
277 static int sunos_filldir(void * __buf
, const char * name
, int namlen
,
278 loff_t offset
, ino_t ino
, unsigned int d_type
)
280 struct sunos_dirent __user
*dirent
;
281 struct sunos_dirent_callback
* buf
= (struct sunos_dirent_callback
*) __buf
;
282 int reclen
= ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 1);
285 buf
->error
= -EINVAL
; /* only used if we fail.. */
286 if (reclen
> buf
->count
)
289 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
291 dirent
= buf
->previous
;
293 put_user(offset
, &dirent
->d_off
);
295 buf
->previous
= dirent
;
296 put_user(d_ino
, &dirent
->d_ino
);
297 put_user(namlen
, &dirent
->d_namlen
);
298 put_user(reclen
, &dirent
->d_reclen
);
299 if (copy_to_user(dirent
->d_name
, name
, namlen
))
301 put_user(0, dirent
->d_name
+ namlen
);
302 dirent
= (void __user
*) dirent
+ reclen
;
304 buf
->count
-= reclen
;
308 asmlinkage
int sunos_getdents(unsigned int fd
, void __user
*dirent
, int cnt
)
311 struct sunos_dirent __user
*lastdirent
;
312 struct sunos_dirent_callback buf
;
315 if (fd
>= SUNOS_NR_OPEN
)
323 if (cnt
< (sizeof(struct sunos_dirent
) + 255))
326 buf
.curr
= (struct sunos_dirent __user
*) dirent
;
331 error
= vfs_readdir(file
, sunos_filldir
, &buf
);
335 lastdirent
= buf
.previous
;
338 put_user(file
->f_pos
, &lastdirent
->d_off
);
339 error
= cnt
- buf
.count
;
348 /* Old sunos getdirentries, severely broken compatibility stuff here. */
349 struct sunos_direntry
{
356 struct sunos_direntry_callback
{
357 struct sunos_direntry __user
*curr
;
358 struct sunos_direntry __user
*previous
;
363 static int sunos_filldirentry(void * __buf
, const char * name
, int namlen
,
364 loff_t offset
, ino_t ino
, unsigned int d_type
)
366 struct sunos_direntry __user
*dirent
;
367 struct sunos_direntry_callback
* buf
=
368 (struct sunos_direntry_callback
*) __buf
;
369 int reclen
= ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 1);
372 buf
->error
= -EINVAL
; /* only used if we fail.. */
373 if (reclen
> buf
->count
)
376 if (sizeof(d_ino
) < sizeof(ino
) && d_ino
!= ino
)
378 dirent
= buf
->previous
;
380 buf
->previous
= dirent
;
381 put_user(d_ino
, &dirent
->d_ino
);
382 put_user(namlen
, &dirent
->d_namlen
);
383 put_user(reclen
, &dirent
->d_reclen
);
384 if (copy_to_user(dirent
->d_name
, name
, namlen
))
386 put_user(0, dirent
->d_name
+ namlen
);
387 dirent
= (void __user
*) dirent
+ reclen
;
389 buf
->count
-= reclen
;
393 asmlinkage
int sunos_getdirentries(unsigned int fd
,
396 unsigned int __user
*basep
)
399 struct sunos_direntry __user
*lastdirent
;
401 struct sunos_direntry_callback buf
;
403 if (fd
>= SUNOS_NR_OPEN
)
411 if (cnt
< (sizeof(struct sunos_direntry
) + 255))
414 buf
.curr
= (struct sunos_direntry __user
*) dirent
;
419 error
= vfs_readdir(file
, sunos_filldirentry
, &buf
);
423 lastdirent
= buf
.previous
;
426 put_user(file
->f_pos
, basep
);
427 error
= cnt
- buf
.count
;
436 struct sunos_utsname
{
445 asmlinkage
int sunos_uname(struct sunos_utsname __user
*name
)
450 ret
= copy_to_user(&name
->sname
[0], &utsname()->sysname
[0],
451 sizeof(name
->sname
) - 1);
452 ret
|= copy_to_user(&name
->nname
[0], &utsname()->nodename
[0],
453 sizeof(name
->nname
) - 1);
454 ret
|= put_user('\0', &name
->nname
[8]);
455 ret
|= copy_to_user(&name
->rel
[0], &utsname()->release
[0],
456 sizeof(name
->rel
) - 1);
457 ret
|= copy_to_user(&name
->ver
[0], &utsname()->version
[0],
458 sizeof(name
->ver
) - 1);
459 ret
|= copy_to_user(&name
->mach
[0], &utsname()->machine
[0],
460 sizeof(name
->mach
) - 1);
462 return (ret
? -EFAULT
: 0);
465 asmlinkage
int sunos_nosys(void)
467 struct pt_regs
*regs
;
471 regs
= current_thread_info()->kregs
;
472 if (test_thread_flag(TIF_32BIT
)) {
473 regs
->tpc
&= 0xffffffff;
474 regs
->tnpc
&= 0xffffffff;
476 info
.si_signo
= SIGSYS
;
478 info
.si_code
= __SI_FAULT
|0x100;
479 info
.si_addr
= (void __user
*)regs
->tpc
;
480 info
.si_trapno
= regs
->u_regs
[UREG_G1
];
481 send_sig_info(SIGSYS
, &info
, current
);
483 printk("Process makes ni_syscall number %d, register dump:\n",
484 (int) regs
->u_regs
[UREG_G1
]);
490 /* This is not a real and complete implementation yet, just to keep
491 * the easy SunOS binaries happy.
493 asmlinkage
int sunos_fpathconf(int fd
, int name
)
516 case _PCONF_CHRESTRICT
: /* XXX Investigate XXX */
519 case _PCONF_NOTRUNC
: /* XXX Investigate XXX */
520 case _PCONF_VDISABLE
:
530 asmlinkage
int sunos_pathconf(u32 u_path
, int name
)
534 ret
= sunos_fpathconf(0, name
); /* XXX cheese XXX */
538 asmlinkage
int sunos_select(int width
, u32 inp
, u32 outp
, u32 exp
, u32 tvp_x
)
542 /* SunOS binaries expect that select won't change the tvp contents */
543 ret
= compat_sys_select(width
, compat_ptr(inp
), compat_ptr(outp
),
544 compat_ptr(exp
), compat_ptr(tvp_x
));
545 if (ret
== -EINTR
&& tvp_x
) {
546 struct compat_timeval __user
*tvp
= compat_ptr(tvp_x
);
549 __get_user(sec
, &tvp
->tv_sec
);
550 __get_user(usec
, &tvp
->tv_usec
);
551 if (sec
== 0 && usec
== 0)
557 asmlinkage
void sunos_nop(void)
562 #if 0 /* This code doesn't translate user pointers correctly,
563 * disable for now. -DaveM
566 /* XXXXXXXXXX SunOS mount/umount. XXXXXXXXXXX */
567 #define SMNT_RDONLY 1
568 #define SMNT_NOSUID 2
569 #define SMNT_NEWTYPE 4
571 #define SMNT_REMOUNT 16
572 #define SMNT_NOSUB 32
573 #define SMNT_MULTI 64
574 #define SMNT_SYS5 128
577 char fh_data
[NFS_FHSIZE
];
580 struct sunos_nfs_mount_args
{
581 struct sockaddr_in
*addr
; /* file server address */
582 struct nfs_fh
*fh
; /* File handle to be mounted */
583 int flags
; /* flags */
584 int wsize
; /* write size in bytes */
585 int rsize
; /* read size in bytes */
586 int timeo
; /* initial timeout in .1 secs */
587 int retrans
; /* times to retry send */
588 char *hostname
; /* server's hostname */
589 int acregmin
; /* attr cache file min secs */
590 int acregmax
; /* attr cache file max secs */
591 int acdirmin
; /* attr cache dir min secs */
592 int acdirmax
; /* attr cache dir max secs */
593 char *netname
; /* server's netname */
597 /* Bind the socket on a local reserved port and connect it to the
598 * remote server. This on Linux/i386 is done by the mount program,
601 /* XXXXXXXXXXXXXXXXXXXX */
603 sunos_nfs_get_server_fd (int fd
, struct sockaddr_in
*addr
)
605 struct sockaddr_in local
;
606 struct sockaddr_in server
;
609 struct socket
*socket
;
617 inode
= file
->f_path
.dentry
->d_inode
;
619 socket
= SOCKET_I(inode
);
620 local
.sin_family
= AF_INET
;
621 local
.sin_addr
.s_addr
= INADDR_ANY
;
623 /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
626 local
.sin_port
= htons (--try_port
);
627 ret
= socket
->ops
->bind(socket
, (struct sockaddr
*)&local
,
629 } while (ret
&& try_port
> (1024 / 2));
636 server
.sin_family
= AF_INET
;
637 server
.sin_addr
= addr
->sin_addr
;
638 server
.sin_port
= NFS_PORT
;
640 /* Call sys_connect */
641 ret
= socket
->ops
->connect (socket
, (struct sockaddr
*) &server
,
642 sizeof (server
), file
->f_flags
);
649 /* XXXXXXXXXXXXXXXXXXXX */
650 static int get_default (int value
, int def_value
)
658 /* XXXXXXXXXXXXXXXXXXXX */
659 static int sunos_nfs_mount(char *dir_name
, int linux_flags
, void __user
*data
)
662 char *the_name
, *mount_page
;
663 struct nfs_mount_data linux_nfs_mount
;
664 struct sunos_nfs_mount_args sunos_mount
;
666 /* Ok, here comes the fun part: Linux's nfs mount needs a
667 * socket connection to the server, but SunOS mount does not
668 * require this, so we use the information on the destination
669 * address to create a socket and bind it to a reserved
670 * port on this system
672 if (copy_from_user(&sunos_mount
, data
, sizeof(sunos_mount
)))
675 server_fd
= sys_socket (AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
679 if (copy_from_user(&linux_nfs_mount
.addr
, sunos_mount
.addr
,
680 sizeof(*sunos_mount
.addr
)) ||
681 copy_from_user(&linux_nfs_mount
.root
, sunos_mount
.fh
,
682 sizeof(*sunos_mount
.fh
))) {
683 sys_close (server_fd
);
687 if (!sunos_nfs_get_server_fd (server_fd
, &linux_nfs_mount
.addr
)){
688 sys_close (server_fd
);
692 /* Now, bind it to a locally reserved port */
693 linux_nfs_mount
.version
= NFS_MOUNT_VERSION
;
694 linux_nfs_mount
.flags
= sunos_mount
.flags
;
695 linux_nfs_mount
.fd
= server_fd
;
697 linux_nfs_mount
.rsize
= get_default (sunos_mount
.rsize
, 8192);
698 linux_nfs_mount
.wsize
= get_default (sunos_mount
.wsize
, 8192);
699 linux_nfs_mount
.timeo
= get_default (sunos_mount
.timeo
, 10);
700 linux_nfs_mount
.retrans
= sunos_mount
.retrans
;
702 linux_nfs_mount
.acregmin
= sunos_mount
.acregmin
;
703 linux_nfs_mount
.acregmax
= sunos_mount
.acregmax
;
704 linux_nfs_mount
.acdirmin
= sunos_mount
.acdirmin
;
705 linux_nfs_mount
.acdirmax
= sunos_mount
.acdirmax
;
707 the_name
= getname(sunos_mount
.hostname
);
708 if (IS_ERR(the_name
))
709 return PTR_ERR(the_name
);
711 strlcpy(linux_nfs_mount
.hostname
, the_name
,
712 sizeof(linux_nfs_mount
.hostname
));
715 mount_page
= (char *) get_zeroed_page(GFP_KERNEL
);
719 memcpy(mount_page
, &linux_nfs_mount
, sizeof(linux_nfs_mount
));
721 err
= do_mount("", dir_name
, "nfs", linux_flags
, mount_page
);
723 free_page((unsigned long) mount_page
);
727 /* XXXXXXXXXXXXXXXXXXXX */
729 sunos_mount(char *type
, char *dir
, int flags
, void *data
)
734 char *dir_page
, *type_page
;
736 if (!capable (CAP_SYS_ADMIN
))
739 /* We don't handle the integer fs type */
740 if ((flags
& SMNT_NEWTYPE
) == 0)
743 /* Do not allow for those flags we don't support */
744 if (flags
& (SMNT_GRPID
|SMNT_NOSUB
|SMNT_MULTI
|SMNT_SYS5
))
747 if (flags
& SMNT_REMOUNT
)
748 linux_flags
|= MS_REMOUNT
;
749 if (flags
& SMNT_RDONLY
)
750 linux_flags
|= MS_RDONLY
;
751 if (flags
& SMNT_NOSUID
)
752 linux_flags
|= MS_NOSUID
;
754 dir_page
= getname(dir
);
755 ret
= PTR_ERR(dir_page
);
756 if (IS_ERR(dir_page
))
759 type_page
= getname(type
);
760 ret
= PTR_ERR(type_page
);
761 if (IS_ERR(type_page
))
764 if (strcmp(type_page
, "ext2") == 0) {
765 dev_fname
= getname(data
);
766 } else if (strcmp(type_page
, "iso9660") == 0) {
767 dev_fname
= getname(data
);
768 } else if (strcmp(type_page
, "minix") == 0) {
769 dev_fname
= getname(data
);
770 } else if (strcmp(type_page
, "nfs") == 0) {
771 ret
= sunos_nfs_mount (dir_page
, flags
, data
);
773 } else if (strcmp(type_page
, "ufs") == 0) {
774 printk("Warning: UFS filesystem mounts unsupported.\n");
777 } else if (strcmp(type_page
, "proc")) {
781 ret
= PTR_ERR(dev_fname
);
782 if (IS_ERR(dev_fname
))
785 ret
= do_mount(dev_fname
, dir_page
, type_page
, linux_flags
, NULL
);
798 asmlinkage
int sunos_setpgrp(pid_t pid
, pid_t pgid
)
803 if ((!pid
|| pid
== current
->pid
) &&
808 ret
= sys_setpgid(pid
, pgid
);
814 extern long compat_sys_wait4(compat_pid_t
, compat_uint_t __user
*, int,
815 struct compat_rusage __user
*);
817 asmlinkage
int sunos_wait4(compat_pid_t pid
, compat_uint_t __user
*stat_addr
, int options
, struct compat_rusage __user
*ru
)
821 ret
= compat_sys_wait4((pid
? pid
: ((compat_pid_t
)-1)),
822 stat_addr
, options
, ru
);
826 asmlinkage
int sunos_killpg(int pgrp
, int sig
)
833 ret
= kill_pgrp(find_vpid(pgrp
), sig
, 0);
839 asmlinkage
int sunos_audit(void)
841 printk ("sys_audit\n");
845 asmlinkage u32
sunos_gethostid(void)
849 ret
= (((u32
)idprom
->id_machtype
<< 24) | ((u32
)idprom
->id_sernum
));
854 /* sysconf options, for SunOS compatibility */
855 #define _SC_ARG_MAX 1
856 #define _SC_CHILD_MAX 2
857 #define _SC_CLK_TCK 3
858 #define _SC_NGROUPS_MAX 4
859 #define _SC_OPEN_MAX 5
860 #define _SC_JOB_CONTROL 6
861 #define _SC_SAVED_IDS 7
862 #define _SC_VERSION 8
864 asmlinkage s32
sunos_sysconf (int name
)
873 ret
= current
->signal
->rlim
[RLIMIT_NPROC
].rlim_cur
;
878 case _SC_NGROUPS_MAX
:
882 ret
= current
->signal
->rlim
[RLIMIT_NOFILE
].rlim_cur
;
884 case _SC_JOB_CONTROL
:
885 ret
= 1; /* yes, we do support job control */
888 ret
= 1; /* yes, we do support saved uids */
891 /* mhm, POSIX_VERSION is in /usr/include/unistd.h
892 * should it go on /usr/include/linux?
903 asmlinkage
int sunos_semsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
, void __user
*ptr
)
910 /* Most arguments match on a 1:1 basis but cmd doesn't */
928 /* value to modify semaphore to */
930 ret
= sys_semctl((int)arg1
, (int)arg2
, (int)arg3
, arg4
);
934 ret
= sys_semget((key_t
)arg1
, (int)arg2
, (int)arg3
);
938 ret
= sys_semop((int)arg1
, (struct sembuf __user
*)(unsigned long)arg2
,
939 (unsigned int) arg3
);
966 struct ipc_perm32 msg_perm
;
969 compat_time_t msg_stime
;
970 compat_time_t msg_rtime
;
971 compat_time_t msg_ctime
;
974 unsigned short msg_cbytes
;
975 unsigned short msg_qnum
;
976 unsigned short msg_qbytes
;
977 compat_ipc_pid_t msg_lspid
;
978 compat_ipc_pid_t msg_lrpid
;
981 static inline int sunos_msqid_get(struct msqid_ds32 __user
*user
,
982 struct msqid_ds
*kern
)
984 if (get_user(kern
->msg_perm
.key
, &user
->msg_perm
.key
) ||
985 __get_user(kern
->msg_perm
.uid
, &user
->msg_perm
.uid
) ||
986 __get_user(kern
->msg_perm
.gid
, &user
->msg_perm
.gid
) ||
987 __get_user(kern
->msg_perm
.cuid
, &user
->msg_perm
.cuid
) ||
988 __get_user(kern
->msg_perm
.cgid
, &user
->msg_perm
.cgid
) ||
989 __get_user(kern
->msg_stime
, &user
->msg_stime
) ||
990 __get_user(kern
->msg_rtime
, &user
->msg_rtime
) ||
991 __get_user(kern
->msg_ctime
, &user
->msg_ctime
) ||
992 __get_user(kern
->msg_ctime
, &user
->msg_cbytes
) ||
993 __get_user(kern
->msg_ctime
, &user
->msg_qnum
) ||
994 __get_user(kern
->msg_ctime
, &user
->msg_qbytes
) ||
995 __get_user(kern
->msg_ctime
, &user
->msg_lspid
) ||
996 __get_user(kern
->msg_ctime
, &user
->msg_lrpid
))
1001 static inline int sunos_msqid_put(struct msqid_ds32 __user
*user
,
1002 struct msqid_ds
*kern
)
1004 if (put_user(kern
->msg_perm
.key
, &user
->msg_perm
.key
) ||
1005 __put_user(kern
->msg_perm
.uid
, &user
->msg_perm
.uid
) ||
1006 __put_user(kern
->msg_perm
.gid
, &user
->msg_perm
.gid
) ||
1007 __put_user(kern
->msg_perm
.cuid
, &user
->msg_perm
.cuid
) ||
1008 __put_user(kern
->msg_perm
.cgid
, &user
->msg_perm
.cgid
) ||
1009 __put_user(kern
->msg_stime
, &user
->msg_stime
) ||
1010 __put_user(kern
->msg_rtime
, &user
->msg_rtime
) ||
1011 __put_user(kern
->msg_ctime
, &user
->msg_ctime
) ||
1012 __put_user(kern
->msg_ctime
, &user
->msg_cbytes
) ||
1013 __put_user(kern
->msg_ctime
, &user
->msg_qnum
) ||
1014 __put_user(kern
->msg_ctime
, &user
->msg_qbytes
) ||
1015 __put_user(kern
->msg_ctime
, &user
->msg_lspid
) ||
1016 __put_user(kern
->msg_ctime
, &user
->msg_lrpid
))
1021 static inline int sunos_msgbuf_get(struct msgbuf32 __user
*user
, struct msgbuf
*kern
, int len
)
1023 if (get_user(kern
->mtype
, &user
->mtype
) ||
1024 __copy_from_user(kern
->mtext
, &user
->mtext
, len
))
1029 static inline int sunos_msgbuf_put(struct msgbuf32 __user
*user
, struct msgbuf
*kern
, int len
)
1031 if (put_user(kern
->mtype
, &user
->mtype
) ||
1032 __copy_to_user(user
->mtext
, kern
->mtext
, len
))
1037 asmlinkage
int sunos_msgsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
, u32 arg4
)
1039 struct sparc_stackf32 __user
*sp
;
1040 struct msqid_ds kds
;
1041 struct msgbuf
*kmbuf
;
1042 mm_segment_t old_fs
= get_fs();
1048 rval
= sys_msgget((key_t
)arg1
, (int)arg2
);
1051 if (!sunos_msqid_get((struct msqid_ds32 __user
*)(unsigned long)arg3
, &kds
)) {
1053 rval
= sys_msgctl((int)arg1
, (int)arg2
,
1054 (struct msqid_ds __user
*)(unsigned long)arg3
);
1057 rval
= sunos_msqid_put((struct msqid_ds32 __user
*)(unsigned long)arg3
,
1064 kmbuf
= kmalloc(sizeof(struct msgbuf
) + arg3
,
1068 sp
= (struct sparc_stackf32 __user
*)
1069 (current_thread_info()->kregs
->u_regs
[UREG_FP
] & 0xffffffffUL
);
1070 if (get_user(arg5
, &sp
->xxargs
[0])) {
1076 rval
= sys_msgrcv((int)arg1
, (struct msgbuf __user
*) kmbuf
,
1078 (long)arg4
, (int)arg5
);
1081 rval
= sunos_msgbuf_put((struct msgbuf32 __user
*)(unsigned long)arg2
,
1087 kmbuf
= kmalloc(sizeof(struct msgbuf
) + arg3
,
1089 if (!kmbuf
|| sunos_msgbuf_get((struct msgbuf32 __user
*)(unsigned long)arg2
,
1093 rval
= sys_msgsnd((int)arg1
, (struct msgbuf __user
*) kmbuf
,
1094 (size_t)arg3
, (int)arg4
);
1106 struct ipc_perm32 shm_perm
;
1108 compat_time_t shm_atime
;
1109 compat_time_t shm_dtime
;
1110 compat_time_t shm_ctime
;
1111 compat_ipc_pid_t shm_cpid
;
1112 compat_ipc_pid_t shm_lpid
;
1113 unsigned short shm_nattch
;
1116 static inline int sunos_shmid_get(struct shmid_ds32 __user
*user
,
1117 struct shmid_ds
*kern
)
1119 if (get_user(kern
->shm_perm
.key
, &user
->shm_perm
.key
) ||
1120 __get_user(kern
->shm_perm
.uid
, &user
->shm_perm
.uid
) ||
1121 __get_user(kern
->shm_perm
.gid
, &user
->shm_perm
.gid
) ||
1122 __get_user(kern
->shm_perm
.cuid
, &user
->shm_perm
.cuid
) ||
1123 __get_user(kern
->shm_perm
.cgid
, &user
->shm_perm
.cgid
) ||
1124 __get_user(kern
->shm_segsz
, &user
->shm_segsz
) ||
1125 __get_user(kern
->shm_atime
, &user
->shm_atime
) ||
1126 __get_user(kern
->shm_dtime
, &user
->shm_dtime
) ||
1127 __get_user(kern
->shm_ctime
, &user
->shm_ctime
) ||
1128 __get_user(kern
->shm_cpid
, &user
->shm_cpid
) ||
1129 __get_user(kern
->shm_lpid
, &user
->shm_lpid
) ||
1130 __get_user(kern
->shm_nattch
, &user
->shm_nattch
))
1135 static inline int sunos_shmid_put(struct shmid_ds32 __user
*user
,
1136 struct shmid_ds
*kern
)
1138 if (put_user(kern
->shm_perm
.key
, &user
->shm_perm
.key
) ||
1139 __put_user(kern
->shm_perm
.uid
, &user
->shm_perm
.uid
) ||
1140 __put_user(kern
->shm_perm
.gid
, &user
->shm_perm
.gid
) ||
1141 __put_user(kern
->shm_perm
.cuid
, &user
->shm_perm
.cuid
) ||
1142 __put_user(kern
->shm_perm
.cgid
, &user
->shm_perm
.cgid
) ||
1143 __put_user(kern
->shm_segsz
, &user
->shm_segsz
) ||
1144 __put_user(kern
->shm_atime
, &user
->shm_atime
) ||
1145 __put_user(kern
->shm_dtime
, &user
->shm_dtime
) ||
1146 __put_user(kern
->shm_ctime
, &user
->shm_ctime
) ||
1147 __put_user(kern
->shm_cpid
, &user
->shm_cpid
) ||
1148 __put_user(kern
->shm_lpid
, &user
->shm_lpid
) ||
1149 __put_user(kern
->shm_nattch
, &user
->shm_nattch
))
1154 asmlinkage
int sunos_shmsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
)
1156 struct shmid_ds ksds
;
1157 unsigned long raddr
;
1158 mm_segment_t old_fs
= get_fs();
1163 /* do_shmat(): attach a shared memory area */
1164 rval
= do_shmat((int)arg1
,(char __user
*)(unsigned long)arg2
,(int)arg3
,&raddr
);
1169 /* sys_shmctl(): modify shared memory area attr. */
1170 if (!sunos_shmid_get((struct shmid_ds32 __user
*)(unsigned long)arg3
, &ksds
)) {
1172 rval
= sys_shmctl((int) arg1
,(int) arg2
,
1173 (struct shmid_ds __user
*) &ksds
);
1176 rval
= sunos_shmid_put((struct shmid_ds32 __user
*)(unsigned long)arg3
,
1182 /* sys_shmdt(): detach a shared memory area */
1183 rval
= sys_shmdt((char __user
*)(unsigned long)arg1
);
1186 /* sys_shmget(): get a shared memory area */
1187 rval
= sys_shmget((key_t
)arg1
,(int)arg2
,(int)arg3
);
1196 extern asmlinkage
long sparc32_open(const char __user
* filename
, int flags
, int mode
);
1198 asmlinkage
int sunos_open(u32 fname
, int flags
, int mode
)
1200 const char __user
*filename
= compat_ptr(fname
);
1202 return sparc32_open(filename
, flags
, mode
);
1205 #define SUNOS_EWOULDBLOCK 35
1207 /* see the sunos man page read(2v) for an explanation
1208 of this garbage. We use O_NDELAY to mark
1209 file descriptors that have been set non-blocking
1210 using 4.2BSD style calls. (tridge) */
1212 static inline int check_nonblock(int ret
, int fd
)
1214 if (ret
== -EAGAIN
) {
1215 struct file
* file
= fget(fd
);
1217 if (file
->f_flags
& O_NDELAY
)
1218 ret
= -SUNOS_EWOULDBLOCK
;
1225 asmlinkage
int sunos_read(unsigned int fd
, char __user
*buf
, u32 count
)
1229 ret
= check_nonblock(sys_read(fd
, buf
, count
), fd
);
1233 asmlinkage
int sunos_readv(u32 fd
, void __user
*vector
, s32 count
)
1237 ret
= check_nonblock(compat_sys_readv(fd
, vector
, count
), fd
);
1241 asmlinkage
int sunos_write(unsigned int fd
, char __user
*buf
, u32 count
)
1245 ret
= check_nonblock(sys_write(fd
, buf
, count
), fd
);
1249 asmlinkage
int sunos_writev(u32 fd
, void __user
*vector
, s32 count
)
1253 ret
= check_nonblock(compat_sys_writev(fd
, vector
, count
), fd
);
1257 asmlinkage
int sunos_recv(u32 __fd
, void __user
*ubuf
, int size
, unsigned flags
)
1259 int ret
, fd
= (int) __fd
;
1261 ret
= check_nonblock(sys_recv(fd
, ubuf
, size
, flags
), fd
);
1265 asmlinkage
int sunos_send(u32 __fd
, void __user
*buff
, int len
, unsigned flags
)
1267 int ret
, fd
= (int) __fd
;
1269 ret
= check_nonblock(sys_send(fd
, buff
, len
, flags
), fd
);
1273 asmlinkage
int sunos_accept(u32 __fd
, struct sockaddr __user
*sa
, int __user
*addrlen
)
1275 int ret
, fd
= (int) __fd
;
1278 ret
= check_nonblock(sys_accept(fd
, sa
, addrlen
), fd
);
1279 if (ret
!= -ENETUNREACH
&& ret
!= -EHOSTUNREACH
)
1285 #define SUNOS_SV_INTERRUPT 2
1287 asmlinkage
int sunos_sigaction (int sig
,
1288 struct old_sigaction32 __user
*act
,
1289 struct old_sigaction32 __user
*oact
)
1291 struct k_sigaction new_ka
, old_ka
;
1295 compat_old_sigset_t mask
;
1298 if (get_user(u_handler
, &act
->sa_handler
) ||
1299 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
))
1301 new_ka
.sa
.sa_handler
= compat_ptr(u_handler
);
1302 __get_user(mask
, &act
->sa_mask
);
1303 new_ka
.sa
.sa_restorer
= NULL
;
1304 new_ka
.ka_restorer
= NULL
;
1305 siginitset(&new_ka
.sa
.sa_mask
, mask
);
1306 new_ka
.sa
.sa_flags
^= SUNOS_SV_INTERRUPT
;
1309 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
1312 old_ka
.sa
.sa_flags
^= SUNOS_SV_INTERRUPT
;
1313 if (put_user(ptr_to_compat(old_ka
.sa
.sa_handler
), &oact
->sa_handler
) ||
1314 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
))
1316 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
1322 asmlinkage
int sunos_setsockopt(u32 __fd
, u32 __level
, u32 __optname
,
1323 char __user
*optval
, u32 __optlen
)
1325 int fd
= (int) __fd
;
1326 int level
= (int) __level
;
1327 int optname
= (int) __optname
;
1328 int optlen
= (int) __optlen
;
1329 int tr_opt
= optname
;
1332 if (level
== SOL_IP
) {
1333 /* Multicast socketopts (ttl, membership) */
1334 if (tr_opt
>=2 && tr_opt
<= 6)
1337 ret
= sys_setsockopt(fd
, level
, tr_opt
,
1342 asmlinkage
int sunos_getsockopt(u32 __fd
, u32 __level
, u32 __optname
,
1343 char __user
*optval
, int __user
*optlen
)
1345 int fd
= (int) __fd
;
1346 int level
= (int) __level
;
1347 int optname
= (int) __optname
;
1348 int tr_opt
= optname
;
1351 if (level
== SOL_IP
) {
1352 /* Multicast socketopts (ttl, membership) */
1353 if (tr_opt
>=2 && tr_opt
<= 6)
1356 ret
= compat_sys_getsockopt(fd
, level
, tr_opt
,