1 /* $Id: sys_sunos32.c,v 1.61 2001/08/13 14:40:07 davem Exp $
2 * sys_sunos32.c: SunOS binary compatability layer on sparc64.
3 *
4 * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 *
7 * Based upon preliminary work which is:
8 *
9 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/types.h>
15 #include <linux/mman.h>
16 #include <linux/mm.h>
17 #include <linux/swap.h>
18 #include <linux/fs.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/slab.h>
31 #include <linux/pagemap.h>
32 #include <linux/errno.h>
33 #include <linux/smp.h>
34 #include <linux/smp_lock.h>
35
36 #include <asm/uaccess.h>
37 #include <asm/page.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>
43
44 /* For the nfs mount emulation */
45 #include <linux/socket.h>
46 #include <linux/in.h>
47 #include <linux/nfs.h>
48 #include <linux/nfs2.h>
49 #include <linux/nfs_mount.h>
50
51 /* for sunos_select */
52 #include <linux/time.h>
53 #include <linux/personality.h>
54
55 /* Use this to get at 32-bit user passed pointers. */
56 #define A(__x) \
57 ({ unsigned long __ret; \
58 __asm__ ("srl %0, 0, %0" \
59 : "=r" (__ret) \
60 : "0" (__x)); \
61 __ret; \
62 })
63
64 #define SUNOS_NR_OPEN 256
65
sunos_mmap(u32 addr,u32 len,u32 prot,u32 flags,u32 fd,u32 off)66 asmlinkage u32 sunos_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off)
67 {
68 struct file *file = NULL;
69 unsigned long retval, ret_type;
70
71 if(flags & MAP_NORESERVE) {
72 static int cnt;
73 if (cnt++ < 10)
74 printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
75 current->comm);
76 flags &= ~MAP_NORESERVE;
77 }
78 retval = -EBADF;
79 if(!(flags & MAP_ANONYMOUS)) {
80 struct inode * inode;
81 if(fd >= SUNOS_NR_OPEN)
82 goto out;
83 file = fget(fd);
84 if (!file)
85 goto out;
86 inode = file->f_dentry->d_inode;
87 if(MAJOR(inode->i_rdev)==MEM_MAJOR && MINOR(inode->i_rdev)==5) {
88 flags |= MAP_ANONYMOUS;
89 fput(file);
90 file = NULL;
91 }
92 }
93
94 retval = -EINVAL;
95 if(!(flags & MAP_FIXED))
96 addr = 0;
97 else if (len > 0xf0000000 || addr > 0xf0000000 - len)
98 goto out_putf;
99 ret_type = flags & _MAP_NEW;
100 flags &= ~_MAP_NEW;
101
102 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
103 down_write(¤t->mm->mmap_sem);
104 retval = do_mmap(file,
105 (unsigned long) addr, (unsigned long) len,
106 (unsigned long) prot, (unsigned long) flags,
107 (unsigned long) off);
108 up_write(¤t->mm->mmap_sem);
109 if(!ret_type)
110 retval = ((retval < 0xf0000000) ? 0 : retval);
111 out_putf:
112 if (file)
113 fput(file);
114 out:
115 return (u32) retval;
116 }
117
sunos_mctl(u32 addr,u32 len,int function,u32 arg)118 asmlinkage int sunos_mctl(u32 addr, u32 len, int function, u32 arg)
119 {
120 return 0;
121 }
122
sunos_brk(u32 baddr)123 asmlinkage int sunos_brk(u32 baddr)
124 {
125 int freepages, retval = -ENOMEM;
126 unsigned long rlim;
127 unsigned long newbrk, oldbrk, brk = (unsigned long) baddr;
128
129 down_write(¤t->mm->mmap_sem);
130 if (brk < current->mm->end_code)
131 goto out;
132 newbrk = PAGE_ALIGN(brk);
133 oldbrk = PAGE_ALIGN(current->mm->brk);
134 retval = 0;
135 if (oldbrk == newbrk) {
136 current->mm->brk = brk;
137 goto out;
138 }
139 /* Always allow shrinking brk. */
140 if (brk <= current->mm->brk) {
141 current->mm->brk = brk;
142 do_munmap(current->mm, newbrk, oldbrk-newbrk);
143 goto out;
144 }
145 /* Check against rlimit and stack.. */
146 retval = -ENOMEM;
147 rlim = current->rlim[RLIMIT_DATA].rlim_cur;
148 if (rlim >= RLIM_INFINITY)
149 rlim = ~0;
150 if (brk - current->mm->end_code > rlim)
151 goto out;
152 /* Check against existing mmap mappings. */
153 if (find_vma_intersection(current->mm, oldbrk, newbrk+PAGE_SIZE))
154 goto out;
155 /* stupid algorithm to decide if we have enough memory: while
156 * simple, it hopefully works in most obvious cases.. Easy to
157 * fool it, but this should catch most mistakes.
158 */
159 freepages = atomic_read(&buffermem_pages) >> PAGE_SHIFT;
160 freepages += page_cache_size;
161 freepages >>= 1;
162 freepages += nr_free_pages();
163 freepages += nr_swap_pages;
164 freepages -= num_physpages >> 4;
165 freepages -= (newbrk-oldbrk) >> PAGE_SHIFT;
166 if (freepages < 0)
167 goto out;
168 /* Ok, we have probably got enough memory - let it rip. */
169 current->mm->brk = brk;
170 do_brk(oldbrk, newbrk-oldbrk);
171 retval = 0;
172 out:
173 up_write(¤t->mm->mmap_sem);
174 return retval;
175 }
176
sunos_sbrk(int increment)177 asmlinkage u32 sunos_sbrk(int increment)
178 {
179 int error, oldbrk;
180
181 /* This should do it hopefully... */
182 oldbrk = (int)current->mm->brk;
183 error = sunos_brk(((int) current->mm->brk) + increment);
184 if(!error)
185 error = oldbrk;
186 return error;
187 }
188
sunos_sstk(int increment)189 asmlinkage u32 sunos_sstk(int increment)
190 {
191 printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
192 current->comm, increment);
193
194 return (u32)-1;
195 }
196
197 /* Give hints to the kernel as to what paging strategy to use...
198 * Completely bogus, don't remind me.
199 */
200 #define VA_NORMAL 0 /* Normal vm usage expected */
201 #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
202 #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
203 #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
204 static char *vstrings[] = {
205 "VA_NORMAL",
206 "VA_ABNORMAL",
207 "VA_SEQUENTIAL",
208 "VA_INVALIDATE",
209 };
210
sunos_vadvise(u32 strategy)211 asmlinkage void sunos_vadvise(u32 strategy)
212 {
213 static int count;
214
215 /* I wanna see who uses this... */
216 if (count++ < 5)
217 printk("%s: Advises us to use %s paging strategy\n",
218 current->comm,
219 strategy <= 3 ? vstrings[strategy] : "BOGUS");
220 }
221
222 /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
223 * resource limit and is for backwards compatibility with older sunos
224 * revs.
225 */
sunos_getdtablesize(void)226 asmlinkage int sunos_getdtablesize(void)
227 {
228 return SUNOS_NR_OPEN;
229 }
230
231
232 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
233
sunos_sigblock(u32 blk_mask)234 asmlinkage u32 sunos_sigblock(u32 blk_mask)
235 {
236 u32 old;
237
238 spin_lock_irq(¤t->sigmask_lock);
239 old = (u32) current->blocked.sig[0];
240 current->blocked.sig[0] |= (blk_mask & _BLOCKABLE);
241 recalc_sigpending(current);
242 spin_unlock_irq(¤t->sigmask_lock);
243 return old;
244 }
245
sunos_sigsetmask(u32 newmask)246 asmlinkage u32 sunos_sigsetmask(u32 newmask)
247 {
248 u32 retval;
249
250 spin_lock_irq(¤t->sigmask_lock);
251 retval = (u32) current->blocked.sig[0];
252 current->blocked.sig[0] = (newmask & _BLOCKABLE);
253 recalc_sigpending(current);
254 spin_unlock_irq(¤t->sigmask_lock);
255 return retval;
256 }
257
258 /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
259 /* getdents system call, the format of the structure just has a different */
260 /* layout (d_off+d_ino instead of d_ino+d_off) */
261 struct sunos_dirent {
262 s32 d_off;
263 u32 d_ino;
264 u16 d_reclen;
265 u16 d_namlen;
266 char d_name[1];
267 };
268
269 struct sunos_dirent_callback {
270 struct sunos_dirent *curr;
271 struct sunos_dirent *previous;
272 int count;
273 int error;
274 };
275
276 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
277 #define ROUND_UP(x) (((x)+sizeof(s32)-1) & ~(sizeof(s32)-1))
278
sunos_filldir(void * __buf,const char * name,int namlen,loff_t offset,ino_t ino,unsigned int d_type)279 static int sunos_filldir(void * __buf, const char * name, int namlen,
280 loff_t offset, ino_t ino, unsigned int d_type)
281 {
282 struct sunos_dirent * dirent;
283 struct sunos_dirent_callback * buf = (struct sunos_dirent_callback *) __buf;
284 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
285
286 buf->error = -EINVAL; /* only used if we fail.. */
287 if (reclen > buf->count)
288 return -EINVAL;
289 dirent = buf->previous;
290 if (dirent)
291 put_user(offset, &dirent->d_off);
292 dirent = buf->curr;
293 buf->previous = dirent;
294 put_user(ino, &dirent->d_ino);
295 put_user(namlen, &dirent->d_namlen);
296 put_user(reclen, &dirent->d_reclen);
297 copy_to_user(dirent->d_name, name, namlen);
298 put_user(0, dirent->d_name + namlen);
299 dirent = (void *) dirent + reclen;
300 buf->curr = dirent;
301 buf->count -= reclen;
302 return 0;
303 }
304
sunos_getdents(unsigned int fd,u32 u_dirent,int cnt)305 asmlinkage int sunos_getdents(unsigned int fd, u32 u_dirent, int cnt)
306 {
307 struct file * file;
308 struct sunos_dirent * lastdirent;
309 struct sunos_dirent_callback buf;
310 int error = -EBADF;
311 void *dirent = (void *)A(u_dirent);
312
313 if(fd >= SUNOS_NR_OPEN)
314 goto out;
315
316 file = fget(fd);
317 if(!file)
318 goto out;
319
320 error = -EINVAL;
321 if(cnt < (sizeof(struct sunos_dirent) + 255))
322 goto out_putf;
323
324 buf.curr = (struct sunos_dirent *) dirent;
325 buf.previous = NULL;
326 buf.count = cnt;
327 buf.error = 0;
328
329 error = vfs_readdir(file, sunos_filldir, &buf);
330 if (error < 0)
331 goto out_putf;
332
333 lastdirent = buf.previous;
334 error = buf.error;
335 if (lastdirent) {
336 put_user(file->f_pos, &lastdirent->d_off);
337 error = cnt - buf.count;
338 }
339
340 out_putf:
341 fput(file);
342 out:
343 return error;
344 }
345
346 /* Old sunos getdirentries, severely broken compatibility stuff here. */
347 struct sunos_direntry {
348 u32 d_ino;
349 u16 d_reclen;
350 u16 d_namlen;
351 char d_name[1];
352 };
353
354 struct sunos_direntry_callback {
355 struct sunos_direntry *curr;
356 struct sunos_direntry *previous;
357 int count;
358 int error;
359 };
360
sunos_filldirentry(void * __buf,const char * name,int namlen,loff_t offset,ino_t ino,unsigned int d_type)361 static int sunos_filldirentry(void * __buf, const char * name, int namlen,
362 loff_t offset, ino_t ino, unsigned int d_type)
363 {
364 struct sunos_direntry * dirent;
365 struct sunos_direntry_callback * buf = (struct sunos_direntry_callback *) __buf;
366 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
367
368 buf->error = -EINVAL; /* only used if we fail.. */
369 if (reclen > buf->count)
370 return -EINVAL;
371 dirent = buf->previous;
372 dirent = buf->curr;
373 buf->previous = dirent;
374 put_user(ino, &dirent->d_ino);
375 put_user(namlen, &dirent->d_namlen);
376 put_user(reclen, &dirent->d_reclen);
377 copy_to_user(dirent->d_name, name, namlen);
378 put_user(0, dirent->d_name + namlen);
379 dirent = (void *) dirent + reclen;
380 buf->curr = dirent;
381 buf->count -= reclen;
382 return 0;
383 }
384
sunos_getdirentries(unsigned int fd,u32 u_dirent,int cnt,u32 u_basep)385 asmlinkage int sunos_getdirentries(unsigned int fd, u32 u_dirent,
386 int cnt, u32 u_basep)
387 {
388 void *dirent = (void *) A(u_dirent);
389 unsigned int *basep = (unsigned int *)A(u_basep);
390 struct file * file;
391 struct sunos_direntry * lastdirent;
392 int error = -EBADF;
393 struct sunos_direntry_callback buf;
394
395 if(fd >= SUNOS_NR_OPEN)
396 goto out;
397
398 file = fget(fd);
399 if(!file)
400 goto out;
401
402 error = -EINVAL;
403 if(cnt < (sizeof(struct sunos_direntry) + 255))
404 goto out_putf;
405
406 buf.curr = (struct sunos_direntry *) dirent;
407 buf.previous = NULL;
408 buf.count = cnt;
409 buf.error = 0;
410
411 error = vfs_readdir(file, sunos_filldirentry, &buf);
412 if (error < 0)
413 goto out_putf;
414
415 lastdirent = buf.previous;
416 error = buf.error;
417 if (lastdirent) {
418 put_user(file->f_pos, basep);
419 error = cnt - buf.count;
420 }
421
422 out_putf:
423 fput(file);
424 out:
425 return error;
426 }
427
428 struct sunos_utsname {
429 char sname[9];
430 char nname[9];
431 char nnext[56];
432 char rel[9];
433 char ver[9];
434 char mach[9];
435 };
436
sunos_uname(struct sunos_utsname * name)437 asmlinkage int sunos_uname(struct sunos_utsname *name)
438 {
439 int ret;
440
441 down_read(&uts_sem);
442 ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0], sizeof(name->sname) - 1);
443 ret |= copy_to_user(&name->nname[0], &system_utsname.nodename[0], sizeof(name->nname) - 1);
444 ret |= put_user('\0', &name->nname[8]);
445 ret |= copy_to_user(&name->rel[0], &system_utsname.release[0], sizeof(name->rel) - 1);
446 ret |= copy_to_user(&name->ver[0], &system_utsname.version[0], sizeof(name->ver) - 1);
447 ret |= copy_to_user(&name->mach[0], &system_utsname.machine[0], sizeof(name->mach) - 1);
448 up_read(&uts_sem);
449 return (ret ? -EFAULT : 0);
450 }
451
sunos_nosys(void)452 asmlinkage int sunos_nosys(void)
453 {
454 struct pt_regs *regs;
455 siginfo_t info;
456 static int cnt;
457
458 regs = current->thread.kregs;
459 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
460 regs->tpc &= 0xffffffff;
461 regs->tnpc &= 0xffffffff;
462 }
463 info.si_signo = SIGSYS;
464 info.si_errno = 0;
465 info.si_code = __SI_FAULT|0x100;
466 info.si_addr = (void *)regs->tpc;
467 info.si_trapno = regs->u_regs[UREG_G1];
468 send_sig_info(SIGSYS, &info, current);
469 if (cnt++ < 4) {
470 printk("Process makes ni_syscall number %d, register dump:\n",
471 (int) regs->u_regs[UREG_G1]);
472 show_regs(regs);
473 }
474 return -ENOSYS;
475 }
476
477 /* This is not a real and complete implementation yet, just to keep
478 * the easy SunOS binaries happy.
479 */
sunos_fpathconf(int fd,int name)480 asmlinkage int sunos_fpathconf(int fd, int name)
481 {
482 int ret;
483
484 switch(name) {
485 case _PCONF_LINK:
486 ret = LINK_MAX;
487 break;
488 case _PCONF_CANON:
489 ret = MAX_CANON;
490 break;
491 case _PCONF_INPUT:
492 ret = MAX_INPUT;
493 break;
494 case _PCONF_NAME:
495 ret = NAME_MAX;
496 break;
497 case _PCONF_PATH:
498 ret = PATH_MAX;
499 break;
500 case _PCONF_PIPE:
501 ret = PIPE_BUF;
502 break;
503 case _PCONF_CHRESTRICT: /* XXX Investigate XXX */
504 ret = 1;
505 break;
506 case _PCONF_NOTRUNC: /* XXX Investigate XXX */
507 case _PCONF_VDISABLE:
508 ret = 0;
509 break;
510 default:
511 ret = -EINVAL;
512 break;
513 }
514 return ret;
515 }
516
sunos_pathconf(u32 u_path,int name)517 asmlinkage int sunos_pathconf(u32 u_path, int name)
518 {
519 int ret;
520
521 ret = sunos_fpathconf(0, name); /* XXX cheese XXX */
522 return ret;
523 }
524
525 /* SunOS mount system call emulation */
526 extern asmlinkage int
527 sys32_select(int n, u32 inp, u32 outp, u32 exp, u32 tvp);
528
529 struct timeval32
530 {
531 int tv_sec, tv_usec;
532 };
533
sunos_select(int width,u32 inp,u32 outp,u32 exp,u32 tvp_x)534 asmlinkage int sunos_select(int width, u32 inp, u32 outp, u32 exp, u32 tvp_x)
535 {
536 int ret;
537
538 /* SunOS binaries expect that select won't change the tvp contents */
539 ret = sys32_select (width, inp, outp, exp, tvp_x);
540 if (ret == -EINTR && tvp_x) {
541 struct timeval32 *tvp = (struct timeval32 *)A(tvp_x);
542 time_t sec, usec;
543
544 __get_user(sec, &tvp->tv_sec);
545 __get_user(usec, &tvp->tv_usec);
546 if (sec == 0 && usec == 0)
547 ret = 0;
548 }
549 return ret;
550 }
551
sunos_nop(void)552 asmlinkage void sunos_nop(void)
553 {
554 return;
555 }
556
557 /* XXXXXXXXXX SunOS mount/umount. XXXXXXXXXXX */
558 #define SMNT_RDONLY 1
559 #define SMNT_NOSUID 2
560 #define SMNT_NEWTYPE 4
561 #define SMNT_GRPID 8
562 #define SMNT_REMOUNT 16
563 #define SMNT_NOSUB 32
564 #define SMNT_MULTI 64
565 #define SMNT_SYS5 128
566
567 struct sunos_fh_t {
568 char fh_data [NFS_FHSIZE];
569 };
570
571 struct sunos_nfs_mount_args {
572 struct sockaddr_in *addr; /* file server address */
573 struct nfs_fh *fh; /* File handle to be mounted */
574 int flags; /* flags */
575 int wsize; /* write size in bytes */
576 int rsize; /* read size in bytes */
577 int timeo; /* initial timeout in .1 secs */
578 int retrans; /* times to retry send */
579 char *hostname; /* server's hostname */
580 int acregmin; /* attr cache file min secs */
581 int acregmax; /* attr cache file max secs */
582 int acdirmin; /* attr cache dir min secs */
583 int acdirmax; /* attr cache dir max secs */
584 char *netname; /* server's netname */
585 };
586
587 extern asmlinkage int sys_mount(char *, char *, char *, unsigned long, void *);
588 extern asmlinkage int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen);
589 extern asmlinkage int sys_socket(int family, int type, int protocol);
590 extern asmlinkage int sys_bind(int fd, struct sockaddr *umyaddr, int addrlen);
591
592
593 /* Bind the socket on a local reserved port and connect it to the
594 * remote server. This on Linux/i386 is done by the mount program,
595 * not by the kernel.
596 */
597 /* XXXXXXXXXXXXXXXXXXXX */
598 static int
sunos_nfs_get_server_fd(int fd,struct sockaddr_in * addr)599 sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
600 {
601 struct sockaddr_in local;
602 struct sockaddr_in server;
603 int try_port;
604 int ret;
605 struct socket *socket;
606 struct inode *inode;
607 struct file *file;
608
609 file = fget(fd);
610 if(!file)
611 return 0;
612
613 inode = file->f_dentry->d_inode;
614
615 socket = &inode->u.socket_i;
616 local.sin_family = AF_INET;
617 local.sin_addr.s_addr = INADDR_ANY;
618
619 /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
620 try_port = 1024;
621 do {
622 local.sin_port = htons (--try_port);
623 ret = socket->ops->bind(socket, (struct sockaddr*)&local,
624 sizeof(local));
625 } while (ret && try_port > (1024 / 2));
626
627 if (ret) {
628 fput(file);
629 return 0;
630 }
631
632 server.sin_family = AF_INET;
633 server.sin_addr = addr->sin_addr;
634 server.sin_port = NFS_PORT;
635
636 /* Call sys_connect */
637 ret = socket->ops->connect (socket, (struct sockaddr *) &server,
638 sizeof (server), file->f_flags);
639 fput(file);
640 if (ret < 0)
641 return 0;
642 return 1;
643 }
644
645 /* XXXXXXXXXXXXXXXXXXXX */
get_default(int value,int def_value)646 static int get_default (int value, int def_value)
647 {
648 if (value)
649 return value;
650 else
651 return def_value;
652 }
653
654 /* XXXXXXXXXXXXXXXXXXXX */
sunos_nfs_mount(char * dir_name,int linux_flags,void * data)655 static int sunos_nfs_mount(char *dir_name, int linux_flags, void *data)
656 {
657 int server_fd, err;
658 char *the_name, *mount_page;
659 struct nfs_mount_data linux_nfs_mount;
660 struct sunos_nfs_mount_args sunos_mount;
661
662 /* Ok, here comes the fun part: Linux's nfs mount needs a
663 * socket connection to the server, but SunOS mount does not
664 * require this, so we use the information on the destination
665 * address to create a socket and bind it to a reserved
666 * port on this system
667 */
668 if (copy_from_user(&sunos_mount, data, sizeof(sunos_mount)))
669 return -EFAULT;
670
671 server_fd = sys_socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
672 if (server_fd < 0)
673 return -ENXIO;
674
675 if (copy_from_user(&linux_nfs_mount.addr,sunos_mount.addr,
676 sizeof(*sunos_mount.addr)) ||
677 copy_from_user(&linux_nfs_mount.root,sunos_mount.fh,
678 sizeof(*sunos_mount.fh))) {
679 sys_close (server_fd);
680 return -EFAULT;
681 }
682
683 if (!sunos_nfs_get_server_fd (server_fd, &linux_nfs_mount.addr)){
684 sys_close (server_fd);
685 return -ENXIO;
686 }
687
688 /* Now, bind it to a locally reserved port */
689 linux_nfs_mount.version = NFS_MOUNT_VERSION;
690 linux_nfs_mount.flags = sunos_mount.flags;
691 linux_nfs_mount.fd = server_fd;
692
693 linux_nfs_mount.rsize = get_default (sunos_mount.rsize, 8192);
694 linux_nfs_mount.wsize = get_default (sunos_mount.wsize, 8192);
695 linux_nfs_mount.timeo = get_default (sunos_mount.timeo, 10);
696 linux_nfs_mount.retrans = sunos_mount.retrans;
697
698 linux_nfs_mount.acregmin = sunos_mount.acregmin;
699 linux_nfs_mount.acregmax = sunos_mount.acregmax;
700 linux_nfs_mount.acdirmin = sunos_mount.acdirmin;
701 linux_nfs_mount.acdirmax = sunos_mount.acdirmax;
702
703 the_name = getname(sunos_mount.hostname);
704 if(IS_ERR(the_name))
705 return PTR_ERR(the_name);
706
707 strncpy (linux_nfs_mount.hostname, the_name, 254);
708 linux_nfs_mount.hostname [255] = 0;
709 putname (the_name);
710
711 mount_page = (char *) get_zeroed_page(GFP_KERNEL);
712 if (!mount_page)
713 return -ENOMEM;
714
715 memcpy(mount_page, &linux_nfs_mount, sizeof(linux_nfs_mount));
716
717 err = do_mount("", dir_name, "nfs", linux_flags, mount_page);
718
719 free_page((unsigned long) mount_page);
720 return err;
721 }
722
723 /* XXXXXXXXXXXXXXXXXXXX */
724 asmlinkage int
sunos_mount(char * type,char * dir,int flags,void * data)725 sunos_mount(char *type, char *dir, int flags, void *data)
726 {
727 int linux_flags = 0;
728 int ret = -EINVAL;
729 char *dev_fname = 0;
730 char *dir_page, *type_page;
731
732 if (!capable (CAP_SYS_ADMIN))
733 return -EPERM;
734
735 /* We don't handle the integer fs type */
736 if ((flags & SMNT_NEWTYPE) == 0)
737 goto out;
738
739 /* Do not allow for those flags we don't support */
740 if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5))
741 goto out;
742
743 if(flags & SMNT_REMOUNT)
744 linux_flags |= MS_REMOUNT;
745 if(flags & SMNT_RDONLY)
746 linux_flags |= MS_RDONLY;
747 if(flags & SMNT_NOSUID)
748 linux_flags |= MS_NOSUID;
749
750 dir_page = getname(dir);
751 ret = PTR_ERR(dir_page);
752 if (IS_ERR(dir_page))
753 goto out;
754
755 type_page = getname(type);
756 ret = PTR_ERR(type_page);
757 if (IS_ERR(type_page))
758 goto out1;
759
760 if(strcmp(type_page, "ext2") == 0) {
761 dev_fname = getname(data);
762 } else if(strcmp(type_page, "iso9660") == 0) {
763 dev_fname = getname(data);
764 } else if(strcmp(type_page, "minix") == 0) {
765 dev_fname = getname(data);
766 } else if(strcmp(type_page, "nfs") == 0) {
767 ret = sunos_nfs_mount (dir_page, flags, data);
768 goto out2;
769 } else if(strcmp(type_page, "ufs") == 0) {
770 printk("Warning: UFS filesystem mounts unsupported.\n");
771 ret = -ENODEV;
772 goto out2;
773 } else if(strcmp(type_page, "proc")) {
774 ret = -ENODEV;
775 goto out2;
776 }
777 ret = PTR_ERR(dev_fname);
778 if (IS_ERR(dev_fname))
779 goto out2;
780 lock_kernel();
781 ret = do_mount(dev_fname, dir_page, type_page, linux_flags, NULL);
782 unlock_kernel();
783 if (dev_fname)
784 putname(dev_fname);
785 out2:
786 putname(type_page);
787 out1:
788 putname(dir_page);
789 out:
790 return ret;
791 }
792
793 extern asmlinkage int sys_setsid(void);
794 extern asmlinkage int sys_setpgid(pid_t, pid_t);
795
sunos_setpgrp(pid_t pid,pid_t pgid)796 asmlinkage int sunos_setpgrp(pid_t pid, pid_t pgid)
797 {
798 int ret;
799
800 /* So stupid... */
801 if((!pid || pid == current->pid) &&
802 !pgid) {
803 sys_setsid();
804 ret = 0;
805 } else {
806 ret = sys_setpgid(pid, pgid);
807 }
808 return ret;
809 }
810
811 /* So stupid... */
812 extern asmlinkage int sys32_wait4(__kernel_pid_t32 pid,
813 u32 stat_addr, int options, u32 ru);
814
sunos_wait4(__kernel_pid_t32 pid,u32 stat_addr,int options,u32 ru)815 asmlinkage int sunos_wait4(__kernel_pid_t32 pid, u32 stat_addr, int options, u32 ru)
816 {
817 int ret;
818
819 ret = sys32_wait4((pid ? pid : ((__kernel_pid_t32)-1)),
820 stat_addr, options, ru);
821 return ret;
822 }
823
824 extern int kill_pg(int, int, int);
sunos_killpg(int pgrp,int sig)825 asmlinkage int sunos_killpg(int pgrp, int sig)
826 {
827 return kill_pg(pgrp, sig, 0);
828 }
829
sunos_audit(void)830 asmlinkage int sunos_audit(void)
831 {
832 printk ("sys_audit\n");
833 return -1;
834 }
835
sunos_gethostid(void)836 extern asmlinkage u32 sunos_gethostid(void)
837 {
838 u32 ret;
839
840 ret = (((u32)idprom->id_machtype << 24) | ((u32)idprom->id_sernum));
841
842 return ret;
843 }
844
845 /* sysconf options, for SunOS compatibility */
846 #define _SC_ARG_MAX 1
847 #define _SC_CHILD_MAX 2
848 #define _SC_CLK_TCK 3
849 #define _SC_NGROUPS_MAX 4
850 #define _SC_OPEN_MAX 5
851 #define _SC_JOB_CONTROL 6
852 #define _SC_SAVED_IDS 7
853 #define _SC_VERSION 8
854
sunos_sysconf(int name)855 extern asmlinkage s32 sunos_sysconf (int name)
856 {
857 s32 ret;
858
859 switch (name){
860 case _SC_ARG_MAX:
861 ret = ARG_MAX;
862 break;
863 case _SC_CHILD_MAX:
864 ret = CHILD_MAX;
865 break;
866 case _SC_CLK_TCK:
867 ret = HZ;
868 break;
869 case _SC_NGROUPS_MAX:
870 ret = NGROUPS_MAX;
871 break;
872 case _SC_OPEN_MAX:
873 ret = OPEN_MAX;
874 break;
875 case _SC_JOB_CONTROL:
876 ret = 1; /* yes, we do support job control */
877 break;
878 case _SC_SAVED_IDS:
879 ret = 1; /* yes, we do support saved uids */
880 break;
881 case _SC_VERSION:
882 /* mhm, POSIX_VERSION is in /usr/include/unistd.h
883 * should it go on /usr/include/linux?
884 */
885 ret = 199009;
886 break;
887 default:
888 ret = -1;
889 break;
890 };
891 return ret;
892 }
893
sunos_semsys(int op,u32 arg1,u32 arg2,u32 arg3,u32 ptr)894 asmlinkage int sunos_semsys(int op, u32 arg1, u32 arg2, u32 arg3, u32 ptr)
895 {
896 union semun arg4;
897 int ret;
898
899 switch (op) {
900 case 0:
901 /* Most arguments match on a 1:1 basis but cmd doesn't */
902 switch(arg3) {
903 case 4:
904 arg3=GETPID; break;
905 case 5:
906 arg3=GETVAL; break;
907 case 6:
908 arg3=GETALL; break;
909 case 3:
910 arg3=GETNCNT; break;
911 case 7:
912 arg3=GETZCNT; break;
913 case 8:
914 arg3=SETVAL; break;
915 case 9:
916 arg3=SETALL; break;
917 }
918 /* sys_semctl(): */
919 arg4.__pad=(void *)A(ptr); /* value to modify semaphore to */
920 ret = sys_semctl((int)arg1, (int)arg2, (int)arg3, arg4);
921 break;
922 case 1:
923 /* sys_semget(): */
924 ret = sys_semget((key_t)arg1, (int)arg2, (int)arg3);
925 break;
926 case 2:
927 /* sys_semop(): */
928 ret = sys_semop((int)arg1, (struct sembuf *)A(arg2), (unsigned)arg3);
929 break;
930 default:
931 ret = -EINVAL;
932 break;
933 };
934 return ret;
935 }
936
937 struct msgbuf32 {
938 s32 mtype;
939 char mtext[1];
940 };
941
942 struct ipc_perm32
943 {
944 key_t key;
945 __kernel_uid_t32 uid;
946 __kernel_gid_t32 gid;
947 __kernel_uid_t32 cuid;
948 __kernel_gid_t32 cgid;
949 __kernel_mode_t32 mode;
950 unsigned short seq;
951 };
952
953 struct msqid_ds32
954 {
955 struct ipc_perm32 msg_perm;
956 u32 msg_first;
957 u32 msg_last;
958 __kernel_time_t32 msg_stime;
959 __kernel_time_t32 msg_rtime;
960 __kernel_time_t32 msg_ctime;
961 u32 wwait;
962 u32 rwait;
963 unsigned short msg_cbytes;
964 unsigned short msg_qnum;
965 unsigned short msg_qbytes;
966 __kernel_ipc_pid_t32 msg_lspid;
967 __kernel_ipc_pid_t32 msg_lrpid;
968 };
969
sunos_msqid_get(struct msqid_ds32 * user,struct msqid_ds * kern)970 static inline int sunos_msqid_get(struct msqid_ds32 *user,
971 struct msqid_ds *kern)
972 {
973 if(get_user(kern->msg_perm.key, &user->msg_perm.key) ||
974 __get_user(kern->msg_perm.uid, &user->msg_perm.uid) ||
975 __get_user(kern->msg_perm.gid, &user->msg_perm.gid) ||
976 __get_user(kern->msg_perm.cuid, &user->msg_perm.cuid) ||
977 __get_user(kern->msg_perm.cgid, &user->msg_perm.cgid) ||
978 __get_user(kern->msg_stime, &user->msg_stime) ||
979 __get_user(kern->msg_rtime, &user->msg_rtime) ||
980 __get_user(kern->msg_ctime, &user->msg_ctime) ||
981 __get_user(kern->msg_ctime, &user->msg_cbytes) ||
982 __get_user(kern->msg_ctime, &user->msg_qnum) ||
983 __get_user(kern->msg_ctime, &user->msg_qbytes) ||
984 __get_user(kern->msg_ctime, &user->msg_lspid) ||
985 __get_user(kern->msg_ctime, &user->msg_lrpid))
986 return -EFAULT;
987 return 0;
988 }
989
sunos_msqid_put(struct msqid_ds32 * user,struct msqid_ds * kern)990 static inline int sunos_msqid_put(struct msqid_ds32 *user,
991 struct msqid_ds *kern)
992 {
993 if(put_user(kern->msg_perm.key, &user->msg_perm.key) ||
994 __put_user(kern->msg_perm.uid, &user->msg_perm.uid) ||
995 __put_user(kern->msg_perm.gid, &user->msg_perm.gid) ||
996 __put_user(kern->msg_perm.cuid, &user->msg_perm.cuid) ||
997 __put_user(kern->msg_perm.cgid, &user->msg_perm.cgid) ||
998 __put_user(kern->msg_stime, &user->msg_stime) ||
999 __put_user(kern->msg_rtime, &user->msg_rtime) ||
1000 __put_user(kern->msg_ctime, &user->msg_ctime) ||
1001 __put_user(kern->msg_ctime, &user->msg_cbytes) ||
1002 __put_user(kern->msg_ctime, &user->msg_qnum) ||
1003 __put_user(kern->msg_ctime, &user->msg_qbytes) ||
1004 __put_user(kern->msg_ctime, &user->msg_lspid) ||
1005 __put_user(kern->msg_ctime, &user->msg_lrpid))
1006 return -EFAULT;
1007 return 0;
1008 }
1009
sunos_msgbuf_get(struct msgbuf32 * user,struct msgbuf * kern,int len)1010 static inline int sunos_msgbuf_get(struct msgbuf32 *user, struct msgbuf *kern, int len)
1011 {
1012 if(get_user(kern->mtype, &user->mtype) ||
1013 __copy_from_user(kern->mtext, &user->mtext, len))
1014 return -EFAULT;
1015 return 0;
1016 }
1017
sunos_msgbuf_put(struct msgbuf32 * user,struct msgbuf * kern,int len)1018 static inline int sunos_msgbuf_put(struct msgbuf32 *user, struct msgbuf *kern, int len)
1019 {
1020 if(put_user(kern->mtype, &user->mtype) ||
1021 __copy_to_user(user->mtext, kern->mtext, len))
1022 return -EFAULT;
1023 return 0;
1024 }
1025
sunos_msgsys(int op,u32 arg1,u32 arg2,u32 arg3,u32 arg4)1026 asmlinkage int sunos_msgsys(int op, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
1027 {
1028 struct sparc_stackf32 *sp;
1029 struct msqid_ds kds;
1030 struct msgbuf *kmbuf;
1031 mm_segment_t old_fs = get_fs();
1032 u32 arg5;
1033 int rval;
1034
1035 switch(op) {
1036 case 0:
1037 rval = sys_msgget((key_t)arg1, (int)arg2);
1038 break;
1039 case 1:
1040 if(!sunos_msqid_get((struct msqid_ds32 *)A(arg3), &kds)) {
1041 set_fs(KERNEL_DS);
1042 rval = sys_msgctl((int)arg1, (int)arg2,
1043 (struct msqid_ds *)A(arg3));
1044 set_fs(old_fs);
1045 if(!rval)
1046 rval = sunos_msqid_put((struct msqid_ds32 *)A(arg3),
1047 &kds);
1048 } else
1049 rval = -EFAULT;
1050 break;
1051 case 2:
1052 rval = -EFAULT;
1053 kmbuf = (struct msgbuf *)kmalloc(sizeof(struct msgbuf) + arg3,
1054 GFP_KERNEL);
1055 if(!kmbuf)
1056 break;
1057 sp = (struct sparc_stackf32 *)
1058 (current->thread.kregs->u_regs[UREG_FP] & 0xffffffffUL);
1059 if(get_user(arg5, &sp->xxargs[0])) {
1060 rval = -EFAULT;
1061 kfree(kmbuf);
1062 break;
1063 }
1064 set_fs(KERNEL_DS);
1065 rval = sys_msgrcv((int)arg1, kmbuf, (size_t)arg3,
1066 (long)arg4, (int)arg5);
1067 set_fs(old_fs);
1068 if(!rval)
1069 rval = sunos_msgbuf_put((struct msgbuf32 *)A(arg2),
1070 kmbuf, arg3);
1071 kfree(kmbuf);
1072 break;
1073 case 3:
1074 rval = -EFAULT;
1075 kmbuf = (struct msgbuf *)kmalloc(sizeof(struct msgbuf) + arg3,
1076 GFP_KERNEL);
1077 if(!kmbuf || sunos_msgbuf_get((struct msgbuf32 *)A(arg2),
1078 kmbuf, arg3))
1079 break;
1080 set_fs(KERNEL_DS);
1081 rval = sys_msgsnd((int)arg1, kmbuf, (size_t)arg3, (int)arg4);
1082 set_fs(old_fs);
1083 kfree(kmbuf);
1084 break;
1085 default:
1086 rval = -EINVAL;
1087 break;
1088 }
1089 return rval;
1090 }
1091
1092 struct shmid_ds32 {
1093 struct ipc_perm32 shm_perm;
1094 int shm_segsz;
1095 __kernel_time_t32 shm_atime;
1096 __kernel_time_t32 shm_dtime;
1097 __kernel_time_t32 shm_ctime;
1098 __kernel_ipc_pid_t32 shm_cpid;
1099 __kernel_ipc_pid_t32 shm_lpid;
1100 unsigned short shm_nattch;
1101 };
1102
sunos_shmid_get(struct shmid_ds32 * user,struct shmid_ds * kern)1103 static inline int sunos_shmid_get(struct shmid_ds32 *user,
1104 struct shmid_ds *kern)
1105 {
1106 if(get_user(kern->shm_perm.key, &user->shm_perm.key) ||
1107 __get_user(kern->shm_perm.uid, &user->shm_perm.uid) ||
1108 __get_user(kern->shm_perm.gid, &user->shm_perm.gid) ||
1109 __get_user(kern->shm_perm.cuid, &user->shm_perm.cuid) ||
1110 __get_user(kern->shm_perm.cgid, &user->shm_perm.cgid) ||
1111 __get_user(kern->shm_segsz, &user->shm_segsz) ||
1112 __get_user(kern->shm_atime, &user->shm_atime) ||
1113 __get_user(kern->shm_dtime, &user->shm_dtime) ||
1114 __get_user(kern->shm_ctime, &user->shm_ctime) ||
1115 __get_user(kern->shm_cpid, &user->shm_cpid) ||
1116 __get_user(kern->shm_lpid, &user->shm_lpid) ||
1117 __get_user(kern->shm_nattch, &user->shm_nattch))
1118 return -EFAULT;
1119 return 0;
1120 }
1121
sunos_shmid_put(struct shmid_ds32 * user,struct shmid_ds * kern)1122 static inline int sunos_shmid_put(struct shmid_ds32 *user,
1123 struct shmid_ds *kern)
1124 {
1125 if(put_user(kern->shm_perm.key, &user->shm_perm.key) ||
1126 __put_user(kern->shm_perm.uid, &user->shm_perm.uid) ||
1127 __put_user(kern->shm_perm.gid, &user->shm_perm.gid) ||
1128 __put_user(kern->shm_perm.cuid, &user->shm_perm.cuid) ||
1129 __put_user(kern->shm_perm.cgid, &user->shm_perm.cgid) ||
1130 __put_user(kern->shm_segsz, &user->shm_segsz) ||
1131 __put_user(kern->shm_atime, &user->shm_atime) ||
1132 __put_user(kern->shm_dtime, &user->shm_dtime) ||
1133 __put_user(kern->shm_ctime, &user->shm_ctime) ||
1134 __put_user(kern->shm_cpid, &user->shm_cpid) ||
1135 __put_user(kern->shm_lpid, &user->shm_lpid) ||
1136 __put_user(kern->shm_nattch, &user->shm_nattch))
1137 return -EFAULT;
1138 return 0;
1139 }
1140
sunos_shmsys(int op,u32 arg1,u32 arg2,u32 arg3)1141 asmlinkage int sunos_shmsys(int op, u32 arg1, u32 arg2, u32 arg3)
1142 {
1143 struct shmid_ds ksds;
1144 unsigned long raddr;
1145 mm_segment_t old_fs = get_fs();
1146 int rval;
1147
1148 switch(op) {
1149 case 0:
1150 /* sys_shmat(): attach a shared memory area */
1151 rval = sys_shmat((int)arg1,(char *)A(arg2),(int)arg3,&raddr);
1152 if(!rval)
1153 rval = (int) raddr;
1154 break;
1155 case 1:
1156 /* sys_shmctl(): modify shared memory area attr. */
1157 if(!sunos_shmid_get((struct shmid_ds32 *)A(arg3), &ksds)) {
1158 set_fs(KERNEL_DS);
1159 rval = sys_shmctl((int)arg1,(int)arg2, &ksds);
1160 set_fs(old_fs);
1161 if(!rval)
1162 rval = sunos_shmid_put((struct shmid_ds32 *)A(arg3),
1163 &ksds);
1164 } else
1165 rval = -EFAULT;
1166 break;
1167 case 2:
1168 /* sys_shmdt(): detach a shared memory area */
1169 rval = sys_shmdt((char *)A(arg1));
1170 break;
1171 case 3:
1172 /* sys_shmget(): get a shared memory area */
1173 rval = sys_shmget((key_t)arg1,(int)arg2,(int)arg3);
1174 break;
1175 default:
1176 rval = -EINVAL;
1177 break;
1178 };
1179 return rval;
1180 }
1181
1182 extern asmlinkage long sparc32_open(const char * filename, int flags, int mode);
1183
sunos_open(u32 fname,int flags,int mode)1184 asmlinkage int sunos_open(u32 fname, int flags, int mode)
1185 {
1186 const char *filename = (const char *)(long)fname;
1187
1188 return sparc32_open(filename, flags, mode);
1189 }
1190
1191 #define SUNOS_EWOULDBLOCK 35
1192
1193 /* see the sunos man page read(2v) for an explanation
1194 of this garbage. We use O_NDELAY to mark
1195 file descriptors that have been set non-blocking
1196 using 4.2BSD style calls. (tridge) */
1197
check_nonblock(int ret,int fd)1198 static inline int check_nonblock(int ret, int fd)
1199 {
1200 if (ret == -EAGAIN) {
1201 struct file * file = fget(fd);
1202 if (file) {
1203 if (file->f_flags & O_NDELAY)
1204 ret = -SUNOS_EWOULDBLOCK;
1205 fput(file);
1206 }
1207 }
1208 return ret;
1209 }
1210
1211 extern asmlinkage ssize_t sys_read(unsigned int fd, char *buf, unsigned long count);
1212 extern asmlinkage ssize_t sys_write(unsigned int fd, char *buf, unsigned long count);
1213 extern asmlinkage int sys_recv(int fd, void *ubuf, size_t size, unsigned flags);
1214 extern asmlinkage int sys_send(int fd, void *buff, size_t len, unsigned flags);
1215 extern asmlinkage int sys_accept(int fd, struct sockaddr *sa, int *addrlen);
1216 extern asmlinkage int sys32_readv(u32 fd, u32 vector, s32 count);
1217 extern asmlinkage int sys32_writev(u32 fd, u32 vector, s32 count);
1218
sunos_read(unsigned int fd,u32 buf,u32 count)1219 asmlinkage int sunos_read(unsigned int fd, u32 buf, u32 count)
1220 {
1221 int ret;
1222
1223 ret = check_nonblock(sys_read(fd, (char *)A(buf), count), fd);
1224 return ret;
1225 }
1226
sunos_readv(u32 fd,u32 vector,s32 count)1227 asmlinkage int sunos_readv(u32 fd, u32 vector, s32 count)
1228 {
1229 int ret;
1230
1231 ret = check_nonblock(sys32_readv(fd, vector, count), fd);
1232 return ret;
1233 }
1234
sunos_write(unsigned int fd,u32 buf,u32 count)1235 asmlinkage int sunos_write(unsigned int fd, u32 buf, u32 count)
1236 {
1237 int ret;
1238
1239 ret = check_nonblock(sys_write(fd, (char *)A(buf), count), fd);
1240 return ret;
1241 }
1242
sunos_writev(u32 fd,u32 vector,s32 count)1243 asmlinkage int sunos_writev(u32 fd, u32 vector, s32 count)
1244 {
1245 int ret;
1246
1247 ret = check_nonblock(sys32_writev(fd, vector, count), fd);
1248 return ret;
1249 }
1250
sunos_recv(int fd,u32 ubuf,int size,unsigned flags)1251 asmlinkage int sunos_recv(int fd, u32 ubuf, int size, unsigned flags)
1252 {
1253 int ret;
1254
1255 ret = check_nonblock(sys_recv(fd, (void *)A(ubuf), size, flags), fd);
1256 return ret;
1257 }
1258
sunos_send(int fd,u32 buff,int len,unsigned flags)1259 asmlinkage int sunos_send(int fd, u32 buff, int len, unsigned flags)
1260 {
1261 int ret;
1262
1263 ret = check_nonblock(sys_send(fd, (void *)A(buff), len, flags), fd);
1264 return ret;
1265 }
1266
1267 extern asmlinkage int sys_setsockopt(int fd, int level, int optname,
1268 char *optval, int optlen);
1269
sunos_socket(int family,int type,int protocol)1270 asmlinkage int sunos_socket(int family, int type, int protocol)
1271 {
1272 int ret, one = 1;
1273
1274 ret = sys_socket(family, type, protocol);
1275 if (ret < 0)
1276 goto out;
1277
1278 sys_setsockopt(ret, SOL_SOCKET, SO_BSDCOMPAT,
1279 (char *)&one, sizeof(one));
1280 out:
1281 return ret;
1282 }
1283
sunos_accept(int fd,u32 sa,u32 addrlen)1284 asmlinkage int sunos_accept(int fd, u32 sa, u32 addrlen)
1285 {
1286 int ret, one = 1;
1287
1288 while (1) {
1289 ret = check_nonblock(sys_accept(fd, (struct sockaddr *)A(sa),
1290 (int *)A(addrlen)), fd);
1291 if (ret != -ENETUNREACH && ret != -EHOSTUNREACH)
1292 break;
1293 }
1294 if (ret < 0)
1295 goto out;
1296
1297 sys_setsockopt(ret, SOL_SOCKET, SO_BSDCOMPAT,
1298 (char *)&one, sizeof(one));
1299 out:
1300 return ret;
1301 }
1302
1303 #define SUNOS_SV_INTERRUPT 2
1304
sunos_sigaction(int sig,u32 act,u32 oact)1305 asmlinkage int sunos_sigaction (int sig, u32 act, u32 oact)
1306 {
1307 struct k_sigaction new_ka, old_ka;
1308 int ret;
1309
1310 if (act) {
1311 old_sigset_t32 mask;
1312 u32 u_handler;
1313
1314 if (get_user(u_handler, &((struct old_sigaction32 *)A(act))->sa_handler) ||
1315 __get_user(new_ka.sa.sa_flags, &((struct old_sigaction32 *)A(act))->sa_flags))
1316 return -EFAULT;
1317 new_ka.sa.sa_handler = (void *) (long) u_handler;
1318 __get_user(mask, &((struct old_sigaction32 *)A(act))->sa_mask);
1319 new_ka.sa.sa_restorer = NULL;
1320 new_ka.ka_restorer = NULL;
1321 siginitset(&new_ka.sa.sa_mask, mask);
1322 new_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1323 }
1324
1325 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
1326
1327 if (!ret && oact) {
1328 old_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1329 if (put_user((long)old_ka.sa.sa_handler, &((struct old_sigaction32 *)A(oact))->sa_handler) ||
1330 __put_user(old_ka.sa.sa_flags, &((struct old_sigaction32 *)A(oact))->sa_flags))
1331 return -EFAULT;
1332 __put_user(old_ka.sa.sa_mask.sig[0], &((struct old_sigaction32 *)A(oact))->sa_mask);
1333 }
1334
1335 return ret;
1336 }
1337
1338 extern asmlinkage int sys_setsockopt(int fd, int level, int optname,
1339 char *optval, int optlen);
1340 extern asmlinkage int sys32_getsockopt(int fd, int level, int optname,
1341 u32 optval, u32 optlen);
1342
sunos_setsockopt(int fd,int level,int optname,u32 optval,int optlen)1343 asmlinkage int sunos_setsockopt(int fd, int level, int optname, u32 optval,
1344 int optlen)
1345 {
1346 int tr_opt = optname;
1347 int ret;
1348
1349 if (level == SOL_IP) {
1350 /* Multicast socketopts (ttl, membership) */
1351 if (tr_opt >=2 && tr_opt <= 6)
1352 tr_opt += 30;
1353 }
1354 ret = sys_setsockopt(fd, level, tr_opt, (char *)A(optval), optlen);
1355 return ret;
1356 }
1357
sunos_getsockopt(int fd,int level,int optname,u32 optval,u32 optlen)1358 asmlinkage int sunos_getsockopt(int fd, int level, int optname,
1359 u32 optval, u32 optlen)
1360 {
1361 int tr_opt = optname;
1362 int ret;
1363
1364 if (level == SOL_IP) {
1365 /* Multicast socketopts (ttl, membership) */
1366 if (tr_opt >=2 && tr_opt <= 6)
1367 tr_opt += 30;
1368 }
1369 ret = sys32_getsockopt(fd, level, tr_opt, optval, optlen);
1370 return ret;
1371 }
1372