SRS 6.0-b0 源码 + danmaku 后端(排除 objs/3rdparty/测试媒体)

This commit is contained in:
RRRosmontis
2026-08-27 21:46:20 +08:00
commit 41b5da7c7e
578 changed files with 237858 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
/*
# see: https://ossrs.net/lts/zh-cn/docs/v4/doc/arm
g++ -g -O0 -o jmp jmp.cpp
arm-linux-gnueabi-g++ -o jmp jmp.cpp -static
arm-linux-gnueabi-strip jmp
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <setjmp.h>
bool func1_ok = false, func2_ok = false;
jmp_buf env_func1, env_func2;
int sum = 0;
void func1() {
int ret = setjmp(env_func1);
printf("[func1] setjmp ret=%d, sum++=%d\n", ret, sum++);
func1_ok = true;
sleep(1);
// jmp to func2
if (func2_ok) {
longjmp(env_func2, 1);
}
}
void func2() {
int ret = setjmp(env_func2);
printf("[func2] setjmp ret=%d, sum++=%d\n", ret, sum++);
func2_ok = true;
sleep(1);
// jmp to func1
if (func1_ok) {
longjmp(env_func1, 2);
}
}
int main(int argc, char** argv) {
printf("hello, setjmp/longjmp!\n");
func1();
func2();
printf("jmp finished, sum=%d\n", sum);
return 0;
}
+65
View File
@@ -0,0 +1,65 @@
/*
# http://blog.csdn.net/win_lin/article/details/40948277
# for all supports setjmp and longjmp:
g++ -g -O0 -o jmp_2flow jmp_2flow.cpp
*/
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf context_thread_0;
jmp_buf context_thread_1;
void thread0_functions()
{
int ret = setjmp(context_thread_0);
// when ret is 0, create thread,
// when ret is not 0, longjmp to this thread.
if (ret == 0) {
return;
}
int age = 10000;
const char* name = "winlin";
printf("[thread0] age=%d, name=%s\n", age, name);
if (!setjmp(context_thread_0)) {
printf("[thread0] switch to thread1\n");
longjmp(context_thread_1, 1);
}
// crash, for the stack is modified by thread1.
// name = 0x2b67004009c8 <error: Cannot access memory at address 0x2b67004009c8>
printf("[thread0] terminated, age=%d, name=%s\n", age, name);
exit(0);
}
void thread1_functions()
{
int ret = setjmp(context_thread_1);
// when ret is 0, create thread,
// when ret is not 0, longjmp to this thread.
if (ret == 0) {
return;
}
int age = 11111;
printf("[thread1] age=%d\n", age);
if (!setjmp(context_thread_1)) {
printf("[thread1] switch to thread0\n");
longjmp(context_thread_0, 1);
}
printf("[thread1] terminated, age=%d\n", age);
exit(0);
}
int main(int argc, char** argv)
{
thread0_functions();
thread1_functions();
// kickstart
longjmp(context_thread_0, 1);
return 0;
}
+28
View File
@@ -0,0 +1,28 @@
/*
# http://blog.csdn.net/win_lin/article/details/40948277
# for all supports setjmp and longjmp:
g++ -g -O0 -o jmp_flow jmp_flow.cpp
*/
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf context_level_0;
void func_level_0()
{
const char* level_0_0 = "stack variables for func_level_0";
int ret = setjmp(context_level_0);
printf("func_level_0 ret=%d\n", ret);
if (ret != 0) {
printf("call by longjmp.\n");
exit(0);
}
}
int main(int argc, char** argv)
{
func_level_0();
longjmp(context_level_0, 1);
return 0;
}
+137
View File
@@ -0,0 +1,137 @@
/*
# see: https://ossrs.net/lts/zh-cn/docs/v4/doc/arm
g++ -g -O0 -o jmp_sp jmp_sp.cpp
arm-linux-gnueabi-g++ -g -o jmp_sp jmp_sp.cpp -static
arm-linux-gnueabi-strip jmp_sp
*/
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf context;
void do_longjmp()
{
/**
the definition of jmp_buf:
typedef struct __jmp_buf_tag jmp_buf[1];
struct __jmp_buf_tag {
__jmp_buf __jmpbuf;
int __mask_was_saved;
__sigset_t __saved_mask;
};
*/
#if defined(__amd64__) || defined(__x86_64__)
// http://ftp.gnu.org/gnu/glibc/glibc-2.12.2.tar.xz
// http://ftp.gnu.org/gnu/glibc/glibc-2.12.1.tar.gz
/*
* Starting with glibc 2.4, JB_SP definitions are not public anymore.
* They, however, can still be found in glibc source tree in
* architecture-specific "jmpbuf-offsets.h" files.
* Most importantly, the content of jmp_buf is mangled by setjmp to make
* it completely opaque (the mangling can be disabled by setting the
* LD_POINTER_GUARD environment variable before application execution).
* Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore
* functions as a setjmp/longjmp replacement wherever they are available
* unless USE_LIBC_SETJMP is defined.
*/
// for glibc 2.4+, it's not possible to get and set the sp in jmp_buf
/**
for example, the following is show the jmp_buf when setjmp:
(gdb) x /64xb context[0].__jmpbuf
0x600ca0 <context>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x600ca8 <context+8>: 0xf8 0xc1 0x71 0xe5 0xa8 0x88 0xb4 0x15
0x600cb0 <context+16>: 0xa0 0x05 0x40 0x00 0x00 0x00 0x00 0x00
0x600cb8 <context+24>: 0x90 0xe4 0xff 0xff 0xff 0x7f 0x00 0x00
0x600cc0 <context+32>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x600cc8 <context+40>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x600cd0 <context+48>: 0xf8 0xc1 0x51 0xe5 0xa8 0x88 0xb4 0x15
0x600cd8 <context+56>: 0xf8 0xc1 0xd9 0x2f 0xd7 0x77 0x4b 0xea
(gdb) p /x $sp
$4 = 0x7fffffffe380
we cannot finger the sp out.
where the glibc is 2.12.
*/
register long int rsp0 asm("rsp");
int ret = setjmp(context);
printf("setjmp func0 ret=%d, rsp=%#lx\n", ret, rsp0);
printf("after setjmp: ");
for (int i = 0; i < 8; i++) {
printf("env[%d]=%#x, ", i, (int)context[0].__jmpbuf[i]);
}
printf("\n");
#endif
#if defined(__arm__)
/**
/usr/arm-linux-gnueabi/include/bits/setjmp.h
#ifndef _ASM
The exact set of registers saved may depend on the particular core
in use, as some coprocessor registers may need to be saved. The C
Library ABI requires that the buffer be 8-byte aligned, and
recommends that the buffer contain 64 words. The first 28 words
are occupied by v1-v6, sl, fp, sp, pc, d8-d15, and fpscr. (Note
that d8-15 require 17 words, due to the use of fstmx.)
typedef int __jmp_buf[64] __attribute__((__aligned__ (8)));
the layout of setjmp for arm:
0-5: v1-v6
6: sl
7: fp
8: sp
9: pc
10-26: d8-d15 17words
27: fpscr
*/
/**
For example, on raspberry-pi, armv6 cpu:
(gdb) x /64xb (char*)context[0].__jmpbuf
v1, 0: 0x00 0x00 0x00 0x00
v2, 1: 0x00 0x00 0x00 0x00
v3, 2: 0x2c 0x84 0x00 0x00
v4, 3: 0x00 0x00 0x00 0x00
v5, 4: 0x00 0x00 0x00 0x00
v6, 5: 0x00 0x00 0x00 0x00
sl, 6: 0x00 0xf0 0xff 0xb6
fp, 7: 0x9c 0xfb 0xff 0xbe
sp, 8: 0x88 0xfb 0xff 0xbe
pc, 9: 0x08 0x85 0x00 0x00
(gdb) p /x $sp
$5 = 0xbefffb88
(gdb) p /x $pc
$4 = 0x850c
*/
int ret = setjmp(context);
printf("setjmp func1 ret=%d\n", ret);
printf("after setjmp: ");
for (int i = 0; i < 64; i++) {
printf("env[%d]=%#x, ", i, (int)context[0].__jmpbuf[i]);
}
printf("func0 terminated\n");
#endif
}
int main(int argc, char** argv)
{
#if defined(__amd64__) || defined(__x86_64__)
printf("x86_64 sizeof(long int)=%d, sizeof(long)=%d, "
"sizeof(int)=%d, __WORDSIZE=%d, __GLIBC__=%d, __GLIBC_MINOR__=%d\n",
(int)sizeof(long int), (int)sizeof(long), (int)sizeof(int),
(int)__WORDSIZE, (int)__GLIBC__, (int)__GLIBC_MINOR__);
#else
printf("arm sizeof(long int)=%d, sizeof(long)=%d, "
"sizeof(int)=%d, __GLIBC__=%d,__GLIBC_MINOR__=%d\n",
(int)sizeof(long int), (int)sizeof(long), (int)sizeof(int),
(int)__GLIBC__, (int)__GLIBC_MINOR__);
#endif
do_longjmp();
printf("terminated\n");
return 0;
}
+48
View File
@@ -0,0 +1,48 @@
/**
g++ pipe_fds.cpp -g -O0 -o pipe_fds
About the limits:
[winlin@dev6 srs]$ ulimit -n
1024
[winlin@dev6 srs]$ sudo lsof -p 21182
pipe_fds 21182 winlin 0u CHR 136,4 0t0 7 /dev/pts/4
pipe_fds 21182 winlin 1u CHR 136,4 0t0 7 /dev/pts/4
pipe_fds 21182 winlin 2u CHR 136,4 0t0 7 /dev/pts/4
pipe_fds 21182 winlin 3r FIFO 0,8 0t0 464543 pipe
pipe_fds 21182 winlin 1021r FIFO 0,8 0t0 465052 pipe
pipe_fds 21182 winlin 1022w FIFO 0,8 0t0 465052 pipe
So, all fds can be open is <1024, that is, can open 1023 files.
The 0, 1, 2 is opened file, so can open 1023-3=1020files,
Where 1020/2=512, so we can open 512 pipes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main(int argc, char** argv)
{
if (argc <= 1) {
printf("Usage: %s <nb_pipes>\n"
" nb_pipes the pipes to open.\n"
"For example:\n"
" %s 1024\n", argv[0], argv[0]);
exit(-1);
}
int nb_pipes = ::atoi(argv[1]);
for (int i = 0; i < nb_pipes; i++) {
int fds[2];
if (pipe(fds) < 0) {
printf("failed to create pipe. i=%d, errno=%d(%s)\n",
i, errno, strerror(errno));
break;
}
}
printf("Press CTRL+C to quit, use bellow command to show the fds opened:\n");
printf(" sudo lsof -p %d\n", getpid());
sleep(-1);
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
/*
# see: https://ossrs.net/lts/zh-cn/docs/v4/doc/arm
arm-linux-gnueabi-g++ -o test test.cpp -static
arm-linux-gnueabi-strip test
*/
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello, arm!\n");
return 0;
}