Skip to content

Commit

Permalink
OSX: Refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 1, 2021
1 parent f9ea8a1 commit bb94c45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions tools/porting/porting.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void print_jmpbuf()
} jmp_buf[1];
*/
jmp_buf ctx = {0};
if (!setjmp(ctx)) {
int r0 = setjmp(ctx);
if (!r0) {
longjmp(ctx, 1);
}

Expand Down Expand Up @@ -118,11 +119,14 @@ void print_jmpbuf()
__asm__ __volatile__ ("movq %%r15,%0": "=r"(r15): /* No input */);
__asm__ __volatile__ ("movq %%rsp,%0": "=r"(rsp): /* No input */);

printf("rbx=%p, rbp=%p,%p, r12=%p, r13=%p, r14=%p, r15=%p, rsp=%p\n",
rbx, rbp, rbp2, r12, r13, r14, r15, rsp);
printf("rbx=%p, rbp=%p, r12=%p, r13=%p, r14=%p, r15=%p, rsp=%p\n",
rbx, rbp, r12, r13, r14, r15, rsp);

jmp_buf ctx = {0};
setjmp(ctx);
int r0 = setjmp(ctx);
if (!r0) {
longjmp(ctx, 1);
}

int nn_jb = sizeof(ctx);
printf("sizeof(jmp_buf)=%d (unsigned long long [%d])\n", nn_jb, nn_jb/8);
Expand Down
9 changes: 6 additions & 3 deletions tools/verify/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ void verify_jmpbuf()
__asm__ __volatile__ ("movq %%r15,%0": "=r"(r15): /* No input */);
__asm__ __volatile__ ("movq %%rsp,%0": "=r"(rsp): /* No input */);

printf("rbx=%p, rbp=%p,%p, r12=%p, r13=%p, r14=%p, r15=%p, rsp=%p\n",
rbx, rbp, rbp2, r12, r13, r14, r15, rsp);
printf("rbx=%p, rbp=%p, r12=%p, r13=%p, r14=%p, r15=%p, rsp=%p\n",
rbx, rbp, r12, r13, r14, r15, rsp);

jmp_buf ctx = {0};
_st_md_cxt_save(ctx);
int r0 = _st_md_cxt_save(ctx);
if (!r0) {
_st_md_cxt_restore(ctx, 1); // Restore/Jump to previous line, set r0 to 1.
}

int nn_jb = sizeof(ctx);
printf("sizeof(jmp_buf)=%d (unsigned long long [%d])\n", nn_jb, nn_jb/8);
Expand Down

0 comments on commit bb94c45

Please sign in to comment.