Import 2.3.47pre1
[davej-history.git] / arch / sparc64 / solaris / misc.c
blob9e2bd4118f2980581950a6615e80cc52317265ec
1 /* $Id: misc.c,v 1.22 2000/02/16 07:31:41 davem Exp $
2 * misc.c: Miscelaneous syscall emulation for Solaris
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 */
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/smp_lock.h>
10 #include <linux/utsname.h>
11 #include <linux/limits.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/mman.h>
15 #include <linux/file.h>
16 #include <linux/timex.h>
18 #include <asm/uaccess.h>
19 #include <asm/string.h>
20 #include <asm/oplib.h>
21 #include <asm/idprom.h>
22 #include <asm/machines.h>
24 #include "conv.h"
26 /* Conversion from Linux to Solaris errnos. 0-34 are identity mapped.
27 Some Linux errnos (EPROCLIM, EDOTDOT, ERREMOTE, EUCLEAN, ENOTNAM,
28 ENAVAIL, EISNAM, EREMOTEIO, ENOMEDIUM, EMEDIUMTYPE) have no Solaris
29 equivalents. I return EINVAL in that case, which is very wrong. If
30 someone suggest a better value for them, you're welcomed.
31 On the other side, Solaris ECANCELED and ENOTSUP have no Linux equivalents,
32 but that doesn't matter here. --jj */
33 int solaris_err_table[] = {
34 /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
35 /* 10 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
36 /* 20 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
37 /* 30 */ 30, 31, 32, 33, 34, 22, 150, 149, 95, 96,
38 /* 40 */ 97, 98, 99, 120, 121, 122, 123, 124, 125, 126,
39 /* 50 */ 127, 128, 129, 130, 131, 132, 133, 134, 143, 144,
40 /* 60 */ 145, 146, 90, 78, 147, 148, 93, 22, 94, 49,
41 /* 70 */ 151, 66, 60, 62, 63, 35, 77, 36, 45, 46,
42 /* 80 */ 64, 22, 67, 68, 69, 70, 71, 74, 22, 82,
43 /* 90 */ 89, 92, 79, 81, 37, 38, 39, 40, 41, 42,
44 /* 100 */ 43, 44, 50, 51, 52, 53, 54, 55, 56, 57,
45 /* 110 */ 87, 61, 84, 65, 83, 80, 91, 22, 22, 22,
46 /* 120 */ 22, 22, 88, 86, 85, 22, 22,
49 #define SOLARIS_NR_OPEN 256
51 static u32 do_solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u64 off)
53 struct file *file = NULL;
54 unsigned long retval, ret_type;
56 lock_kernel();
57 current->personality |= PER_SVR4;
58 if (flags & MAP_NORESERVE) {
59 static int cnt = 0;
61 if (cnt < 5) {
62 printk("%s: unimplemented Solaris MAP_NORESERVE mmap() flag\n",
63 current->comm);
64 cnt++;
66 flags &= ~MAP_NORESERVE;
68 retval = -EBADF;
69 if(!(flags & MAP_ANONYMOUS)) {
70 if(fd >= SOLARIS_NR_OPEN)
71 goto out;
72 file = fget(fd);
73 if (!file)
74 goto out;
75 if (file->f_dentry && file->f_dentry->d_inode) {
76 struct inode * inode = file->f_dentry->d_inode;
77 if(MAJOR(inode->i_rdev) == MEM_MAJOR &&
78 MINOR(inode->i_rdev) == 5) {
79 flags |= MAP_ANONYMOUS;
80 fput(file);
81 file = NULL;
86 retval = -EINVAL;
87 len = PAGE_ALIGN(len);
88 if(!(flags & MAP_FIXED))
89 addr = 0;
90 else if (len > 0xf0000000UL || addr > 0xf0000000UL - len)
91 goto out_putf;
92 ret_type = flags & _MAP_NEW;
93 flags &= ~_MAP_NEW;
95 down(&current->mm->mmap_sem);
96 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
97 retval = do_mmap(file,
98 (unsigned long) addr, (unsigned long) len,
99 (unsigned long) prot, (unsigned long) flags, off);
100 up(&current->mm->mmap_sem);
101 if(!ret_type)
102 retval = ((retval < 0xf0000000) ? 0 : retval);
104 out_putf:
105 if (file)
106 fput(file);
107 out:
108 unlock_kernel();
109 return (u32) retval;
112 asmlinkage u32 solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off)
114 return do_solaris_mmap(addr, len, prot, flags, fd, (u64) off);
117 asmlinkage u32 solaris_mmap64(struct pt_regs *regs, u32 len, u32 prot, u32 flags, u32 fd, u32 offhi)
119 u32 offlo;
121 if (regs->u_regs[UREG_G1]) {
122 if (get_user (offlo, (u32 *)(long)((u32)regs->u_regs[UREG_I6] + 0x5c)))
123 return -EFAULT;
124 } else {
125 if (get_user (offlo, (u32 *)(long)((u32)regs->u_regs[UREG_I6] + 0x60)))
126 return -EFAULT;
128 return do_solaris_mmap((u32)regs->u_regs[UREG_I0], len, prot, flags, fd, (((u64)offhi)<<32)|offlo);
131 asmlinkage int solaris_brk(u32 brk)
133 int (*sunos_brk)(u32) = (int (*)(u32))SUNOS(17);
135 return sunos_brk(brk);
138 #define set_utsfield(to, from, dotchop, countfrom) { \
139 char *p; \
140 int i, len = (countfrom) ? \
141 ((sizeof(to) > sizeof(from) ? \
142 sizeof(from) : sizeof(to))) : sizeof(to); \
143 copy_to_user_ret(to, from, len, -EFAULT); \
144 if (dotchop) \
145 for (p=from,i=0; *p && *p != '.' && --len; p++,i++); \
146 else \
147 i = len - 1; \
148 __put_user_ret('\0', (char *)(to+i), -EFAULT); \
151 struct sol_uname {
152 char sysname[9];
153 char nodename[9];
154 char release[9];
155 char version[9];
156 char machine[9];
159 struct sol_utsname {
160 char sysname[257];
161 char nodename[257];
162 char release[257];
163 char version[257];
164 char machine[257];
167 static char *machine(void)
169 switch (sparc_cpu_model) {
170 case sun4: return "sun4";
171 case sun4c: return "sun4c";
172 case sun4e: return "sun4e";
173 case sun4m: return "sun4m";
174 case sun4d: return "sun4d";
175 case sun4u: return "sun4u";
176 default: return "sparc";
180 static char *platform(char *buffer)
182 int i, len;
183 struct {
184 char *platform;
185 int id_machtype;
186 } platforms [] = {
187 { "sun4", (SM_SUN4 | SM_4_110) },
188 { "sun4", (SM_SUN4 | SM_4_260) },
189 { "sun4", (SM_SUN4 | SM_4_330) },
190 { "sun4", (SM_SUN4 | SM_4_470) },
191 { "SUNW,Sun_4_60", (SM_SUN4C | SM_4C_SS1) },
192 { "SUNW,Sun_4_40", (SM_SUN4C | SM_4C_IPC) },
193 { "SUNW,Sun_4_65", (SM_SUN4C | SM_4C_SS1PLUS) },
194 { "SUNW,Sun_4_20", (SM_SUN4C | SM_4C_SLC) },
195 { "SUNW,Sun_4_75", (SM_SUN4C | SM_4C_SS2) },
196 { "SUNW,Sun_4_25", (SM_SUN4C | SM_4C_ELC) },
197 { "SUNW,Sun_4_50", (SM_SUN4C | SM_4C_IPX) },
198 { "SUNW,Sun_4_600", (SM_SUN4M | SM_4M_SS60) },
199 { "SUNW,SPARCstation-5", (SM_SUN4M | SM_4M_SS50) },
200 { "SUNW,SPARCstation-20", (SM_SUN4M | SM_4M_SS40) }
203 *buffer = 0;
204 len = prom_getproperty(prom_root_node, "name", buffer, 256);
205 if(len > 0)
206 buffer[len] = 0;
207 if (*buffer) {
208 char *p;
210 for (p = buffer; *p; p++)
211 if (*p == '/' || *p == ' ') *p = '_';
212 return buffer;
214 for (i = 0; i < sizeof (platforms)/sizeof (platforms[0]); i++)
215 if (platforms[i].id_machtype == idprom->id_machtype)
216 return platforms[i].platform;
217 return "sun4c";
220 static char *serial(char *buffer)
222 int node = prom_getchild(prom_root_node);
223 int len;
225 node = prom_searchsiblings(node, "options");
226 *buffer = 0;
227 len = prom_getproperty(node, "system-board-serial#", buffer, 256);
228 if(len > 0)
229 buffer[len] = 0;
230 if (!*buffer)
231 return "4512348717234";
232 else
233 return buffer;
236 asmlinkage int solaris_utssys(u32 buf, u32 flags, int which, u32 buf2)
238 switch (which) {
239 case 0: /* old uname */
240 /* Let's cheat */
241 set_utsfield(((struct sol_uname *)A(buf))->sysname,
242 "SunOS", 1, 0);
243 down_read(&uts_sem);
244 set_utsfield(((struct sol_uname *)A(buf))->nodename,
245 system_utsname.nodename, 1, 1);
246 up_read(&uts_sem);
247 set_utsfield(((struct sol_uname *)A(buf))->release,
248 "2.6", 0, 0);
249 set_utsfield(((struct sol_uname *)A(buf))->version,
250 "Generic", 0, 0);
251 set_utsfield(((struct sol_uname *)A(buf))->machine,
252 machine(), 0, 0);
253 return 0;
254 case 2: /* ustat */
255 return -ENOSYS;
256 case 3: /* fusers */
257 return -ENOSYS;
258 default:
259 return -ENOSYS;
263 asmlinkage int solaris_utsname(u32 buf)
265 /* Why should we not lie a bit? */
266 down_read(&uts_sem);
267 set_utsfield(((struct sol_utsname *)A(buf))->sysname,
268 "SunOS", 0, 0);
269 set_utsfield(((struct sol_utsname *)A(buf))->nodename,
270 system_utsname.nodename, 1, 1);
271 set_utsfield(((struct sol_utsname *)A(buf))->release,
272 "5.6", 0, 0);
273 set_utsfield(((struct sol_utsname *)A(buf))->version,
274 "Generic", 0, 0);
275 set_utsfield(((struct sol_utsname *)A(buf))->machine,
276 machine(), 0, 0);
277 up_read(&uts_sem);
278 return 0;
281 #define SI_SYSNAME 1 /* return name of operating system */
282 #define SI_HOSTNAME 2 /* return name of node */
283 #define SI_RELEASE 3 /* return release of operating system */
284 #define SI_VERSION 4 /* return version field of utsname */
285 #define SI_MACHINE 5 /* return kind of machine */
286 #define SI_ARCHITECTURE 6 /* return instruction set arch */
287 #define SI_HW_SERIAL 7 /* return hardware serial number */
288 #define SI_HW_PROVIDER 8 /* return hardware manufacturer */
289 #define SI_SRPC_DOMAIN 9 /* return secure RPC domain */
290 #define SI_PLATFORM 513 /* return platform identifier */
292 asmlinkage int solaris_sysinfo(int cmd, u32 buf, s32 count)
294 char *p, *q, *r;
295 char buffer[256];
296 int len;
298 /* Again, we cheat :)) */
299 switch (cmd) {
300 case SI_SYSNAME: r = "SunOS"; break;
301 case SI_HOSTNAME:
302 r = buffer + 256;
303 down_read(&uts_sem);
304 for (p = system_utsname.nodename, q = buffer;
305 q < r && *p && *p != '.'; *q++ = *p++);
306 up_read(&uts_sem);
307 *q = 0;
308 r = buffer;
309 break;
310 case SI_RELEASE: r = "5.6"; break;
311 case SI_MACHINE: r = machine(); break;
312 case SI_ARCHITECTURE: r = "sparc"; break;
313 case SI_HW_PROVIDER: r = "Sun_Microsystems"; break;
314 case SI_HW_SERIAL: r = serial(buffer); break;
315 case SI_PLATFORM: r = platform(buffer); break;
316 case SI_SRPC_DOMAIN: r = ""; break;
317 case SI_VERSION: r = "Generic"; break;
318 default: return -EINVAL;
320 len = strlen(r) + 1;
321 if (count < len) {
322 copy_to_user_ret((char *)A(buf), r, count - 1, -EFAULT);
323 __put_user_ret(0, (char *)A(buf) + count - 1, -EFAULT);
324 } else
325 copy_to_user_ret((char *)A(buf), r, len, -EFAULT);
326 return len;
329 #define SOLARIS_CONFIG_NGROUPS 2
330 #define SOLARIS_CONFIG_CHILD_MAX 3
331 #define SOLARIS_CONFIG_OPEN_FILES 4
332 #define SOLARIS_CONFIG_POSIX_VER 5
333 #define SOLARIS_CONFIG_PAGESIZE 6
334 #define SOLARIS_CONFIG_CLK_TCK 7
335 #define SOLARIS_CONFIG_XOPEN_VER 8
336 #define SOLARIS_CONFIG_PROF_TCK 10
337 #define SOLARIS_CONFIG_NPROC_CONF 11
338 #define SOLARIS_CONFIG_NPROC_ONLN 12
339 #define SOLARIS_CONFIG_AIO_LISTIO_MAX 13
340 #define SOLARIS_CONFIG_AIO_MAX 14
341 #define SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX 15
342 #define SOLARIS_CONFIG_DELAYTIMER_MAX 16
343 #define SOLARIS_CONFIG_MQ_OPEN_MAX 17
344 #define SOLARIS_CONFIG_MQ_PRIO_MAX 18
345 #define SOLARIS_CONFIG_RTSIG_MAX 19
346 #define SOLARIS_CONFIG_SEM_NSEMS_MAX 20
347 #define SOLARIS_CONFIG_SEM_VALUE_MAX 21
348 #define SOLARIS_CONFIG_SIGQUEUE_MAX 22
349 #define SOLARIS_CONFIG_SIGRT_MIN 23
350 #define SOLARIS_CONFIG_SIGRT_MAX 24
351 #define SOLARIS_CONFIG_TIMER_MAX 25
352 #define SOLARIS_CONFIG_PHYS_PAGES 26
353 #define SOLARIS_CONFIG_AVPHYS_PAGES 27
355 extern unsigned prom_cpu_nodes[NR_CPUS];
357 asmlinkage int solaris_sysconf(int id)
359 switch (id) {
360 case SOLARIS_CONFIG_NGROUPS: return NGROUPS_MAX;
361 case SOLARIS_CONFIG_CHILD_MAX: return CHILD_MAX;
362 case SOLARIS_CONFIG_OPEN_FILES: return OPEN_MAX;
363 case SOLARIS_CONFIG_POSIX_VER: return 199309;
364 case SOLARIS_CONFIG_PAGESIZE: return PAGE_SIZE;
365 case SOLARIS_CONFIG_XOPEN_VER: return 3;
366 case SOLARIS_CONFIG_CLK_TCK:
367 case SOLARIS_CONFIG_PROF_TCK:
368 return prom_getintdefault(prom_cpu_nodes[smp_processor_id()],
369 "clock-frequency", 167000000);
370 #ifdef __SMP__
371 case SOLARIS_CONFIG_NPROC_CONF: return NR_CPUS;
372 case SOLARIS_CONFIG_NPROC_ONLN: return smp_num_cpus;
373 #else
374 case SOLARIS_CONFIG_NPROC_CONF: return 1;
375 case SOLARIS_CONFIG_NPROC_ONLN: return 1;
376 #endif
377 case SOLARIS_CONFIG_SIGRT_MIN: return 37;
378 case SOLARIS_CONFIG_SIGRT_MAX: return 44;
379 case SOLARIS_CONFIG_PHYS_PAGES:
380 case SOLARIS_CONFIG_AVPHYS_PAGES:
382 struct sysinfo s;
384 si_meminfo(&s);
385 if (id == SOLARIS_CONFIG_PHYS_PAGES)
386 return s.totalram >>= PAGE_SHIFT;
387 else
388 return s.freeram >>= PAGE_SHIFT;
390 /* XXX support these as well -jj */
391 case SOLARIS_CONFIG_AIO_LISTIO_MAX: return -EINVAL;
392 case SOLARIS_CONFIG_AIO_MAX: return -EINVAL;
393 case SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX: return -EINVAL;
394 case SOLARIS_CONFIG_DELAYTIMER_MAX: return -EINVAL;
395 case SOLARIS_CONFIG_MQ_OPEN_MAX: return -EINVAL;
396 case SOLARIS_CONFIG_MQ_PRIO_MAX: return -EINVAL;
397 case SOLARIS_CONFIG_RTSIG_MAX: return -EINVAL;
398 case SOLARIS_CONFIG_SEM_NSEMS_MAX: return -EINVAL;
399 case SOLARIS_CONFIG_SEM_VALUE_MAX: return -EINVAL;
400 case SOLARIS_CONFIG_SIGQUEUE_MAX: return -EINVAL;
401 case SOLARIS_CONFIG_TIMER_MAX: return -EINVAL;
402 default: return -EINVAL;
406 asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
408 int ret;
410 switch (cmd) {
411 case 0: /* getpgrp */
412 return current->pgrp;
413 case 1: /* setpgrp */
415 int (*sys_setpgid)(pid_t,pid_t) =
416 (int (*)(pid_t,pid_t))SYS(setpgid);
418 /* can anyone explain me the difference between
419 Solaris setpgrp and setsid? */
420 ret = sys_setpgid(0, 0);
421 if (ret) return ret;
422 current->tty = NULL;
423 return current->pgrp;
425 case 2: /* getsid */
427 int (*sys_getsid)(pid_t) = (int (*)(pid_t))SYS(getsid);
428 return sys_getsid(pid);
430 case 3: /* setsid */
432 int (*sys_setsid)(void) = (int (*)(void))SYS(setsid);
433 return sys_setsid();
435 case 4: /* getpgid */
437 int (*sys_getpgid)(pid_t) = (int (*)(pid_t))SYS(getpgid);
438 return sys_getpgid(pid);
440 case 5: /* setpgid */
442 int (*sys_setpgid)(pid_t,pid_t) =
443 (int (*)(pid_t,pid_t))SYS(setpgid);
444 return sys_setpgid(pid,pgid);
447 return -EINVAL;
450 asmlinkage int solaris_gettimeofday(u32 tim)
452 int (*sys_gettimeofday)(struct timeval *, struct timezone *) =
453 (int (*)(struct timeval *, struct timezone *))SYS(gettimeofday);
455 return sys_gettimeofday((struct timeval *)(u64)tim, NULL);
458 #define RLIM_SOL_INFINITY32 0x7fffffff
459 #define RLIM_SOL_SAVED_MAX32 0x7ffffffe
460 #define RLIM_SOL_SAVED_CUR32 0x7ffffffd
461 #define RLIM_SOL_INFINITY ((u64)-3)
462 #define RLIM_SOL_SAVED_MAX ((u64)-2)
463 #define RLIM_SOL_SAVED_CUR ((u64)-1)
464 #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
465 #define RLIMIT_SOL_NOFILE 5
466 #define RLIMIT_SOL_VMEM 6
468 struct rlimit32 {
469 u32 rlim_cur;
470 u32 rlim_max;
473 asmlinkage int solaris_getrlimit(unsigned int resource, struct rlimit32 *rlim)
475 struct rlimit r;
476 int ret;
477 mm_segment_t old_fs = get_fs ();
478 int (*sys_getrlimit)(unsigned int, struct rlimit *) =
479 (int (*)(unsigned int, struct rlimit *))SYS(getrlimit);
481 if (resource > RLIMIT_SOL_VMEM)
482 return -EINVAL;
483 switch (resource) {
484 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
485 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
486 default: break;
488 set_fs (KERNEL_DS);
489 ret = sys_getrlimit(resource, &r);
490 set_fs (old_fs);
491 if (!ret) {
492 if (r.rlim_cur == RLIM_INFINITY)
493 r.rlim_cur = RLIM_SOL_INFINITY32;
494 else if ((u64)r.rlim_cur > RLIM_SOL_INFINITY32)
495 r.rlim_cur = RLIM_SOL_SAVED_CUR32;
496 if (r.rlim_max == RLIM_INFINITY)
497 r.rlim_max = RLIM_SOL_INFINITY32;
498 else if ((u64)r.rlim_max > RLIM_SOL_INFINITY32)
499 r.rlim_max = RLIM_SOL_SAVED_MAX32;
500 ret = put_user (r.rlim_cur, &rlim->rlim_cur);
501 ret |= __put_user (r.rlim_max, &rlim->rlim_max);
503 return ret;
506 asmlinkage int solaris_setrlimit(unsigned int resource, struct rlimit32 *rlim)
508 struct rlimit r, rold;
509 int ret;
510 mm_segment_t old_fs = get_fs ();
511 int (*sys_getrlimit)(unsigned int, struct rlimit *) =
512 (int (*)(unsigned int, struct rlimit *))SYS(getrlimit);
513 int (*sys_setrlimit)(unsigned int, struct rlimit *) =
514 (int (*)(unsigned int, struct rlimit *))SYS(setrlimit);
516 if (resource > RLIMIT_SOL_VMEM)
517 return -EINVAL;
518 switch (resource) {
519 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
520 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
521 default: break;
523 if (get_user (r.rlim_cur, &rlim->rlim_cur) ||
524 __get_user (r.rlim_max, &rlim->rlim_max))
525 return -EFAULT;
526 set_fs (KERNEL_DS);
527 ret = sys_getrlimit(resource, &rold);
528 if (!ret) {
529 if (r.rlim_cur == RLIM_SOL_INFINITY32)
530 r.rlim_cur = RLIM_INFINITY;
531 else if (r.rlim_cur == RLIM_SOL_SAVED_CUR32)
532 r.rlim_cur = rold.rlim_cur;
533 else if (r.rlim_cur == RLIM_SOL_SAVED_MAX32)
534 r.rlim_cur = rold.rlim_max;
535 if (r.rlim_max == RLIM_SOL_INFINITY32)
536 r.rlim_max = RLIM_INFINITY;
537 else if (r.rlim_max == RLIM_SOL_SAVED_CUR32)
538 r.rlim_max = rold.rlim_cur;
539 else if (r.rlim_max == RLIM_SOL_SAVED_MAX32)
540 r.rlim_max = rold.rlim_max;
541 ret = sys_setrlimit(resource, &r);
543 set_fs (old_fs);
544 return ret;
547 asmlinkage int solaris_getrlimit64(unsigned int resource, struct rlimit *rlim)
549 struct rlimit r;
550 int ret;
551 mm_segment_t old_fs = get_fs ();
552 int (*sys_getrlimit)(unsigned int, struct rlimit *) =
553 (int (*)(unsigned int, struct rlimit *))SYS(getrlimit);
555 if (resource > RLIMIT_SOL_VMEM)
556 return -EINVAL;
557 switch (resource) {
558 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
559 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
560 default: break;
562 set_fs (KERNEL_DS);
563 ret = sys_getrlimit(resource, &r);
564 set_fs (old_fs);
565 if (!ret) {
566 if (r.rlim_cur == RLIM_INFINITY)
567 r.rlim_cur = RLIM_SOL_INFINITY;
568 if (r.rlim_max == RLIM_INFINITY)
569 r.rlim_max = RLIM_SOL_INFINITY;
570 ret = put_user (r.rlim_cur, &rlim->rlim_cur);
571 ret |= __put_user (r.rlim_max, &rlim->rlim_max);
573 return ret;
576 asmlinkage int solaris_setrlimit64(unsigned int resource, struct rlimit *rlim)
578 struct rlimit r, rold;
579 int ret;
580 mm_segment_t old_fs = get_fs ();
581 int (*sys_getrlimit)(unsigned int, struct rlimit *) =
582 (int (*)(unsigned int, struct rlimit *))SYS(getrlimit);
583 int (*sys_setrlimit)(unsigned int, struct rlimit *) =
584 (int (*)(unsigned int, struct rlimit *))SYS(setrlimit);
586 if (resource > RLIMIT_SOL_VMEM)
587 return -EINVAL;
588 switch (resource) {
589 case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break;
590 case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break;
591 default: break;
593 if (get_user (r.rlim_cur, &rlim->rlim_cur) ||
594 __get_user (r.rlim_max, &rlim->rlim_max))
595 return -EFAULT;
596 set_fs (KERNEL_DS);
597 ret = sys_getrlimit(resource, &rold);
598 if (!ret) {
599 if (r.rlim_cur == RLIM_SOL_INFINITY)
600 r.rlim_cur = RLIM_INFINITY;
601 else if (r.rlim_cur == RLIM_SOL_SAVED_CUR)
602 r.rlim_cur = rold.rlim_cur;
603 else if (r.rlim_cur == RLIM_SOL_SAVED_MAX)
604 r.rlim_cur = rold.rlim_max;
605 if (r.rlim_max == RLIM_SOL_INFINITY)
606 r.rlim_max = RLIM_INFINITY;
607 else if (r.rlim_max == RLIM_SOL_SAVED_CUR)
608 r.rlim_max = rold.rlim_cur;
609 else if (r.rlim_max == RLIM_SOL_SAVED_MAX)
610 r.rlim_max = rold.rlim_max;
611 ret = sys_setrlimit(resource, &r);
613 set_fs (old_fs);
614 return ret;
617 struct timeval32 {
618 int tv_sec, tv_usec;
621 struct sol_ntptimeval {
622 struct timeval32 time;
623 s32 maxerror;
624 s32 esterror;
627 struct sol_timex {
628 u32 modes;
629 s32 offset;
630 s32 freq;
631 s32 maxerror;
632 s32 esterror;
633 s32 status;
634 s32 constant;
635 s32 precision;
636 s32 tolerance;
637 s32 ppsfreq;
638 s32 jitter;
639 s32 shift;
640 s32 stabil;
641 s32 jitcnt;
642 s32 calcnt;
643 s32 errcnt;
644 s32 stbcnt;
647 asmlinkage int solaris_ntp_gettime(struct sol_ntptimeval *ntp)
649 int (*sys_adjtimex)(struct timex *) =
650 (int (*)(struct timex *))SYS(adjtimex);
651 struct timex t;
652 int ret;
653 mm_segment_t old_fs = get_fs();
655 set_fs(KERNEL_DS);
656 t.modes = 0;
657 ret = sys_adjtimex(&t);
658 set_fs(old_fs);
659 if (ret < 0)
660 return ret;
661 ret = put_user (t.time.tv_sec, &ntp->time.tv_sec);
662 ret |= __put_user (t.time.tv_usec, &ntp->time.tv_usec);
663 ret |= __put_user (t.maxerror, &ntp->maxerror);
664 ret |= __put_user (t.esterror, &ntp->esterror);
665 return ret;
668 asmlinkage int solaris_ntp_adjtime(struct sol_timex *txp)
670 int (*sys_adjtimex)(struct timex *) =
671 (int (*)(struct timex *))SYS(adjtimex);
672 struct timex t;
673 int ret, err;
674 mm_segment_t old_fs = get_fs();
676 ret = get_user (t.modes, &txp->modes);
677 ret |= __get_user (t.offset, &txp->offset);
678 ret |= __get_user (t.freq, &txp->freq);
679 ret |= __get_user (t.maxerror, &txp->maxerror);
680 ret |= __get_user (t.esterror, &txp->esterror);
681 ret |= __get_user (t.status, &txp->status);
682 ret |= __get_user (t.constant, &txp->constant);
683 set_fs(KERNEL_DS);
684 ret = sys_adjtimex(&t);
685 set_fs(old_fs);
686 if (ret < 0)
687 return ret;
688 err = put_user (t.offset, &txp->offset);
689 err |= __put_user (t.freq, &txp->freq);
690 err |= __put_user (t.maxerror, &txp->maxerror);
691 err |= __put_user (t.esterror, &txp->esterror);
692 err |= __put_user (t.status, &txp->status);
693 err |= __put_user (t.constant, &txp->constant);
694 err |= __put_user (t.precision, &txp->precision);
695 err |= __put_user (t.tolerance, &txp->tolerance);
696 err |= __put_user (t.ppsfreq, &txp->ppsfreq);
697 err |= __put_user (t.jitter, &txp->jitter);
698 err |= __put_user (t.shift, &txp->shift);
699 err |= __put_user (t.stabil, &txp->stabil);
700 err |= __put_user (t.jitcnt, &txp->jitcnt);
701 err |= __put_user (t.calcnt, &txp->calcnt);
702 err |= __put_user (t.errcnt, &txp->errcnt);
703 err |= __put_user (t.stbcnt, &txp->stbcnt);
704 if (err)
705 return -EFAULT;
706 return ret;
709 asmlinkage int do_sol_unimplemented(struct pt_regs *regs)
711 printk ("Unimplemented Solaris syscall %d %08x %08x %08x %08x\n",
712 (int)regs->u_regs[UREG_G1],
713 (int)regs->u_regs[UREG_I0],
714 (int)regs->u_regs[UREG_I1],
715 (int)regs->u_regs[UREG_I2],
716 (int)regs->u_regs[UREG_I3]);
717 return -ENOSYS;
720 asmlinkage void solaris_register(void)
722 lock_kernel();
723 current->personality = PER_SVR4;
724 if (current->exec_domain && current->exec_domain->module)
725 __MOD_DEC_USE_COUNT(current->exec_domain->module);
726 current->exec_domain = lookup_exec_domain(current->personality);
727 if (current->exec_domain && current->exec_domain->module)
728 __MOD_INC_USE_COUNT(current->exec_domain->module);
729 unlock_kernel();
732 extern long solaris_to_linux_signals[], linux_to_solaris_signals[];
734 struct exec_domain solaris_exec_domain = {
735 "Solaris",
736 (lcall7_func)NULL,
737 1, 1, /* PER_SVR4 personality */
738 solaris_to_linux_signals,
739 linux_to_solaris_signals,
740 THIS_MODULE,
741 NULL
744 extern int init_socksys(void);
746 #ifdef MODULE
748 MODULE_AUTHOR("Jakub Jelinek (jj@ultra.linux.cz), Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)");
749 MODULE_DESCRIPTION("Solaris binary emulation module");
750 EXPORT_NO_SYMBOLS;
752 #ifdef __sparc_v9__
753 extern u32 tl0_solaris[8];
754 #define update_ttable(x) \
755 tl0_solaris[3] = (((long)(x) - (long)tl0_solaris - 3) >> 2) | 0x40000000; \
756 __asm__ __volatile__ ("membar #StoreStore; flush %0" : : "r" (&tl0_solaris[3]))
757 #else
758 #endif
760 extern u32 solaris_sparc_syscall[];
761 extern u32 solaris_syscall[];
762 extern void cleanup_socksys(void);
764 int init_module(void)
766 int ret;
768 SOLDD(("Solaris module at %p\n", solaris_sparc_syscall));
769 register_exec_domain(&solaris_exec_domain);
770 if ((ret = init_socksys())) {
771 unregister_exec_domain(&solaris_exec_domain);
772 return ret;
774 update_ttable(solaris_sparc_syscall);
775 return 0;
778 void cleanup_module(void)
780 update_ttable(solaris_syscall);
781 cleanup_socksys();
782 unregister_exec_domain(&solaris_exec_domain);
785 #else
786 int init_solaris_emul(void)
788 register_exec_domain(&solaris_exec_domain);
789 init_socksys();
791 #endif