1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/kernel/kernelinfo.cpp

62 lines
1.9 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2012, 2015 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* kernelinfo.cpp
* Lets user-space query information about the kernel.
*/
2013-07-10 15:37:07 -04:00
#include <brand.h>
#include <errno.h>
#include <sortix/kernel/copy.h>
2013-10-26 20:42:10 -04:00
#include <sortix/kernel/kernel.h>
2013-01-08 18:41:35 -05:00
#include <sortix/kernel/syscall.h>
#ifndef VERSIONSTR
#define VERSIONSTR "unknown"
#endif
namespace Sortix {
static const char* KernelInfo(const char* req)
{
2013-07-10 15:37:07 -04:00
if ( strcmp(req, "name") == 0 ) { return BRAND_KERNEL_NAME; }
if ( strcmp(req, "version") == 0 ) { return VERSIONSTR; }
2015-04-25 17:39:21 -04:00
if ( strcmp(req, "tagline") == 0 ) { return BRAND_RELEASE_TAGLINE; }
if ( strcmp(req, "builddate") == 0 ) { return __DATE__; }
if ( strcmp(req, "buildtime") == 0 ) { return __TIME__; }
2015-10-30 13:10:34 -04:00
#if defined(__i386__) || defined(__x86_64__)
if ( strcmp(req, "firmware") == 0 ) { return "bios"; }
#else
#warning "Name your system firmware here"
#endif
return NULL;
}
ssize_t sys_kernelinfo(const char* req, char* resp, size_t resplen)
{
const char* str = KernelInfo(req);
if ( !str )
return errno = EINVAL, -1;
size_t stringlen = strlen(str);
if ( resplen < stringlen + 1 )
return errno = ERANGE, (ssize_t) stringlen;
if ( !CopyToUser(resp, str, sizeof(char) * (stringlen + 1)) )
return -1;
return 0;
}
} // namespace Sortix