mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
update the research of arm
This commit is contained in:
parent
0f41e0d26f
commit
1db69b153e
2 changed files with 111 additions and 34 deletions
|
@ -1,48 +1,48 @@
|
||||||
/*
|
/*
|
||||||
# see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm
|
# see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm
|
||||||
|
g++ -g -O0 -o jmp jmp.cpp
|
||||||
arm-linux-gnueabi-g++ -o jmp jmp.cpp -static
|
arm-linux-gnueabi-g++ -o jmp jmp.cpp -static
|
||||||
arm-linux-gnueabi-strip jmp
|
arm-linux-gnueabi-strip jmp
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
bool func1_ok = false, func2_ok = false;
|
||||||
jmp_buf env_func1, env_func2;
|
jmp_buf env_func1, env_func2;
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
void func1() {
|
void func1() {
|
||||||
int ret = setjmp(env_func1);
|
int ret = setjmp(env_func1);
|
||||||
printf("setjmp func1 ret=%d\n", ret);
|
printf("[func1] setjmp ret=%d, sum++=%d\n", ret, sum++);
|
||||||
|
func1_ok = true;
|
||||||
|
|
||||||
if (sum <= 0) {
|
sleep(1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sum++ > 1000) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// jmp to func2
|
// jmp to func2
|
||||||
longjmp(env_func2, 3);
|
if (func2_ok) {
|
||||||
|
longjmp(env_func2, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void func2() {
|
void func2() {
|
||||||
int ret = setjmp(env_func2);
|
int ret = setjmp(env_func2);
|
||||||
printf("setjmp func2 ret=%d\n", ret);
|
printf("[func2] setjmp ret=%d, sum++=%d\n", ret, sum++);
|
||||||
|
func2_ok = true;
|
||||||
|
|
||||||
if (sum <= 0) {
|
sleep(1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// jmp to func1
|
// jmp to func1
|
||||||
|
if (func1_ok) {
|
||||||
longjmp(env_func1, 2);
|
longjmp(env_func1, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
printf("hello, setjmp/longjmp!\n");
|
printf("hello, setjmp/longjmp!\n");
|
||||||
func1();
|
func1();
|
||||||
sum++;
|
|
||||||
func2();
|
func2();
|
||||||
printf("jmp finished, sum=%d\n", sum);
|
printf("jmp finished, sum=%d\n", sum);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
# see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm
|
# see: https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_SrsLinuxArm
|
||||||
|
g++ -g -O0 -o jmp_sp jmp_sp.cpp
|
||||||
arm-linux-gnueabi-g++ -g -o jmp_sp jmp_sp.cpp -static
|
arm-linux-gnueabi-g++ -g -o jmp_sp jmp_sp.cpp -static
|
||||||
arm-linux-gnueabi-strip jmp_sp
|
arm-linux-gnueabi-strip jmp_sp
|
||||||
*/
|
*/
|
||||||
|
@ -7,33 +8,109 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
jmp_buf env_func1;
|
||||||
|
|
||||||
|
void func1()
|
||||||
|
{
|
||||||
#if defined(__amd64__) || defined(__x86_64__)
|
#if defined(__amd64__) || defined(__x86_64__)
|
||||||
printf("x86_64 sizeof(long int)=%d, sizeof(long)=%d, sizeof(int)=%d\n", (int)sizeof(long int), (int)sizeof(long), (int)sizeof(int));
|
register long int rsp0 asm("rsp");
|
||||||
#else
|
printf("in func1, rsp=%#lx, longjmp to func0\n", rsp0);
|
||||||
printf("arm sizeof(long int)=%d, sizeof(long)=%d, sizeof(int)=%d\n", (int)sizeof(long int), (int)sizeof(long), (int)sizeof(int));
|
|
||||||
|
longjmp(env_func1, 0x101);
|
||||||
|
|
||||||
|
printf("func1 terminated\n");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
jmp_buf env;
|
void func0(int* pv0, int* pv1)
|
||||||
|
{
|
||||||
int ret = setjmp(env);
|
/**
|
||||||
printf("setjmp func1 ret=%d\n", ret);
|
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__)
|
#if defined(__amd64__) || defined(__x86_64__)
|
||||||
// typedef lint64_t __jmp_buf[8];
|
/**
|
||||||
|
here, the __jmp_buf is 8*8=64 bytes
|
||||||
|
# if __WORDSIZE == 64
|
||||||
|
typedef long int __jmp_buf[8];
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
the layout for setjmp of x86_64
|
||||||
|
#
|
||||||
|
# The jmp_buf is assumed to contain the following, in order:
|
||||||
|
# %rbx
|
||||||
|
# %rsp (post-return)
|
||||||
|
# %rbp
|
||||||
|
# %r12
|
||||||
|
# %r13
|
||||||
|
# %r14
|
||||||
|
# %r15
|
||||||
|
# <return address>
|
||||||
|
#
|
||||||
|
*/
|
||||||
|
register long int rsp0 asm("rsp");
|
||||||
|
|
||||||
|
int ret = setjmp(env_func1);
|
||||||
|
printf("setjmp func0 ret=%d, rsp=%#lx\n", ret, rsp0);
|
||||||
|
|
||||||
printf("after setjmp: ");
|
printf("after setjmp: ");
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
printf("env[%d]=%#x, ", i, (int)env[0].__jmpbuf[i]);
|
printf("env[%d]=%#x, ", i, (int)env_func1[0].__jmpbuf[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#else
|
#else
|
||||||
// typedef int32_t __jmp_buf[64] __attribute__((__aligned__ (8)));
|
/**
|
||||||
|
/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
|
||||||
|
*/
|
||||||
|
int ret = setjmp(env_func1);
|
||||||
|
printf("setjmp func1 ret=%d\n", ret);
|
||||||
|
|
||||||
printf("after setjmp: ");
|
printf("after setjmp: ");
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
printf("env[%d]=%#x, ", i, (int)env[0].__jmpbuf[i]);
|
printf("env[%d]=%#x, ", i, (int)env_func1[0].__jmpbuf[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
|
printf("func0 terminated\n");
|
||||||
#endif
|
#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\n",
|
||||||
|
(int)sizeof(long int), (int)sizeof(long), (int)sizeof(int), (int)__WORDSIZE);
|
||||||
|
#else
|
||||||
|
printf("arm sizeof(long int)=%d, sizeof(long)=%d, sizeof(int)=%d\n",
|
||||||
|
(int)sizeof(long int), (int)sizeof(long), (int)sizeof(int));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int pv0 = 0xf0;
|
||||||
|
int pv1 = 0xf1;
|
||||||
|
func0(&pv0, &pv1);
|
||||||
|
func1();
|
||||||
|
|
||||||
|
printf("terminated\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue