X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fmap.c;h=0fc5255640b4655b3d5928221ed767ecb24520fa;hb=2605f4d14956350887591f7d1111d7c1adc10416;hp=1701cf3e58e8cc14648726691fed1a544ae6df56;hpb=4eb352bcb3ef7a71dc9ab62c5cd2d5e7598619f7;p=mono.git diff --git a/support/map.c b/support/map.c index 1701cf3e58e..0fc5255640b 100644 --- a/support/map.c +++ b/support/map.c @@ -27,7 +27,9 @@ */ #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif /* ndef HAVE_SYS_TIME_H */ #ifdef HAVE_SYS_POLL_H #include #endif /* ndef HAVE_SYS_POLL_H */ @@ -43,7 +45,9 @@ #ifdef HAVE_SYS_MMAN_H #include #endif /* ndef HAVE_SYS_MMAN_H */ +#ifdef HAVE_UNISTD_H #include +#endif /* ndef HAVE_UNISTD_H */ #include #include #ifdef HAVE_POLL_H @@ -56,8 +60,13 @@ #ifdef HAVE_SYSLOG_H #include #endif /* ndef HAVE_SYSLOG_H */ +#ifdef HAVE_DIRENT_H #include +#endif /* ndef HAVE_DIRENT_H */ +#ifdef HAVE_UTIME_H #include +#endif /* ndef HAVE_UTIME_H */ +#include #include "mph.h" #include "map.h" @@ -186,34 +195,46 @@ ? CNM_MAXINT64 \ : (g_assert_not_reached (), 0)) -#ifdef DEBUG -#define _cnm_dump_(to_t,from) \ - printf ("# %s -> %s: min=%llx; max=%llx; value=%llx; lt=%i; l0=%i; gt=%i; e=%i\n", \ +#ifdef _CNM_DUMP +#define _cnm_dump(to_t,from) \ + printf ("# %s -> %s: uns=%i; min=%llx; max=%llx; value=%llx; lt=%i; l0=%i; gt=%i; e=%i\n", \ #from, #to_t, \ - (gint64) (_cnm_integral_type_min(to_t)), \ + (int) _cnm_integral_type_is_unsigned (to_t), \ + (gint64) (_cnm_integral_type_min (to_t)), \ (gint64) (_cnm_integral_type_max (to_t)), \ (gint64) (from), \ - (_cnm_integral_type_min (to_t) <= from), \ + (((gint64) _cnm_integral_type_min (to_t)) <= (gint64) from), \ (from < 0), \ - /* (_cnm_integral_type_max (to_t) >= from) */ \ - (from <= _cnm_integral_type_max (to_t)), \ - ((_cnm_integral_type_min(to_t) >= from) && \ - ((from < 0) ? 1 : (from <= _cnm_integral_type_max(to_t)))) \ + (((guint64) from) <= (guint64) _cnm_integral_type_max (to_t)), \ + !((int) _cnm_integral_type_is_unsigned (to_t) \ + ? ((0 <= from) && \ + ((guint64) from <= (guint64) _cnm_integral_type_max (to_t))) \ + : ((gint64) _cnm_integral_type_min(to_t) <= (gint64) from && \ + (guint64) from <= (guint64) _cnm_integral_type_max (to_t))) \ ) -#else -#define _cnm_dump_(to_t, from) do {} while (0) -#endif +#else /* ndef _CNM_DUMP */ +#define _cnm_dump(to_t, from) do {} while (0) +#endif /* def _CNM_DUMP */ +#ifdef DEBUG #define _cnm_return_val_if_overflow(to_t,from,val) G_STMT_START { \ - gint64 sf = (gint64) from; \ - guint64 uf = (guint64) from; \ - if (!(_cnm_integral_type_min(to_t) <= sf && \ - ((from < 0) || (uf <= _cnm_integral_type_max(to_t))))) { \ - _cnm_dump_(to_t, from); \ + int uns = _cnm_integral_type_is_unsigned (to_t); \ + gint64 min = (gint64) _cnm_integral_type_min (to_t); \ + guint64 max = (guint64) _cnm_integral_type_max (to_t); \ + gint64 sf = (gint64) from; \ + guint64 uf = (guint64) from; \ + if (!(uns ? ((0 <= from) && (uf <= max)) \ + : (min <= sf && (from < 0 || uf <= max)))) { \ + _cnm_dump(to_t, from); \ errno = EOVERFLOW; \ return (val); \ } \ } G_STMT_END +#else /* !def DEBUG */ +/* don't do any overflow checking */ +#define _cnm_return_val_if_overflow(to_t,from,val) G_STMT_START { \ + } G_STMT_END +#endif /* def DEBUG */ int Mono_Posix_FromAccessModes (int x, int *r) { @@ -2511,6 +2532,56 @@ int Mono_Posix_ToFilePermissions (unsigned int x, unsigned int *r) return 0; } +#ifdef HAVE_STRUCT_FLOCK +int +Mono_Posix_FromFlock (struct Mono_Posix_Flock *from, struct flock *to) +{ + _cnm_return_val_if_overflow (off_t, from->l_start, -1); + _cnm_return_val_if_overflow (off_t, from->l_len, -1); + _cnm_return_val_if_overflow (pid_t, from->l_pid, -1); + + memset (to, 0, sizeof(*to)); + + if (Mono_Posix_FromLockType (from->l_type, &to->l_type) != 0) { + return -1; + } + if (Mono_Posix_FromSeekFlags (from->l_whence, &to->l_whence) != 0) { + return -1; + } + to->l_start = from->l_start; + to->l_len = from->l_len; + to->l_pid = from->l_pid; + + return 0; +} +#endif /* ndef HAVE_STRUCT_FLOCK */ + + +#ifdef HAVE_STRUCT_FLOCK +int +Mono_Posix_ToFlock (struct flock *from, struct Mono_Posix_Flock *to) +{ + _cnm_return_val_if_overflow (gint64, from->l_start, -1); + _cnm_return_val_if_overflow (gint64, from->l_len, -1); + _cnm_return_val_if_overflow (int, from->l_pid, -1); + + memset (to, 0, sizeof(*to)); + + if (Mono_Posix_ToLockType (from->l_type, &to->l_type) != 0) { + return -1; + } + if (Mono_Posix_ToSeekFlags (from->l_whence, &to->l_whence) != 0) { + return -1; + } + to->l_start = from->l_start; + to->l_len = from->l_len; + to->l_pid = from->l_pid; + + return 0; +} +#endif /* ndef HAVE_STRUCT_FLOCK */ + + int Mono_Posix_FromLockType (short x, short *r) { *r = 0; @@ -2890,6 +2961,12 @@ int Mono_Posix_FromMountFlags (guint64 x, guint64 *r) #else /* def ST_APPEND */ {errno = EINVAL; return -1;} #endif /* ndef ST_APPEND */ + if ((x & Mono_Posix_MountFlags_ST_BIND) == Mono_Posix_MountFlags_ST_BIND) +#ifdef ST_BIND + *r |= ST_BIND; +#else /* def ST_BIND */ + {errno = EINVAL; return -1;} +#endif /* ndef ST_BIND */ if ((x & Mono_Posix_MountFlags_ST_IMMUTABLE) == Mono_Posix_MountFlags_ST_IMMUTABLE) #ifdef ST_IMMUTABLE *r |= ST_IMMUTABLE; @@ -2920,6 +2997,12 @@ int Mono_Posix_FromMountFlags (guint64 x, guint64 *r) #else /* def ST_NODIRATIME */ {errno = EINVAL; return -1;} #endif /* ndef ST_NODIRATIME */ + if ((x & Mono_Posix_MountFlags_ST_NOEXEC) == Mono_Posix_MountFlags_ST_NOEXEC) +#ifdef ST_NOEXEC + *r |= ST_NOEXEC; +#else /* def ST_NOEXEC */ + {errno = EINVAL; return -1;} +#endif /* ndef ST_NOEXEC */ if ((x & Mono_Posix_MountFlags_ST_NOSUID) == Mono_Posix_MountFlags_ST_NOSUID) #ifdef ST_NOSUID *r |= ST_NOSUID; @@ -2932,6 +3015,12 @@ int Mono_Posix_FromMountFlags (guint64 x, guint64 *r) #else /* def ST_RDONLY */ {errno = EINVAL; return -1;} #endif /* ndef ST_RDONLY */ + if ((x & Mono_Posix_MountFlags_ST_REMOUNT) == Mono_Posix_MountFlags_ST_REMOUNT) +#ifdef ST_REMOUNT + *r |= ST_REMOUNT; +#else /* def ST_REMOUNT */ + {errno = EINVAL; return -1;} +#endif /* ndef ST_REMOUNT */ if ((x & Mono_Posix_MountFlags_ST_SYNCHRONOUS) == Mono_Posix_MountFlags_ST_SYNCHRONOUS) #ifdef ST_SYNCHRONOUS *r |= ST_SYNCHRONOUS; @@ -2958,6 +3047,10 @@ int Mono_Posix_ToMountFlags (guint64 x, guint64 *r) if ((x & ST_APPEND) == ST_APPEND) *r |= Mono_Posix_MountFlags_ST_APPEND; #endif /* ndef ST_APPEND */ +#ifdef ST_BIND + if ((x & ST_BIND) == ST_BIND) + *r |= Mono_Posix_MountFlags_ST_BIND; +#endif /* ndef ST_BIND */ #ifdef ST_IMMUTABLE if ((x & ST_IMMUTABLE) == ST_IMMUTABLE) *r |= Mono_Posix_MountFlags_ST_IMMUTABLE; @@ -2978,6 +3071,10 @@ int Mono_Posix_ToMountFlags (guint64 x, guint64 *r) if ((x & ST_NODIRATIME) == ST_NODIRATIME) *r |= Mono_Posix_MountFlags_ST_NODIRATIME; #endif /* ndef ST_NODIRATIME */ +#ifdef ST_NOEXEC + if ((x & ST_NOEXEC) == ST_NOEXEC) + *r |= Mono_Posix_MountFlags_ST_NOEXEC; +#endif /* ndef ST_NOEXEC */ #ifdef ST_NOSUID if ((x & ST_NOSUID) == ST_NOSUID) *r |= Mono_Posix_MountFlags_ST_NOSUID; @@ -2986,6 +3083,10 @@ int Mono_Posix_ToMountFlags (guint64 x, guint64 *r) if ((x & ST_RDONLY) == ST_RDONLY) *r |= Mono_Posix_MountFlags_ST_RDONLY; #endif /* ndef ST_RDONLY */ +#ifdef ST_REMOUNT + if ((x & ST_REMOUNT) == ST_REMOUNT) + *r |= Mono_Posix_MountFlags_ST_REMOUNT; +#endif /* ndef ST_REMOUNT */ #ifdef ST_SYNCHRONOUS if ((x & ST_SYNCHRONOUS) == ST_SYNCHRONOUS) *r |= Mono_Posix_MountFlags_ST_SYNCHRONOUS; @@ -6697,6 +6798,40 @@ int Mono_Posix_ToSyslogOptions (int x, int *r) return 0; } +#ifdef HAVE_STRUCT_TIMESPEC +int +Mono_Posix_FromTimespec (struct Mono_Posix_Timespec *from, struct timespec *to) +{ + _cnm_return_val_if_overflow (time_t, from->tv_sec, -1); + _cnm_return_val_if_overflow (gint64, from->tv_nsec, -1); + + memset (to, 0, sizeof(*to)); + + to->tv_sec = from->tv_sec; + to->tv_nsec = from->tv_nsec; + + return 0; +} +#endif /* ndef HAVE_STRUCT_TIMESPEC */ + + +#ifdef HAVE_STRUCT_TIMESPEC +int +Mono_Posix_ToTimespec (struct timespec *from, struct Mono_Posix_Timespec *to) +{ + _cnm_return_val_if_overflow (gint64, from->tv_sec, -1); + _cnm_return_val_if_overflow (gint64, from->tv_nsec, -1); + + memset (to, 0, sizeof(*to)); + + to->tv_sec = from->tv_sec; + to->tv_nsec = from->tv_nsec; + + return 0; +} +#endif /* ndef HAVE_STRUCT_TIMESPEC */ + + #ifdef HAVE_STRUCT_TIMEVAL int Mono_Posix_FromTimeval (struct Mono_Posix_Timeval *from, struct timeval *to) @@ -6765,6 +6900,40 @@ Mono_Posix_ToTimezone (struct timezone *from, struct Mono_Posix_Timezone *to) #endif /* ndef HAVE_STRUCT_TIMEZONE */ +#ifdef HAVE_STRUCT_UTIMBUF +int +Mono_Posix_FromUtimbuf (struct Mono_Posix_Utimbuf *from, struct utimbuf *to) +{ + _cnm_return_val_if_overflow (time_t, from->actime, -1); + _cnm_return_val_if_overflow (time_t, from->modtime, -1); + + memset (to, 0, sizeof(*to)); + + to->actime = from->actime; + to->modtime = from->modtime; + + return 0; +} +#endif /* ndef HAVE_STRUCT_UTIMBUF */ + + +#ifdef HAVE_STRUCT_UTIMBUF +int +Mono_Posix_ToUtimbuf (struct utimbuf *from, struct Mono_Posix_Utimbuf *to) +{ + _cnm_return_val_if_overflow (gint64, from->actime, -1); + _cnm_return_val_if_overflow (gint64, from->modtime, -1); + + memset (to, 0, sizeof(*to)); + + to->actime = from->actime; + to->modtime = from->modtime; + + return 0; +} +#endif /* ndef HAVE_STRUCT_UTIMBUF */ + + int Mono_Posix_FromWaitOptions (int x, int *r) { *r = 0;