[{"data":1,"prerenderedAt":485},["ShallowReactive",2],{"navigation_docs":3,"-stdlib-syscall":198,"-stdlib-syscall-surround":482},[4,30,81,118,147,171,184],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"/getting-started","1.getting-started",[10,15,20,25],{"title":11,"path":12,"stem":13,"icon":14},"Introduction","/getting-started/introduction","1.getting-started/2.introduction","i-lucide-house",{"title":16,"path":17,"stem":18,"icon":19},"Installation","/getting-started/installation","1.getting-started/3.installation","i-lucide-download",{"title":21,"path":22,"stem":23,"icon":24},"Quick start","/getting-started/quickstart","1.getting-started/4.quickstart","i-lucide-code-xml",{"title":26,"path":27,"stem":28,"icon":29},"Troubleshooting","/getting-started/troubleshooting","1.getting-started/5.troubleshooting","i-lucide-wrench",{"title":31,"icon":6,"path":32,"stem":33,"children":34,"page":6},"Core Features","/core-features","2.core-features",[35,39,43,48,52,56,60,64,68,73,77],{"title":36,"path":37,"stem":38,"icon":24},"Main function","/core-features/main-function","2.core-features/1.main-function",{"title":40,"path":41,"stem":42,"icon":24},"Variables","/core-features/variables","2.core-features/2.variables",{"title":44,"path":45,"stem":46,"icon":47},"Comment","/core-features/comment","2.core-features/3.comment","i-lucide-hash",{"title":49,"path":50,"stem":51,"icon":24},"Conditionals","/core-features/conditionals","2.core-features/4.conditionals",{"title":53,"path":54,"stem":55,"icon":24},"Loops","/core-features/loops","2.core-features/5.loops",{"title":57,"path":58,"stem":59,"icon":24},"Functions","/core-features/functions","2.core-features/6.functions",{"title":61,"path":62,"stem":63,"icon":24},"Pointers","/core-features/pointers","2.core-features/7.pointers",{"title":65,"path":66,"stem":67,"icon":24},"Data types","/core-features/datatypes","2.core-features/8.datatypes",{"title":69,"path":70,"stem":71,"icon":72},"Operators","/core-features/operators","2.core-features/9.operators","i-lucide-percent",{"title":74,"path":75,"stem":76,"icon":24},"Literals","/core-features/a.literals","2.core-features/a.literals",{"title":78,"path":79,"stem":80,"icon":24},"Keywords","/core-features/b.keywords","2.core-features/b.keywords",{"title":82,"icon":6,"path":83,"stem":84,"children":85,"page":6},"Features","/features","3.features",[86,90,94,98,102,106,110,114],{"title":87,"path":88,"stem":89,"icon":24},"Const","/features/const","3.features/1.const",{"title":91,"path":92,"stem":93,"icon":24},"Define","/features/define","3.features/2.define",{"title":95,"path":96,"stem":97,"icon":24},"Enum","/features/enum","3.features/3.enum",{"title":99,"path":100,"stem":101,"icon":24},"Union","/features/union","3.features/4.union",{"title":103,"path":104,"stem":105,"icon":24},"Overloading","/features/overloading","3.features/5.overloading",{"title":107,"path":108,"stem":109,"icon":24},"Lambda","/features/lambda","3.features/6.lambda",{"title":111,"path":112,"stem":113,"icon":24},"Callback","/features/callback","3.features/7.callback",{"title":115,"path":116,"stem":117,"icon":24},"Auto","/features/auto","3.features/8.auto",{"title":119,"icon":6,"path":120,"stem":121,"children":122,"page":6},"Advance Features","/advance","4.advance",[123,127,131,135,139,143],{"title":124,"path":125,"stem":126,"icon":24},"Generic Type","/advance/generic-type","4.advance/1.generic-type",{"title":128,"path":129,"stem":130,"icon":24},"Errors","/advance/error","4.advance/2.error",{"title":132,"path":133,"stem":134,"icon":24},"Annotation","/advance/annotation","4.advance/3.annotation",{"title":136,"path":137,"stem":138,"icon":24},"Variadic Function","/advance/variadic-func","4.advance/4.variadic-func",{"title":140,"path":141,"stem":142,"icon":24},"Module","/advance/module-interface","4.advance/5.module-interface",{"title":144,"path":145,"stem":146,"icon":24},"Operator Overloading","/advance/operator-overloading","4.advance/6.operator-overloading",{"title":148,"icon":6,"path":149,"stem":150,"children":151,"page":6},"Struct","/struct","5.struct",[152,155,159,163,167],{"title":148,"path":153,"stem":154,"icon":24},"/struct/struct","5.struct/1.struct",{"title":156,"path":157,"stem":158,"icon":24},"Methods","/struct/methods","5.struct/2.methods",{"title":160,"path":161,"stem":162,"icon":24},"Init/Deinit","/struct/init-deinit","5.struct/3.init-deinit",{"title":164,"path":165,"stem":166,"icon":24},"Encapsulation","/struct/encapsulation","5.struct/4.encapsulation",{"title":168,"path":169,"stem":170,"icon":24},"Static","/struct/static","5.struct/5.static",{"title":172,"icon":6,"path":173,"stem":174,"children":175,"page":6},"Data Structures","/data-structure","6.data-structure",[176,180],{"title":177,"path":178,"stem":179,"icon":24},"Array","/data-structure/array","6.data-structure/array",{"title":181,"path":182,"stem":183,"icon":24},"Structural Type","/data-structure/strutural-type","6.data-structure/strutural-type",{"title":185,"icon":6,"path":186,"stem":187,"children":188,"page":6},"Standard Libraries","/stdlib","7.stdlib",[189,194],{"title":190,"path":191,"stem":192,"icon":193},"stdlib","/stdlib/stdlib","7.stdlib/stdlib","i-lucide-library-big",{"title":195,"path":196,"stem":197,"icon":24},"syscall","/stdlib/syscall","7.stdlib/syscall",{"id":199,"title":195,"body":200,"description":475,"extension":476,"links":477,"meta":478,"navigation":479,"path":196,"seo":480,"stem":197,"__hash__":481},"docs/7.stdlib/syscall.md",{"type":201,"value":202,"toc":470},"minimark",[203,220,226,270,286,291,296,305,309,316,375,378,382,389,403,411,446,466],[204,205,206,207,214,215,219],"p",{},"A ",[208,209,213],"a",{"href":210,"rel":211},"https://en.wikipedia.org/wiki/System_call",[212],"nofollow","system call"," is the programmatic way in which a computer program requests a service from the operating system kernel on which it is executed. System call is the only one who makes actions like I/O operations, file managment, memeory allocation, and any other things possible. It's the backbone of the implementation of the entire ",[216,217,218],"strong",{},"standard library",".",[204,221,222,223,219],{},"Normally, invoking a system call requires writing a direct assembly code and that's complicated. However, in Cambo, there exists a keyword to do so, which is ",[224,225,195],"code",{},[227,228,234],"pre",{"className":229,"code":230,"filename":231,"language":232,"meta":233,"style":233},"language-kh shiki shiki-themes material-theme-lighter one-light one-dark-pro","syscall NR (arg0, arg1, arg2, ...)\n","syntax","kh","",[224,235,236],{"__ignoreMap":233},[237,238,241,244,248,252,256,259,262,264,267],"span",{"class":239,"line":240},"line",1,[237,242,195],{"class":243},"sQsOY",[237,245,247],{"class":246},"spnjr"," NR",[237,249,251],{"class":250},"sM89C"," (",[237,253,255],{"class":254},"s8dPH","arg0",[237,257,258],{"class":250},", ",[237,260,261],{"class":254},"arg1",[237,263,258],{"class":250},[237,265,266],{"class":254},"arg2",[237,268,269],{"class":250},", ...)\n",[271,272,273,280],"ul",{},[274,275,276,279],"li",{},[224,277,278],{},"NR"," is the numeric reference of the syscall",[274,281,282,285],{},[224,283,284],{},"arg"," are the required arguments, can be none.",[287,288,290],"h3",{"id":289},"what-does-syscall-do-behind-the-scene","What does syscall do behind the scene?",[204,292,293,295],{},[224,294,195],{}," will tell the compiler to generate assembly instructions to invoke a\nsystem call based on the given arguments. The generated assembly is platform and\nachitecture dependent.\nCambo has the philosophy of write once compile anywhere (WOCA). Inline assembly\nis not portable, so it's forbidden in the language, and syscall keyword is\nused instead.",[204,297,298,301,302,304],{},[216,299,300],{},"Note",": because all system calls across different platforms and achitectures\nhave at most 6 arguments, so ",[224,303,195],{}," has only 6 for now, from arg0 to arg5.",[287,306,308],{"id":307},"example-1","Example #1",[204,310,311,312,315],{},"Below is an example of invoking syscall ",[224,313,314],{},"exit()"," for Linux x86_64.",[227,317,319],{"className":229,"code":318,"language":232,"meta":233,"style":233},"int main(string args[]){\n\n  syscall 0x3c (0);\n\n}\n",[224,320,321,341,348,364,369],{"__ignoreMap":233},[237,322,323,326,329,332,335,338],{"class":239,"line":240},[237,324,325],{"class":254},"int",[237,327,328],{"class":246}," main",[237,330,331],{"class":250},"(",[237,333,334],{"class":243},"string",[237,336,337],{"class":254}," args",[237,339,340],{"class":250},"[]){\n",[237,342,344],{"class":239,"line":343},2,[237,345,347],{"emptyLinePlaceholder":346},true,"\n",[237,349,351,354,357,361],{"class":239,"line":350},3,[237,352,353],{"class":243},"  syscall",[237,355,356],{"class":250}," 0x3c (",[237,358,360],{"class":359},"sriKn","0",[237,362,363],{"class":250},");\n",[237,365,367],{"class":239,"line":366},4,[237,368,347],{"emptyLinePlaceholder":346},[237,370,372],{"class":239,"line":371},5,[237,373,374],{"class":250},"}\n",[204,376,377],{},"On Linux x86_64, the NR for exit is 0x3c or 60, taking one argument which is the\nerror code.",[287,379,381],{"id":380},"example-2","Example #2",[204,383,384,385,388],{},"Here is another syscall ",[224,386,387],{},"write()",";",[271,390,391,394,397,400],{},[274,392,393],{},"NR: 0x01",[274,395,396],{},"arg0: file descriptor",[274,398,399],{},"arg1: buffer",[274,401,402],{},"arg2: size of buffer",[227,404,409],{"className":405,"code":407,"language":408},[406],"language-text","int main(string args[]){\n\n  int written_bytes = syscall 0x1 (1, \"hello, world\\n\", 13 );\n  \n\n  return 0;\n}\n","text",[224,410,407],{"__ignoreMap":233},[271,412,413,419,425,432,440],{},[274,414,415,416],{},"We want to write to stdout (terminal), and stdout has file descriptor of ",[224,417,418],{},"1",[274,420,421,424],{},[224,422,423],{},"\"hello, world\\b\""," is the buffer.",[274,426,427,428,431],{},"If we count each character one by one in ",[224,429,430],{},"hello, world\\n",", we will get 13 which\nis length of the string.",[274,433,434,436,437,388],{},[224,435,387],{}," returns the number of written bytes on success, or -1 on error, so we\nassign it to ",[224,438,439],{},"written_byte",[274,441,442,445],{},[224,443,444],{},"hello, world"," should be output to the terminal when this program is run",[447,448,449,451],"note",{},[204,450,300],{},[271,452,453,456,461],{},[274,454,455],{},"The above code example is not safe and not recommended.",[274,457,458,460],{},[224,459,195],{}," does not check the types of arguments, must handle carefully.",[274,462,463,465],{},[224,464,195],{}," serves as a bridge to request services directly from the kernel, and\nshould only be used in the low-level standard libraries with proper implementation.",[467,468,469],"style",{},"html pre.shiki code .sQsOY, html code.shiki .sQsOY{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#A626A4;--shiki-default-font-style:inherit;--shiki-dark:#C678DD;--shiki-dark-font-style:inherit}html pre.shiki code .spnjr, html code.shiki .spnjr{--shiki-light:#6182B8;--shiki-default:#4078F2;--shiki-dark:#61AFEF}html pre.shiki code .sM89C, html code.shiki .sM89C{--shiki-light:#90A4AE;--shiki-default:#383A42;--shiki-dark:#ABB2BF}html pre.shiki code .s8dPH, html code.shiki .s8dPH{--shiki-light:#90A4AE;--shiki-default:#E45649;--shiki-dark:#E06C75}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sriKn, html code.shiki .sriKn{--shiki-light:#F76D47;--shiki-default:#986801;--shiki-dark:#D19A66}",{"title":233,"searchDepth":343,"depth":343,"links":471},[472,473,474],{"id":289,"depth":350,"text":290},{"id":307,"depth":350,"text":308},{"id":380,"depth":350,"text":381},"Invoke a system call with one line!","md",null,{},{"icon":24},{"title":195,"description":475},"3JhAfWMvGK8zLSpkzQgKUO8m_2qVVqPzyrRj_Fbo_Gc",[483,477],{"title":190,"path":191,"stem":192,"description":484,"icon":193,"children":-1},"Cambo's standard library.",1774971231591]