ID:426 - Fallback to run-time detection of PAGESIZE if compile-time detection is not supported

Fixes an error ('EXEC_PAGESIZE' undeclared) with musl libc.

Should adhere to sysconf(3) and posixoptions(7).
This commit is contained in:
Dennis Schridde 2016-04-11 16:03:44 +02:00
parent aeba39bffc
commit 0008072590

View File

@ -105,9 +105,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define IMB_DEVICE "/dev/instru/mismic" #define IMB_DEVICE "/dev/instru/mismic"
#else #else
#define IMB_DEVICE "/dev/imb" #define IMB_DEVICE "/dev/imb"
#ifndef PAGESIZE
# define PAGESIZE EXEC_PAGESIZE
#endif #endif
#if !defined(PAGESIZE) && defined(PAGE_SIZE)
# define PAGESIZE PAGE_SIZE
#endif
#if !defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)
# define _SC_PAGESIZE _SC_PAGE_SIZE
#endif #endif
/*Just to make the DEBUG code cleaner.*/ /*Just to make the DEBUG code cleaner.*/
@ -1985,6 +1990,16 @@ MapPhysicalMemory(int startAddress,int addressLength, int *virtualAddress )
off_t startpAddress = (off_t)startAddress; off_t startpAddress = (off_t)startAddress;
unsigned int diff; unsigned int diff;
char *startvAddress; char *startvAddress;
#if defined(PAGESIZE)
long int pagesize = PAGESIZE;
#elif defined(_SC_PAGESIZE)
long int pagesize = sysconf(_SC_PAGESIZE);
if (pagesize < 1) {
perror("Invalid pagesize");
}
#else
# error PAGESIZE unsupported
#endif
if ((startAddress == 0) || (addressLength <= 0)) if ((startAddress == 0) || (addressLength <= 0))
return ACCESN_ERROR; return ACCESN_ERROR;
@ -1999,7 +2014,7 @@ MapPhysicalMemory(int startAddress,int addressLength, int *virtualAddress )
} }
/* aliging the offset to a page boundary and adjusting the length */ /* aliging the offset to a page boundary and adjusting the length */
diff = (int)startpAddress % PAGESIZE; diff = (int)startpAddress % pagesize;
startpAddress -= diff; startpAddress -= diff;
length += diff; length += diff;
@ -2043,9 +2058,19 @@ ACCESN_STATUS
UnmapPhysicalMemory( int virtualAddress, int Length ) UnmapPhysicalMemory( int virtualAddress, int Length )
{ {
unsigned int diff = 0; unsigned int diff = 0;
#if defined(PAGESIZE)
long int pagesize = PAGESIZE;
#elif defined(_SC_PAGESIZE)
long int pagesize = sysconf(_SC_PAGESIZE);
if (pagesize < 1) {
perror("Invalid pagesize");
}
#else
# error PAGESIZE unsupported
#endif
/* page align the virtual address and adjust length accordingly */ /* page align the virtual address and adjust length accordingly */
diff = ((unsigned int) virtualAddress) % PAGESIZE; diff = ((unsigned int) virtualAddress) % pagesize;
virtualAddress -= diff; virtualAddress -= diff;
Length += diff; Length += diff;
#ifndef NO_MACRO_ARGS #ifndef NO_MACRO_ARGS