Abstract away minix_kerninfo access

Instead of importing an external _minix_kerninfo variable, any code
using the shared kernel page should now call get_minix_kerninfo(3).
Since this is the only logical name for such a function, rename the
previous get_minix_kerninfo call to ipc_minix_kerninfo.

Change-Id: I2e424b6fb55aa55d3da850187f1f7a0b7cbbf910
This commit is contained in:
David van Moolenbroek 2015-09-19 16:31:12 +00:00
parent e4d99eb9b0
commit 594df55e53
19 changed files with 64 additions and 50 deletions

View file

@ -11,8 +11,6 @@
#include <assert.h>
extern struct minix_kerninfo *_minix_kerninfo;
/*==========================================================================*
* do_new_kmess *
*==========================================================================*/
@ -24,8 +22,7 @@ void do_new_kmess(void)
int i, r, next, bytes;
static int prev_next = 0;
assert(_minix_kerninfo);
kmess = _minix_kerninfo->kmessages;
kmess = get_minix_kerninfo()->kmessages;
/* Print only the new part. Determine how many new bytes there are with
* help of the current and previous 'next' index. Note that the kernel

View file

@ -140,8 +140,6 @@ static void sef_local_startup(void);
static int sef_cb_init_fresh(int type, sef_init_info_t *info);
static void sef_cb_signal_handler(int signo);
extern struct minix_kerninfo *_minix_kerninfo;
/*===========================================================================*
* tty_task *
*===========================================================================*/
@ -397,8 +395,7 @@ do_new_kmess(void)
int next, bytes, copy, restore = 0;
tty_t *tp, rtp;
assert(_minix_kerninfo);
kmess_ptr = _minix_kerninfo->kmessages;
kmess_ptr = get_minix_kerninfo()->kmessages;
/* The kernel buffer is circular; print only the new part. Determine
* how many new bytes there are with the help of current and

View file

@ -183,7 +183,6 @@ root_dmap(void)
static void
root_ipcvecs(void)
{
extern struct minix_kerninfo *_minix_kerninfo;
extern struct minix_ipcvecs _minix_ipcvecs;
/*
@ -191,8 +190,7 @@ root_ipcvecs(void)
* will be using their own in-libc vectors that are normal symbols in
* the binary.
*/
if (!_minix_kerninfo ||
!(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS))
if (!(get_minix_kerninfo()->ki_flags & MINIX_KIF_IPCVECS))
return;
/*

View file

@ -21,10 +21,13 @@
#include <minix/endpoint.h>
#include <minix/ipc.h>
struct minix_kerninfo *get_minix_kerninfo(void);
struct ps_strings; /* forward declaration for minix_stack_fill. */
void minix_stack_params(const char *path, char * const *argv, char * const *envp,
size_t *stack_size, char *overflow, int *argc, int *envc);
void minix_stack_params(const char *path, char * const *argv,
char * const *envp, size_t *stack_size, char *overflow, int *argc,
int *envc);
void minix_stack_fill(const char *path, int argc, char * const *argv,
int envc, char * const *envp, size_t stack_size, char *frame,
int *vsp, struct ps_strings **psp);

View file

@ -2357,7 +2357,7 @@ int _ipc_senda_intr(asynmsg_t *table, size_t count);
int _do_kernel_call_intr(message *m_ptr);
int get_minix_kerninfo(struct minix_kerninfo **);
int ipc_minix_kerninfo(struct minix_kerninfo **);
/* Hide names to avoid name space pollution. */
#define ipc_notify _ipc_notify

View file

@ -14,7 +14,7 @@ SRCS+= \
_do_kernel_call_intr.S \
_ipc.S \
brksize.S \
get_minix_kerninfo.S \
ipc_minix_kerninfo.S \
ucontext.S
ucontextoffsets.h: ${CF}

View file

@ -1,13 +1,13 @@
#include <minix/ipcconst.h>
#include <machine/asm.h>
ENTRY(get_minix_kerninfo)
ENTRY(ipc_minix_kerninfo)
push {fp}
mov fp, sp
push {r0}
mov r1, #0
mov r2, #0
mov r0, #MINIX_KERNINFO /* _get_minix_kerninfo() */
mov r0, #MINIX_KERNINFO /* _ipc_minix_kerninfo() */
mov r3, #IPCVEC_INTR /* r3 determines the SVC type */
svc #0 /* trap to kernel */
pop {r2} /* r2 = return struct ptr (was r0) */

View file

@ -14,7 +14,7 @@ SRCS+= \
_do_kernel_call_intr.S \
_ipc.S \
brksize.S \
get_minix_kerninfo.S \
ipc_minix_kerninfo.S \
ucontext.S
ucontextoffsets.h: ${CF}

View file

@ -1,7 +1,7 @@
#include <minix/ipcconst.h>
#include <machine/asm.h>
ENTRY(get_minix_kerninfo)
ENTRY(ipc_minix_kerninfo)
push %ebp
movl %esp, %ebp
push %ebx

View file

@ -25,7 +25,7 @@ SRCS+= accept.c access.c adjtime.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \
getrusage.c setrlimit.c setpgid.c
# Minix specific syscalls / utils.
SRCS+= sprofile.c stack_utils.c _mcontext.c
SRCS+= kernel_utils.c sprofile.c stack_utils.c _mcontext.c
# Emulation for missing lchown/lchmod
OBJS+= lchown.o lchmod.o

View file

@ -19,7 +19,7 @@ struct minix_ipcvecs _minix_ipcvecs = {
void __minix_init(void)
{
if((get_minix_kerninfo(&_minix_kerninfo) != 0) ||
if((ipc_minix_kerninfo(&_minix_kerninfo) != 0) ||
(_minix_kerninfo->kerninfo_magic != KERNINFO_MAGIC))
{
_minix_kerninfo = NULL;
@ -30,4 +30,3 @@ void __minix_init(void)
_minix_ipcvecs = *_minix_kerninfo->minix_ipcvecs;
}
}

View file

@ -0,0 +1,25 @@
/*
* This file contains the main routine for retrieval of the kernel information
* page.
*/
#define _MINIX_SYSTEM
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <assert.h>
extern struct minix_kerninfo *_minix_kerninfo;
/*
* Get a pointer to the kernel information page.
*/
struct minix_kerninfo *
get_minix_kerninfo(void)
{
assert(_minix_kerninfo != NULL);
return _minix_kerninfo;
}

View file

@ -16,8 +16,6 @@
#include <sys/exec_elf.h>
#include <sys/exec.h>
extern struct minix_kerninfo *_minix_kerninfo;
/* Create a stack image that only needs to be patched up slightly by
* the kernel to be used for the process to be executed.
*
@ -133,7 +131,7 @@ void minix_stack_fill(const char *path, int argc, char * const *argv,
size_t const min_size = STACK_MIN_SZ;
/* Virtual address of the stack pointer, in new memory space. */
*vsp = _minix_kerninfo->kinfo->user_sp - stack_size;
*vsp = get_minix_kerninfo()->kinfo->user_sp - stack_size;
/* Fill in the frame now. */
fpw = (char **) frame;

View file

@ -286,7 +286,7 @@ CPPFLAGS.strcspn.c+= -D_LIBC
.for f in \
access.o brk.o close.o environ.o execve.o fork.o fsync.o \
getgid.o getpid.o geteuid.o getuid.o gettimeofday.o getvfsstat.o \
init.o link.o loadname.o lseek.o _mcontext.o mknod.o \
init.o kernel_utils.o link.o loadname.o lseek.o _mcontext.o mknod.o \
mmap.o nanosleep.o open.o pread.o pwrite.o read.o sbrk.o \
select.o setuid.o sigprocmask.o stack_utils.o stat.o stime.o \
syscall.o _ucontext.o umask.o unlink.o write.o \
@ -302,7 +302,7 @@ CLEANFILES+= ${f:C/\.o/.bc/}
.endfor
.for f in \
brksize.o _do_kernel_call_intr.o get_minix_kerninfo.o _ipc.o ucontext.o
brksize.o _do_kernel_call_intr.o ipc_minix_kerninfo.o _ipc.o ucontext.o
${f} ${f:C/\.o/.bc/}: ${LIBMINIXCARCHDIR}/sys/${f:C/\.o/.S/}
OBJS+= ${f}
CLEANFILES+= ${f}

View file

@ -5,9 +5,9 @@
#include <minix/minlib.h>
#include <minix/sysutil.h>
#include <minix/type.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <lib.h>
#include <assert.h>
#define MICROHZ 1000000ULL /* number of micros per second */
@ -15,19 +15,19 @@
static u64_t Hz;
extern struct minix_kerninfo *_minix_kerninfo;
int
micro_delay(u32_t micros)
{
struct minix_kerninfo *minix_kerninfo;
u64_t start, delta, delta_end;
Hz = sys_hz();
minix_kerninfo = get_minix_kerninfo();
/* Start of delay. */
read_frclock_64(&start);
assert(_minix_kerninfo->minix_arm_frclock_hz);
delta_end = (_minix_kerninfo->minix_arm_frclock_hz * micros) / MICROHZ;
assert(minix_kerninfo->minix_arm_frclock_hz);
delta_end = (minix_kerninfo->minix_arm_frclock_hz * micros) / MICROHZ;
/* If we have to wait for at least one HZ tick, use the regular
* tickdelay first. Round downwards on purpose, so the average
@ -49,16 +49,20 @@ micro_delay(u32_t micros)
u32_t frclock_64_to_micros(u64_t tsc)
{
return (u32_t) (tsc / (_minix_kerninfo->minix_arm_frclock_hz / MICROHZ));
return (u32_t)
(tsc / (get_minix_kerninfo()->minix_arm_frclock_hz / MICROHZ));
}
void
read_frclock(u32_t *frclk)
{
struct minix_kerninfo *minix_kerninfo = get_minix_kerninfo();
assert(frclk);
assert(_minix_kerninfo->minix_frclock_tcrr);
assert(_minix_kerninfo->minix_arm_frclock_hz);
*frclk = *(volatile u32_t *)((u8_t *) _minix_kerninfo->minix_frclock_tcrr);
assert(minix_kerninfo->minix_frclock_tcrr);
assert(minix_kerninfo->minix_arm_frclock_hz);
*frclk = *(volatile u32_t *)((u8_t *)
minix_kerninfo->minix_frclock_tcrr);
}
u32_t

View file

@ -1,6 +1,7 @@
/* Debugging dump procedures for the kernel. */
#include "inc.h"
#include <lib.h>
#include <minix/timers.h>
#include <assert.h>
#include <machine/interrupt.h>
@ -55,8 +56,6 @@ struct proc proc[NR_TASKS + NR_PROCS];
struct priv priv[NR_SYS_PROCS];
struct boot_image image[NR_BOOT_PROCS];
extern struct minix_kerninfo *_minix_kerninfo;
/*===========================================================================*
* kmessages_dmp *
*===========================================================================*/
@ -68,8 +67,7 @@ void kmessages_dmp()
int r;
int size;
assert(_minix_kerninfo);
kmess = _minix_kerninfo->kmessages;
kmess = get_minix_kerninfo()->kmessages;
/* Try to print the kernel messages. First determine start and copy the
* buffer into a print-buffer. This is done because the messages in the

View file

@ -19,8 +19,6 @@ static struct exec_loaders {
{ NULL }
};
extern struct minix_kerninfo *_minix_kerninfo;
int srv_execve(int proc_e, char *exec, size_t exec_len, char **argv,
char **envp)
{
@ -75,7 +73,7 @@ static int do_exec(int proc_e, char *exec, size_t exec_len, char *progname,
memset(&execi, 0, sizeof(execi));
execi.stack_high = _minix_kerninfo->kinfo->user_sp;
execi.stack_high = get_minix_kerninfo()->kinfo->user_sp;
execi.stack_size = DEFAULT_STACK_LIMIT;
execi.proc_e = proc_e;
execi.hdr = exec;

View file

@ -21,6 +21,7 @@
#include <minix/endpoint.h>
#include <minix/com.h>
#include <minix/u64.h>
#include <lib.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
@ -82,8 +83,6 @@ static const struct exec_loaders exec_loaders[] = {
#define lock_exec() lock_proc(fproc_addr(VM_PROC_NR))
#define unlock_exec() unlock_proc(fproc_addr(VM_PROC_NR))
extern struct minix_kerninfo *_minix_kerninfo;
/*===========================================================================*
* get_read_vp *
*===========================================================================*/
@ -215,7 +214,7 @@ int pm_exec(vir_bytes path, size_t path_len, vir_bytes frame, size_t frame_len,
/* passed from exec() libc code */
execi.userflags = 0;
execi.args.stack_high = _minix_kerninfo->kinfo->user_sp;
execi.args.stack_high = get_minix_kerninfo()->kinfo->user_sp;
execi.args.stack_size = DEFAULT_STACK_LIMIT;
fp->text_size = 0;

View file

@ -23,11 +23,9 @@
#if defined(__i386__)
#include "kernel/arch/i386/include/archconst.h" /* for the KTS_ constants */
#endif
#include <lib.h>
#include <minix/param.h>
extern struct minix_kerninfo *_minix_kerninfo;
/*
* Working area. By obtaining values from the kernel into these local process
* structures, and then returning them, we gain a little robustness against
@ -156,7 +154,7 @@ vir_bytes
kernel_get_stacktop(void)
{
return _minix_kerninfo->kinfo->user_sp;
return get_minix_kerninfo()->kinfo->user_sp;
}
/*