mirror of
https://github.com/fspc/gbootroot.git
synced 2025-02-23 00:53:23 -05:00
This adds a new c program skas-or-tt mostly from uml code which
automates the recognition of whether or not the host kernel has the skas patch applied. Makefile edits itself, and all gui is automated.
This commit is contained in:
parent
1578dff32e
commit
62ac34672a
@ -27,7 +27,7 @@ package BootRoot::BootRoot;
|
||||
use vars qw(@ISA @EXPORT %EXPORT_TAGS);
|
||||
use Exporter;
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(start);
|
||||
@EXPORT = qw(start skas_or_tt);
|
||||
|
||||
use strict;
|
||||
use POSIX;
|
||||
@ -2201,7 +2201,7 @@ sub uml_box {
|
||||
# Order does matter because it's used by linuxrc
|
||||
$entry_advanced[9] =
|
||||
"mtd=mtdram,$fs_type,$total_size,$erasure_size,$init, " .
|
||||
"$mem $ramdisk_size $initrd " .
|
||||
"$mem $ramdisk_size $initrd " . "mode=" . skas_or_tt() . " " .
|
||||
$entry_advanced[9];
|
||||
|
||||
}
|
||||
@ -2216,7 +2216,7 @@ sub uml_box {
|
||||
# Order does matter because it's used by linuxrc
|
||||
$entry_advanced[9] =
|
||||
"mtd=blkmtd,$fs_type,$total_size,$erasure_size,$init, " .
|
||||
"$mem $initrd " .
|
||||
"$mem $initrd " . "mode=" . skas_or_tt() . " " .
|
||||
$entry_advanced[9];
|
||||
|
||||
}
|
||||
@ -5307,4 +5307,28 @@ HELP
|
||||
|
||||
}
|
||||
|
||||
sub skas_or_tt {
|
||||
|
||||
my $ret;
|
||||
|
||||
# CLI is never appended, but it could be.
|
||||
if ( !$option{gui_mode} ) {
|
||||
open(SKAS_OR_TT,"/usr/lib/bootroot/skas-or-tt|") or
|
||||
die "Couldn't open /usr/lib/bootroot/skas-or-tt\n";
|
||||
}
|
||||
else {
|
||||
my $skas_or_tt = $option{home} . "/skas-or-tt/skas-or-tt";
|
||||
open(SKAS_OR_TT,"$skas_or_tt|") or
|
||||
die "Couldn't open $skas_or_tt\n";
|
||||
}
|
||||
|
||||
while (<SKAS_OR_TT>) {
|
||||
!m,not found$, ? ($ret = "skas") : ($ret = "tt");
|
||||
}
|
||||
close(SKAS_OR_TT);
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -1538,10 +1538,15 @@ sub create_expect_uml {
|
||||
}
|
||||
|
||||
my $ubd1 = "ubd1=$device";
|
||||
# This works for both forms of gui, but avoids cli.
|
||||
if ( !$option{template} ) {
|
||||
$option{"uml-options"} = $option{"uml-options"} .
|
||||
" mode=" . skas_or_tt();
|
||||
}
|
||||
my $options = "root=/dev/ubd0 " . $option{"uml-options"};
|
||||
my $filesystem;
|
||||
if ( $fs_type eq "genext2fs" ) {
|
||||
$filesystem = "mke2fs -m0";
|
||||
$filesystem = "mke2fs -m0";
|
||||
}
|
||||
else {
|
||||
$filesystem = $main::makefs;
|
||||
|
3
Makefile
3
Makefile
@ -28,6 +28,9 @@ install:
|
||||
cp -fa genext2fs/genext2fs.c /usr/share/gbootroot/genext2fs
|
||||
cp -fa genext2fs/Makefile /usr/share/gbootroot/genext2fs
|
||||
cp -fa genext2fs/dev* /usr/share/gbootroot/genext2fs
|
||||
install -d /usr/share/gbootroot/skas-or-tt
|
||||
cp -fa skas-or-tt/skas-or-tt.c /usr/share/gbootroot/skas-or-tt
|
||||
cp -fa skas-or-tt/Makefile /usr/share/gbootroot/skas-or-tt
|
||||
install -d /etc/gbootroot
|
||||
cp -fa gbootrootrc /etc/gbootroot/gbootrootrc
|
||||
install -d /usr/X11R6/include/X11/pixmaps
|
||||
|
25
Makefile.pkg
25
Makefile.pkg
@ -2,7 +2,7 @@
|
||||
# buildroot, UML, and gbootroot.
|
||||
|
||||
VERSION=2.4.19
|
||||
PATCH_VERSION=40
|
||||
PATCH_VERSION=45
|
||||
UTIL_VER=20021103
|
||||
|
||||
BASE_DIR=${shell pwd}
|
||||
@ -19,13 +19,17 @@ KERNEL_1_SITE=http://www.uk.kernel.org/pub/linux/kernel/v2.4 http://www.us.kerne
|
||||
PATCH_1_SITE=http://jdike.stearns.org/mirror http://uml-pub.ists.dartmouth.edu/uml http://ftp.nl.linux.org/pub/uml http://mirror.math.leidenuniv.nl/uml-pub.ists.dartmouth.edu
|
||||
PATCH_1=uml-patch-$(VERSION)-$(PATCH_VERSION).bz2
|
||||
PATCH_2=$(BASE_DIR)/user-mode-linux/usr/lib/uml/cramfs-vfs-order.patch
|
||||
MODE=tt
|
||||
KCONFIG_FILE=config
|
||||
KCONFIG=$(BASE_DIR)/user-mode-linux/usr/lib/uml/$(KCONFIG_FILE)
|
||||
|
||||
# Genext2fs
|
||||
GENEXT2_DIR=$(BASE_DIR)/genext2fs
|
||||
|
||||
# skas-or-tt .. MODE is automatically figured out, and added as an
|
||||
# uml-options for CLI.
|
||||
SKAS_OR_TT_DIR=$(BASE_DIR)/skas-or-tt
|
||||
MODE=tt
|
||||
|
||||
# Utilities
|
||||
UTILITIES=uml_utilities_$(UTIL_VER).tar.bz2
|
||||
UTIL_DIR=$(BASE_DIR)/tools
|
||||
@ -35,6 +39,14 @@ TOOLS = $(UTIL_DIR)/mconsole $(UTIL_DIR)/port-helper $(UTIL_DIR)/moo $(UTIL_DIR)
|
||||
all: world
|
||||
world: sources initrd
|
||||
|
||||
skas-or-tt:
|
||||
@if [ ! -f $(SKAS_OR_TT_DIR)/skas-or-tt ] ; then \
|
||||
$(MAKE) -C $(SKAS_OR_TT_DIR); \
|
||||
strip -s $(SKAS_OR_TT_DIR)/skas-or-tt; \
|
||||
fi;
|
||||
perl -e 'open(IT,"skas-or-tt/skas-or-tt|") or die "Trouble opening skas-or-tt/skas-or-tt\n"; while (<IT>) { if (!m,not found$$,) { $$it = "skas"; } else { $$it = "tt"; } } system "perl -pi.bak -e \"s/MODE=tt\\n/MODE=skas\\n/\" Makefile" if $$it eq "skas"; system "perl -pi.bak -e \"s/MODE=skas\\n/MODE=tt\\n/\" Makefile" if $$it eq "tt"; '
|
||||
|
||||
|
||||
sources:
|
||||
@if [ ! -e $(SOURCE_DIR)/$(KERNEL_SOURCE) ] ; then \
|
||||
while [ ! -f $(SOURCE_DIR)/$(KERNEL_SOURCE) ] ; do \
|
||||
@ -91,7 +103,7 @@ kernel:
|
||||
|
||||
|
||||
|
||||
root_fs_helper: genext2fs
|
||||
root_fs_helper: skas-or-tt genext2fs
|
||||
|
||||
@if [ ! -f $(ROOT_FS_DIR)/root_fs_helper ] ; then \
|
||||
perl -I . ./gbootroot --home . --template Helper.yard --root-filename root_fs_helper --filesystem-command "genext2fs -z -r0" --genext2fs-dir genext2fs/ --uml-options mode=$(MODE); \
|
||||
@ -151,6 +163,7 @@ clean:
|
||||
rm -rf $(KERNEL_DIR)
|
||||
rm -rf $(UTIL_DIR)
|
||||
rm -f $(GENEXT2_DIR)/{genext2fs,genext2fs.o}
|
||||
rm -f $(SKAS_OR_TT_DIR)/{skas-or-tt,skas-or-tt.o}
|
||||
rm -f $(ROOT_FS_DIR)/{root_fs_helper,Initrd.gz}
|
||||
rm -f $(BASE_DIR)/user-mode-linux/usr/bin/*
|
||||
rm -f $(BASE_DIR)/user-mode-linux/usr/lib/uml/{modules*,port-helper}
|
||||
@ -165,6 +178,7 @@ install:
|
||||
install -d $(DESTDIR)/usr/lib/bootroot
|
||||
cp -fa yard_chrooted_tests $(DESTDIR)/usr/lib/bootroot/yard_chrooted_tests
|
||||
cp -fa genext2fs/genext2fs $(DESTDIR)/usr/lib/bootroot/genext2fs
|
||||
cp -fa skas-or-tt/skas-or-tt $(DESTDIR)/usr/lib/bootroot/skas-or-tt
|
||||
cp -fa expect_uml $(DESTDIR)/usr/lib/bootroot/expect_uml
|
||||
install -d $(DESTDIR)/usr/lib/bootroot/root_filesystem
|
||||
cp -fa root_filesystem/root_fs_helper $(DESTDIR)/usr/lib/bootroot/root_filesystem
|
||||
@ -188,6 +202,9 @@ install:
|
||||
cp -fa genext2fs/genext2fs.c $(DESTDIR)/usr/share/gbootroot/genext2fs
|
||||
cp -fa genext2fs/Makefile $(DESTDIR)/usr/share/gbootroot/genext2fs
|
||||
cp -fa genext2fs/dev* $(DESTDIR)/usr/share/gbootroot/genext2fs
|
||||
install -d $(DESTDIR)/usr/share/gbootroot/skas-or-tt
|
||||
cp -fa skas-or-tt/skas-or-tt.c $(DESTDIR)/usr/share/gbootroot/skas-or-tt
|
||||
cp -fa skas-or-tt/Makefile $(DESTDIR)/usr/share/gbootroot/skas-or-tt
|
||||
cp -fa user-mode-linux/usr/bin/uml_* $(DESTDIR)/usr/bin
|
||||
cp -fa user-mode-linux/usr/bin/tunctl $(DESTDIR)/usr/bin/tunctl
|
||||
cp -fa user-mode-linux/usr/bin/linuxbr $(DESTDIR)/usr/bin/linuxbr
|
||||
@ -217,4 +234,4 @@ remove:
|
||||
rm /usr/X11R6/include/X11/pixmaps/gbootroot.xpm
|
||||
rm -rf /usr/share/doc/gbootroot
|
||||
|
||||
.PHONY: tools sources genext2fs root_fs_helper
|
||||
.PHONY: tools sources genext2fs root_fs_helper skas-or-tt
|
||||
|
19
skas-or-tt/Makefile
Normal file
19
skas-or-tt/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -O2
|
||||
|
||||
SRC=skas-or-tt.c
|
||||
OBJS=$(patsubst %.c,%.o, $(SRC))
|
||||
|
||||
|
||||
all: skas-or-tt
|
||||
|
||||
skas-or-tt: $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(OBJS) -o $@
|
||||
|
||||
$(OBJS): %.o : %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJS): Makefile
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a core skas-or-tt
|
141
skas-or-tt/skas-or-tt.c
Normal file
141
skas-or-tt/skas-or-tt.c
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
skas_or_tt Copyright (C) 2003
|
||||
Jonathan Rosenbaum <freesource@users.sourceforge.net>
|
||||
|
||||
A program to check for the existence of the skas patch in the host
|
||||
kernel and /proc/mm. Basically borrowed/simplified from jdike's
|
||||
process.c. This is a good way to learn about clone() and ptrace().
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <wait.h>
|
||||
#include <sys/mman.h> /* for mmap */
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/types.h>
|
||||
#include <sched.h> /* clone */
|
||||
#define PTRACE_FAULTINFO 52
|
||||
#define PAGE_SIZE 1024
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
int n, pid, ret = 1;
|
||||
void *stack;
|
||||
|
||||
struct ptrace_faultinfo {
|
||||
int is_write;
|
||||
unsigned long addr;
|
||||
};
|
||||
|
||||
|
||||
struct ptrace_faultinfo fi;
|
||||
|
||||
printf("Checking for the skas3 patch in the host...");
|
||||
pid = start_ptraced_child(&stack);
|
||||
|
||||
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
|
||||
if(n < 0){
|
||||
if(errno == EIO)
|
||||
printf("not found\n");
|
||||
else printf("No (unexpected errno - %d)\n", errno);
|
||||
ret = 0;
|
||||
}
|
||||
else printf("found\n");
|
||||
|
||||
|
||||
printf("Checking for /proc/mm...");
|
||||
if(access("/proc/mm", W_OK)){
|
||||
printf("not found\n");
|
||||
ret = 0;
|
||||
}
|
||||
else printf("found\n");
|
||||
|
||||
kill(pid, SIGKILL);
|
||||
return(ret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int threadFunction( void* argument )
|
||||
{
|
||||
printf( "child thread exiting\n" );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int os_getpid(void)
|
||||
{
|
||||
return(getpid());
|
||||
}
|
||||
|
||||
void os_stop_process(int pid)
|
||||
{
|
||||
kill(pid, SIGSTOP);
|
||||
}
|
||||
|
||||
void os_kill_process(int pid, int reap_child)
|
||||
{
|
||||
kill(pid, SIGKILL);
|
||||
if(reap_child)
|
||||
waitpid(pid, NULL, 0);
|
||||
|
||||
}
|
||||
|
||||
static int ptrace_child(void *arg)
|
||||
{
|
||||
int pid = os_getpid();
|
||||
|
||||
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
|
||||
perror("ptrace");
|
||||
os_kill_process(pid, 0);
|
||||
}
|
||||
|
||||
os_stop_process(pid);
|
||||
_exit(os_getpid() == pid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int start_ptraced_child(void **stack_out)
|
||||
{
|
||||
void *stack;
|
||||
unsigned long sp;
|
||||
int pid, n, status;
|
||||
|
||||
stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if(stack == MAP_FAILED)
|
||||
printf("check_ptrace : mmap failed, errno = %d", errno);
|
||||
sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
|
||||
pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
|
||||
if(pid < 0) {
|
||||
printf("check_ptrace : clone failed, errno = %d\n", errno);
|
||||
exit(0);
|
||||
}
|
||||
n = waitpid(pid, &status, WUNTRACED);
|
||||
if(n < 0) {
|
||||
printf("check_ptrace : wait failed, errno = %d\n", errno);
|
||||
exit(0);
|
||||
}
|
||||
if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) {
|
||||
printf("check_ptrace : expected SIGSTOP, got status = %d\n",
|
||||
status);
|
||||
exit(0);
|
||||
}
|
||||
*stack_out = stack;
|
||||
return(pid);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Overrides for Emacs so that we follow Linus's tabbing style.
|
||||
* Emacs will notice this stuff at the end of the file and automatically
|
||||
* adjust the settings for this buffer only. This must remain at the end
|
||||
* of the file.
|
||||
* ---------------------------------------------------------------------------
|
||||
* Local variables:
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
@ -5,7 +5,7 @@
|
||||
## YARD_CHROOT_TEST
|
||||
## Code from CHECK_ROOT_FS by Tom Fawcett
|
||||
## Copyright (C) 1996,1997,1998 Tom Fawcett (fawcett@croftj.net)
|
||||
## Copyright (C) 2000, 2001, 2002 Modifications by Jonathan Rosenbaum
|
||||
## Copyright (C) 2000, 2001, 2002, 2003 Modifications by Jonathan Rosenbaum
|
||||
## <freesource@users.sourceforge.net>
|
||||
##
|
||||
## This program is free software; you may redistribute it and/or modify
|
||||
|
Loading…
x
Reference in New Issue
Block a user