X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib_internal%2Funify-copy.c;h=6b93089ed9c742492a54fef7816c438dd62ac7bc;hb=faa778968d1a7dfeaebc9fe4b847e691dc62fd15;hp=06c8aef60440017fb9bbe0b18f1cfda97fe2c210;hpb=2b4a53c0516fcbddbdab9d82bb6519fd04fecbae;p=util-vserver.git diff --git a/util-vserver/lib_internal/unify-copy.c b/util-vserver/lib_internal/unify-copy.c index 06c8aef..6b93089 100644 --- a/util-vserver/lib_internal/unify-copy.c +++ b/util-vserver/lib_internal/unify-copy.c @@ -36,6 +36,10 @@ #define MMAP_BLOCKSIZE (16 * 1024*1024) +#ifndef TESTSUITE_COPY_CODE +# define TESTSUITE_COPY_CODE do { } while (false) +#endif + static inline bool verifySource(int fd, struct stat const *exp_stat) { @@ -65,14 +69,14 @@ copyLnk(char const *src, char const *dst) } } -static jmp_buf bus_error_restore; +static sigjmp_buf bus_error_restore; static volatile sig_atomic_t bus_error; static void handlerSIGBUS(int UNUSED num) { bus_error = 1; - longjmp(bus_error_restore, 1); + siglongjmp(bus_error_restore, 1); } static void @@ -108,12 +112,11 @@ static UNUSED bool copyMMap(int in_fd, int out_fd) { off_t in_len = lseek(in_fd, 0, SEEK_END); - void const *in_buf = 0; - void *out_buf = 0; + void const * volatile in_buf = 0; + void * volatile out_buf = 0; - loff_t in_size = 0; - loff_t out_size = 0; - bool res = false; + loff_t volatile buf_size = 0; + bool volatile res = false; if (in_len==-1) return false; if (in_len>0 && @@ -122,36 +125,36 @@ copyMMap(int in_fd, int out_fd) return false; bus_error = 0; - if (setjmp(bus_error_restore)==0) { - off_t offset = 0; + if (sigsetjmp(bus_error_restore, 1)==0) { + off_t offset = 0; while (offset < in_len) { - in_size = in_len - offset; - if (in_size > MMAP_BLOCKSIZE) in_size = MMAP_BLOCKSIZE; + buf_size = in_len - offset; + if (buf_size > MMAP_BLOCKSIZE) buf_size = MMAP_BLOCKSIZE; - in_buf = mmap(0, in_size, PROT_READ, MAP_SHARED, in_fd, offset); - if (in_buf==0) goto out; - - out_size = in_size; - out_buf = mmap(0, out_size, PROT_WRITE, MAP_SHARED, out_fd, offset); - if (out_buf==0) goto out; + if ((in_buf = mmap(0, buf_size, PROT_READ, MAP_SHARED, in_fd, offset))==0 || + (out_buf = mmap(0, buf_size, PROT_WRITE, MAP_SHARED, out_fd, offset))==0) { + perror("mmap()"); + goto out; + } - offset += in_size; - madvise(const_cast(void *)(in_buf), in_size, MADV_SEQUENTIAL); - madvise(out_buf, out_size, MADV_SEQUENTIAL); + offset += buf_size; + madvise(const_cast(void *)(in_buf), buf_size, MADV_SEQUENTIAL); + madvise(out_buf, buf_size, MADV_SEQUENTIAL); - copyMem(out_buf, in_buf, in_size); + TESTSUITE_COPY_CODE; + copyMem(out_buf, in_buf, buf_size); - munmap(const_cast(void *)(in_buf), in_size); in_buf = 0; - munmap(out_buf, out_size); out_buf = 0; + munmap(const_cast(void *)(in_buf), buf_size); in_buf = 0; + munmap(out_buf, buf_size); out_buf = 0; } res = true; } out: - if (in_buf!=0) munmap(const_cast(void *)(in_buf), in_size); - if (out_buf!=0) munmap(out_buf, out_size); + if (in_buf !=0) munmap(const_cast(void *)(in_buf), buf_size); + if (out_buf!=0) munmap(out_buf, buf_size); return res; }