Skip to content

Instantly share code, notes, and snippets.

@Const-me Const-me/fibersTest.cpp
Last active Oct 24, 2018

What would you like to do?
#define NOMINMAX
#include <windows.h>
#include <stdio.h>
#include <stdint.h>
#include <array>
#include <algorithm>
void printStack( const char* what )
ULONG_PTR lo, high;
GetCurrentThreadStackLimits( &lo, &high );
printf( "%s: %p - %p\n", what, lo, high );
void* fiberMain, *fiberSecondary;
constexpr size_t cbBuffer = 24;
void __stdcall fiberProc( void* lpFiberParameter )
std::array<uint8_t, cbBuffer> localBuffer;
std::copy_n( (const uint8_t*)lpFiberParameter, cbBuffer, localBuffer.begin() );
printStack( "fiber" );
SwitchToFiber( fiberMain );
int main()
printStack( "start" );
std::array<uint8_t, cbBuffer> localBuffer = { 0x4e, 0x65, 0x76, 0x65, 0x72, 0x20, 0x67, 0x6f, 0x6e, 0x6e, 0x61, 0x20, 0x67, 0x69, 0x76, 0x65, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x70, 0x2c };
fiberMain = ConvertThreadToFiber( nullptr );
fiberSecondary = CreateFiber( 0, &fiberProc, );
printStack( "converted" );
SwitchToFiber( fiberSecondary );
printStack( "back to main" );
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.