This reverts commit 34344982a9
.
This commit is contained in:
1
programs/bpf/c/.gitignore
vendored
Normal file
1
programs/bpf/c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/out/
|
2
programs/bpf/c/makefile
Normal file
2
programs/bpf/c/makefile
Normal file
@ -0,0 +1,2 @@
|
||||
BPF_SDK := ../../../sdk/bpf
|
||||
include $(BPF_SDK)/bpf.mk
|
30
programs/bpf/c/src/bench_alu/bench_alu.c
Normal file
30
programs/bpf/c/src/bench_alu/bench_alu.c
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @brief Benchmark program that does work
|
||||
*
|
||||
* Counts Armstrong Numbers between 1 and x
|
||||
*/
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
uint64_t x = *(uint64_t *) input;
|
||||
uint64_t *result = (uint64_t *) input + 1;
|
||||
uint64_t count = 0;
|
||||
|
||||
for (int i = 1; i <= x; i++) {
|
||||
uint64_t temp = i;
|
||||
uint64_t num = 0;
|
||||
while (temp != 0) {
|
||||
uint64_t rem = (temp % 10);
|
||||
num += rem * rem * rem;
|
||||
temp /= 10;
|
||||
}
|
||||
if (i == num) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
sol_log_64(x, count, 0, 0, 0);
|
||||
*result = count;
|
||||
return true;
|
||||
}
|
11
programs/bpf/c/src/bench_alu/test_bench_alu.c
Normal file
11
programs/bpf/c/src/bench_alu/test_bench_alu.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <criterion/criterion.h>
|
||||
#include "bench_alu.c"
|
||||
|
||||
Test(bench_alu, sanity) {
|
||||
uint64_t input[] = {500, 0};
|
||||
|
||||
cr_assert(entrypoint((uint8_t *) input));
|
||||
|
||||
cr_assert_eq(input[0], 500);
|
||||
cr_assert_eq(input[1], 5);
|
||||
}
|
14
programs/bpf/c/src/bpf_to_bpf/entrypoint.c
Normal file
14
programs/bpf/c/src/bpf_to_bpf/entrypoint.c
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @brief Example C-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
sol_log(__FILE__);
|
||||
helper_function();
|
||||
sol_log(__FILE__);
|
||||
return true;
|
||||
}
|
11
programs/bpf/c/src/bpf_to_bpf/helper.c
Normal file
11
programs/bpf/c/src/bpf_to_bpf/helper.c
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @brief Example C-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
void helper_function(void) {
|
||||
sol_log(__FILE__);
|
||||
}
|
7
programs/bpf/c/src/bpf_to_bpf/helper.h
Normal file
7
programs/bpf/c/src/bpf_to_bpf/helper.h
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @brief Example C-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
void helper_function(void);
|
36
programs/bpf/c/src/move_funds/move_funds.c
Normal file
36
programs/bpf/c/src/move_funds/move_funds.c
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @brief Example C-based BPF program that moves funds from one account to
|
||||
* another
|
||||
*/
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
/**
|
||||
* Number of SolKeyedAccount expected. The program should bail if an
|
||||
* unexpected number of accounts are passed to the program's entrypoint
|
||||
*/
|
||||
#define NUM_KA 3
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[NUM_KA];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!params.ka[0].is_signer) {
|
||||
sol_log("Transaction not signed by key 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t lamports = *(int64_t *)params.data;
|
||||
if (*params.ka[0].lamports >= lamports) {
|
||||
*params.ka[0].lamports -= lamports;
|
||||
*params.ka[2].lamports += lamports;
|
||||
// sol_log_64(0, 0, *ka[0].lamports, *ka[2].lamports, lamports);
|
||||
} else {
|
||||
// sol_log_64(0, 0, 0xFF, *ka[0].lamports, lamports);
|
||||
}
|
||||
return true;
|
||||
}
|
10
programs/bpf/c/src/multiple_static/multiple_static.c
Normal file
10
programs/bpf/c/src/multiple_static/multiple_static.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <solana_sdk.h>
|
||||
|
||||
static const char msg[] = "This is a message";
|
||||
static const char msg2[] = "This is a different message";
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
sol_log((char*)msg);
|
||||
sol_log((char*)msg2);
|
||||
return true;
|
||||
}
|
22
programs/bpf/c/src/noop++/noop++.cc
Normal file
22
programs/bpf/c/src/noop++/noop++.cc
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @brief Example C++-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[1];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log the provided input parameters. In the case of the no-op
|
||||
// program, no account keys or input data are expected but real
|
||||
// programs will have specific requirements so they can do their work.
|
||||
sol_log_params(¶ms);
|
||||
return true;
|
||||
}
|
23
programs/bpf/c/src/noop/noop.c
Normal file
23
programs/bpf/c/src/noop/noop.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @brief Example C-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
SolKeyedAccount ka[1];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log the provided input parameters. In the case of the no-op
|
||||
// program, no account keys or input data are expected but real
|
||||
// programs will have specific requirements so they can do their work.
|
||||
sol_log_params(¶ms);
|
||||
return true;
|
||||
}
|
||||
|
16
programs/bpf/c/src/relative_call/relative_call.c
Normal file
16
programs/bpf/c/src/relative_call/relative_call.c
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @brief test program that generates BPF PC relative call instructions
|
||||
*/
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
void __attribute__ ((noinline)) helper() {
|
||||
sol_log(__func__);
|
||||
}
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
sol_log(__func__);
|
||||
helper();
|
||||
return true;
|
||||
}
|
||||
|
17
programs/bpf/c/src/struct_pass/struct_pass.c
Normal file
17
programs/bpf/c/src/struct_pass/struct_pass.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <solana_sdk.h>
|
||||
|
||||
struct foo {const uint8_t *input;};
|
||||
void foo(const uint8_t *input, struct foo foo) ;
|
||||
|
||||
extern bool entrypoint(const uint8_t *input) {
|
||||
struct foo f;
|
||||
f.input = input;
|
||||
foo(input, f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void foo(const uint8_t *input, struct foo foo) {
|
||||
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
|
||||
sol_assert(input == foo.input);
|
||||
}
|
||||
|
21
programs/bpf/c/src/struct_ret/struct_ret.c
Normal file
21
programs/bpf/c/src/struct_ret/struct_ret.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <solana_sdk.h>
|
||||
|
||||
struct test_struct { uint64_t x; uint64_t y; uint64_t z;};
|
||||
|
||||
static struct test_struct __attribute__ ((noinline)) test_function(void) {
|
||||
struct test_struct s;
|
||||
s.x = 3;
|
||||
s.y = 4;
|
||||
s.z = 5;
|
||||
return s;
|
||||
}
|
||||
|
||||
extern bool entrypoint(const uint8_t* input) {
|
||||
struct test_struct s = test_function();
|
||||
sol_log("foobar");
|
||||
if (s.x + s.y + s.z == 12 ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user