25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: useremul.c,v 1.46 2005/04/14 21:01:54 debug Exp $ |
* $Id: useremul.c,v 1.62 2005/08/16 06:49:26 debug Exp $ |
29 |
* |
* |
30 |
* Userland (syscall) emulation. |
* Userland (syscall) emulation. |
31 |
* |
* |
67 |
#include <sys/time.h> |
#include <sys/time.h> |
68 |
#include <sys/stat.h> |
#include <sys/stat.h> |
69 |
#include <sys/socket.h> |
#include <sys/socket.h> |
70 |
|
#include <sys/resource.h> |
71 |
#include <time.h> |
#include <time.h> |
72 |
|
|
73 |
#include "cpu.h" |
#include "cpu.h" |
133 |
{ |
{ |
134 |
debug("useremul__freebsd_setup(): TODO\n"); |
debug("useremul__freebsd_setup(): TODO\n"); |
135 |
|
|
136 |
if (cpu->machine->arch != ARCH_ALPHA) { |
switch (cpu->machine->arch) { |
137 |
|
case ARCH_ALPHA: |
138 |
|
/* According to FreeBSD's /usr/src/lib/csu/alpha/crt1.c: */ |
139 |
|
/* a0 = char **ap */ |
140 |
|
/* a1 = void (*cleanup)(void) from shared loader */ |
141 |
|
/* a2 = struct Struct_Obj_Entry *obj from shared loader */ |
142 |
|
/* a3 = struct ps_strings *ps_strings */ |
143 |
|
cpu->cd.alpha.r[ALPHA_A0] = 0; |
144 |
|
cpu->cd.alpha.r[ALPHA_A1] = 0; |
145 |
|
cpu->cd.alpha.r[ALPHA_A2] = 0; |
146 |
|
cpu->cd.alpha.r[ALPHA_A3] = 0; |
147 |
|
|
148 |
|
/* What is a good stack pointer? TODO */ |
149 |
|
cpu->cd.alpha.r[ALPHA_SP] = 0x120000000ULL + |
150 |
|
1048576 * cpu->machine->physical_ram_in_mb - 1024; |
151 |
|
break; |
152 |
|
default: |
153 |
fatal("non-Alpha not yet implemented for freebsd emul.\n"); |
fatal("non-Alpha not yet implemented for freebsd emul.\n"); |
154 |
exit(1); |
exit(1); |
155 |
} |
} |
|
|
|
|
/* What is a good stack pointer? TODO */ |
|
|
/* cpu->cd.alpha.gpr[...] = ... */ |
|
156 |
} |
} |
157 |
|
|
158 |
|
|
200 |
/* The userland stack: */ |
/* The userland stack: */ |
201 |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
202 |
add_symbol_name(&cpu->machine->symbol_context, |
add_symbol_name(&cpu->machine->symbol_context, |
203 |
stack_top - stacksize, stacksize, "userstack", 0); |
stack_top - stacksize, stacksize, "userstack", 0, 0); |
204 |
|
|
205 |
/* Stack contents: (TODO: is this correct?) */ |
/* Stack contents: (TODO: is this correct?) */ |
206 |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
232 |
} |
} |
233 |
break; |
break; |
234 |
|
|
235 |
|
case ARCH_ARM: |
236 |
|
debug("useremul__netbsd_setup(): ARM: TODO\n"); |
237 |
|
break; |
238 |
|
|
239 |
case ARCH_PPC: |
case ARCH_PPC: |
240 |
debug("useremul__netbsd_setup(): PPC: TODO\n"); |
debug("useremul__netbsd_setup(): PPC: TODO\n"); |
241 |
|
|
278 |
/* The userland stack: */ |
/* The userland stack: */ |
279 |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
cpu->cd.mips.gpr[MIPS_GPR_SP] = stack_top - stack_margin; |
280 |
add_symbol_name(&cpu->machine->symbol_context, |
add_symbol_name(&cpu->machine->symbol_context, |
281 |
stack_top - stacksize, stacksize, "userstack", 0); |
stack_top - stacksize, stacksize, "userstack", 0, 0); |
282 |
|
|
283 |
/* Stack contents: (TODO: is this correct?) */ |
/* Stack contents: (TODO: is this correct?) */ |
284 |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
store_32bit_word(cpu, stack_top - stack_margin, argc); |
357 |
* TODO: combine this with get_userland_string() in some way |
* TODO: combine this with get_userland_string() in some way |
358 |
*/ |
*/ |
359 |
static unsigned char *get_userland_buf(struct cpu *cpu, |
static unsigned char *get_userland_buf(struct cpu *cpu, |
360 |
uint64_t baseaddr, int len) |
uint64_t baseaddr, uint64_t len) |
361 |
{ |
{ |
362 |
unsigned char *charbuf; |
unsigned char *charbuf; |
363 |
int i; |
ssize_t i; |
364 |
|
|
365 |
charbuf = malloc(len); |
charbuf = malloc(len); |
366 |
if (charbuf == NULL) { |
if (charbuf == NULL) { |
367 |
fprintf(stderr, "get_userland_buf(): out of memory (trying" |
fprintf(stderr, "get_userland_buf(): out of memory (trying" |
368 |
" to allocate %i bytes)\n", len); |
" to allocate %lli bytes)\n", (long long)len); |
369 |
exit(1); |
exit(1); |
370 |
} |
} |
371 |
|
|
398 |
} |
} |
399 |
|
|
400 |
|
|
401 |
|
/*****************************************************************************/ |
402 |
|
|
403 |
|
|
404 |
|
/* |
405 |
|
* useremul_exit(): |
406 |
|
*/ |
407 |
|
int useremul_exit(struct cpu *cpu, uint64_t arg0) |
408 |
|
{ |
409 |
|
debug("[ exit(%i) ]\n", (int)arg0); |
410 |
|
cpu->running = 0; |
411 |
|
cpu->machine->exit_without_entering_debugger = 1; |
412 |
|
return 0; |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
|
/* |
417 |
|
* useremul_write(): |
418 |
|
*/ |
419 |
|
int64_t useremul_write(struct cpu *cpu, int64_t *errnop, |
420 |
|
uint64_t arg0, uint64_t arg1, uint64_t arg2) |
421 |
|
{ |
422 |
|
int64_t res = 0; |
423 |
|
*errnop = 0; |
424 |
|
debug("[ write(%i,0x%llx,%lli) ]\n", |
425 |
|
(int)arg0, (long long)arg1, (long long)arg2); |
426 |
|
if (arg2 != 0) { |
427 |
|
unsigned char *cp = get_userland_buf(cpu, arg1, arg2); |
428 |
|
res = write(arg0, cp, arg2); |
429 |
|
if (res < 0) |
430 |
|
*errnop = errno; |
431 |
|
free(cp); |
432 |
|
} |
433 |
|
return res; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
|
/* |
438 |
|
* useremul_break(): |
439 |
|
*/ |
440 |
|
int64_t useremul_break(struct cpu *cpu, uint64_t arg0) |
441 |
|
{ |
442 |
|
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
443 |
|
|
444 |
|
/* TODO */ |
445 |
|
return 0; |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
/* |
450 |
|
* useremul_getpid(): |
451 |
|
*/ |
452 |
|
int64_t useremul_getpid(struct cpu *cpu) |
453 |
|
{ |
454 |
|
int64_t pid = getpid(); |
455 |
|
debug("[ getpid(): %lli ]\n", (long long)pid); |
456 |
|
return pid; |
457 |
|
} |
458 |
|
|
459 |
|
|
460 |
|
/* |
461 |
|
* useremul_getuid(): |
462 |
|
*/ |
463 |
|
int64_t useremul_getuid(struct cpu *cpu) |
464 |
|
{ |
465 |
|
int64_t uid = getuid(); |
466 |
|
debug("[ getuid(): %lli ]\n", (long long)uid); |
467 |
|
return uid; |
468 |
|
} |
469 |
|
|
470 |
|
|
471 |
|
/* |
472 |
|
* useremul_getegid(): |
473 |
|
*/ |
474 |
|
int64_t useremul_getegid(struct cpu *cpu) |
475 |
|
{ |
476 |
|
int64_t egid = getegid(); |
477 |
|
debug("[ getegid(): %lli ]\n", (long long)egid); |
478 |
|
return egid; |
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
|
/* |
483 |
|
* useremul_getgid(): |
484 |
|
*/ |
485 |
|
int64_t useremul_getgid(struct cpu *cpu) |
486 |
|
{ |
487 |
|
int64_t gid = getgid(); |
488 |
|
debug("[ getgid(): %lli ]\n", (long long)gid); |
489 |
|
return gid; |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
/* |
494 |
|
* useremul_sync(): |
495 |
|
*/ |
496 |
|
int useremul_sync(struct cpu *cpu) |
497 |
|
{ |
498 |
|
debug("[ sync() ]\n"); |
499 |
|
sync(); |
500 |
|
return 0; |
501 |
|
} |
502 |
|
|
503 |
|
|
504 |
|
/* |
505 |
|
* useremul_readlink(): |
506 |
|
*/ |
507 |
|
int64_t useremul_readlink(struct cpu *cpu, int64_t *errnop, |
508 |
|
uint64_t arg0, uint64_t arg1, int64_t arg2) |
509 |
|
{ |
510 |
|
int64_t res = 0; |
511 |
|
unsigned char *charbuf = get_userland_string(cpu, arg0); |
512 |
|
unsigned char *buf2; |
513 |
|
|
514 |
|
debug("[ readlink(\"%s\",0x%llx,%lli) ]\n", |
515 |
|
charbuf, (long long)arg1, (long long)arg2); |
516 |
|
if (arg2 == 0 || arg2 > 150000) { |
517 |
|
fprintf(stderr, "[ useremul_readlink(): TODO ]\n"); |
518 |
|
exit(1); |
519 |
|
} |
520 |
|
|
521 |
|
buf2 = malloc(arg2); |
522 |
|
if (buf2 == NULL) { |
523 |
|
fprintf(stderr, "[ useremul_readlink(): out of memory ]\n"); |
524 |
|
exit(1); |
525 |
|
} |
526 |
|
res = readlink((char *)charbuf, (char *)buf2, arg2); |
527 |
|
buf2[arg2-1] = '\0'; |
528 |
|
if (res < 0) |
529 |
|
*errnop = errno; |
530 |
|
else |
531 |
|
store_string(cpu, arg1, (char *)buf2); |
532 |
|
free(buf2); |
533 |
|
free(charbuf); |
534 |
|
return res; |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
/* |
539 |
|
* useremul_getrusage(): |
540 |
|
*/ |
541 |
|
int64_t useremul_getrusage(struct cpu *cpu, int64_t *errnop, |
542 |
|
uint64_t arg0, uint64_t arg1) |
543 |
|
{ |
544 |
|
int64_t res; |
545 |
|
struct rusage rusage; |
546 |
|
debug("[ getrusage(%i,0x%llx) ]\n", (int)arg0, (long long)arg1); |
547 |
|
res = getrusage(arg0, &rusage); |
548 |
|
|
549 |
|
fatal("TODO: convert rusage into emulated memory!\n"); |
550 |
|
store_64bit_word(cpu, arg1 + 0, rusage.ru_utime.tv_sec); |
551 |
|
store_64bit_word(cpu, arg1 + 8, rusage.ru_utime.tv_usec); |
552 |
|
store_64bit_word(cpu, arg1 + 16, rusage.ru_stime.tv_sec); |
553 |
|
store_64bit_word(cpu, arg1 + 24, rusage.ru_stime.tv_usec); |
554 |
|
|
555 |
|
return res; |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
|
/* |
560 |
|
* useremul_fstat(): |
561 |
|
*/ |
562 |
|
int64_t useremul_fstat(struct cpu *cpu, int64_t *errnop, |
563 |
|
int64_t arg0, uint64_t arg1) |
564 |
|
{ |
565 |
|
int64_t res; |
566 |
|
struct stat sb; |
567 |
|
debug("[ fstat(%i,0x%llx) ]\n", (int)arg0, (long long)arg1); |
568 |
|
res = fstat(arg0, &sb); |
569 |
|
if (res < 0) |
570 |
|
*errnop = errno; |
571 |
|
else { |
572 |
|
fatal("TODO: convert sb into emulated memory!\n"); |
573 |
|
|
574 |
|
/* NOTE: FreeBSD/alpha only */ |
575 |
|
|
576 |
|
store_32bit_word(cpu, arg1 + 0, sb.st_dev); |
577 |
|
store_32bit_word(cpu, arg1 + 4, sb.st_ino); |
578 |
|
/* store_16bit_word(cpu, arg1 + 8, sb.st_mode); |
579 |
|
*/ store_16bit_word(cpu, arg1 + 10, sb.st_nlink); |
580 |
|
store_32bit_word(cpu, arg1 + 12, sb.st_uid); |
581 |
|
store_32bit_word(cpu, arg1 + 16, sb.st_gid); |
582 |
|
store_32bit_word(cpu, arg1 + 20, sb.st_rdev); |
583 |
|
#if 0 |
584 |
|
store_64bit_word(cpu, arg1 + 24, sb.st_atimespec.tv_sec); |
585 |
|
store_64bit_word(cpu, arg1 + 32, sb.st_atimespec.tv_nsec); |
586 |
|
store_64bit_word(cpu, arg1 + 40, sb.st_mtimespec.tv_sec); |
587 |
|
store_64bit_word(cpu, arg1 + 48, sb.st_mtimespec.tv_nsec); |
588 |
|
store_64bit_word(cpu, arg1 + 56, sb.st_ctimespec.tv_sec); |
589 |
|
store_64bit_word(cpu, arg1 + 64, sb.st_ctimespec.tv_nsec); |
590 |
|
|
591 |
|
store_64bit_word(cpu, arg1 + 72, sb.st_size); |
592 |
|
store_64bit_word(cpu, arg1 + 80, sb.st_blocks); |
593 |
|
store_64bit_word(cpu, arg1 + 88, sb.st_blksize); |
594 |
|
store_64bit_word(cpu, arg1 + 92, sb.st_flags); |
595 |
|
store_64bit_word(cpu, arg1 + 96, sb.st_gen); |
596 |
|
#endif |
597 |
|
} |
598 |
|
return res; |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
|
/* |
603 |
|
* useremul_mmap(): |
604 |
|
*/ |
605 |
|
int64_t useremul_mmap(struct cpu *cpu, int64_t *errnop, |
606 |
|
uint64_t arg0, int64_t arg1, int64_t arg2, |
607 |
|
int64_t arg3, int64_t arg4, uint64_t arg5) |
608 |
|
{ |
609 |
|
int64_t res = 0; |
610 |
|
|
611 |
|
/* arg0..5: addr, len, prot, flags, fd, offset */ |
612 |
|
debug("[ mmap(0x%llx,%lli,%i,%i,%i,%lli) ]\n", |
613 |
|
(long long)arg0, (long long)arg1, |
614 |
|
(int)arg2, (int)arg3, (int)arg4, (long long)arg5); |
615 |
|
|
616 |
|
if (arg4 != -1) { |
617 |
|
fatal("[ useremul_mmap(): fd != -1: TODO ]\n"); |
618 |
|
cpu->running = 0; |
619 |
|
return 0; |
620 |
|
} |
621 |
|
|
622 |
|
/* Anonymous allocation. */ |
623 |
|
if (arg0 != 0) { |
624 |
|
fatal("[ useremul_mmap(): addr != 0: TODO ]\n"); |
625 |
|
cpu->running = 0; |
626 |
|
return 0; |
627 |
|
} |
628 |
|
|
629 |
|
fatal("[ useremul_mmap(): TODO ]\n"); |
630 |
|
|
631 |
|
res = 0x18000000ULL; |
632 |
|
|
633 |
|
return res; |
634 |
|
} |
635 |
|
|
636 |
|
|
637 |
|
/*****************************************************************************/ |
638 |
|
|
639 |
|
|
640 |
/* |
/* |
641 |
* useremul__freebsd(): |
* useremul__freebsd(): |
642 |
* |
* |
643 |
* FreeBSD syscall emulation. |
* FreeBSD/Alpha syscall emulation. |
644 |
* |
* |
645 |
* TODO: How to make this work nicely with non-Alpha archs. |
* TODO: How to make this work nicely with non-Alpha archs. |
646 |
*/ |
*/ |
647 |
static void useremul__freebsd(struct cpu *cpu, uint32_t code) |
static void useremul__freebsd(struct cpu *cpu, uint32_t code) |
648 |
{ |
{ |
|
#if 0 |
|
|
unsigned char *cp; |
|
649 |
int nr; |
int nr; |
650 |
uint64_t arg0, arg1, arg2, arg3; |
int64_t res = 0, err = 0; |
651 |
|
uint64_t arg0, arg1, arg2, arg3, arg4, arg5; |
652 |
|
|
653 |
nr = cpu->cd.ppc.gpr[0]; |
nr = cpu->cd.alpha.r[ALPHA_V0]; |
654 |
arg0 = cpu->cd.ppc.gpr[3]; |
arg0 = cpu->cd.alpha.r[ALPHA_A0]; |
655 |
arg1 = cpu->cd.ppc.gpr[4]; |
arg1 = cpu->cd.alpha.r[ALPHA_A1]; |
656 |
arg2 = cpu->cd.ppc.gpr[5]; |
arg2 = cpu->cd.alpha.r[ALPHA_A2]; |
657 |
arg3 = cpu->cd.ppc.gpr[6]; |
arg3 = cpu->cd.alpha.r[ALPHA_A3]; |
658 |
|
arg4 = cpu->cd.alpha.r[ALPHA_A4]; |
659 |
|
arg5 = cpu->cd.alpha.r[ALPHA_A5]; |
660 |
|
|
661 |
|
if (nr == 198) { |
662 |
|
/* ___syscall */ |
663 |
|
nr = arg0; |
664 |
|
arg0 = arg1; |
665 |
|
arg1 = arg2; |
666 |
|
arg2 = arg3; |
667 |
|
arg3 = arg4; |
668 |
|
arg4 = arg5; |
669 |
|
/* TODO: stack arguments */ |
670 |
|
} |
671 |
|
|
672 |
switch (nr) { |
switch (nr) { |
673 |
|
|
674 |
case LINUX_PPC_SYS_exit: |
case 1: res = useremul_exit(cpu, arg0); |
|
debug("[ exit(%i) ]\n", (int)arg0); |
|
|
cpu->running = 0; |
|
675 |
break; |
break; |
676 |
|
|
677 |
case LINUX_PPC_SYS_write: |
case 4: res = useremul_write(cpu, &err, arg0, arg1, arg2); |
|
debug("[ write(%i,0x%llx,%lli) ]\n", |
|
|
(int)arg0, (long long)arg1, (long long)arg2); |
|
|
cp = get_userland_buf(cpu, arg1, arg2); |
|
|
write(arg0, cp, arg2); |
|
|
free(cp); |
|
678 |
break; |
break; |
679 |
|
|
680 |
default: |
case 17:res = useremul_break(cpu, arg0); |
681 |
fatal("useremul__linux(): syscall %i not yet implemented\n", |
break; |
682 |
nr); |
|
683 |
|
case 20:res = useremul_getpid(cpu); |
684 |
|
break; |
685 |
|
|
686 |
|
case 24:res = useremul_getuid(cpu); |
687 |
|
break; |
688 |
|
|
689 |
|
case 43:res = useremul_getegid(cpu); |
690 |
|
break; |
691 |
|
|
692 |
|
case 47:res = useremul_getgid(cpu); |
693 |
|
break; |
694 |
|
|
695 |
|
case 58:res = useremul_readlink(cpu, &err, arg0, arg1, arg2); |
696 |
|
break; |
697 |
|
|
698 |
|
case 117:res = useremul_getrusage(cpu, &err, arg0, arg1); |
699 |
|
break; |
700 |
|
|
701 |
|
case 189:res = useremul_fstat(cpu, &err, arg0, arg1); |
702 |
|
break; |
703 |
|
|
704 |
|
case 197:res = useremul_mmap(cpu, &err, arg0, arg1, arg2, arg3, |
705 |
|
arg4, arg5); |
706 |
|
break; |
707 |
|
|
708 |
|
default:fatal("useremul__freebsd(): syscall %i not yet " |
709 |
|
"implemented\n", nr); |
710 |
cpu->running = 0; |
cpu->running = 0; |
711 |
} |
} |
712 |
#endif |
|
713 |
|
if (err) { |
714 |
|
cpu->cd.alpha.r[ALPHA_A3] = 1; |
715 |
|
cpu->cd.alpha.r[ALPHA_V0] = err; |
716 |
|
} else { |
717 |
|
cpu->cd.alpha.r[ALPHA_A3] = 0; |
718 |
|
cpu->cd.alpha.r[ALPHA_V0] = res; |
719 |
|
} |
720 |
} |
} |
721 |
|
|
722 |
|
|
730 |
static void useremul__linux(struct cpu *cpu, uint32_t code) |
static void useremul__linux(struct cpu *cpu, uint32_t code) |
731 |
{ |
{ |
732 |
int nr; |
int nr; |
733 |
unsigned char *cp; |
int64_t res = 0, err = 0; |
734 |
uint64_t arg0, arg1, arg2, arg3; |
uint64_t arg0, arg1, arg2, arg3; |
735 |
|
|
736 |
if (code != 0) { |
if (code != 0) { |
747 |
switch (nr) { |
switch (nr) { |
748 |
|
|
749 |
case LINUX_PPC_SYS_exit: |
case LINUX_PPC_SYS_exit: |
750 |
debug("[ exit(%i) ]\n", (int)arg0); |
res = useremul_exit(cpu, arg0); |
|
cpu->running = 0; |
|
751 |
break; |
break; |
752 |
|
|
753 |
case LINUX_PPC_SYS_write: |
case LINUX_PPC_SYS_write: |
754 |
debug("[ write(%i,0x%llx,%lli) ]\n", |
res = useremul_write(cpu, &err, arg0, arg1, arg2); |
|
(int)arg0, (long long)arg1, (long long)arg2); |
|
|
cp = get_userland_buf(cpu, arg1, arg2); |
|
|
write(arg0, cp, arg2); |
|
|
free(cp); |
|
755 |
break; |
break; |
756 |
|
|
757 |
default: |
default: |
759 |
nr); |
nr); |
760 |
cpu->running = 0; |
cpu->running = 0; |
761 |
} |
} |
762 |
|
|
763 |
|
/* return res: TODO */ |
764 |
} |
} |
765 |
|
|
766 |
|
|
774 |
int error_flag = 0, result_high_set = 0; |
int error_flag = 0, result_high_set = 0; |
775 |
uint64_t arg0=0,arg1=0,arg2=0,arg3=0,stack0=0,stack1=0,stack2=0; |
uint64_t arg0=0,arg1=0,arg2=0,arg3=0,stack0=0,stack1=0,stack2=0; |
776 |
int sysnr = 0; |
int sysnr = 0; |
777 |
uint64_t error_code = 0; |
int64_t error_code = 0; |
778 |
uint64_t result_low = 0; |
uint64_t result_low = 0; |
779 |
uint64_t result_high = 0; |
uint64_t result_high = 0; |
780 |
struct timeval tv; |
struct timeval tv; |
925 |
break; |
break; |
926 |
|
|
927 |
case NETBSD_SYS_getuid: |
case NETBSD_SYS_getuid: |
928 |
debug("[ getuid() ]\n"); |
result_low = useremul_getuid(cpu); |
|
result_low = getuid(); |
|
929 |
break; |
break; |
930 |
|
|
931 |
case NETBSD_SYS_geteuid: |
case NETBSD_SYS_geteuid: |
983 |
break; |
break; |
984 |
|
|
985 |
case NETBSD_SYS_break: |
case NETBSD_SYS_break: |
986 |
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
useremul_break(cpu, arg0); |
|
/* TODO */ |
|
987 |
break; |
break; |
988 |
|
|
989 |
case NETBSD_SYS_readlink: |
case NETBSD_SYS_readlink: |
990 |
charbuf = get_userland_string(cpu, arg0); |
result_low = useremul_readlink(cpu, &error_code, |
991 |
debug("[ readlink(\"%s\",0x%lli,%lli) ]\n", |
arg0, arg1, arg2); |
|
charbuf, (long long)arg1, (long long)arg2); |
|
|
if (arg2 != 0 && arg2 < 50000) { |
|
|
unsigned char *buf2 = malloc(arg2); |
|
|
buf2[arg2-1] = '\0'; |
|
|
result_low = readlink((char *)charbuf, |
|
|
(char *)buf2, arg2 - 1); |
|
|
if ((int64_t)result_low < 0) { |
|
|
error_flag = 1; |
|
|
error_code = errno; |
|
|
} else |
|
|
store_string(cpu, arg1, (char *)buf2); |
|
|
free(buf2); |
|
|
} |
|
|
free(charbuf); |
|
992 |
break; |
break; |
993 |
|
|
994 |
case NETBSD_SYS_sync: |
case NETBSD_SYS_sync: |
995 |
debug("[ sync() ]\n"); |
useremul_sync(cpu); |
|
sync(); |
|
996 |
break; |
break; |
997 |
|
|
998 |
case NETBSD_SYS_gettimeofday: |
case NETBSD_SYS_gettimeofday: |
1228 |
int error_flag = 0, result_high_set = 0; |
int error_flag = 0, result_high_set = 0; |
1229 |
uint64_t arg0,arg1,arg2,arg3,stack0=0,stack1=0,stack2; |
uint64_t arg0,arg1,arg2,arg3,stack0=0,stack1=0,stack2; |
1230 |
int sysnr = 0; |
int sysnr = 0; |
1231 |
uint64_t error_code = 0; |
int64_t error_code = 0; |
1232 |
uint64_t result_low = 0; |
uint64_t result_low = 0; |
1233 |
uint64_t result_high = 0; |
uint64_t result_high = 0; |
1234 |
struct timeval tv; |
struct timeval tv; |
1349 |
break; |
break; |
1350 |
|
|
1351 |
case ULTRIX_SYS_break: |
case ULTRIX_SYS_break: |
1352 |
debug("[ break(0x%llx): TODO ]\n", (long long)arg0); |
useremul_break(cpu, arg0); |
|
/* TODO */ |
|
1353 |
break; |
break; |
1354 |
|
|
1355 |
case ULTRIX_SYS_sync: |
case ULTRIX_SYS_sync: |
1356 |
debug("[ sync() ]\n"); |
useremul_sync(cpu); |
|
sync(); |
|
1357 |
break; |
break; |
1358 |
|
|
1359 |
case ULTRIX_SYS_getuid: |
case ULTRIX_SYS_getuid: |
1360 |
debug("[ getuid() ]\n"); |
result_low = useremul_getuid(cpu); |
|
result_low = getuid(); |
|
1361 |
break; |
break; |
1362 |
|
|
1363 |
case ULTRIX_SYS_getgid: |
case ULTRIX_SYS_getgid: |
1463 |
break; |
break; |
1464 |
|
|
1465 |
case ULTRIX_SYS_fstat: |
case ULTRIX_SYS_fstat: |
1466 |
debug("[ fstat(%i, 0x%llx): TODO ]\n", |
result_low = useremul_fstat(cpu, &error_code, arg0, arg1); |
|
(int)arg0, (long long)arg1); |
|
|
|
|
|
if (arg1 != 0) { |
|
|
struct stat st; |
|
|
result_low = fstat(arg0, &st); |
|
|
if ((int64_t)result_low < 0) { |
|
|
error_flag = 1; |
|
|
error_code = errno; |
|
|
} else { |
|
|
/* Fill in the Ultrix stat struct at arg1: */ |
|
|
|
|
|
/* TODO */ |
|
|
} |
|
|
} else { |
|
|
error_flag = 1; |
|
|
error_code = 1111; /* TODO: ultrix ENOMEM? */ |
|
|
} |
|
1467 |
break; |
break; |
1468 |
|
|
1469 |
case ULTRIX_SYS_getpagesize: |
case ULTRIX_SYS_getpagesize: |
1729 |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
add_useremul("NetBSD/pmax", ARCH_MIPS, "R3000", |
1730 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1731 |
|
|
1732 |
|
add_useremul("NetBSD/arm", ARCH_ARM, "ARM", |
1733 |
|
useremul__netbsd, useremul__netbsd_setup); |
1734 |
|
|
1735 |
add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", |
add_useremul("NetBSD/amd64", ARCH_X86, "AMD64", |
1736 |
useremul__netbsd, useremul__netbsd_setup); |
useremul__netbsd, useremul__netbsd_setup); |
1737 |
|
|
1738 |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |
add_useremul("Linux/PPC64", ARCH_PPC, "PPC970", |
1739 |
useremul__linux, useremul__linux_setup); |
useremul__linux, useremul__linux_setup); |
1740 |
|
|
1741 |
add_useremul("FreeBSD/Alpha", ARCH_ALPHA, "EV4", |
add_useremul("FreeBSD/Alpha", ARCH_ALPHA, "Alpha", |
1742 |
useremul__freebsd, useremul__freebsd_setup); |
useremul__freebsd, useremul__freebsd_setup); |
1743 |
} |
} |
1744 |
|
|