r/linux_programming • • Dec 10 '23

Writing a device driver; dmesg says "section size must match the kernel's built struct module size at run time"

6 Upvotes

I'm trying to load a barebones Linux device driver module, but I keep getting hit with this:

insmod: ERROR: could not insert module dummydriver.ko: Invalid module format 

and dmesg says:

module dummydriver: .gnu.linkonce.this_module section size must match the kernel's built struct module size at run time

Driver code:

#include <linux/module.h>
#include <linux/version.h> 
include <linux/kernel.h>

static int __init driver_init(void) {
    printk(KERN_INFO "bababooey :D");
    return 0; 
}

static void __exit driver_exit(void) {
    printk(KERN_INFO "bababooey :(");
} 

module_init(driver_init);
module_exit(driver_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("dude");
MODULE_DESCRIPTION("driver"); 

Makefile:

obj-m = dummydriver.o
KVERSION = $(shell uname -r)
all:
     make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) modules

clean:
     make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) clean 

Make output:

make -C /lib/modules/6.5.6-76060506-generic/build M=/home/david/Programming/dummydriver modules
make[1]: Entering directory '/usr/src/linux-headers-6.5.6-76060506-generic'
   CC [M]  /home/david/Programming/dummydriver/dummydriver.o
   MODPOST /home/david/Programming/dummydriver/Module.symvers   CC [M]  /home/david/Programming/dummydriver/dummydriver.mod.o
   LD [M]  /home/david/Programming/dummydriver/dummydriver.ko
make[1]: Leaving directory '/usr/src/linux-headers-6.5.6-76060506-generic' 

uname -r:

6.5.6-76060506-generic 

I'm running Pop OS 22.04 if it matters. Any advice is appreciated, really not sure what to do with that dmesg output.


r/linux_programming • • Nov 29 '23

Is ptrace optimal

6 Upvotes

Greetings fellow programmers,

I'm currently embarking on a project that involves modifying the memory of a running game. The game in question is a simple C++ program that merely displays the value of a variable. For prototyping purposes, I'm utilizing Python.

I've successfully employed /proc/PID/maps to locate the pertinent memory addresses and /proc/PID/mem to read their values. However, my attempts to modify the memory have been met with failure. According to my research, using /proc/PID/mem for memory editing is an unconventional approach, with ptrace being the preferred method.

This brings me to my quandary: is ptrace the optimal solution for my endeavor? While I've managed to read and write memory using ptrace, it necessitates attaching and detaching from the process, which appears rather inconvenient. I'm concerned that this repetitive attaching and detaching could introduce performance bottlenecks in the game, which I aim to prevent.

On a side note, the final version of my tool will be crafted in C/C++/Rust.

Any insights or suggestions would be immensely valuable. Thank you in advance for your assistance!


On linux mint, version 5.15.0-87-generic. The kernel was built on October 2, 2023 at 21:09 UTC. The computer's architecture is x86_64


r/linux_programming • • Sep 01 '23

A start point for a beginner

6 Upvotes

Hello everyone, I've been using Linux as my main operating system for a few years now, I've also been studying programming for a long time (java, python and currently C). What I would like to know is where I should start to program applications for linux, I don't know if you know of any type of course (it doesn't matter if it is paid) where I can learn to develop projects for linux using C.


r/linux_programming • • Jun 29 '23

PAM guidance needed

6 Upvotes

I am trying to build a simple authentication module linux PAM, which checks against webserver if the user attempting to login is allowed

My repository:

  1. https://github.com/godwinpinto/passage-connect

  2. I have built the .so file (using make command) and placed in /usr/lib64/security of my AWS server ec2 instance

  3. Made an entry in /etc/pam.d/sshd

  4. "auth required mysofile.so"

  5. restarted sshd

However, i have no clue whats going on and why my auth PAM module doesnt work (like the golang print statements dont show up. I can simply loggedin to AWS ec2 using ssh with private keys even though this module is enabled.

No logs in /var/log/secure too

I am extremely new to this PAM field

Any help will be greatly appreciated.


r/linux_programming • • Jun 26 '23

When do you use systemd's resolv.conf instead of stub-resolv.conf ?

6 Upvotes

Learned the difference of these two files.

/run/systemd/resolve/resolv.conf 
/run/systemd/resolve/stub-resolv.conf

On modern systems that use `systemd-resolved` for DNS resolution, by default the `/etc/resolv.conf` file is a symlink that points to `/run/systemd/resolve/stub-resolv.conf`.

The `stub-resolv.conf` file is a dynamically maintained list of nameservers that `systemd-resolved` uses, and it includes the local `systemd-resolved` stub resolver (127.0.0.53) to handle DNS queries.

`/run/systemd/resolve/resolv.conf` is also maintained by `systemd-resolved` but only includes upstream DNS servers, not the local stub resolver.

Do you ever have `/etc/resolv.conf` point to `/run/systemd/resolve/resolv.conf` ?

The only reason I can think of for a person actively changing this is an existence of applications that do not work correctly with the stub resolver, but how does that happen?


r/linux_programming • • Jun 13 '23

Error installing Stunnel

6 Upvotes

I'm trying to install Stunnel on Fedora (Red hat 8). However, i'm getting the below error:

[FAILED] stunnel-5.56-5.el8_3.x86_64.rpm: No more mirrors to try - All mirrors were already tried without success

The downloaded packages were saved in cache until the next successful transaction.

You can remove cached packages by executing 'yum clean packages'.

Error: Error downloading packages:

stunnel-5.56-5.el8_3.x86_64: Cannot download, all mirrors were already tried without success

The stunnel package doesn't need any prerequisite that i'm aware of. Can anyone assist?


r/linux_programming • • Jun 12 '23

Did YouTube just break middle-click behavior?

6 Upvotes

Before installing the latest chrome, middle-clicking on the thumbnail on the YT browse page would open the video in a new table. Now, the same action does nothing of the sort. Middle-clicking the title will still open the video in a new tab. Left-clicking still opens the video in the current tab. Anyone else seeing this? I'm using Chrome 114.0.5735.106 on Ubuntu 22.04.2 LTS.


r/linux_programming • • Jun 08 '23

programming workstation on weak hardware

6 Upvotes

I've asked a number of questions in different linux subreddits but I found that what I was asking is wrong after trying different distros. I'm testing out if I can make a workstation out of an old macbook air mid 2011. it has 4gb of ram ddr3, an i5 2th gen and an ssd in it. ram is solderen on so can't change it. right now I'm running kubuntu on it but that cpu doesn't really like my workload all that much, ramwise i'm still in the clear by a gig. In you'r opinion what linux distro should I be using for programming, I'm doing mainly backend with some fullstack using java, javascript, html css, some frameworks for those, python, postgres database usage or mongodb database basically the normall fullstack or backend stuff. I was also wondering if undervolting this instance of kubuntu would help me at all.


r/linux_programming • • May 12 '23

[wish] Flexible array members in unions

Thumbnail gcc.gnu.org
6 Upvotes

r/linux_programming • • May 10 '23

Rust Based Linux Process Manager with both a GUI and a TUI

6 Upvotes

🚀 Exciting Announcement: Introducing PCtrl - Your New Interactive GUI and TUI Linux Process Manager! 🎉 I'm thrilled to announce the release of PCtrl, a robust and featureful process manager for Linux, built entirely in Rust! 🌟

🌐 GitHub Repository: https://github.com/MohamedSherifNoureldin/PCtrl

PCtrl provides an overview of the system, allowing you to monitor and control running processes effortlessly. With its powerful features and user-friendly interface, PCtrl is set to revolutionize your process management experience. Whether you prefer a Terminal User Interface (TUI), Graphical User Interface (GUI), or both, PCtrl has got you covered! 💪

This amazing project was the final submission for the Operating Systems (CSCE 3401) course at The American University in Cairo. Our talented team embarked on this journey to explore the Rust programming language and unleash the full potential of process management. 🎓

Let's take a quick look at PCtrl's key features: ✅ Run as a TUI or GUI, or both ✅ View processes in a tabular or tree format ✅ Sort processes by any column ✅ Search for processes by name or PID ✅ Filter processes by various categories ✅ View detailed process information ✅ Visualize memory and CPU usage through intuitive graphs ✅ Manage processes efficiently: kill, change priority, pause/unpause, change niceness, and change owner ✅ Export processes list to CSV ✅ Monitor processes and automatically restart them if they crash ✅ Track and log process resource usage over time


r/linux_programming • • Apr 27 '23

Transmeta Crusoe: The Most Interesting Processor To Ever Exist?

Thumbnail
tedium.co
6 Upvotes

r/linux_programming • • Apr 25 '23

Demystifying bitwise operations, a gentle C tutorial

Thumbnail andreinc.net
6 Upvotes

r/linux_programming • • Apr 20 '23

Linux Backup server for external usb hard drives

6 Upvotes

I have been tasked to create a server to back up the various external hard drives that we receive from customers. I am fairly new to linux. I am open to either debian or Fedora distros but don't have a clue on which backup app to use. I also need to be able to delete the backup files automatically after 7 days. Any suggestions


r/linux_programming • • Apr 20 '23

A love letter to make

Thumbnail kmaasrud.com
6 Upvotes

r/linux_programming • • Apr 09 '23

Writing a Simple Garbage Collector in C

Thumbnail maplant.com
6 Upvotes

r/linux_programming • • Apr 03 '23

Linux 6.3-rc5 Released - Looking To Be In Good Shape

Thumbnail
phoronix.com
6 Upvotes

r/linux_programming • • Mar 16 '23

How did Dennis Ritchie Produce his PhD Thesis? A Typographical Mystery ....(Stole it from Colin Ian King's share on another channel)

Thumbnail cs.princeton.edu
6 Upvotes

r/linux_programming • • Feb 23 '23

Linux Performance Patches Revved To Avoid Too Many Unnecessary Cross-CPU Wake-ups

Thumbnail
phoronix.com
6 Upvotes

r/linux_programming • • Feb 13 '23

Practical parsing with Flex and Bison

Thumbnail begriffs.com
6 Upvotes

r/linux_programming • • Jan 20 '23

wanting to make a text expander app

6 Upvotes

So I've been having a hell of a time getting Amy text expander app to work with Linux, I've tried 3 and they all I could. Not get to install, were dead in development or can't run with my system, so I was thinking how hard ccould it be to just make one, It would just paste a stores txt snippet whenever I typed the magic key combo such as REI . You could store all of the saved snippets then call them like variables do. i know I am greatly simplifying this but you get the idea. In case you don't know what a txt expander is, its a app that saves you time by saving common phrases that you type often. So instead of typing your entire address you would just type ady and the program would auto paste your address. Anyway what do you think?


r/linux_programming • • Nov 19 '22

Reboot function without an included libraries

6 Upvotes

Hi, I recently desided to brush up on my c while learning about the linux kernel api. The first thing I did was to reboot my system from inside my c program (which was very easy) here's that code:

#include <unistd.h>
#include <sys/syscall.h>
#include <linux/reboot.h>

int main() {
    reboot(LINUX_REBOOT_CMD_RESTART);
    return 0;
}

That worked exactly as intended (with a warning from gcc), but when I looked at /usr/include/linux/reboot.h I can see that there was no reboot function defined. So I decided to not include any files, and just call reboot with the hex code in the reboot.h file:

int main(){
    reboot(0x01234567);
    return 0;
}

So what's going on here?

Why does gcc do this?

Would this work on Windows or macOS?

I'm not new to coding or linux, but I am new to low level programming in c, and new to the linux kernel, so an explanation would be nice.


r/linux_programming • • Nov 18 '22

Implementing a nested transport protocol on a noisy channel

6 Upvotes

I need to write two programs able to communicate with each other over a noisy communication channel.
Both programs can write characters on this channel and receive characters written by the other program, but there might be noise/errors/interference: some characters you write may never get delivered, or extra characters may be delivered at any point.

If the error is too much, the two programs may never be able to communicate at all (all the characters a process write can go lost, for instance), but I can hope that the error is not much, and would like to make the two programs able to communicate as well as possible, best-effort.

The first solution I can think of, is to basically implement a transport layer like TCP to transmit the data: something that offers error detection, retransmission and reordering and so on...
However TCP is usually implemented on packets, while I'm working on characters... I guess I can transfer data in chunks (packets), but I suspect that the optimal packet size should vary dynamically depending on the noise (similar to TCP's congestion control, which I don't need otherwise). I'm also afraid of implementing TCP because it sounds quite easy to make hard-to-catch mistakes and to come up with slow/suboptimal implementations.

To further complicate things, I wish my transport layer to support "nesting", at least on one side: a program (only the first one of the two) should be able to send child streams together with its data (and children can have further children, recursively); the other program should be able to send replies to one specific stream.
Should this be implemented in the transport layer, or the application one? I think this should be an abstraction above the transport layer, but it's definitely not application layer...

So, I'm a bit lost. Is there any project that does something similar? Do you have any insights or tips on what to try?


r/linux_programming • • Oct 12 '22

Can I and how do I install RST from to fix SSD showing up as USB?

Thumbnail
gallery
6 Upvotes

r/linux_programming • • Jul 18 '22

X11 vs Framebuffer hardware accel.

6 Upvotes

Hey,

I was wondering what technique the X11/X-Servers use to accelerate the drawing of windows etc.

I know that a lot of applications can then choose to use e.g. OpenGL, SDL, but what does X use if the OS is just running its DE on it?

Is it DE dependent?

I wrote a small C++ program which allows me to write to the framebuffer at /dev/fb0, but I draw everything using the CPU which takes a lot of time.

How can I achieve "simple" grahics acceleration like X does in order to draw multiple e.g. Windows, Strings, Buttons, Images etc?

I do not want to move to OpenGL or similar since it would change my rendering structure, I do not want to render everything from images/textures from a spritesheet.

I just find it hard to get into Qt or similar Frameworks, especially if I would just want to draw simple Interfaces.

Thanks!