Skip to content

Instantly share code, notes, and snippets.

View pavly-gerges's full-sized avatar
🤖
Electrostat Lab.

Pavly Gerges (pavl_g) pavly-gerges

🤖
Electrostat Lab.
View GitHub Profile
@pavly-gerges
pavly-gerges / ioctl.h
Created May 31, 2024 09:35
Generic IOCTL Macro Functions for all IOCTL routing controls @ `/usr/include/asm-generic/ioctl.h`.
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_GENERIC_IOCTL_H
#define _ASM_GENERIC_IOCTL_H
/* ioctl command encoding: 32 bits total, command in lower 16 bits,
* size of the parameter structure in the lower 14 bits of the
* upper 16 bits.
* Encoding the size of the parameter structure in the ioctl request
* is useful for catching programs compiled with old versions
* and to avoid overwriting user space outside the user buffer area.
@pavly-gerges
pavly-gerges / termios.h
Created May 31, 2024 09:31
/usr/include/asm-generic/termios.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_GENERIC_TERMIOS_H
#define _ASM_GENERIC_TERMIOS_H
/*
* Most architectures have straight copies of the x86 code, with
* varying levels of bug fixes on top. Usually it's a good idea
* to use this generic version instead, but be careful to avoid
* ABI changes.
* New architectures should not provide their own version.
*/
@pavly-gerges
pavly-gerges / parport.h
Created May 31, 2024 09:09
Linux `parport.h` IOCTL Magic Macros
/*
* Any part of this program may be used in documents licensed under
* the GNU Free Documentation License, Version 1.1 or any later version
* published by the Free Software Foundation.
*/
#ifndef _PARPORT_H_
#define _PARPORT_H_
/* Start off with user-visible constants */
@pavly-gerges
pavly-gerges / free_buffer_cells.c
Created September 19, 2023 22:24
Example for freeing buffer cells of a pointer to a pointer
// Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static inline void freeBufferCells(void** buffer, int count) {
for (int i = 0; i < count; i++) {
free(buffer[i]);
buffer[i] = NULL;
}
git rm -r --cached .
git add .
git commit -m "fixing .gitignore"
@pavly-gerges
pavly-gerges / Disassemble.as
Created April 24, 2023 19:29
Disassemble code
└──╼ $./avr-objdump -S '/home/twisted/GradleProjects/ShiftAvr/shiftavr-examples/build/atmega328p/hello_gpio_write.c.elf'
/home/twisted/GradleProjects/ShiftAvr/shiftavr-examples/build/atmega328p/hello_gpio_write.c.elf: file format elf32-avr
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 34 00 jmp 0x68 ; 0x68 <__ctors_end>
4: 0c 94 46 00 jmp 0x8c ; 0x8c <__bad_interrupt>
@pavly-gerges
pavly-gerges / Wrapper.java
Last active April 8, 2023 09:18
Generics in java
public class Wrapper {
private Object object;
public Wrapper(Object object) {
this.object = object;
}
public void setObject(Object object) {
this.object = object;
}
import java.util.ArrayList;
class TestSuperCapture {
static class TestSuper {}
static class TestSub extends TestSuper {}
static class TestSub2 extends TestSub {}
static class TestSub3 extends TestSub2 {}
public static void main(String[] args) {
@pavly-gerges
pavly-gerges / jlong_implement.c
Last active March 27, 2023 23:23
Test void* to jlong implicit type-conversion.
#include <stdio.h>
#include <stdlib.h>
/* define a non-system-specific pointer type that can hold an address of up-to 8-bytes */
typedef long long jlong;
jlong Java_util_getAddress() {
int* x = malloc(sizeof(int));
*x = 2312;
void* address = x;
@pavly-gerges
pavly-gerges / star_matrix.c
Last active March 7, 2023 23:58
Tests a clean way of printing star matrices
#include <stdio.h>
/** Header file */
typedef struct {
int rows;
int columns;
} StarMatrixMetadata;
void print_star_matrix(StarMatrixMetadata metadata);