Linuxã«ã¼ãã«ãé£ããï¼Rustã§å®è£ ãããï¼
ãã«ã¼ãã«éçºè ã«ãªãããï¼ã
ã¯ã©ã¦ããã¤ãã£ãä¸ä»£ã®çæ§ã¯ãä½ãè¨ã£ã¦ããã®ãç解ã§ããªãã¨æãã¾ãããä¸æåã¯ãLinuxã«ã¼ãã«éçºã®é åã«ãã¼ããã¨ã³ã¸ãã¢ããããããã¾ãããã¯ã©ã¦ããã¡ã¼ã¹ãæ代ã«ã誰ããã£ã¦ãªãã ããã¨ã軽ãæ°æã¡ã§è©¦ãã¨ãä»ãã²ã£ããã¨çæ¯ãã¦ããã«ã¼ãã«éçºè ã«ãä¸æ©ä¸ãæå°ããããã¯ãã«ãªãããã¾ãããåä¾ã®ãªãRustãªãå®å¿ã§ãã
Rustã§ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãå®è£ ããå©ç¹
Rustã¸ã®æã ããçç±ã§ã¯ãªããã«ã¼ãã«éçºã«Rustãç¨ããã¨ãæ§ã ãªãã°ãæ¸ãããã¨ãã§ãããã¨ããå©ç¹ãããã¾ããä¾ãã°ãåçãªã¡ã¢ãªç®¡çã§ããã£ããã解æ¾ãå¿ããã¨ãã解æ¾ããå¾ã«ä½¿ã£ã¦ãã¾ãã¨ãå¾ã ã¨ãã¦ãè¾ããããã°ã«ãªãã¾ãã
Rustã®ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«éçºãã¬ã¼ã ã¯ã¼ã¯ã«ãããã°ã³ã¼ãã追å ãã¦ãåçãªã¡ã¢ãªç¢ºä¿ã¨è§£æ¾ã確èªãã¦ã¿ã¾ããä¸è¨ã®ã¢ã¸ã¥ã¼ã«ã¯ãã«ã¼ãã«ã«ãã¼ããããåæåæã«ãé·ã32ã®u64ã®å¯å¤é·é åã確ä¿ãã¦ãã¾ãï¼16è¡ç®ï¼ãCè¨èªã§ããã°ãkmallocé¢æ°ãæ示çã«å¼ã³åºãã¦ã¡ã¢ãªã確ä¿ããé åã¨ãã¦åæåããã¨ããã§ãããRustã§ã¯èªåçã«kmallocé¢æ°ã使ã£ã¦ãé åãå¿ è¦ã¨ãã256ãã¤ãã確ä¿ãã¦ããã¾ãã
# insmod helloworld.ko
# dmesg |tail -n 2
Hello kernel module!
kmalloc: addr=0xffff8dc887af8d00, size=256
Cè¨èªã§ããã°ã確ä¿ããã¡ã¢ãªãä¸è¦ã«ãªã£ãéã«ã解æ¾ããããã«ãkfreeé¢æ°ãæ示çã«å¼ã³åºãå¿ è¦ãããã¾ãããRustã§ããã°ãä¸è¦ã§ãããã®ã¢ã¸ã¥ã¼ã«ã§ã¯ãã¢ã³ãã¼ãããéã«ã確ä¿ããã¡ã¢ãªã®ææè ã§ããã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ã¿ã³ã¹ãåé¤ããããããèªåçã«ã¡ã¢ãªã解æ¾ããã¾ãã
# rmmod helloworld
# dmesg |tail -n 2
Goodbye kernel module!
kfree: addr=0xffff8dc887af8d00
åçãªã¡ã¢ãªç®¡çã«é¢ãããã°ãçºçããªãã¨ãªãã°ãå®å¿ãã¦ãä»ã®ãã°ã®ä¿®æ£ã«éä¸ãããã¨ãã§ãã¾ããï¼
ã©ããªæ©è½ãå®è£ ã§ããã®ã
Rustã§ã®ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«éçºãå¾ ã¡ãããªãæãã§ããï¼
æ©éãä½ãã¢ã¸ã¥ã¼ã«ãå®è£ ãããã¨ããã¨ãç¾å¨ããã®ãã¬ã¼ã ã¯ã¼ã¯ã¯ããã¡ã¤ã«ã·ã¹ãã ãç»é²ããï¼ãã¡ã¤ã«ã·ã¹ãã ã®ä¸èº«ã¯å®è£ ã§ããªãï¼ããã£ã©ã¯ã¿ããã¤ã¹ãç»é²ããï¼ä¸èº«ã¯ã»ã¨ãã©å®è£ ã§ããªãï¼ããããããµãã¼ããã¦ããããæå³ã®ããæ©è½ã¯å®è£ ã§ããªããã¨ãçºè¦ã§ããã§ãããã
æ§ã ãªã¢ã¸ã¥ã¼ã«ãRustã§å®è£ ã§ããããã«ããããã«ã¯ãä¸è¨ã®ããã«ããã¬ã¼ã ã¯ã¼ã¯ãæ¡å¼µããå¿ è¦ãããã¾ãã
- Rustãããå¿ è¦ãªLinuxã«ã¼ãã«ã®APIãå¼ã³åºããããã«ããã
- Linuxã«ã¼ãã«ã®APIã確ä¿ããã½ã¼ã¹ããé©åã«è§£æ¾ãããããã«ãRustã®ææ権ã¢ãã«ã«ä¸è´ããAPIãå®è£ ããã
1ã¯ç°¡åã§ãLinuxã«ã¼ãã«ã®ããããããèªåçã«ãRustã®ã³ã¼ããçæãã¦ããã¾ãã2ã¯Rustã¸ã®æã§ä¹ãè¶ãã¦ããã¾ãããã
ã¾ã¨ã
ç¾ç¶ãRustã§ã®Linuxã«ã¼ãã«ã¢ã¸ã¥ã¼ã«å®è£ ã¯ãRustã ããªããCè¨èªã§ã®ã«ã¼ãã«éçºç¥èãå¿ è¦ã«ãªããCè¨èªã§å®è£ ããã»ããç°¡åã¨ãããã¨ãåããã¾ãããããããå ¨ã¦ã®Linuxã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ããRustã§æ¸ãç´ãã¨ãªãã°ããã®å 10å¹´éããããã¨ã³ã¸ãã¢ã¿ããªã®ä»äºãä½ããã¨ãã§ãã¾ããæ¥çæã§ãããNTTã§ã¯ã仲éãåéä¸ã§ããé£çµ¡ãå¾ ã¡ãã¦ãã¾ãã