├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── constants.c ├── index.html └── server.asm /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.txt 3 | server 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Nir Lichtman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: constants build 2 | 3 | constants: 4 | gcc -E -P constants.c > constants.txt 5 | 6 | build: 7 | fasm server.asm 8 | ld server.o -o server 9 | 10 | clean: 11 | rm -f server server.o constants.txt 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastws 2 | Minimalist Web Server for Linux written in x64 Assembly 3 | 4 | ## Building 5 | 6 | ``` 7 | make 8 | ``` 9 | -------------------------------------------------------------------------------- /constants.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // rdi rsi rdx r10 r8 r9 7 | socket = SYS_socket 8 | bind = SYS_bind 9 | listen = SYS_listen 10 | accept = SYS_accept 11 | read = SYS_read 12 | write = SYS_write 13 | open = SYS_open 14 | exit = SYS_exit 15 | close = SYS_close 16 | af_inet = AF_INET 17 | sock_stream = SOCK_STREAM 18 | o_rdonly = O_RDONLY 19 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | HTTP/1.0 200 OK 2 | Content-type: text/html 3 | 4 | Hello from Assembly! 5 | -------------------------------------------------------------------------------- /server.asm: -------------------------------------------------------------------------------- 1 | format ELF64 2 | public _start 3 | 4 | socket = 41 5 | bind = 49 6 | listen = 50 7 | accept = 43 8 | read = 0 9 | write = 1 10 | open = 2 11 | exit = 60 12 | close = 3 13 | af_inet = 2 14 | sock_stream = 1 15 | o_rdonly = 0 16 | 17 | section '.text' executable 18 | _start: 19 | mov rdi, af_inet 20 | mov rsi, sock_stream 21 | mov rdx, 0 22 | mov rax, socket 23 | syscall 24 | 25 | mov r12, rax ; socket fd 26 | mov rdi, r12 27 | mov rsi, address 28 | mov rdx, 16 29 | mov rax, bind 30 | syscall 31 | 32 | mov rdi, r12 33 | mov rsi, 10 34 | mov rax, listen 35 | syscall 36 | 37 | accept_loop: 38 | 39 | mov rdi, r12 40 | mov rsi, 0 41 | mov rdx, 0 42 | mov rax, accept 43 | syscall 44 | 45 | mov r13, rax ; client socket fd 46 | mov rdi, r13 47 | mov rsi, buffer 48 | mov rdx, 256 49 | mov rax, read 50 | syscall 51 | 52 | mov rdi, path 53 | mov rsi, o_rdonly 54 | mov rax, open 55 | syscall 56 | 57 | mov r14, rax ; save index.html fd 58 | 59 | mov rdi, rax 60 | mov rsi, buffer2 61 | mov rdx, 256 62 | mov rax, read 63 | syscall 64 | 65 | mov rdi, r13 66 | mov rsi, buffer2 67 | mov rdx, 256 68 | mov rax, write 69 | syscall 70 | 71 | mov rdi, r13 72 | mov rax, close 73 | syscall 74 | 75 | mov rdi, r14 76 | mov rax, close 77 | syscall 78 | 79 | jmp accept_loop 80 | 81 | mov rdi, 0 82 | mov rax, exit 83 | syscall 84 | 85 | section '.data' writeable 86 | address: 87 | dw af_inet 88 | dw 0x901f 89 | dd 0 90 | dq 0 91 | buffer: 92 | db 256 dup 0 93 | buffer2: 94 | db 256 dup 0 95 | path: 96 | db 'index.html', 0 97 | --------------------------------------------------------------------------------