forked from mtl1979/Bittorium
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
2,052 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers | ||
// Copyright (c) 2022-2024, The Talleo developers | ||
// | ||
// This file is part of Karbo. | ||
// | ||
// Karbo is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Karbo is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Karbo. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include <string.h> | ||
#include <sys/types.h> | ||
#include "Context.h" | ||
|
||
void | ||
makecontext(uctx *ucp, void (*func)(void), intptr_t arg) | ||
{ | ||
long *sp; | ||
|
||
memset(&ucp->uc_mcontext, 0, sizeof ucp->uc_mcontext); | ||
ucp->uc_mcontext.mc_rdi = (long)arg; | ||
sp = (long*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/sizeof(long); | ||
sp -= 1; | ||
sp = (void*)((uintptr_t)sp - (uintptr_t)sp%16); /* 16-align for OS X */ | ||
*--sp = 0; /* return address */ | ||
ucp->uc_mcontext.mc_rip = (long)func; | ||
ucp->uc_mcontext.mc_rsp = (long)sp; | ||
} | ||
|
||
int | ||
swapcontext(uctx *oucp, const uctx *ucp) | ||
{ | ||
if(getcontext(oucp) == 0) | ||
setcontext(ucp); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers | ||
// | ||
// This file is part of Karbo. | ||
// | ||
// Karbo is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Karbo is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Karbo. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#pragma once | ||
|
||
#define setcontext(u) _setmcontext(&(u)->uc_mcontext) | ||
#define getcontext(u) _getmcontext(&(u)->uc_mcontext) | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
|
||
typedef struct mcontext mctx; | ||
typedef struct ucontext uctx; | ||
|
||
extern int swapcontext(uctx*, const uctx*); | ||
extern void makecontext(uctx*, void(*)(void), intptr_t); | ||
extern int _getmcontext(mctx*); | ||
extern void _setmcontext(const mctx*); | ||
|
||
struct mcontext { | ||
/* | ||
* The first 20 fields must match the definition of | ||
* sigcontext. So that we can support sigcontext | ||
* and ucontext_t at the same time. | ||
*/ | ||
long mc_onstack; /* XXX - sigcontext compat. */ | ||
long mc_rdi; /* machine state (struct trapframe) */ | ||
long mc_rsi; | ||
long mc_rdx; | ||
long mc_rcx; | ||
long mc_r8; | ||
long mc_r9; | ||
long mc_rax; | ||
long mc_rbx; | ||
long mc_rbp; | ||
long mc_r10; | ||
long mc_r11; | ||
long mc_r12; | ||
long mc_r13; | ||
long mc_r14; | ||
long mc_r15; | ||
long mc_trapno; | ||
long mc_addr; | ||
long mc_flags; | ||
long mc_err; | ||
long mc_rip; | ||
long mc_cs; | ||
long mc_rflags; | ||
long mc_rsp; | ||
long mc_ss; | ||
|
||
long mc_len; /* sizeof(mcontext_t) */ | ||
#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ | ||
#define _MC_FPFMT_XMM 0x10002 | ||
long mc_fpformat; | ||
#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ | ||
#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ | ||
#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ | ||
long mc_ownedfp; | ||
/* | ||
* See <machine/fpu.h> for the internals of mc_fpstate[]. | ||
*/ | ||
long mc_fpstate[64]; | ||
long mc_spare[8]; | ||
}; | ||
|
||
struct ucontext { | ||
/* | ||
* Keep the order of the first two fields. Also, | ||
* keep them the first two fields in the structure. | ||
* This way we can have a union with struct | ||
* sigcontext and ucontext_t. This allows us to | ||
* support them both at the same time. | ||
* note: the union is not defined, though. | ||
*/ | ||
sigset_t uc_sigmask; | ||
mctx uc_mcontext; | ||
|
||
struct __ucontext *uc_link; | ||
stack_t uc_stack; | ||
int __spare__[8]; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.