Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: misc.c,v 1.36 2002/02/09 19:49:31 davem Exp $ |
| 2 | * misc.c: Miscellaneous syscall emulation for Solaris |
| 3 | * |
| 4 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 5 | */ |
| 6 | |
| 7 | #include <linux/config.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/smp_lock.h> |
| 11 | #include <linux/utsname.h> |
| 12 | #include <linux/limits.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/smp.h> |
| 15 | #include <linux/mman.h> |
| 16 | #include <linux/file.h> |
| 17 | #include <linux/timex.h> |
| 18 | #include <linux/major.h> |
| 19 | #include <linux/compat.h> |
| 20 | |
| 21 | #include <asm/uaccess.h> |
| 22 | #include <asm/string.h> |
| 23 | #include <asm/oplib.h> |
| 24 | #include <asm/idprom.h> |
| 25 | #include <asm/smp.h> |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 26 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include "conv.h" |
| 29 | |
| 30 | /* Conversion from Linux to Solaris errnos. 0-34 are identity mapped. |
| 31 | Some Linux errnos (EPROCLIM, EDOTDOT, ERREMOTE, EUCLEAN, ENOTNAM, |
| 32 | ENAVAIL, EISNAM, EREMOTEIO, ENOMEDIUM, EMEDIUMTYPE) have no Solaris |
| 33 | equivalents. I return EINVAL in that case, which is very wrong. If |
| 34 | someone suggest a better value for them, you're welcomed. |
| 35 | On the other side, Solaris ECANCELED and ENOTSUP have no Linux equivalents, |
| 36 | but that doesn't matter here. --jj */ |
| 37 | int solaris_err_table[] = { |
| 38 | /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 39 | /* 10 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
| 40 | /* 20 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 41 | /* 30 */ 30, 31, 32, 33, 34, 22, 150, 149, 95, 96, |
| 42 | /* 40 */ 97, 98, 99, 120, 121, 122, 123, 124, 125, 126, |
| 43 | /* 50 */ 127, 128, 129, 130, 131, 132, 133, 134, 143, 144, |
| 44 | /* 60 */ 145, 146, 90, 78, 147, 148, 93, 22, 94, 49, |
| 45 | /* 70 */ 151, 66, 60, 62, 63, 35, 77, 36, 45, 46, |
| 46 | /* 80 */ 64, 22, 67, 68, 69, 70, 71, 74, 22, 82, |
| 47 | /* 90 */ 89, 92, 79, 81, 37, 38, 39, 40, 41, 42, |
| 48 | /* 100 */ 43, 44, 50, 51, 52, 53, 54, 55, 56, 57, |
| 49 | /* 110 */ 87, 61, 84, 65, 83, 80, 91, 22, 22, 22, |
| 50 | /* 120 */ 22, 22, 88, 86, 85, 22, 22, |
| 51 | }; |
| 52 | |
| 53 | #define SOLARIS_NR_OPEN 256 |
| 54 | |
| 55 | static u32 do_solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u64 off) |
| 56 | { |
| 57 | struct file *file = NULL; |
| 58 | unsigned long retval, ret_type; |
| 59 | |
| 60 | /* Do we need it here? */ |
| 61 | set_personality(PER_SVR4); |
| 62 | if (flags & MAP_NORESERVE) { |
| 63 | static int cnt; |
| 64 | |
| 65 | if (cnt < 5) { |
| 66 | printk("%s: unimplemented Solaris MAP_NORESERVE mmap() flag\n", |
| 67 | current->comm); |
| 68 | cnt++; |
| 69 | } |
| 70 | flags &= ~MAP_NORESERVE; |
| 71 | } |
| 72 | retval = -EBADF; |
| 73 | if(!(flags & MAP_ANONYMOUS)) { |
| 74 | if(fd >= SOLARIS_NR_OPEN) |
| 75 | goto out; |
| 76 | file = fget(fd); |
| 77 | if (!file) |
| 78 | goto out; |
| 79 | else { |
| 80 | struct inode * inode = file->f_dentry->d_inode; |
| 81 | if(imajor(inode) == MEM_MAJOR && |
| 82 | iminor(inode) == 5) { |
| 83 | flags |= MAP_ANONYMOUS; |
| 84 | fput(file); |
| 85 | file = NULL; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | retval = -EINVAL; |
| 91 | len = PAGE_ALIGN(len); |
| 92 | if(!(flags & MAP_FIXED)) |
| 93 | addr = 0; |
David S. Miller | d61e16d | 2006-03-17 17:33:56 -0800 | [diff] [blame] | 94 | else if (len > STACK_TOP32 || addr > STACK_TOP32 - len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | goto out_putf; |
| 96 | ret_type = flags & _MAP_NEW; |
| 97 | flags &= ~_MAP_NEW; |
| 98 | |
| 99 | down_write(¤t->mm->mmap_sem); |
| 100 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 101 | retval = do_mmap(file, |
| 102 | (unsigned long) addr, (unsigned long) len, |
| 103 | (unsigned long) prot, (unsigned long) flags, off); |
| 104 | up_write(¤t->mm->mmap_sem); |
| 105 | if(!ret_type) |
David S. Miller | d61e16d | 2006-03-17 17:33:56 -0800 | [diff] [blame] | 106 | retval = ((retval < STACK_TOP32) ? 0 : retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | out_putf: |
| 109 | if (file) |
| 110 | fput(file); |
| 111 | out: |
| 112 | return (u32) retval; |
| 113 | } |
| 114 | |
| 115 | asmlinkage u32 solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off) |
| 116 | { |
| 117 | return do_solaris_mmap(addr, len, prot, flags, fd, (u64) off); |
| 118 | } |
| 119 | |
| 120 | asmlinkage u32 solaris_mmap64(struct pt_regs *regs, u32 len, u32 prot, u32 flags, u32 fd, u32 offhi) |
| 121 | { |
| 122 | u32 offlo; |
| 123 | |
| 124 | if (regs->u_regs[UREG_G1]) { |
| 125 | if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x5c))) |
| 126 | return -EFAULT; |
| 127 | } else { |
| 128 | if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x60))) |
| 129 | return -EFAULT; |
| 130 | } |
| 131 | return do_solaris_mmap((u32)regs->u_regs[UREG_I0], len, prot, flags, fd, (((u64)offhi)<<32)|offlo); |
| 132 | } |
| 133 | |
| 134 | asmlinkage int solaris_brk(u32 brk) |
| 135 | { |
| 136 | int (*sunos_brk)(u32) = (int (*)(u32))SUNOS(17); |
| 137 | |
| 138 | return sunos_brk(brk); |
| 139 | } |
| 140 | |
| 141 | static int __set_utsfield(char __user *to, int to_size, |
| 142 | const char *from, int from_size, |
| 143 | int dotchop, int countfrom) |
| 144 | { |
| 145 | int len = countfrom ? (to_size > from_size ? |
| 146 | from_size : to_size) : to_size; |
| 147 | int off; |
| 148 | |
| 149 | if (copy_to_user(to, from, len)) |
| 150 | return -EFAULT; |
| 151 | |
| 152 | off = len < to_size? len: len - 1; |
| 153 | if (dotchop) { |
| 154 | const char *p = strnchr(from, len, '.'); |
| 155 | if (p) off = p - from; |
| 156 | } |
| 157 | |
| 158 | if (__put_user('\0', to + off)) |
| 159 | return -EFAULT; |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | #define set_utsfield(to, from, dotchop, countfrom) \ |
| 165 | __set_utsfield((to), sizeof(to), \ |
| 166 | (from), sizeof(from), \ |
| 167 | (dotchop), (countfrom)) |
| 168 | |
| 169 | struct sol_uname { |
| 170 | char sysname[9]; |
| 171 | char nodename[9]; |
| 172 | char release[9]; |
| 173 | char version[9]; |
| 174 | char machine[9]; |
| 175 | }; |
| 176 | |
| 177 | struct sol_utsname { |
| 178 | char sysname[257]; |
| 179 | char nodename[257]; |
| 180 | char release[257]; |
| 181 | char version[257]; |
| 182 | char machine[257]; |
| 183 | }; |
| 184 | |
| 185 | static char *machine(void) |
| 186 | { |
| 187 | switch (sparc_cpu_model) { |
| 188 | case sun4: return "sun4"; |
| 189 | case sun4c: return "sun4c"; |
| 190 | case sun4e: return "sun4e"; |
| 191 | case sun4m: return "sun4m"; |
| 192 | case sun4d: return "sun4d"; |
| 193 | case sun4u: return "sun4u"; |
| 194 | default: return "sparc"; |
| 195 | } |
| 196 | } |
| 197 | |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 198 | static char *platform(char *buffer, int sz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 200 | struct device_node *dp = of_find_node_by_path("/"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | int len; |
| 202 | |
| 203 | *buffer = 0; |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 204 | len = strlen(dp->name); |
| 205 | if (len > sz) |
| 206 | len = sz; |
| 207 | memcpy(buffer, dp->name, len); |
| 208 | buffer[len] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (*buffer) { |
| 210 | char *p; |
| 211 | |
| 212 | for (p = buffer; *p; p++) |
| 213 | if (*p == '/' || *p == ' ') *p = '_'; |
| 214 | return buffer; |
| 215 | } |
| 216 | |
| 217 | return "sun4u"; |
| 218 | } |
| 219 | |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 220 | static char *serial(char *buffer, int sz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 222 | struct device_node *dp = of_find_node_by_path("/options"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | int len; |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | *buffer = 0; |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 226 | if (dp) { |
| 227 | char *val = of_get_property(dp, "system-board-serial#", &len); |
| 228 | |
| 229 | if (val && len > 0) { |
| 230 | if (len > sz) |
| 231 | len = sz; |
| 232 | memcpy(buffer, val, len); |
| 233 | buffer[len] = 0; |
| 234 | } |
| 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | if (!*buffer) |
| 237 | return "4512348717234"; |
| 238 | else |
| 239 | return buffer; |
| 240 | } |
| 241 | |
| 242 | asmlinkage int solaris_utssys(u32 buf, u32 flags, int which, u32 buf2) |
| 243 | { |
| 244 | struct sol_uname __user *v = A(buf); |
| 245 | int err; |
| 246 | |
| 247 | switch (which) { |
| 248 | case 0: /* old uname */ |
| 249 | /* Let's cheat */ |
| 250 | err = set_utsfield(v->sysname, "SunOS", 1, 0); |
| 251 | down_read(&uts_sem); |
| 252 | err |= set_utsfield(v->nodename, system_utsname.nodename, |
| 253 | 1, 1); |
| 254 | up_read(&uts_sem); |
| 255 | err |= set_utsfield(v->release, "2.6", 0, 0); |
| 256 | err |= set_utsfield(v->version, "Generic", 0, 0); |
| 257 | err |= set_utsfield(v->machine, machine(), 0, 0); |
| 258 | return (err ? -EFAULT : 0); |
| 259 | case 2: /* ustat */ |
| 260 | return -ENOSYS; |
| 261 | case 3: /* fusers */ |
| 262 | return -ENOSYS; |
| 263 | default: |
| 264 | return -ENOSYS; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | asmlinkage int solaris_utsname(u32 buf) |
| 269 | { |
| 270 | struct sol_utsname __user *v = A(buf); |
| 271 | int err; |
| 272 | |
| 273 | /* Why should we not lie a bit? */ |
| 274 | down_read(&uts_sem); |
| 275 | err = set_utsfield(v->sysname, "SunOS", 0, 0); |
| 276 | err |= set_utsfield(v->nodename, system_utsname.nodename, 1, 1); |
| 277 | err |= set_utsfield(v->release, "5.6", 0, 0); |
| 278 | err |= set_utsfield(v->version, "Generic", 0, 0); |
| 279 | err |= set_utsfield(v->machine, machine(), 0, 0); |
| 280 | up_read(&uts_sem); |
| 281 | |
| 282 | return (err ? -EFAULT : 0); |
| 283 | } |
| 284 | |
| 285 | #define SI_SYSNAME 1 /* return name of operating system */ |
| 286 | #define SI_HOSTNAME 2 /* return name of node */ |
| 287 | #define SI_RELEASE 3 /* return release of operating system */ |
| 288 | #define SI_VERSION 4 /* return version field of utsname */ |
| 289 | #define SI_MACHINE 5 /* return kind of machine */ |
| 290 | #define SI_ARCHITECTURE 6 /* return instruction set arch */ |
| 291 | #define SI_HW_SERIAL 7 /* return hardware serial number */ |
| 292 | #define SI_HW_PROVIDER 8 /* return hardware manufacturer */ |
| 293 | #define SI_SRPC_DOMAIN 9 /* return secure RPC domain */ |
| 294 | #define SI_PLATFORM 513 /* return platform identifier */ |
| 295 | |
| 296 | asmlinkage int solaris_sysinfo(int cmd, u32 buf, s32 count) |
| 297 | { |
| 298 | char *p, *q, *r; |
| 299 | char buffer[256]; |
| 300 | int len; |
| 301 | |
| 302 | /* Again, we cheat :)) */ |
| 303 | switch (cmd) { |
| 304 | case SI_SYSNAME: r = "SunOS"; break; |
| 305 | case SI_HOSTNAME: |
| 306 | r = buffer + 256; |
| 307 | down_read(&uts_sem); |
| 308 | for (p = system_utsname.nodename, q = buffer; |
| 309 | q < r && *p && *p != '.'; *q++ = *p++); |
| 310 | up_read(&uts_sem); |
| 311 | *q = 0; |
| 312 | r = buffer; |
| 313 | break; |
| 314 | case SI_RELEASE: r = "5.6"; break; |
| 315 | case SI_MACHINE: r = machine(); break; |
| 316 | case SI_ARCHITECTURE: r = "sparc"; break; |
| 317 | case SI_HW_PROVIDER: r = "Sun_Microsystems"; break; |
David S. Miller | 25c7581 | 2006-06-22 20:21:22 -0700 | [diff] [blame^] | 318 | case SI_HW_SERIAL: r = serial(buffer, sizeof(buffer)); break; |
| 319 | case SI_PLATFORM: r = platform(buffer, sizeof(buffer)); break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | case SI_SRPC_DOMAIN: r = ""; break; |
| 321 | case SI_VERSION: r = "Generic"; break; |
| 322 | default: return -EINVAL; |
| 323 | } |
| 324 | len = strlen(r) + 1; |
| 325 | if (count < len) { |
| 326 | if (copy_to_user(A(buf), r, count - 1) || |
| 327 | __put_user(0, (char __user *)A(buf) + count - 1)) |
| 328 | return -EFAULT; |
| 329 | } else { |
| 330 | if (copy_to_user(A(buf), r, len)) |
| 331 | return -EFAULT; |
| 332 | } |
| 333 | return len; |
| 334 | } |
| 335 | |
| 336 | #define SOLARIS_CONFIG_NGROUPS 2 |
| 337 | #define SOLARIS_CONFIG_CHILD_MAX 3 |
| 338 | #define SOLARIS_CONFIG_OPEN_FILES 4 |
| 339 | #define SOLARIS_CONFIG_POSIX_VER 5 |
| 340 | #define SOLARIS_CONFIG_PAGESIZE 6 |
| 341 | #define SOLARIS_CONFIG_CLK_TCK 7 |
| 342 | #define SOLARIS_CONFIG_XOPEN_VER 8 |
| 343 | #define SOLARIS_CONFIG_PROF_TCK 10 |
| 344 | #define SOLARIS_CONFIG_NPROC_CONF 11 |
| 345 | #define SOLARIS_CONFIG_NPROC_ONLN 12 |
| 346 | #define SOLARIS_CONFIG_AIO_LISTIO_MAX 13 |
| 347 | #define SOLARIS_CONFIG_AIO_MAX 14 |
| 348 | #define SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX 15 |
| 349 | #define SOLARIS_CONFIG_DELAYTIMER_MAX 16 |
| 350 | #define SOLARIS_CONFIG_MQ_OPEN_MAX 17 |
| 351 | #define SOLARIS_CONFIG_MQ_PRIO_MAX 18 |
| 352 | #define SOLARIS_CONFIG_RTSIG_MAX 19 |
| 353 | #define SOLARIS_CONFIG_SEM_NSEMS_MAX 20 |
| 354 | #define SOLARIS_CONFIG_SEM_VALUE_MAX 21 |
| 355 | #define SOLARIS_CONFIG_SIGQUEUE_MAX 22 |
| 356 | #define SOLARIS_CONFIG_SIGRT_MIN 23 |
| 357 | #define SOLARIS_CONFIG_SIGRT_MAX 24 |
| 358 | #define SOLARIS_CONFIG_TIMER_MAX 25 |
| 359 | #define SOLARIS_CONFIG_PHYS_PAGES 26 |
| 360 | #define SOLARIS_CONFIG_AVPHYS_PAGES 27 |
| 361 | |
| 362 | asmlinkage int solaris_sysconf(int id) |
| 363 | { |
| 364 | switch (id) { |
| 365 | case SOLARIS_CONFIG_NGROUPS: return NGROUPS_MAX; |
David S. Miller | 597d1f0 | 2005-12-22 23:04:39 -0800 | [diff] [blame] | 366 | case SOLARIS_CONFIG_CHILD_MAX: return -1; /* no limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | case SOLARIS_CONFIG_OPEN_FILES: return OPEN_MAX; |
| 368 | case SOLARIS_CONFIG_POSIX_VER: return 199309; |
| 369 | case SOLARIS_CONFIG_PAGESIZE: return PAGE_SIZE; |
| 370 | case SOLARIS_CONFIG_XOPEN_VER: return 3; |
| 371 | case SOLARIS_CONFIG_CLK_TCK: |
| 372 | case SOLARIS_CONFIG_PROF_TCK: |
| 373 | return sparc64_get_clock_tick(smp_processor_id()); |
| 374 | #ifdef CONFIG_SMP |
| 375 | case SOLARIS_CONFIG_NPROC_CONF: return NR_CPUS; |
| 376 | case SOLARIS_CONFIG_NPROC_ONLN: return num_online_cpus(); |
| 377 | #else |
| 378 | case SOLARIS_CONFIG_NPROC_CONF: return 1; |
| 379 | case SOLARIS_CONFIG_NPROC_ONLN: return 1; |
| 380 | #endif |
| 381 | case SOLARIS_CONFIG_SIGRT_MIN: return 37; |
| 382 | case SOLARIS_CONFIG_SIGRT_MAX: return 44; |
| 383 | case SOLARIS_CONFIG_PHYS_PAGES: |
| 384 | case SOLARIS_CONFIG_AVPHYS_PAGES: |
| 385 | { |
| 386 | struct sysinfo s; |
| 387 | |
| 388 | si_meminfo(&s); |
| 389 | if (id == SOLARIS_CONFIG_PHYS_PAGES) |
| 390 | return s.totalram >>= PAGE_SHIFT; |
| 391 | else |
| 392 | return s.freeram >>= PAGE_SHIFT; |
| 393 | } |
| 394 | /* XXX support these as well -jj */ |
| 395 | case SOLARIS_CONFIG_AIO_LISTIO_MAX: return -EINVAL; |
| 396 | case SOLARIS_CONFIG_AIO_MAX: return -EINVAL; |
| 397 | case SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX: return -EINVAL; |
| 398 | case SOLARIS_CONFIG_DELAYTIMER_MAX: return -EINVAL; |
| 399 | case SOLARIS_CONFIG_MQ_OPEN_MAX: return -EINVAL; |
| 400 | case SOLARIS_CONFIG_MQ_PRIO_MAX: return -EINVAL; |
| 401 | case SOLARIS_CONFIG_RTSIG_MAX: return -EINVAL; |
| 402 | case SOLARIS_CONFIG_SEM_NSEMS_MAX: return -EINVAL; |
| 403 | case SOLARIS_CONFIG_SEM_VALUE_MAX: return -EINVAL; |
| 404 | case SOLARIS_CONFIG_SIGQUEUE_MAX: return -EINVAL; |
| 405 | case SOLARIS_CONFIG_TIMER_MAX: return -EINVAL; |
| 406 | default: return -EINVAL; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid) |
| 411 | { |
| 412 | int ret; |
| 413 | |
| 414 | switch (cmd) { |
| 415 | case 0: /* getpgrp */ |
| 416 | return process_group(current); |
| 417 | case 1: /* setpgrp */ |
| 418 | { |
| 419 | int (*sys_setpgid)(pid_t,pid_t) = |
| 420 | (int (*)(pid_t,pid_t))SYS(setpgid); |
| 421 | |
| 422 | /* can anyone explain me the difference between |
| 423 | Solaris setpgrp and setsid? */ |
| 424 | ret = sys_setpgid(0, 0); |
| 425 | if (ret) return ret; |
| 426 | current->signal->tty = NULL; |
| 427 | return process_group(current); |
| 428 | } |
| 429 | case 2: /* getsid */ |
| 430 | { |
| 431 | int (*sys_getsid)(pid_t) = (int (*)(pid_t))SYS(getsid); |
| 432 | return sys_getsid(pid); |
| 433 | } |
| 434 | case 3: /* setsid */ |
| 435 | { |
| 436 | int (*sys_setsid)(void) = (int (*)(void))SYS(setsid); |
| 437 | return sys_setsid(); |
| 438 | } |
| 439 | case 4: /* getpgid */ |
| 440 | { |
| 441 | int (*sys_getpgid)(pid_t) = (int (*)(pid_t))SYS(getpgid); |
| 442 | return sys_getpgid(pid); |
| 443 | } |
| 444 | case 5: /* setpgid */ |
| 445 | { |
| 446 | int (*sys_setpgid)(pid_t,pid_t) = |
| 447 | (int (*)(pid_t,pid_t))SYS(setpgid); |
| 448 | return sys_setpgid(pid,pgid); |
| 449 | } |
| 450 | } |
| 451 | return -EINVAL; |
| 452 | } |
| 453 | |
| 454 | asmlinkage int solaris_gettimeofday(u32 tim) |
| 455 | { |
| 456 | int (*sys_gettimeofday)(struct timeval *, struct timezone *) = |
| 457 | (int (*)(struct timeval *, struct timezone *))SYS(gettimeofday); |
| 458 | |
| 459 | return sys_gettimeofday((struct timeval *)(u64)tim, NULL); |
| 460 | } |
| 461 | |
| 462 | #define RLIM_SOL_INFINITY32 0x7fffffff |
| 463 | #define RLIM_SOL_SAVED_MAX32 0x7ffffffe |
| 464 | #define RLIM_SOL_SAVED_CUR32 0x7ffffffd |
| 465 | #define RLIM_SOL_INFINITY ((u64)-3) |
| 466 | #define RLIM_SOL_SAVED_MAX ((u64)-2) |
| 467 | #define RLIM_SOL_SAVED_CUR ((u64)-1) |
| 468 | #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) |
| 469 | #define RLIMIT_SOL_NOFILE 5 |
| 470 | #define RLIMIT_SOL_VMEM 6 |
| 471 | |
| 472 | struct rlimit32 { |
| 473 | u32 rlim_cur; |
| 474 | u32 rlim_max; |
| 475 | }; |
| 476 | |
| 477 | asmlinkage int solaris_getrlimit(unsigned int resource, struct rlimit32 __user *rlim) |
| 478 | { |
| 479 | struct rlimit r; |
| 480 | int ret; |
| 481 | mm_segment_t old_fs = get_fs (); |
| 482 | int (*sys_getrlimit)(unsigned int, struct rlimit *) = |
| 483 | (int (*)(unsigned int, struct rlimit *))SYS(getrlimit); |
| 484 | |
| 485 | if (resource > RLIMIT_SOL_VMEM) |
| 486 | return -EINVAL; |
| 487 | switch (resource) { |
| 488 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; |
| 489 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; |
| 490 | default: break; |
| 491 | } |
| 492 | set_fs (KERNEL_DS); |
| 493 | ret = sys_getrlimit(resource, &r); |
| 494 | set_fs (old_fs); |
| 495 | if (!ret) { |
| 496 | if (r.rlim_cur == RLIM_INFINITY) |
| 497 | r.rlim_cur = RLIM_SOL_INFINITY32; |
| 498 | else if ((u64)r.rlim_cur > RLIM_SOL_INFINITY32) |
| 499 | r.rlim_cur = RLIM_SOL_SAVED_CUR32; |
| 500 | if (r.rlim_max == RLIM_INFINITY) |
| 501 | r.rlim_max = RLIM_SOL_INFINITY32; |
| 502 | else if ((u64)r.rlim_max > RLIM_SOL_INFINITY32) |
| 503 | r.rlim_max = RLIM_SOL_SAVED_MAX32; |
| 504 | ret = put_user (r.rlim_cur, &rlim->rlim_cur); |
| 505 | ret |= __put_user (r.rlim_max, &rlim->rlim_max); |
| 506 | } |
| 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | asmlinkage int solaris_setrlimit(unsigned int resource, struct rlimit32 __user *rlim) |
| 511 | { |
| 512 | struct rlimit r, rold; |
| 513 | int ret; |
| 514 | mm_segment_t old_fs = get_fs (); |
| 515 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = |
| 516 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); |
| 517 | int (*sys_setrlimit)(unsigned int, struct rlimit __user *) = |
| 518 | (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit); |
| 519 | |
| 520 | if (resource > RLIMIT_SOL_VMEM) |
| 521 | return -EINVAL; |
| 522 | switch (resource) { |
| 523 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; |
| 524 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; |
| 525 | default: break; |
| 526 | } |
| 527 | if (get_user (r.rlim_cur, &rlim->rlim_cur) || |
| 528 | __get_user (r.rlim_max, &rlim->rlim_max)) |
| 529 | return -EFAULT; |
| 530 | set_fs (KERNEL_DS); |
| 531 | ret = sys_getrlimit(resource, &rold); |
| 532 | if (!ret) { |
| 533 | if (r.rlim_cur == RLIM_SOL_INFINITY32) |
| 534 | r.rlim_cur = RLIM_INFINITY; |
| 535 | else if (r.rlim_cur == RLIM_SOL_SAVED_CUR32) |
| 536 | r.rlim_cur = rold.rlim_cur; |
| 537 | else if (r.rlim_cur == RLIM_SOL_SAVED_MAX32) |
| 538 | r.rlim_cur = rold.rlim_max; |
| 539 | if (r.rlim_max == RLIM_SOL_INFINITY32) |
| 540 | r.rlim_max = RLIM_INFINITY; |
| 541 | else if (r.rlim_max == RLIM_SOL_SAVED_CUR32) |
| 542 | r.rlim_max = rold.rlim_cur; |
| 543 | else if (r.rlim_max == RLIM_SOL_SAVED_MAX32) |
| 544 | r.rlim_max = rold.rlim_max; |
| 545 | ret = sys_setrlimit(resource, &r); |
| 546 | } |
| 547 | set_fs (old_fs); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | asmlinkage int solaris_getrlimit64(unsigned int resource, struct rlimit __user *rlim) |
| 552 | { |
| 553 | struct rlimit r; |
| 554 | int ret; |
| 555 | mm_segment_t old_fs = get_fs (); |
| 556 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = |
| 557 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); |
| 558 | |
| 559 | if (resource > RLIMIT_SOL_VMEM) |
| 560 | return -EINVAL; |
| 561 | switch (resource) { |
| 562 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; |
| 563 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; |
| 564 | default: break; |
| 565 | } |
| 566 | set_fs (KERNEL_DS); |
| 567 | ret = sys_getrlimit(resource, &r); |
| 568 | set_fs (old_fs); |
| 569 | if (!ret) { |
| 570 | if (r.rlim_cur == RLIM_INFINITY) |
| 571 | r.rlim_cur = RLIM_SOL_INFINITY; |
| 572 | if (r.rlim_max == RLIM_INFINITY) |
| 573 | r.rlim_max = RLIM_SOL_INFINITY; |
| 574 | ret = put_user (r.rlim_cur, &rlim->rlim_cur); |
| 575 | ret |= __put_user (r.rlim_max, &rlim->rlim_max); |
| 576 | } |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | asmlinkage int solaris_setrlimit64(unsigned int resource, struct rlimit __user *rlim) |
| 581 | { |
| 582 | struct rlimit r, rold; |
| 583 | int ret; |
| 584 | mm_segment_t old_fs = get_fs (); |
| 585 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = |
| 586 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); |
| 587 | int (*sys_setrlimit)(unsigned int, struct rlimit __user *) = |
| 588 | (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit); |
| 589 | |
| 590 | if (resource > RLIMIT_SOL_VMEM) |
| 591 | return -EINVAL; |
| 592 | switch (resource) { |
| 593 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; |
| 594 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; |
| 595 | default: break; |
| 596 | } |
| 597 | if (get_user (r.rlim_cur, &rlim->rlim_cur) || |
| 598 | __get_user (r.rlim_max, &rlim->rlim_max)) |
| 599 | return -EFAULT; |
| 600 | set_fs (KERNEL_DS); |
| 601 | ret = sys_getrlimit(resource, &rold); |
| 602 | if (!ret) { |
| 603 | if (r.rlim_cur == RLIM_SOL_INFINITY) |
| 604 | r.rlim_cur = RLIM_INFINITY; |
| 605 | else if (r.rlim_cur == RLIM_SOL_SAVED_CUR) |
| 606 | r.rlim_cur = rold.rlim_cur; |
| 607 | else if (r.rlim_cur == RLIM_SOL_SAVED_MAX) |
| 608 | r.rlim_cur = rold.rlim_max; |
| 609 | if (r.rlim_max == RLIM_SOL_INFINITY) |
| 610 | r.rlim_max = RLIM_INFINITY; |
| 611 | else if (r.rlim_max == RLIM_SOL_SAVED_CUR) |
| 612 | r.rlim_max = rold.rlim_cur; |
| 613 | else if (r.rlim_max == RLIM_SOL_SAVED_MAX) |
| 614 | r.rlim_max = rold.rlim_max; |
| 615 | ret = sys_setrlimit(resource, &r); |
| 616 | } |
| 617 | set_fs (old_fs); |
| 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | struct sol_ntptimeval { |
| 622 | struct compat_timeval time; |
| 623 | s32 maxerror; |
| 624 | s32 esterror; |
| 625 | }; |
| 626 | |
| 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; |
| 645 | }; |
| 646 | |
| 647 | asmlinkage int solaris_ntp_gettime(struct sol_ntptimeval __user *ntp) |
| 648 | { |
| 649 | int (*sys_adjtimex)(struct timex __user *) = |
| 650 | (int (*)(struct timex __user *))SYS(adjtimex); |
| 651 | struct timex t; |
| 652 | int ret; |
| 653 | mm_segment_t old_fs = get_fs(); |
| 654 | |
| 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; |
| 666 | } |
| 667 | |
| 668 | asmlinkage int solaris_ntp_adjtime(struct sol_timex __user *txp) |
| 669 | { |
| 670 | int (*sys_adjtimex)(struct timex __user *) = |
| 671 | (int (*)(struct timex __user *))SYS(adjtimex); |
| 672 | struct timex t; |
| 673 | int ret, err; |
| 674 | mm_segment_t old_fs = get_fs(); |
| 675 | |
| 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; |
| 707 | } |
| 708 | |
| 709 | asmlinkage int do_sol_unimplemented(struct pt_regs *regs) |
| 710 | { |
| 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; |
| 718 | } |
| 719 | |
| 720 | asmlinkage void solaris_register(void) |
| 721 | { |
| 722 | set_personality(PER_SVR4); |
| 723 | } |
| 724 | |
| 725 | extern long solaris_to_linux_signals[], linux_to_solaris_signals[]; |
| 726 | |
| 727 | struct exec_domain solaris_exec_domain = { |
| 728 | .name = "Solaris", |
| 729 | .handler = NULL, |
| 730 | .pers_low = 1, /* PER_SVR4 personality */ |
| 731 | .pers_high = 1, |
| 732 | .signal_map = solaris_to_linux_signals, |
| 733 | .signal_invmap =linux_to_solaris_signals, |
| 734 | .module = THIS_MODULE, |
| 735 | .next = NULL |
| 736 | }; |
| 737 | |
| 738 | extern int init_socksys(void); |
| 739 | |
| 740 | #ifdef MODULE |
| 741 | |
| 742 | MODULE_AUTHOR("Jakub Jelinek (jj@ultra.linux.cz), Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)"); |
| 743 | MODULE_DESCRIPTION("Solaris binary emulation module"); |
| 744 | MODULE_LICENSE("GPL"); |
| 745 | |
| 746 | #ifdef __sparc_v9__ |
| 747 | extern u32 tl0_solaris[8]; |
| 748 | #define update_ttable(x) \ |
| 749 | tl0_solaris[3] = (((long)(x) - (long)tl0_solaris - 3) >> 2) | 0x40000000; \ |
David S. Miller | 4f07118 | 2005-08-29 12:46:22 -0700 | [diff] [blame] | 750 | wmb(); \ |
| 751 | __asm__ __volatile__ ("flush %0" : : "r" (&tl0_solaris[3])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | #else |
| 753 | #endif |
| 754 | |
| 755 | extern u32 solaris_sparc_syscall[]; |
| 756 | extern u32 solaris_syscall[]; |
| 757 | extern void cleanup_socksys(void); |
| 758 | |
| 759 | extern u32 entry64_personality_patch; |
| 760 | |
| 761 | int init_module(void) |
| 762 | { |
| 763 | int ret; |
| 764 | |
| 765 | SOLDD(("Solaris module at %p\n", solaris_sparc_syscall)); |
| 766 | register_exec_domain(&solaris_exec_domain); |
| 767 | if ((ret = init_socksys())) { |
| 768 | unregister_exec_domain(&solaris_exec_domain); |
| 769 | return ret; |
| 770 | } |
| 771 | update_ttable(solaris_sparc_syscall); |
| 772 | entry64_personality_patch |= |
| 773 | (offsetof(struct task_struct, personality) + |
| 774 | (sizeof(unsigned long) - 1)); |
David S. Miller | 4f07118 | 2005-08-29 12:46:22 -0700 | [diff] [blame] | 775 | wmb(); |
| 776 | __asm__ __volatile__("flush %0" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | : : "r" (&entry64_personality_patch)); |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | void cleanup_module(void) |
| 782 | { |
| 783 | update_ttable(solaris_syscall); |
| 784 | cleanup_socksys(); |
| 785 | unregister_exec_domain(&solaris_exec_domain); |
| 786 | } |
| 787 | |
| 788 | #else |
| 789 | int init_solaris_emul(void) |
| 790 | { |
| 791 | register_exec_domain(&solaris_exec_domain); |
| 792 | init_socksys(); |
| 793 | return 0; |
| 794 | } |
| 795 | #endif |
| 796 | |