Code Monkey home page Code Monkey logo

os-project02's Introduction

Hệ điều hành

Đồ án 2 : Linux Kernel license

logo

Thực hiện bởi:

  • Nguyễn Khánh Hoàng - MSSV: 1712457
  • Nguyễn Hữu Vinh - MSSV: 1712206

Phần 1 (/KernelModule) : Mục tiêu hiểu về Linux kernel module và hệ thống quản lý file và device trong linux, giao tiếp giữa tiến trình ở user space và kernel space.

  • Viết một module dùng để tạo ra số ngẫu nhiên.

  • Module này sẽ tạo một character device để cho phép các tiến trình ở user space có thể open và read các số ngẫu nhiên

    Linux Kernel Module - Random Number Generator Character Device Driver

    Mã nguồn trong file chardevdrv.c dùng để biên dịch ra module là một character device driver, có chức năng cho phép các tiến trình ở user space mở và đọc một số ngẫu nhiên từ file thiết bị của device này.

    Hướng dẫn sử dụng

    1. Mở Terminal tại thư mục KernelModule, gõ lệnh make , file chardevdrv.ko sẽ được tạo ra

    2. Gõ lệnh modinfo chardevdrv.ko để xem thông tin của module

    3. Gõ lệnh sudo insmod chardevdrv.ko để cài đặt module driver này

    4. Gõ lệnh lsmod | grep chardevdrv để xem module đã được cài đặt thành công chưa

    5. Để đọc một số ngẫu nhiên từ device này, ta dùng lệnh sau :

      sudo dd if=/dev/randnum bs=4 count=1 | hexdump -C      
      

      hoặc biên dịch file mã nguồn testRead.c bằng lệnh

      gcc testRead.c -o test
      

      rồi chạy tập tin thực thi test

    Lệnh trên đọc 4 byte từ file thiết bị /dev/randnum và xuất ra màn hình Terminal dưới dạng kí tự hexa (dùng lệnh hexdump). Chạy lệnh này nhiều lần, mỗi lần sẽ cho ra các kết quả ngẫu nhiên khác nhau. Tương tự với tập tin thực thi test, nhưng kết quả hiển thị là số thập phân.

    1. Để gỡ module này, gõ lệnh sudo rmmod chardevdrv

    2. Để dọn sạch các file được tạo ra trong thư mục trong quá trình biên dịch, gõ lệnh make clean

Phần 2 (/Hook) : Chương trình hook vào một system call:

  • syscall open => ghi vào dmesg tên tiến trình mở file và tên file được mở

  • syscall write => ghi vào dmesg tên tiến trình, tên file bị ghi và số byte được ghi

    Hướng dẫn sử dụng:

    1. Truy cập vào đường dẫn chứa mã nguồn:

      $ cd <đường dẫn>
      
    2. Sử dụng lệnh make để compile chương trình

      $ make
      
    3. Dùng insmod để hook syscall vào hệ thống

      $ sudo insmod hookSyscall.ko
      
    4. Dùng lệnh dmesg để kiểm tra (có thể gọi lệnh này trong terminal khác)

      $ dmesg
      

      hoặc có thể theo dõi liên tục bằng lệnh

      $ dmesg -wH
      
    5. Dùng lệnh rmmod để gỡ hook khỏi hệ thống

      $ sudo rmmod hookSyscall
      

os-project02's People

Contributors

hoangknguyen1807 avatar nghvinh99 avatar

Stargazers

 avatar

Watchers

 avatar

os-project02's Issues

Có bug trong test, cho thấy module không tạo số ngẫu nhiên

Trong file testRead.c, biến value được định nghĩa nhưng không được khởi tạo bằng 0. Nếu khởi tạo nó bằng 0 và chạy lại test, ta có thể thấy test in ra giá trị ngẫu nhiên là 0.
Như vậy, module bạn viết không hề tạo số ngẫu nhiên, số ngẫu nhiên mà test in ra là có sẵn trong biến value chứ không phải từ module tạo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.