Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coro alignment #232

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion libs/coroutine/source/Coro.c
Expand Up @@ -85,6 +85,14 @@ Coro *Coro_new(void)
return self;
}

// Returns a size that corresponds to `size` aligned on `alignment` bounds
static inline size_t aligned_size(size_t size, size_t alignment)
{
assert(alignment <= 0x8000);
size_t r = size + --alignment + 2;
return (r + 2 + alignment) & ~alignment;
}

#ifndef USE_FIBERS
void Coro_allocStackIfNeeded(Coro *self)
{
Expand Down Expand Up @@ -599,7 +607,7 @@ void Coro_setup(Coro *self, void *arg)
if (64 > (- sav[i] + (uintptr_t)&i))
break;
assert(i < sz);
sav[i] = stackend - sizeof(uintptr_t) - 128;
sav[i] = aligned_size(stackend - sizeof(uintptr_t) - 128, 16);
}
}

Expand Down