Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ASP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
j2-tulloch
ASP
Commits
c40459d5
Commit
c40459d5
authored
1 year ago
by
j2-tulloch
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
3b95cd0e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment/FiberFooGoo.cpp
+38
-0
38 additions, 0 deletions
Assignment/FiberFooGoo.cpp
with
38 additions
and
0 deletions
Assignment/FiberFooGoo.cpp
0 → 100644
+
38
−
0
View file @
c40459d5
#include
<iostream>
#include
<array>
#include
"context.h"
void
foo
()
{
std
::
cout
<<
"you called foo"
<<
std
::
endl
;
exit
(
0
);
// Exit to prevent returning to a different stack
}
void
goo
()
{
std
::
cout
<<
"you called goo"
<<
std
::
endl
;
exit
(
0
);
}
int
main
()
{
// Allocate space for stacks
std
::
array
<
char
,
4096
>
stackFoo
,
stackGoo
;
// Set up stack pointers, aligned to 16 bytes and accounting for the Red Zone
char
*
spFoo
=
reinterpret_cast
<
char
*>
((
reinterpret_cast
<
uintptr_t
>
(
stackFoo
.
data
()
+
4096
)
&
-
16L
)
-
128
);
char
*
spGoo
=
reinterpret_cast
<
char
*>
((
reinterpret_cast
<
uintptr_t
>
(
stackGoo
.
data
()
+
4096
)
&
-
16L
)
-
128
);
Context
cFoo
,
cGoo
;
// Set up contexts
get_context
(
&
cFoo
);
cFoo
.
rip
=
reinterpret_cast
<
void
*>
(
&
foo
);
cFoo
.
rsp
=
spFoo
;
get_context
(
&
cGoo
);
cGoo
.
rip
=
reinterpret_cast
<
void
*>
(
&
goo
);
cGoo
.
rsp
=
spGoo
;
// Use set_context to switch to either foo or goo
set_context
(
&
cFoo
);
// This will transfer control to foo
return
0
;
// Return an integer from main
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment