ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.7k stars 5.38k forks source link

In the Alpine image, when compiling SRS with musl, the st-thread crashes. #3222

Closed qiantaossx closed 2 years ago

qiantaossx commented 2 years ago

Description

The image based on Ubuntu is too large, so I plan to run SRS on Alpine and make adaptations. After successful compilation, when starting SRS, it crashes in the st coroutine after the first call to st_thread_create to create a coroutine.

The crash occurs in the st_thread_create function. memset(ptds, 0, ST_KEYS_MAX sizeof(void ));

Below is the structure in setjmp.h that SRS depends on. Some adaptations were made during the compilation process.

struct __jmp_buf_tag
  {
    /* NOTE: The machine-dependent definitions of `__sigsetjmp'
       assume that a `jmp_buf' begins with a `__jmp_buf' and that
       `__mask_was_saved' follows it.  Do not move these members
       or add others before it.  */
    __jmp_buf __jmpbuf;     /* Calling environment.  */
    int __mask_was_saved;   /* Saved the signal mask?  */
    __sigset_t __saved_mask;    /* Saved signal mask.  */
  };

Below is the structure in setjmp.h in Alpine.

typedef struct __jmp_buf_tag {
    __jmp_buf __jb;
    unsigned long __fl;
    unsigned long __ss[128/sizeof(long)];
} jmp_buf[1];
  1. SRS Version: v4.0.198

The above are the issues encountered during the process of using the Alpine image. If possible, I would like to submit a PR with the compilation script and modifications in the ST thread. Could you please take a look? Thank you very much.

Additionally, since the Ubuntu image is quite large, if there is a need to reduce the Docker image size, I would like to ask for suggestions on what other solutions can be used?

TRANS_BY_GPT3

qiantaossx commented 2 years ago

Update it:

The dependency of srs is the st-thread coroutine library.

The following 2 lines of code in the skt.c file: mprotect(ts->vaddr, REDZONE, PROT_NONE); mprotect(ts->stk_top + extra, REDZONE, PROT_NONE);

This will cause the sched.c file to... memset(ptds, 0, ST_KEYS_MAX sizeof(void )); crash

The alpine code segment may have compatibility issues. Commenting out this memory protection function will allow it to run normally.

Also, may I ask what is the purpose of these two lines of code? Thank you.

TRANS_BY_GPT3

winlinvip commented 2 years ago

Regarding the jmpbuf of ST, it is only related to the system+CPU architecture. This part of the code has already been modified in version 5.0, resolving this issue. Please avoid duplicating the work.

If you want to use Alpine, you can also compile the binary using Ubuntu or CentOS and then directly copy it to Alpine, instead of installing various tools and compiling SRS on Alpine. This can be achieved using Docker's multi-stage capability.

You can refer to SRS's docker file, which also uses multi-stage compilation.

TRANS_BY_GPT3