1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 * 22 * Copyright 1995 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 #pragma ident "%Z%%M% %I% %E% SMI" 26 27 #include <errno.h> 28 #include <stdio.h> 29 #include <varargs.h> 30 #include <sys/syscall.h> 31 #include "xsyscall.h" 32 33 /* 34 * Array of SVR4 system call numbers. The 4.1 numbers are mapped 35 * to their SVR4/5.0 equivalents before trapping into the kernel. 36 */ 37 38 int syscallnum[190] = { SYS_syscall, SYS_exit, SYS_fork, 39 SYS_read, SYS_write, SYS_open, SYS_close, 40 -1, SYS_creat, SYS_link, SYS_unlink, 41 -1, SYS_chdir, 0, SYS_mknod, 42 SYS_chmod, SYS_lchown, 0, 0, 43 SYS_lseek, SYS_getpid, 0, 0, 44 0, SYS_getuid, 0, SYS_ptrace, 45 0, 0, 0, 0, 46 0, 0, SYS_access, 0, 47 0, SYS_sync, SYS_kill, SYS_stat, 48 0, SYS_lstat, SYS_dup, SYS_pipe, 49 0, SYS_profil, 0, 0, 50 SYS_getgid, 0, 0, 0, 51 SYS_acct, 0, -1, SYS_ioctl, 52 -1 /*reboot*/, 0, SYS_symlink, SYS_readlink, 53 SYS_execve, SYS_umask, SYS_chroot, SYS_fstat, 54 0, -1/*getpagesize*/,-1, 0, 55 0, 0, -1, -1, 56 SYS_mmap, -1, SYS_munmap, SYS_mprotect, 57 -1 /*advise*/, SYS_vhangup, 0, SYS_mincore, 58 SYS_getgroups, SYS_setgroups, -1 /*getpgrp*/, -1 /*setpgrp*/, 59 SYS_setitimer, 0, -1 /*swapon*/, SYS_getitimer, 60 -1/*gethostname*/,-1/*sethostname*/,-1/*getdtablesize*/,-1/*dup2*/, 61 -1/*getdopt*/, SYS_fcntl, -1 /*select*/, -1 /*setdopt*/, 62 SYS_fsync, -1 /*setprio*/, -1 /*socket*/, -1 /*connect*/, 63 -1 /*accept*/, -1 /*getprio*/, -1 /*send*/, -1 /*recv*/, 64 0, -1 /*bind*/, -1 /*setsockopt*/,-1 /*listen*/, 65 0, -1 /*sigvec*/, -1 /*sigblock*/, -1 /*sigsetmask*/, 66 -1 /*sigpause*/, -1 /*sigstack*/, -1 /*recvmsg*/, -1 /*sendmsg*/, 67 -1 /*vtrace*/, SYS_gettimeofday, -1 /*getrusage*/, -1 /*getsockopt*/, 68 0, SYS_readv, SYS_writev, -1 /*settimeofday*/, 69 SYS_fchown, SYS_fchmod, -1 /*recvfrom*/, -1 /*setreuid*/, 70 -1 /*getregid*/, SYS_rename, -1 /*truncate*/, -1 /*ftruncate*/, 71 -1 /*flock*/, 0, -1 /*sendto*/, -1 /*shutdown*/, 72 -1 /*socketpair*/,SYS_mkdir, SYS_rmdir, SYS_utimes, 73 0, SYS_adjtime, -1 /*getpeername*/,-1 /*gethostid*/, 74 0, SYS_getrlimit, SYS_setrlimit, -1 /*killpg*/, 75 0, 0, 0, -1/*getsockname*/, 76 SYS_getmsg, SYS_putmsg, SYS_poll, 0, 77 -1/*nfssvc*/, -1 /*getdirentries*/, SYS_statfs, SYS_fstatfs, 78 SYS_umount, -1 /*async_daemmon*/ -1 /*getfh*/, -1/*getdomain*/, 79 -1/*setdomain*/, 0, -1 /*quotactl*/, -1 /*exportfs*/, 80 SYS_mount, -1/*ustat*/, SYS_semsys, SYS_msgsys, 81 SYS_shmsys, -1 /*auditsys*/, -1 /*rfsys*/, SYS_getdents, 82 -1 /*setsid*/, SYS_fchdir, SYS_fchroot, -1 /*vpixsys*/, 83 -1 /*aioread*/, -1 /*aiowrite*/, -1 /*aiocancel*/, SYS_sigpending, 84 0, -1 /*setpgid*/, SYS_pathconf, SYS_uname, 85 }; 86 87 88 syscall(sysnum, va_alist) 89 int sysnum; 90 va_dcl 91 { 92 va_list ap; 93 int i1, i2, i3, i4; 94 char *c1, *c2, *c3, *c4; 95 96 va_start(ap); 97 switch(sysnum) { 98 case XSYS_read: 99 i1 = va_arg(ap, int); 100 c1 = va_arg(ap, char *); 101 i2 = va_arg(ap, int); 102 return(bc_read(i1, c1, i2)); 103 case XSYS_write: 104 i1 = va_arg(ap, int); 105 c1 = va_arg(ap, char *); 106 i2 = va_arg(ap, int); 107 return(bc_write(i1, c1, i2)); 108 case XSYS_readv: 109 i1 = va_arg(ap, int); 110 c1 = va_arg(ap, char *); 111 i2 = va_arg(ap, int); 112 return(bc_readv(i1, c1, i2)); 113 case XSYS_writev: 114 i1 = va_arg(ap, int); 115 c1 = va_arg(ap, char *); 116 i2 = va_arg(ap, int); 117 return(bc_writev(i1, c1, i2)); 118 case XSYS_open: 119 c1 = va_arg(ap, char *); 120 i1 = va_arg(ap, int); 121 i2 = va_arg(ap, int); 122 if (i2) 123 return(bc_open(c1, i1, i2)); 124 else 125 return(bc_open(c1, i1)); 126 case XSYS_close: 127 i1 = va_arg(ap, int); 128 return(bc_close(i1)); 129 case XSYS_fcntl: 130 i1 = va_arg(ap, int); 131 i2 = va_arg(ap, int); 132 i3 = va_arg(ap, int); 133 return(bc_fcntl(i1, i2, i3)); 134 case XSYS_select: 135 i1 = va_arg(ap, int); 136 c1 = va_arg(ap, char *); 137 c2 = va_arg(ap, char *); 138 c3 = va_arg(ap, char *); 139 c4 = va_arg(ap, char *); 140 return(_select(i1, c1, c2, c3, c4)); 141 case XSYS_ioctl : 142 i1 = va_arg(ap, int); 143 i2 = va_arg(ap, int); 144 c1 = va_arg(ap, char *); 145 return(bc_ioctl(i1, i2, c1)); 146 case XSYS_stat: 147 c1 = va_arg(ap, char *); 148 c2 = va_arg(ap, char *); 149 return(bc_stat(c1, c2)); 150 case XSYS_lstat: 151 c1 = va_arg(ap, char *); 152 c2 = va_arg(ap, char *); 153 return(bc_lstat(c1, c2)); 154 case XSYS_fstat: 155 i1 = va_arg(ap, int); 156 c1 = va_arg(ap, char *); 157 return(bc_fstat(i1, c1)); 158 case XSYS_getdents: 159 i1 = va_arg(ap, int); 160 c1 = va_arg(ap, char *); 161 i2 = va_arg(ap, int); 162 return(bc_getdents(i1, c1, i2)); 163 case XSYS_kill: 164 i1 = va_arg(ap, int); 165 i2 = va_arg(ap, int); 166 return(bc_kill(i1, i2)); 167 case XSYS_mount: 168 c1 = va_arg(ap, char *); 169 c2 = va_arg(ap, char *); 170 i1 = va_arg(ap, int); 171 c3 = va_arg(ap, char *); 172 return(mount(c1, c2, i1, c3)); 173 case XSYS_getrlimit: 174 i1 = va_arg(ap, int); 175 c1 = va_arg(ap, char *); 176 return(bc_getrlimit(i1, c1)); 177 case XSYS_setrlimit: 178 i1 = va_arg(ap, int); 179 c1 = va_arg(ap, char *); 180 return(bc_setrlimit(i1, c1)); 181 case XSYS_uname: 182 c1 = va_arg(ap, char *); 183 return(bc_uname(c1)); 184 case XSYS_creat: 185 c1 = va_arg(ap, char *); 186 i1 = va_arg(ap, int); 187 return(creat(c1, i1)); 188 case XSYS_unmount: 189 c1 = va_arg(ap, char *); 190 return(umount(c1)); 191 case XSYS_link: 192 c1 = va_arg(ap, char *); 193 c2 = va_arg(ap, char *); 194 return(link(c1, c2)); 195 case XSYS_unlink: 196 c1 = va_arg(ap, char *); 197 return(unlink(c1)); 198 case XSYS_chdir: 199 c1 = va_arg(ap, char *); 200 return(chdir(c1)); 201 case XSYS_mknod: 202 c1 = va_arg(ap, char *); 203 i1 = va_arg(ap, int); 204 i2 = va_arg(ap, int); 205 return(mknod(c1, i1, i2)); 206 case XSYS_chmod: 207 c1 = va_arg(ap, char *); 208 i1 = va_arg(ap, int); 209 return(chmod(c1, i1)); 210 case XSYS_chown: 211 c1 = va_arg(ap, char *); 212 i1 = va_arg(ap, int); 213 i2 = va_arg(ap, int); 214 return(chown(c1, i1, i2)); 215 case XSYS_lseek: 216 i1 = va_arg(ap, int); 217 i2 = va_arg(ap, int); 218 i3 = va_arg(ap, int); 219 return(lseek(i1, i2, i3)); 220 case XSYS_access: 221 c1 = va_arg(ap, char *); 222 i1 = va_arg(ap, int); 223 return(access(c1, i1)); 224 case XSYS_dup: 225 i1 = va_arg(ap, int); 226 return(dup(i1)); 227 case XSYS_dup2: 228 i1 = va_arg(ap, int); 229 i2 = va_arg(ap, int); 230 return(dup(i1, i2)); 231 case XSYS_pipe: 232 c1 = (char *)va_arg(ap, int *); 233 return(pipe(c1)); 234 case XSYS_symlink: 235 c1 = va_arg(ap, char *); 236 c2 = va_arg(ap, char *); 237 return(symlink(c1, c2)); 238 case XSYS_readlink: 239 c1 = va_arg(ap, char *); 240 c2 = va_arg(ap, char *); 241 i1 = va_arg(ap, int); 242 return(readlink(c1, c2, i1)); 243 case XSYS_execve: 244 c1 = va_arg(ap, char *); 245 c2 = (char *)va_arg(ap, char **); 246 c3 = (char *)va_arg(ap, char **); 247 return(execve(c1, c2, c3)); 248 case XSYS_chroot: 249 c1 = va_arg(ap, char *); 250 return(chroot(c1)); 251 case XSYS_getgroups: 252 i1 = va_arg(ap, int); 253 c1 = (char *)va_arg(ap, int *); 254 return(getgroups(i1, c1)); 255 case XSYS_setgroups: 256 i1 = va_arg(ap, int); 257 c1 = (char *)va_arg(ap, int *); 258 return(setgroups(i1, c1)); 259 case XSYS_fsync: 260 i1 = va_arg(ap, int); 261 return(fsync(i1)); 262 case XSYS_gettimeofday: 263 c1 = va_arg(ap, char *); 264 c2 = va_arg(ap, char *); 265 return(gettimeofday(c1, c2)); 266 case XSYS_settimeofday: 267 c1 = va_arg(ap, char *); 268 c2 = va_arg(ap, char *); 269 return(settimeofday(c1, c2)); 270 case XSYS_rename: 271 c1 = va_arg(ap, char *); 272 c2 = va_arg(ap, char *); 273 return(rename(c1, c2)); 274 case XSYS_mkdir: 275 c1 = va_arg(ap, char *); 276 i1 = va_arg(ap, int); 277 return(mkdir(c1, i1)); 278 case XSYS_rmdir: 279 c1 = va_arg(ap, char *); 280 return(rmdir(c1)); 281 case XSYS_statfs: 282 c1 = va_arg(ap, char *); 283 c2 = va_arg(ap, char *); 284 return(statfs(c1, c2)); 285 case XSYS_fstatfs: 286 i1 = va_arg(ap, int); 287 c1 = va_arg(ap, char *); 288 return(fstatfs(i1, c1)); 289 case XSYS_getpagesize: 290 return(getpagesize()); 291 case XSYS_gethostid: 292 return(gethostid()); 293 case XSYS_getdtablesize: 294 return(getdtablesize()); 295 case XSYS_pathconf: 296 c1 = va_arg(ap, char *); 297 i1 = va_arg(ap, int); 298 return(pathconf(c1, i1)); 299 case XSYS_gethostname: 300 c1 = va_arg(ap, char *); 301 i1 = va_arg(ap, int); 302 return(gethostname(c1, i1)); 303 case XSYS_sethostname: 304 c1 = va_arg(ap, char *); 305 i1 = va_arg(ap, int); 306 return(sethostname(c1, i1)); 307 case XSYS_setreuid: 308 i1 = va_arg(ap, int); 309 i2 = va_arg(ap, int); 310 return(setreuid(i1, i2)); 311 case XSYS_setregid: 312 i1 = va_arg(ap, int); 313 i2 = va_arg(ap, int); 314 return(setregid(i1, i2)); 315 case XSYS_getpriority: 316 i1 = va_arg(ap, int); 317 i2 = va_arg(ap, int); 318 return(getpriority(i1, i2)); 319 case XSYS_setpriority: 320 i1 = va_arg(ap, int); 321 i2 = va_arg(ap, int); 322 i3 = va_arg(ap, int); 323 return(setpriority(i1, i2, i3)); 324 case XSYS_sigvec: 325 i1 = va_arg(ap, int); 326 c1 = va_arg(ap, char *); 327 c2 = va_arg(ap, char *); 328 return(sigvec(i1, c1, c2)); 329 case XSYS_sigblock: 330 i1 = va_arg(ap, int); 331 return(sigblock(i1)); 332 case XSYS_sigpending: 333 c1 = va_arg(ap, char *); 334 return(sigpending(c1)); 335 case XSYS_sigsetmask: 336 i1 = va_arg(ap, int); 337 return(sigsetmask(i1)); 338 case XSYS_sigpause: 339 c1 = va_arg(ap, char *); 340 return(sigpause(c1)); 341 case XSYS_sigstack: 342 c1 = va_arg(ap, char *); 343 c2 = va_arg(ap, char *); 344 return(sigstack(c1, c2)); 345 case XSYS_truncate: 346 c1 = va_arg(ap, char *); 347 i1 = va_arg(ap, int); 348 return(truncate(c1, i1)); 349 case XSYS_ftruncate: 350 i1 = va_arg(ap, int); 351 i2 = va_arg(ap, int); 352 return(ftruncate(i1, i2)); 353 case XSYS_killpg: 354 i1 = va_arg(ap, int); 355 i2 = va_arg(ap, int); 356 return(killpg(i1, i2)); 357 case XSYS_setpgid: 358 i1 = va_arg(ap, int); 359 i2 = va_arg(ap, int); 360 return(setpgid(i1, i2)); 361 case XSYS_ptrace: 362 i1 = va_arg(ap, int); 363 i2 = va_arg(ap, int); 364 i3 = va_arg(ap, int); 365 c1 = va_arg(ap, char *); 366 i4 = va_arg(ap, int); 367 c2 = va_arg(ap, char *); 368 return(ptrace(i1, i2, i3, c1, i4, c2)); 369 #ifdef S5EMUL 370 case XSYS_getpgrp: 371 return(getpgrp()); 372 case XSYS_setpgrp: 373 return(setpgrp()); 374 #else 375 case XSYS_getpgrp: 376 i1 = va_arg(ap, int); 377 return(getpgrp(i1)); 378 case XSYS_setpgrp: 379 i1 = va_arg(ap, int); 380 i2 = va_arg(ap, int); 381 return(setpgrp(i1, i2)); 382 #endif 383 case XSYS_getrusage: 384 i1 = va_arg(ap, int); 385 c1 = va_arg(ap, char *); 386 return(getrusage(i1, c1)); 387 case XSYS_setsid: 388 return(setsid()); 389 390 case XSYS_flock: 391 i1 = va_arg(ap, int); 392 i2 = va_arg(ap, int); 393 return(flock(i1, i2)); 394 395 /* the following system calls are now implemented in 396 * libsocket */ 397 case XSYS_accept: 398 i1 = va_arg(ap, int); 399 c1 = va_arg(ap, char *); 400 c2 = (char *)va_arg(ap, int *); 401 return(_accept(i1, c1, c2)); 402 case XSYS_bind: 403 i1 = va_arg(ap, int); 404 c1 = va_arg(ap, char *); 405 i2 = va_arg(ap, int); 406 return(_bind(i1, c1, i2)); 407 case XSYS_connect: 408 i1 = va_arg(ap, int); 409 c1 = va_arg(ap, char *); 410 i2 = va_arg(ap, int); 411 return(_connect(i1, c1, i2)); 412 case XSYS_getsockopt: 413 i1 = va_arg(ap, int); 414 i2 = va_arg(ap, int); 415 i3 = va_arg(ap, int); 416 c1 = va_arg(ap, char *); 417 c2 = va_arg(ap, char *); 418 return(_getsockopt(i1, i2, i3, c1, c2)); 419 case XSYS_getpeername: 420 i1 = va_arg(ap, int); 421 c1 = va_arg(ap, char *); 422 c2 = va_arg(ap, char *); 423 return(_getpeername(i1, c1, c2)); 424 case XSYS_getsockname: 425 i1 = va_arg(ap, int); 426 c1 = va_arg(ap, char *); 427 c2 = va_arg(ap, char *); 428 return(_getsockname(i1, c1, c2)); 429 case XSYS_getdomainname: 430 c1 = va_arg(ap, char *); 431 i1 = va_arg(ap, int); 432 return(getdomainname(c1, i1)); 433 case XSYS_listen: 434 i1 = va_arg(ap, int); 435 i2 = va_arg(ap, int); 436 return(_listen(i1, i2)); 437 case XSYS_recv: 438 i1 = va_arg(ap, int); 439 c1 = va_arg(ap, char *); 440 i2 = va_arg(ap, int); 441 i3 = va_arg(ap, int); 442 return(_recv(i1, c1, i2, i3)); 443 case XSYS_recvfrom: 444 i1 = va_arg(ap, int); 445 c1 = va_arg(ap, char *); 446 i2 = va_arg(ap, int); 447 i3 = va_arg(ap, int); 448 c2 = va_arg(ap, char *); 449 c3 = va_arg(ap, char *); 450 return(_recvfrom(i1, c1, i2, i3, c2, c3)); 451 case XSYS_recvmsg: 452 i1 = va_arg(ap, int); 453 c1 = va_arg(ap, char *); 454 i2 = va_arg(ap, int); 455 return(_recvmsg(i1, c1, i2)); 456 case XSYS_send: 457 i1 = va_arg(ap, int); 458 c1 = va_arg(ap, char *); 459 i2 = va_arg(ap, int); 460 i3 = va_arg(ap, int); 461 return(_send(i1, c1, i2, i3)); 462 case XSYS_sendto: 463 i1 = va_arg(ap, int); 464 c1 = va_arg(ap, char *); 465 i2 = va_arg(ap, int); 466 i3 = va_arg(ap, int); 467 c2 = va_arg(ap, char *); 468 i4 = va_arg(ap, int); 469 return(_sendto(i1, c1, i2, i3, c2, i4)); 470 case XSYS_sendmsg: 471 i1 = va_arg(ap, int); 472 c1 = va_arg(ap, char *); 473 i2 = va_arg(ap, int); 474 return(_sendmsg(i1, c1, i2)); 475 case XSYS_setdomainname: 476 c1 = va_arg(ap, char *); 477 i1 = va_arg(ap, int); 478 return(setdomainname(c1 ,i1)); 479 case XSYS_setsockopt: 480 i1 = va_arg(ap, int); 481 i2 = va_arg(ap, int); 482 i3 = va_arg(ap, int); 483 c1 = va_arg(ap, char *); 484 i4 = va_arg(ap, int); 485 return(_setsockopt(i1, i2, i3, c1, i4)); 486 case XSYS_shutdown: 487 i1 = va_arg(ap, int); 488 i2 = va_arg(ap, int); 489 return(_shutdown(i1, i2)); 490 case XSYS_socket: 491 i1 = va_arg(ap, int); 492 i2 = va_arg(ap, int); 493 i3 = va_arg(ap, int); 494 return(_socket(i1, i2, i3)); 495 case XSYS_socketpair: 496 i1 = va_arg(ap, int); 497 i2 = va_arg(ap, int); 498 i3 = va_arg(ap, int); 499 c1 = va_arg(ap, char *); 500 return(_socketpair(i1, i2, i3, c1)); 501 502 503 /* The following can directly go through syscall */ 504 case XSYS_acct: 505 case XSYS_adjtime: 506 case XSYS_exit: 507 case XSYS_fchdir: 508 case XSYS_fchmod: 509 case XSYS_fchown: 510 case XSYS_fchroot: 511 case XSYS_fork: 512 case XSYS_getgid: 513 case XSYS_getitimer: 514 case XSYS_getmsg: 515 case XSYS_getpid: 516 case XSYS_getuid: 517 case XSYS_mincore: 518 case XSYS_mprotect: 519 case XSYS_munmap: 520 case XSYS_putmsg: 521 case XSYS_poll: 522 case XSYS_profil: 523 case XSYS_setitimer: 524 case XSYS_sync: 525 case XSYS_umask: 526 case XSYS_utimes: 527 case XSYS_semsys: 528 case XSYS_msgsys: 529 case XSYS_shmsys: 530 case XSYS_mmap: 531 case XSYS_vhangup: 532 return(_syscall(syscallnum[sysnum], va_alist)); 533 534 case XSYS_aioread: 535 case XSYS_aiowrite: 536 case XSYS_aiocancel: 537 case XSYS_swapon: 538 case XSYS_async_daemon: 539 case XSYS_getfh: 540 case XSYS_nfssvc: 541 case XSYS_exportfs: 542 case XSYS_auditsys: 543 case XSYS_vpixsys: 544 case XSYS_quotactl: 545 case XSYS_getdopt: 546 case XSYS_setdopt: 547 case XSYS_ustat: 548 case XSYS_vtrace: 549 case XSYS_reboot: 550 case XSYS_madvise: 551 case XSYS_vadvise: 552 case XSYS_getdirentries: 553 fprintf(stderr,"system call not supported\n"); 554 return(-1); 555 } 556 } 557