From mboxrd@z Thu Jan 1 00:00:00 1970 From: matthew green To: sid@sources.redhat.com Subject: RFA: gloss component extensions Date: Sat, 06 Jan 2001 18:59:00 -0000 Message-id: <2138.978836327@cygnus.com> X-SW-Source: 2001-q1/msg00016.html hi folks. the following changes implement times() & gettimeofday(), finish the time() syscall (it did not fill in it's argument, just returned the time), and fix the open() flags to match what newlib uses. OK to commit? .mrg. [component/ChangeLog] 2001-01-03 matthew green * configure.in (AC_HAVE_FUNCS): Also check for times(2). * configure: Regenerate. * config.in: Regenerate. [component/gloss/ChangeLog] 2001-01-06 matthew green * gloss.cxx (gloss32::target_to_host_open_flags): Properly check for valid open() flags. 2001-01-04 matthew green * gloss.cxx (gloss32::target_to_host_open_flags): Properly deal with newlib open flags. Need for gettimeofday(). Only include if we have times(). 2000-12-30 matthew green * gloss.cxx (do_sys_time): New function. (do_sys_times): Likewise. (do_sys_gettimeofday): Likewise. (syscall_trap): Call do_sys_time(). Call new do_sys_times() and do_sys_gettimeofday() for times() and . * gloss.h (do_sys_time): Prototype. (do_sys_times): Likewise. (do_sys_gettimeofday): Likewise. * libgloss.h (libgloss_syscall): Add `times' and `gettimeofday'. Index: component/config.in =================================================================== RCS file: /cvs/src/src/sid/component/config.in,v retrieving revision 1.1 diff -p -r1.1 config.in *** config.in 2000/12/07 19:30:45 1.1 --- config.in 2001/01/06 05:38:48 *************** *** 27,32 **** --- 27,35 ---- /* Define if you have the strtoull function. */ #undef HAVE_STRTOULL + /* Define if you have the times function. */ + #undef HAVE_TIMES + /* Define if you have the usleep function. */ #undef HAVE_USLEEP Index: component/configure =================================================================== RCS file: /cvs/src/src/sid/component/configure,v retrieving revision 1.1 diff -p -r1.1 configure *** configure 2000/12/07 19:30:45 1.1 --- configure 2001/01/06 05:38:50 *************** fi *** 2652,2658 **** ! for ac_func in ftime gettimeofday usleep strtoul strtoull select do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2659: checking for $ac_func" >&5 --- 2652,2658 ---- ! for ac_func in ftime times gettimeofday usleep strtoul strtoull select do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2659: checking for $ac_func" >&5 Index: component/configure.in =================================================================== RCS file: /cvs/src/src/sid/component/configure.in,v retrieving revision 1.1 diff -p -r1.1 configure.in *** configure.in 2000/12/07 19:30:45 1.1 --- configure.in 2001/01/06 05:38:50 *************** AC_CHECK_LIB(nsl, gethostbyname, socket_ *** 38,44 **** socket_libs="$socket_libs -lresolv")) AC_SUBST(socket_libs) ! AC_CHECK_FUNCS(ftime gettimeofday usleep strtoul strtoull select) old_libs="$LIBS" LIBS="$LIBS $socket_libs" --- 38,44 ---- socket_libs="$socket_libs -lresolv")) AC_SUBST(socket_libs) ! AC_CHECK_FUNCS(ftime times gettimeofday usleep strtoul strtoull select) old_libs="$LIBS" LIBS="$LIBS $socket_libs" Index: component/gloss/gloss.cxx =================================================================== RCS file: /cvs/src/src/sid/component/gloss/gloss.cxx,v retrieving revision 1.1 diff -p -r1.1 gloss.cxx *** gloss.cxx 2000/12/07 19:30:50 1.1 --- gloss.cxx 2001/01/06 05:38:51 *************** *** 10,15 **** --- 10,21 ---- #include "libgloss.h" // ??? For now. grep for newlib below. #include "newlib.h" + #ifdef HAVE_TIMES + #include + #endif + #ifdef HAVE_GETTIMEOFDAY + #include + #endif #include #include *************** gloss32::syscall_trap() *** 570,577 **** do_sys_open(); break; case libgloss::SYS_time: ! set_int_result(time(NULL)); break; default: do_nonstandard_target_syscalls (syscall); break; --- 576,589 ---- do_sys_open(); break; case libgloss::SYS_time: ! do_sys_time(); break; + case libgloss::SYS_gettimeofday: + do_sys_gettimeofday(); + break; + case libgloss::SYS_times: + do_sys_times(); + break; default: do_nonstandard_target_syscalls (syscall); break; *************** gloss32::do_nonstandard_target_syscalls *** 588,593 **** --- 600,672 ---- } void + gloss32::do_sys_time() + { + int32 timetp, rv; + + get_int_argument(1, timetp); + rv = time(NULL); + if (timetp) + set_word(timetp, rv); + + set_int_result(rv); + } + + void + gloss32::do_sys_gettimeofday() + { + #ifdef HAVE_GETTIMEOFDAY + int32 timevalp, rv, value; + struct timeval tv; + + /* Ignore 2nd parameter to gettimeofday(). */ + get_int_argument(1, timevalp); + rv = gettimeofday(&tv, NULL); + if (rv != -1) + { + value = tv.tv_sec; + set_word(timevalp, value); + value = tv.tv_usec; + set_word(timevalp + 4, value); + } + set_int_result(rv); + #else + set_int_result(-1); + #endif + } + + void + gloss32::do_sys_times() + { + #ifdef HAVE_TIMES + int32 value, rv, tmsp; + struct tms tms; + + get_int_argument(1, tmsp); + if (!tmsp) + { + set_int_result(EFAULT); + return; + } + rv = times(&tms); + if (rv != -1) + { + value = tms.tms_utime; + set_word(tmsp, value); + value = tms.tms_stime; + set_word(tmsp + 4, value); + value = tms.tms_cutime; + set_word(tmsp + 8, value); + value = tms.tms_cstime; + set_word(tmsp + 12, value); + } + set_int_result(rv); + #else + set_int_result(-1); + #endif + } + + void gloss32::do_sys_exit() { int32 value; *************** gloss32::do_sys_open() *** 758,807 **** } } bool gloss32::target_to_host_open_flags (int open_flags, int& flags) { ! switch (open_flags) { ! case 0: ! flags = hostops::open_read_only | hostops::open_text; ! break; ! case 1: flags = hostops::open_read_only; break; ! case 2: ! flags = hostops::open_read_write | hostops::open_text; break; ! case 3: flags = hostops::open_read_write; break; - case 4: - flags = hostops::open_write_only | hostops::open_create | hostops::open_trunc | hostops::open_text; - break; - case 5: - flags = hostops::open_write_only | hostops::open_create | hostops::open_trunc; - break; - case 6: - flags = hostops::open_read_write | hostops::open_create | hostops::open_trunc | hostops::open_text; - break; - case 7: - flags = hostops::open_read_write | hostops::open_create | hostops::open_trunc; - break; - case 8: - flags = hostops::open_write_only | hostops::open_create | hostops::open_append | hostops::open_text; - break; - case 9: - flags = hostops::open_write_only | hostops::open_create | hostops::open_append; - break; - case 10: - flags = hostops::open_read_write | hostops::open_create | hostops::open_append | hostops::open_text; - break; - case 11: - flags = hostops::open_read_write | hostops::open_create | hostops::open_append; - break; default: return false; } return true; } --- 837,879 ---- } } + // This only handles O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_CREAT & O_TRUNC. + #define NEWLIB_O_RDONLY 0x0000 + #define NEWLIB_O_WRONLY 0x0001 + #define NEWLIB_O_RDWR 0x0002 + #define NEWLIB_O_APPEND 0x0008 + #define NEWLIB_O_CREAT 0x0200 + #define NEWLIB_O_TRUNC 0x0400 bool gloss32::target_to_host_open_flags (int open_flags, int& flags) { ! switch (open_flags & 3) { ! case NEWLIB_O_RDONLY: flags = hostops::open_read_only; break; ! case NEWLIB_O_WRONLY: ! flags = hostops::open_write_only; break; ! case NEWLIB_O_RDWR: flags = hostops::open_read_write; break; default: return false; } + + if ((open_flags & ~(3|NEWLIB_O_APPEND|NEWLIB_O_CREAT|NEWLIB_O_TRUNC)) != 0) + return false; + + if (open_flags & NEWLIB_O_APPEND) + flags |= hostops::open_append; + + if (open_flags & NEWLIB_O_CREAT) + flags |= hostops::open_create; + + if (open_flags & NEWLIB_O_TRUNC) + flags |= hostops::open_trunc; + return true; } Index: component/gloss/gloss.h =================================================================== RCS file: /cvs/src/src/sid/component/gloss/gloss.h,v retrieving revision 1.1 diff -p -r1.1 gloss.h *** gloss.h 2000/12/07 19:30:50 1.1 --- gloss.h 2001/01/06 05:38:51 *************** protected: *** 140,145 **** --- 140,148 ---- void do_sys_open(); void do_sys_close(); void do_sys_lseek(); + void do_sys_time(); + void do_sys_gettimeofday(); + void do_sys_times(); virtual void do_nonstandard_target_syscalls(int32 syscall); virtual bool target_to_host_open_flags (int open_flags, int& flags); virtual int32 target_to_host_syscall (int32 syscall); Index: component/gloss/libgloss.h =================================================================== RCS file: /cvs/src/src/sid/component/gloss/libgloss.h,v retrieving revision 1.1 diff -p -r1.1 libgloss.h *** libgloss.h 2000/12/07 19:30:50 1.1 --- libgloss.h 2001/01/06 05:38:51 *************** public: *** 35,41 **** SYS_stat = 15, SYS_chmod = 16, SYS_utime = 17, ! SYS_time = 18 }; }; --- 35,43 ---- SYS_stat = 15, SYS_chmod = 16, SYS_utime = 17, ! SYS_time = 18, ! SYS_gettimeofday = 19, ! SYS_times = 20 }; };