From f0bd9763ea4be22f0f235c0f3aa6628944a56c7e Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Thu, 6 May 2021 14:28:59 +0200 Subject: Aktualizacja --- Semestr 4/ask/lista7/zad7.ll | 174 +++++++ Semestr 4/ask/lista8/._lista_8 | Bin 0 -> 212 bytes Semestr 4/ask/lista8/ask21_lista_8.tgz | Bin 0 -> 2136 bytes Semestr 4/ask/lista8/bar.c | 5 + Semestr 4/ask/lista8/even.c | 8 + Semestr 4/ask/lista8/foo.c | 5 + Semestr 4/ask/lista8/lazy.c | 7 + Semestr 4/ask/lista8/main.lds | 39 ++ Semestr 4/ask/lista8/merge-1.map | 300 ++++++++++++ Semestr 4/ask/lista8/merge-2.map | 301 ++++++++++++ Semestr 4/ask/lista8/mismatch-a.c | 7 + Semestr 4/ask/lista8/mismatch-b.c | 8 + Semestr 4/ask/lista8/odd.c | 8 + Semestr 4/ask/lista8/relo3.c | 15 + Semestr 4/ask/lista8/start.c | 8 + Semestr 4/ask/lista8/str-a.c | 10 + Semestr 4/ask/lista8/str-b.c | 9 + Semestr 4/ask/lista8/swap.c | 18 + Semestr 4/ask/lista9/gadget.s | 16 + Semestr 4/ask/lista9/lazy.c | 7 + Semestr 4/ask/lista9/lista_9.tgz | Bin 0 -> 1278 bytes Semestr 4/ask/lista9/relo3.c | 15 + Semestr 4/ask/lista9/ropex.c | 31 ++ Semestr 4/ask/lista9/ropex.in (1).txt | 7 + Semestr 4/ask/lista9/ropex.in.txt | 7 + Semestr 4/ask/lista9/ropex.map | 511 +++++++++++++++++++++ Semestr 4/ask/lista9/test.c | 7 + Semestr 4/ask/lista9/test.s | 50 ++ Semestr 4/pstwo/wyklady/Wyklad 9.pdf | Bin 0 -> 2971703 bytes Semestr 4/rr1r/kol1/kol1.xopp | Bin 0 -> 890 bytes Semestr 4/rr1r/kol1/zad1.pdf | Bin 0 -> 510360 bytes Semestr 4/rr1r/kol1/zad2.pdf | Bin 0 -> 620724 bytes Semestr 4/rr1r/kol1/zad3.pdf | Bin 0 -> 658285 bytes Semestr 4/rr1r/lista8/L8.pdf | Bin 0 -> 1064722 bytes .../sieci/pracownia2/franciszek_malinka.tar.xz | Bin 0 -> 6012 bytes .../sieci/pracownia2/franciszek_malinka/config.h | 15 + .../pracownia2/franciszek_malinka/dist_vector.c | 114 +++++ .../pracownia2/franciszek_malinka/dist_vector.h | 36 ++ .../pracownia2/franciszek_malinka/linked_list.c | 79 ++++ .../pracownia2/franciszek_malinka/linked_list.h | 42 ++ .../sieci/pracownia2/franciszek_malinka/makefile | 34 ++ .../pracownia2/franciszek_malinka/network_addr.c | 65 +++ .../pracownia2/franciszek_malinka/network_addr.h | 28 ++ .../sieci/pracownia2/franciszek_malinka/router.c | 60 +++ .../sieci/pracownia2/franciszek_malinka/test.c | 52 +++ .../sieci/pracownia2/franciszek_malinka/utils.c | 208 +++++++++ .../sieci/pracownia2/franciszek_malinka/utils.h | 52 +++ 47 files changed, 2358 insertions(+) create mode 100644 Semestr 4/ask/lista7/zad7.ll create mode 100755 Semestr 4/ask/lista8/._lista_8 create mode 100644 Semestr 4/ask/lista8/ask21_lista_8.tgz create mode 100644 Semestr 4/ask/lista8/bar.c create mode 100644 Semestr 4/ask/lista8/even.c create mode 100644 Semestr 4/ask/lista8/foo.c create mode 100644 Semestr 4/ask/lista8/lazy.c create mode 100644 Semestr 4/ask/lista8/main.lds create mode 100644 Semestr 4/ask/lista8/merge-1.map create mode 100644 Semestr 4/ask/lista8/merge-2.map create mode 100644 Semestr 4/ask/lista8/mismatch-a.c create mode 100644 Semestr 4/ask/lista8/mismatch-b.c create mode 100644 Semestr 4/ask/lista8/odd.c create mode 100644 Semestr 4/ask/lista8/relo3.c create mode 100644 Semestr 4/ask/lista8/start.c create mode 100644 Semestr 4/ask/lista8/str-a.c create mode 100644 Semestr 4/ask/lista8/str-b.c create mode 100644 Semestr 4/ask/lista8/swap.c create mode 100644 Semestr 4/ask/lista9/gadget.s create mode 100644 Semestr 4/ask/lista9/lazy.c create mode 100644 Semestr 4/ask/lista9/lista_9.tgz create mode 100644 Semestr 4/ask/lista9/relo3.c create mode 100644 Semestr 4/ask/lista9/ropex.c create mode 100644 Semestr 4/ask/lista9/ropex.in (1).txt create mode 100644 Semestr 4/ask/lista9/ropex.in.txt create mode 100644 Semestr 4/ask/lista9/ropex.map create mode 100644 Semestr 4/ask/lista9/test.c create mode 100644 Semestr 4/ask/lista9/test.s create mode 100644 Semestr 4/pstwo/wyklady/Wyklad 9.pdf create mode 100644 Semestr 4/rr1r/kol1/kol1.xopp create mode 100644 Semestr 4/rr1r/kol1/zad1.pdf create mode 100644 Semestr 4/rr1r/kol1/zad2.pdf create mode 100644 Semestr 4/rr1r/kol1/zad3.pdf create mode 100644 Semestr 4/rr1r/lista8/L8.pdf create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka.tar.xz create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/config.h create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.h create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.h create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/makefile create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.h create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/router.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/test.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/utils.c create mode 100644 Semestr 4/sieci/pracownia2/franciszek_malinka/utils.h diff --git a/Semestr 4/ask/lista7/zad7.ll b/Semestr 4/ask/lista7/zad7.ll new file mode 100644 index 0000000..a99e8d8 --- /dev/null +++ b/Semestr 4/ask/lista7/zad7.ll @@ -0,0 +1,174 @@ +; ModuleID = 'zad7.cpp' +source_filename = "zad7.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" + +%struct.Base = type <{ i32 (...)**, i32, [4 x i8] }> +%struct.Derived = type { %struct.Base.base, [4 x i8] } +%struct.Base.base = type <{ i32 (...)**, i32 }> + +$_ZN4BaseC1Ei = comdat any + +$_ZN7DerivedC1Ei = comdat any + +$_ZN4BaseC2Ei = comdat any + +$_ZN4Base4doitEi = comdat any + +$_ZN7DerivedC2Ei = comdat any + +$_ZN7Derived4doitEi = comdat any + +$_ZTV4Base = comdat any + +$_ZTS4Base = comdat any + +$_ZTI4Base = comdat any + +$_ZTV7Derived = comdat any + +$_ZTS7Derived = comdat any + +$_ZTI7Derived = comdat any + +@_ZTV4Base = linkonce_odr unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI4Base to i8*), i8* bitcast (i32 (%struct.Base*, i32)* @_ZN4Base4doitEi to i8*)] }, comdat, align 8 +@_ZTVN10__cxxabiv117__class_type_infoE = external global i8* +@_ZTS4Base = linkonce_odr constant [6 x i8] c"4Base\00", comdat, align 1 +@_ZTI4Base = linkonce_odr constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @_ZTS4Base, i32 0, i32 0) }, comdat, align 8 +@_ZTV7Derived = linkonce_odr unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI7Derived to i8*), i8* bitcast (i32 (%struct.Derived*, i32)* @_ZN7Derived4doitEi to i8*)] }, comdat, align 8 +@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8* +@_ZTS7Derived = linkonce_odr constant [9 x i8] c"7Derived\00", comdat, align 1 +@_ZTI7Derived = linkonce_odr constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @_ZTS7Derived, i32 0, i32 0), i8* bitcast ({ i8*, i8* }* @_ZTI4Base to i8*) }, comdat, align 8 + +; Function Attrs: noinline nounwind optnone +define i32 @_Z4doitP4Base(%struct.Base* %bp) #0 { +entry: + %bp.addr = alloca %struct.Base*, align 8 + store %struct.Base* %bp, %struct.Base** %bp.addr, align 8 + %0 = load %struct.Base*, %struct.Base** %bp.addr, align 8 + %1 = bitcast %struct.Base* %0 to i32 (%struct.Base*, i32)*** + %vtable = load i32 (%struct.Base*, i32)**, i32 (%struct.Base*, i32)*** %1, align 8 + %vfn = getelementptr inbounds i32 (%struct.Base*, i32)*, i32 (%struct.Base*, i32)** %vtable, i64 0 + %2 = load i32 (%struct.Base*, i32)*, i32 (%struct.Base*, i32)** %vfn, align 8 + %call = call i32 %2(%struct.Base* %0, i32 1) + ret i32 %call +} + +; Function Attrs: noinline norecurse nounwind optnone +define i32 @main(i32 %argc, i8** %argv) #1 { +entry: + %retval = alloca i32, align 4 + %argc.addr = alloca i32, align 4 + %argv.addr = alloca i8**, align 8 + %b = alloca %struct.Base, align 8 + %d = alloca %struct.Derived, align 8 + store i32 0, i32* %retval, align 4 + store i32 %argc, i32* %argc.addr, align 4 + store i8** %argv, i8*** %argv.addr, align 8 + call void @_ZN4BaseC1Ei(%struct.Base* %b, i32 10) + call void @_ZN7DerivedC1Ei(%struct.Derived* %d, i32 20) + %call = call i32 @_Z4doitP4Base(%struct.Base* %b) + %0 = bitcast %struct.Derived* %d to %struct.Base* + %call1 = call i32 @_Z4doitP4Base(%struct.Base* %0) + %add = add nsw i32 %call, %call1 + ret i32 %add +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr void @_ZN4BaseC1Ei(%struct.Base* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Base*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Base* %this, %struct.Base** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Base*, %struct.Base** %this.addr, align 8 + %0 = load i32, i32* %n.addr, align 4 + call void @_ZN4BaseC2Ei(%struct.Base* %this1, i32 %0) + ret void +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr void @_ZN7DerivedC1Ei(%struct.Derived* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Derived*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Derived* %this, %struct.Derived** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Derived*, %struct.Derived** %this.addr, align 8 + %0 = load i32, i32* %n.addr, align 4 + call void @_ZN7DerivedC2Ei(%struct.Derived* %this1, i32 %0) + ret void +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr void @_ZN4BaseC2Ei(%struct.Base* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Base*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Base* %this, %struct.Base** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Base*, %struct.Base** %this.addr, align 8 + %0 = bitcast %struct.Base* %this1 to i32 (...)*** + store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV4Base, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %0, align 8 + %data = getelementptr inbounds %struct.Base, %struct.Base* %this1, i32 0, i32 1 + %1 = load i32, i32* %n.addr, align 4 + store i32 %1, i32* %data, align 8 + ret void +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr i32 @_ZN4Base4doitEi(%struct.Base* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Base*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Base* %this, %struct.Base** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Base*, %struct.Base** %this.addr, align 8 + %0 = load i32, i32* %n.addr, align 4 + %data = getelementptr inbounds %struct.Base, %struct.Base* %this1, i32 0, i32 1 + %1 = load i32, i32* %data, align 8 + %sub = sub nsw i32 %0, %1 + ret i32 %sub +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr void @_ZN7DerivedC2Ei(%struct.Derived* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Derived*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Derived* %this, %struct.Derived** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Derived*, %struct.Derived** %this.addr, align 8 + %0 = bitcast %struct.Derived* %this1 to %struct.Base* + %1 = load i32, i32* %n.addr, align 4 + %add = add nsw i32 %1, 1 + call void @_ZN4BaseC2Ei(%struct.Base* %0, i32 %add) + %2 = bitcast %struct.Derived* %this1 to i32 (...)*** + store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV7Derived, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %2, align 8 + ret void +} + +; Function Attrs: noinline nounwind optnone +define linkonce_odr i32 @_ZN7Derived4doitEi(%struct.Derived* %this, i32 %n) unnamed_addr #0 comdat align 2 { +entry: + %this.addr = alloca %struct.Derived*, align 8 + %n.addr = alloca i32, align 4 + store %struct.Derived* %this, %struct.Derived** %this.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + %this1 = load %struct.Derived*, %struct.Derived** %this.addr, align 8 + %0 = load i32, i32* %n.addr, align 4 + %1 = bitcast %struct.Derived* %this1 to %struct.Base* + %data = getelementptr inbounds %struct.Base, %struct.Base* %1, i32 0, i32 1 + %2 = load i32, i32* %data, align 8 + %mul = mul nsw i32 %0, %2 + ret i32 %mul +} + +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { noinline norecurse nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 10.0.0-4ubuntu1 "} diff --git a/Semestr 4/ask/lista8/._lista_8 b/Semestr 4/ask/lista8/._lista_8 new file mode 100755 index 0000000..893436c Binary files /dev/null and b/Semestr 4/ask/lista8/._lista_8 differ diff --git a/Semestr 4/ask/lista8/ask21_lista_8.tgz b/Semestr 4/ask/lista8/ask21_lista_8.tgz new file mode 100644 index 0000000..789c9af Binary files /dev/null and b/Semestr 4/ask/lista8/ask21_lista_8.tgz differ diff --git a/Semestr 4/ask/lista8/bar.c b/Semestr 4/ask/lista8/bar.c new file mode 100644 index 0000000..97fbd4f --- /dev/null +++ b/Semestr 4/ask/lista8/bar.c @@ -0,0 +1,5 @@ +// extern long foo; + +int bar = 42; +// long *foo_p = &foo; +short dead[15]; diff --git a/Semestr 4/ask/lista8/even.c b/Semestr 4/ask/lista8/even.c new file mode 100644 index 0000000..5bf8606 --- /dev/null +++ b/Semestr 4/ask/lista8/even.c @@ -0,0 +1,8 @@ +int is_odd(long n); + +int is_even(long n) { + if (n == 0) + return 1; + else + return is_odd(n - 1); +} diff --git a/Semestr 4/ask/lista8/foo.c b/Semestr 4/ask/lista8/foo.c new file mode 100644 index 0000000..080d831 --- /dev/null +++ b/Semestr 4/ask/lista8/foo.c @@ -0,0 +1,5 @@ +// extern int bar; + +long foo = 19; +// int *bar_p = &bar; +char code[17]; diff --git a/Semestr 4/ask/lista8/lazy.c b/Semestr 4/ask/lista8/lazy.c new file mode 100644 index 0000000..fb08cf7 --- /dev/null +++ b/Semestr 4/ask/lista8/lazy.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + puts("first time"); + puts("second time"); + return 0; +} diff --git a/Semestr 4/ask/lista8/main.lds b/Semestr 4/ask/lista8/main.lds new file mode 100644 index 0000000..25a4ca9 --- /dev/null +++ b/Semestr 4/ask/lista8/main.lds @@ -0,0 +1,39 @@ +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) +ENTRY(_start) +PHDRS +{ + code PT_LOAD FLAGS(5); + rodata PT_LOAD FLAGS(4); + data PT_LOAD FLAGS(6); +} +SECTIONS +{ + . = 0x400000 + SIZEOF_HEADERS; + + .text : + { + *(.text .text.*) + } : code + + .rodata : + { + *(.rodata .rodata.*) + } : rodata + + .data : + { + *(.data .data.*) + } : data + + .bss : + { + *(.bss .bss.*) + *(COMMON) + } : data + + /DISCARD/ : + { + *(.note.gnu.property) + } +} diff --git a/Semestr 4/ask/lista8/merge-1.map b/Semestr 4/ask/lista8/merge-1.map new file mode 100644 index 0000000..2e93e7c --- /dev/null +++ b/Semestr 4/ask/lista8/merge-1.map @@ -0,0 +1,300 @@ + +Merging program properties + + +Discarded input sections + + .note.gnu.property + 0x0000000000000000 0x20 bar.o + +Memory Configuration + +Name Origin Length Attributes +*default* 0x0000000000000000 0xffffffffffffffff + +Linker script and memory map + +LOAD foo.o +LOAD bar.o + +.interp + *(.interp) + +.note.gnu.property + 0x0000000000000000 0x20 + .note.gnu.property + 0x0000000000000000 0x20 foo.o + +.note.gnu.build-id + *(.note.gnu.build-id) + +.hash + *(.hash) + +.gnu.hash + *(.gnu.hash) + +.dynsym + *(.dynsym) + +.dynstr + *(.dynstr) + +.gnu.version + *(.gnu.version) + +.gnu.version_d + *(.gnu.version_d) + +.gnu.version_r + *(.gnu.version_r) + +.rela.init + *(.rela.init) + +.rela.text + *(.rela.text) + +.rela.fini + *(.rela.fini) + +.rela.rodata + *(.rela.rodata) + +.rela.data.rel.ro + *(.rela.data.rel.ro) + +.rela.data + *(.rela.data) + +.rela.tdata + *(.rela.tdata) + +.rela.tbss + *(.rela.tbss) + +.rela.ctors + *(.rela.ctors) + +.rela.dtors + *(.rela.dtors) + +.rela.got + *(.rela.got) + +.rela.bss + *(.rela.bss) + +.rela.ldata + *(.rela.ldata) + +.rela.lbss + *(.rela.lbss) + +.rela.lrodata + *(.rela.lrodata) + +.rela.ifunc + *(.rela.ifunc) + +.rela.plt + *(.rela.plt) + +.init + *(SORT_NONE(.init)) + +.plt + *(.plt) + +.plt.got + *(.plt.got) + +.plt.sec + *(.plt.sec) + +.text 0x0000000000000000 0x0 + *(.text .stub) + .text 0x0000000000000000 0x0 foo.o + .text 0x0000000000000000 0x0 bar.o + *(.gnu.warning) + +.fini + *(SORT_NONE(.fini)) + +.rodata + *(.rodata) + +.rodata1 + *(.rodata1) + +.eh_frame_hdr + *(.eh_frame_hdr) + +.eh_frame + *(.eh_frame) + +.gcc_except_table + *(.gcc_except_table) + +.gnu_extab + *(.gnu_extab*) + +.exception_ranges + *(.exception_ranges) + +.eh_frame + *(.eh_frame) + +.gnu_extab + *(.gnu_extab) + +.gcc_except_table + *(.gcc_except_table) + +.exception_ranges + *(.exception_ranges) + +.tdata + *(.tdata) + +.tbss + *(.tbss) + +.jcr + *(.jcr) + +.dynamic + *(.dynamic) + +.got + *(.got) + +.got.plt + *(.got.plt) + +.data 0x0000000000000000 0xc + *(.data) + .data 0x0000000000000000 0x8 foo.o + 0x0000000000000000 foo + .data 0x0000000000000008 0x4 bar.o + 0x0000000000000008 bar + +.data1 + *(.data1) + +.bss 0x0000000000000000 0x3e + *(.bss) + .bss 0x0000000000000000 0x11 foo.o + 0x0000000000000000 code + *fill* 0x0000000000000011 0xf + .bss 0x0000000000000020 0x1e bar.o + 0x0000000000000020 dead + +.lbss + *(.lbss) + +.lrodata + *(.lrodata) + +.ldata + *(.ldata) + +.stab + *(.stab) + +.stabstr + *(.stabstr) + +.stab.excl + *(.stab.excl) + +.stab.exclstr + *(.stab.exclstr) + +.stab.index + *(.stab.index) + +.stab.indexstr + *(.stab.indexstr) + +.comment 0x0000000000000000 0x56 + *(.comment) + .comment 0x0000000000000000 0x2b foo.o + .comment 0x000000000000002b 0x2b bar.o + +.note.GNU-stack + 0x0000000000000000 0x0 + .note.GNU-stack + 0x0000000000000000 0x0 foo.o + .note.GNU-stack + 0x0000000000000000 0x0 bar.o + +.gnu.build.attributes + *(.gnu.build.attributes) + +.debug + *(.debug) + +.line + *(.line) + +.debug_srcinfo + *(.debug_srcinfo) + +.debug_sfnames + *(.debug_sfnames) + +.debug_aranges + *(.debug_aranges) + +.debug_pubnames + *(.debug_pubnames) + +.debug_info + *(.debug_info) + +.debug_abbrev + *(.debug_abbrev) + +.debug_line + *(.debug_line) + +.debug_frame + *(.debug_frame) + +.debug_str + *(.debug_str) + +.debug_loc + *(.debug_loc) + +.debug_macinfo + *(.debug_macinfo) + +.debug_weaknames + *(.debug_weaknames) + +.debug_funcnames + *(.debug_funcnames) + +.debug_typenames + *(.debug_typenames) + +.debug_varnames + *(.debug_varnames) + +.debug_pubtypes + *(.debug_pubtypes) + +.debug_ranges + *(.debug_ranges) + +.debug_macro + *(.debug_macro) + +.debug_addr + *(.debug_addr) + +.gnu.attributes + *(.gnu.attributes) +OUTPUT(merge-1.o elf64-x86-64) diff --git a/Semestr 4/ask/lista8/merge-2.map b/Semestr 4/ask/lista8/merge-2.map new file mode 100644 index 0000000..2677803 --- /dev/null +++ b/Semestr 4/ask/lista8/merge-2.map @@ -0,0 +1,301 @@ + +Merging program properties + + +Discarded input sections + + .note.gnu.property + 0x0000000000000000 0x20 foo.o + +Memory Configuration + +Name Origin Length Attributes +*default* 0x0000000000000000 0xffffffffffffffff + +Linker script and memory map + +LOAD bar.o +LOAD foo.o + +.interp + *(.interp) + +.note.gnu.property + 0x0000000000000000 0x20 + .note.gnu.property + 0x0000000000000000 0x20 bar.o + +.note.gnu.build-id + *(.note.gnu.build-id) + +.hash + *(.hash) + +.gnu.hash + *(.gnu.hash) + +.dynsym + *(.dynsym) + +.dynstr + *(.dynstr) + +.gnu.version + *(.gnu.version) + +.gnu.version_d + *(.gnu.version_d) + +.gnu.version_r + *(.gnu.version_r) + +.rela.init + *(.rela.init) + +.rela.text + *(.rela.text) + +.rela.fini + *(.rela.fini) + +.rela.rodata + *(.rela.rodata) + +.rela.data.rel.ro + *(.rela.data.rel.ro) + +.rela.data + *(.rela.data) + +.rela.tdata + *(.rela.tdata) + +.rela.tbss + *(.rela.tbss) + +.rela.ctors + *(.rela.ctors) + +.rela.dtors + *(.rela.dtors) + +.rela.got + *(.rela.got) + +.rela.bss + *(.rela.bss) + +.rela.ldata + *(.rela.ldata) + +.rela.lbss + *(.rela.lbss) + +.rela.lrodata + *(.rela.lrodata) + +.rela.ifunc + *(.rela.ifunc) + +.rela.plt + *(.rela.plt) + +.init + *(SORT_NONE(.init)) + +.plt + *(.plt) + +.plt.got + *(.plt.got) + +.plt.sec + *(.plt.sec) + +.text 0x0000000000000000 0x0 + *(.text .stub) + .text 0x0000000000000000 0x0 bar.o + .text 0x0000000000000000 0x0 foo.o + *(.gnu.warning) + +.fini + *(SORT_NONE(.fini)) + +.rodata + *(.rodata) + +.rodata1 + *(.rodata1) + +.eh_frame_hdr + *(.eh_frame_hdr) + +.eh_frame + *(.eh_frame) + +.gcc_except_table + *(.gcc_except_table) + +.gnu_extab + *(.gnu_extab*) + +.exception_ranges + *(.exception_ranges) + +.eh_frame + *(.eh_frame) + +.gnu_extab + *(.gnu_extab) + +.gcc_except_table + *(.gcc_except_table) + +.exception_ranges + *(.exception_ranges) + +.tdata + *(.tdata) + +.tbss + *(.tbss) + +.jcr + *(.jcr) + +.dynamic + *(.dynamic) + +.got + *(.got) + +.got.plt + *(.got.plt) + +.data 0x0000000000000000 0x10 + *(.data) + .data 0x0000000000000000 0x4 bar.o + 0x0000000000000000 bar + *fill* 0x0000000000000004 0x4 + .data 0x0000000000000008 0x8 foo.o + 0x0000000000000008 foo + +.data1 + *(.data1) + +.bss 0x0000000000000000 0x31 + *(.bss) + .bss 0x0000000000000000 0x1e bar.o + 0x0000000000000000 dead + *fill* 0x000000000000001e 0x2 + .bss 0x0000000000000020 0x11 foo.o + 0x0000000000000020 code + +.lbss + *(.lbss) + +.lrodata + *(.lrodata) + +.ldata + *(.ldata) + +.stab + *(.stab) + +.stabstr + *(.stabstr) + +.stab.excl + *(.stab.excl) + +.stab.exclstr + *(.stab.exclstr) + +.stab.index + *(.stab.index) + +.stab.indexstr + *(.stab.indexstr) + +.comment 0x0000000000000000 0x56 + *(.comment) + .comment 0x0000000000000000 0x2b bar.o + .comment 0x000000000000002b 0x2b foo.o + +.note.GNU-stack + 0x0000000000000000 0x0 + .note.GNU-stack + 0x0000000000000000 0x0 bar.o + .note.GNU-stack + 0x0000000000000000 0x0 foo.o + +.gnu.build.attributes + *(.gnu.build.attributes) + +.debug + *(.debug) + +.line + *(.line) + +.debug_srcinfo + *(.debug_srcinfo) + +.debug_sfnames + *(.debug_sfnames) + +.debug_aranges + *(.debug_aranges) + +.debug_pubnames + *(.debug_pubnames) + +.debug_info + *(.debug_info) + +.debug_abbrev + *(.debug_abbrev) + +.debug_line + *(.debug_line) + +.debug_frame + *(.debug_frame) + +.debug_str + *(.debug_str) + +.debug_loc + *(.debug_loc) + +.debug_macinfo + *(.debug_macinfo) + +.debug_weaknames + *(.debug_weaknames) + +.debug_funcnames + *(.debug_funcnames) + +.debug_typenames + *(.debug_typenames) + +.debug_varnames + *(.debug_varnames) + +.debug_pubtypes + *(.debug_pubtypes) + +.debug_ranges + *(.debug_ranges) + +.debug_macro + *(.debug_macro) + +.debug_addr + *(.debug_addr) + +.gnu.attributes + *(.gnu.attributes) +OUTPUT(merge-2.o elf64-x86-64) diff --git a/Semestr 4/ask/lista8/mismatch-a.c b/Semestr 4/ask/lista8/mismatch-a.c new file mode 100644 index 0000000..39436f2 --- /dev/null +++ b/Semestr 4/ask/lista8/mismatch-a.c @@ -0,0 +1,7 @@ +/* mismatch-a.c */ +void p2(void); + +int main() { + p2(); + return 0; +} diff --git a/Semestr 4/ask/lista8/mismatch-b.c b/Semestr 4/ask/lista8/mismatch-b.c new file mode 100644 index 0000000..451d5b3 --- /dev/null +++ b/Semestr 4/ask/lista8/mismatch-b.c @@ -0,0 +1,8 @@ +/* mismatch-b.c */ +#include + +char main; + +void p2() { + printf("0x%x\n", main); +} diff --git a/Semestr 4/ask/lista8/odd.c b/Semestr 4/ask/lista8/odd.c new file mode 100644 index 0000000..c32961e --- /dev/null +++ b/Semestr 4/ask/lista8/odd.c @@ -0,0 +1,8 @@ +int is_even(long n); + +int is_odd(long n) { + if (n == 0) + return 0; + else + return is_even(n - 1); +} diff --git a/Semestr 4/ask/lista8/relo3.c b/Semestr 4/ask/lista8/relo3.c new file mode 100644 index 0000000..6aca7b6 --- /dev/null +++ b/Semestr 4/ask/lista8/relo3.c @@ -0,0 +1,15 @@ +int relo3(int val) { + switch (val) { + case 100: + return val; + case 101: + return val + 1; + case 103: + case 104: + return val + 3; + case 105: + return val + 5; + default: + return val + 6; + } +} diff --git a/Semestr 4/ask/lista8/start.c b/Semestr 4/ask/lista8/start.c new file mode 100644 index 0000000..a875ace --- /dev/null +++ b/Semestr 4/ask/lista8/start.c @@ -0,0 +1,8 @@ +int is_even(long); + +void _start(void) { + asm volatile( + "syscall" + : /* no output */ + : "a" (0x3c), "D" (is_even(42))); +} diff --git a/Semestr 4/ask/lista8/str-a.c b/Semestr 4/ask/lista8/str-a.c new file mode 100644 index 0000000..3b0fb36 --- /dev/null +++ b/Semestr 4/ask/lista8/str-a.c @@ -0,0 +1,10 @@ +#include + +char *somestr(void); + +int main(void) { + char *s = somestr(); + s[5] = '\0'; + puts(s); + return 0; +} diff --git a/Semestr 4/ask/lista8/str-b.c b/Semestr 4/ask/lista8/str-b.c new file mode 100644 index 0000000..50101cb --- /dev/null +++ b/Semestr 4/ask/lista8/str-b.c @@ -0,0 +1,9 @@ +#include +#include + +char *somestr(void) { + char *buf = malloc(sizeof("Hello, world!")); + strcpy(buf, "Hello, world!"); + return buf; +} + diff --git a/Semestr 4/ask/lista8/swap.c b/Semestr 4/ask/lista8/swap.c new file mode 100644 index 0000000..e1966fd --- /dev/null +++ b/Semestr 4/ask/lista8/swap.c @@ -0,0 +1,18 @@ +extern int buf[]; + +int *bufp0 = &buf[0]; +static int *bufp1; + +static void incr() { + static int count = 0; + count++; +} + +void swap() { + int temp; + incr(); + bufp1 = &buf[1]; + temp = *bufp0; + *bufp0 = *bufp1; + *bufp1 = temp; +} diff --git a/Semestr 4/ask/lista9/gadget.s b/Semestr 4/ask/lista9/gadget.s new file mode 100644 index 0000000..6d60a63 --- /dev/null +++ b/Semestr 4/ask/lista9/gadget.s @@ -0,0 +1,16 @@ + .global gadget + + .text + +# rax: 0x3c +# rdi: 0 +# rdx: {NULL, ...} +# rsi: path + '\n' +gadget: + dec %rax # rax: 0x3c -> 0x3b (sys_execve) + mov %rdx, %rsi # rsi: argv = {NULL} + mov %rdi, %rdx # rdx: envp = NULL + lea 16(%rsp),%rdi # rdi: path + ret + +# vim: ft=gas diff --git a/Semestr 4/ask/lista9/lazy.c b/Semestr 4/ask/lista9/lazy.c new file mode 100644 index 0000000..fb08cf7 --- /dev/null +++ b/Semestr 4/ask/lista9/lazy.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + puts("first time"); + puts("second time"); + return 0; +} diff --git a/Semestr 4/ask/lista9/lista_9.tgz b/Semestr 4/ask/lista9/lista_9.tgz new file mode 100644 index 0000000..5e5c6f4 Binary files /dev/null and b/Semestr 4/ask/lista9/lista_9.tgz differ diff --git a/Semestr 4/ask/lista9/relo3.c b/Semestr 4/ask/lista9/relo3.c new file mode 100644 index 0000000..6aca7b6 --- /dev/null +++ b/Semestr 4/ask/lista9/relo3.c @@ -0,0 +1,15 @@ +int relo3(int val) { + switch (val) { + case 100: + return val; + case 101: + return val + 1; + case 103: + case 104: + return val + 3; + case 105: + return val + 5; + default: + return val + 6; + } +} diff --git a/Semestr 4/ask/lista9/ropex.c b/Semestr 4/ask/lista9/ropex.c new file mode 100644 index 0000000..dbeae12 --- /dev/null +++ b/Semestr 4/ask/lista9/ropex.c @@ -0,0 +1,31 @@ +#include +#include +#include + +/* Get string from stdin */ +void readline(FILE *in, char *p) { + int c; + while (true) { + c = fgetc(in); + if (c == EOF || c == '\n') + break; + *p++ = c; + } + *p = '\0'; +} + +void echo(FILE *in) { + char buf[48]; + readline(in, buf); + puts(buf); +} + +int main(int argc, char *argv[]) { + FILE *in = NULL; + if (argc == 2) + in = fopen(argv[1], "rb"); + if (in == NULL) + in = stdin; + echo(in); + return 0; +} diff --git a/Semestr 4/ask/lista9/ropex.in (1).txt b/Semestr 4/ask/lista9/ropex.in (1).txt new file mode 100644 index 0000000..902773e --- /dev/null +++ b/Semestr 4/ask/lista9/ropex.in (1).txt @@ -0,0 +1,7 @@ +00000000: dead c0de dead c0de dead c0de dead c0de ................ +00000010: dead c0de dead c0de dead c0de dead c0de ................ +00000020: dead c0de dead c0de dead c0de dead c0de ................ +00000030: dead c0de dead c0de 731c 4000 0000 0000 ................ +00000040: f422 4000 0000 0000 0000 0000 0000 0000 ................ +00000050: 2f75 7372 2f62 696e 2f70 7974 686f 6e32 /usr/bin/python2 +00000060: 000a ................ diff --git a/Semestr 4/ask/lista9/ropex.in.txt b/Semestr 4/ask/lista9/ropex.in.txt new file mode 100644 index 0000000..8deabfe --- /dev/null +++ b/Semestr 4/ask/lista9/ropex.in.txt @@ -0,0 +1,7 @@ +00000000: dead c0de dead c0de dead c0de dead c0de ................ +00000010: dead c0de dead c0de dead c0de dead c0de ................ +00000020: dead c0de dead c0de dead c0de dead c0de ................ +00000030: dead c0de dead c0de 671d 4000 0000 0000 ................ +00000040: 8e44 4900 0000 0000 0000 0000 0000 0000 ................ +00000050: 2f75 7372 2f62 696e 2f6e 7961 6e63 6174 /usr/bin/nyancat +00000060: 000a ................ \ No newline at end of file diff --git a/Semestr 4/ask/lista9/ropex.map b/Semestr 4/ask/lista9/ropex.map new file mode 100644 index 0000000..4bd12a5 --- /dev/null +++ b/Semestr 4/ask/lista9/ropex.map @@ -0,0 +1,511 @@ +Archive member included to satisfy reference by file (symbol) + +/usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (__libc_csu_init) + +Merging program properties + +Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (0x3) and gadget.o (not found) +Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (not found) and /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) (0x3) +Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (not found) and /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o (0x3) +Removed property 0xc0000002 to merge /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (not found) and /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o (0x3) + +As-needed library included to satisfy reference by file (symbol) + +libc.so.6 ropex.o (fopen@@GLIBC_2.2.5) + +Discarded input sections + + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + .note.GNU-stack + 0x0000000000000000 0x0 ropex.o + .note.gnu.property + 0x0000000000000000 0x20 ropex.o + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + .note.gnu.property + 0x0000000000000000 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + .note.GNU-stack + 0x0000000000000000 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + +Memory Configuration + +Name Origin Length Attributes +*default* 0x0000000000000000 0xffffffffffffffff + +Linker script and memory map + +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o +LOAD ropex.o +LOAD gadget.o +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_s.so +START GROUP +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgcc_s.so.1 +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a +END GROUP +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so +START GROUP +LOAD /lib/x86_64-linux-gnu/libc.so.6 +LOAD /usr/lib/x86_64-linux-gnu/libc_nonshared.a +LOAD /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 +END GROUP +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_s.so +START GROUP +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgcc_s.so.1 +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a +END GROUP +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o +LOAD /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + [!provide] PROVIDE (__executable_start = SEGMENT_START ("text-segment", 0x0)) + 0x00000000000002a8 . = (SEGMENT_START ("text-segment", 0x0) + SIZEOF_HEADERS) + +.interp 0x00000000000002a8 0x1c + *(.interp) + .interp 0x00000000000002a8 0x1c /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.note.gnu.build-id + 0x00000000000002c4 0x24 + *(.note.gnu.build-id) + .note.gnu.build-id + 0x00000000000002c4 0x24 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.note.ABI-tag 0x00000000000002e8 0x20 + .note.ABI-tag 0x00000000000002e8 0x20 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.hash + *(.hash) + +.gnu.hash 0x0000000000000308 0x28 + *(.gnu.hash) + .gnu.hash 0x0000000000000308 0x28 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.dynsym 0x0000000000000330 0x108 + *(.dynsym) + .dynsym 0x0000000000000330 0x108 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.dynstr 0x0000000000000438 0xaf + *(.dynstr) + .dynstr 0x0000000000000438 0xaf /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.gnu.version 0x00000000000004e8 0x16 + *(.gnu.version) + .gnu.version 0x00000000000004e8 0x16 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.gnu.version_d 0x0000000000000500 0x0 + *(.gnu.version_d) + .gnu.version_d + 0x0000000000000500 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.gnu.version_r 0x0000000000000500 0x30 + *(.gnu.version_r) + .gnu.version_r + 0x0000000000000500 0x30 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.rela.dyn 0x0000000000000530 0xd8 + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + .rela.text 0x0000000000000530 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + .rela.data.rel.ro + 0x0000000000000530 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .rela.data.rel.local + 0x0000000000000530 0x18 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + .rela.got 0x0000000000000548 0x78 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + .rela.bss 0x00000000000005c0 0x18 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*) + *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*) + *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*) + *(.rela.ifunc) + .rela.ifunc 0x00000000000005d8 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .rela.fini_array + 0x00000000000005d8 0x18 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .rela.init_array + 0x00000000000005f0 0x18 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.rela.plt 0x0000000000000608 0x60 + *(.rela.plt) + .rela.plt 0x0000000000000608 0x60 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.rela.iplt) + 0x0000000000001000 . = ALIGN (CONSTANT (MAXPAGESIZE)) + +.init 0x0000000000001000 0x1b + *(SORT_NONE(.init)) + .init 0x0000000000001000 0x16 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + 0x0000000000001000 _init + .init 0x0000000000001016 0x5 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + +.plt 0x0000000000001020 0x50 + *(.plt) + .plt 0x0000000000001020 0x50 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000001030 puts@@GLIBC_2.2.5 + 0x0000000000001040 __stack_chk_fail@@GLIBC_2.4 + 0x0000000000001050 fgetc@@GLIBC_2.2.5 + 0x0000000000001060 fopen@@GLIBC_2.2.5 + *(.iplt) + +.plt.got 0x0000000000001070 0x8 + *(.plt.got) + .plt.got 0x0000000000001070 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000001070 __cxa_finalize@@GLIBC_2.2.5 + +.plt.sec + *(.plt.sec) + +.text 0x0000000000001080 0x235 + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(SORT_BY_NAME(.text.sorted.*)) + *(.text .stub .text.* .gnu.linkonce.t.*) + .text 0x0000000000001080 0x2f /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000001080 _start + .text 0x00000000000010af 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + *fill* 0x00000000000010af 0x1 + .text 0x00000000000010b0 0xb9 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + .text 0x0000000000001169 0xbb ropex.o + 0x0000000000001169 readline + 0x00000000000011a3 echo + 0x00000000000011e7 main + .text 0x0000000000001224 0xf gadget.o + 0x0000000000001224 gadget + *fill* 0x0000000000001233 0xd + .text 0x0000000000001240 0x75 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + 0x0000000000001240 __libc_csu_init + 0x00000000000012b0 __libc_csu_fini + .text 0x00000000000012b5 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + .text 0x00000000000012b5 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + *(.gnu.warning) + +.fini 0x00000000000012b8 0xd + *(SORT_NONE(.fini)) + .fini 0x00000000000012b8 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + 0x00000000000012b8 _fini + .fini 0x00000000000012c0 0x5 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + [!provide] PROVIDE (__etext = .) + [!provide] PROVIDE (_etext = .) + [!provide] PROVIDE (etext = .) + 0x0000000000002000 . = ALIGN (CONSTANT (MAXPAGESIZE)) + 0x0000000000002000 . = SEGMENT_START ("rodata-segment", (ALIGN (CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 0x1)))) + +.rodata 0x0000000000002000 0x7 + *(.rodata .rodata.* .gnu.linkonce.r.*) + .rodata.cst4 0x0000000000002000 0x4 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000002000 _IO_stdin_used + .rodata.str1.1 + 0x0000000000002004 0x3 ropex.o + +.rodata1 + *(.rodata1) + +.eh_frame_hdr 0x0000000000002008 0x34 + *(.eh_frame_hdr) + .eh_frame_hdr 0x0000000000002008 0x34 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000002008 __GNU_EH_FRAME_HDR + *(.eh_frame_entry .eh_frame_entry.*) + +.eh_frame 0x0000000000002040 0xd0 + *(.eh_frame) + .eh_frame 0x0000000000002040 0x30 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x2c (size before relaxing) + *fill* 0x0000000000002070 0x0 + .eh_frame 0x0000000000002070 0x28 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x40 (size before relaxing) + .eh_frame 0x0000000000002098 0x18 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x30 (size before relaxing) + .eh_frame 0x00000000000020b0 0x5c /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + 0x78 (size before relaxing) + .eh_frame 0x000000000000210c 0x4 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + *(.eh_frame.*) + +.gcc_except_table + *(.gcc_except_table .gcc_except_table.*) + +.gnu_extab + *(.gnu_extab*) + +.exception_ranges + *(.exception_ranges*) + 0x0000000000003da0 . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)) + +.eh_frame + *(.eh_frame) + *(.eh_frame.*) + +.gnu_extab + *(.gnu_extab) + +.gcc_except_table + *(.gcc_except_table .gcc_except_table.*) + +.exception_ranges + *(.exception_ranges*) + +.tdata 0x0000000000003da0 0x0 + [!provide] PROVIDE (__tdata_start = .) + *(.tdata .tdata.* .gnu.linkonce.td.*) + +.tbss + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + +.preinit_array 0x0000000000003da0 0x0 + [!provide] PROVIDE (__preinit_array_start = .) + *(.preinit_array) + [!provide] PROVIDE (__preinit_array_end = .) + +.init_array 0x0000000000003da0 0x8 + 0x0000000000003da0 PROVIDE (__init_array_start = .) + *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)) + *(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors) + .init_array 0x0000000000003da0 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + 0x0000000000003da8 PROVIDE (__init_array_end = .) + +.fini_array 0x0000000000003da8 0x8 + [!provide] PROVIDE (__fini_array_start = .) + *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)) + *(.fini_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .dtors) + .fini_array 0x0000000000003da8 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + [!provide] PROVIDE (__fini_array_end = .) + +.ctors + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT_BY_NAME(.ctors.*)) + *(.ctors) + +.dtors + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT_BY_NAME(.dtors.*)) + *(.dtors) + +.jcr + *(.jcr) + +.data.rel.ro 0x0000000000003db0 0x0 + *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) + *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) + .data.rel.ro 0x0000000000003db0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + +.dynamic 0x0000000000003db0 0x1f0 + *(.dynamic) + .dynamic 0x0000000000003db0 0x1f0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000003db0 _DYNAMIC + +.got 0x0000000000003fa0 0x60 + *(.got.plt) + .got.plt 0x0000000000003fa0 0x38 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000003fa0 _GLOBAL_OFFSET_TABLE_ + *(.igot.plt) + *(.got) + .got 0x0000000000003fd8 0x28 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + *(.igot) + 0x0000000000004000 . = DATA_SEGMENT_RELRO_END (., 0x0) + +.data 0x0000000000004000 0x10 + *(.data .data.* .gnu.linkonce.d.*) + .data 0x0000000000004000 0x4 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000004000 data_start + 0x0000000000004000 __data_start + .data 0x0000000000004004 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + .data 0x0000000000004004 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + *fill* 0x0000000000004004 0x4 + .data.rel.local + 0x0000000000004008 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + 0x0000000000004008 __dso_handle + .data 0x0000000000004010 0x0 ropex.o + .data 0x0000000000004010 0x0 gadget.o + .data 0x0000000000004010 0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + .data 0x0000000000004010 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + .data 0x0000000000004010 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + +.tm_clone_table + 0x0000000000004010 0x0 + .tm_clone_table + 0x0000000000004010 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + .tm_clone_table + 0x0000000000004010 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + +.data1 + *(.data1) + 0x0000000000004010 _edata = . + [!provide] PROVIDE (edata = .) + 0x0000000000004010 . = . + 0x0000000000004010 __bss_start = . + +.bss 0x0000000000004010 0x10 + *(.dynbss) + *fill* 0x0000000000004010 0x0 + .dynbss 0x0000000000004010 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + 0x0000000000004010 stdin@@GLIBC_2.2.5 + *(.bss .bss.* .gnu.linkonce.b.*) + .bss 0x0000000000004018 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o + .bss 0x0000000000004018 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o + .bss 0x0000000000004018 0x1 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + .bss 0x0000000000004019 0x0 ropex.o + .bss 0x0000000000004019 0x0 gadget.o + .bss 0x0000000000004019 0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) + .bss 0x0000000000004019 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + .bss 0x0000000000004019 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o + *(COMMON) + 0x0000000000004020 . = ALIGN ((. != 0x0)?0x8:0x1) + *fill* 0x0000000000004019 0x7 + +.lbss + *(.dynlbss) + *(.lbss .lbss.* .gnu.linkonce.lb.*) + *(LARGE_COMMON) + 0x0000000000004020 . = ALIGN (0x8) + 0x0000000000004020 . = SEGMENT_START ("ldata-segment", .) + +.lrodata + *(.lrodata .lrodata.* .gnu.linkonce.lr.*) + +.ldata 0x0000000000006020 0x0 + *(.ldata .ldata.* .gnu.linkonce.l.*) + 0x0000000000006020 . = ALIGN ((. != 0x0)?0x8:0x1) + 0x0000000000006020 . = ALIGN (0x8) + 0x0000000000004020 _end = . + [!provide] PROVIDE (end = .) + 0x0000000000006020 . = DATA_SEGMENT_END (.) + +.stab + *(.stab) + +.stabstr + *(.stabstr) + +.stab.excl + *(.stab.excl) + +.stab.exclstr + *(.stab.exclstr) + +.stab.index + *(.stab.index) + +.stab.indexstr + *(.stab.indexstr) + +.comment 0x0000000000000000 0x2a + *(.comment) + .comment 0x0000000000000000 0x2a /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o + 0x2b (size before relaxing) + .comment 0x000000000000002a 0x2b ropex.o + .comment 0x000000000000002a 0x2b /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o + +.gnu.build.attributes + *(.gnu.build.attributes .gnu.build.attributes.*) + +.debug + *(.debug) + +.line + *(.line) + +.debug_srcinfo + *(.debug_srcinfo) + +.debug_sfnames + *(.debug_sfnames) + +.debug_aranges 0x0000000000000000 0x30 + *(.debug_aranges) + .debug_aranges + 0x0000000000000000 0x30 ropex.o + +.debug_pubnames + *(.debug_pubnames) + +.debug_info 0x0000000000000000 0x49e + *(.debug_info .gnu.linkonce.wi.*) + .debug_info 0x0000000000000000 0x49e ropex.o + +.debug_abbrev 0x0000000000000000 0x19b + *(.debug_abbrev) + .debug_abbrev 0x0000000000000000 0x19b ropex.o + +.debug_line 0x0000000000000000 0x188 + *(.debug_line .debug_line.* .debug_line_end) + .debug_line 0x0000000000000000 0x188 ropex.o + +.debug_frame 0x0000000000000000 0xa8 + *(.debug_frame) + .debug_frame 0x0000000000000000 0xa8 ropex.o + +.debug_str 0x0000000000000000 0x2f4 + *(.debug_str) + .debug_str 0x0000000000000000 0x2f4 ropex.o + 0x333 (size before relaxing) + +.debug_loc 0x0000000000000000 0x254 + *(.debug_loc) + .debug_loc 0x0000000000000000 0x254 ropex.o + +.debug_macinfo + *(.debug_macinfo) + +.debug_weaknames + *(.debug_weaknames) + +.debug_funcnames + *(.debug_funcnames) + +.debug_typenames + *(.debug_typenames) + +.debug_varnames + *(.debug_varnames) + +.debug_pubtypes + *(.debug_pubtypes) + +.debug_ranges + *(.debug_ranges) + +.debug_macro + *(.debug_macro) + +.debug_addr + *(.debug_addr) + +.gnu.attributes + *(.gnu.attributes) + +/DISCARD/ + *(.note.GNU-stack) + *(.gnu_debuglink) + *(.gnu.lto_*) +OUTPUT(ropex elf64-x86-64) diff --git a/Semestr 4/ask/lista9/test.c b/Semestr 4/ask/lista9/test.c new file mode 100644 index 0000000..1dae111 --- /dev/null +++ b/Semestr 4/ask/lista9/test.c @@ -0,0 +1,7 @@ +void foobar() {} + +static const struct { + char a[3]; int b; long c; float pi; +} baz = { "abc", 42, -3, 1.4142 }; + +long array[100]; \ No newline at end of file diff --git a/Semestr 4/ask/lista9/test.s b/Semestr 4/ask/lista9/test.s new file mode 100644 index 0000000..5e60585 --- /dev/null +++ b/Semestr 4/ask/lista9/test.s @@ -0,0 +1,50 @@ + .file "test.c" + .text + .globl foobar + .type foobar, @function +foobar: +.LFB0: + .cfi_startproc + endbr64 + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + nop + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size foobar, .-foobar + .section .rodata + .align 16 + .type baz, @object + .size baz, 24 +baz: + .ascii "abc" + .zero 1 + .long 42 + .quad -3 + .long 1068827777 + .zero 4 + .comm array,800,32 + .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" + .section .note.GNU-stack,"",@progbits + .section .note.gnu.property,"a" + .align 8 + .long 1f - 0f + .long 4f - 1f + .long 5 +0: + .string "GNU" +1: + .align 8 + .long 0xc0000002 + .long 3f - 2f +2: + .long 0x3 +3: + .align 8 +4: diff --git a/Semestr 4/pstwo/wyklady/Wyklad 9.pdf b/Semestr 4/pstwo/wyklady/Wyklad 9.pdf new file mode 100644 index 0000000..5c0e798 Binary files /dev/null and b/Semestr 4/pstwo/wyklady/Wyklad 9.pdf differ diff --git a/Semestr 4/rr1r/kol1/kol1.xopp b/Semestr 4/rr1r/kol1/kol1.xopp new file mode 100644 index 0000000..b7bd15e Binary files /dev/null and b/Semestr 4/rr1r/kol1/kol1.xopp differ diff --git a/Semestr 4/rr1r/kol1/zad1.pdf b/Semestr 4/rr1r/kol1/zad1.pdf new file mode 100644 index 0000000..6f142b3 Binary files /dev/null and b/Semestr 4/rr1r/kol1/zad1.pdf differ diff --git a/Semestr 4/rr1r/kol1/zad2.pdf b/Semestr 4/rr1r/kol1/zad2.pdf new file mode 100644 index 0000000..7ca8b4a Binary files /dev/null and b/Semestr 4/rr1r/kol1/zad2.pdf differ diff --git a/Semestr 4/rr1r/kol1/zad3.pdf b/Semestr 4/rr1r/kol1/zad3.pdf new file mode 100644 index 0000000..9fd9835 Binary files /dev/null and b/Semestr 4/rr1r/kol1/zad3.pdf differ diff --git a/Semestr 4/rr1r/lista8/L8.pdf b/Semestr 4/rr1r/lista8/L8.pdf new file mode 100644 index 0000000..174c6f9 Binary files /dev/null and b/Semestr 4/rr1r/lista8/L8.pdf differ diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka.tar.xz b/Semestr 4/sieci/pracownia2/franciszek_malinka.tar.xz new file mode 100644 index 0000000..ac3b1f7 Binary files /dev/null and b/Semestr 4/sieci/pracownia2/franciszek_malinka.tar.xz differ diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/config.h b/Semestr 4/sieci/pracownia2/franciszek_malinka/config.h new file mode 100644 index 0000000..ee4eac0 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/config.h @@ -0,0 +1,15 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define SERVER_PORT 54321 +#define TURN_LEN_S 20 + +#define INFINITY_DIST 16 +#define REACHABILITY_WAIT_TIME 3 + +#define DV_DATAGRAM_LEN 9 + +#define TURN_LEN_MS (1000 * TURN_LEN_S) +#define TURN_LEN_US (1000000 * TURN_LEN_S) + +#endif diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.c new file mode 100644 index 0000000..74ae82e --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.c @@ -0,0 +1,114 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include "dist_vector.h" +#include +#include +#include + +bool is_connected_directly(struct vector_item item) { + return item.is_connected_directly; +} + +bool is_reachable(struct vector_item item) { + return (item.distance < INFINITY_DIST); +} + +void init_dv(list_t *dv, int n_cnt, struct network_addr *neighbours) { + for (int i = 0; i < n_cnt; i++) { + struct vector_item new_item; + new_item.network = neighbours[i]; + new_item.distance = INFINITY_DIST; + new_item.is_connected_directly = true; + insert(dv, &new_item, sizeof(new_item)); + } +} + +void update_dv_reachability(list_t *distance_vector) { + reset(distance_vector); + while (distance_vector->it != NULL) { + struct vector_item *current = (struct vector_item *)distance_vector->it->data; + if(++current->reachable > REACHABILITY_WAIT_TIME) { + if (current->distance >= INFINITY_DIST) { + if (!is_connected_directly(*current)) { + erase_it(distance_vector); + } + } else { + current->distance = INFINITY_DIST; + current->reachable = 0; + } + } + iterate(distance_vector); + } +} + +void update_dv_new_item(list_t *distance_vector, struct vector_item new_item) { + bool new_entry = true; + reset(distance_vector); + while (distance_vector->it != NULL) { + struct vector_item *current = (struct vector_item *)distance_vector->it->data; + + /* If the network is already in the distance vector, then we possibly want to change it: + * - if the new item has better distance than the previous one, then we just want to change it no matter what, + * - if the new item has the same via ip, then we want to check two things: + * - if new item has infinity dist, then we want to set infinity (if it wasn't set, then we want to change reachable to 0) + * - if new item has < inf dist, then we want to change reachable to 0 and set our dist accordingly. + * - else we ignore the entry. + */ + if (get_network_address(current->network).s_addr == get_network_address(new_item.network).s_addr) { + if (current->distance > new_item.distance) { + *current = new_item; + current->reachable = 0; + } else if(current->via_ip.s_addr == new_item.via_ip.s_addr) { + if (new_item.distance >= INFINITY_DIST) { + if (current->distance < INFINITY_DIST) { + current->distance = INFINITY_DIST; + current->reachable = 0; + } + } else { + current->distance = new_item.distance; + current->reachable = 0; + } + } + new_entry = false; + } + + iterate(distance_vector); + } + + if (new_entry && new_item.reachable < INFINITY_DIST) { + insert(distance_vector, &new_item, sizeof(new_item)); + } +} + +void print_dv(list_t *distance_vector) { + time_t rawtime; + struct tm * timeinfo; + + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + char t[100]; + strcpy(t, asctime(timeinfo)); + t[strlen(t) - 1] = 0; + printf("Distance vector [%s]:\n", t); + reset(distance_vector); + while (distance_vector->it != NULL) { + char addr[20], via_addr[20]; + struct vector_item current = *(struct vector_item *)distance_vector->it->data; + struct in_addr net_addr = get_network_address(current.network); + inet_ntop(AF_INET, &net_addr, addr, sizeof(addr)); + printf("%s/%d ", addr, current.network.netmask); + + if (is_reachable(current)) printf("distance %d ", current.distance); + else printf("unreachable "); + + inet_ntop(AF_INET, ¤t.via_ip, via_addr, sizeof(via_addr)); + if (is_connected_directly(current)) printf("connected directly\n"); + else printf("via %s\n", via_addr); + + iterate(distance_vector); + } + printf("\n"); +} \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.h b/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.h new file mode 100644 index 0000000..14159b4 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/dist_vector.h @@ -0,0 +1,36 @@ +#ifndef DIST_VECTOR_H +#define DIST_VECTOR_H + +#include "linked_list.h" +#include "network_addr.h" +#include "config.h" + +/* Item of the distance vector. + * If <> is set to 0, then it means that the network is reachable. + * If <> has positive value, then it indicates that the network was + * unreachable for <> turns. + */ +struct vector_item { + struct network_addr network; + struct in_addr via_ip; + uint16_t distance; + uint8_t reachable; + bool is_connected_directly; +}; + +/* Initis distance vector with given neighbours array. */ +void init_dv(list_t *dv, int n_cnt, struct network_addr *neighbours); + +/* Returns true if given distance vector item is connected directly, false otherwise. */ +bool is_connected_directly(struct vector_item item); + +/* Updates the distance vector. */ +void update_dv_new_item(list_t *distance_vector, struct vector_item new_item); + +/* Updates reachabilities. */ +void update_dv_reachability(list_t *distance_vector); + +/* Print distance vector. */ +void print_dv(list_t *distance_vector); + +#endif \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.c new file mode 100644 index 0000000..16113ac --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.c @@ -0,0 +1,79 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include "linked_list.h" +#include +#include + +node_t *_next(node_t *node) { + return (node == NULL) ? NULL : node->next; +} + +void _insert(node_t **head, void *data, size_t data_size) { + node_t *new_node = (node_t *)malloc(sizeof(node_t)); + new_node->data = malloc(data_size); + for (int i = 0; i < data_size; i++) + *(uint8_t *)(new_node->data + i) = *(uint8_t *)(data + i); + new_node->next = *head; + *head = new_node; +} + +void _free_node(node_t *node) { + free(node->data); + free(node); +} + +void _erase(node_t **head) { + node_t *next_node = _next(*head); + _free_node(*head); + *head = next_node; +} + +void _free_list(node_t *head) { + if (head == NULL) return; + _free_list(head->next); + _free_node(head); +} + +list_t create_list() { + list_t ret; + ret.head = NULL; + ret.it = NULL; + return ret; +} + +void insert(list_t *list, void *data, size_t data_size) { + _insert(&list->head, data, data_size); +} + +void erase(list_t *list) { + _erase(&list->head); +} + +void erase_it(list_t *list) { + if(list->it == NULL) return; + if(list->prev_it == NULL) { + erase(list); + reset(list); + return; + } + list->prev_it->next = _next(list->it); + _free_node(list->it); + list->it = list->prev_it->next; +} + +void iterate(list_t *list) { + list->prev_it = list->it; + list->it = _next(list->it); +} + +void reset(list_t *list) { + list->prev_it = NULL; + list->it = list->head; +} + +void free_list(list_t *list) { + _free_list(list->head); +} \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.h b/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.h new file mode 100644 index 0000000..1574b2f --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/linked_list.h @@ -0,0 +1,42 @@ +#ifndef LINKED_LIST_H +#define LINKED_LIST_H + +#include + +typedef struct node { + void *data; + struct node *next; +} node_t; + + +typedef struct list_t { + node_t *head; + node_t *it; + node_t *prev_it; +} list_t; + +/* Creates an empty list. */ +list_t create_list(); + +/* Insert a new node in the begining of a list. */ +void insert(list_t *list, void *data, size_t data_size); + +/* Erases first node from the list. */ +void erase(list_t *list); + +/* Erases element under iterator and sets iterator to the next one. */ +void erase_it(list_t *list); + +/* Moves iterator one step. */ +void iterate(list_t *list); + +/* Resets the iterator. + * Should execute the function after if you want to itarate unless you didnt insert or erase anything from the list. + */ +void reset(list_t *list); + +/* Deletes the whole list. */ +void free_list(list_t *list); + + +#endif \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/makefile b/Semestr 4/sieci/pracownia2/franciszek_malinka/makefile new file mode 100644 index 0000000..bf6a327 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/makefile @@ -0,0 +1,34 @@ +CC := gcc +CFLAGS := -O2 -std=gnu17 -Wall -Wall -Wno-unused-result +TARGET := router +TEST := test +DEPS := config.h + +ODIR := obj +_OBJ := router.o utils.o linked_list.o network_addr.o dist_vector.o +OBJ := $(patsubst %,$(ODIR)/%,$(_OBJ)) + +_TEST_OBJ := test.o linked_list.o +TEST_OBJ := $(patsubst %,$(ODIR)/%,$(_TEST_OBJ)) + + +all: $(TARGET) +test: $(TEST) + +$(ODIR)/%.o: %.c $(DEPS) + $(CC) $(CFLAGS) -c -o $@ $< + +$(TARGET): $(OBJ) + $(CC) -o $@ $^ $(CFLAGS) + +$(TEST): $(TEST_OBJ) + $(CC) -o $@ $^ $(CFLAGS) + +clean: + rm -rf $(TARGET) + rm -rf test + +distclean: + rm -rf $(TARGET) + rm -rf test + rm -rf $(ODIR)/*.o diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.c new file mode 100644 index 0000000..cac1060 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.c @@ -0,0 +1,65 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include "network_addr.h" +#include +#include +#include + +struct in_addr _get_broadcast_address(struct in_addr addr, uint16_t netmask) { + struct in_addr result = addr; + result.s_addr = ntohl(result.s_addr); + /* bitshift by more than 31 is UB */ + if (netmask == 0) { + result.s_addr = -1; + } + else { + result.s_addr |= ((1 << (32 - netmask)) - 1); + } + result.s_addr = htonl(result.s_addr); + + return result; +} + +struct in_addr _get_network_address(struct in_addr addr, uint16_t netmask) { + struct in_addr result = addr; + result.s_addr = ntohl(result.s_addr); + + if (netmask == 0) { + result.s_addr = 0; + } + else { + result.s_addr &= ~((1 << (32 - netmask)) - 1); + } + result.s_addr = htonl(result.s_addr); + + return result; +} + +struct in_addr get_broadcast_address(struct network_addr na) { + return _get_broadcast_address(na.addr, na.netmask); +} + +struct in_addr get_network_address(struct network_addr na) { + return _get_network_address(na.addr, na.netmask); +} + +void pretty_print_network(struct network_addr na) { + char ip_addr[20]; + inet_ntop(AF_INET, &na.addr, ip_addr, sizeof(ip_addr)); + printf("%s/%d\n", ip_addr, na.netmask); +} + +struct network_addr stona(char *str) { + struct network_addr result; + char addr[20]; + size_t ip_preffix = strcspn(str, "/"); + + strncpy(addr, str, ip_preffix); + addr[ip_preffix] = 0; + inet_pton(AF_INET, addr, &(result.addr)); + result.netmask = atoi(str + ip_preffix + 1); + return result; +} diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.h b/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.h new file mode 100644 index 0000000..6347bbd --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/network_addr.h @@ -0,0 +1,28 @@ +#ifndef ROUTER_ADDR_H +#define ROUTER_ADDR_H + +#include +#include +#include + +/* Network address with netmask. */ +struct network_addr { + struct in_addr addr; + uint8_t netmask; +}; + +typedef struct network_addr router_addr; + +/* Returns broadcast address of a given network. */ +struct in_addr get_broadcast_address(struct network_addr na); + +/* Returns network address of a given network. */ +struct in_addr get_network_address(struct network_addr na); + +/* Prints network_addr via stdio. */ +void pretty_print_network(struct network_addr na); + +/* Converts string of ip in CIDR notation with a netmask to network_addr. */ +struct network_addr stona(char *str); + +#endif \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/router.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/router.c new file mode 100644 index 0000000..b5e732c --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/router.c @@ -0,0 +1,60 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "network_addr.h" +#include "utils.h" +#include "dist_vector.h" + +uint16_t read_configuration(struct network_addr** networks, uint16_t **dists) { + uint16_t n; + scanf("%hd", &n); + *networks = malloc(n * sizeof(struct network_addr)); + *dists = malloc(n * sizeof(uint16_t)); + for (int i = 0; i < n; i++) { + char addr[20]; + char _dist[10]; + uint16_t dist; + scanf(" %s %s %hd", addr, _dist, &dist); + (*networks)[i] = stona(addr); + (*dists)[i] = dist; + } + return n; +} + +void router_loop(int sockfd, int networks_number, struct network_addr *networks, uint16_t *dists) { + list_t dv = create_list(); + init_dv(&dv, networks_number, networks); + + printf("Starting the router loop...\n"); + for (;;) { + print_dv(&dv); + propagate_distance_vector(sockfd, networks_number, networks, dists, &dv); + listen_for_routers(sockfd, TURN_LEN_MS, networks_number, networks, dists, &dv); + } +} + +int main() { + struct network_addr* networks; + uint16_t *dists; + int n = read_configuration(&networks, &dists); + int sockfd = get_socket(); + bind_to_port(sockfd, SERVER_PORT); + + router_loop(sockfd, n, networks, dists); + + close(sockfd); + free(networks); + free(dists); +} \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/test.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/test.c new file mode 100644 index 0000000..958ff36 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/test.c @@ -0,0 +1,52 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include "linked_list.h" +#include +#include + +/* Prints the list of ints to stdio */ +void print_list(list_t list) { + printf("List: "); + reset(&list); + while (list.it != NULL) { + printf("%d, ", *(int *)(list.it->data)); + iterate(&list); + } + printf("\n"); + reset(&list); +} + +int main() { + int n; + scanf("%d", &n); + list_t list = create_list(); + + for (int i = 0; i < n; i++) { + int t; + scanf("%d", &t); + // insert + if (t == 0) { + int val = 0; + scanf("%d", &val); + insert(&list, &val, sizeof(int)); + reset(&list); + } + if (t == 1) { + iterate(&list); + if (list.it != NULL) + printf("it: %d\n", *(int *)list.it->data); + else printf("End of list.\n"); + } + if (t == 2) { + erase_it(&list); + } + if (t == 3) { + print_list(list); + } + } + + free_list(&list); +} \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.c b/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.c new file mode 100644 index 0000000..0c0cae5 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.c @@ -0,0 +1,208 @@ +/* + * Program: router + * Autor: Franciszek Malinka, 316093 + */ + +#include "utils.h" +#include +#include +#include +#include +#include +#include +#include + +int get_socket() { + int sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) { + fprintf(stderr, "Socket error: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + return sockfd; +} + +void bind_to_port(int sockfd, uint16_t port) { + struct sockaddr_in server_address; + bzero(&server_address, sizeof(server_address)); + server_address.sin_family = AF_INET; + server_address.sin_port = htons(port); + server_address.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(sockfd, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) { + fprintf(stderr, "Bind error: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + int broadcastPermission = 1; + setsockopt (sockfd, SOL_SOCKET, SO_BROADCAST, (void *)&broadcastPermission, sizeof(broadcastPermission)); +} + +long get_time_interval(struct timespec start, struct timespec finish) { + return S_TO_MS(finish.tv_sec - start.tv_sec) + NS_TO_MS(finish.tv_nsec - start.tv_nsec); +} + +int poll_socket_modify_timeout(int sockfd, int *timeout) { + if (*timeout < 0) { + *timeout = 0; + return 0; + } + + struct pollfd fds; + struct timespec start; + struct timespec finish; + + fds.fd = sockfd; + fds.events = POLLIN; + fds.revents = 0; + + clock_gettime(CLOCK_REALTIME, &start); + int result = poll(&fds, 1, *timeout); + clock_gettime(CLOCK_REALTIME, &finish); + + if (result == -1) { + fprintf(stderr, "poll error: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + if (result == 0) { + *timeout = 0; + return 0; + } + + *timeout -= get_time_interval(start, finish); + return result; +} + +size_t send_message(int sockfd, char *buffer, int buffer_len, struct in_addr network) { + struct sockaddr_in network_address; + bzero (&network_address, sizeof(network_address)); + network_address.sin_family = AF_INET; + network_address.sin_port = htons(SERVER_PORT); + network_address.sin_addr = network; + + return sendto(sockfd, buffer, buffer_len, 0, (struct sockaddr*) &network_address, sizeof(network_address)); +} + +size_t recv_message(int sockfd, char *buffer, struct sockaddr_in *sender) { + socklen_t sender_len = sizeof(*sender); + for (int i = 0; i < DV_DATAGRAM_LEN; i++) buffer[i] = 0; + size_t datagram_len = recvfrom(sockfd, buffer, IP_MAXPACKET, 0, + (struct sockaddr*)sender, &sender_len); + if (datagram_len < 0) { + fprintf(stderr, "recvfrom error: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + return datagram_len; +} + +struct vector_item parse_message(char *buffer, struct sockaddr_in *sender) { + struct vector_item res; + uint32_t ip_addr = *(uint32_t *)buffer; + uint32_t dist = *(uint32_t *)(buffer + 5); + dist = ntohl(dist); + + res.network.addr.s_addr = ip_addr; + res.network.netmask = buffer[4]; + res.is_connected_directly = true; + res.via_ip = sender->sin_addr; + res.distance = (dist < INFINITY_DIST ? dist : INFINITY_DIST); + res.reachable = 0; + + char addr[20]; + inet_ntop(AF_INET, &res.network.addr, addr, sizeof(addr)); + char via[20]; + inet_ntop(AF_INET, &sender->sin_addr, via, sizeof(via)); + return res; +} + +void _get_message(struct vector_item item, char *message) { + *(uint32_t *)message = item.network.addr.s_addr; + message[4] = item.network.netmask; + uint32_t distance = htonl(item.distance >= INFINITY_DIST ? INT_MAX : item.distance); + for (int i = 0; i < 4; i++) { + *(message + 5 + i) = *((char *)(&distance) + i); + } +} + +int _send_item(int sockfd, struct network_addr network, struct vector_item item) { + char message[DV_DATAGRAM_LEN + 1]; + _get_message(item, message); + message[DV_DATAGRAM_LEN] = 0; + ssize_t message_len = DV_DATAGRAM_LEN; + + struct in_addr na = get_broadcast_address(network); + + char addr[20]; + inet_ntop(AF_INET, &na, addr, sizeof(addr)); + + int result; + if ((result = send_message(sockfd, message, message_len, na)) != message_len) { + // fprintf(stderr, "sendto error: %s\n", strerror(errno)); + } + return result; +} + +void listen_for_routers(int sockfd, int timeout, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv) { + char buffer[IP_MAXPACKET + 1]; + struct sockaddr_in sender; + + while (poll_socket_modify_timeout(sockfd, &timeout)) { + recv_message(sockfd, buffer, &sender); + struct vector_item new_item = parse_message(buffer, &sender); + + bool is_neighbour = false; + for (int i = 0; i < networks_number; i++) { + if (is_from_network(sender.sin_addr, networks[i])) { + is_neighbour = true; + break; + } + } + + /* Shouldn't happen, just in case. */ + if (!is_neighbour) { + char addr[20]; + inet_ntop(AF_INET, &sender.sin_addr, addr, sizeof(addr)); + fprintf(stderr, "Received datagram from %s, he is in none of my networks, ignoring\n. Maybe his VM routing table is configured incorrectly?\n", addr); + continue; + } + + if (!is_from_network(sender.sin_addr, new_item.network)) { + new_item.is_connected_directly = false; + + for (int i = 0; i < networks_number; i++) { + if (is_from_network(sender.sin_addr, networks[i])) { + new_item.distance += dists[i]; + break; + } + } + } + + update_dv_new_item(dv, new_item); + } + update_dv_reachability(dv); +} + +void propagate_distance_vector(int sockfd, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv) { + for (int i = 0; i < networks_number; i++) { + reset(dv); + while (dv->it != NULL) { + struct vector_item data = *(struct vector_item *)dv->it->data; + if (!(get_network_address(data.network).s_addr == get_network_address(networks[i]).s_addr) && data.reachable <= REACHABILITY_WAIT_TIME) { + _send_item(sockfd, networks[i], data); + } + iterate(dv); + } + + struct vector_item self_item; + self_item.distance = dists[i]; + self_item.network = networks[i]; + _send_item(sockfd, networks[i], self_item); + } +} + +bool is_from_network(struct in_addr ip_addr, struct network_addr network) { + struct network_addr temp; + temp.addr= ip_addr; + temp.netmask = network.netmask; + return (get_network_address(temp).s_addr == get_network_address(network).s_addr); +} \ No newline at end of file diff --git a/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.h b/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.h new file mode 100644 index 0000000..edf90d0 --- /dev/null +++ b/Semestr 4/sieci/pracownia2/franciszek_malinka/utils.h @@ -0,0 +1,52 @@ +#ifndef UTILS_H +#define UTILS_H +#define UTILS_H + +#include "config.h" +#include +#include +#include +#include "network_addr.h" +#include "dist_vector.h" + +#define NS_TO_MS(X) ((long)(X) / (long)1000000) +#define S_TO_MS(X) ((long)(X) * (long)1000) + +/* Returns a UDP socket. */ +int get_socket(); + +/* Binds socket to given port and set the broadcast permission. */ +void bind_to_port(int sockfd, uint16_t port); + +/* Computes the time elapsed between start and finish in miliseconds. */ +long get_time_interval(struct timespec start, struct timespec finish); + +/* Polls given socket with given timeout and changes the timeout accordingly. */ +int poll_socket_modify_timeout(int sockfd, int *timeout); + +/* For debug purposes only. Recieves and prints UDP message. */ +void recv_and_print(int sockfd, int networks_number, struct network_addr *networks); + +/* Sends message in buffer of length buffer_len to addr through given socket. + * IT DOES NOT TERMINATE THE PROGRAM IF SENDTO RETURNS ANY ERRORS! + * One must handle the errors on their own. + */ +size_t send_message(int sockfd, char *buffer, int buffer_len, struct in_addr addr); + +/* Receive message and write it to buffer. */ +size_t recv_message(int sockfd, char *buffer, struct sockaddr_in *sender); + +/* Parse datagram into a vector item. */ +struct vector_item parse_message(char *buffer, struct sockaddr_in *sender); + +/* Listnes for routers for timeout ms. */ +void listen_for_routers(int sockfd, int timeout, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv); + +/* Propagates dv to all connected networks. */ +void propagate_distance_vector(int sockfd, int networks_number, struct network_addr *networks, uint16_t *dists, list_t *dv); + +/* Checks if given address is in network range. */ +bool is_from_network(struct in_addr ip_addr, struct network_addr network); + + +#endif \ No newline at end of file -- cgit v1.2.3