Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions submissions/guillermovidalsule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Physical Memory Protection - Configuration Verifier

This purpose of this tool is to verify whether a given access
with privilege mode _M_ can undertake an operation of type _O_
at a specific address.

## Project Structure

The folders and files are the following:

| Name | Type | Description |
| :--- | :---: | :---------- |
| `bin` | Directory | Output directory where the executable is placed. |
| `config` | Directory | Further configuration of the project. |
| `src` | Directory | Source code. |
| `alire.toml` | File | Crate settings. |
| `configuration.txt` | File | Basic PMP configuration to test the program. |
| `pmp_check.gpr` | File | Project configuration file. |
| `README.md` | File | Informational README about the project. |

There could be more entries, but they are out of the scope for the coding challenge.

The most important part is the source code, which consists of:

1. `pmp_check.adb` - Main program.
2. `pmp.ads` - Description of the PMP system.
3. `pmp.adb` - Implementation of the PMP system.

## Compile

In order to run the program you will need `gprbuild`. You can download it
with the GNAT FSF toolchain, which includes other necessary packages.

```
project-dir$ gprbuild -P pmp_check.adb
```

Alternatively, if you have the toolchain set up with Alire:

```
project-dir$ alr build
```

## Run

Running it is as simple as:

```
project-dir$ ./bin/pmp_check <path-to-config-file> <address> <privilege-mode> <operation>
```

> [!NOTE]
> If you do not wish / cannot compile it, a binary is already provided at the bin directory, but it can only be run on a x86\_64 architecture.

## Tools

I used the GNAT FSF 14 toolchain paired with Alire. In particular:

- `gprbuild 22.0.0`
- `alr 2.0.2`
- `gcc 14.2.0` (precompiled version that came with the toolchain)

This does not imply that other versions will not work, you could even try
using `gnatmake`, but I will not verify whether they are compatible or not.

## Final Remarks

I chose Ada because it is a statically and strongly typed language like IDL,
which is mentioned in the project description.
12 changes: 12 additions & 0 deletions submissions/guillermovidalsule/alire.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "pmp_check"
description = ""
version = "0.1.0-dev"

authors = ["Guillermo Vidal Sulé"]
maintainers = ["Guillermo Vidal Sulé <[email protected]>"]
maintainers-logins = ["github-username"]
licenses = "MIT OR Apache-2.0 WITH LLVM-exception"
website = ""
tags = []

executables = ["pmp_check"]
6 changes: 6 additions & 0 deletions submissions/guillermovidalsule/alire/alire.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# THIS FILE IS GENERATED. DO NOT EDIT.

[solution]
[solution.context]
solved = true

4 changes: 4 additions & 0 deletions submissions/guillermovidalsule/alire/build_hash_inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
external:LIBRARY_TYPE=default
external:PMP_CHECK_LIBRARY_TYPE=default
profile:pmp_check=DEVELOPMENT
switches:pmp_check=-Og,-fdata-sections,-ffunction-sections,-g,-gnatVa,-gnatW8,-gnatw.X,-gnatwa,-gnaty-d,-gnaty3,-gnatyA,-gnatyB,-gnatyI,-gnatyO,-gnatyS,-gnatya,-gnatyb,-gnatyc,-gnatye,-gnatyf,-gnatyh,-gnatyi,-gnatyk,-gnatyl,-gnatym,-gnatyn,-gnatyp,-gnatyr,-gnatyt,-gnatyu,-gnatyx
Empty file.
2 changes: 2 additions & 0 deletions submissions/guillermovidalsule/alire/settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
last_build_profile = "pmp_check=DEVELOPMENT"

Binary file added submissions/guillermovidalsule/bin/pmp_check
Binary file not shown.
20 changes: 20 additions & 0 deletions submissions/guillermovidalsule/config/pmp_check_config.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Configuration for pmp_check generated by Alire
pragma Restrictions (No_Elaboration_Code);
pragma Style_Checks (Off);

package Pmp_Check_Config is
pragma Pure;

Crate_Version : constant String := "0.1.0-dev";
Crate_Name : constant String := "pmp_check";

Alire_Host_OS : constant String := "linux";

Alire_Host_Arch : constant String := "x86_64";

Alire_Host_Distro : constant String := "ubuntu";

type Build_Profile_Kind is (release, validation, development);
Build_Profile : constant Build_Profile_Kind := development;

end Pmp_Check_Config;
50 changes: 50 additions & 0 deletions submissions/guillermovidalsule/config/pmp_check_config.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Configuration for pmp_check generated by Alire
abstract project Pmp_Check_Config is
Crate_Version := "0.1.0-dev";
Crate_Name := "pmp_check";

Alire_Host_OS := "linux";

Alire_Host_Arch := "x86_64";

Alire_Host_Distro := "ubuntu";
Ada_Compiler_Switches := External_As_List ("ADAFLAGS", " ");
Ada_Compiler_Switches := Ada_Compiler_Switches &
(
"-Og" -- Optimize for debug
,"-ffunction-sections" -- Separate ELF section for each function
,"-fdata-sections" -- Separate ELF section for each variable
,"-g" -- Generate debug info
,"-gnatwa" -- Enable all warnings
,"-gnatw.X" -- Disable warnings for No_Exception_Propagation
,"-gnatVa" -- All validity checks
,"-gnaty3" -- Specify indentation level of 3
,"-gnatya" -- Check attribute casing
,"-gnatyA" -- Use of array index numbers in array attributes
,"-gnatyB" -- Check Boolean operators
,"-gnatyb" -- Blanks not allowed at statement end
,"-gnatyc" -- Check comments
,"-gnaty-d" -- Disable check no DOS line terminators present
,"-gnatye" -- Check end/exit labels
,"-gnatyf" -- No form feeds or vertical tabs
,"-gnatyh" -- No horizontal tabs
,"-gnatyi" -- Check if-then layout
,"-gnatyI" -- check mode IN keywords
,"-gnatyk" -- Check keyword casing
,"-gnatyl" -- Check layout
,"-gnatym" -- Check maximum line length
,"-gnatyn" -- Check casing of entities in Standard
,"-gnatyO" -- Check that overriding subprograms are explicitly marked as such
,"-gnatyp" -- Check pragma casing
,"-gnatyr" -- Check identifier references casing
,"-gnatyS" -- Check no statements after THEN/ELSE
,"-gnatyt" -- Check token spacing
,"-gnatyu" -- Check unnecessary blank lines
,"-gnatyx" -- Check extra parentheses
,"-gnatW8" -- UTF-8 encoding for wide characters
);

type Build_Profile_Kind is ("release", "validation", "development");
Build_Profile : Build_Profile_Kind := "development";

end Pmp_Check_Config;
20 changes: 20 additions & 0 deletions submissions/guillermovidalsule/config/pmp_check_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Configuration for pmp_check generated by Alire */
#ifndef PMP_CHECK_CONFIG_H
#define PMP_CHECK_CONFIG_H

#define CRATE_VERSION "0.1.0-dev"
#define CRATE_NAME "pmp_check"

#define ALIRE_HOST_OS "linux"

#define ALIRE_HOST_ARCH "x86_64"

#define ALIRE_HOST_DISTRO "ubuntu"

#define BUILD_PROFILE_RELEASE 1
#define BUILD_PROFILE_VALIDATION 2
#define BUILD_PROFILE_DEVELOPMENT 3

#define BUILD_PROFILE 3

#endif
128 changes: 128 additions & 0 deletions submissions/guillermovidalsule/configuration.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
0x0F
0x08
0x17
0x1C
0x18
0x99
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x00001000
0x00002000
0x00003000
0x0817ffff
0x00005000
0x00006000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
0x00000000
22 changes: 22 additions & 0 deletions submissions/guillermovidalsule/pmp_check.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with "config/pmp_check_config.gpr";
project Pmp_Check is

for Source_Dirs use ("src/", "config/");
for Object_Dir use "obj/" & Pmp_Check_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("pmp_check.adb");

package Compiler is
for Default_Switches ("Ada") use Pmp_Check_Config.Ada_Compiler_Switches;
end Compiler;

package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;

package Install is
for Artifacts (".") use ("share");
end Install;

end Pmp_Check;
Loading