{"id":24791459,"url":"https://github.com/jetsetilly/critsec","last_synced_at":"2025-08-29T09:19:17.327Z","repository":{"id":237201607,"uuid":"791404842","full_name":"JetSetIlly/critsec","owner":"JetSetIlly","description":"Proof-of concept for a method of creating and identifying critical sections such that they can be statically analysed for violations","archived":false,"fork":false,"pushed_at":"2024-04-24T16:56:12.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-10T09:01:06.336Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","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/JetSetIlly.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-24T16:55:28.000Z","updated_at":"2024-04-24T16:56:36.000Z","dependencies_parsed_at":"2024-04-30T11:43:30.469Z","dependency_job_id":"475ef3bb-a57c-406c-8507-37676312ad29","html_url":"https://github.com/JetSetIlly/critsec","commit_stats":null,"previous_names":["jetsetilly/critsec"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JetSetIlly/critsec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetSetIlly%2Fcritsec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetSetIlly%2Fcritsec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetSetIlly%2Fcritsec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetSetIlly%2Fcritsec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JetSetIlly","download_url":"https://codeload.github.com/JetSetIlly/critsec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetSetIlly%2Fcritsec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272659282,"owners_count":24971607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang"],"created_at":"2025-01-29T19:17:03.212Z","updated_at":"2025-08-29T09:19:17.275Z","avatar_url":"https://github.com/JetSetIlly.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# critsec\n\nProof-of concept for a method of treating critical sections such that they can\nbe statically analysed for violations.\n\n### Critical Sectioning\n\nIn this scheme critical sections are defined by embedding the `crit.Section`\ntype into a new struct type.\n\n```\ntype exampleCritSectioning struct {\n\tcrit.Section\n\t\n\ta int\n\tb bool\n}\n```\n\nAny fields in this new struct type can then only be accessed if the critical\nsection has been `leased`\n\n```\nvar A exampleCritSectioning\n\n_ = A.Lease(func() error {\n\tA.a = 10\n\tA.b = true\n\treturn nil\n})\n```\n\n### Limitations\n\nFor simplicity and for the purposes of the proof-of-concept there are two\nsignificant restrictions on `crit.Section` usage:\n\n- instances of types derived from `crit.Section` cannot be passed as arguments\n  to functions\n- only one instance of each `crit.Section` derived type can be declared\n\nTo be clear these limitations are enforced by the static analysis and the\n`critcheck` driver. They only exist to make the job of Lease enforcment easier\nand with more sophisticated parsing of the AST the limitations can most probably\nbe lifted.\n\n### Static Analysis\n\nThe project provides a [static\nanalyser](https://pkg.go.dev/golang.org/x/tools@v0.20.0/go/analysis) to report critical section violations.\n\nA `critcheck` command is also provided. This is a standalone driver for the\nanalysis package and will be used for the following demonstration. The\ndemonstration uses the `example/example.go` program for input.\n\n#### Example output\n\nWhen run without arguments, as in the example below, the static analysis issues\nsingle line reports with a brief description of the violation.\n\n```\n\u003e critcheck example.go\n/home/steve/critsec/example/example.go:27:1: crit.Section types cannot be passed to a function\n/home/steve/critsec/example/example.go:28:2: assignment to crit.Section without Lease\n/home/steve/critsec/example/example.go:47:4: assignment to crit.Section without Lease\n/home/steve/critsec/example/example.go:55:2: assignment to crit.Section without Lease\n/home/steve/critsec/example/example.go:56:6: access of crit.Section without Lease\n/home/steve/critsec/example/example.go:63:6: multiple instance of a crit.Section derived type\n```\n\n`critcheck` accepts the standard command line arguments for Go analysis drivers.\nFor example, the `-c` option instructs the program to print the line of source\nthat caused the violation and additional lines to provide context.\n\n```\n\u003e critcheck -c 1 example.go\n/home/steve/critsec/example/example.go:27:1: crit.Section types cannot be passed to a function\n26\t// use of a crit.Section derived type as a parameter\n27\tfunc used(c *critSectionExample) {\n28\t\tc.value = -1\n/home/steve/critsec/example/example.go:28:2: assignment to crit.Section without Lease\n27\tfunc used(c *critSectionExample) {\n28\t\tc.value = -1\n29\t}\n/home/steve/critsec/example/example.go:47:4: assignment to crit.Section without Lease\n46\t\t\tfor i := 0; i \u003c 1000; i++ {\n47\t\t\t\tC.value = 2\n48\t\t\t}\n/home/steve/critsec/example/example.go:55:2: assignment to crit.Section without Lease\n54\t\t// deliberate critical section violations\n55\t\tC.value = 4\n56\t\t_ = C.value\n/home/steve/critsec/example/example.go:56:6: access of crit.Section without Lease\n55\t\tC.value = 4\n56\t\t_ = C.value\n57\t\n/home/steve/critsec/example/example.go:63:6: multiple instance of a crit.Section derived type\n62\tfunc subtask() {\n63\t\tvar D critSectionExample\n64\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetsetilly%2Fcritsec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjetsetilly%2Fcritsec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetsetilly%2Fcritsec/lists"}