Ruby
2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
coroutine
win32
Context.h
Go to the documentation of this file.
1
/*
2
* This file is part of the "Coroutine" project and released under the MIT License.
3
*
4
* Created by Samuel Williams on 10/5/2018.
5
* Copyright, 2018, by Samuel Williams. All rights reserved.
6
*/
7
8
#pragma once
9
10
#include <
assert.h
>
11
#include <string.h>
12
13
#define COROUTINE __declspec(noreturn) void __fastcall
14
#define COROUTINE_LIMITED_ADDRESS_SPACE
15
16
/* This doesn't include thread information block */
17
enum
{
COROUTINE_REGISTERS
= 4};
18
19
struct
coroutine_context
20
{
21
void
**
stack_pointer
;
22
};
23
24
typedef
void
(
__fastcall
*
coroutine_start
)(
struct
coroutine_context
*
from
,
struct
coroutine_context
*
self
);
25
26
static
inline
void
coroutine_initialize_main(
struct
coroutine_context
* context) {
27
context->
stack_pointer
=
NULL
;
28
}
29
30
static
inline
void
coroutine_initialize(
31
struct
coroutine_context
*context,
32
coroutine_start
start,
33
void
*
stack
,
34
size_t
size
35
) {
36
assert
(start &&
stack
&&
size
>= 1024);
37
38
// Stack grows down. Force 16-byte alignment.
39
char
*
top
= (
char
*)
stack
+
size
;
40
context->
stack_pointer
= (
void
**)((
uintptr_t
)
top
& ~0xF);
41
42
*--context->
stack_pointer
= (
void
*)start;
43
44
/* Windows Thread Information Block */
45
*--context->
stack_pointer
= (
void
*)0xFFFFFFFF;
/* fs:[0] */
46
*--context->
stack_pointer
= (
void
*)
top
;
/* fs:[4] */
47
*--context->
stack_pointer
= (
void
*)
stack
;
/* fs:[8] */
48
49
context->
stack_pointer
-=
COROUTINE_REGISTERS
;
50
memset
(context->
stack_pointer
, 0,
sizeof
(
void
*) *
COROUTINE_REGISTERS
);
51
}
52
53
struct
coroutine_context
*
__fastcall
coroutine_transfer
(
struct
coroutine_context
* current,
struct
coroutine_context
* target);
54
55
static
inline
void
coroutine_destroy(
struct
coroutine_context
* context)
56
{
57
}
coroutine_start
COROUTINE(* coroutine_start)(struct coroutine_context *from, struct coroutine_context *self)
Definition:
Context.h:22
coroutine_transfer
struct coroutine_context * coroutine_transfer(struct coroutine_context *current, struct coroutine_context *target)
Definition:
Context.c:136
COROUTINE_REGISTERS
@ COROUTINE_REGISTERS
Definition:
Context.h:15
assert.h
top
unsigned int top
Definition:
nkf.c:4323
NULL
#define NULL
Definition:
rb_mjit_min_header-2.7.7.h:11172
__fastcall
#define __fastcall
Definition:
rb_mjit_min_header-2.7.7.h:754
memset
void * memset(void *, int, size_t)
size
unsigned int size
uintptr_t
__uintptr_t uintptr_t
Definition:
rb_mjit_min_header-2.7.7.h:1210
void
void
Definition:
rb_mjit_min_header-2.7.7.h:13382
assert
#define assert
Definition:
rb_mjit_min_header-2.7.7.h:9036
coroutine_context
Definition:
Context.h:18
coroutine_context::from
struct coroutine_context * from
Definition:
Context.h:37
coroutine_context::stack_pointer
void ** stack_pointer
Definition:
Context.h:19
coroutine_context::stack
void * stack
Definition:
Context.h:29
Generated by
1.9.2