{"id":20648551,"url":"https://github.com/linuxthor/openlsd","last_synced_at":"2026-03-19T16:55:39.261Z","repository":{"id":11777432,"uuid":"14316171","full_name":"linuxthor/OpenLSD","owner":"linuxthor","description":"Assembly \"Hello World\" that runs on both Linux and OpenBSD ","archived":false,"fork":false,"pushed_at":"2013-11-11T23:14:14.000Z","size":120,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T19:13:03.415Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linuxthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-11T23:04:22.000Z","updated_at":"2023-07-23T21:54:16.000Z","dependencies_parsed_at":"2022-09-07T15:41:58.285Z","dependency_job_id":null,"html_url":"https://github.com/linuxthor/OpenLSD","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/linuxthor/OpenLSD","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2FOpenLSD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2FOpenLSD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2FOpenLSD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2FOpenLSD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linuxthor","download_url":"https://codeload.github.com/linuxthor/OpenLSD/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2FOpenLSD/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30236051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T17:09:18.828Z","updated_at":"2026-03-07T23:02:58.489Z","avatar_url":"https://github.com/linuxthor.png","language":null,"readme":"OpenLSD\n=======\n\nAssembly \"Hello World\" that runs on both Linux and OpenBSD.\n\nAssemble this to make a binary that prints \"Linux\" on 64 Bit Linux and\n\"OpenBSD\" on 64 Bit OpenBSD. As the syscalls are numbered differently\na simple test is used to determine which OS this is; Syscall 6 (sys_close\non OpenBSD and sys_lstat on Linux) is called with the first argument being\na pointer to the string /proc/self/stat, on Linux we get a return code of\n0 as we're calling sys_lstat and the file exists but on OpenBSD this is\nsys_close with an invalid FD so we get a -1 error, a comparison of the return\ncode is used to jump to either OpenBSD or Linux code.\n\nThere is probably a better way to do this (and indeed Google tells me an actual\nLinux emulation layer in OpenBSD!) but I was drunk and bored..\n\nAssemble with:\n```\nnasm -f elf64 -o openlsd.o openlsd.asm\nld -o openlsd openlsd.o\n \n$ file ./openlsd\n./openlsd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically\nlinked, for OpenBSD, not stripped\n``` \nOn Linux:\n```\n$ strace ./openlsd\nexecve(\"./openlsd\", [\"./openlsd\"], [/* 35 vars */]) = 0\nlstat(\"/proc/self/stat\", {st_mode=S_IFREG|0444, st_size=0, ...}) = 0\nwrite(1, \"Linux\\n\", 6Linux\n)                  = 6\n_exit(42)                               = ?\n```\nOn OpenBSD:\n```\n$ kdump\n  5762 ktrace   EMUL  \"native\"\n  5762 ktrace   RET   ktrace 0\n  5762 ktrace   CALL  execve(0x7f7ffffe8ab7,0x7f7ffffe89c0,0x7f7ffffe89d0)\n  5762 ktrace   NAMI  \"/tmp/openlsd\"\n  5762 openlsd  EMUL  \"native\"\n  5762 openlsd  RET   execve 0\n  5762 openlsd  CALL  close(0x600178)\n  5762 openlsd  RET   close -1 errno 9 Bad file descriptor\n  5762 openlsd  CALL  write(0x1,0x600188,0x8)\n  5762 openlsd  GIO   fd 1 wrote 8 bytes\n       \"OpenBSD\n       \"\n  5762 openlsd  RET   write 8\n  5762 openlsd  CALL  exit(0x45)\n```\n \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxthor%2Fopenlsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinuxthor%2Fopenlsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxthor%2Fopenlsd/lists"}