Git Product home page Git Product logo

aritdev's Introduction

aritdev

Kernel module for providing basic arithmetic operations, and associated userspace server and client applications.

Dependencies

  • Linux environment (tested with kernel 5.15.13)
  • GCC (tested with 11.2.0)
  • CMake (tested with 3.22.1)
  • Make (tested with 4.3)
  • Python (tested with 3.10.0)

Building

To build all aplications, run cmake -Bbuild; cd build; make; cd .. at the root of the repo.

To clean all aplications, simply remove directory build/ and its contents.

Kernel module

Load the module from the root of the repo with:

# insmod build/module/aritdev.ko

This creates character device /dev/aritdev, with which applications can interact to request basic arithmetic operations. The module logs messages on the kernel log (dmesg).

The module awaits for write operations that describe arithmetic operations. Messages written must be exactly 17 bytes long. Byte 0 must be one of the following ASCII characters that define an arithmetic operation:

  • + (sum)
  • * (multiplication)
  • - (subtraction)
  • / (division)

Bytes 1 through 8 contain the first 64-bit operand and bytes 9 through 16 contain the second 64-bit operand. The operands are little endian in the x86-64 architecture.

Upon reception of a write operation, the module returns the amount of bytes received (17) if the message is well-formed or -EINVAL if it is malformed (e.g. invalid length or invalid operation). The result is then computed.

If a result is available (meaning that there has been a write describing a valid operation and the result has not yet been read), it can be obtained through a read operation.

The module may be unloaded with

# rmmod aritdev

while no application holds the device open.

By default, when the module is loaded, device /dev/aritdev is created with read/write permissions for root only. To allow other users to interface with the device, copy file udev/96-aritdev.rules to directory /etc/udev/rules.d/, then run:

# udevadm control -R

to reload udev rules.

Server application

Run the server application from the root of the repo with:

$ build/server/server

The server listens to requests from client applications on port 8080. A request message must be composed identically to the operations expected by the aritdev device (one operation byte and two 64-bit operands).

Before forwarding the request to aritdev, the server performs validations and responds to the client with a status code. A valid message returns a zero, a message with invalid length returns a 1 and a message with and invalid operation returns a 2.

If the request is valid, it is written to aritdev and the result is read. The server then responds with the 64-bit result to the client, closes the connection, and waits for a new connection.

Client applications

Two client applications are provided, one in C and one in Python. They are identical in functionality. The C client is executed from the root of the repo with:

$ build/client/client

while the Python client is executed with:

$ python python_client/python_client.py

Both clients present four arithmetic operations for the user to choose from. The user inputs the chosen application then inputs the two signed integer operands.

The clients perform validations then assemble a request which is sent to the server on port 8080. The status code response from the server is then retrieved and, in case of success, so is the result of the arithmetic operation.

aritdev's People

Contributors

rgwott avatar

Watchers

 avatar

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.