mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-21 20:23:38 +08:00
...
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := uts_name.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,107 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#include <generated/compile.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/uts.h>
|
||||
#include <linux/utsname.h>
|
||||
#include <generated/utsrelease.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/proc_ns.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* init_uts_ns be defined in init/version.c
|
||||
* http://lxr.free-electrons.com/source/init/version.c?v=4.5#L25
|
||||
*
|
||||
* the struct uts_namespace be degined in linux/utsname.h
|
||||
* http://lxr.free-electrons.com/source/include/linux/utsname.h?v=4.5#L23
|
||||
*
|
||||
|
||||
struct uts_namespace init_uts_ns =
|
||||
{
|
||||
.kref =
|
||||
{
|
||||
.refcount = ATOMIC_INIT(2),
|
||||
},
|
||||
|
||||
.name =
|
||||
{
|
||||
.sysname = UTS_SYSNAME,
|
||||
.nodename = UTS_NODENAME,
|
||||
.release = UTS_RELEASE,
|
||||
.version = UTS_VERSION,
|
||||
.machine = UTS_MACHINE,
|
||||
.domainname = UTS_DOMAINNAME,
|
||||
},
|
||||
|
||||
.user_ns = &init_user_ns,
|
||||
.proc_inum = PROC_UTS_INIT_INO,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(init_uts_ns);
|
||||
|
||||
*/
|
||||
struct uts_namespace *utsns = &init_uts_ns;
|
||||
|
||||
|
||||
static void print_new_utsname(struct new_utsname *pnew_utsname)
|
||||
{
|
||||
|
||||
printk(KERN_ALERT "sysname = %s\n", pnew_utsname->sysname);
|
||||
printk(KERN_ALERT "nodename = %s\n", pnew_utsname->nodename);
|
||||
printk(KERN_ALERT "release = %s\n", pnew_utsname->release);
|
||||
printk(KERN_ALERT "version = %s\n", pnew_utsname->version);
|
||||
printk(KERN_ALERT "sysname = %s\n", pnew_utsname->machine);
|
||||
printk(KERN_ALERT "domainname = %s\n", pnew_utsname->domainname);
|
||||
|
||||
}
|
||||
|
||||
static void print_user_namespace(struct user_namespace *puser_ns)
|
||||
{
|
||||
struct ns_common ns;
|
||||
}
|
||||
|
||||
|
||||
static void print_uts_namespace(struct uts_namespace *utsns)
|
||||
{
|
||||
// struct kref kref;
|
||||
//printk(KERN_ALERT "atomic kref %d\n", utsns->kref.refcount.val);
|
||||
printk(KERN_ALERT "atomic kref %d\n", utsns->kref.refcount.counter);
|
||||
|
||||
struct new_utsname *pnew_utsname = &utsns->name;
|
||||
print_new_utsname(pnew_utsname);
|
||||
|
||||
|
||||
struct user_namespace *puser_ns = utsns->user_ns;
|
||||
print_user_namespace(puser_ns);
|
||||
|
||||
//printk(KERN_ALERT "proc_inum = %d\n", utsns->proc_inum);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int __init init_uts_name(void)
|
||||
{
|
||||
print_uts_namespace(utsns);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit exit_uts_name(void)
|
||||
{
|
||||
printk(KERN_ALERT "Good Bye!!--uts_name");
|
||||
}
|
||||
|
||||
module_init(init_uts_name);
|
||||
module_exit(exit_uts_name);
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_AUTHOR("Gatieme @ HIT CS HDMC team");
|
||||
MODULE_DESCRIPTION("Memory Engine Module.");
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mm_types.h>
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, field) ((long) &((type *)0)->field)
|
||||
#endif /* offsetof */
|
||||
|
||||
#ifndef container_of
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, field) ((long) &((type *)0)->field)
|
||||
#endif /* offsetof */
|
||||
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
static int pid = 1;
|
||||
@@ -27,11 +27,11 @@ static void printvm_list(void)
|
||||
struct task_struct *p;
|
||||
struct pid *k;
|
||||
struct vm_area_struct *tmp;
|
||||
|
||||
|
||||
k = find_vpid(pid);
|
||||
p = pid_task(k,PIDTYPE_PID);
|
||||
tmp = p->mm->mmap;
|
||||
|
||||
|
||||
printk("process:%s,pid:%d\n",p->comm,p->pid);
|
||||
|
||||
while (tmp != NULL) {
|
||||
@@ -43,20 +43,20 @@ static void printvm_list(void)
|
||||
|
||||
if (tmp->vm_flags & VM_WRITE)
|
||||
printk("w");
|
||||
else
|
||||
else
|
||||
printk("-");
|
||||
|
||||
|
||||
if (tmp->vm_flags & VM_EXEC)
|
||||
printk("x");
|
||||
else
|
||||
printk("-");
|
||||
|
||||
|
||||
if (tmp->vm_flags & VM_SHARED)
|
||||
printk("s\n");
|
||||
else
|
||||
printk("p\n");
|
||||
|
||||
tmp = tmp->vm_next;
|
||||
tmp = tmp->vm_next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +74,14 @@ static void visit(struct rb_node *root)
|
||||
|
||||
if (tmp->vm_flags & VM_WRITE)
|
||||
printk("w");
|
||||
else
|
||||
else
|
||||
printk("-");
|
||||
|
||||
|
||||
if (tmp->vm_flags & VM_EXEC)
|
||||
printk("x");
|
||||
else
|
||||
printk("-");
|
||||
|
||||
|
||||
if (tmp->vm_flags & VM_SHARED)
|
||||
printk("s\n");
|
||||
else
|
||||
@@ -107,14 +107,14 @@ static void printvm_tree(void)
|
||||
p = pid_task(k,PIDTYPE_PID);
|
||||
root = p->mm->mm_rb.rb_node;
|
||||
print_rb_tree(root);
|
||||
return ;
|
||||
return ;
|
||||
}
|
||||
|
||||
static int __init printvm_init(void)
|
||||
{
|
||||
printvm_list();
|
||||
printk("------------------------\n");
|
||||
printvm_tree();
|
||||
printvm_tree();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user