libk  Artifact [582c735deb]

Artifact 582c735deb9789100aec4ff1bb404d5fdb8d127dc4ec6f948d0af104444733bb:

  • Executable file global/common.sh — part of check-in [e50a476efe] at 2019-08-22 02:52:20 on branch trunk — removed sneaky segfault in x86-64 syscall fn where %r8 (the register that contains the pointer to the syscall arguments from the C syscall wrapper, which need to be copied into the correct registers before the kernel is invoked) gets overwritten if the syscall valency > 5, because of overlapping ccall and syscall ABI argument registers - r8 is clobbered by argument 5 and any further attempts to use it as a ptr segfault at best. also modified the report function so that it immediate cancels compilation if a sub-process reports failure. changed allocator function signatures so they can return a condition code if the kernel reports an error; updated example code so it compiles and runs without fault. (user: lexi, size: 1780) [annotate] [blame] [check-ins using]

me=$0
say() { echo >&2 "($me) $1";      }
has() { command -v $1 >/dev/null 2>&1; return $?; }
check() {
	var=$1
	test "${!var}" == "" || return 0
	say "we were not able to detect a default value for the configuration variable \$$var. please set this variable to $2 and try again."
	exit 1
}

test "$to" = "" && {
	say "\$to environment variable must be set to your build directory - are you running this script by hand? run ./build.sh in the root directory instead!"
	exit 2
}

reqpack() {
	if ! has "$1"; then
		say "to $2 for libk, install the $1 package and try again"
		exit 3
	fi
}

noimpl() {
	say "$1 is not currently implemented on your system. an exciting chance for you to contribute, no?"
	exit 1
}

timestamp() { date "+%H:%M:%S %A"; }

scan() { find "$1" -name "$2"; }

if test "$COLORTERM" != ""; then
	announce() {
		test "$verbose" = "silent" && return
		local cmd="$1"; shift;
		local color=225;
		case "$cmd" in
			rm) color=196;; $asm) color=198;;
			$cc) color=213;; ar) color=120;;
			ranlib) color=105;; ld) color=216;;
			global/build-manpage.sh) color=177;;
			$m4) color=207;;
		esac

		printf " → [38;5;$color;1m$cmd"
		for a in "$@"; do
			if test ${a:0:1} = "-"; then
				printf " $a";
			else
				printf " $a";
			fi
		done
		echo
	}
else
	announce() { echo " --> " $@; }
fi

# the following function is called to report a command invocation
# the person compiling the library. the first argument should be
# an ansi format string; this is used to color-code the tool being
# launched and thus should be different for each one.

report() {
	announce $@; $@;
	status=$?
	if test $status -ne 0; then
		args=($@)
		say "process ${args[0]} failed with status code $status"
		exit $status
	fi
}