util: refactor misc utility stuff

This commit is contained in:
anna 2021-09-21 17:34:27 +02:00
parent 623daf58ed
commit 2a0ed8121a
Signed by: fef
GPG key ID: EC22E476DC2D3D84
7 changed files with 106 additions and 37 deletions

29
kernel/util.c Normal file
View file

@ -0,0 +1,29 @@
/* See the end of this file for copyright and license terms. */
#include <gay/types.h>
#include <gay/util.h>
void *ptr_align(void *ptr, int log)
{
uintptr_t shifted = 1 << abs(log);
uintptr_t aligned = (uintptr_t)ptr & ~(shifted - 1);
if (log > 0 && aligned != (uintptr_t)ptr)
aligned += shifted;
return (void *)aligned;
}
/*
* This file is part of GayBSD.
* Copyright (c) 2021 fef <owo@fef.moe>.
*
* GayBSD is nonviolent software: you may only use, redistribute, and/or
* modify it under the terms of the Cooperative Nonviolent Public License
* (CNPL) as found in the LICENSE file in the source code root directory
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
* of the license, or (at your option) any later version.
*
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPL for details.
*/