mirror of
				https://gitlab.com/sortix/sortix.git
				synced 2023-02-13 20:55:38 -05:00 
			
		
		
		
	Added kernelinfo(2), which reads a kernel information string.
Currently it lets you query the name of the kernel, its version, and the build timestamp of the kernelinfo.cpp file.
This commit is contained in:
		
							parent
							
								
									7d4c79bc8c
								
							
						
					
					
						commit
						8a9a0c58ea
					
				
					 9 changed files with 200 additions and 1 deletions
				
			
		
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -40,6 +40,8 @@ ISOFILE:=builds/$(DEBNAME).iso
 | 
			
		|||
INITRDDIR:=initrd
 | 
			
		||||
INITRD=sortix/sortix.initrd
 | 
			
		||||
 | 
			
		||||
MFLAGS:=$(MFLAGS) VERSION=$(VERSION)
 | 
			
		||||
 | 
			
		||||
all: $(INITRD)
 | 
			
		||||
 | 
			
		||||
suball:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,7 @@ process.o \
 | 
			
		|||
thread.o \
 | 
			
		||||
io.o \
 | 
			
		||||
terminal.o \
 | 
			
		||||
kernelinfo.o \
 | 
			
		||||
init.o \
 | 
			
		||||
signal.o \
 | 
			
		||||
$(CPU)/signal.o \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										40
									
								
								libmaxsi/include/sys/kernelinfo.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								libmaxsi/include/sys/kernelinfo.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,40 @@
 | 
			
		|||
/*******************************************************************************
 | 
			
		||||
 | 
			
		||||
	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
 | 
			
		||||
 | 
			
		||||
	This file is part of LibMaxsi.
 | 
			
		||||
 | 
			
		||||
	LibMaxsi is free software: you can redistribute it and/or modify it under
 | 
			
		||||
	the terms of the GNU Lesser General Public License as published by the Free
 | 
			
		||||
	Software Foundation, either version 3 of the License, or (at your option)
 | 
			
		||||
	any later version.
 | 
			
		||||
 | 
			
		||||
	LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
 | 
			
		||||
	WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | 
			
		||||
	FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 | 
			
		||||
	details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
	along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
	sys/kernelinfo.h
 | 
			
		||||
	Queries information about the kernel.
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef	_SYS_KERNELINFO_H
 | 
			
		||||
#define	_SYS_KERNELINFO_H 1
 | 
			
		||||
 | 
			
		||||
#include <features.h>
 | 
			
		||||
 | 
			
		||||
__BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
@include(size_t.h)
 | 
			
		||||
@include(ssize_t.h)
 | 
			
		||||
 | 
			
		||||
ssize_t kernelinfo(const char* req, char* resp, size_t resplen);
 | 
			
		||||
 | 
			
		||||
__END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								libmaxsi/kernelinfo.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								libmaxsi/kernelinfo.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
/*******************************************************************************
 | 
			
		||||
 | 
			
		||||
	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
 | 
			
		||||
 | 
			
		||||
	This file is part of LibMaxsi.
 | 
			
		||||
 | 
			
		||||
	LibMaxsi is free software: you can redistribute it and/or modify it under
 | 
			
		||||
	the terms of the GNU Lesser General Public License as published by the Free
 | 
			
		||||
	Software Foundation, either version 3 of the License, or (at your option)
 | 
			
		||||
	any later version.
 | 
			
		||||
 | 
			
		||||
	LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
 | 
			
		||||
	WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | 
			
		||||
	FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 | 
			
		||||
	details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
	along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
	kernelinfo.cpp
 | 
			
		||||
	Queries information about the kernel.
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <libmaxsi/platform.h>
 | 
			
		||||
#include <libmaxsi/syscall.h>
 | 
			
		||||
#include <sys/kernelinfo.h>
 | 
			
		||||
 | 
			
		||||
namespace Maxsi {
 | 
			
		||||
 | 
			
		||||
DEFN_SYSCALL3(ssize_t, SysKernelInfo, SYSCALL_KERNELINFO, const char*, char*, size_t);
 | 
			
		||||
 | 
			
		||||
extern "C" ssize_t kernelinfo(const char* req, char* resp, size_t resplen)
 | 
			
		||||
{
 | 
			
		||||
	return SysKernelInfo(req, resp, resplen);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Maxsi
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,6 +65,9 @@ ifeq ($(CALLTRACE),1)
 | 
			
		|||
else
 | 
			
		||||
    DEFINES:=$(DEFINES) -DENABLE_CALLTRACE=0
 | 
			
		||||
endif
 | 
			
		||||
ifdef VERSION
 | 
			
		||||
    DEFINES:=$(DEFINES) -DVERSIONSTR=\"$(VERSION)\"
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
INCLUDES=-I../libmaxsi/preproc -I.. -I.
 | 
			
		||||
CPPFLAGS=$(INCLUDES) $(DEFINES)
 | 
			
		||||
| 
						 | 
				
			
			@ -118,6 +121,7 @@ descriptors.o \
 | 
			
		|||
device.o \
 | 
			
		||||
refcount.o \
 | 
			
		||||
vga.o \
 | 
			
		||||
kernelinfo.o \
 | 
			
		||||
elf.o \
 | 
			
		||||
process.o \
 | 
			
		||||
initrd.o \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,7 @@
 | 
			
		|||
#include <libmaxsi/format.h>
 | 
			
		||||
#include "log.h"
 | 
			
		||||
#include "panic.h"
 | 
			
		||||
#include "kernelinfo.h"
 | 
			
		||||
#include "x86-family/gdt.h"	
 | 
			
		||||
#include "time.h"
 | 
			
		||||
#include "keyboard.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -256,6 +257,9 @@ namespace Sortix
 | 
			
		|||
		// Initialize the scheduler.
 | 
			
		||||
		Scheduler::Init();
 | 
			
		||||
 | 
			
		||||
		// Initialize the kernel information query syscall.
 | 
			
		||||
		Info::Init();
 | 
			
		||||
 | 
			
		||||
		// Set up the initial ram disk.
 | 
			
		||||
		InitRD::Init(initrd, initrdsize);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										70
									
								
								sortix/kernelinfo.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								sortix/kernelinfo.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,70 @@
 | 
			
		|||
/*******************************************************************************
 | 
			
		||||
 | 
			
		||||
	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
 | 
			
		||||
 | 
			
		||||
	This file is part of Sortix.
 | 
			
		||||
 | 
			
		||||
	Sortix is free software: you can redistribute it and/or modify it under the
 | 
			
		||||
	terms of the GNU General Public License as published by the Free Software
 | 
			
		||||
	Foundation, either version 3 of the License, or (at your option) any later
 | 
			
		||||
	version.
 | 
			
		||||
 | 
			
		||||
	Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
 | 
			
		||||
	WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | 
			
		||||
	FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 | 
			
		||||
	details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU General Public License along with
 | 
			
		||||
	Sortix. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
	kernelinfo.cpp
 | 
			
		||||
	Lets user-space query information about the kernel.
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "platform.h"
 | 
			
		||||
#include <libmaxsi/error.h>
 | 
			
		||||
#include <libmaxsi/string.h>
 | 
			
		||||
#include "syscall.h"
 | 
			
		||||
#include "kernelinfo.h"
 | 
			
		||||
 | 
			
		||||
#ifndef VERSIONSTR
 | 
			
		||||
#define VERSIONSTR "unknown"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using namespace Maxsi;
 | 
			
		||||
 | 
			
		||||
namespace Sortix {
 | 
			
		||||
namespace Info {
 | 
			
		||||
 | 
			
		||||
const char* KernelInfo(const char* req)
 | 
			
		||||
{
 | 
			
		||||
	if ( String::Compare(req, "name") == 0 ) { return "Sortix"; }
 | 
			
		||||
	if ( String::Compare(req, "version") == 0 ) { return VERSIONSTR; }
 | 
			
		||||
	if ( String::Compare(req, "builddate") == 0 ) { return __DATE__; }
 | 
			
		||||
	if ( String::Compare(req, "buildtime") == 0 ) { return __TIME__; }
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ssize_t SysKernelInfo(const char* req, char* resp, size_t resplen)
 | 
			
		||||
{
 | 
			
		||||
	const char* str = KernelInfo(req);
 | 
			
		||||
	if ( !str ) { Error::Set(EINVAL); return -1; }
 | 
			
		||||
	size_t stringlen = String::Length(str);
 | 
			
		||||
	if ( resplen < stringlen + 1 )
 | 
			
		||||
	{
 | 
			
		||||
		Error::Set(ERANGE);
 | 
			
		||||
		return (ssize_t) stringlen;
 | 
			
		||||
	}
 | 
			
		||||
	String::Copy(resp, str);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Init()
 | 
			
		||||
{
 | 
			
		||||
	Syscall::Register(SYSCALL_KERNELINFO, (void*) SysKernelInfo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Info
 | 
			
		||||
} // namespace Sortix
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								sortix/kernelinfo.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								sortix/kernelinfo.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
/*******************************************************************************
 | 
			
		||||
 | 
			
		||||
	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012.
 | 
			
		||||
 | 
			
		||||
	This file is part of Sortix.
 | 
			
		||||
 | 
			
		||||
	Sortix is free software: you can redistribute it and/or modify it under the
 | 
			
		||||
	terms of the GNU General Public License as published by the Free Software
 | 
			
		||||
	Foundation, either version 3 of the License, or (at your option) any later
 | 
			
		||||
	version.
 | 
			
		||||
 | 
			
		||||
	Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
 | 
			
		||||
	WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | 
			
		||||
	FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 | 
			
		||||
	details.
 | 
			
		||||
 | 
			
		||||
	You should have received a copy of the GNU General Public License along with
 | 
			
		||||
	Sortix. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
	kernelinfo.h
 | 
			
		||||
	Lets user-space query information about the kernel.
 | 
			
		||||
 | 
			
		||||
*******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef SORTIX_KERNELINFO_H
 | 
			
		||||
#define SORTIX_KERNELINFO_H
 | 
			
		||||
 | 
			
		||||
namespace Sortix {
 | 
			
		||||
namespace Info {
 | 
			
		||||
 | 
			
		||||
const char* KernelInfo(const char* req);
 | 
			
		||||
void Init();
 | 
			
		||||
 | 
			
		||||
} // namespace Version
 | 
			
		||||
} // namespace Sortix
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +72,8 @@
 | 
			
		|||
#define SYSCALL_FSTAT 45
 | 
			
		||||
#define SYSCALL_FCNTL 46
 | 
			
		||||
#define SYSCALL_ACCESS 47
 | 
			
		||||
#define SYSCALL_MAX_NUM 48 /* index of highest constant + 1 */
 | 
			
		||||
#define SYSCALL_KERNELINFO 48
 | 
			
		||||
#define SYSCALL_MAX_NUM 49 /* index of highest constant + 1 */
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue