All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline
@ 2014-08-21 10:02 Jan Stancek
  2014-08-21 11:51 ` chrubis
  2014-08-25 13:09 ` chrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Stancek @ 2014-08-21 10:02 UTC (permalink / raw)
  To: ltp-list

Some functions used to implement safe macros have parameters
of type off_t or structures containing off_t fields.

We don't want these to be compiled into libltp, because
some testcases are compiled with different flags such as:
  -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t
which then creates incompatibility and testcases can fail.

For example sendfile06_64 on i386:
    sendfile06_64    1  TFAIL  :  sendfile06.c:90: sendfile(2) failed
          to return expected value, expected: 17592186044442, got: 26

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/safe_macros.h |  167 ++++++++++++++++++++++++++++++++++++++-----------
 lib/safe_macros.c     |  109 --------------------------------
 2 files changed, 130 insertions(+), 146 deletions(-)

diff --git a/include/safe_macros.h b/include/safe_macros.h
index a79c4ad..5ee4d42 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -16,6 +16,7 @@
 #ifndef __SAFE_MACROS_H__
 #define __SAFE_MACROS_H__
 
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
@@ -81,12 +82,6 @@ int     safe_rmdir(const char *file, const int lineno,
 #define SAFE_RMDIR(cleanup_fn, pathname) \
 	safe_rmdir(__FILE__, __LINE__, (cleanup_fn), (pathname))
 
-void*	safe_mmap(const char *file, const int lineno,
-	    void (*cleanup_fn)(void), void *addr, size_t length, int prot,
-	    int flags, int fd, off_t offset);
-#define SAFE_MMAP(cleanup_fn, addr, length, prot, flags, fd, offset)	\
-	safe_mmap(__FILE__, __LINE__, (cleanup_fn), (addr), (length), (prot), \
-	    (flags), (fd), (offset))
 
 int	safe_munmap(const char *file, const int lineno,
 	    void (*cleanup_fn)(void), void *addr, size_t length);
@@ -152,12 +147,6 @@ int	safe_link(const char *file, const int lineno,
 #define SAFE_LINK(cleanup_fn, oldpath, newpath) \
         safe_link(__FILE__, __LINE__, cleanup_fn, (oldpath), (newpath))
 
-off_t	safe_lseek(const char *file, const int lineno,
-                   void (cleanup_fn)(void), int fd,
-                   off_t offset, int whence);
-#define SAFE_LSEEK(cleanup_fn, fd, offset, whence) \
-        safe_lseek(__FILE__, __LINE__, cleanup_fn, (fd), (offset), (whence))
-
 int	safe_symlink(const char *file, const int lineno,
                      void (cleanup_fn)(void), const char *oldpath,
                      const char *newpath);
@@ -171,16 +160,6 @@ ssize_t	safe_write(const char *file, const int lineno,
 	safe_write(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \
 	    (buf), (nbyte))
 
-int safe_ftruncate(const char *file, const int lineno,
-	    void (cleanup_fn)(void), int fd, off_t length);
-#define SAFE_FTRUNCATE(cleanup_fn, fd, length) \
-	safe_ftruncate(__FILE__, __LINE__, cleanup_fn, (fd), (length))
-
-int safe_truncate(const char *file, const int lineno,
-	    void (cleanup_fn)(void), const char *path, off_t length);
-#define SAFE_TRUNCATE(cleanup_fn, fd, length) \
-	safe_truncate(__FILE__, __LINE__, cleanup_fn, (path), (length))
-
 long safe_strtol(const char *file, const int lineno,
 	    void (cleanup_fn)(void), char *str, long min, long max);
 #define SAFE_STRTOL(cleanup_fn, str, min, max) \
@@ -196,21 +175,6 @@ long safe_sysconf(const char *file, const int lineno,
 #define SAFE_SYSCONF(cleanup_fn, name) \
 	safe_sysconf(__FILE__, __LINE__, cleanup_fn, name)
 
-int safe_stat(const char *file, const int lineno, void (cleanup_fn)(void),
-              const char *path, struct stat *buf);
-#define SAFE_STAT(cleanup_fn, path, buf) \
-	safe_stat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
-
-int safe_fstat(const char *file, const int lineno, void (cleanup_fn)(void),
-	       int fd, struct stat *buf);
-#define SAFE_FSTAT(cleanup_fn, fd, buf) \
-	safe_fstat(__FILE__, __LINE__, (cleanup_fn), (fd), (buf))
-
-int safe_lstat(const char *file, const int lineno, void (cleanup_fn)(void),
-               const char *path, struct stat *buf);
-#define SAFE_LSTAT(cleanup_fn, path, buf) \
-	safe_lstat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
-
 int safe_getrlimit(const char *file, const int lineno, void (cleanup_fn)(void),
 		   int resource, struct rlimit *rlim);
 #define SAFE_GETRLIMIT(cleanup_fn, resource, rlim) \
@@ -271,5 +235,134 @@ int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void),
 #define SAFE_RENAME(cleanup_fn, oldpath, newpath) \
 	safe_rename(__FILE__, __LINE__, (cleanup_fn), (oldpath), (newpath))
 
+/*
+ * following functions are inline because the behaviour may depend on
+ * -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t compile flags
+ */
+
+static inline void *safe_mmap(const char *file, const int lineno,
+	void (*cleanup_fn)(void), void *addr, size_t length,
+	int prot, int flags, int fd, off_t offset)
+{
+	void *rval;
+
+	rval = mmap(addr, length, prot, flags, fd, offset);
+	if (rval == MAP_FAILED) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: mmap(%p,%zu,%d,%d,%d,%ld) failed",
+			 file, lineno, addr, length, prot, flags, fd,
+			 (long) offset);
+	}
+
+	return rval;
+}
+#define SAFE_MMAP(cleanup_fn, addr, length, prot, flags, fd, offset) \
+	safe_mmap(__FILE__, __LINE__, (cleanup_fn), (addr), (length), (prot), \
+	(flags), (fd), (offset))
+
+static inline int safe_ftruncate(const char *file, const int lineno,
+	void (cleanup_fn) (void), int fd, off_t length)
+{
+	int rval;
+
+	rval = ftruncate(fd, length);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: ftruncate(%d,%ld) failed",
+			 file, lineno, fd, (long)length);
+	}
+
+	return rval;
+}
+#define SAFE_FTRUNCATE(cleanup_fn, fd, length) \
+	safe_ftruncate(__FILE__, __LINE__, cleanup_fn, (fd), (length))
+
+static inline int safe_truncate(const char *file, const int lineno,
+	void (cleanup_fn) (void), const char *path, off_t length)
+{
+	int rval;
+
+	rval = truncate(path, length);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: truncate(%s,%ld) failed",
+			 file, lineno, path, (long)length);
+	}
+
+	return rval;
+}
+#define SAFE_TRUNCATE(cleanup_fn, fd, length) \
+	safe_truncate(__FILE__, __LINE__, cleanup_fn, (path), (length))
+
+static inline int safe_stat(const char *file, const int lineno,
+	void (cleanup_fn)(void), const char *path, struct stat *buf)
+{
+	int rval;
+
+	rval = stat(path, buf);
+
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: stat(%s,%p) failed", file, lineno, path, buf);
+	}
+
+	return rval;
+}
+#define SAFE_STAT(cleanup_fn, path, buf) \
+	safe_stat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
+
+static inline int safe_fstat(const char *file, const int lineno,
+	void (cleanup_fn)(void), int fd, struct stat *buf)
+{
+	int rval;
+
+	rval = fstat(fd, buf);
+
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: fstat(%d,%p) failed", file, lineno, fd, buf);
+	}
+
+	return rval;
+}
+#define SAFE_FSTAT(cleanup_fn, fd, buf) \
+	safe_fstat(__FILE__, __LINE__, (cleanup_fn), (fd), (buf))
+
+static inline int safe_lstat(const char *file, const int lineno,
+	void (cleanup_fn)(void), const char *path, struct stat *buf)
+{
+	int rval;
+
+	rval = lstat(path, buf);
+
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: lstat(%s,%p) failed", file, lineno, path, buf);
+	}
+
+	return rval;
+}
+#define SAFE_LSTAT(cleanup_fn, path, buf) \
+	safe_lstat(__FILE__, __LINE__, (cleanup_fn), (path), (buf))
+
+static inline off_t safe_lseek(const char *file, const int lineno,
+	void (cleanup_fn)(void), int fd, off_t offset, int whence)
+{
+	off_t rval;
+
+	rval = lseek(fd, offset, whence);
+
+	if (rval == (off_t) -1) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			"%s:%d: lseek(%d,%ld,%d) failed",
+			file, lineno, fd, (long)offset, whence);
+	}
+
+	return rval;
+}
+#define SAFE_LSEEK(cleanup_fn, fd, offset, whence) \
+	safe_lseek(__FILE__, __LINE__, cleanup_fn, (fd), (offset), (whence))
+
+
 #endif /* __SAFE_MACROS_H__ */
 #endif /* __TEST_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index eefacae..76d781f 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -185,23 +185,6 @@ int safe_rmdir(const char *file, const int lineno, void (*cleanup_fn) (void),
 	return (rval);
 }
 
-void *safe_mmap(const char *file, const int lineno, void (*cleanup_fn) (void),
-		void *addr, size_t length, int prot, int flags, int fd,
-		off_t offset)
-{
-	void *rval;
-
-	rval = mmap(addr, length, prot, flags, fd, offset);
-	if (rval == MAP_FAILED) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: mmap(%p,%zu,%d,%d,%d,%ld) failed",
-			 file, lineno, addr, length, prot, flags, fd,
-			 (long) offset);
-	}
-
-	return rval;
-}
-
 int safe_munmap(const char *file, const int lineno, void (*cleanup_fn) (void),
                 void *addr, size_t length)
 {
@@ -391,23 +374,6 @@ int safe_link(const char *file, const int lineno,
 	return rval;
 }
 
-off_t safe_lseek(const char *file, const int lineno,
-                 void (cleanup_fn)(void), int fd,
-                 off_t offset, int whence)
-{
-	off_t rval;
-
-	rval = lseek(fd, offset, whence);
-
-	if (rval == (off_t) -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-		         "%s:%d: lseek(%d,%ld,%d) failed",
-			 file, lineno, fd, (long)offset, whence);
-	}
-
-	return rval;
-}
-
 int safe_symlink(const char *file, const int lineno,
                  void (cleanup_fn)(void), const char *oldpath,
                  const char *newpath)
@@ -440,36 +406,6 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
 	return rval;
 }
 
-int safe_ftruncate(const char *file, const int lineno,
-		   void (cleanup_fn) (void), int fd, off_t length)
-{
-	int rval;
-
-	rval = ftruncate(fd, length);
-	if (rval == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: ftruncate(%d,%ld) failed",
-			 file, lineno, fd, (long)length);
-	}
-
-	return rval;
-}
-
-int safe_truncate(const char *file, const int lineno,
-		  void (cleanup_fn) (void), const char *path, off_t length)
-{
-	int rval;
-
-	rval = truncate(path, length);
-	if (rval == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: truncate(%s,%ld) failed",
-			 file, lineno, path, (long)length);
-	}
-
-	return rval;
-}
-
 long safe_strtol(const char *file, const int lineno,
 		 void (cleanup_fn) (void), char *str, long min, long max)
 {
@@ -553,51 +489,6 @@ long safe_sysconf(const char *file, const int lineno,
 	return rval;
 }
 
-int safe_stat(const char *file, const int lineno,
-	      void (cleanup_fn)(void), const char *path, struct stat *buf)
-{
-	int rval;
-
-	rval = stat(path, buf);
-
-	if (rval == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: stat(%s,%p) failed", file, lineno, path, buf);
-	}
-
-	return rval;
-}
-
-int safe_fstat(const char *file, const int lineno,
-	       void (cleanup_fn)(void), int fd, struct stat *buf)
-{
-	int rval;
-
-	rval = fstat(fd, buf);
-
-	if (rval == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: fstat(%d,%p) failed", file, lineno, fd, buf);
-	}
-
-	return rval;
-}
-
-int safe_lstat(const char *file, const int lineno,
-	       void (cleanup_fn)(void), const char *path, struct stat *buf)
-{
-	int rval;
-
-	rval = lstat(path, buf);
-
-	if (rval == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup_fn,
-			 "%s:%d: lstat(%s,%p) failed", file, lineno, path, buf);
-	}
-
-	return rval;
-}
-
 int safe_getrlimit(const char *file, const int lineno,
 		   void (cleanup_fn)(void), int resource, struct rlimit *rlim)
 {
-- 
1.7.1


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline
  2014-08-21 10:02 [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline Jan Stancek
@ 2014-08-21 11:51 ` chrubis
  2014-08-25 13:09 ` chrubis
  1 sibling, 0 replies; 5+ messages in thread
From: chrubis @ 2014-08-21 11:51 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> Some functions used to implement safe macros have parameters
> of type off_t or structures containing off_t fields.
> 
> We don't want these to be compiled into libltp, because
> some testcases are compiled with different flags such as:
>   -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t
> which then creates incompatibility and testcases can fail.
> 
> For example sendfile06_64 on i386:
>     sendfile06_64    1  TFAIL  :  sendfile06.c:90: sendfile(2) failed
>           to return expected value, expected: 17592186044442, got: 26

Looks good, acked.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline
  2014-08-21 10:02 [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline Jan Stancek
  2014-08-21 11:51 ` chrubis
@ 2014-08-25 13:09 ` chrubis
       [not found]   ` <400651514.12451738.1408972658808.JavaMail.zimbra@redhat.com>
  1 sibling, 1 reply; 5+ messages in thread
From: chrubis @ 2014-08-25 13:09 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> Some functions used to implement safe macros have parameters
> of type off_t or structures containing off_t fields.
> 
> We don't want these to be compiled into libltp, because
> some testcases are compiled with different flags such as:
>   -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t
> which then creates incompatibility and testcases can fail.
> 
> For example sendfile06_64 on i386:
>     sendfile06_64    1  TFAIL  :  sendfile06.c:90: sendfile(2) failed
>           to return expected value, expected: 17592186044442, got: 26

And I've just found that the same applies to rlim_t used in setrlimit()
rlimit structure.

(taken from /usr/include/bits/resource.h)

/* Type for resource quantity measurement.  */
#ifndef __USE_FILE_OFFSET64
typedef __rlim_t rlim_t;
#else
typedef __rlim64_t rlim_t;
#endif
#ifdef __USE_LARGEFILE64
typedef __rlim64_t rlim64_t;
#endif

And the testcase that fails in SAFE_SETRLIMIT() is truncate03_64 after
the patch that fixes the EFBIG limit.

So unless you are already working on it I will prepare and push a patch
that moves rlimit related safe macros to the header as well.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline
       [not found]   ` <400651514.12451738.1408972658808.JavaMail.zimbra@redhat.com>
@ 2014-08-25 14:07     ` chrubis
       [not found]       ` <1251340269.12540621.1408977990485.JavaMail.zimbra@redhat.com>
  0 siblings, 1 reply; 5+ messages in thread
From: chrubis @ 2014-08-25 14:07 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> > And the testcase that fails in SAFE_SETRLIMIT() is truncate03_64 after
> > the patch that fixes the EFBIG limit.
> > 
> > So unless you are already working on it I will prepare and push a patch
> > that moves rlimit related safe macros to the header as well.
> 
> I'm not - it did not fail when I tested the patch for some reason.

Fixed and pushed, please test.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline
       [not found]         ` <1139993286.12980615.1409044361683.JavaMail.zimbra@redhat.com>
@ 2014-08-26  9:36           ` chrubis
  0 siblings, 0 replies; 5+ messages in thread
From: chrubis @ 2014-08-26  9:36 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> Testing went OK, I came across one new issue on system supporting CPU hotplug in 
> sched_setaffinity01.c / tst_ncpus_max().
> 
> tst_ncpus_max is using sysconf(_SC_NPROCESSORS_CONF), but sched_getaffinity
> cares about all possible cpus, so it fails with EINVAL, because mask is too small.
> 
> I'm thinking we should try to read /sys/devices/system/cpu/possible or even
> /sys/devices/system/cpu/kernel_max (NR_CPUS) and use that value to be safe
> and only fall back to _SC_NPROCESSORS_CONF as last resort.

Sounds good to me.

> There's a big mail thread about this issue, I think Carlos made a nice summary:
>   https://sourceware.org/ml/libc-alpha/2013-07/msg00429.html

I was part of the discussion, the API for getting number of processors
on Linux is currently in mess :(.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-26  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-21 10:02 [LTP] [PATCH] safe_macros: turn functions with off_t parameter into static inline Jan Stancek
2014-08-21 11:51 ` chrubis
2014-08-25 13:09 ` chrubis
     [not found]   ` <400651514.12451738.1408972658808.JavaMail.zimbra@redhat.com>
2014-08-25 14:07     ` chrubis
     [not found]       ` <1251340269.12540621.1408977990485.JavaMail.zimbra@redhat.com>
     [not found]         ` <1139993286.12980615.1409044361683.JavaMail.zimbra@redhat.com>
2014-08-26  9:36           ` chrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.