ABI - Use Rust code from C

I just followed “The Rust Reference: 17. Application Binary Interface (ABI)” and “The Embedded Rust Book: 10.2 A little Rust with your C” After then, I tried to expose Rust program to C as ABI. Test the code in the first reference foo.rs: // This is kept because of `#[used]`: #[used] static FOO: u32 = 123; // This is removable because it is unused: #[allow(dead_code)] static BAR: u32 = 0; // This is kept because it is publicly reachable: pub static BAZ: u32 = 0; // This is kept because it is referenced by a public, reachable function: static QUUX: u32 = 0; pub fn quux() -> &'static u32 { &QUUX } // This is removable because it is referenced by a private, unused (dead) function: static CORGE: u32 = 0; #[allow(dead_code)] fn corge() -> &'static u32 { &CORGE } used attribute The attribute can only be applied to static item.

Memory location of environment variable (Linux)

Check that each envirnment variables are assigned to processes you can see /pro/{{ process_id }}/environ holds all environment variable which is used for the process. https://man7.org/linux/man-pages/man5/proc.5.html /proc/[pid]/environ This file contains the initial environment that was set when the currently executing program was started via execve(2). The entries are separated by null bytes ('\0'), and there may be a null byte at the end. Thus, to print out the environment of process 1, you would do: $ cat /proc/1/environ | tr '\000' '\n' If, after an execve(2), the process modifies its environment (e.

ELF - My note for quick review

101 TL;DR 101 in a single image from Wikipedia: ELF file layout from Wikipedia ELF Executable and Linkable Fotmat. Major usage (in file header, offset 0x10) Executable Shared library Core file (core dump) The word segments is used at runtime (text segment, data segment, stack, heap). Sections means the functions in elf file. link time. Header info The ELF file header consists of two header, ELF header and program header table.

Memory allocation in Rust

While learning “15.3. Running Code on Cleanup with the Drop Trait” of the Rust official book, I just wondered the memory layout of Rust program. TL;DR: Currently the default global allocator is unspecified. Libraries, however, like cdylibs and staticlibs are guaranteed to use the System by default. Struct std::alloc::System: The default memory allocator provided by the operating system. This is based on malloc on Unix platforms and HeapAlloc on Windows, plus related functions.

Linear Algebra libraries for Rust

I tried to implement LWE with Rust. Here is the memo about linear algebra libraries. Which library to use As of Nov.2021, there was no “defacto standard” linear algebra library in Rust. I investigated, and decided to use ndarray or nlagebra. ndarray vs nalgebra - Reddit ndarray https://github.com/rust-ndarray/ndarray tensorflow/Rust uses ndarray. ndarray is mentioned in Rust cookbook: ndarray use BLAS impelementation on the runtime (Intel MKL, OpenBLAS, etc.), so it could be faster than other libraries.

Serde - tutorial

Serde (serializing and deserializing) is one of the most frequently used library in Rust. The library is production ready, usually used with Serde JSON (because of the popularity of REST APIs). Serialization From Wikipedia, In computing, serialization is the process of translating a data structure or object state into a format that can be stored (for example, in a file or memory data buffer) or transmitted (for example, over a computer network) and reconstructed later (possibly in a different computer environment)

Newtype Pattern, Avoid String Parameter in Strongly-Typed Languages

Why? String type has generally lots of choices for the values, so it prones to bugs. If your programing language supports strong-typing, you need to consider avoiding Strings as parameters of functions. Strong-typing led you Less bugs and validations. In Rust, it’s called a “newtype pattern”. The trinity, “Good naming (based on DDD) + good typing (struct) + enum”, helps us always. Newtype patterns in Rust https://doc.rust-lang.org/book/ch19-03-advanced-traits.html use std::ops::Add; struct Millimeters(u32); struct Meters(u32); impl Add<Meters> for Millimeters { type Output = Millimeters; fn add(self, other: Meters) -> Millimeters { Millimeters(self.

Trusted Certificates List - ca-certificate

I always googled the exact way to install certificates on Ubuntu local machine, so I left a note for my reference. Ubuntu cert store http://manpages.ubuntu.com/manpages/jammy/man8/update-ca-certificates.8.html Add the self-sign certificate to the trusted CA list under /usr/share/ca-certificates. The extension should be .crt. Add a line about the certificate in the configuration file /etc/ca-certificates.conf. Run sudo update-ca-certificates.

Import Free-Tier EC2 instance configuration in CloudFormation

Step 1. Create the CloudFormation YAML file AWSTemplateFormatVersion: '2010-09-09' Description: My Free Tier Parameters: KeyPair: Description: Select KeyPair Name. Type: AWS::EC2::KeyPair::KeyName Resources: DefaultVPC: Type: 'AWS::EC2::VPC' DeletionPolicy: Retain Properties: CidrBlock: '172.31.0.0/16' Tags: - Key: 'Name' Value: 'atlex00-default-VPC' DefaultSubnet: Type: 'AWS::EC2::Subnet' DeletionPolicy: Retain Properties: CidrBlock: '172.31.0.0/20' Tags: - Key: 'Name' Value: 'atlex00-default-subnet' VpcId: !Ref DefaultVPC FreeEC2Instance: Type: 'AWS::EC2::Instance' DeletionPolicy: Delete Properties: ImageId: "ami-05d34d340fb1d89e5" InstanceType: t2.micro SubnetId: !Ref DefaultSubnet BlockDeviceMappings: - DeviceName: '/dev/xvda' Ebs: VolumeType: 'gp2' VolumeSize: 8 Tags: - Key: 'Name' Value: 'free-tier' SecurityGroupIds: - !

CloudFormation - Tutorial with an EC2 instance

Important terminology Stack A stack is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting stacks. Resource Unbreakable components, like an EC2 instances, a routing table, VPC, Lambda function, etc. The form of template file The official document was quite comprehensive for me. Parameters: myparam: Type: String Default: foo .