Skip to content

Instantly share code, notes, and snippets.

diff --git a/libs/context/src/asm/fcontext_i386_sysv_elf_gas.S b/libs/context/src/asm/fcontext_i386_sysv_elf_gas.S
index ee27876..25c3339 100644
--- a/libs/context/src/asm/fcontext_i386_sysv_elf_gas.S
+++ b/libs/context/src/asm/fcontext_i386_sysv_elf_gas.S
@@ -86,9 +86,13 @@ boost_fcontext_make:
movl %ecx, 0x14(%eax) /* save the address of the function supposed to run */
movl 0x20(%eax), %edx /* load the stack base */
+ pushl %ebx
pushl %eax /* save pointer to fcontext_t */
@kikairoya
kikairoya / seh.cc
Last active December 10, 2022 15:19
SEH for gcc
/*
Copyright (c) 2012- kikairoya
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
@kikairoya
kikairoya / gthr-win32-gcc471.patch
Created January 22, 2012 10:10
implement condition-variable to gthr-win32 needed for std::thread family. modify from gcc-4.7.0.
diff --git a/libgcc/config/i386/gthr-win32.c b/libgcc/config/i386/gthr-win32.c
index ab1b69f..4b35582 100644
--- a/libgcc/config/i386/gthr-win32.c
+++ b/libgcc/config/i386/gthr-win32.c
@@ -1,11 +1,13 @@
/* Implementation of W32-specific threads compatibility routines for
libgcc2. */
-/* Copyright (C) 1999, 2000, 2002, 2004, 2008, 2009, 2011
+/* Copyright (C) 1999, 2000, 2002, 2004, 2008, 2009, 2011, 2012
#include <iostream>
#include <thread>
#include <future>
#include <chrono>
#include <functional>
#include <deque>
struct task_queue {
task_queue() = default;
task_queue(const task_queue &) = delete;
#ifdef __GNUG__
#include <cxxabi.h>
std::string demangle(const std::string &s) {
int r;
char *const p = abi::__cxa_demangle(s.c_str(), 0, 0, &r);
if (r) return s;
try {
const std::string x(p);
free(p);
p = 0;
#include <array>
#include <type_traits>
template <typename T, std::size_t N>
constexpr std::size_t size(const std::array<T, N> &a) { return a.size(); }
template <typename A> // テンプレートでなくても同じ
void f(const A &a) {
char x[a.size()]; // VLA扱いされる。std::array::size()はconstexprになっている
char y[size(a)]; // 一段噛ませると通る
#include <vector>
class myclass{
public:
myclass(const std::vector<int>&){
throw std::exception();
}
private:
myclass() = delete;
};
@kikairoya
kikairoya / string_piece.hpp
Created October 14, 2011 06:32
string_piece
#include <string>
#include <iterator>
template <typename charT>
class basic_string_piece {
public:
typedef std::char_traits<charT> trait_type;
typedef typename trait_type::char_type char_type;
typedef const char_type *const_pointer;
typedef const char_type &const_reference;
@kikairoya
kikairoya / stdin_stream.hpp
Created April 9, 2011 03:47
boost::asio AsyncReadStream for console input
class stdin_stream: boost::noncopyable {
typedef boost::function<void (const boost::system::error_code &, size_t bytes_transferred)> read_handler_type;
public:
stdin_stream(boost::asio::io_service &io, HANDLE hin): io(io), hin(hin), hev(CreateEvent(0, 0, 0, 0)), handler(), buffer(0), size(0) {
_beginthread(&stdin_stream::thread_handler_gateway, 0, this);
}
~stdin_stream() {
buffer = 0;
CloseHandle(hev);
}
@kikairoya
kikairoya / asio_range_util.hpp
Created April 7, 2011 05:11
asio http client without istream
#ifndef ASIO_RANGE_UTIL_HPP_
#define ASIO_RANGE_UTIL_HPP_
#include <boost/range/iterator_range.hpp>
#include <boost/range/algorithm/search.hpp>
#include <boost/asio/buffer.hpp>
namespace httpc {
template <typename T>
inline boost::iterator_range<T *> make_iterator_range_from_memory(T *head, size_t size) {