X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fmph.h;h=e5992e5e71f03357080123ffb7a460016db8c488;hb=30cddad5fb4c3d290906a6e6c33ecd8b07d8b48c;hp=74dab37cb1b809f19f50c5ed7db3a78694a22660;hpb=538d3bb80572334c18ae117ea7703406a4a22872;p=mono.git diff --git a/support/mph.h b/support/mph.h index 74dab37cb1b..e5992e5e71f 100644 --- a/support/mph.h +++ b/support/mph.h @@ -27,6 +27,7 @@ #include +#include /* offsetof */ #include /* LONG_MAX, ULONG_MAX */ #include /* for ERANGE */ #include /* for g* types, etc. */ @@ -35,9 +36,7 @@ #include /* for SIZE_MAX */ #endif -#include "map-icalls.h" - -#if __APPLE__ || __BSD__ || __FreeBSD__ +#if __APPLE__ || __BSD__ || __FreeBSD__ || __OpenBSD__ #define MPH_ON_BSD #endif @@ -47,9 +46,55 @@ #define MPH_INTERNAL #endif -#if defined (PLATFORM_WIN32) && !defined (EOVERFLOW) -#define EOVERFLOW 75 -#endif /* def PLATFORM_WIN32 && ndef EOVERFLOW */ +#if !defined(EOVERFLOW) +# if defined(HOST_WIN32) +# define EOVERFLOW 75 +# elif defined(__OpenBSD__) +# define EOVERFLOW 87 +# endif +#endif /* !defined(EOVERFLOW) */ + +/* + * Solaris/Windows don't define these BSD values, and if they're not present + * then map.c:Mono_Posix_FromSeekFlags() breaks badly; see: + * http://bugzilla.gnome.org/show_bug.cgi?id=370081 + */ + +#ifndef L_SET +#define L_SET SEEK_SET +#endif /* ndef L_SET */ + +#ifndef L_INCR +#define L_INCR SEEK_CUR +#endif /* ndef L_INCR */ + +#ifndef L_XTND +#define L_XTND SEEK_END +#endif /* ndef L_XTND */ + +#if !defined (HOST_WIN32) + +/* + * OS X doesn't define MAP_ANONYMOUS, but it does define MAP_ANON. + * Alias them to fix: https://bugzilla.xamarin.com/show_bug.cgi?id=3419 + */ +#ifdef HOST_DARWIN +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif /* ndef MAP_ANONYMOUS */ +#endif /* ndef HOST_DARWIN */ + +/* + * XATTR_AUTO is a synonym for 0 within XattrFlags, but most systems don't + * define it. map.c doesn't know that, though, so we ensure that it's defined + * so that the value 0 round-trips through MonoPosixHelper. + */ + +#ifndef XATTR_AUTO +#define XATTR_AUTO 0 +#endif /* ndef XATTR_AUTO */ + +#endif /* ndef HOST_WIN32 */ typedef gint64 mph_blkcnt_t; typedef gint64 mph_blksize_t; @@ -67,6 +112,19 @@ typedef gint64 mph_clock_t; typedef guint64 mph_fsblkcnt_t; typedef guint64 mph_fsfilcnt_t; +/* Some versions of OS X don't define these typedefs, needed by map.c */ +#ifndef HAVE_BLKCNT_T +typedef mph_blkcnt_t blkcnt_t; +#endif + +#ifndef HAVE_BLKSIZE_T +typedef mph_blksize_t blksize_t; +#endif + +#ifndef HAVE_SUSECONDS_T +typedef gint64 suseconds_t; +#endif + #ifdef HAVE_LARGE_FILE_SUPPORT #define MPH_OFF_T_MAX G_MAXINT64 #define MPH_OFF_T_MIN G_MININT64 @@ -91,6 +149,13 @@ typedef guint64 mph_fsfilcnt_t; return ret; \ }}G_STMT_END +#define mph_have_uint_overflow(var) ((var) < 0 || (var) > UINT_MAX) + +#define mph_return_val_if_uint_overflow(var, ret) \ + _mph_return_val_if_cb_(var, ret, mph_have_uint_overflow) + +#define mph_return_if_uint_overflow(var) mph_return_val_if_uint_overflow(var, -1) + #define mph_have_long_overflow(var) ((var) > LONG_MAX || (var) < LONG_MIN) #define mph_return_val_if_long_overflow(var, ret) \ @@ -98,14 +163,14 @@ typedef guint64 mph_fsfilcnt_t; #define mph_return_if_long_overflow(var) mph_return_val_if_long_overflow(var, -1) -#define mph_have_ulong_overflow(var) ((var) > ULONG_MAX) +#define mph_have_ulong_overflow(var) (var) < 0 || ((var) > ULONG_MAX) #define mph_return_val_if_ulong_overflow(var, ret) \ _mph_return_val_if_cb_(var, ret, mph_have_ulong_overflow) #define mph_return_if_ulong_overflow(var) mph_return_val_if_ulong_overflow(var, -1) -#define mph_have_size_t_overflow(var) ((var) > MPH_SIZE_T_MAX) +#define mph_have_size_t_overflow(var) ((var) < 0 || (var) > MPH_SIZE_T_MAX) #define mph_return_val_if_size_t_overflow(var, ret) \ _mph_return_val_if_cb_(var, ret, mph_have_size_t_overflow) @@ -127,6 +192,15 @@ typedef guint64 mph_fsfilcnt_t; #define mph_return_if_time_t_overflow(var) mph_return_if_long_overflow(var) +#define mph_return_if_socklen_t_overflow(var) mph_return_if_uint_overflow(var) + +#define mph_return_if_val_in_list5(var,a,b,c,d,e) \ + do { \ + int v = (var); \ + if (v == a || v == b || v == c || v == d || v == e) \ + return -1; \ + } while (0) + /* * Helper function for functions which use ERANGE (such as getpwnam_r and * getgrnam_r). These functions accept buffers which are dynamically @@ -148,10 +222,20 @@ recheck_range (int ret) return 0; } +typedef unsigned int mph_string_offset_t; + +enum { + MPH_STRING_OFFSET_PTR = 0x0, + MPH_STRING_OFFSET_ARRAY = 0x1, + MPH_STRING_OFFSET_MASK = 0x1 +}; + +#define MPH_STRING_OFFSET(type,member,kind) ((offsetof(type,member) << 1) | kind) + MPH_INTERNAL char* _mph_copy_structure_strings ( - void *to, const size_t *to_offsets, - const void *from, const size_t *from_offsets, + void *to, const mph_string_offset_t *to_offsets, + const void *from, const mph_string_offset_t *from_offsets, size_t num_strings); #endif /* ndef INC_mph_H */