1 /* $Id: sys_sunos32.c,v 1.49 2000/06/22 11:42:25 davem Exp $
2 * sys_sunos32.c: SunOS binary compatability 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/mman.h>
17 #include <linux/swap.h>
19 #include <linux/file.h>
20 #include <linux/resource.h>
21 #include <linux/ipc.h>
22 #include <linux/shm.h>
23 #include <linux/msg.h>
24 #include <linux/sem.h>
25 #include <linux/signal.h>
26 #include <linux/uio.h>
27 #include <linux/utsname.h>
28 #include <linux/major.h>
29 #include <linux/stat.h>
30 #include <linux/malloc.h>
31 #include <linux/pagemap.h>
32 #include <linux/errno.h>
33 #include <linux/smp.h>
34 #include <linux/smp_lock.h>
36 #include <asm/uaccess.h>
38 #include <asm/pgtable.h>
39 #include <asm/pconf.h>
40 #include <asm/idprom.h> /* for gethostid() */
41 #include <asm/unistd.h>
42 #include <asm/system.h>
44 /* For the nfs mount emulation */
45 #include <linux/socket.h>
47 #include <linux/nfs.h>
48 #include <linux/nfs2.h>
49 #include <linux/nfs_mount.h>
51 /* for sunos_select */
52 #include <linux/time.h>
53 #include <linux/personality.h>
55 /* Use this to get at 32-bit user passed pointers. */
57 ({ unsigned long __ret; \
58 __asm__ ("srl %0, 0, %0" \
64 #define SUNOS_NR_OPEN 256
66 asmlinkage u32
sunos_mmap(u32 addr
, u32 len
, u32 prot
, u32 flags
, u32 fd
, u32 off
)
68 struct file
*file
= NULL
;
69 unsigned long retval
, ret_type
;
72 if(flags
& MAP_NORESERVE
) {
75 printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
77 flags
&= ~MAP_NORESERVE
;
80 if(!(flags
& MAP_ANONYMOUS
)) {
82 if(fd
>= SUNOS_NR_OPEN
)
87 inode
= file
->f_dentry
->d_inode
;
88 if(MAJOR(inode
->i_rdev
)==MEM_MAJOR
&& MINOR(inode
->i_rdev
)==5) {
89 flags
|= MAP_ANONYMOUS
;
96 if(!(flags
& MAP_FIXED
))
98 else if (len
> 0xf0000000 || addr
> 0xf0000000 - len
)
100 ret_type
= flags
& _MAP_NEW
;
103 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
104 down(¤t
->mm
->mmap_sem
);
105 retval
= do_mmap(file
,
106 (unsigned long) addr
, (unsigned long) len
,
107 (unsigned long) prot
, (unsigned long) flags
,
108 (unsigned long) off
);
109 up(¤t
->mm
->mmap_sem
);
111 retval
= ((retval
< 0xf0000000) ? 0 : retval
);
120 asmlinkage
int sunos_mctl(u32 addr
, u32 len
, int function
, u32 arg
)
125 asmlinkage
int sunos_brk(u32 baddr
)
127 int freepages
, retval
= -ENOMEM
;
129 unsigned long newbrk
, oldbrk
, brk
= (unsigned long) baddr
;
131 down(¤t
->mm
->mmap_sem
);
132 if (brk
< current
->mm
->end_code
)
134 newbrk
= PAGE_ALIGN(brk
);
135 oldbrk
= PAGE_ALIGN(current
->mm
->brk
);
137 if (oldbrk
== newbrk
) {
138 current
->mm
->brk
= brk
;
141 /* Always allow shrinking brk. */
142 if (brk
<= current
->mm
->brk
) {
143 current
->mm
->brk
= brk
;
144 do_munmap(current
->mm
, newbrk
, oldbrk
-newbrk
);
147 /* Check against rlimit and stack.. */
149 rlim
= current
->rlim
[RLIMIT_DATA
].rlim_cur
;
150 if (rlim
>= RLIM_INFINITY
)
152 if (brk
- current
->mm
->end_code
> rlim
)
154 /* Check against existing mmap mappings. */
155 if (find_vma_intersection(current
->mm
, oldbrk
, newbrk
+PAGE_SIZE
))
157 /* stupid algorithm to decide if we have enough memory: while
158 * simple, it hopefully works in most obvious cases.. Easy to
159 * fool it, but this should catch most mistakes.
161 freepages
= atomic_read(&buffermem_pages
) >> PAGE_SHIFT
;
162 freepages
+= atomic_read(&page_cache_size
);
164 freepages
+= nr_free_pages();
165 freepages
+= nr_swap_pages
;
166 freepages
-= num_physpages
>> 4;
167 freepages
-= (newbrk
-oldbrk
) >> PAGE_SHIFT
;
170 /* Ok, we have probably got enough memory - let it rip. */
171 current
->mm
->brk
= brk
;
172 do_brk(oldbrk
, newbrk
-oldbrk
);
175 up(¤t
->mm
->mmap_sem
);
179 asmlinkage u32
sunos_sbrk(int increment
)
183 /* This should do it hopefully... */
185 oldbrk
= (int)current
->mm
->brk
;
186 error
= sunos_brk(((int) current
->mm
->brk
) + increment
);
193 asmlinkage u32
sunos_sstk(int increment
)
196 printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
197 current
->comm
, increment
);
202 /* Give hints to the kernel as to what paging strategy to use...
203 * Completely bogus, don't remind me.
205 #define VA_NORMAL 0 /* Normal vm usage expected */
206 #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
207 #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
208 #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
209 static char *vstrings
[] = {
216 asmlinkage
void sunos_vadvise(u32 strategy
)
218 /* I wanna see who uses this... */
220 printk("%s: Advises us to use %s paging strategy\n",
222 strategy
<= 3 ? vstrings
[strategy
] : "BOGUS");
226 /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
227 * resource limit and is for backwards compatibility with older sunos
230 asmlinkage
int sunos_getdtablesize(void)
232 return SUNOS_NR_OPEN
;
236 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
238 asmlinkage u32
sunos_sigblock(u32 blk_mask
)
242 spin_lock_irq(¤t
->sigmask_lock
);
243 old
= (u32
) current
->blocked
.sig
[0];
244 current
->blocked
.sig
[0] |= (blk_mask
& _BLOCKABLE
);
245 recalc_sigpending(current
);
246 spin_unlock_irq(¤t
->sigmask_lock
);
250 asmlinkage u32
sunos_sigsetmask(u32 newmask
)
254 spin_lock_irq(¤t
->sigmask_lock
);
255 retval
= (u32
) current
->blocked
.sig
[0];
256 current
->blocked
.sig
[0] = (newmask
& _BLOCKABLE
);
257 recalc_sigpending(current
);
258 spin_unlock_irq(¤t
->sigmask_lock
);
262 /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
263 /* getdents system call, the format of the structure just has a different */
264 /* layout (d_off+d_ino instead of d_ino+d_off) */
265 struct sunos_dirent
{
273 struct sunos_dirent_callback
{
274 struct sunos_dirent
*curr
;
275 struct sunos_dirent
*previous
;
280 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
281 #define ROUND_UP(x) (((x)+sizeof(s32)-1) & ~(sizeof(s32)-1))
283 static int sunos_filldir(void * __buf
, const char * name
, int namlen
,
284 off_t offset
, ino_t ino
)
286 struct sunos_dirent
* dirent
;
287 struct sunos_dirent_callback
* buf
= (struct sunos_dirent_callback
*) __buf
;
288 int reclen
= ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 1);
290 buf
->error
= -EINVAL
; /* only used if we fail.. */
291 if (reclen
> buf
->count
)
293 dirent
= buf
->previous
;
295 put_user(offset
, &dirent
->d_off
);
297 buf
->previous
= dirent
;
298 put_user(ino
, &dirent
->d_ino
);
299 put_user(namlen
, &dirent
->d_namlen
);
300 put_user(reclen
, &dirent
->d_reclen
);
301 copy_to_user(dirent
->d_name
, name
, namlen
);
302 put_user(0, dirent
->d_name
+ namlen
);
303 ((char *) dirent
) += reclen
;
305 buf
->count
-= reclen
;
309 asmlinkage
int sunos_getdents(unsigned int fd
, u32 u_dirent
, int cnt
)
312 struct sunos_dirent
* lastdirent
;
313 struct sunos_dirent_callback buf
;
315 void *dirent
= (void *)A(u_dirent
);
317 if(fd
>= SUNOS_NR_OPEN
)
327 if(cnt
< (sizeof(struct sunos_dirent
) + 255))
330 buf
.curr
= (struct sunos_dirent
*) dirent
;
335 error
= vfs_readdir(file
, sunos_filldir
, &buf
);
339 lastdirent
= buf
.previous
;
342 put_user(file
->f_pos
, &lastdirent
->d_off
);
343 error
= cnt
- buf
.count
;
353 /* Old sunos getdirentries, severely broken compatibility stuff here. */
354 struct sunos_direntry
{
361 struct sunos_direntry_callback
{
362 struct sunos_direntry
*curr
;
363 struct sunos_direntry
*previous
;
368 static int sunos_filldirentry(void * __buf
, const char * name
, int namlen
,
369 off_t offset
, ino_t ino
)
371 struct sunos_direntry
* dirent
;
372 struct sunos_direntry_callback
* buf
= (struct sunos_direntry_callback
*) __buf
;
373 int reclen
= ROUND_UP(NAME_OFFSET(dirent
) + namlen
+ 1);
375 buf
->error
= -EINVAL
; /* only used if we fail.. */
376 if (reclen
> buf
->count
)
378 dirent
= buf
->previous
;
380 buf
->previous
= dirent
;
381 put_user(ino
, &dirent
->d_ino
);
382 put_user(namlen
, &dirent
->d_namlen
);
383 put_user(reclen
, &dirent
->d_reclen
);
384 copy_to_user(dirent
->d_name
, name
, namlen
);
385 put_user(0, dirent
->d_name
+ namlen
);
386 ((char *) dirent
) += reclen
;
388 buf
->count
-= reclen
;
392 asmlinkage
int sunos_getdirentries(unsigned int fd
, u32 u_dirent
,
393 int cnt
, u32 u_basep
)
395 void *dirent
= (void *) A(u_dirent
);
396 unsigned int *basep
= (unsigned int *)A(u_basep
);
398 struct sunos_direntry
* lastdirent
;
400 struct sunos_direntry_callback buf
;
402 if(fd
>= SUNOS_NR_OPEN
)
412 if(cnt
< (sizeof(struct sunos_direntry
) + 255))
415 buf
.curr
= (struct sunos_direntry
*) dirent
;
420 error
= vfs_readdir(file
, sunos_filldirentry
, &buf
);
424 lastdirent
= buf
.previous
;
427 put_user(file
->f_pos
, basep
);
428 error
= cnt
- buf
.count
;
438 struct sunos_utsname
{
447 asmlinkage
int sunos_uname(struct sunos_utsname
*name
)
452 ret
= copy_to_user(&name
->sname
[0], &system_utsname
.sysname
[0], sizeof(name
->sname
) - 1);
453 ret
|= copy_to_user(&name
->nname
[0], &system_utsname
.nodename
[0], sizeof(name
->nname
) - 1);
454 ret
|= put_user('\0', &name
->nname
[8]);
455 ret
|= copy_to_user(&name
->rel
[0], &system_utsname
.release
[0], sizeof(name
->rel
) - 1);
456 ret
|= copy_to_user(&name
->ver
[0], &system_utsname
.version
[0], sizeof(name
->ver
) - 1);
457 ret
|= copy_to_user(&name
->mach
[0], &system_utsname
.machine
[0], sizeof(name
->mach
) - 1);
462 asmlinkage
int sunos_nosys(void)
464 struct pt_regs
*regs
;
469 regs
= current
->thread
.kregs
;
470 info
.si_signo
= SIGSYS
;
472 info
.si_code
= __SI_FAULT
|0x100;
473 info
.si_addr
= (void *)regs
->tpc
;
474 info
.si_trapno
= regs
->u_regs
[UREG_G1
];
475 send_sig_info(SIGSYS
, &info
, current
);
477 printk("Process makes ni_syscall number %d, register dump:\n",
478 (int) regs
->u_regs
[UREG_G1
]);
485 /* This is not a real and complete implementation yet, just to keep
486 * the easy SunOS binaries happy.
488 asmlinkage
int sunos_fpathconf(int fd
, int name
)
512 case _PCONF_CHRESTRICT
: /* XXX Investigate XXX */
515 case _PCONF_NOTRUNC
: /* XXX Investigate XXX */
516 case _PCONF_VDISABLE
:
527 asmlinkage
int sunos_pathconf(u32 u_path
, int name
)
532 ret
= sunos_fpathconf(0, name
); /* XXX cheese XXX */
537 /* SunOS mount system call emulation */
538 extern asmlinkage
int
539 sys32_select(int n
, u32 inp
, u32 outp
, u32 exp
, u32 tvp
);
546 asmlinkage
int sunos_select(int width
, u32 inp
, u32 outp
, u32 exp
, u32 tvp_x
)
550 /* SunOS binaries expect that select won't change the tvp contents */
552 ret
= sys32_select (width
, inp
, outp
, exp
, tvp_x
);
553 if (ret
== -EINTR
&& tvp_x
) {
554 struct timeval32
*tvp
= (struct timeval32
*)A(tvp_x
);
557 __get_user(sec
, &tvp
->tv_sec
);
558 __get_user(usec
, &tvp
->tv_usec
);
559 if (sec
== 0 && usec
== 0)
566 asmlinkage
void sunos_nop(void)
571 /* XXXXXXXXXX SunOS mount/umount. XXXXXXXXXXX */
572 #define SMNT_RDONLY 1
573 #define SMNT_NOSUID 2
574 #define SMNT_NEWTYPE 4
576 #define SMNT_REMOUNT 16
577 #define SMNT_NOSUB 32
578 #define SMNT_MULTI 64
579 #define SMNT_SYS5 128
582 char fh_data
[NFS_FHSIZE
];
585 struct sunos_nfs_mount_args
{
586 struct sockaddr_in
*addr
; /* file server address */
587 struct nfs_fh
*fh
; /* File handle to be mounted */
588 int flags
; /* flags */
589 int wsize
; /* write size in bytes */
590 int rsize
; /* read size in bytes */
591 int timeo
; /* initial timeout in .1 secs */
592 int retrans
; /* times to retry send */
593 char *hostname
; /* server's hostname */
594 int acregmin
; /* attr cache file min secs */
595 int acregmax
; /* attr cache file max secs */
596 int acdirmin
; /* attr cache dir min secs */
597 int acdirmax
; /* attr cache dir max secs */
598 char *netname
; /* server's netname */
601 extern dev_t
get_unnamed_dev(void);
602 extern void put_unnamed_dev(dev_t
);
603 extern asmlinkage
int sys_mount(char *, char *, char *, unsigned long, void *);
604 extern asmlinkage
int sys_connect(int fd
, struct sockaddr
*uservaddr
, int addrlen
);
605 extern asmlinkage
int sys_socket(int family
, int type
, int protocol
);
606 extern asmlinkage
int sys_bind(int fd
, struct sockaddr
*umyaddr
, int addrlen
);
609 /* Bind the socket on a local reserved port and connect it to the
610 * remote server. This on Linux/i386 is done by the mount program,
613 /* XXXXXXXXXXXXXXXXXXXX */
615 sunos_nfs_get_server_fd (int fd
, struct sockaddr_in
*addr
)
617 struct sockaddr_in local
;
618 struct sockaddr_in server
;
621 struct socket
*socket
;
622 struct dentry
*dentry
;
630 dentry
= file
->f_dentry
;
631 inode
= dentry
->d_inode
;
633 socket
= &inode
->u
.socket_i
;
634 local
.sin_family
= AF_INET
;
635 local
.sin_addr
.s_addr
= INADDR_ANY
;
637 /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
640 local
.sin_port
= htons (--try_port
);
641 ret
= socket
->ops
->bind(socket
, (struct sockaddr
*)&local
,
643 } while (ret
&& try_port
> (1024 / 2));
650 server
.sin_family
= AF_INET
;
651 server
.sin_addr
= addr
->sin_addr
;
652 server
.sin_port
= NFS_PORT
;
654 /* Call sys_connect */
655 ret
= socket
->ops
->connect (socket
, (struct sockaddr
*) &server
,
656 sizeof (server
), file
->f_flags
);
663 /* XXXXXXXXXXXXXXXXXXXX */
664 static int get_default (int value
, int def_value
)
672 /* XXXXXXXXXXXXXXXXXXXX */
673 static int sunos_nfs_mount(char *dir_name
, int linux_flags
, void *data
)
677 struct nfs_mount_data linux_nfs_mount
;
678 struct sunos_nfs_mount_args sunos_mount
;
680 /* Ok, here comes the fun part: Linux's nfs mount needs a
681 * socket connection to the server, but SunOS mount does not
682 * require this, so we use the information on the destination
683 * address to create a socket and bind it to a reserved
684 * port on this system
686 if (copy_from_user(&sunos_mount
, data
, sizeof(sunos_mount
)))
689 server_fd
= sys_socket (AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
693 if (copy_from_user(&linux_nfs_mount
.addr
,sunos_mount
.addr
,
694 sizeof(*sunos_mount
.addr
)) ||
695 copy_from_user(&linux_nfs_mount
.root
,sunos_mount
.fh
,
696 sizeof(*sunos_mount
.fh
))) {
697 sys_close (server_fd
);
701 if (!sunos_nfs_get_server_fd (server_fd
, &linux_nfs_mount
.addr
)){
702 sys_close (server_fd
);
706 /* Now, bind it to a locally reserved port */
707 linux_nfs_mount
.version
= NFS_MOUNT_VERSION
;
708 linux_nfs_mount
.flags
= sunos_mount
.flags
;
709 linux_nfs_mount
.fd
= server_fd
;
711 linux_nfs_mount
.rsize
= get_default (sunos_mount
.rsize
, 8192);
712 linux_nfs_mount
.wsize
= get_default (sunos_mount
.wsize
, 8192);
713 linux_nfs_mount
.timeo
= get_default (sunos_mount
.timeo
, 10);
714 linux_nfs_mount
.retrans
= sunos_mount
.retrans
;
716 linux_nfs_mount
.acregmin
= sunos_mount
.acregmin
;
717 linux_nfs_mount
.acregmax
= sunos_mount
.acregmax
;
718 linux_nfs_mount
.acdirmin
= sunos_mount
.acdirmin
;
719 linux_nfs_mount
.acdirmax
= sunos_mount
.acdirmax
;
721 the_name
= getname(sunos_mount
.hostname
);
723 return PTR_ERR(the_name
);
725 strncpy (linux_nfs_mount
.hostname
, the_name
, 254);
726 linux_nfs_mount
.hostname
[255] = 0;
729 return do_mount ("", dir_name
, "nfs", linux_flags
, &linux_nfs_mount
);
732 /* XXXXXXXXXXXXXXXXXXXX */
734 sunos_mount(char *type
, char *dir
, int flags
, void *data
)
736 int linux_flags
= MS_MGC_MSK
; /* new semantics */
739 char *dir_page
, *type_page
;
741 if (!capable (CAP_SYS_ADMIN
))
744 /* We don't handle the integer fs type */
745 if ((flags
& SMNT_NEWTYPE
) == 0)
748 /* Do not allow for those flags we don't support */
749 if (flags
& (SMNT_GRPID
|SMNT_NOSUB
|SMNT_MULTI
|SMNT_SYS5
))
752 if(flags
& SMNT_REMOUNT
)
753 linux_flags
|= MS_REMOUNT
;
754 if(flags
& SMNT_RDONLY
)
755 linux_flags
|= MS_RDONLY
;
756 if(flags
& SMNT_NOSUID
)
757 linux_flags
|= MS_NOSUID
;
759 dir_page
= getname(dir
);
760 ret
= PTR_ERR(dir_page
);
761 if (IS_ERR(dir_page
))
764 type_page
= getname(type
);
765 ret
= PTR_ERR(type_page
);
766 if (IS_ERR(type_page
))
769 if(strcmp(type_page
, "ext2") == 0) {
770 dev_fname
= getname(data
);
771 } else if(strcmp(type_page
, "iso9660") == 0) {
772 dev_fname
= getname(data
);
773 } else if(strcmp(type_page
, "minix") == 0) {
774 dev_fname
= getname(data
);
775 } else if(strcmp(type_page
, "nfs") == 0) {
776 ret
= sunos_nfs_mount (dir_page
, flags
, data
);
778 } else if(strcmp(type_page
, "ufs") == 0) {
779 printk("Warning: UFS filesystem mounts unsupported.\n");
782 } else if(strcmp(type_page
, "proc")) {
786 ret
= PTR_ERR(dev_fname
);
787 if (IS_ERR(dev_fname
))
789 ret
= do_mount(dev_fname
, dir_page
, type_page
, linux_flags
, NULL
);
801 extern asmlinkage
int sys_setsid(void);
802 extern asmlinkage
int sys_setpgid(pid_t
, pid_t
);
804 asmlinkage
int sunos_setpgrp(pid_t pid
, pid_t pgid
)
810 if((!pid
|| pid
== current
->pid
) &&
815 ret
= sys_setpgid(pid
, pgid
);
822 extern asmlinkage
int sys32_wait4(__kernel_pid_t32 pid
,
823 u32 stat_addr
, int options
, u32 ru
);
825 asmlinkage
int sunos_wait4(__kernel_pid_t32 pid
, u32 stat_addr
, int options
, u32 ru
)
830 ret
= sys32_wait4((pid
? pid
: ((__kernel_pid_t32
)-1)),
831 stat_addr
, options
, ru
);
836 extern int kill_pg(int, int, int);
837 asmlinkage
int sunos_killpg(int pgrp
, int sig
)
842 ret
= kill_pg(pgrp
, sig
, 0);
847 asmlinkage
int sunos_audit(void)
850 printk ("sys_audit\n");
855 extern asmlinkage u32
sunos_gethostid(void)
860 ret
= (((u32
)idprom
->id_machtype
<< 24) | ((u32
)idprom
->id_sernum
));
865 /* sysconf options, for SunOS compatibility */
866 #define _SC_ARG_MAX 1
867 #define _SC_CHILD_MAX 2
868 #define _SC_CLK_TCK 3
869 #define _SC_NGROUPS_MAX 4
870 #define _SC_OPEN_MAX 5
871 #define _SC_JOB_CONTROL 6
872 #define _SC_SAVED_IDS 7
873 #define _SC_VERSION 8
875 extern asmlinkage s32
sunos_sysconf (int name
)
890 case _SC_NGROUPS_MAX
:
896 case _SC_JOB_CONTROL
:
897 ret
= 1; /* yes, we do support job control */
900 ret
= 1; /* yes, we do support saved uids */
903 /* mhm, POSIX_VERSION is in /usr/include/unistd.h
904 * should it go on /usr/include/linux?
916 asmlinkage
int sunos_semsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
, u32 ptr
)
924 /* Most arguments match on a 1:1 basis but cmd doesn't */
942 arg4
.__pad
=(void *)A(ptr
); /* value to modify semaphore to */
943 ret
= sys_semctl((int)arg1
, (int)arg2
, (int)arg3
, arg4
);
947 ret
= sys_semget((key_t
)arg1
, (int)arg2
, (int)arg3
);
951 ret
= sys_semop((int)arg1
, (struct sembuf
*)A(arg2
), (unsigned)arg3
);
969 __kernel_uid_t32 uid
;
970 __kernel_gid_t32 gid
;
971 __kernel_uid_t32 cuid
;
972 __kernel_gid_t32 cgid
;
973 __kernel_mode_t32 mode
;
979 struct ipc_perm32 msg_perm
;
982 __kernel_time_t32 msg_stime
;
983 __kernel_time_t32 msg_rtime
;
984 __kernel_time_t32 msg_ctime
;
987 unsigned short msg_cbytes
;
988 unsigned short msg_qnum
;
989 unsigned short msg_qbytes
;
990 __kernel_ipc_pid_t32 msg_lspid
;
991 __kernel_ipc_pid_t32 msg_lrpid
;
994 static inline int sunos_msqid_get(struct msqid_ds32
*user
,
995 struct msqid_ds
*kern
)
997 if(get_user(kern
->msg_perm
.key
, &user
->msg_perm
.key
) ||
998 __get_user(kern
->msg_perm
.uid
, &user
->msg_perm
.uid
) ||
999 __get_user(kern
->msg_perm
.gid
, &user
->msg_perm
.gid
) ||
1000 __get_user(kern
->msg_perm
.cuid
, &user
->msg_perm
.cuid
) ||
1001 __get_user(kern
->msg_perm
.cgid
, &user
->msg_perm
.cgid
) ||
1002 __get_user(kern
->msg_stime
, &user
->msg_stime
) ||
1003 __get_user(kern
->msg_rtime
, &user
->msg_rtime
) ||
1004 __get_user(kern
->msg_ctime
, &user
->msg_ctime
) ||
1005 __get_user(kern
->msg_ctime
, &user
->msg_cbytes
) ||
1006 __get_user(kern
->msg_ctime
, &user
->msg_qnum
) ||
1007 __get_user(kern
->msg_ctime
, &user
->msg_qbytes
) ||
1008 __get_user(kern
->msg_ctime
, &user
->msg_lspid
) ||
1009 __get_user(kern
->msg_ctime
, &user
->msg_lrpid
))
1014 static inline int sunos_msqid_put(struct msqid_ds32
*user
,
1015 struct msqid_ds
*kern
)
1017 if(put_user(kern
->msg_perm
.key
, &user
->msg_perm
.key
) ||
1018 __put_user(kern
->msg_perm
.uid
, &user
->msg_perm
.uid
) ||
1019 __put_user(kern
->msg_perm
.gid
, &user
->msg_perm
.gid
) ||
1020 __put_user(kern
->msg_perm
.cuid
, &user
->msg_perm
.cuid
) ||
1021 __put_user(kern
->msg_perm
.cgid
, &user
->msg_perm
.cgid
) ||
1022 __put_user(kern
->msg_stime
, &user
->msg_stime
) ||
1023 __put_user(kern
->msg_rtime
, &user
->msg_rtime
) ||
1024 __put_user(kern
->msg_ctime
, &user
->msg_ctime
) ||
1025 __put_user(kern
->msg_ctime
, &user
->msg_cbytes
) ||
1026 __put_user(kern
->msg_ctime
, &user
->msg_qnum
) ||
1027 __put_user(kern
->msg_ctime
, &user
->msg_qbytes
) ||
1028 __put_user(kern
->msg_ctime
, &user
->msg_lspid
) ||
1029 __put_user(kern
->msg_ctime
, &user
->msg_lrpid
))
1034 static inline int sunos_msgbuf_get(struct msgbuf32
*user
, struct msgbuf
*kern
, int len
)
1036 if(get_user(kern
->mtype
, &user
->mtype
) ||
1037 __copy_from_user(kern
->mtext
, &user
->mtext
, len
))
1042 static inline int sunos_msgbuf_put(struct msgbuf32
*user
, struct msgbuf
*kern
, int len
)
1044 if(put_user(kern
->mtype
, &user
->mtype
) ||
1045 __copy_to_user(user
->mtext
, kern
->mtext
, len
))
1050 asmlinkage
int sunos_msgsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
, u32 arg4
)
1052 struct sparc_stackf32
*sp
;
1053 struct msqid_ds kds
;
1054 struct msgbuf
*kmbuf
;
1055 mm_segment_t old_fs
= get_fs();
1062 rval
= sys_msgget((key_t
)arg1
, (int)arg2
);
1065 if(!sunos_msqid_get((struct msqid_ds32
*)A(arg3
), &kds
)) {
1067 rval
= sys_msgctl((int)arg1
, (int)arg2
,
1068 (struct msqid_ds
*)A(arg3
));
1071 rval
= sunos_msqid_put((struct msqid_ds32
*)A(arg3
),
1078 kmbuf
= (struct msgbuf
*)kmalloc(sizeof(struct msgbuf
) + arg3
,
1082 sp
= (struct sparc_stackf32
*)
1083 (current
->thread
.kregs
->u_regs
[UREG_FP
] & 0xffffffffUL
);
1084 if(get_user(arg5
, &sp
->xxargs
[0])) {
1089 rval
= sys_msgrcv((int)arg1
, kmbuf
, (size_t)arg3
,
1090 (long)arg4
, (int)arg5
);
1093 rval
= sunos_msgbuf_put((struct msgbuf32
*)A(arg2
),
1099 kmbuf
= (struct msgbuf
*)kmalloc(sizeof(struct msgbuf
) + arg3
,
1101 if(!kmbuf
|| sunos_msgbuf_get((struct msgbuf32
*)A(arg2
),
1105 rval
= sys_msgsnd((int)arg1
, kmbuf
, (size_t)arg3
, (int)arg4
);
1118 struct ipc_perm32 shm_perm
;
1120 __kernel_time_t32 shm_atime
;
1121 __kernel_time_t32 shm_dtime
;
1122 __kernel_time_t32 shm_ctime
;
1123 __kernel_ipc_pid_t32 shm_cpid
;
1124 __kernel_ipc_pid_t32 shm_lpid
;
1125 unsigned short shm_nattch
;
1128 static inline int sunos_shmid_get(struct shmid_ds32
*user
,
1129 struct shmid_ds
*kern
)
1131 if(get_user(kern
->shm_perm
.key
, &user
->shm_perm
.key
) ||
1132 __get_user(kern
->shm_perm
.uid
, &user
->shm_perm
.uid
) ||
1133 __get_user(kern
->shm_perm
.gid
, &user
->shm_perm
.gid
) ||
1134 __get_user(kern
->shm_perm
.cuid
, &user
->shm_perm
.cuid
) ||
1135 __get_user(kern
->shm_perm
.cgid
, &user
->shm_perm
.cgid
) ||
1136 __get_user(kern
->shm_segsz
, &user
->shm_segsz
) ||
1137 __get_user(kern
->shm_atime
, &user
->shm_atime
) ||
1138 __get_user(kern
->shm_dtime
, &user
->shm_dtime
) ||
1139 __get_user(kern
->shm_ctime
, &user
->shm_ctime
) ||
1140 __get_user(kern
->shm_cpid
, &user
->shm_cpid
) ||
1141 __get_user(kern
->shm_lpid
, &user
->shm_lpid
) ||
1142 __get_user(kern
->shm_nattch
, &user
->shm_nattch
))
1147 static inline int sunos_shmid_put(struct shmid_ds32
*user
,
1148 struct shmid_ds
*kern
)
1150 if(put_user(kern
->shm_perm
.key
, &user
->shm_perm
.key
) ||
1151 __put_user(kern
->shm_perm
.uid
, &user
->shm_perm
.uid
) ||
1152 __put_user(kern
->shm_perm
.gid
, &user
->shm_perm
.gid
) ||
1153 __put_user(kern
->shm_perm
.cuid
, &user
->shm_perm
.cuid
) ||
1154 __put_user(kern
->shm_perm
.cgid
, &user
->shm_perm
.cgid
) ||
1155 __put_user(kern
->shm_segsz
, &user
->shm_segsz
) ||
1156 __put_user(kern
->shm_atime
, &user
->shm_atime
) ||
1157 __put_user(kern
->shm_dtime
, &user
->shm_dtime
) ||
1158 __put_user(kern
->shm_ctime
, &user
->shm_ctime
) ||
1159 __put_user(kern
->shm_cpid
, &user
->shm_cpid
) ||
1160 __put_user(kern
->shm_lpid
, &user
->shm_lpid
) ||
1161 __put_user(kern
->shm_nattch
, &user
->shm_nattch
))
1166 asmlinkage
int sunos_shmsys(int op
, u32 arg1
, u32 arg2
, u32 arg3
)
1168 struct shmid_ds ksds
;
1169 unsigned long raddr
;
1170 mm_segment_t old_fs
= get_fs();
1176 /* sys_shmat(): attach a shared memory area */
1177 rval
= sys_shmat((int)arg1
,(char *)A(arg2
),(int)arg3
,&raddr
);
1182 /* sys_shmctl(): modify shared memory area attr. */
1183 if(!sunos_shmid_get((struct shmid_ds32
*)A(arg3
), &ksds
)) {
1185 rval
= sys_shmctl((int)arg1
,(int)arg2
, &ksds
);
1188 rval
= sunos_shmid_put((struct shmid_ds32
*)A(arg3
),
1194 /* sys_shmdt(): detach a shared memory area */
1195 rval
= sys_shmdt((char *)A(arg1
));
1198 /* sys_shmget(): get a shared memory area */
1199 rval
= sys_shmget((key_t
)arg1
,(int)arg2
,(int)arg3
);
1209 extern asmlinkage
long sparc32_open(const char * filename
, int flags
, int mode
);
1211 asmlinkage
int sunos_open(u32 fname
, int flags
, int mode
)
1213 const char *filename
= (const char *)(long)fname
;
1215 return sparc32_open(filename
, flags
, mode
);
1218 #define SUNOS_EWOULDBLOCK 35
1220 /* see the sunos man page read(2v) for an explanation
1221 of this garbage. We use O_NDELAY to mark
1222 file descriptors that have been set non-blocking
1223 using 4.2BSD style calls. (tridge) */
1225 static inline int check_nonblock(int ret
, int fd
)
1227 if (ret
== -EAGAIN
) {
1228 struct file
* file
= fcheck(fd
);
1229 if (file
&& (file
->f_flags
& O_NDELAY
))
1230 ret
= -SUNOS_EWOULDBLOCK
;
1235 extern asmlinkage
int sys_read(unsigned int fd
, char *buf
, unsigned long count
);
1236 extern asmlinkage
int sys_write(unsigned int fd
, char *buf
, unsigned long count
);
1237 extern asmlinkage
int sys_recv(int fd
, void *ubuf
, size_t size
, unsigned flags
);
1238 extern asmlinkage
int sys_send(int fd
, void *buff
, size_t len
, unsigned flags
);
1239 extern asmlinkage
int sys_accept(int fd
, struct sockaddr
*sa
, int *addrlen
);
1240 extern asmlinkage
int sys32_readv(u32 fd
, u32 vector
, s32 count
);
1241 extern asmlinkage
int sys32_writev(u32 fd
, u32 vector
, s32 count
);
1243 asmlinkage
int sunos_read(unsigned int fd
, u32 buf
, u32 count
)
1248 ret
= check_nonblock(sys_read(fd
, (char *)A(buf
), count
), fd
);
1253 asmlinkage
int sunos_readv(u32 fd
, u32 vector
, s32 count
)
1258 ret
= check_nonblock(sys32_readv(fd
, vector
, count
), fd
);
1263 asmlinkage
int sunos_write(unsigned int fd
, u32 buf
, u32 count
)
1268 ret
= check_nonblock(sys_write(fd
, (char *)A(buf
), count
), fd
);
1273 asmlinkage
int sunos_writev(u32 fd
, u32 vector
, s32 count
)
1278 ret
= check_nonblock(sys32_writev(fd
, vector
, count
), fd
);
1283 asmlinkage
int sunos_recv(int fd
, u32 ubuf
, int size
, unsigned flags
)
1288 ret
= check_nonblock(sys_recv(fd
, (void *)A(ubuf
), size
, flags
), fd
);
1293 asmlinkage
int sunos_send(int fd
, u32 buff
, int len
, unsigned flags
)
1298 ret
= check_nonblock(sys_send(fd
, (void *)A(buff
), len
, flags
), fd
);
1303 extern asmlinkage
int sys_setsockopt(int fd
, int level
, int optname
,
1304 char *optval
, int optlen
);
1306 asmlinkage
int sunos_socket(int family
, int type
, int protocol
)
1311 ret
= sys_socket(family
, type
, protocol
);
1315 sys_setsockopt(ret
, SOL_SOCKET
, SO_BSDCOMPAT
,
1316 (char *)&one
, sizeof(one
));
1322 asmlinkage
int sunos_accept(int fd
, u32 sa
, u32 addrlen
)
1328 ret
= check_nonblock(sys_accept(fd
, (struct sockaddr
*)A(sa
),
1329 (int *)A(addrlen
)), fd
);
1330 if (ret
!= -ENETUNREACH
&& ret
!= -EHOSTUNREACH
)
1336 sys_setsockopt(ret
, SOL_SOCKET
, SO_BSDCOMPAT
,
1337 (char *)&one
, sizeof(one
));
1343 #define SUNOS_SV_INTERRUPT 2
1345 asmlinkage
int sunos_sigaction (int sig
, u32 act
, u32 oact
)
1347 struct k_sigaction new_ka
, old_ka
;
1351 old_sigset_t32 mask
;
1353 if (get_user((long)new_ka
.sa
.sa_handler
, &((struct old_sigaction32
*)A(act
))->sa_handler
) ||
1354 __get_user(new_ka
.sa
.sa_flags
, &((struct old_sigaction32
*)A(act
))->sa_flags
))
1356 __get_user(mask
, &((struct old_sigaction32
*)A(act
))->sa_mask
);
1357 new_ka
.sa
.sa_restorer
= NULL
;
1358 new_ka
.ka_restorer
= NULL
;
1359 siginitset(&new_ka
.sa
.sa_mask
, mask
);
1360 new_ka
.sa
.sa_flags
^= SUNOS_SV_INTERRUPT
;
1363 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
1366 old_ka
.sa
.sa_flags
^= SUNOS_SV_INTERRUPT
;
1367 if (put_user((long)old_ka
.sa
.sa_handler
, &((struct old_sigaction32
*)A(oact
))->sa_handler
) ||
1368 __put_user(old_ka
.sa
.sa_flags
, &((struct old_sigaction32
*)A(oact
))->sa_flags
))
1370 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &((struct old_sigaction32
*)A(oact
))->sa_mask
);
1376 extern asmlinkage
int sys_setsockopt(int fd
, int level
, int optname
,
1377 char *optval
, int optlen
);
1378 extern asmlinkage
int sys32_getsockopt(int fd
, int level
, int optname
,
1379 u32 optval
, u32 optlen
);
1381 asmlinkage
int sunos_setsockopt(int fd
, int level
, int optname
, u32 optval
,
1384 int tr_opt
= optname
;
1388 if (level
== SOL_IP
) {
1389 /* Multicast socketopts (ttl, membership) */
1390 if (tr_opt
>=2 && tr_opt
<= 6)
1393 ret
= sys_setsockopt(fd
, level
, tr_opt
, (char *)A(optval
), optlen
);
1398 asmlinkage
int sunos_getsockopt(int fd
, int level
, int optname
,
1399 u32 optval
, u32 optlen
)
1401 int tr_opt
= optname
;
1405 if (level
== SOL_IP
) {
1406 /* Multicast socketopts (ttl, membership) */
1407 if (tr_opt
>=2 && tr_opt
<= 6)
1410 ret
= sys32_getsockopt(fd
, level
, tr_opt
, optval
, optlen
);