Re: mingw64 pjsip sizeof(fd_set) always double sizeof(pj_fd_set_t) causing assertion in sock_select.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

When target string is 'x86_64-w64-mingw32', PJ_WIN32 macro set should be enabled automatically, you can confirm it by checking file "pjlib\include\pj\compat\os_auto.h". Then I think you'd need to set PJ_WIN64=1 manually, e.g: via user.mak file.

We don't officially support msys2, not sure if we have tried it either. But on msys with mingw 64 bit, I think you can do this:
--
./configure --host=x86_64-w64-mingw32
--
Make sure target string is 'x86_64-w64-mingw32'. Then add "CFLAGS+=-DPJ_WIN64=1" into user.mak file, then 'make' as usual.

BR,
nanang


On Sat, Jun 29, 2019 at 4:23 AM Michael A. Leonetti <michael@xxxxxxxxxxxxxxx> wrote:

Sort of fixed the issue.

Posted on stackoverflow. Linking here: https://stackoverflow.com/questions/56793545/mingw64-pjsip-sizeoffd-set-always-double-sizeofpj-fd-set-t-causing-assertion

Michael A. Leonetti
As warm as green tea
On 6/28/19 11:44 AM, Michael A. Leonetti wrote:

All,

In tracking this bug it looks like on configure the flags for PJ_WIN32 are not being set for the build. The system isn't being detected as mingw although it is provided in the target as seen below: x86_64-w64-mingw32

checking build system type... x86_64-w64-mingw32
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
For this reason, it seems that WIN64 is not being detected and pj_sock_t is not being set to the proper value as shown below in pjlib/include/pj/types.h:

/** Socket handle. */
#if defined(PJ_WIN64) && PJ_WIN64!=0
    typedef pj_int64_t pj_sock_t;
#else
    typedef long pj_sock_t;
#endif
And thus pj_fd_set_t is smaller than fd_set *probably* because fd_set is using a bigger type for fd.

That's at least what I've come up with.

Any way to force PJ_WIN32=1 in the build instead of PJ_AUTOCONF=1 which it is being detected?

Michael A. Leonetti
As warm as green tea
On 6/27/19 12:08 PM, Michael A. Leonetti wrote:

Hello all,

Long time user first time caller. Nice to meet you all!

I'm trying to get pjsip to work on Windows. I've compiled pjsip into my program that I'm writing in an msys2/mingw environment (64-bit). It compiles fine. However, when I run it in my program I'm getting an assertion

// Line 49 of ../src/pj/sock_select.c
sizeof(pj_fd_set_t)-sizeof(pj_sock_t)>=sizeof(fd_set)

Every time I run the program.

When I do some digging people talk about increasing PJ_IOQUEUE_MAX_HANDLES. So I did, and I put a printf in the function before the asserts to see what the sizes are:

// My PJ_FD_ZERO variant
PJ_DEF(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp)
{
    printf( "PJ_IOQUEUE_MAX_HANDLES: %d, pj_fd_set_t: %I64d, pj_sock_t: %I64d, fd_set: %I64d\n", PJ_IOQUEUE_MAX_HANDLES, sizeof(pj_fd_set_t), sizeof(pj_sock_t), sizeof(fd_set) );
    PJ_CHECK_STACK();
    pj_assert(sizeof(pj_fd_set_t)-sizeof(pj_sock_t) >= sizeof(fd_set));

    FD_ZERO(PART_FDSET(fdsetp));
    PART_COUNT(fdsetp) = 0;
}
The program will output something like this:

10:27:43.477        os_core_win32.c !pjlib 2.9 for win32 initialized
10:27:43.507         sip_endpoint.c  .Creating endpoint instance...
PJ_IOQUEUE_MAX_HANDLES: 16384, pj_fd_set_t: 65552, pj_sock_t: 4, fd_set: 131080

However, when I tweak PJ_IOQUEUE_MAX_HANDLES the size of pj_fd_set_t increases as it should but! the sizeof(fd_set) also becomes slight less than DOUBLE whatever sizeof(pj_fd_set_t) is! The winsock guide says that I cannot set the size of fd_set so I am very confused how the size is getting set! I don't see anywhere in the pjsip code that this is being set.

So adjusting PJ_IOQUEUE_MAX_HANDLES is quite the losing battle.

How can I fix this so my code will stop asserting?

The bash script that I ran to configure pjsip

#!/bin/bash

JOPT=1
DEBUG=false
BUILD_ALL=true
CLEAN_BEFORE_BUILD=false

TOUCH_COMMAND="touch configure.ac aclocal.m4 configure Makefile.am Makefile.in"

while getopts ":pdj:o:c" opt; do
        case $opt in
                j)
                        JOPT="$OPTARG"
                        ;;
                c)
                        echo "Clean before build is set."
                        CLEAN_BEFORE_BUILD=true;
                        ;;
                d)
                        DEBUG=true
                        ;;
                o)
                        IFS=', ' read -r -a BUILD_OPTS <<< "${OPTARG}"
                        BUILD_ALL=false

                        for option in "${BUILD_OPTS[@]}" ; do
                                # Set individual
                                case $option in
                                        pjsip)
                                                BUILD_PJSIP=true;
                                                ;;
                                        *)
                                                echo "Unknown build option ${option}"
                                                exit
                                esac
                        done
                        ;;
                \?)
                        echo "Invalid option: -${OPTARG}" >&2
                        exit 1
                        ;;
                :)
                        echo "Option -${OPTARG} requires an argument." >&2
                        exit 1
                        ;;
        esac
done

# Make the out
mkdir out
OUT_PREFIX="$( pwd )/out"
export PKG_CONFIG_PATH="${OUT_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}"

if [ "$DEBUG" = true ] ; then
MAKEFLAGS="-g -O0"
else
MAKEFLAGS="-O2"
fi

# Main directory
LIB_DIRECTORY="$(pwd)/lib"

# Descend
cd "${LIB_DIRECTORY}"

pwd

# pjsip
cd "${LIB_DIRECTORY}/pjsip"
if [ "${BUILD_ALL}" = true ] || [ "${BUILD_PJSIP}" = true ] ; then
        eval $TOUCH_COMMAND

        ./configure CFLAGS="${MAKEFLAGS} -I${OUT_PREFIX}/include" CXXFLAGS="${MAKEFLAGS}" LDFLAGS="-L${OUT_PREFIX}/lib" \
                --prefix="${OUT_PREFIX}" \
                --disable-openh264 \
                --disable-v4l2 \
                --disable-ffmpeg \
                --enable-libsamplerate \
                --disable-video \
                --enable-shared \
                --disable-static \
                --disable-libyuv \
                --with-external-speex \
                --with-gnutls \
                || exit

        if [ "${CLEAN_BEFORE_BUILD}" = true ] ; then
                make clean
        fi

        # Without this it breaks on msys2
        make -j $JOPT dep || exit
        # Make the actual
        make -j $JOPT || exit
        # Note, had issue with writing to //c/.../pkgconfig/libproject.pc
        make install || exit
fi

-- 
Michael A. Leonetti
As warm as green tea

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux